7 messages in net.java.dev.jna.usersRe: [jna-users] Help mapping libpam i...
FromSent OnAttachments
Crump, MichaelNov 12, 2008 11:12 am 
Stefan EndrullisNov 12, 2008 1:33 pm 
Timothy WallNov 12, 2008 1:57 pm 
Crump, MichaelNov 12, 2008 2:44 pm 
Timothy WallNov 12, 2008 4:01 pm 
Crump, MichaelNov 13, 2008 10:44 am 
Timothy WallNov 13, 2008 12:06 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Help mapping libpam in LinuxActions...
From:Stefan Endrullis (ste@endrullis.de)
Date:Nov 12, 2008 1:33:02 pm
List:net.java.dev.jna.users

Hello,

comments below.

Crump, Michael schrieb:

Hello,

I’m still working on mapping libpam in Linux using jna. I think once I get an understanding of the first couple of functions it won’t be too bad. Anyhow here are the declarations of the first two functions I am trying to map:

int pam_start(const char *service_name, const char *user,

const struct pam_conv *pam_conversation,

pam_handle_t **pamh);

int pam_end(pam_handle_t *pamh, int pam_status);

and here are the related c structs:

struct pam_message {

int msg_style;

const char *msg;

};

struct pam_response {

char *resp;

int resp_retcode;

};

struct pam_conv {

int (*conv)(int num_msg, const struct pam_message **msg,

struct pam_response **resp, void *appdata_ptr);

void *appdata_ptr;

};

Here is what I’ve come up with so far. I would appreciate it if someone could tell me whether or not what I have come up with so far will work.

* public * * class * PamMessage * extends * Structure {

* int * msgStyle ;

String msg ;

}

OK, but all Structure fields must be "public".

* public * * class * PamResponse * extends * Structure {

* public * String resp ;

* public * * int * respRetCode ;

}

Looks good.

* *

* public * * class * PamConv * extends * Structure {

* public * * static * * interface * Conv * extends * Callback {

* int * callback( * int * numMsg, PamMessage pamMessage, PamResponse resp, Pointer appDataPtr);

}

I haven't used callbacks yet, therefore I cannot say if your Callback definition is correct. But I think you cannot translate the parameter type "const struct pam_message **" into a simple "PamMessage", because PamMessage
acts as "struct pam_message *".

IMO you have to use "PointerByReference pamMessage". Then you can read the
Structure content that way: PamMessage realPam = new PamMessage(); realPam.setMemory(pamMessage.getValue()); realPam.read();

Same for PamResponse parameter.

Conv conv ;

Pointer appDataPtr ;

}

Don't forget "public" before the Structure fields.

* public * * interface * LibPam * extends * Library {

* public * * int * pam_start(String service_name, String user,

PamConv pam_conversation, PointerByReference pamh) ;

* public * * int * pam_end(Pointer pamh, * int * pam_status);

}

Looks good.

Sorry for the long email and tia for any advice you are willing to provide.

Regards,

Michael

Regards, Stefan