]> git.ipfire.org Git - thirdparty/squid.git/blob - helpers/basic_auth/YP/yp_auth.c
Major rewrite of proxy authentication to support other schemes than
[thirdparty/squid.git] / helpers / basic_auth / YP / yp_auth.c
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
32 int get_nis_password();
33
34
35 int
36 main(int argc, char **argv)
37 {
38 char buf[256];
39 char nispasswd[15];
40 char *nisdomain;
41 char *nismap;
42 char *user, *passwd, *p;
43 int res;
44 setbuf(stdout, NULL);
45
46 if (argc != 3) {
47 fprintf(stderr, "Usage: yp_auth <domainname> <nis map for password>\n");
48 fprintf(stderr, "\n");
49 fprintf(stderr, "Example yp_auth mydomain.com passwd.byname\n");
50 exit(1);
51 }
52 nisdomain = argv[1];
53 nismap = argv[2];
54
55 while (fgets(buf, 256, stdin) != NULL) {
56 if ((p = strchr(buf, '\n')) != NULL)
57 *p = '\0'; /* strip \n */
58
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 }
67 res = get_nis_password(user, nispasswd, nisdomain, nismap);
68
69 if (res) {
70 /* User does not exist */
71 printf("ERR\n");
72 } else if (strcmp(nispasswd, (char *) crypt(passwd, nispasswd))) {
73 /* Password incorrect */
74 printf("ERR\n");
75 } else {
76 /* All ok !, thanks... */
77 printf("OK\n");
78 }
79 }
80 exit(0);
81 }