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