1 Index: squid/helpers/ntlm_auth/fakeauth/fakeauth_auth.c
2 diff -c squid/helpers/ntlm_auth/fakeauth/fakeauth_auth.c:1.3.2.1 squid/helpers/ntlm_auth/fakeauth/fakeauth_auth.c:1.3.2.7
3 *** squid/helpers/ntlm_auth/fakeauth/fakeauth_auth.c:1.3.2.1 Fri Aug 20 02:09:58 2004
4 --- squid/helpers/ntlm_auth/fakeauth/fakeauth_auth.c Fri Jan 7 14:12:27 2005
16 #define NTLM_STATIC_CHALLENGE "deadbeef"
26 #define NTLM_STATIC_CHALLENGE "deadbeef"
32 ! char *p = string, c;
49 * Generates a challenge request. The randomness of the 8 byte
50 ! * challenge strings can be guarenteed to be poor at best.
53 ntlmMakeChallenge(struct ntlm_challenge *chal)
57 * Generates a challenge request. The randomness of the 8 byte
58 ! * challenge strings can be guaranteed to be poor at best.
61 ntlmMakeChallenge(struct ntlm_challenge *chal)
64 if (authenticate_ntlm_domain != NULL)
65 while (authenticate_ntlm_domain[i++]);
68 chal->target.offset = WSWAP(48);
69 chal->target.maxlen = SSWAP(i);
70 chal->target.len = chal->target.maxlen;
77 ! * Check the vailidity of a request header. Return -1 on error.
80 ntlmCheckHeader(ntlmhdr * hdr, int type)
85 ! * Check the validity of a request header. Return -1 on error.
88 ntlmCheckHeader(ntlmhdr * hdr, int type)
93 if (WSWAP(hdr->type) != type) {
94 ! /* don't report this error - it's ok as we do a if() around this function */
95 ! // fprintf(stderr, "ntlmCheckHeader: type is %d, wanted %d\n",
96 ! // WSWAP(hdr->type), type);
103 if (WSWAP(hdr->type) != type) {
104 ! /* don't report this error - it's ok as we do a if() around this function */
105 ! /* fprintf(stderr, "ntlmCheckHeader: type is %d, wanted %d\n", WSWAP(hdr->type), type); */
111 ntlmGetString(ntlmhdr * hdr, strhdr * str, int flags)
113 static char buf[512];
119 o = WSWAP(str->offset);
121 ntlmGetString(ntlmhdr * hdr, strhdr * str, int flags)
123 static char buf[512];
132 o = WSWAP(str->offset);
136 ntlmDecodeAuth(struct ntlm_authenticate *auth, char *buf, size_t size)
145 ! if (ntlmCheckHeader(&auth->hdr, NTLM_AUTHENTICATE)) {
147 - fprintf(stderr, "ntlmDecodeAuth: header check fails\n");
150 - /* only on when you need to debug
151 - * fprintf(stderr,"ntlmDecodeAuth: size of %d\n", size);
152 - * fprintf(stderr,"ntlmDecodeAuth: flg %08x\n", auth->flags);
153 - * fprintf(stderr,"ntlmDecodeAuth: usr o(%d) l(%d)\n", auth->user.offset, auth->user.len);
155 if ((p = ntlmGetString(&auth->hdr, &auth->domain, 2)) == NULL)
156 p = authenticate_ntlm_domain;
157 ! // fprintf(stderr,"ntlmDecodeAuth: Domain '%s'.\n",p);
158 if ((s = strlen(p) + 1) >= size)
161 ! // fprintf(stdout,"ntlmDecodeAuth: Domain '%s'.\n",buf);
165 *buf++ = '\\'; /* Using \ is more consistent with MS-proxy */
167 p = ntlmGetString(&auth->hdr, &auth->user, 2);
168 if ((s = strlen(p) + 1) >= size)
171 ! *buf++ = (*p++); //tolower
175 ! // fprintf(stderr, "ntlmDecodeAuth: user: %s%s\n",origbuf, p);
186 ! char user[256], *p, *cleartext;
187 struct ntlm_challenge chal;
191 setbuf(stdout, NULL);
192 while (fgets(buf, 256, stdin) != NULL) {
193 ! user[0] = '\0'; /*no usercode */
195 if ((p = strchr(buf, '\n')) != NULL)
196 *p = '\0'; /* strip \n */
199 ntlmDecodeAuth(struct ntlm_authenticate *auth, char *buf, size_t size)
208 ! assert (0 == ntlmCheckHeader(&auth->hdr, NTLM_AUTHENTICATE));
211 ! fprintf(stderr,"ntlmDecodeAuth: size of %d\n", size);
212 ! fprintf(stderr,"ntlmDecodeAuth: flg %08x\n", auth->flags);
213 ! fprintf(stderr,"ntlmDecodeAuth: usr o(%d) l(%d)\n", auth->user.offset,
217 if ((p = ntlmGetString(&auth->hdr, &auth->domain, 2)) == NULL)
218 p = authenticate_ntlm_domain;
220 ! fprintf(stderr,"ntlmDecodeAuth: Domain '%s'.\n",p);
222 if ((s = strlen(p) + 1) >= size)
226 ! fprintf(stdout,"ntlmDecodeAuth: Domain '%s'.\n",buf);
231 *buf++ = '\\'; /* Using \ is more consistent with MS-proxy */
233 p = ntlmGetString(&auth->hdr, &auth->user, 2);
236 if ((s = strlen(p) + 1) >= size)
239 ! *buf++ = (*p++); /* tolower */
244 ! fprintf(stderr, "ntlmDecodeAuth: user: %s%s\n",origbuf, p);
252 ! main(int argc, char *argv[])
257 ! char *cleartext = NULL;
258 struct ntlm_challenge chal;
262 setbuf(stdout, NULL);
263 while (fgets(buf, 256, stdin) != NULL) {
264 ! memset(user, '\0', sizeof(user)); /* no usercode */
266 if ((p = strchr(buf, '\n')) != NULL)
267 *p = '\0'; /* strip \n */
270 printf("AF %s\n", user);
273 ! printf("NA invalid credentials%s\n", user);
277 ! printf("BH wrong packet type!%s\n", user);
282 printf("AF %s\n", user);
285 ! printf("NA invalid credentials, user=%s\n", user);
289 ! printf("BH wrong packet type! user=%s\n", user);
295 SSWAP(chal.target.maxlen);
296 data = (char *) base64_encode_bin((char *) &chal, len);
297 printf("CH %s\n", data);
298 ! } else if (!ntlmCheckHeader
299 ! ((struct ntlmhdr *) cleartext, NTLM_AUTHENTICATE)) {
300 ! if (!ntlmDecodeAuth
301 ! ((struct ntlm_authenticate *) cleartext, user, 256)) {
303 printf("OK %s\n", user);
306 SSWAP(chal.target.maxlen);
307 data = (char *) base64_encode_bin((char *) &chal, len);
308 printf("CH %s\n", data);
309 ! } else if (!ntlmCheckHeader ((struct ntlmhdr *) cleartext, NTLM_AUTHENTICATE)) {
310 ! if (!ntlmDecodeAuth ((struct ntlm_authenticate *) cleartext, user, 256)) {
312 printf("OK %s\n", user);