summaryrefslogtreecommitdiff
path: root/daemon/ntlmssp.h
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/ntlmssp.h')
-rw-r--r--daemon/ntlmssp.h140
1 files changed, 140 insertions, 0 deletions
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__ */