]> git.ipfire.org Git - thirdparty/squid.git/blame - helpers/basic_auth/NIS/basic_nis_auth.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / helpers / basic_auth / NIS / basic_nis_auth.cc
CommitLineData
94439e4e 1/*
2 * Adapted By Rabellino Sergio (rabellino@di.unito.it) For Solaris 2.x
3 * From NCSA Authentication module
4 */
5
f7f3304a 6#include "squid.h"
5a48ed18
AJ
7#include "hash.h"
8#include "nis_support.h"
1fa9b1a7 9#include "rfc1738.h"
5a48ed18 10#include "util.h"
1fa9b1a7 11
94439e4e 12#if HAVE_STDIO_H
13#include <stdio.h>
14#endif
15#if HAVE_STDLIB_H
16#include <stdlib.h>
17#endif
18#if HAVE_UNISTD_H
19#include <unistd.h>
20#endif
21#if HAVE_STRING_H
22#include <string.h>
23#endif
24#if HAVE_SYS_TYPES_H
25#include <sys/types.h>
26#endif
27#if HAVE_SYS_STAT_H
28#include <sys/stat.h>
29#endif
30#if HAVE_CRYPT_H
31#include <crypt.h>
32#endif
33
94439e4e 34int
35main(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) {
5a48ed18 46 fprintf(stderr, "Usage: basic_yp_auth <domainname> <nis map for password>\n");
26ac0430 47 fprintf(stderr, "\n");
5a48ed18 48 fprintf(stderr, "Example basic_yp_auth mydomain.com passwd.byname\n");
26ac0430 49 exit(1);
94439e4e 50 }
51 nisdomain = argv[1];
52 nismap = argv[2];
53
54 while (fgets(buf, 256, stdin) != NULL) {
26ac0430
AJ
55 if ((p = strchr(buf, '\n')) != NULL)
56 *p = '\0'; /* strip \n */
94439e4e 57
26ac0430
AJ
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
26ac0430
AJ
67 rfc1738_unescape(user);
68 rfc1738_unescape(passwd);
9bbd1655 69
26ac0430 70 nispasswd = get_nis_password(user, nisdomain, nismap);
94439e4e 71
26ac0430
AJ
72 if (!nispasswd) {
73 /* User does not exist */
74 printf("ERR No such user\n");
75 } else if (strcmp(nispasswd, (char *) crypt(passwd, nispasswd)) == 0) {
76 /* All ok !, thanks... */
77 printf("OK\n");
78 } else {
79 /* Password incorrect */
80 printf("ERR Wrong password\n");
81 }
94439e4e 82 }
83 exit(0);
84}