]>
Commit | Line | Data |
---|---|---|
94439e4e | 1 | /* |
2 | * Adapted By Rabellino Sergio (rabellino@di.unito.it) For Solaris 2.x | |
3 | * From NCSA Authentication module | |
4 | */ | |
5 | ||
6 | #include "config.h" | |
1fa9b1a7 AJ |
7 | #include "rfc1738.h" |
8 | ||
94439e4e | 9 | #if HAVE_STDIO_H |
10 | #include <stdio.h> | |
11 | #endif | |
12 | #if HAVE_STDLIB_H | |
13 | #include <stdlib.h> | |
14 | #endif | |
15 | #if HAVE_UNISTD_H | |
16 | #include <unistd.h> | |
17 | #endif | |
18 | #if HAVE_STRING_H | |
19 | #include <string.h> | |
20 | #endif | |
21 | #if HAVE_SYS_TYPES_H | |
22 | #include <sys/types.h> | |
23 | #endif | |
24 | #if HAVE_SYS_STAT_H | |
25 | #include <sys/stat.h> | |
26 | #endif | |
27 | #if HAVE_CRYPT_H | |
28 | #include <crypt.h> | |
29 | #endif | |
30 | ||
31 | #include "util.h" | |
32 | #include "hash.h" | |
33 | ||
686e91cd | 34 | #include "nis_support.h" |
94439e4e | 35 | |
36 | int | |
37 | main(int argc, char **argv) | |
38 | { | |
39 | char buf[256]; | |
94439e4e | 40 | char *nisdomain; |
41 | char *nismap; | |
42 | char *user, *passwd, *p; | |
686e91cd | 43 | char *nispasswd; |
44 | ||
94439e4e | 45 | setbuf(stdout, NULL); |
46 | ||
47 | if (argc != 3) { | |
26ac0430 AJ |
48 | fprintf(stderr, "Usage: yp_auth <domainname> <nis map for password>\n"); |
49 | fprintf(stderr, "\n"); | |
50 | fprintf(stderr, "Example yp_auth mydomain.com passwd.byname\n"); | |
51 | exit(1); | |
94439e4e | 52 | } |
53 | nisdomain = argv[1]; | |
54 | nismap = argv[2]; | |
55 | ||
56 | while (fgets(buf, 256, stdin) != NULL) { | |
26ac0430 AJ |
57 | if ((p = strchr(buf, '\n')) != NULL) |
58 | *p = '\0'; /* strip \n */ | |
94439e4e | 59 | |
26ac0430 AJ |
60 | if ((user = strtok(buf, " ")) == NULL) { |
61 | printf("ERR\n"); | |
62 | continue; | |
63 | } | |
64 | if ((passwd = strtok(NULL, "")) == NULL) { | |
65 | printf("ERR\n"); | |
66 | continue; | |
67 | } | |
9bbd1655 | 68 | |
26ac0430 AJ |
69 | rfc1738_unescape(user); |
70 | rfc1738_unescape(passwd); | |
9bbd1655 | 71 | |
26ac0430 | 72 | nispasswd = get_nis_password(user, nisdomain, nismap); |
94439e4e | 73 | |
26ac0430 AJ |
74 | if (!nispasswd) { |
75 | /* User does not exist */ | |
76 | printf("ERR No such user\n"); | |
77 | } else if (strcmp(nispasswd, (char *) crypt(passwd, nispasswd)) == 0) { | |
78 | /* All ok !, thanks... */ | |
79 | printf("OK\n"); | |
80 | } else { | |
81 | /* Password incorrect */ | |
82 | printf("ERR Wrong password\n"); | |
83 | } | |
94439e4e | 84 | } |
85 | exit(0); | |
86 | } |