Just nu i M3-nätverket
Gå till innehåll

LDAP-koppling till AD


Daniel Wahlgren

Rekommendera Poster

Daniel Wahlgren

Hej! Försökte få svar på detta i forumet för asp, men har nog förstått att det handlar om mer Windowsspecifika frågor.

 

Jag har en IIS-server som står i ett windowsnätverk. Jag vill i en ASP applikation använda mig av ADSI för att lista medlemmar i en grupp.

 

Strukturen ser ut på detta sätt i MMC:

 

Active Directory Users and Computers

euit.com <-- Domän

Groups/Contacts <-- OU

faculty <-- Grupp

 

Vilken sträng skall jag använda i min LDAP://???? för att koppla mig till detta objekt? Vad jag än försöker får jag bara felmeddelanden. Har läst mig galen på MSDN...

 

**********

Om spelvåld påverkar unga, hur skulle pacmangenerationen se ut idag?

 

Länk till kommentar
Dela på andra webbplatser

Följande VBscript fungerar. Antar att du bara kan porta det rakt av till ASP (kanske måste du använda Server.CreateObject eller hur det nu är alla webnissar skriver =)

Set GroupObj = GetObject("LDAP://CN=faculty,OU=Groups/Contacts,DC=euit,DC=com")
For each UserObj in GroupObj.Members
   Wscript.Echo UserObj.Name, "(" & UserObj.FullName & ")"
Next

 

Annars kan du kör på det gamla hederliga viset (om du tycker LDAP är svårt:

Set GroupObj = GetObject("WinNT://euit.com/faculty)
For each UserObj in GroupObj.Members
   Wscript.Echo UserObj.Name, "(" & UserObj.FullName & ")"
Next

Då går den på NetBios-namnet för gruppen istället.

 

Lycka till... fråga gärna mer, sånt här gillar jag :-D.

 

/Mn

 

Länk till kommentar
Dela på andra webbplatser

  • 2 veckor senare...
Daniel Wahlgren

Tack för ditt svar.

På kodexempel 1 får jag:

error '80005000'

/path/to/file/test.asp, line 2

 

På kodexempel 2 får jag:

error '80070035'

/path/to/file/test.asp, line 2

Jag kör IIS 5 på Win2k SP3 SRP1.

Delegation är på.

 

Linje 2 är Set GroupObj...

Att direkt byta ut GetObject mot Server.CreateObject fungerade inte.

 

**********

Om spelvåld påverkar unga, hur skulle pacmangenerationen se ut idag?

 

Länk till kommentar
Dela på andra webbplatser

  • 2 veckor senare...
Daniel Wahlgren

Är det ingen som är kung på ADSI via ASP?

 

Jag har verkligen stora probelm och måste lösa dem så fort som möjligt. Det enda jag vill göra är att lista medlemmar i grupper, samt få ut viss information om användare. Jag har adminbehörighet på en W2Ksrv SP3 SRP1 IIS5 ASP-classic. Servern är inte Domänkontrollant men har en domänkontrollant på samma nät.

 

Som ni ser tidigare i denna tråd har jag testat både LDAP samt WinNT och får fel varje gång.

 

Snälla hjälp mig någon!

 

 

**********

Om spelvåld påverkar unga, hur skulle pacmangenerationen se ut idag?

 

Länk till kommentar
Dela på andra webbplatser

Daniel Wahlgren

Ok, jag har fått denna mycket tydliga beskrivning som ändå inte fungerade ett dugg. Men jag postar den i alla fall för den är mycket bra.

 

I remember struggling with connection strings when I

 

started using LDAP. The example you gave shows only the

 

right side of the equation. This object must be assigned

 

to a variable. The statement should be:

 

 

 

Set oUser = GetObject("LDAP://CN=Jeff

 

Smith,OU=Sales,DC=Fabrikam,DC=Com")

 

 

 

The object named oUser (a name of your choice) is a copy

 

of the user object in Active Directory for the

 

user "CN=Jeff Smith". The domain in this case is

 

Fabrikam.com. The user is in an OU called "Sales". CN is

 

the "Common Name" of the user, also referred to as

 

the "Full Name" when you create a user in Active Directory

 

Users and Computers. (Unfortunately, there is also a "Full

 

Name" or "Display Name" attribute, which is not the same.)

 

 

 

A couple of complications. The NetBIOS domain name in the

 

example would usually be Fabrikam, but it doesn't have to

 

be. In ADUC if you right click on your domain, you will

 

see the complete domain name, plus the Pre-Windows 2000

 

domain name, which is the NetBIOS Domain name. Your domain

 

name could be MyDomain.MyCompany.net, in which case the

 

LDAP string would end with

 

dc=MyDomain,dc=MyCompany,dc=net

 

 

 

A standard way to get the correct domain name for any

 

domain programmatically is to use RootDSE

 

 

 

Set oRoot = GetObject("LDAP://RootDSE")

 

sDomain = oRoot.Get("DefaultNamingContext")

 

 

 

sDomain will be the complete domain name the current user

 

is authenticated to in the form:

 

dc=MyDomain,dc=MyCompany,dc=net

 

 

 

Next, LDAP requires you know the complete path to the

 

object, including any containers or organizational units.

 

If the user is in the Sales OU, which in turn is in the

 

Denver OU, the string could be

 

cn=Jeff

 

Smith,ou=Sales,ou=Denver,dc=MyDomain,dc=MyCompany,dc=net

 

 

 

Many domains have users in the "users" container. Then the

 

string would be

 

cn=Jeff Smith,cn=users,dc=MyDomain,dc=MyCompany,dc=net

 

 

 

Containers have a cn (common name), like users.

 

Finally, the cn of a user can be different from their pre-

 

Windows 2000 logon name, also called the sAMAccountName in

 

LDAP. If you find the user in ADUC, the name field is cn

 

(common name). One of the properties on the Account tab is

 

Pre=Windows 2000 logon name (sAMAccountName). The

 

wshNetwork object returns the sAMAccountName.

 

 

 

Set wshNetwork = CreateObject("Wscript.Network")

 

sUserName = wshNetwork.UserName

 

 

 

This is probably what you are calling nt user name.

 

Unfortunately, unless it is the same as cn, it cannot be

 

used to bind to the user object with LDAP. There are few

 

ways to get cn from sAMAccountName. If the client is

 

W2k/XP, you can use ADSystemInfo.

 

 

 

Set oSysInfo = CreateObject("ADSystemInfo")

 

sUserAdsPath = oSysInfo.UserName

 

 

 

This will be the complete distinguished name of the user,

 

including OU's, containers, domain, etc. For example

 

cn=Jeff Smith,cn=users,dc=MyDomain,dc=MyCompany,dc=net

 

 

 

If the client is Win9x or NT, you can use NameTranslate,

 

as long as DSClient is installed.

 

 

 

sUserName = wshNetwork.UserName

 

Set oTrans = CreateObject("NameTranslate")

 

oTrans.Init 1, "MyDomain"

 

oTrans.Set 3, "MyDomain\" & sUserName

 

sUserAdsPath = oTrans.Get(1)

 

 

 

"MyDomain" is the NetBIOS Domain name. sUserAdsPath will

 

be the distinguishedName as above.

 

 

 

ADSI and DirectoryServices advice : http://groups.yahoo.com/group/ADSIANDDirectoryServices

 

WMI programming advice : http://groups.yahoo.com/group/WMIPROGRAMMING

 

ASPELITE member: www.aspelite.com

 

Carlos Magalhaes

 

 

**********

Om spelvåld påverkar unga, hur skulle pacmangenerationen se ut idag?

 

Länk till kommentar
Dela på andra webbplatser

Arkiverat

Det här ämnet är nu arkiverat och är stängt för ytterligare svar.

×
×
  • Skapa nytt...