4 Replies Last post: Jun 15, 2006 12:52 AM by Anders Nilsson  
Anders Nilsson   5 posts since
Apr 24, 2006
Currently Being Moderated

Jun 12, 2006 3:27 PM

Parameter problem when calling LsaOpenPolicy

Hello,

 

I am trying to call LsaOpenPolicy.

 

See my code below. When I run it, I get:

 

Exception c0000005, at 77DE1C38

Access violation: attempting to write memory at address 00000000

Native function stack data: 0,b0e2bd0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,ffff,b0e2df0,0,460050,2000000,3503f8,3503f8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

 

I assume there is a problem with the last parameter.

 

Can someone please help?

 

Regards

 

Anders

 

-


 

package jniwrapper;

 

import com.jniwrapper.DefaultLibraryLoader;

import com.jniwrapper.Function;

import com.jniwrapper.Library;

import com.jniwrapper.Parameter;

import com.jniwrapper.Pointer;

import com.jniwrapper.Structure;

import com.jniwrapper.UInt32;

import com.jniwrapper.ULongInt;

import com.jniwrapper.WideString;

 

/**

*

*/

 

/**

  • @author Anders Nilsson

*

*/

public class TestLsaOpenPolicy {

     

    private static class LSA_OBJECT_ATTRIBUTES extends Structure

    {

/*

typedef struct LSAOBJECT_ATTRIBUTES {

     ULONG Length;

     HANDLE RootDirectory;

     PLSA_UNICODE_STRING ObjectName;

     ULONG Attributes;

     PVOID SecurityDescriptor;

     PVOID SecurityQualityOfService;

} LSA_OBJECT_ATTRIBUTES,  *PLSA_OBJECT_ATTRIBUTES;

*/         

        public ULongInt length = new ULongInt();

        public Pointer.Void rootDirectory = new Pointer.Void();

        public WideString objectName = new WideString();

        public ULongInt attributes = new ULongInt();

        public Pointer.Void securityDescriptor = new Pointer.Void();

        public Pointer.Void securityQualityOfService = new Pointer.Void();

 

        public LSA_OBJECT_ATTRIBUTES()

        {

            init(new Parameter[] {

                      length,

                      rootDirectory,

                      objectName,

                      attributes,

                      securityDescriptor,

                      securityQualityOfService

            });

        }

    }

     private Library _advapi;

     private Library _kernel;

 

     public TestLsaOpenPolicy() {

          _kernel = new Library("kernel32");          

          _advapi = new Library("Advapi32");

     }

 

     /**

     

  • @param args

      */

     public static void main(String[] args) {

          TestLsaOpenPolicy t;

          

          t = new TestLsaOpenPolicy();

          t.execute(args);

 

     }

 

     protected void execute(String[] args) {

          

          Parameter[] argn;

          Pointer.Void rtrn;

               

          DefaultLibraryLoader.getInstance().addPath(

          "G:
eclipse
newton
MetaData
GenericMechanisms
extlib");

          

          // Open Policy

          Function openPolicy = _advapi.getFunction("LsaOpenPolicy");

 

          UInt32 lsaHandle;

          

          lsaHandle = new UInt32(0);

          

          rtrn = new Pointer.Void(0);

          

          argn = new Parameter[4];

          argn[0] = new WideString();

          argn[1] = new LSA_OBJECT_ATTRIBUTES();

          argn[2] = new UInt32(0x0000FFFF);

          argn[3] = new Pointer(lsaHandle);

 

          openPolicy.invoke(rtrn, argn);

          System.out.println(rtrn);

 

     }

     private long getLastError(boolean clear)

    {

        UInt32 r = new UInt32();

        Function getLE = _kernel.getFunction("GetLastError");

        getLE.invoke(r);

        long errCode = r.getValue();

        if (clear)

        {

            UInt32 zero = new UInt32(0);

            Function setLE = _kernel.getFunction("SetLastError");

            setLE.invoke(null, zero);

        }

        return errCode;

    }     

}

 

Igor Novikov TeamDev Ltd. 225 posts since
Apr 24, 2006
Currently Being Moderated
1. Jun 14, 2006 12:53 PM in response to: Anders Nilsson
Re: Parameter problem when calling LsaOpenPolicy

Hi Anders,

 

In your sample you try to substitute LSA_UNICODE_STRING structure by WideString() instance. This may be the reason why your sample fails, because pointer to a wide character string should be inside the structure as specified in the documentation:

 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/lsaopenpolicy.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secmgmt/security/lsa_unicode_string.asp

 

Please try to fix this and let us know the results.

 

Sincerely,

 

Igor Novikov

 

Igor Novikov TeamDev Ltd. 225 posts since
Apr 24, 2006
Currently Being Moderated
3. Jun 14, 2006 7:35 PM in response to: Anders Nilsson
Re: Re: Re: Parameter problem when calling LsaOpenPolicy

Hi Anders,

 

There are several mistakes in your sample code:

 

1.LsaOpenPolicy return value is not pointer.

2.LSA_OBJECT_ATTRIBUTES is not filled correctly. ULONG Length should be equal to the structure lenght (default size of new WideString() instance is 256).

3.Second argument in LsaOpenPolicy function call should be pointer to structure but not structure.

 

Please fing the fixed sample code attached.

 

Do not hesitate to contact us if you have other questions.

 

Sincerely,

 

Igor Novikov

Attachments:

More Like This

  • Retrieving data ...