140 size_t decodedLen = 0;
141 char helper_command[3];
156 SEND(
"BH illegal request received");
157 fprintf(stderr,
"ERROR: Illegal request received: '%s'\n", buf);
162 fprintf(stderr,
"No newline in '%s'\n", buf);
170 xstrncpy(helper_command, buf,
sizeof(helper_command));
171 debug(
"Got '%s' from Squid with data:\n", helper_command);
172 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
174 debug(
"Got '%s' from Squid\n", buf);
176 if (memcmp(buf,
"YR ", 3) == 0) {
178 if (!decodedLen && !
token_decode(&decodedLen, decoded, buf+3))
180 if (decodedLen <
sizeof(
ntlmhdr)) {
181 SEND(
"NA * Packet format error");
185 c = (
char *) SSP_MakeNegotiateBlob(decoded, decodedLen, &Done, &status, cred);
195 debug(
"sending 'AF' %s to squid with data:\n", cred);
197 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
199 fprintf(stderr,
"No data available.\n");
200 printf(
"AF %s %s\n", c, cred);
202 SEND3(
"AF %s %s", c, cred);
207 debug(
"sending 'TT' to squid with data:\n");
208 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
209 printf(
"TT %s\n", c);
216 SEND(
"BH can't obtain server blob");
219 if (memcmp(buf,
"KK ", 3) == 0) {
221 SEND(
"BH invalid server blob");
225 if (!decodedLen && !
token_decode(&decodedLen, decoded, buf+3))
227 if (decodedLen <
sizeof(
ntlmhdr)) {
228 SEND(
"NA * Packet format error");
232 c = (
char *) SSP_ValidateNegotiateCredentials(decoded, decodedLen, &Done, &status, cred);
235 const auto err = GetLastError();
236 const auto n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
237 FORMAT_MESSAGE_IGNORE_INSERTS,
240 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
241 (LPTSTR) & ErrorMessage,
245 SEND2(
"NA * Windows error: %lu",
static_cast<unsigned long>(err));
248 if (ErrorMessage[strlen(ErrorMessage) - 1] ==
'\n')
249 ErrorMessage[strlen(ErrorMessage) - 1] =
'\0';
250 if (ErrorMessage[strlen(ErrorMessage) - 1] ==
'\r')
251 ErrorMessage[strlen(ErrorMessage) - 1] =
'\0';
252 SEND2(
"NA * %s", ErrorMessage);
253 LocalFree(ErrorMessage);
263 debug(
"sending 'AF' %s to squid with data:\n", cred);
265 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
267 fprintf(stderr,
"No data available.\n");
268 printf(
"AF %s %s\n", c, cred);
270 SEND3(
"AF %s %s", c, cred);
277 debug(
"sending 'TT' to squid with data:\n");
278 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
279 printf(
"TT %s\n", c);
286 SEND(
"BH illegal request received");
287 fprintf(stderr,
"Illegal request received: '%s'\n", buf);
290 SEND(
"BH detected protocol error");