]> git.ipfire.org Git - thirdparty/squid.git/blob - src/authenticate.cc
fixed helper restart bugs
[thirdparty/squid.git] / src / authenticate.cc
1
2 /*
3 * $Id: authenticate.cc,v 1.6 1998/10/16 20:02:45 wessels 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 * Duane Wessels and the University of California San Diego. Please
16 * see the COPYRIGHT file for full details. Squid incorporates
17 * software developed and/or copyrighted by other sources. Please see
18 * the 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);
55 if ((t = strchr(reply, ' ')))
56 *t = '\0';
57 if (*reply == '\0')
58 reply = NULL;
59 valid = cbdataValid(r->data);
60 cbdataUnlock(r->data);
61 if (valid)
62 r->handler(r->data, reply);
63 authenticateStateFree(r);
64 }
65
66 static void
67 authenticateStateFree(authenticateStateData * r)
68 {
69 cbdataFree(r);
70 }
71
72 static void
73 authenticateStats(StoreEntry * sentry)
74 {
75 storeAppendPrintf(sentry, "Authenticator Statistics:\n");
76 helperStats(sentry, authenticators);
77 }
78
79 /**** PUBLIC FUNCTIONS ****/
80
81
82 void
83 authenticateStart(acl_proxy_auth_user * auth_user, RH * handler, void *data)
84 {
85 authenticateStateData *r = NULL;
86 char buf[8192];
87 assert(auth_user);
88 assert(handler);
89 debug(29, 5) ("authenticateStart: '%s:%s'\n", auth_user->user,
90 auth_user->passwd);
91 if (Config.Program.authenticate == NULL) {
92 handler(data, NULL);
93 return;
94 }
95 r = xcalloc(1, sizeof(authenticateStateData));
96 cbdataAdd(r, MEM_NONE);
97 r->handler = handler;
98 r->data = data;
99 r->auth_user = auth_user;
100 snprintf(buf, 8192, "%s %s\n", r->auth_user->user, r->auth_user->passwd);
101 helperSubmit(authenticators, buf, authenticateHandleReply, r);
102 }
103
104 void
105 authenticateInit(void)
106 {
107 static int init = 0;
108 assert(authenticators == NULL);
109 if (!Config.Program.authenticate)
110 return;
111 authenticators = helperCreate("authenticator");
112 authenticators->cmdline = Config.Program.authenticate;
113 authenticators->n_to_start = Config.authenticateChildren;
114 authenticators->ipc_type = IPC_TCP_SOCKET;
115 helperOpenServers(authenticators);
116 if (!init) {
117 cachemgrRegister("authenticator",
118 "User Authenticator Stats",
119 authenticateStats, 0, 1);
120 }
121 init++;
122 }
123
124 void
125 authenticateShutdown(void)
126 {
127 if (authenticators) {
128 helperShutdown(authenticators);
129 helperFree(authenticators);
130 authenticators = NULL;
131 }
132 }