LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2004, 06:27 PM   #1
EddyHahn
LQ Newbie
 
Registered: Nov 2004
Location: North Bend, WA
Distribution: Suse 10.1 amd64
Posts: 8

Rep: Reputation: 0
Angry Having pain with PAM programming


Hello,
I'm trying to authenticate a user, such as I have the username and password. I go through the calls but I'm always receiving error 7 PAM_AUTH_ERROR. If I use a fake username and password it returns 10 (PAM_USER_UNKOWN) what is correct. So, I know it's working but I guess I'm missing something else.
Long story short: I need to be able to authenticate against PAM (it's very flexable).
To compile you need pam_devel*.rpm an you need to link with libpam (-lpam).

Your main should have
CAuthenticate a;
a.Authenticate("test","test");

the C++ header and cpp follows

Thanks for the help,

Eddy

Header:
#ifndef CAUTHENTICATE_H
#define CAUTHENTICATE_H

#include <cstdlib>
#include <security/pam_appl.h>
#include <string.h>

/**
@author Eddy Hahn
*/
class CAuthenticate{
private:
pam_handle_t* m_pPAM;

public:
CAuthenticate();

~CAuthenticate();
bool Authenticate(char* UserName, char* Password);

};

#endif

CPP:
#include "cauthenticate.h"

CAuthenticate::CAuthenticate()
{
m_pPAM = NULL;
}


CAuthenticate::~CAuthenticate()
{
}

int Conversation(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
{
if((*resp = (pam_response*) calloc( num_msg, sizeof **resp)) == NULL)
return PAM_SUCCESS;
for(int i=0; i< num_msg; i++)
switch(msg[i]->msg_style)
{
case PAM_PROMPT_ECHO_OFF:
resp[i]->resp_retcode=0;
resp[i]->resp = (char*) malloc( strlen( (char*) appdata_ptr));
strcpy(resp[i]->resp, (char*) appdata_ptr);
break;
case PAM_PROMPT_ECHO_ON:
break;
case PAM_ERROR_MSG:
break;
case PAM_TEXT_INFO:
break;
default:
break;
}

return PAM_SUCCESS;
}




bool CAuthenticate::Authenticate(char* UserName, char* Password)
{
bool RetVal = false;
int ret;
pam_handle_t* ph;
pam_conv conv;

conv.conv = &Conversation;
conv.appdata_ptr = Password;

if( pam_start( "auth", UserName, &conv, &m_pPAM) != PAM_SUCCESS)
return false;


ret = pam_authenticate( m_pPAM, PAM_SILENT);
if( ret == PAM_SUCCESS)
RetVal = true;

pam_end( m_pPAM, PAM_SUCCESS);

return RetVal;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorry to be a pain, but can someone help please? twirl Programming 5 09-06-2005 05:15 PM
Having pain with PAM programming EddyHahn Programming 0 11-21-2004 06:42 PM
vsftpd + pam + virtual users - Pam cannot load database file. mdkelly069 Linux - Networking 3 09-22-2004 11:07 PM
What a pain BajaNick General 4 08-30-2003 11:15 PM
oh the pain, the pain of c bobthebat Programming 2 07-04-2002 11:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration