From ff76efc3e5e1b0e4ca3b10b7402406f619509bba Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 21 Apr 2004 17:37:06 +0000 Subject: Initial Import --- daemon/ntlmssp.h | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 daemon/ntlmssp.h (limited to 'daemon/ntlmssp.h') diff --git a/daemon/ntlmssp.h b/daemon/ntlmssp.h new file mode 100644 index 0000000..7654a74 --- /dev/null +++ b/daemon/ntlmssp.h @@ -0,0 +1,140 @@ + +#ifndef __NTLMSSP_H__ +#define __NTLMSSP_H__ + +#define MAX_HOSTLEN 32 +#define MAX_DOMLEN 32 +#define MAX_USERLEN 32 +#define RESP_LEN 24 +#define NONCE_LEN 8 + +/* fhz, 01-10-15 : borrowed from samba code */ +/* NTLMSSP negotiation flags */ +#define NTLMSSP_NEGOTIATE_UNICODE 0x00000001 +#define NTLMSSP_NEGOTIATE_OEM 0x00000002 +#define NTLMSSP_REQUEST_TARGET 0x00000004 +#define NTLMSSP_NEGOTIATE_SIGN 0x00000010 +#define NTLMSSP_NEGOTIATE_SEAL 0x00000020 +#define NTLMSSP_NEGOTIATE_LM_KEY 0x00000080 +#define NTLMSSP_NEGOTIATE_NTLM 0x00000200 +#define NTLMSSP_NEGOTIATE_00001000 0x00001000 +#define NTLMSSP_NEGOTIATE_00002000 0x00002000 +#define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x00008000 +#define NTLMSSP_TARGET_TYPE_DOMAIN 0x00010000 +#define NTLMSSP_TARGET_TYPE_SERVER 0x00020000 +#define NTLMSSP_NEGOTIATE_NTLM2 0x00080000 +#define NTLMSSP_NEGOTIATE_TARGET_INFO 0x00800000 +#define NTLMSSP_NEGOTIATE_128 0x20000000 +#define NTLMSSP_NEGOTIATE_KEY_EXCH 0x40000000 + +#define SMBD_NTLMSSP_NEG_FLAGS 0x000082b1 +#define NTLM_NTLMSSP_NEG_FLAGS 0x00008206 +/* 8201 8207 */ + + + +#define LEN_NTLMSSP_FLAGS 4 +#define OFFSET_MSG1_NTLMSSP_FLAGS 12 + +struct ntlm_msg1 { + unsigned char protocol[8]; + unsigned char type; /* 1 */ + unsigned char zero1[3]; + unsigned char flags[2]; + unsigned char zero2[2]; + + unsigned char dom_len[4]; + unsigned char dom_off[4]; + + unsigned char host_len[4]; + unsigned char host_off[4]; + +#if 0 + unsigned char data[0]; +#endif +} __attribute__((packed)); + +struct ntlm_msg2 { + unsigned char protocol[8]; + unsigned char type; /* 2 */ + unsigned char zero1[7]; + unsigned char msg_len[4]; + unsigned char flags[2]; + unsigned char zero2[2]; + + unsigned char nonce[8]; + unsigned char zero3[8]; +} __attribute__((packed)); + +struct ntlm_msg3 { + unsigned char protocol[8]; + unsigned char type; /* 3 */ + unsigned char zero1[3]; + + unsigned char lm_len[4]; + unsigned char lm_off[4]; + + unsigned char nt_len[4]; + unsigned char nt_off[4]; + + unsigned char dom_len[4]; + unsigned char dom_off[4]; + + unsigned char user_len[4]; + unsigned char user_off[4]; + + unsigned char host_len[4]; + unsigned char host_off[4]; + + unsigned char msg_len[4]; /* Win9x: data begins here! */ + +#if 0 + unsigned char data[0]; +#endif +} __attribute__((packed)); + +struct ntlm_msg2_win9x { + unsigned char protocol[8]; + unsigned char type; /* 2 */ + unsigned char zero1[3]; + unsigned char dom_len1[2]; + unsigned char dom_len2[2]; + unsigned char dom_off[4]; + unsigned char flags[2]; + unsigned char zero2[2]; + + unsigned char nonce[8]; + unsigned char zero3[8]; + unsigned char zero4[4]; + unsigned char msg_len[4]; + unsigned char dom[MAX_DOMLEN]; +} __attribute__((packed)); + +/* size without dom[] : */ +#define NTLM_MSG2_WIN9X_FIXED_SIZE (sizeof(struct ntlm_msg2_win9x)-MAX_DOMLEN) + + +typedef struct ntlmssp_info { + int msg_type; + unsigned char user[MAX_USERLEN + 1]; + unsigned char host[MAX_HOSTLEN + 1]; + unsigned char domain[MAX_DOMLEN + 1]; + unsigned char lm[RESP_LEN]; + unsigned char nt[RESP_LEN]; +} ntlmssp_info_rec; + +int ntlmssp_decode_msg(struct ntlmssp_info *info, unsigned char *raw_msg, unsigned msglen, unsigned *ntlmssp_flags); +int ntlmssp_encode_msg2(unsigned char *nonce, struct ntlm_msg2 *msg); +int ntlmssp_encode_msg2_win9x(unsigned char *nonce, struct ntlm_msg2_win9x *msg,char *domainname,unsigned ntlmssp_flags); + +#define NTV_NO_ERROR 0 +#define NTV_SERVER_ERROR 1 +#define NTV_PROTOCOL_ERROR 2 +#define NTV_LOGON_ERROR 3 + +int ntlmssp_validuser(const char* username, const char* password, const char* server, const char* backup, const char* domain); +void* ntlmssp_connect(const char* server, const char* backup, const char* domain, char* nonce); +int ntlmssp_auth(void* handle, const char* user, const char* password, int flag, char* domain); +void ntlmssp_disconnect(void* handle); + +#endif /* __NTLMSSP_H__ */ -- cgit v1.2.3