Go to the documentation of this file.
52 #define DEAD_DC_RETRY_INTERVAL 30
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);
76 static void usage(
void);
84 #define ENCODED_PASS_LEN 24
85 #define MAX_USERNAME_LEN 255
86 #define MAX_DOMAIN_LEN 255
87 #define MAX_PASSWD_LEN 31
125 debug(
"Connecting to server %s domain %s\n", domain_controller, domain);
131 debug(
"Couldn't connect to SMB Server. Error:%s\n",
errstr);
135 debug(
"Error negotiating protocol with SMB Server\n");
141 debug(
"SMB Server uses share-level security .. we need user security.\n");
180 debug(
"base64 encoding of the token challenge will exceed %zu bytes",
sizeof(b64buf));
186 size_t blen =
base64_encode_update(&ctx, b64buf, len,
reinterpret_cast<const uint8_t *
>(&chal));
207 debug(
"Weird, we've been disconnected\n");
214 if (tmp.
str ==
NULL || tmp.
l == 0) {
215 debug(
"No domain supplied. Returning no-auth\n");
224 memcpy(domain, tmp.
str, tmp.
l);
225 user = domain + tmp.
l;
231 if (tmp.
str ==
NULL || tmp.
l == 0) {
232 debug(
"No username supplied. Returning no-auth\n");
241 memcpy(user, tmp.
str, tmp.
l);
242 *(user + tmp.
l) =
'\0';
253 debug(
"LM response: insane data (pkt-sz: %d, fetch len: %d, offset: %d)\n", auth_length, len, offset);
257 tmp.
str = (
char *)packet + offset;
267 memcpy(pass, tmp.
str, tmp.
l);
270 debug(
"Empty LM pass detection: user: '%s', ours:'%s', his: '%s' (length: %d)\n",
273 fprintf(stderr,
"Empty LM password supplied for user %s\\%s. "
274 "No-auth\n",domain,user);
288 debug(
"NT response: insane data (pkt-sz: %d, fetch len: %d, offset: %d)\n", auth_length, len, offset);
292 tmp.
str = (
char *)packet + offset;
295 debug(
"Empty NT pass detection: user: '%s', ours:'%s', his: '%s' (length: %d)\n",
298 fprintf(stderr,
"ERROR: Empty NT password supplied for user %s\\%s. No-auth\n", domain, user);
305 debug(
"checking domain: '%s', user: '%s', pass='%s'\n", domain, user, pass);
308 debug(
"Login attempt had result %d\n", rv);
370 "%s usage:\n%s [-b] [-f] [-d] [-l] domain\\controller [domain\\controller ...]\n"
371 "-b enables load-balancing among controllers\n"
372 "-f enables failover among controllers (DEPRECATED and always active)\n"
373 "-d enables debugging statements if DEBUG was defined at build-time.\n\n"
374 "You MUST specify at least one Domain Controller.\n"
375 "You can use either \\ or / as separator between the domain name \n"
376 "and the controller name\n",
385 int opt, j, had_error = 0;
386 dc *new_dc =
nullptr, *last_dc =
nullptr;
387 while (-1 != (opt =
getopt(argc, argv,
"bfld"))) {
394 "WARNING. The -f flag is DEPRECATED and always active.\n");
400 fprintf(stderr,
"unknown option: -%c. Exiting\n", opt);
409 for (j =
optind; j < argc; ++j) {
413 d =
static_cast<char*
>(
xmalloc(strlen(argv[j]) + 1));
415 debug(
"Adding domain-controller %s\n", d);
416 if (
NULL == (c = strchr(d,
'\\')) &&
NULL == (c = strchr(d,
'/'))) {
417 fprintf(stderr,
"Couldn't grok domain-controller %s\n", d);
422 if (
NULL != strchr(c + 1,
'\\') ||
NULL != strchr(c + 1,
'/')) {
423 fprintf(stderr,
"Broken domain-controller %s\n", d);
431 fprintf(stderr,
"Malloc error while parsing DC options\n");
446 last_dc->
next = new_dc;
451 fprintf(stderr,
"You must specify at least one domain-controller!\n");
466 const char *ch =
nullptr;
468 debug(
"obtain_challenge: selecting %s\\%s (attempt #%d)\n",
473 debug(
"Reviving DC\n");
476 debug(
"Skipping it\n");
481 debug(
"attempting challenge retrieval\n");
483 debug(
"make_challenge retuned %p\n", ch);
489 debug(
"Marking DC as DEAD\n");
492 debug(
"moving on to next controller\n");
505 char *ch2, *cred =
nullptr;
508 fprintf(stderr,
"fgets() failed! dying..... errno=%d (%s)\n", errno,
512 debug(
"managing request\n");
517 debug(
"ntlm authenticator. Got '%s' from Squid\n", buf);
519 if (memcmp(buf,
"KK ", 3) == 0) {
525 if (!
base64_decode_update(&ctx, &dstLen,
reinterpret_cast<uint8_t*
>(decoded), strlen(buf)-3, buf+3) ||
527 SEND(
"NA Packet format error, couldn't base64-decode");
532 if ((
size_t)decodedLen <
sizeof(
ntlmhdr)) {
533 SEND(
"NA Packet format error, truncated packet header.");
537 fast_header = (
ntlmhdr *) decoded;
541 SEND(
"NA Broken authentication packet");
546 SEND(
"NA Invalid negotiation request received");
550 SEND(
"NA Got a challenge. We refuse to have our authority disputed");
559 signal(SIGALRM, SIG_DFL);
561 fprintf(stderr,
"ntlm-auth[%ld]: Timeout during authentication.\n", (
long)getpid());
562 SEND(
"BH Timeout during authentication");
567 int smblib_err, smb_errorclass, smb_errorcode, nb_error;
569 SEND(
"NA Logon Failure");
580 debug(
"No creds. SMBlib error %d, SMB error class %d, SMB error code %d, NB error %d\n",
581 smblib_err, smb_errorclass, smb_errorcode, nb_error);
585 SEND(
"BH NetBios error!");
586 fprintf(stderr,
"NetBios error code %d (%s)\n", nb_error,
590 switch (smb_errorclass) {
592 debug(
"Huh? Got a SMB success code but could check auth..");
593 SEND(
"NA Authentication failed");
597 debug(
"DOS error\n");
598 switch (smb_errorcode) {
602 SEND(
"NA Access denied");
605 SEND(
"NA bad format in authentication packet");
608 SEND(
"NA Bad access request");
614 SEND(
"BH DOS Error");
618 debug(
"Server error");
619 switch (smb_errorcode) {
622 SEND(
"NA Bad password");
625 SEND(
"NA Server access error");
628 SEND(
"BH Server Error");
632 SEND(
"BH Domain Controller Hardware error");
635 SEND(
"BH Domain Controller Command Error");
638 SEND(
"BH unknown internal error.");
643 SEND2(
"AF %s", cred);
646 SEND(
"BH unknown authentication packet type");
652 if (memcmp(buf,
"YR", 2) == 0) {
664 SEND(
"BH Helper detected protocol error");
673 debug(
"%s " VERSION " " SQUID_BUILD_INFO
" starting up...\n", argv[0]);
678 debug(
"options processed OK\n");
681 setbuf(stdout,
nullptr);
682 setbuf(stderr,
nullptr);
688 pid_t
pid = getpid();
690 debug(
"load balancing. Selected controller #%d\n", n);
#define SMBlibE_NoSuchMsg
static const char * make_challenge(char *domain, char *controller)
int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle)
static char my_domain[100]
#define SMBlibE_NegNoProt
#define base64_encode_len(length)
void debug(const char *format,...)
void base64_decode_init(struct base64_decode_ctx *ctx)
#define NTLM_BLOB_BUFFER_SIZE
#define NTLM_NEGOTIATE_ALWAYS_SIGN
size_t base64_encode_final(struct base64_encode_ctx *ctx, char *dst)
static char * ntlm_check_auth(ntlm_authenticate *auth, int auth_length)
char smb_error_buffer[1000]
static const char * obtain_challenge(void)
#define SMBlibE_LowerLayer
static void process_options(int argc, char *argv[])
static void dc_disconnect(void)
int getopt(int nargc, char *const *nargv, const char *ostr)
#define NTLM_NEGOTIATE_ASCII
#define SMBlibE_GuestOnly
#define SMBlibE_CallFailed
int main(int argc, char *argv[])
#define DEAD_DC_RETRY_INTERVAL
#define NTLM_NEGOTIATE_USE_NTLM
int base64_decode_final(struct base64_decode_ctx *ctx)
static unsigned char lmencoded_empty_pass[ENCODED_PASS_LEN]
#define NTLM_AUTHENTICATE
#define SMBlib_Error_Class(p)
int SMB_Get_Last_SMB_Err()
void SMB_Get_Error_Msg(int msg, char *msgbuf, int len)
int base64_decode_update(struct base64_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, const char *src)
#define NTLM_NEGOTIATE_USE_LM
void base64_encode_init(struct base64_encode_ctx *ctx)
static unsigned char ntencoded_empty_pass[ENCODED_PASS_LEN]
static void manage_request(void)
static int init_challenge(char *domain, char *domain_controller)
const char * RFCNB_Error_Strings[]
int RFCNB_Get_Last_Error(void)
#define HELPER_INPUT_BUFFER
#define SMBlibE_ProtUnknown
SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle, const char *server, const char *NTdomain)
void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
void timeout_during_auth(int)
static char credentials[MAX_USERNAME_LEN+MAX_DOMAIN_LEN+2]
static NtlmError ntlm_errno
int SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, char *PassWord, const char *NtDomain, int PreCrypted)
size_t base64_encode_update(struct base64_encode_ctx *ctx, char *dst, size_t length, const uint8_t *src)
#define SMBlibE_SendFailed
NtlmError ntlm_validate_packet(const ntlmhdr *hdr, const int32_t type)
void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24)
lstring ntlm_fetch_string(const ntlmhdr *packet, const int32_t packet_size, const strhdr *str, const uint32_t flags)
int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[])
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)
static char my_domain_controller[100]
const A & min(A const &lhs, A const &rhs)
#define NTLM_CHALLENGE_TARGET_IS_DOMAIN
#define SMBlib_Error_Code(p)
#define NTLM_REQUEST_NON_NT_SESSION_KEY
#define SMBlibE_RecvFailed
static unsigned char challenge[NTLM_NONCE_LEN]