RogFleming Posted May 7, 2009 Share Posted May 7, 2009 (edited) I figured since I really do not know C+ but I do know TCL I could bridge the gap without knowing C+I wrapped an existing TCL extension with a TCL wrapper to created a Command Line LDAP tool which can write output to stdout and a log file.To access the command line for this please visit this Manual Page Site.Click here!Here is the TCL code:load [file join [pwd] "ldap.dll"] proc {main} {argc argv} { set LdapResults $argv set chan [open c:\\ldap.log a] set timestamp [clock format [clock seconds]] puts $chan "$timestamp - $LdapResults" close $chan } proc init {argc argv} { } init $argc $argv main $argc $argvWith the LDAP extension added to the TCL compiler the user can use basic TCL code to be passed and allow LDAP queries to be completed.Example Log out put.Thu May 07 13:46:32 CDT 2009 - LDAP Erorr:Thu May 07 13:46:33 CDT 2009 - LDAP Query:{cn=TEXAS,ou=Fleming\, Roger:CN,ou=IT Security:OU,ou=Administrative Users:OU,ou=ad-texas,ou=LoginInfos,o=PS}Thu May 07 13:46:33 CDT 2009 - LDAP Query Results:ou=Fleming\, Roger:CN,ou=IT Security:OU,ou=Administrative Users:OU,ou=ad-texas,ou=LoginInfos,o=PSHere an example of Input code to use:set ps_ldap [ldap -timeout 10 ftwsso03 25000] set user_dn "cn=$_LOGINNAME,ou=ezbio" # Loop until user cancels dialog box or enters a null string catch {$ps_ldap bind cn=ldap-ezbio,ou=ezbio etrust2} catch_error if {$catch_error != ""} { set chan [open c:\\ldap.log a] set timestamp [clock format [clock seconds]] puts $chan "$timestamp - $LdapResults" close $chan } set user_found [$ps_ldap search -scope one -names 1 ou=ezbio cn=$_LOGINNAME] set user_results [$ps_ldap search $user_found] set param_name_len [string length $user_results] set param_name_start_index [string last " " $user_results] set param_name_end_index [string first "}" $user_results] set param_value [string range $user_results $param_name_start_index $param_name_end_index] set badgeid [string trimright $param_value "}"] set user_badge_num $badgeid Edited May 7, 2009 by RogFleming Link to comment Share on other sites More sharing options...
RogFleming Posted May 7, 2009 Author Share Posted May 7, 2009 (edited) Well it would seem I am limited to a 1 meg upload the zip file is 1.85 meg I will e-mail it to anyone who would like to see it or you can wrap it your self from the sourceforge.net look for freewrapTCLSH642.zip Here what you need the code I wrote load [file join [pwd] "ldap.dll"] proc {main} {argc argv} { set LdapResults $argv set chan [open c:\\ldap.log a] set timestamp [clock format [clock seconds]] puts $chan "$timestamp - $LdapResults" close $chan exit } proc init {argc argv} { } init $argc $argv main $argc $argvnsldapssl32v30.dllldap.dllfilelist.txtLdapCliTcl.zip Edited May 7, 2009 by RogFleming Link to comment Share on other sites More sharing options...
Creator Posted May 7, 2009 Share Posted May 7, 2009 Uuuhm...maybe im a bit stupid. But what relation to autoit does this have? Creator Link to comment Share on other sites More sharing options...
sdfijoi3kirt Posted August 19, 2010 Share Posted August 19, 2010 I thought I'd post this in case anyone googles. I made a very simple script in VB to get any property of our FDS and translated it to AutoIt. It can use authorization if needed. I think it can be interesting to many because of the use of GetInfoEx and ADSTYPE_OCTET_STRING needed for unusual properties. VBScript ---------------- 'CONSTANTS ------------ Set out = Wscript.StdOut Const ADSTYPE_OCTET_STRING = 8 Const attrToRetrieve = "passwordExpirationTime" Const uidToCheck = "uidToWorkOn" Const userToBindTo = "" '"uid=myUID,ou=randomOU,o=randomO" Const passwordToBindTo = "" '"mypassword" LDAPURL = "LDAP://10.100.100.100/uid=" & uidToCheck & ",ou=randomOU,o=randomO" 'MAIN PROGRAM ----------------- 'conect to the LDAP and perform the search Set dso = GetObject("LDAP:") Set obj = dso.OpenDSObject(LDAPURL, userToBindTo, passwordToBindTo, 0) 'fetch it to the cache, if a propierty is non standard you have to splicitly retrieve it (Ex) obj.GetInfo obj.GetInfoEx Array(attrToRetrieve), 0 'retrieve it from the cache Set prop = obj.GetPropertyItem(attrToRetrieve, ADSTYPE_OCTET_STRING) 'convert the octecstring value to a string we can manipulate valuearray = prop.Values For Each value In valuearray data = data & OctetToHexStr(value.OctetString) Next data = HexStrToAscii(data, true) 'now data has the needed string and we can extract the needed information expirationYear=GetYearFromYYYYMMDDHHMMSST (data) expirationMonth=GetMonthFromYYYYMMDDHHMMSST (data) expirationDay=GetDayFromYYYYMMDDHHMMSST (data) 'WScript.Echo expirationYear 'WScript.Echo expirationMonth 'WScript.Echo expirationDay ' compare the two dates, IMPORTANT: it seems VB func DateDiff doesn't take into account the different number of days of a month expirationDateForComparing= CStr(expirationDay) & "/" & CStr(expirationMonth) & "/" & CStr(expirationYear) daysToExpire= DateDiff("d", Date(), expirationDateForComparing) ' >0 we have time left until expiration. < 0 means already expired WScript.Echo "Days to expire: " daysToExpire 'AUXILIARY FUNCTIONS ------------- Function GetYearFromYYYYMMDDHHMMSST(S) GetYearFromYYYYMMDDHHMMSST = CInt( Mid(S, 1, 4) ) End Function Function GetMonthFromYYYYMMDDHHMMSST(S) GetMonthFromYYYYMMDDHHMMSST= CInt( Mid(S, 5, 2) ) End Function Function GetDayFromYYYYMMDDHHMMSST(S) GetDayFromYYYYMMDDHHMMSST =CInt( Mid(S, 7, 2) ) End Function '-------------------------- MORE AUX FUNCTIONS Function OctetToHexStr(var_octet) 'Converts binary data to a hex string Dim n OctetToHexStr = "" For n = 1 To lenb(var_octet) OctetToHexStr = OctetToHexStr & Right("0" & hex(ascb(midb(var_octet, n, 1))), 2) Next End Function Function PrintoutHex(var_hex, width) 'Takes a hexstring and returns an output in a hex editor style 'The width parameter determines how many byte per line the output has Dim k1, k2, s1, s2 PrintOutHex = "" For k1 = 1 To Len(var_hex) Step (width *2) s1 = Mid(var_hex, k1, (width *2)) s2 = "" s3 = HexStrToAscii(s1, False) For k2 = 1 To Len(s1) Step 2 s2 = S2 & Mid(S1, k2, 2) & " " Next s2 = s2 & String((width *3)-Len(s2), " ") If (k1=1) Then PrintOutHex = PrintOutHex & s2 & "| " & s3 Else PrintOutHex = PrintOutHex & vbcrlf & s2 & "| " & s3 End If Next End Function Function HexStrToAscii(var_hex, format) 'Converts a hex string to an ASCII string. 'If 'format'=TRUE, tabs and CR/LFs are inserted Dim k, v HexStrToAscii = "" For k = 1 To Len(var_hex) Step 2 v = CInt("&H" & Mid(var_hex, k, 2)) If ((v>31) And (v<128)) Then HexStrToAscii = HexStrToAscii & (chr(v)) Else If (format) Then Select Case v Case 8 HexStrToAscii = HexStrToAscii & vbTab Case 10 HexStrToAscii = HexStrToAscii & vbCrLf Case 13 Case Else HexStrToAscii = HexStrToAscii & "." End Select Else HexStrToAscii = HexStrToAscii & "." End If End If Next End Function Function BinaryToString(Binary) Dim I,S For I = 1 to LenB(Binary) S = S & Chr(AscB(MidB(Binary,I,1))) Next BinaryToString = S End Function ------------------------- AutoIt------------------- #include <Array.au3> ;CONSTANTS ------------ Const $ADSTYPE_OCTET_STRING = 8 Const $attrToRetrieve = "passwordExpirationTime" Const $uidToCheck = "uidToWorkOn" Const $userToBindTo = "" ;"uid=myUID,ou=randomOU,o=randomO" Const $passwordToBindTo = "" ;"mypassword" Const $LDAPURL = "LDAP://10.100.100.100/uid=" & $uidToCheck & ",ou=randomOU,o=randomO" ;MAIN PROGRAM ----------------- ;conect to the LDAP and perform the search $dso = ObjGet("LDAP:"); $obj = $dso.OpenDSObject($LDAPURL, $userToBindTo, $passwordToBindTo, 0); ;feed it to the cache, if a propierty is non standard you have to splicitly retrieve it (Ex) Dim $tempArray[1] $tempArray[0] = $attrToRetrieve $obj.GetInfo(); $obj.GetInfoEx ($tempArray, 0); ;retrieve it from the cache. OctetString for non AD standard objs $prop = $obj.GetPropertyItem($attrToRetrieve, $ADSTYPE_OCTET_STRING); Dim $varArray $varArray = $prop.Values ;transform the (always 1, but i'll do a loop just in case) OctetString value to an ANSI string $propertyValue="" For $i = 0 to (UBound($varArray)-1) $propertyValue= $propertyValue & BinaryToString($varArray[$i].OctetString) Next MsgBox(0, "", GetYearFromYYYYMMDDHHMMSST($propertyValue)) MsgBox(0, "", GetMonthFromYYYYMMDDHHMMSST($propertyValue)) MsgBox(0, "", GetDayFromYYYYMMDDHHMMSST($propertyValue)) ; ; AUX FUNCs ------------------------- ; Func GetYearFromYYYYMMDDHHMMSST($S) return Int( StringMid ($S, 1, 4) ) EndFunc Func GetMonthFromYYYYMMDDHHMMSST($S) return Int( StringMid ($S, 5, 2) ) EndFunc Func GetDayFromYYYYMMDDHHMMSST($S) return Int( StringMid ($S, 7, 2) ) EndFunc ------------------------- Link to comment Share on other sites More sharing options...
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