]> git.ipfire.org Git - thirdparty/squid.git/blob - src/authenticate.cc
A modified / unified cbdata and mempool implementation. cbdata
[thirdparty/squid.git] / src / authenticate.cc
1
2 /*
3 * $Id: authenticate.cc,v 1.14 2001/01/05 09:51:36 adrian Exp $
4 *
5 * DEBUG: section 29 Authenticator
6 * AUTHOR: Duane Wessels
7 *
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by the
14 * National Science Foundation. Squid is Copyrighted (C) 1998 by
15 * the Regents of the University of California. Please see the
16 * COPYRIGHT file for full details. Squid incorporates software
17 * developed and/or copyrighted by other sources. Please see the
18 * CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36 #include "squid.h"
37
38 typedef struct {
39 void *data;
40 acl_proxy_auth_user *auth_user;
41 RH *handler;
42 } authenticateStateData;
43
44 static HLPCB authenticateHandleReply;
45 static void authenticateStateFree(authenticateStateData * r);
46 static helper *authenticators = NULL;
47
48 static void
49 authenticateHandleReply(void *data, char *reply)
50 {
51 authenticateStateData *r = data;
52 int valid;
53 char *t = NULL;
54 debug(29, 5) ("authenticateHandleReply: {%s}\n", reply ? reply : "<NULL>");
55 if (reply) {
56 if ((t = strchr(reply, ' ')))
57 *t = '\0';
58 if (*reply == '\0')
59 reply = NULL;
60 }
61 valid = cbdataValid(r->data);
62 cbdataUnlock(r->data);
63 if (valid)
64 r->handler(r->data, reply);
65 authenticateStateFree(r);
66 }
67
68 static void
69 authenticateStateFree(authenticateStateData * r)
70 {
71 cbdataFree(r);
72 }
73
74 static void
75 authenticateStats(StoreEntry * sentry)
76 {
77 storeAppendPrintf(sentry, "Authenticator Statistics:\n");
78 helperStats(sentry, authenticators);
79 }
80
81 CBDATA_TYPE(authenticateStateData);
82
83 /**** PUBLIC FUNCTIONS ****/
84
85
86 void
87 authenticateStart(acl_proxy_auth_user * auth_user, RH * handler, void *data)
88 {
89 authenticateStateData *r = NULL;
90 char buf[8192];
91 assert(auth_user);
92 assert(handler);
93 debug(29, 5) ("authenticateStart: '%s:%s'\n", hashKeyStr(&auth_user->hash),
94 auth_user->passwd);
95 if (Config.Program.authenticate == NULL) {
96 handler(data, NULL);
97 return;
98 }
99 r = CBDATA_ALLOC(authenticateStateData, NULL);
100 r->handler = handler;
101 cbdataLock(data);
102 r->data = data;
103 r->auth_user = auth_user;
104 snprintf(buf, 8192, "%s %s\n", hashKeyStr(&r->auth_user->hash),
105 r->auth_user->passwd);
106 helperSubmit(authenticators, buf, authenticateHandleReply, r);
107 }
108
109 void
110 authenticateInit(void)
111 {
112 static int init = 0;
113 if (!Config.Program.authenticate)
114 return;
115 if (authenticators == NULL)
116 authenticators = helperCreate("authenticator");
117 authenticators->cmdline = Config.Program.authenticate;
118 authenticators->n_to_start = Config.authenticateChildren;
119 authenticators->ipc_type = IPC_TCP_SOCKET;
120 helperOpenServers(authenticators);
121 if (!init) {
122 cachemgrRegister("authenticator",
123 "User Authenticator Stats",
124 authenticateStats, 0, 1);
125 init++;
126 }
127 CBDATA_INIT_TYPE(authenticateStateData);
128 }
129
130 void
131 authenticateShutdown(void)
132 {
133 if (!authenticators)
134 return;
135 helperShutdown(authenticators);
136 if (!shutting_down)
137 return;
138 helperFree(authenticators);
139 authenticators = NULL;
140 }