Sign in to follow this  
Followers 0
ptrex

LDAP Byte return - is not recognized

59 posts in this topic

#1 ·  Posted (edited)

Some of us have been trying to get the return value of the following code :

#include <array.au3>

Dim $objUser  ;'An ADSI user object
Dim $arrProps ;'An array of properties to return
   
$objUser=ObjGet ("LDAP://cn=User,ou=OU,dc=DOMAIN,dc=COM")
   
;'**********************************************************************
;'Set the list of properties to return
;'**********************************************************************
$ArrProps = _ArrayCreate("cn","ADsPath", "LogonHours")
   
;'**********************************************************************
;'Get the specified properties
;'**********************************************************************
$objUser.GetInfoEx ($arrProps, 0)


ConsoleWrite( $objUser.cn & " | " & $objUser.ADsPath & " | " & _
              IsInt($objUser.LogonHours) & " | " & _
              IsString($objUser.LogonHours) & " | " & _
              IsArray($objUser.LogonHours) & " | " & _
              IsBool($objUser.LogonHours) & " | " & _
              IsNumber($objUser.LogonHours) & " | " & _
              IsBinary($objUser.LogonHours) & " | " & _
              IsFloat($objUser.LogonHours) & " | " & _
              Isobj($objUser.LogonHours) & " | " & _
              @LF)

This example should return values from the LDAP properties.

The problem is that non of the types that are returned, are recognized by AU3 for "LogonHours"

It's not an integer, not a string, not an Array, not a binary, ect.

This is a VBScript that does work :

Dim arrLogonHoursBytes(20)
Dim arrLogonHoursBits(167)
arrDayOfWeek = Array _
  ("Sun", "Mon", "Tue", "Wed", _
   "Thu", "Fri", "Sat")
 
Set objUser = GetObject _
  ("LDAP://CN=User,OU=IT,DC=Domain,DC=com")
objUser.GetInfoEx Array("logonHours"), 0
arrLogonHours = objUser.Get("logonHours")
 
For i = 1 To LenB(arrLogonHours)
     arrLogonHoursBytes(i-1) = AscB(MidB(arrLogonHours, i, 1))
Next
 
intCounter = 0
intLoopCounter = 0
WScript.Echo "Day  Byte 1   Byte 2   Byte 3"
For Each LogonHourByte In arrLogonHoursBytes
  arrLogonHourBits = GetLogonHourBits(LogonHourByte)
 
   If intCounter = 0 Then
    'WScript.STDOUT.Write arrDayOfWeek(intLoopCounter) & Space(2)
    WScript.Echo arrDayOfWeek(intLoopCounter) & Space(2)
    intLoopCounter = intLoopCounter + 1
  End If
 
    For Each LogonHourBit In arrLogonHourBits
       ' WScript.STDOUT.Write LogonHourBit
        WScript.Echo LogonHourBit
        intCounter = 1 + intCounter
 
        If intCounter = 8 or intCounter = 16 Then
         ' WScript.STDOUT.Write Space(1)
        WScript.Echo Space(1)
        End If
        
        If intCounter = 24 Then
          WScript.echo VbCr
          intCounter = 0
        End If 
    Next
Next
 
Function GetLogonHourBits(x)
    Dim arrBits(7)
    For i = 7 to 0 Step -1
        If x And 2^i Then
            arrBits(i) = 1
        Else
            arrBits(i) = 0
        End If
    Next
    GetLogonHourBits = arrBits
End Function

Regards

ptrex

Edited by ptrex

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The first question you should be asking yourself is, "Does AutoIt support Byte-Arrays returned from COM?" I think the answer to that question is no (I am not sure, I haven't kept up with AutoIt development). It's pretty obvious from the VBS code that what's being returned is a Byte-Array.

Edit: I should point out, this is only a bug if AutoIt claims to support Byte-Array's. If it doesn't, then this is not a bug.

Edited by Valik

Share this post


Link to post
Share on other sites

I was thinking if there is a creative way of using this to intercepts the Byte return values

$Ret = $objUser.Get("LogonHours")
$str        = "byte"
$a          = DllStructCreate($str)
DllStructSetData($a,1,$Ret,1)
MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($a) & @CRLF & _
        "Struct pointer: " & DllStructGetPtr($a) & @CRLF & _
        "Data: " & DllStructGetData($a,1) )

But I am not into DLLCall stuff so I can't tell if this is making sense.

regards,

ptrexd

Share this post


Link to post
Share on other sites

Interesting posts by Jon in another topic: How do I create a variant which contains a byte array?

Byte arrays are supported in the beta. Are you sure that the function wants byte data or does it want a null terminated ANSI string?

And then...

AutoIt can work with byte data but it may not have been implemented in the AutoIt to COM interface - that's probably where the problem is.

I guess Byte arrays might have been a typo, and he only meant byte data. So the confusion remains. Is there a way to deal with the byte array returned by $oUser.Get("LogonHours")?

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Interesting posts by Jon in another topic: How do I create a variant which contains a byte array?

And then...

I guess Byte arrays might have been a typo, and he only meant byte data. So the confusion remains. Is there a way to deal with the byte array returned by $oUser.Get("LogonHours")?

<_<

I don't understand what VBScript

objUser.GetInfoEx Array("logonHours"), 0

is supposed to do?

does it reserve array something for the

arrLogonHours = objUser.Get("logonHours")

for me referencing something with a string "logonHours" cannot return an array except is some very special relation between the 2 statements.

If you provide me a

$objUser=ObjGet ("LDAP://cn=User,ou=OU,dc=DOMAIN,dc=COM")

That I can work on a machine not being in a domain. I can analyse what is done by those 2 Statements :)

Share this post


Link to post
Share on other sites

mmm that's why it didn't work when i tried more than a year ago ...

really special this property. I tried to test with logonHours.LowPart (used for pwdLastSet) but i's not recognized.

this feature would be really cool for administration of AD <_<


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

@jpm

In order to simulate the script you NEED to be in a Domain for this.

So if you are not, you can"t test it I am afraid ?!

Someone else maybe ?

regards

ptrex

thanks,

so somebody else ...

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

thanks,

so somebody else ...

Yeah, the LogonHours property doesn't exist for non-AD user objects. So it has to be done on a domain.

This is a nice kerfuffle... the smart people can figure it out but they don't have domains to test -- I'm not one of the them but I have domains to play with (assuming legitimate educational purpose).

So, as I've done for some of ptrex's suggestions, if you have something to try then please post it and I'll run it and post back the results.

<_<

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Yeah, the LogonHours property doesn't exist for non-AD user objects. So it has to be done on a domain.

This is a nice kerfuffle... the smart people can figure it out but they don't have domains to test -- I'm not one of the them but I have domains to play with (assuming legitimate educational purpose).

So, as I've done for some of ptrex's suggestions, if you have something to try then please post it and I'll run it and post back the results.

<_<

can you explain what is suppose to do?

objUser.GetInfoEx Array("logonHours"), 0

I need that to understand what the next can do

Share this post


Link to post
Share on other sites

@All

i tested the following code, as explained by Jon's example in post 5 referred by PsaltyDS.

#include <array.au3>

Dim $objUser  ;'An ADSI user object
Dim $arrProps ;'An array of properties to return
   
$objUser=ObjGet ("LDAP://cn=USER,ou=DEPT,dc=DOMAIN,dc=COM")
   
;'**********************************************************************
;'Set the list of properties to return
;'**********************************************************************
$ArrProps = _ArrayCreate("cn","ADsPath", "LogonHours")
   
;'**********************************************************************
;'Get the specified properties
;'**********************************************************************
$objUser.GetInfoEx ($arrProps, 0)
$Ret = $objUser.Get("LogonHours")

$str        = "byte[20]"
$a          = DllStructCreate($str)
DllStructSetData($a,1,$Ret,1) ;,1
MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($a) & @CRLF & _
        "Struct pointer: " & DllStructGetPtr($a) & @CRLF & _
        "Data: " & DllStructGetData($a,1) & @CRLF & _
        "ErrorCode : " & @Error )

But no success :

Output :

Struct Size: 20

Struct pointer: 14803128

Data: 0x0000000000000000000000000000000000000000

@Jpm

Indead your confusion is correct.

Regarding the ARRAY function

objUser.GetInfoEx Array("logonHours"), 0

But this is how the funtion works.

The GetInfoEx only excepts an ARRAY. Even if it contains only 1 Element.

Strange but true.

regards

ptrex

Share this post


Link to post
Share on other sites

@All

i tested the following code, as explained by Jon's example in post 5 referred by PsaltyDS.

#include <array.au3>

Dim $objUser  ;'An ADSI user object
Dim $arrProps ;'An array of properties to return
   
$objUser=ObjGet ("LDAP://cn=USER,ou=DEPT,dc=DOMAIN,dc=COM")
   
;'**********************************************************************
;'Set the list of properties to return
;'**********************************************************************
$ArrProps = _ArrayCreate("cn","ADsPath", "LogonHours")
   
;'**********************************************************************
;'Get the specified properties
;'**********************************************************************
$objUser.GetInfoEx ($arrProps, 0)
$Ret = $objUser.Get("LogonHours")

$str        = "byte[20]"
$a          = DllStructCreate($str)
DllStructSetData($a,1,$Ret,1) ;,1
MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($a) & @CRLF & _
        "Struct pointer: " & DllStructGetPtr($a) & @CRLF & _
        "Data: " & DllStructGetData($a,1) & @CRLF & _
        "ErrorCode : " & @Error )

But no success :

Output :

@Jpm

Indead your confusion is correct.

Regarding the ARRAY function

But this is how the funtion works.

The GetInfoEx only excepts an ARRAY. Even if it contains only 1 Element.

Strange but true.

regards

ptrex

so next question is why do we need it in VB

the

arrLogonHours = objUser.Get("logonHours")

seems enough to retrieve the requested information.

Share this post


Link to post
Share on other sites

Come on guys, the simple answer is this. You want to know the answer to this, provide us something JP can test. If he can't test because he's not in a Domain, FIND ANOTHER BYTE ARRAY RETURN VALUE. Do you immediately start changing valve springs when your engine drops a cylinder or do you check the spark plug first? Same idea, don't try to debug the hard stuff until you debug the easy stuff first. If you can find a function that returns a byte array and that does not work, well, there's your answer.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

@jpm

Because at the moment nothing is returned ?

So we can't use the functions at all as it stands now.

regards

ptrex

are you speaking of the VBscript executed without the GetInfoEx statement?

can somebody explain me what this GetInfoEx statement is suppose to do?

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Come on guys, the simple answer is this. You want to know the answer to this, provide us something JP can test. If he can't test because he's not in a Domain, FIND ANOTHER BYTE ARRAY RETURN VALUE. Do you immediately start changing valve springs when your engine drops a cylinder or do you check the spark plug first? Same idea, don't try to debug the hard stuff until you debug the easy stuff first. If you can find a function that returns a byte array and that does not work, well, there's your answer.

Fair statement, Valik. But, at least for me, this is a very singular instance of this type of data. I would love to work this on some kind of byte array value that could be gotten from a standalone WinXP workstation. That would make it easy for anyone to duplicate the symptoms and try various solutions. The need to represent data this way however seems pretty unique to the LogonHours property of an AD user.

Do you know of another, more common, example we could be working on instead?

<_<

P.S. Another good point you made earlier, this is looking more like a feature request than a bug report, the more we play with it...

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Do you know of another, more common, example we could be working on instead?

Kind of a dumb question - if I knew of an example method/property returning a byte array, I would either debug this myself or post the code so others could!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0