34#define IGNORANCE_IS_BLISS
57#define SEND(X) {debug("sending '%s' to squid\n",X); printf(X "\n");}
59#define SEND2(X,Y...) {debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);}
60#define SEND3(X,Y...) {debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);}
61#define SEND4(X,Y...) {debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);}
64#define SEND2(X,Y) {debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);}
65#define SEND3(X,Y,Z) {debug("sending '" X "' to squid\n",Y,Z); printf(X "\n",Y,Z);}
66#define SEND4(X,Y,Z,W) {debug("sending '" X "' to squid\n",Y,Z,W); printf(X "\n",Y,Z,W);}
86 "Usage: %s [-d] [-t N] [-v] [-h]\n"
87 " -d enable debugging.\n"
88 " -S strip domain from username.\n"
89 " -t timeout to delay responses (milliseconds).\n"
90 " -v enable verbose NTLM packet debugging.\n"
91 " -h this message\n\n",
98 int opt, had_error = 0;
101 while (-1 != (opt =
getopt(argc, argv,
"hdvSt:"))) {
115 fprintf(stderr,
"ERROR: invalid parameter value for -t '%s'",
optarg);
127 fprintf(stderr,
"unknown option: -%c. Exiting\n", opt);
145 char helper_command[3];
148 setbuf(stdout,
nullptr);
149 setbuf(stderr,
nullptr);
161 if ((p = strchr(buf,
'\n')) !=
nullptr)
163 buflen = strlen(buf);
179 strncpy(helper_command, buf, 2);
180 helper_command[2] =
'\0';
181 debug(
"Got '%s' from Squid with data:\n", helper_command);
182 hex_dump((
unsigned char *)decodedBuf, decodedLen);
184 debug(
"Got '%s' from Squid\n", buf);
187 std::this_thread::sleep_for(std::chrono::milliseconds(
response_delay));
190 if (strncmp(buf,
"YR", 2) == 0) {
194 if (buflen > 3 && packet) {
211 printf(
"TT %.*s\n", (
int)blen, data);
212 debug(
"sending 'TT' to squid with data:\n");
213 hex_dump((
unsigned char *)&chal, len);
215 SEND3(
"TT %.*s", (
int)blen, data);
218 }
else if (strncmp(buf,
"KK ", 3) == 0) {
220 SEND(
"BH received KK with no data! user=");
225 SEND2(
"AF %s", user);
227 SEND4(
"AF %s%s%s", domain, (*domain?
"\\":
""), user);
231 SEND4(
"NA invalid credentials, user=%s%s%s", domain, (*domain?
"\\":
""), user);
234 SEND(
"BH wrong packet type! user=");
void base64_encode_init(struct base64_encode_ctx *ctx)
size_t base64_encode_update(struct base64_encode_ctx *ctx, char *dst, size_t length, const uint8_t *src)
void base64_decode_init(struct base64_decode_ctx *ctx)
size_t base64_encode_final(struct base64_encode_ctx *ctx, char *dst)
#define base64_encode_len(length)
int base64_decode_update(struct base64_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, const char *src)
int base64_decode_final(struct base64_decode_ctx *ctx)
#define HELPER_INPUT_BUFFER
void debug(const char *format,...)
int getopt(int nargc, char *const *nargv, const char *ostr)
int NTLM_packet_debug_enabled
int main(int argc, char *argv[])
#define SEND4(X, Y, Z, W)
const char * authenticate_ntlm_domain
static void process_options(int argc, char *argv[])
unsigned int response_delay
int ntlm_validate_packet(const ntlmhdr *hdr, const int32_t type)
int ntlm_unpack_auth(const ntlm_authenticate *auth, char *user, char *domain, const int32_t size)
void ntlm_make_challenge(ntlm_challenge *ch, const char *domain, const char *, const char *challenge_nonce, const int challenge_nonce_len, const uint32_t flags)
void ntlm_make_nonce(char *nonce)
#define NTLM_MAX_FIELD_LENGTH
#define NTLM_AUTHENTICATE
#define NTLM_NEGOTIATE_ASCII
void hex_dump(unsigned char *data, int size)
void * xcalloc(size_t n, size_t sz)
bool xstrtoui(const char *s, char **end, unsigned int *value, unsigned int min, unsigned int max)