dev_dopen() can be called multiple times with only one dev_dclose() when
[dragonfly/vkernel-mp.git] / lib / libskey / skey_crypt.c
blob4e3a141333a56432aafbbce1af899f748066985d
1 /* Author: Wietse Venema, Eindhoven University of Technology. */
3 #include <string.h>
4 #include <stdio.h>
5 #include <pwd.h>
6 #include <unistd.h>
8 #include "skey.h"
10 /* skey_crypt - return encrypted UNIX passwd if s/key or regular password ok */
12 const char *skey_crypt(pp, salt, pwd, pwok)
13 char *pp;
14 char *salt;
15 struct passwd *pwd;
16 int pwok;
18 struct skey skey;
19 char *p;
21 /* Try s/key authentication even when the UNIX password is permitted. */
23 if (pwd != 0 && skeyinfo(&skey, pwd->pw_name, (char *) 0) == 0
24 && skeyverify(&skey, pp) == 0) {
25 /* s/key authentication succeeded */
26 return (pwd->pw_passwd);
29 /* When s/key authentication does not work, always invoke crypt(). */
31 p = crypt(pp, salt);
32 if (pwok && pwd != 0 && strcmp(p, pwd->pw_passwd) == 0)
33 return (pwd->pw_passwd);
35 /* The user does not exist or entered bad input. */
37 return (":");