1 | /*
|
---|
2 | Unix SMB/Netbios implementation.
|
---|
3 | NTLMSSP ndr functions
|
---|
4 |
|
---|
5 | Copyright (C) Guenther Deschner 2009
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 3 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "includes.h"
|
---|
22 | #include "../librpc/gen_ndr/ndr_ntlmssp.h"
|
---|
23 | #include "../libcli/auth/ntlmssp_ndr.h"
|
---|
24 |
|
---|
25 | #define NTLMSSP_PULL_MESSAGE(type, blob, mem_ctx, r) \
|
---|
26 | do { \
|
---|
27 | enum ndr_err_code __ndr_err; \
|
---|
28 | __ndr_err = ndr_pull_struct_blob(blob, mem_ctx, r, \
|
---|
29 | (ndr_pull_flags_fn_t)ndr_pull_ ##type); \
|
---|
30 | if (!NDR_ERR_CODE_IS_SUCCESS(__ndr_err)) { \
|
---|
31 | return ndr_map_error2ntstatus(__ndr_err); \
|
---|
32 | } \
|
---|
33 | if (memcmp(r->Signature, "NTLMSSP\0", 8)) {\
|
---|
34 | return NT_STATUS_INVALID_PARAMETER; \
|
---|
35 | } \
|
---|
36 | return NT_STATUS_OK; \
|
---|
37 | } while(0);
|
---|
38 |
|
---|
39 | #define NTLMSSP_PUSH_MESSAGE(type, blob, mem_ctx, r) \
|
---|
40 | do { \
|
---|
41 | enum ndr_err_code __ndr_err; \
|
---|
42 | __ndr_err = ndr_push_struct_blob(blob, mem_ctx, r, \
|
---|
43 | (ndr_push_flags_fn_t)ndr_push_ ##type); \
|
---|
44 | if (!NDR_ERR_CODE_IS_SUCCESS(__ndr_err)) { \
|
---|
45 | return ndr_map_error2ntstatus(__ndr_err); \
|
---|
46 | } \
|
---|
47 | return NT_STATUS_OK; \
|
---|
48 | } while(0);
|
---|
49 |
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Pull NTLMSSP NEGOTIATE_MESSAGE struct from a blob
|
---|
53 | * @param blob The plain packet blob
|
---|
54 | * @param mem_ctx A talloc context
|
---|
55 | * @param r Pointer to a NTLMSSP NEGOTIATE_MESSAGE structure
|
---|
56 | */
|
---|
57 |
|
---|
58 | NTSTATUS ntlmssp_pull_NEGOTIATE_MESSAGE(const DATA_BLOB *blob,
|
---|
59 | TALLOC_CTX *mem_ctx,
|
---|
60 | struct NEGOTIATE_MESSAGE *r)
|
---|
61 | {
|
---|
62 | NTLMSSP_PULL_MESSAGE(NEGOTIATE_MESSAGE, blob, mem_ctx, r);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Pull NTLMSSP CHALLENGE_MESSAGE struct from a blob
|
---|
67 | * @param blob The plain packet blob
|
---|
68 | * @param mem_ctx A talloc context
|
---|
69 | * @param r Pointer to a NTLMSSP CHALLENGE_MESSAGE structure
|
---|
70 | */
|
---|
71 |
|
---|
72 | NTSTATUS ntlmssp_pull_CHALLENGE_MESSAGE(const DATA_BLOB *blob,
|
---|
73 | TALLOC_CTX *mem_ctx,
|
---|
74 | struct CHALLENGE_MESSAGE *r)
|
---|
75 | {
|
---|
76 | NTLMSSP_PULL_MESSAGE(CHALLENGE_MESSAGE, blob, mem_ctx, r);
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Pull NTLMSSP AUTHENTICATE_MESSAGE struct from a blob
|
---|
81 | * @param blob The plain packet blob
|
---|
82 | * @param mem_ctx A talloc context
|
---|
83 | * @param r Pointer to a NTLMSSP AUTHENTICATE_MESSAGE structure
|
---|
84 | */
|
---|
85 |
|
---|
86 | NTSTATUS ntlmssp_pull_AUTHENTICATE_MESSAGE(const DATA_BLOB *blob,
|
---|
87 | TALLOC_CTX *mem_ctx,
|
---|
88 | struct AUTHENTICATE_MESSAGE *r)
|
---|
89 | {
|
---|
90 | NTLMSSP_PULL_MESSAGE(AUTHENTICATE_MESSAGE, blob, mem_ctx, r);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Push NTLMSSP NEGOTIATE_MESSAGE struct into a blob
|
---|
95 | * @param blob The plain packet blob
|
---|
96 | * @param mem_ctx A talloc context
|
---|
97 | * @param r Pointer to a NTLMSSP NEGOTIATE_MESSAGE structure
|
---|
98 | */
|
---|
99 |
|
---|
100 | NTSTATUS ntlmssp_push_NEGOTIATE_MESSAGE(DATA_BLOB *blob,
|
---|
101 | TALLOC_CTX *mem_ctx,
|
---|
102 | const struct NEGOTIATE_MESSAGE *r)
|
---|
103 | {
|
---|
104 | NTLMSSP_PUSH_MESSAGE(NEGOTIATE_MESSAGE, blob, mem_ctx, r);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Push NTLMSSP CHALLENGE_MESSAGE struct into a blob
|
---|
109 | * @param blob The plain packet blob
|
---|
110 | * @param mem_ctx A talloc context
|
---|
111 | * @param r Pointer to a NTLMSSP CHALLENGE_MESSAGE structure
|
---|
112 | */
|
---|
113 |
|
---|
114 | NTSTATUS ntlmssp_push_CHALLENGE_MESSAGE(DATA_BLOB *blob,
|
---|
115 | TALLOC_CTX *mem_ctx,
|
---|
116 | const struct CHALLENGE_MESSAGE *r)
|
---|
117 | {
|
---|
118 | NTLMSSP_PUSH_MESSAGE(CHALLENGE_MESSAGE, blob, mem_ctx, r);
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Push NTLMSSP AUTHENTICATE_MESSAGE struct into a blob
|
---|
123 | * @param blob The plain packet blob
|
---|
124 | * @param mem_ctx A talloc context
|
---|
125 | * @param r Pointer to a NTLMSSP AUTHENTICATE_MESSAGE structure
|
---|
126 | */
|
---|
127 |
|
---|
128 | NTSTATUS ntlmssp_push_AUTHENTICATE_MESSAGE(DATA_BLOB *blob,
|
---|
129 | TALLOC_CTX *mem_ctx,
|
---|
130 | const struct AUTHENTICATE_MESSAGE *r)
|
---|
131 | {
|
---|
132 | NTLMSSP_PUSH_MESSAGE(AUTHENTICATE_MESSAGE, blob, mem_ctx, r);
|
---|
133 | }
|
---|