]>
Commit | Line | Data |
---|---|---|
94439e4e | 1 | /* |
2 | * Written By Rabellino Sergio (rabellino@di.unito.it) For Solaris 2.x | |
3 | */ | |
4 | ||
5 | #include <strings.h> | |
6 | #include <stdlib.h> | |
7 | #include <stdio.h> | |
8 | #include <syslog.h> | |
9 | #include <sys/types.h> | |
10 | #include <rpc/rpc.h> | |
11 | #include <rpcsvc/ypclnt.h> | |
12 | #include <rpcsvc/yp_prot.h> | |
13 | ||
14 | #define NO_YPERR 0 /* There is no error */ | |
15 | ||
16 | int | |
17 | get_nis_password(char *user, char *passwd, char *nisdomain, char *nismap) | |
18 | { | |
19 | char *val = NULL; | |
20 | char *username = NULL; | |
21 | int vallen, res; | |
22 | ||
23 | #ifdef DEBUG | |
24 | printf("Domain is set to %s\n", nisdomain); | |
25 | printf("YP Map is set to %s\n", nismap); | |
26 | #endif | |
27 | ||
28 | /* Get NIS entry */ | |
29 | res = yp_match(nisdomain, nismap, user, strlen(user), &val, &vallen); | |
30 | ||
31 | switch (res) { | |
32 | case NO_YPERR: | |
33 | username = strtok(val, ":"); | |
34 | strcpy(passwd, strtok(NULL, ":")); | |
35 | free(val); | |
36 | break; | |
37 | case YPERR_YPBIND: | |
38 | syslog(LOG_ERR, "Squid Authentication through ypbind failure: can't communicate with ypbind"); | |
39 | return 1; | |
40 | case YPERR_KEY: /* No such key in map */ | |
41 | return 1; | |
42 | default: | |
43 | return 1; | |
44 | } | |
45 | return 0; | |
46 | } |