2
* smb_auth - SMB proxy authentication module
3
* Copyright (C) 1998 Richard Huveneers <richard@hekkihek.hacom.nl>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* SQUID Web Proxy Cache http://www.squid-cache.org/
18
* ----------------------------------------------------------
20
* Squid is the result of efforts by numerous individuals from
21
* the Internet community; see the CONTRIBUTORS file for full
22
* details. Many organizations have provided support for Squid's
23
* development; see the SPONSORS file for full details. Squid is
24
* Copyrighted (C) 2001 by the Regents of the University of
25
* California; see the COPYRIGHT file for full details. Squid
26
* incorporates software developed and/or copyrighted by other
27
* sources; see the CREDITS file for full details.
29
* This program is free software; you can redistribute it and/or modify
30
* it under the terms of the GNU General Public License as published by
31
* the Free Software Foundation; either version 2 of the License, or
32
* (at your option) any later version.
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37
* GNU General Public License for more details.
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
52
#define NMB_BROADCAST 2
55
char *name; /* domain name */
56
char *sname; /* match this with user input */
57
char *passthrough; /* pass-through authentication */
58
char *nmbaddr; /* name service address */
59
int nmbcast; /* broadcast or unicast */
60
char *authshare; /* share name of auth file */
61
char *authfile; /* pathname of auth file */
62
struct SMBDOMAIN *next; /* linked list */
65
struct SMBDOMAIN *firstdom = NULL;
66
struct SMBDOMAIN *lastdom = NULL;
69
* escape the backslash character, since it has a special meaning
70
* to the read command of the bourne shell.
74
print_esc(FILE * p, char *s)
80
for (t = s; *t != '\0'; t++) {
99
main(int argc, char *argv[])
103
struct SMBDOMAIN *dom;
112
/* make standard output line buffered */
113
if (setvbuf(stdout, NULL, _IOLBF, 0) != 0)
116
/* parse command line arguments */
117
for (i = 1; i < argc; i++) {
118
if (strcmp(argv[i], "-d") == 0) {
122
/* the next options require an argument */
126
if (strcmp(argv[i], "-W") == 0) {
127
if ((dom = (struct SMBDOMAIN *) malloc(sizeof(struct SMBDOMAIN))) == NULL)
130
dom->name = dom->sname = argv[++i];
131
dom->passthrough = "";
133
dom->nmbcast = NMB_BROADCAST;
134
dom->authshare = "NETLOGON";
135
dom->authfile = "proxyauth";
138
/* append to linked list */
147
if (strcmp(argv[i], "-w") == 0) {
149
lastdom->sname = argv[++i];
152
if (strcmp(argv[i], "-P") == 0) {
154
lastdom->passthrough = argv[++i];
157
if (strcmp(argv[i], "-B") == 0) {
158
if (lastdom != NULL) {
159
lastdom->nmbaddr = argv[++i];
160
lastdom->nmbcast = NMB_BROADCAST;
164
if (strcmp(argv[i], "-U") == 0) {
165
if (lastdom != NULL) {
166
lastdom->nmbaddr = argv[++i];
167
lastdom->nmbcast = NMB_UNICAST;
171
if (strcmp(argv[i], "-S") == 0) {
172
if (lastdom != NULL) {
173
if ((lastdom->authshare = strdup(argv[++i])) == NULL)
176
/* convert backslashes to forward slashes */
177
for (s = lastdom->authshare; *s != '\0'; s++)
181
/* strip leading forward slash from share name */
182
if (*lastdom->authshare == '/')
183
lastdom->authshare++;
185
if ((s = strchr(lastdom->authshare, '/')) != NULL) {
187
lastdom->authfile = s + 1;
194
shcmd = debug ? HELPERSCRIPT : HELPERSCRIPT " > /dev/null 2>&1";
196
/* pass to helper script */
197
if (putenv("SAMBAPREFIX=" SAMBAPREFIX) != 0)
201
if (fgets(buf, BUFSIZE, stdin) == NULL)
204
if ((s = strchr(buf, '\n')) == NULL)
208
if ((s = strchr(buf, ' ')) == NULL) {
209
(void) printf("ERR\n");
218
rfc1738_unescape(user);
219
rfc1738_unescape(pass);
221
if ((s = strchr(user, '\\')) != NULL) {
226
/* match domname with linked list */
227
if (domname != NULL && strlen(domname) > 0) {
228
for (dom = firstdom; dom != NULL; dom = dom->next)
229
if (strcasecmp(dom->sname, domname) == 0)
235
(void) printf("ERR\n");
238
if ((p = popen(shcmd, "w")) == NULL) {
239
(void) printf("ERR\n");
242
(void) fprintf(p, "%s\n", dom->name);
243
(void) fprintf(p, "%s\n", dom->passthrough);
244
(void) fprintf(p, "%s\n", dom->nmbaddr);
245
(void) fprintf(p, "%d\n", dom->nmbcast);
246
(void) fprintf(p, "%s\n", dom->authshare);
247
(void) fprintf(p, "%s\n", dom->authfile);
248
(void) fprintf(p, "%s\n", user);
249
/* the password can contain special characters */
251
(void) fputc('\n', p);
255
(void) printf("OK\n");
257
(void) printf("ERR\n");