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