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>
27 #define setkey pwdauth_setkey
28 #define encrypt pwdauth_encrypt
33 int main(int argc
, char **argv
)
40 /* Read input data. Check if there are exactly two null terminated
47 while (salt
> key
) if (*--salt
== 0) n
++;
49 salt
= key
+ strlen(key
) + 1;
51 if (salt
[0] == '#' && salt
[1] == '#') {
52 if ((pw
= getpwnam(salt
+ 2)) == nil
) return 2;
54 /* A null encrypted password matches a null key, otherwise
55 * do the normal crypt(3) authentication check.
57 if (*pw
->pw_passwd
== 0 && *key
== 0) {
60 if (strcmp(crypt(key
, pw
->pw_passwd
), pw
->pw_passwd
) != 0) {
64 /* Normal encryption. */
65 if (*salt
== 0 && *key
== 0) {
68 salt
= crypt(key
, salt
);
72 /* Return the (possibly new) salt to the caller. */
73 if (write(1, salt
, strlen(salt
) + 1) < 0) return 1;