68 #define SEND(X) debug("sending '%s' to squid\n",X); printf(X "\n");
70 #define SEND2(X,Y...) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
71 #define SEND3(X,Y...) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
74 #define SEND2(X,Y) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
75 #define SEND3(X,Y,Z) debug("sending '" X "' to squid\n",Y,Z); printf(X "\n",Y,Z);
91 "Usage: %s [-d] [-v] [-h]\n"
92 " -d enable debugging.\n"
93 " -v enable verbose Negotiate packet debugging.\n"
94 " -h this message\n\n",
101 int opt, had_error = 0;
104 while (-1 != (opt =
getopt(argc, argv,
"hdv"))) {
120 fprintf(stderr,
"ERROR: unknown option: -%c. Exiting\n", opt);
136 SEND(
"BH base64 decode failed");
137 fprintf(stderr,
"ERROR: base64 decoding failed for: '%s'\n", buf);
148 size_t decodedLen = 0;
149 char helper_command[3];
154 static char cred[SSP_MAX_CRED_LEN + 1];
164 SEND(
"BH illegal request received");
165 fprintf(stderr,
"ERROR: Illegal request received: '%s'\n", buf);
170 fprintf(stderr,
"No newline in '%s'\n", buf);
178 strncpy(helper_command, buf, 2);
179 debug(
"Got '%s' from Squid with data:\n", helper_command);
180 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
182 debug(
"Got '%s' from Squid\n", buf);
184 if (memcmp(buf,
"YR ", 3) == 0) {
186 if (!decodedLen && !
token_decode(&decodedLen, decoded, buf+3))
188 if (decodedLen <
sizeof(
ntlmhdr)) {
189 SEND(
"NA * Packet format error");
195 if (status == SSP_OK) {
203 debug(
"sending 'AF' %s to squid with data:\n", cred);
205 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
207 fprintf(stderr,
"No data available.\n");
208 printf(
"AF %s %s\n", c, cred);
210 SEND3(
"AF %s %s", c, cred);
215 debug(
"sending 'TT' to squid with data:\n");
216 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
217 printf(
"TT %s\n", c);
224 SEND(
"BH can't obtain server blob");
227 if (memcmp(buf,
"KK ", 3) == 0) {
229 SEND(
"BH invalid server blob");
233 if (!decodedLen && !
token_decode(&decodedLen, decoded, buf+3))
235 if (decodedLen <
sizeof(
ntlmhdr)) {
236 SEND(
"NA * Packet format error");
242 if (status == SSP_ERROR) {
243 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
244 FORMAT_MESSAGE_IGNORE_INSERTS,
247 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
248 (LPTSTR) & ErrorMessage,
251 if (ErrorMessage[strlen(ErrorMessage) - 1] ==
'\n')
252 ErrorMessage[strlen(ErrorMessage) - 1] =
'\0';
253 if (ErrorMessage[strlen(ErrorMessage) - 1] ==
'\r')
254 ErrorMessage[strlen(ErrorMessage) - 1] =
'\0';
255 SEND2(
"NA * %s", ErrorMessage);
256 LocalFree(ErrorMessage);
266 debug(
"sending 'AF' %s to squid with data:\n", cred);
268 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
270 fprintf(stderr,
"No data available.\n");
271 printf(
"AF %s %s\n", c, cred);
273 SEND3(
"AF %s %s", c, cred);
280 debug(
"sending 'TT' to squid with data:\n");
281 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
282 printf(
"TT %s\n", c);
289 SEND(
"BH illegal request received");
290 fprintf(stderr,
"Illegal request received: '%s'\n", buf);
293 SEND(
"BH detected protocol error");
308 fprintf(stderr,
"FATAL: %s: can't initialize SSPI, exiting.\n", argv[0]);
311 debug(
"SSPI initialized OK\n");
316 setbuf(stdout,
NULL);
317 setbuf(stderr,
NULL);