]> git.ipfire.org Git - thirdparty/squid.git/blame - src/auth/basic/NIS/nis_support.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / auth / basic / NIS / nis_support.cc
CommitLineData
5b95b903 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
5b95b903
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
94439e4e 9/*
10 * Written By Rabellino Sergio (rabellino@di.unito.it) For Solaris 2.x
11 */
f7f3304a 12#include "squid.h"
7f297a66 13
074d6a40
AJ
14#include <cstdlib>
15#include <cstring>
7f297a66 16#if HAVE_SYSLOG_H
94439e4e 17#include <syslog.h>
7f297a66
FC
18#endif
19#if HAVE_SYS_TYPES_H
94439e4e 20#include <sys/types.h>
7f297a66
FC
21#endif
22#if HAVE_RPC_RPC_H
94439e4e 23#include <rpc/rpc.h>
7f297a66 24#endif
a8f7fbed
PW
25
26#if _SQUID_FREEBSD_ && !defined(BOOL_DEFINED)
27// BUG: FreeBSD rpcsvc/yp_* headers try to redefine bool unless we match their non-standard hack.
28#define BOOL_DEFINED
29#endif
30
786b7fa9 31#if HAVE_RPCSVC_YPCLNT_H
94439e4e 32#include <rpcsvc/ypclnt.h>
786b7fa9 33#endif
7f297a66 34#if HAVE_RPCSVC_YP_PROT_H
94439e4e 35#include <rpcsvc/yp_prot.h>
7f297a66 36#endif
94439e4e 37
03901cf8 38#include "auth/basic/NIS/nis_support.h"
686e91cd 39
f53969cc 40#define NO_YPERR 0 /* There is no error */
94439e4e 41
686e91cd 42char *
43get_nis_password(char *user, char *nisdomain, char *nismap)
94439e4e 44{
aee3523a
AR
45 static char *val = nullptr;
46 char *password = nullptr;
94439e4e 47 int vallen, res;
48
49#ifdef DEBUG
50 printf("Domain is set to %s\n", nisdomain);
51 printf("YP Map is set to %s\n", nismap);
52#endif
53
686e91cd 54 /* Free last entry */
55 if (val) {
26ac0430 56 free(val);
aee3523a 57 val = nullptr;
686e91cd 58 }
59
94439e4e 60 /* Get NIS entry */
61 res = yp_match(nisdomain, nismap, user, strlen(user), &val, &vallen);
62
63 switch (res) {
64 case NO_YPERR:
26ac0430
AJ
65 /* username = */
66 (void) strtok(val, ":");
aee3523a 67 password = strtok(nullptr, ",:");
26ac0430 68 return password;
94439e4e 69 case YPERR_YPBIND:
26ac0430 70 syslog(LOG_ERR, "Squid Authentication through ypbind failure: can't communicate with ypbind");
aee3523a 71 return nullptr;
f53969cc 72 case YPERR_KEY: /* No such key in map */
aee3523a 73 return nullptr;
94439e4e 74 default:
aee3523a 75 return nullptr;
94439e4e 76 }
94439e4e 77}
f53969cc 78