This is what I've done so far:
My OS: Debian Squeezy 64bit
Created a testuser with a password.
Created a file called "/etc/pam.d/pb_test":
Code: Select all
# On Debian I would prefer following:
#@include common-auth
#@include common-account
#@include common-session
#@include common-password
# Else for testing this should do:
auth required pam_unix.so
account required pam_unix.so
And my PB-code so far:
Code: Select all
If Not OpenConsole()
End 1
EndIf
Structure pam_message
msg_style.i
msgPtr.i
EndStructure
Structure pam_response
resp.i
resp_retcode.i
EndStructure
Global *currentPW
Prototype ProtoPamStart(servicenamePtr, usernamePtr, pamconvPtr, getpamhandlePtr)
Prototype ProtoPamAuthenticate(pamhandlePtr,flag)
Prototype ProtoPamEnd(pamhandlePtr,flag)
Prototype ProtoPamAcctMgmt(pamhandlePtr,flag)
Prototype ProtoPamStrerror(pamhandlePtr,errnum)
If OpenLibrary(0, "libpam.so")
Global pam_start.ProtoPamStart = GetFunction(0, "pam_start")
Global pam_authenticate.ProtoPamAuthenticate = GetFunction(0, "pam_authenticate")
Global pam_end.ProtoPamEnd = GetFunction(0, "pam_end")
Global pam_acct_mgmt.ProtoPamAcctMgmt = GetFunction(0, "pam_acct_mgmt")
Global pam_strerror.ProtoPamStrerror = GetFunction(0, "pam_strerror")
CloseLibrary(0)
If Not pam_start Or Not pam_authenticate Or Not pam_end Or Not pam_acct_mgmt Or Not pam_strerror
PrintN("Could NOT load function!")
End
EndIf
Else
PrintN("Could NOT open library!")
End
EndIf
Procedure Conv(*num_msg,*pam_msg.pam_message,*pam_resp.pam_response,*appdataPtr)
*resp.pam_response = AllocateMemory(SizeOf(*pam_resp))
*msg.pam_message = AllocateMemory(SizeOf(*pam_msg))
Select PeekI(*pam_msg\msg_style.i)
Case 1 ; Means Echo off
*resp\resp.i = *currentPW
*resp\resp_retcode = 0
Case 2 ; Means Echo on
PrintN("Echo ON - I guess we should prompt for username here")
EndSelect
*pam_resp = *resp
ProcedureReturn(0)
EndProcedure
PrintN("Authenticating ...")
*pam_conv_callback = @Conv()
retval = pam_start(@"pb_test",@"testuser",@*pam_conv_callback,@pamhandlePtr)
PrintN("Pam start: "+PeekS(pam_strerror(pamhandlePtr,retval)))
*currentPW = @"abc"
retval = pam_authenticate(pamhandlePtr,#NULL);32768)
PrintN("Pam auth: "+PeekS(pam_strerror(pamhandlePtr,retval)))
retval = pam_end(pamhandlePtr,0)
PrintN("Pam end: "+PeekS(pam_strerror(pamhandlePtr,retval)))
CloseConsole()
; ExecutableFormat = Console
It logs: "purebasic.out: pam_unix(pb_test:auth): auth could not identify password for [testuser]" in /var/log/auth.log
I'm pretty sure my Conv() function is not finished right now. I've searched in more then one other C-code how they did it and all of them are allocating some memory in one or another way and use a "for loop" for incoming *num_msg for the structure. I've no clue how I can do this in PB (it seems some kind of dynamic array at structures). But I think that is currently not the problem (or it would never be) cause the *num_msg is "1" at the current call anyway (so I guess I can skip the loop at this step).
C-Code example that needs some tweaking in PB:
Code: Select all
resp = malloc (net_msgs * sizeof(struct pam_response));
for (i = 0; i < net_msgs; i++) {
resp[i].resp_retcode = 0;
PB-Code??
Code: Select all
*resp.pam_response = AllocateMemory(SizeOf(*pam_resp))
For i = 0 to net_msg
resp[i]\resp_retcode = 0 ; that [i] for sure does not work
Next
Edit: Fixed small stuff. Even tried already when changing to pam_permit.so for sure I even get sucess with pam_authenticate. But that's not valid cause that always works.
Greetings,
auser


