1 /* pwdauth 2.0 - check a shadow password Author: Kees J. Bot
4 * This program gets as input the key and salt arguments of the crypt(3)
5 * function as two null terminated strings. The crypt result is output as
6 * one null terminated string. Input and output must be <= 1024 characters.
7 * The exit code will be 1 on any error.
9 * If the key has the form '##name' then the key will be encrypted and the
10 * result checked to be equal to the encrypted password in the shadow password
11 * file. If equal than '##name' will be returned, otherwise exit code 2.
13 * Otherwise the key will be encrypted normally and the result returned.
15 * As a special case, anything matches a null encrypted password to allow
16 * a no-password login.
19 #include <sys/types.h>
26 #define setkey pwdauth_setkey
27 #define encrypt pwdauth_encrypt
31 int main(int argc
, char **argv
)
38 /* Read input data. Check if there are exactly two null terminated
45 while (salt
> key
) if (*--salt
== 0) n
++;
47 salt
= key
+ strlen(key
) + 1;
49 if (salt
[0] == '#' && salt
[1] == '#') {
50 if ((pw
= getpwnam(salt
+ 2)) == nil
) return 2;
52 /* A null encrypted password matches a null key, otherwise
53 * do the normal crypt(3) authentication check.
55 if (*pw
->pw_passwd
== 0 && *key
== 0) {
58 if (strcmp(crypt(key
, pw
->pw_passwd
), pw
->pw_passwd
) != 0) {
62 /* Normal encryption. */
63 if (*salt
== 0 && *key
== 0) {
66 salt
= crypt(key
, salt
);
70 /* Return the (possibly new) salt to the caller. */
71 if (write(1, salt
, strlen(salt
) + 1) < 0) return 1;