tools/llvm: Do not build with symbols
[minix3.git] / minix / commands / pwdauth / pwdauth.c
blob7951731defa5c364113e5f0d3029ffca1289f534
1 /* pwdauth 2.0 - check a shadow password Author: Kees J. Bot
2 * 7 Feb 1994
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.
18 #define nil 0
19 #include <sys/types.h>
20 #include <pwd.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
26 #define setkey pwdauth_setkey
27 #define encrypt pwdauth_encrypt
29 #define LEN 1024
31 int main(int argc, char **argv)
33 char key[LEN];
34 char *salt;
35 struct passwd *pw;
36 int n;
38 /* Read input data. Check if there are exactly two null terminated
39 * strings.
41 n= read(0, key, LEN);
42 if (n < 0) return 1;
43 salt = key + n;
44 n = 0;
45 while (salt > key) if (*--salt == 0) n++;
46 if (n != 2) return 1;
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) {
56 /* fine */
57 } else
58 if (strcmp(crypt(key, pw->pw_passwd), pw->pw_passwd) != 0) {
59 return 2;
61 } else {
62 /* Normal encryption. */
63 if (*salt == 0 && *key == 0) {
64 /* fine */
65 } else {
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;
72 return 0;