I write a sample program to test PAM functionality. basically pam_chauthtok.

It is prefectly working in most of the Unix flavours bit not in HP UX 11i.

My program


#define DEBUG
#include <security/pam_appl.h>
#include <stdio.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
/*
 * PAM call back function to read the password values
 */

extern int convert(int num_msg,struct pam_message **msg,struct
pam_response **resp,void *appdata_ptr)
{
   // Initialize PAM response object and set password
   struct pam_response *temp;
   temp = (struct pam_response *)calloc(num_msg,sizeof(struct pam_response));
   temp[0].resp_retcode = 0;
   temp[0].resp = strdup((const char*)appdata_ptr);
   *resp = temp;
   return PAM_SUCCESS;
}
static struct pam_conv conv = {convert,NULL};
/*
 * Function used to change the password of a user
 */
int changePasswd(char *user,char *pass)
{
   pam_handle_t *pamh=NULL;
   int retval;
   struct pam_response *pp=NULL;
   conv.appdata_ptr = pass;
   // initialize PAM
   retval = pam_start("fisclsnr", user, &conv, &pamh);
   if (retval == PAM_SUCCESS)
   {
       // Change password (auth tocken)
       retval = pam_chauthtok(pamh, PAM_SILENT);
   }
   if (retval != PAM_SUCCESS)
   {
       return -1;
   }
   // End PAM Session
   if (pam_end(pamh,retval) != PAM_SUCCESS)
   {
       pamh = NULL;
       return -1;
   }
   return 0;
}
int main()
{
       int res = changePasswd("india","ClassObject123");
       printf( "Res = %d", res);
       return 0;
}


If I am trying to change the password of a normal user it doesnot work.
But change password of root user works fine.

 One more thing to point that, I add more debug meesages on my convert
function. It shows that, if the username specified is not root, then an
Old password request recieved at convert function. But if it is root ,
then no Old password request.

Anyone have any Idea ???
--
Shijithlal L V
Fischer Systems India
224 NILA Technopark
Trivandrum 695581
INDIA

Ph:  91 471 2527427
Cell: 91 9349100636
email: [EMAIL PROTECTED],[EMAIL PROTECTED]


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
linux-india-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to