Add getopt_long from NetBSD
[dragonfly.git] / lib / libskey / skey_crypt.c
1 /* Author: Wietse Venema, Eindhoven University of Technology. */
2
3 #include <string.h>
4 #include <stdio.h>
5 #include <pwd.h>
6 #include <unistd.h>
7
8 #include "skey.h"
9
10 /* skey_crypt - return encrypted UNIX passwd if s/key or regular password ok */
11
12 const char *skey_crypt(pp, salt, pwd, pwok)
13 char *pp;
14 char *salt;
15 struct passwd *pwd;
16 int     pwok;
17 {
18     struct skey skey;
19     char   *p;
20
21     /* Try s/key authentication even when the UNIX password is permitted. */
22
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);
27     }
28
29     /* When s/key authentication does not work, always invoke crypt(). */
30
31     p = crypt(pp, salt);
32     if (pwok && pwd != 0 && strcmp(p, pwd->pw_passwd) == 0)
33         return (pwd->pw_passwd);
34
35     /* The user does not exist or entered bad input. */
36
37     return (":");
38 }