1996-10-06 13:32:37 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* passwdauth.c - pjchilds@imforei.apana.org.au
|
|
|
|
*
|
|
|
|
* authenticate user via the password file
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Peter Childs. The name of the author may not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <utmp.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <libutil.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "passwdauth.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
PasswdAuth(name, key)
|
|
|
|
char *name, *key;
|
|
|
|
{
|
|
|
|
static int logged_in = 0;
|
|
|
|
struct passwd *pwd;
|
|
|
|
char *salt, *ep;
|
|
|
|
struct utmp utmp;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "PasswdAuth: Called with name %s, key %s\n", name, key );
|
1996-10-06 13:32:37 +00:00
|
|
|
|
|
|
|
if(( pwd = getpwnam( name ) ))
|
|
|
|
salt = pwd->pw_passwd;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
endpwent();
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf( LogLCP, "PasswdAuth - user (%s) not in passwd file\n", name );
|
1996-10-06 13:32:37 +00:00
|
|
|
return 0; /* false - failed to authenticate (password not in file) */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef LOCALHACK
|
|
|
|
/*
|
|
|
|
* All our PPP usernames start with 'P' so i check that here... if you
|
|
|
|
* don't do this i suggest all your PPP users be members of a group
|
|
|
|
* and you check the guid
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( name[0] != 'P' )
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf( LogLCP, "PasswdAuth - user (%s) not a PPP user\n", name );
|
1996-10-06 13:32:37 +00:00
|
|
|
endpwent();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LOCALHACK */
|
|
|
|
|
|
|
|
ep = crypt( key, salt );
|
|
|
|
|
|
|
|
/* strcmp returns 0 if same */
|
|
|
|
if( strcmp( ep, pwd->pw_passwd ) != 0 )
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf( LogLCP, "PasswdAuth - user (%s,%s) authentication failed\n",
|
1996-10-06 13:32:37 +00:00
|
|
|
name, key );
|
|
|
|
endpwent();
|
|
|
|
return 0; /* false - failed to authenticate (didn't match up) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now we log them in... we have a static login flag so we don't
|
|
|
|
* do it twice :)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( ! logged_in )
|
|
|
|
{
|
|
|
|
(void)time(&utmp.ut_time);
|
|
|
|
(void)strncpy(utmp.ut_name, name, sizeof(utmp.ut_name));
|
|
|
|
|
1996-10-18 03:47:53 +00:00
|
|
|
/*
|
|
|
|
* if the first three chacters are "pap" trim them off before doing
|
|
|
|
* utmp entry (see sample.ppp-pap-dialup
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( strncmp( "pap", dstsystem, 3 ) == 0 )
|
|
|
|
(void)strncpy(utmp.ut_line, (char *)(dstsystem + 3), sizeof(utmp.ut_line));
|
|
|
|
else
|
|
|
|
(void)strncpy(utmp.ut_line, dstsystem, sizeof(utmp.ut_line));
|
1996-10-06 13:32:37 +00:00
|
|
|
|
1997-01-10 07:53:28 +00:00
|
|
|
(void)strncpy(utmp.ut_host, "auto-ppp",sizeof(utmp.ut_host));
|
1996-10-06 13:32:37 +00:00
|
|
|
login(&utmp);
|
|
|
|
(void)setlogin( pwd->pw_name );
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf( LogLCP, "PasswdAuth has logged in user %s\n", name );
|
1996-10-06 13:32:37 +00:00
|
|
|
|
|
|
|
logged_in = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
endpwent();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|