]>
Commit | Line | Data |
---|---|---|
94439e4e | 1 | /* |
2 | * Written By Rabellino Sergio (rabellino@di.unito.it) For Solaris 2.x | |
3 | */ | |
4 | ||
94439e4e | 5 | #include <stdlib.h> |
6 | #include <stdio.h> | |
7483aded | 7 | #include <string.h> |
94439e4e | 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 | ||
686e91cd | 14 | #include "nis_support.h" |
15 | ||
94439e4e | 16 | #define NO_YPERR 0 /* There is no error */ |
17 | ||
686e91cd | 18 | char * |
19 | get_nis_password(char *user, char *nisdomain, char *nismap) | |
94439e4e | 20 | { |
686e91cd | 21 | static char *val = NULL; |
22 | char *password = NULL; | |
94439e4e | 23 | int vallen, res; |
24 | ||
25 | #ifdef DEBUG | |
26 | printf("Domain is set to %s\n", nisdomain); | |
27 | printf("YP Map is set to %s\n", nismap); | |
28 | #endif | |
29 | ||
686e91cd | 30 | /* Free last entry */ |
31 | if (val) { | |
32 | free(val); | |
33 | val = NULL; | |
34 | } | |
35 | ||
94439e4e | 36 | /* Get NIS entry */ |
37 | res = yp_match(nisdomain, nismap, user, strlen(user), &val, &vallen); | |
38 | ||
39 | switch (res) { | |
40 | case NO_YPERR: | |
686e91cd | 41 | /* username = */ (void) strtok(val, ":"); |
42 | password = strtok(NULL, ",:"); | |
43 | return password; | |
94439e4e | 44 | case YPERR_YPBIND: |
45 | syslog(LOG_ERR, "Squid Authentication through ypbind failure: can't communicate with ypbind"); | |
686e91cd | 46 | return NULL; |
94439e4e | 47 | case YPERR_KEY: /* No such key in map */ |
686e91cd | 48 | return NULL; |
94439e4e | 49 | default: |
686e91cd | 50 | return NULL; |
94439e4e | 51 | } |
94439e4e | 52 | } |