]>
Commit | Line | Data |
---|---|---|
5b95b903 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
5b95b903 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
94439e4e | 9 | /* |
10 | * Adapted By Rabellino Sergio (rabellino@di.unito.it) For Solaris 2.x | |
11 | * From NCSA Authentication module | |
12 | */ | |
13 | ||
f7f3304a | 14 | #include "squid.h" |
03901cf8 | 15 | #include "auth/basic/NIS/nis_support.h" |
6ea850c1 | 16 | #include "hash.h" |
1fa9b1a7 | 17 | #include "rfc1738.h" |
5a48ed18 | 18 | #include "util.h" |
1fa9b1a7 | 19 | |
074d6a40 AJ |
20 | #include <cstdlib> |
21 | #include <cstring> | |
94439e4e | 22 | #if HAVE_UNISTD_H |
23 | #include <unistd.h> | |
24 | #endif | |
94439e4e | 25 | #if HAVE_SYS_TYPES_H |
26 | #include <sys/types.h> | |
27 | #endif | |
28 | #if HAVE_SYS_STAT_H | |
29 | #include <sys/stat.h> | |
30 | #endif | |
31 | #if HAVE_CRYPT_H | |
32 | #include <crypt.h> | |
33 | #endif | |
34 | ||
94439e4e | 35 | int |
36 | main(int argc, char **argv) | |
37 | { | |
38 | char buf[256]; | |
94439e4e | 39 | char *nisdomain; |
40 | char *nismap; | |
41 | char *user, *passwd, *p; | |
686e91cd | 42 | char *nispasswd; |
43 | ||
94439e4e | 44 | setbuf(stdout, NULL); |
45 | ||
46 | if (argc != 3) { | |
03901cf8 | 47 | fprintf(stderr, "Usage: basic_nis_auth <domainname> <nis map for password>\n"); |
26ac0430 | 48 | fprintf(stderr, "\n"); |
03901cf8 | 49 | fprintf(stderr, "Example basic_nis_auth mydomain.com passwd.byname\n"); |
26ac0430 | 50 | exit(1); |
94439e4e | 51 | } |
52 | nisdomain = argv[1]; | |
53 | nismap = argv[2]; | |
54 | ||
55 | while (fgets(buf, 256, stdin) != NULL) { | |
26ac0430 | 56 | if ((p = strchr(buf, '\n')) != NULL) |
f53969cc | 57 | *p = '\0'; /* strip \n */ |
94439e4e | 58 | |
26ac0430 AJ |
59 | if ((user = strtok(buf, " ")) == NULL) { |
60 | printf("ERR\n"); | |
61 | continue; | |
62 | } | |
63 | if ((passwd = strtok(NULL, "")) == NULL) { | |
64 | printf("ERR\n"); | |
65 | continue; | |
66 | } | |
9bbd1655 | 67 | |
26ac0430 AJ |
68 | rfc1738_unescape(user); |
69 | rfc1738_unescape(passwd); | |
9bbd1655 | 70 | |
26ac0430 | 71 | nispasswd = get_nis_password(user, nisdomain, nismap); |
94439e4e | 72 | |
26ac0430 AJ |
73 | if (!nispasswd) { |
74 | /* User does not exist */ | |
75 | printf("ERR No such user\n"); | |
1ea677a6 AJ |
76 | continue; |
77 | } | |
78 | ||
11978f84 | 79 | #if HAVE_CRYPT |
1ea677a6 AJ |
80 | char *crypted = NULL; |
81 | if ((crypted = crypt(passwd, nispasswd)) && strcmp(nispasswd, crypted) == 0) { | |
26ac0430 AJ |
82 | /* All ok !, thanks... */ |
83 | printf("OK\n"); | |
39970749 AJ |
84 | } else { |
85 | /* Password incorrect */ | |
86 | printf("ERR Wrong password\n"); | |
e2849af8 | 87 | } |
1ea677a6 AJ |
88 | #else |
89 | /* Password incorrect */ | |
90 | printf("BH message=\"Missing crypto capability\"\n"); | |
11978f84 | 91 | #endif |
94439e4e | 92 | } |
93 | exit(0); | |
94 | } | |
f53969cc | 95 |