]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/basic/getpwnam/basic_getpwnam_auth.cc
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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.
10 * basic_getpwnam_auth.c
12 * AUTHOR: Erik Hofman <erik.hofman@a1.nl>
13 * Robin Elfrink <robin@a1.nl>
15 * Example authentication program for Squid, based on the
16 * original proxy_auth code from client_side.c, written by
17 * Jon Thackray <jrmt@uk.gdscorp.com>.
19 * Uses getpwnam() routines for authentication.
20 * This has the following advantages over the NCSA module:
22 * - Allow authentication of all know local users
23 * - Allows authentication through nsswitch.conf
24 * + can handle NIS(+) requests
25 * + can handle LDAP request
26 * + can handle PAM request
28 * 2006-07: Giancarlo Razzolini <linux-fan@onda.com.br>
30 * Added functionality for doing shadow authentication too,
31 * using the getspnam() function on systems that support it.
36 #include "helper/protocol_defines.h"
55 passwd_auth(char *user
, char *passwd
)
60 return 0; /* User does not exist */
62 char *crypted
= crypt(passwd
, pwd
->pw_passwd
);
63 if (!crypted
|| strcmp(pwd
->pw_passwd
, crypted
)) {
64 return 2; /* Wrong password */
66 return 1; /* Authentication Sucessful */
73 shadow_auth(char *user
, char *passwd
)
78 return passwd_auth(user
, passwd
); /* Fall back to passwd_auth */
80 char *crypted
= crypt(passwd
, pwd
->sp_pwdp
);
81 if (!crypted
|| strcmp(pwd
->sp_pwdp
, crypted
)) {
82 return 2; /* Wrong password */
84 return 1; /* Authentication Sucessful */
94 char buf
[HELPER_INPUT_BUFFER
];
95 char *user
, *passwd
, *p
;
98 while (fgets(buf
, HELPER_INPUT_BUFFER
, stdin
) != NULL
) {
100 if ((p
= strchr(buf
, '\n')) != NULL
)
101 *p
= '\0'; /* strip \n */
103 if ((user
= strtok(buf
, " ")) == NULL
) {
104 SEND_ERR("No Username");
107 if ((passwd
= strtok(NULL
, "")) == NULL
) {
108 SEND_ERR("No Password");
111 rfc1738_unescape(user
);
112 rfc1738_unescape(passwd
);
114 auth
= shadow_auth(user
, passwd
);
116 auth
= passwd_auth(user
, passwd
);
119 SEND_ERR("No such user");
122 SEND_ERR("Wrong password");