ECHAIGNE Posted December 26, 2006 Posted December 26, 2006 Hi, how to obtain by script the complete list of the attributes available in a object resulting from a request LDAP, like their type of data? Exemple : Local $objDsOpenObject = ObjGet("LDAP:") Local $objUserDomain = $objDsOpenObject.OpenDSObject ("LDAP://cn=MyAccount,ou=users,dc=MyDomain,dc=organisation,dc=fr", "AdminAccount", "PWDAdmin", 0) I want to list all the attributes and their type of data Exemple : msgbox(0,"test", $objUserDomain.DisplayName & @lf & $objUserDomain.sAMAccountName ....) Thanks you for your answer Eric
ECHAIGNE Posted December 29, 2006 Author Posted December 29, 2006 ECHAIGNE said: Hi, how to obtain by script the complete list of the attributes available in a object resulting from a request LDAP, like their type of data? Exemple : Local $objDsOpenObject = ObjGet("LDAP:") Local $objUserDomain = $objDsOpenObject.OpenDSObject ("LDAP://cn=MyAccount,ou=users,dc=MyDomain,dc=organisation,dc=fr", "AdminAccount", "PWDAdmin", 0) I want to list all the attributes and their type of data Exemple : msgbox(0,"test", $objUserDomain.DisplayName & @lf & $objUserDomain.sAMAccountName ....) Thanks you for your answer Eric I found : I could not yet test all the type of data but that already made a base. On the other hand, one of you know it average to list the attributes (idem listattr) in a Novell directory? Global $dicADsType = ObjCreate("Scripting.Dictionary") $dicADsType.Add (0, "INVALID") $dicADsType.Add (1, "DN_STRING") $dicADsType.Add (2, "CASE_EXACT_STRING") $dicADsType.Add (3, "CASE_IGNORE_STRING") $dicADsType.Add (4, "PRINTABLE_STRING") $dicADsType.Add (5, "NUMERIC_STRING") $dicADsType.Add (6, "BOOLEAN") $dicADsType.Add (7, "INTEGER") $dicADsType.Add (8, "OCTET_STRING") $dicADsType.Add (9, "UTC_TIME") $dicADsType.Add (10, "LARGE_INTEGER") $dicADsType.Add (11, "PROV_SPECIFIC") $dicADsType.Add (12, "OBJECT_CLASS") $dicADsType.Add (13, "CASEIGNORE_LIST") $dicADsType.Add (14, "OCTET_LIST") $dicADsType.Add (15, "PATH") $dicADsType.Add (16, "POSTALADDRESS") $dicADsType.Add (17, "TIMESTAMP") $dicADsType.Add (18, "BACKLINK") $dicADsType.Add (19, "TYPEDNAME") $dicADsType.Add (20, "HOLD") $dicADsType.Add (21, "NETADDRESS") $dicADsType.Add (22, "REPLICAPOINTER") $dicADsType.Add (23, "FAXNUMBER") $dicADsType.Add (24, "EMAIL") $dicADsType.Add (25, "NT_SECURITY_DESCRIPTOR") $dicADsType.Add (26, "UNKNOWN") $dicADsType.Add (27, "DN_WITH_BINARY") $dicADsType.Add (28, "DN_WITH_STRING") Global $dicNtSecurity = ObjCreate("Scripting.Dictionary") $dicNtSecurity.Add (0, "Control") $dicNtSecurity.Add (1, "Group") $dicNtSecurity.Add (2, "Owner") $dicNtSecurity.Add (3, "Revision") Global $vbs, $Resultat DeclareFuncVBS() Demo() Exit Func Demo() Local $Resultat Local $objDsOpenObject = ObjGet("LDAP:") Local $objUser = $objDsOpenObject.OpenDSObject ("LDAP://cn=MyAccount,ou=users,dc=MyDomain,dc=organisation,dc=fr", "AdminAccount", "PWDAdmin", 0) Local $Attr = ListAttr("/schema/user") $objUser.GetInfo For $i = 1 To $Attr[0] $Resultat = PrintProperty($objUser.GetPropertyItem ($Attr[$i], 26), $Attr[$i]) Next EndFunc ;==>Demo Func ListAttr($DeQuoi) Local $Attributs Dim $Attr[1] $Attr[0] = 0 $Attributs = ObjGet("LDAP://" & $DeQuoi) If IsObj($Attributs) Then If IsArray($Attributs.MandatoryProperties) Then For $MandatoryProperties In $Attributs.MandatoryProperties ReDim $Attr[uBound($Attr) + 1] $Attr[0] += 1 $Attr[uBound($Attr) - 1] = $MandatoryProperties Next EndIf If IsArray($Attributs.OptionalProperties) Then For $OptionalProperties In $Attributs.OptionalProperties ReDim $Attr[uBound($Attr) + 1] $Attr[0] += 1 $Attr[uBound($Attr) - 1] = $OptionalProperties Next EndIf EndIf If $Attr[0] = 0 Then SetError(1) EndIf Return $Attr EndFunc ;==>ListAttr Func PrintProperty($propEntry, $Attribut) Local $objLargeInt, $Value, $SecurityDescriptor, $dacl, $sacl, $Inc, $Resultat If IsArray($propEntry.Values) Then ConsoleWrite("============================= " & $Attribut & " est un tableau de " & UBound($propEntry.Values) & " dimension(s) ==================================" & @LF) Dim $Resultat[uBound($propEntry.Values) ] $Inc = 0 For $propVal In $propEntry.Values Switch $dicADsType ($propVal.ADsType) Case "INVALID" $Resultat[$Inc] = "" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & "Donnée invalide") Case "DN_STRING" $Resultat[$Inc] = $propVal.DNSTRING ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "CASE_EXACT_STRING" $Resultat[$Inc] = $propVal.CaseExactString ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "CASE_IGNORE_STRING" $Resultat[$Inc] = $propVal.CaseIgnoreString ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "PRINTABLE_STRING" $Resultat[$Inc] = $propVal.PrintableString ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "NUMERIC_STRING" $Resultat[$Inc] = $propVal.NUMERICSTRING ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "BOOLEAN" $Resultat[$Inc] = (BitAND($propVal.BOOLEAN, 1) = 1) ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "INTEGER" $Resultat[$Inc] = $propVal.INTEGER ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "OCTET_STRING" $Value = OctetToHexStr($propVal.OCTETSTRING) If (StringLen($Value) / 2) = 28 Then ; Il s'agit d'un SID ReDim $Resultat[uBound($Resultat, 1) ][2] $Resultat[$Inc][0] = $Value $Resultat[$Inc][1] = HexStrToDecStr($Value) ConsoleWrite($dicADsType ($propVal.ADsType) & " (SID) ==>" & $Resultat[$Inc][0] & " (" & $Resultat[$Inc][1] & ")") Else $Resultat[$Inc] = $Value ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) EndIf Case "UTC_TIME" $Resultat[$Inc] = $propVal.UTCTIME ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "LARGE_INTEGER" $objLargeInt = $propVal.LargeInteger $Resultat[$Inc] = $objLargeInt.HighPart * 2 ^ 32 + $objLargeInt.LowPart ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "PROV_SPECIFIC" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "OBJECT_CLASS" $Resultat[$Inc] = $propVal.OBJECTCLASS ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "CASEIGNORE_LIST" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "OCTET_LIST" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "PATH" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "POSTALADDRESS" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "TIMESTAMP" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "BACKLINK" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "TYPEDNAME" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "HOLD" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "NETADDRESS" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "REPLICAPOINTER" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "FAXNUMBER" $Resultat[$Inc] = $propVal.FaxNumber ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "EMAIL" $Resultat[$Inc] = $propVal.Email ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "NT_SECURITY_DESCRIPTOR" $SecurityDescriptor = $propVal.SecurityDescriptor ReDim $Resultat[uBound($Resultat, 1) ][$dicNtSecurity.Count] $Resultat[$Inc][0] = $SecurityDescriptor.Control $Resultat[$Inc][1] = $SecurityDescriptor.Group $Resultat[$Inc][2] = $SecurityDescriptor.Owner $Resultat[$Inc][3] = $SecurityDescriptor.Revision ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & @LF) For $z = 0 To $dicNtSecurity.Count - 1 ConsoleWrite(" " & $dicNtSecurity.Item ($z) & "=" & $Resultat[$Inc][$z] & @LF) Next Case "UNKNOWN" $Resultat[$Inc] = "" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & "Donnée inconnue") Case "DN_WITH_BINARY" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case "DN_WITH_STRING" $Resultat[$Inc] = "<" & $dicADsType ($propVal.ADsType) & ">" ConsoleWrite($dicADsType ($propVal.ADsType) & "==>" & $Resultat[$Inc]) Case Else $Resultat[$Inc] = "" ConsoleWrite("Impossible de manipuler une propriété de type : " & $dicADsType ($propVal.ADsType)) EndSwitch ConsoleWrite(@LF) $Inc += 1 Next Else ;~ ConsoleWrite($Attribut & " n'est pas une donnée de l'objet" & @LF) $Resultat = "" EndIf Return $Resultat EndFunc ;==>PrintProperty Func DeclareFuncVBS() Local $s_Quotes = '"' Local $code $code = "Function vbsOctetToHexStr(arrbytOctet)" $code = $code & @CRLF & "Dim k" $code = $code & @CRLF & "vbsOctetToHexStr = """"" $code = $code & @CRLF & "For k = 1 To LenB(arrbytOctet)" $code = $code & @CRLF & "vbsOctetToHexStr = vbsOctetToHexStr & Right(""0"" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)" $code = $code & @CRLF & "Next" $code = $code & @CRLF & "end Function" $vbs = ObjCreate("ScriptControl") $vbs.language = "vbscript" $vbs.addcode ($code) $code = "Function vbsTypeName(VarName)" $code = $code & @CRLF & "vbsTypeName = TypeName(VarName)" $code = $code & @CRLF & "end Function" $vbs.addcode ($code) $code = "Function vbsIsEmpty(VarName)" $code = $code & @CRLF & "vbsIsEmpty = IsEmpty(VarName)" $code = $code & @CRLF & "end Function" $vbs.addcode ($code) $code = "Function vbsIsNull(VarName)" $code = $code & @CRLF & "vbsIsNull = IsNull(VarName)" $code = $code & @CRLF & "end Function" $vbs.addcode ($code) $code = "Function vbsIsNothing(VarName)" $code = $code & @CRLF & "vbsIsNothing = IsNothing(VarName)" $code = $code & @CRLF & "end Function" $vbs.addcode ($code) $code = "Function vbsLenB(VarName)" $code = $code & @CRLF & "vbsLenB = LenB(VarName)" $code = $code & @CRLF & "end Function" $vbs.addcode ($code) EndFunc ;==>DeclareFuncVBS Func OctetToHexStr($arrbytOctet) Local $retour = $vbs.run ("vbsOctetToHexStr", $arrbytOctet) Return $retour EndFunc ;==>OctetToHexStr Func TypeName($VarName) Local $retour = $vbs.run ("vbsTypeName", $VarName) Return $retour EndFunc ;==>TypeName Func IsEmpty($VarName) Local $retour = $vbs.run ("vbsIsEmpty", $VarName) Return $retour EndFunc ;==>IsEmpty Func IsNull($VarName) Local $retour = $vbs.run ("vbsIsNull", $VarName) Return $retour EndFunc ;==>IsNull Func IsNothing($VarName) Local $retour = $vbs.run ("vbsIsNothing", $VarName) Return $retour EndFunc ;==>IsNothing Func LenB($VarName) Local $retour = $vbs.run ("vbsLenB", $VarName) Return $retour EndFunc ;==>LenB ; Converti une valeur SID au format hexa en format décimal Func HexStrToDecStr($strSid) Local $Return = "" ; Function to convert Sid value in hex format ; to decimal display format. Dim $arrbytSid[1], $lngTemp, $j ReDim $arrbytSid[stringLen($strSid) / 2 - 1] For $j = 0 To UBound($arrbytSid) - 1 $arrbytSid[$j] = Number("0x" & StringMid($strSid, 2 * $j + 1, 2)) Next $Return = "S-" & $arrbytSid[0] & "-" & $arrbytSid[1] & "-" & $arrbytSid[8] $lngTemp = $arrbytSid[15] $lngTemp = $lngTemp * 256 + $arrbytSid[14] $lngTemp = $lngTemp * 256 + $arrbytSid[13] $lngTemp = $lngTemp * 256 + $arrbytSid[12] $Return = $Return & "-" & String($lngTemp) $lngTemp = $arrbytSid[19] $lngTemp = $lngTemp * 256 + $arrbytSid[18] $lngTemp = $lngTemp * 256 + $arrbytSid[17] $lngTemp = $lngTemp * 256 + $arrbytSid[16] $Return = $Return & "-" & String($lngTemp) $lngTemp = $arrbytSid[23] $lngTemp = $lngTemp * 256 + $arrbytSid[22] $lngTemp = $lngTemp * 256 + $arrbytSid[21] $lngTemp = $lngTemp * 256 + $arrbytSid[20] $Return = $Return & "-" & String($lngTemp) $lngTemp = $arrbytSid[25] $lngTemp = $lngTemp * 256 + $arrbytSid[24] $Return = $Return & "-" & String($lngTemp) Return $Return EndFunc ;==>HexStrToDecStr
cherdeg Posted August 14, 2008 Posted August 14, 2008 ECHAIGNE said: Local $objLargeInt, $Value, $SecurityDescriptor, $dacl, $sacl, $Inc, $ResultatHi, you define a variable "$sacl" but don't use it anywhere in your script. What did you have in mind with it - applying auditing settings for files and folders? I'm desperateley in search for someone being able to help me out regarding this topic - would you be the one?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now