1994-05-19 18:13:11 +00:00
|
|
|
/* Author: Wietse Venema, Eindhoven University of Technology. */
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <pwd.h>
|
1998-10-26 11:54:36 +00:00
|
|
|
#include <unistd.h>
|
1994-10-19 00:03:45 +00:00
|
|
|
|
|
|
|
#include "skey.h"
|
1994-05-19 18:13:11 +00:00
|
|
|
|
|
|
|
/* skey_crypt - return encrypted UNIX passwd if s/key or regular password ok */
|
|
|
|
|
1998-10-26 11:54:36 +00:00
|
|
|
const char *skey_crypt(pp, salt, pwd, pwok)
|
1997-03-08 06:22:51 +00:00
|
|
|
char *pp;
|
|
|
|
char *salt;
|
1994-05-19 18:13:11 +00:00
|
|
|
struct passwd *pwd;
|
|
|
|
int pwok;
|
|
|
|
{
|
|
|
|
struct skey skey;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
/* Try s/key authentication even when the UNIX password is permitted. */
|
|
|
|
|
1995-06-11 19:33:05 +00:00
|
|
|
if (pwd != 0 && skeyinfo(&skey, pwd->pw_name, (char *) 0) == 0
|
1994-05-19 18:13:11 +00:00
|
|
|
&& skeyverify(&skey, pp) == 0) {
|
|
|
|
/* s/key authentication succeeded */
|
|
|
|
return (pwd->pw_passwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* When s/key authentication does not work, always invoke crypt(). */
|
|
|
|
|
|
|
|
p = crypt(pp, salt);
|
|
|
|
if (pwok && pwd != 0 && strcmp(p, pwd->pw_passwd) == 0)
|
|
|
|
return (pwd->pw_passwd);
|
|
|
|
|
|
|
|
/* The user does not exist or entered bad input. */
|
|
|
|
|
|
|
|
return (":");
|
|
|
|
}
|