Page 1 of 1

convert in PB

Posted: Thu Jul 29, 2010 2:19 pm
by jackymb
Hello
I need to make interogation on active directory, and I need help to convert the following code in purebasic

Code: Select all


IADs *pobjADs;    // Pointer to object interface
BSTR bstrName;    // String with object name    
HRESULT hResult;  // COM result code

    // String to directory service
    WCHAR *pstrADsPath = "LDAP://ldap.itd.umich.edu/O=University of Michigan,C=us";
    // Initalize COM
    CoInitialize ( NULL );

    // Get pointer to object's IADs interface
    hResult = ADsGetObject( pstrADsPath, IID_IADs, (void**) &pobjADs);

    // Check for success
    if ( SUCCEEDED ( hResult ) )
    {
    // Get the Name property from the object
    hResult = pobjADs->get_Name ( &bstrName );

        // Check for success
	if ( SUCCEEDED ( hResult ) )
	{            
	// Display Name property            
	// (must use wide strings when working with COM)
	wcout << "The name of the object found is: << bstrName << endl;
	}        
	else
	{
	wcerr << L"Error occured while getting the object name: " << hResult << endl;
	}
	// When finished with the interface, call the
	// Release method to free object
	pobjADs->Release ();
	}
	else
	{
	wcerr << L"Error occured while getting the object: "  << hResult << endl;
	}

    // Unload COM
    CoUninitialize ();

    // Return the result of any failures
    return hResult;

Thanks you

Re: convert in PB

Posted: Thu Jul 29, 2010 8:55 pm
by Rook Zimbabwe
The Lightweight Directory Access Protocol, or LDAP, is an application protocol for querying and modifying data using directory services running over TCP/IP
This really looks like a bad script kiddy attempted hack on the University of Michigan... it also looks like it could be abused many other places...

Nice 6th post!

Re: convert in PB

Posted: Thu Jul 29, 2010 11:50 pm
by Josh
@Rook Zimbabwe

all the functions in the code from jackymb are well documented in msdn, IADs is a standardinterface in pb and the activeds.dll has a typelib. so i don't see any problem.
i think, this code wasn't written by a bad script kiddy on the university of michigan. this code was written by three 'bad script kiddys', because LDAP was developt by three people at the university of michigan :D

@jackymb

it's not possible for me to test this code. so i think, there is a lot of bugs. see this code only as an idea for your experiments. use unicode mode.

Code: Select all

EnableExplicit

DataSection

  CompilerIf Defined (IID_IUnknown, #PB_Constant) = #False
    IID_IUnknown:
    Data.l $00000000
    Data.w $0000,$0000
    Data.b $C0,$00,$00,$00,$00,$00,$00,$46
  CompilerEndIf
  #IID_IUnknown = "00000000-0000-0000-C000-000000000046"

  CompilerIf Defined (CLSID_ACTIVEDS, #PB_Constant) = #False
    CLSID_ACTIVEDS:
    Data.l $97D25DB0
    Data.w $363,$11CF
    Data.b $AB,$C4,$2,$60,$8C,$9E,$75,$53
  CompilerEndIf
  #CLSID_ACTIVEDS = "97D25DB0-0363-11CF-ABC4-02608C9E7553"

  CompilerIf Defined (IID_IADs, #PB_Constant) = #False
    IID_IADs:
    Data.l $FD8256D0
    Data.w $FD15,$11CE
    Data.b $AB,$C4,$2,$60,$8C,$9E,$75,$53
  CompilerEndIf
  #IID_IADs = "FD8256D0-FD15-11CE-ABC4-02608C9E7553"

EndDataSection


Define hr.l
Define ADsPath.s
Define *oUnk.IUnknown
Define *oADs.IADs
Define *BStr

CoInitialize_ (0)

;Reference to Object
ADsPath = "LDAP://ldap.itd.umich.edu/O=University of Michigan,C=us"
hr = ADsGetObject_ (@ADsPath, ?CLSID_ACTIVEDS, @*oUnk)
If hr : MessageRequester (Str(hr), "Connecting Error") : End : EndIf

;Reference to Standardinterface
hr = *oUnk\QueryInterface (?IID_IADs, @*oADs)
If hr : MessageRequester (Str(hr), "Standardinterface not found") : End : EndIf
*oUnk\Release()

;Read and Display the Name
*oADs\get_Name (@*BStr)
Debug "Name: " + PeekS (*BStr)
SysFreeString_ (*BStr)

;Free Objects
*oADs\Release() : *oADs = 0

CoUninitialize_()
or try this one

Code: Select all

;.....
;.....
;.....


Define hr.l
Define ADsPath.s
Define *oADs.IADs
Define *BStr

CoInitialize_ (0)

;Reference to Object
ADsPath = "LDAP://ldap.itd.umich.edu/O=University of Michigan,C=us"
hr = ADsGetObject_ (@ADsPath, ?IID_IADs, @*oADs)
If hr : MessageRequester (Str(hr), "Connecting Error") : End : EndIf

;Read and Display the Name
*oADs\get_Name (@*BStr)
Debug "Name: " + PeekS (*BStr)
SysFreeString_ (*BStr)

;Free Objects
*oADs\Release() : *oADs = 0

CoUninitialize_()

Re: convert in PB

Posted: Fri Jul 30, 2010 10:41 am
by jackymb
Thank you JOSH
I tested, but I have a connection error, I'll watch
But before I'll take holiday

Re: convert in PB

Posted: Fri Jul 30, 2010 12:31 pm
by Josh
to set the correct ADsPath, i can't help you :roll:

what's the value of hr?