]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/basic/SMB/basic_smb_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_smb_auth - SMB proxy authentication module
11 * Copyright (C) 1998 Richard Huveneers <richard@hekkihek.hacom.nl>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
28 #include "helper/protocol_defines.h"
35 #define NMB_BROADCAST 2
38 const char *name
; /* domain name */
39 const char *sname
; /* match this with user input */
40 const char *passthrough
; /* pass-through authentication */
41 const char *nmbaddr
; /* name service address */
42 int nmbcast
; /* broadcast or unicast */
43 char *authshare
; /* share name of auth file */
44 const char *authfile
; /* pathname of auth file */
45 struct SMBDOMAIN
*next
; /* linked list */
48 struct SMBDOMAIN
*firstdom
= NULL
;
49 struct SMBDOMAIN
*lastdom
= NULL
;
52 * escape the backslash character, since it has a special meaning
53 * to the read command of the bourne shell.
57 print_esc(FILE * p
, char *s
)
59 char buf
[HELPER_INPUT_BUFFER
];
63 for (t
= s
; *t
!= '\0'; ++t
) {
65 * NP: The shell escaping permits 'i' to jump up to 2 octets per loop,
66 * so ensure we have at least 3 free.
68 if (i
> HELPER_INPUT_BUFFER
-3) {
87 main(int argc
, char *argv
[])
90 char buf
[HELPER_INPUT_BUFFER
];
91 struct SMBDOMAIN
*dom
;
99 /* make standard output line buffered */
100 if (setvbuf(stdout
, NULL
, _IOLBF
, 0) != 0)
103 /* parse command line arguments */
104 for (i
= 1; i
< argc
; ++i
) {
105 if (strcmp(argv
[i
], "-d") == 0) {
109 /* the next options require an argument */
113 if (strcmp(argv
[i
], "-W") == 0) {
114 dom
= static_cast<struct SMBDOMAIN
*>(xmalloc(sizeof(struct SMBDOMAIN
)));
116 dom
->name
= dom
->sname
= argv
[++i
];
117 dom
->passthrough
= "";
119 dom
->nmbcast
= NMB_BROADCAST
;
120 dom
->authshare
= (char *)"NETLOGON";
121 dom
->authfile
= "proxyauth";
124 /* append to linked list */
133 if (strcmp(argv
[i
], "-w") == 0) {
135 lastdom
->sname
= argv
[++i
];
138 if (strcmp(argv
[i
], "-P") == 0) {
140 lastdom
->passthrough
= argv
[++i
];
143 if (strcmp(argv
[i
], "-B") == 0) {
144 if (lastdom
!= NULL
) {
145 lastdom
->nmbaddr
= argv
[++i
];
146 lastdom
->nmbcast
= NMB_BROADCAST
;
150 if (strcmp(argv
[i
], "-U") == 0) {
151 if (lastdom
!= NULL
) {
152 lastdom
->nmbaddr
= argv
[++i
];
153 lastdom
->nmbcast
= NMB_UNICAST
;
157 if (strcmp(argv
[i
], "-S") == 0) {
158 if (lastdom
!= NULL
) {
159 if ((lastdom
->authshare
= xstrdup(argv
[++i
])) == NULL
)
162 /* convert backslashes to forward slashes */
163 for (s
= lastdom
->authshare
; *s
!= '\0'; ++s
)
167 /* strip leading forward slash from share name */
168 if (*lastdom
->authshare
== '/')
169 ++lastdom
->authshare
;
171 if ((s
= strchr(lastdom
->authshare
, '/')) != NULL
) {
173 lastdom
->authfile
= s
+ 1;
180 shcmd
= debug_enabled
? HELPERSCRIPT
: HELPERSCRIPT
" > /dev/null 2>&1";
182 while (fgets(buf
, HELPER_INPUT_BUFFER
, stdin
) != NULL
) {
184 if ((s
= strchr(buf
, '\n')) == NULL
)
188 if ((s
= strchr(buf
, ' ')) == NULL
) {
198 rfc1738_unescape(user
);
199 rfc1738_unescape(pass
);
201 if ((s
= strchr(user
, '\\')) != NULL
) {
206 /* match domname with linked list */
207 if (domname
!= NULL
&& strlen(domname
) > 0) {
208 for (dom
= firstdom
; dom
!= NULL
; dom
= dom
->next
)
209 if (strcasecmp(dom
->sname
, domname
) == 0)
218 if ((p
= popen(shcmd
, "w")) == NULL
) {
222 (void) fprintf(p
, "%s\n", dom
->name
);
223 (void) fprintf(p
, "%s\n", dom
->passthrough
);
224 (void) fprintf(p
, "%s\n", dom
->nmbaddr
);
225 (void) fprintf(p
, "%d\n", dom
->nmbcast
);
226 (void) fprintf(p
, "%s\n", dom
->authshare
);
227 (void) fprintf(p
, "%s\n", dom
->authfile
);
228 (void) fprintf(p
, "%s\n", user
);
229 /* the password can contain special characters */
231 (void) fputc('\n', p
);