]> git.ipfire.org Git - thirdparty/squid.git/blob - helpers/basic_auth/NIS/nis_support.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / helpers / basic_auth / NIS / nis_support.cc
1 /*
2 * Written By Rabellino Sergio (rabellino@di.unito.it) For Solaris 2.x
3 */
4 #include "squid.h"
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <syslog.h>
9 #include <sys/types.h>
10 #include <rpc/rpc.h>
11
12 #if _SQUID_FREEBSD_ && !defined(BOOL_DEFINED)
13 // BUG: FreeBSD rpcsvc/yp_* headers try to redefine bool unless we match their non-standard hack.
14 #define BOOL_DEFINED
15 #endif
16
17 #include <rpcsvc/ypclnt.h>
18 #include <rpcsvc/yp_prot.h>
19
20 #include "nis_support.h"
21
22 #define NO_YPERR 0 /* There is no error */
23
24 char *
25 get_nis_password(char *user, char *nisdomain, char *nismap)
26 {
27 static char *val = NULL;
28 char *password = NULL;
29 int vallen, res;
30
31 #ifdef DEBUG
32 printf("Domain is set to %s\n", nisdomain);
33 printf("YP Map is set to %s\n", nismap);
34 #endif
35
36 /* Free last entry */
37 if (val) {
38 free(val);
39 val = NULL;
40 }
41
42 /* Get NIS entry */
43 res = yp_match(nisdomain, nismap, user, strlen(user), &val, &vallen);
44
45 switch (res) {
46 case NO_YPERR:
47 /* username = */
48 (void) strtok(val, ":");
49 password = strtok(NULL, ",:");
50 return password;
51 case YPERR_YPBIND:
52 syslog(LOG_ERR, "Squid Authentication through ypbind failure: can't communicate with ypbind");
53 return NULL;
54 case YPERR_KEY: /* No such key in map */
55 return NULL;
56 default:
57 return NULL;
58 }
59 }