C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 2nd, 2007, 09:31 AM
Darth_Berni Darth_Berni is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 2 Darth_Berni User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 50 sec
Reputation Power: 0
Password strength check using PAM framework

I need to write a C++ class capable of checking the strength of a given password. For convenience I've decided to use the existing PAM modules (e.g.: pam_passwdqc.so) for that purpose, but I can't find a way to pass the password from the (PAM-aware) application down to the checking module. PAM modules seem to get the password themselves and pass it among each other.

I thought writing a small custom module to obtain the password, but it seems a bit awkward to me. Any suggestion out here?.

Many thanks.
Bern

Reply With Quote
  #2  
Old August 3rd, 2007, 10:05 AM
Darth_Berni Darth_Berni is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 2 Darth_Berni User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 50 sec
Reputation Power: 0
I figured it out so I decided to share it.

The way to pass the password from the application to the PAM module to check its strength is via the "conversation" function.

The conversation function is a call-back that is typically used to prompt the user to enter the password, but it can be overwritten with a new one that would feed the password without interaction.

Codewise:

#include <security/pam_appl.h>
#include <security/pam_modules.h>

#include <stdio.h>
#include <string.h>
#include <unistd.h>


static char password[128];
static char buffer[128];
static struct pam_response myresp;


// My conversation function
int myconv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
{
// The PAM module wipes out the memory, so the password to be copied every time.

strcpy( buffer, password );

myresp.resp = buffer;
*resp = &myresp;

return (PAM_SUCCESS);
}




int main( int argc, char *argv[] )
{
pam_conv conv;
pam_handle_t *pamh;
int rv;

if( argc == 1 )
{
printf("Please enter a password in the command line\n");
return(-1);
}

strcpy( password, argv[1] );

// Setup My conversation function
conv.conv = myconv;

// myservice is configured in /etc/pam.d/myservice
if( (rv = pam_start( "myservice", "user", &conv, &pamh )) != PAM_SUCCESS )
{
printf("Error: %s\n", pam_strerror( pamh, rv) );
pam_end( pamh, rv );
return(-1);
}

// Check password strength
if((rv = pam_chauthtok( pamh, PAM_DISALLOW_NULL_AUTHTOK )) != PAM_SUCCESS)
{
printf("Error: %s\n", pam_strerror( pamh, rv) );
}

pam_end( pamh, rv );

return(0);
}


Bern.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Password strength check using PAM framework

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap