/src/samba/auth/ntlmssp/ntlmssp_ndr.c
Line | Count | Source |
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 "ntlmssp_ndr.h" |
24 | | |
25 | 0 | #define NTLMSSP_PULL_MESSAGE(type, blob, mem_ctx, r) \ |
26 | 0 | do { \ |
27 | 0 | enum ndr_err_code __ndr_err; \ |
28 | 0 | ZERO_STRUCTP(r); /* in order to deal with unset neg flags */\ |
29 | 0 | __ndr_err = ndr_pull_struct_blob(blob, mem_ctx, r, \ |
30 | 0 | (ndr_pull_flags_fn_t)ndr_pull_ ##type); \ |
31 | 0 | if (!NDR_ERR_CODE_IS_SUCCESS(__ndr_err)) { \ |
32 | 0 | return ndr_map_error2ntstatus(__ndr_err); \ |
33 | 0 | } \ |
34 | 0 | if (!mem_equal_const_time(r->Signature, "NTLMSSP\0", 8)) { \ |
35 | 0 | return NT_STATUS_INVALID_PARAMETER; \ |
36 | 0 | } \ |
37 | 0 | return NT_STATUS_OK; \ |
38 | 0 | } while(0); |
39 | | |
40 | 0 | #define NTLMSSP_PUSH_MESSAGE(type, blob, mem_ctx, r) \ |
41 | 0 | do { \ |
42 | 0 | enum ndr_err_code __ndr_err; \ |
43 | 0 | __ndr_err = ndr_push_struct_blob(blob, mem_ctx, r, \ |
44 | 0 | (ndr_push_flags_fn_t)ndr_push_ ##type); \ |
45 | 0 | if (!NDR_ERR_CODE_IS_SUCCESS(__ndr_err)) { \ |
46 | 0 | return ndr_map_error2ntstatus(__ndr_err); \ |
47 | 0 | } \ |
48 | 0 | return NT_STATUS_OK; \ |
49 | 0 | } while(0); |
50 | | |
51 | | |
52 | | /** |
53 | | * Pull NTLMSSP NEGOTIATE_MESSAGE struct from a blob |
54 | | * @param blob The plain packet blob |
55 | | * @param mem_ctx A talloc context |
56 | | * @param r Pointer to a NTLMSSP NEGOTIATE_MESSAGE structure |
57 | | */ |
58 | | |
59 | | NTSTATUS ntlmssp_pull_NEGOTIATE_MESSAGE(const DATA_BLOB *blob, |
60 | | TALLOC_CTX *mem_ctx, |
61 | | struct NEGOTIATE_MESSAGE *r) |
62 | 0 | { |
63 | 0 | NTLMSSP_PULL_MESSAGE(NEGOTIATE_MESSAGE, blob, mem_ctx, r); |
64 | 0 | } |
65 | | |
66 | | /** |
67 | | * Pull NTLMSSP CHALLENGE_MESSAGE struct from a blob |
68 | | * @param blob The plain packet blob |
69 | | * @param mem_ctx A talloc context |
70 | | * @param r Pointer to a NTLMSSP CHALLENGE_MESSAGE structure |
71 | | */ |
72 | | |
73 | | NTSTATUS ntlmssp_pull_CHALLENGE_MESSAGE(const DATA_BLOB *blob, |
74 | | TALLOC_CTX *mem_ctx, |
75 | | struct CHALLENGE_MESSAGE *r) |
76 | 0 | { |
77 | 0 | NTLMSSP_PULL_MESSAGE(CHALLENGE_MESSAGE, blob, mem_ctx, r); |
78 | 0 | } |
79 | | |
80 | | /** |
81 | | * Pull NTLMSSP AUTHENTICATE_MESSAGE struct from a blob |
82 | | * @param blob The plain packet blob |
83 | | * @param mem_ctx A talloc context |
84 | | * @param r Pointer to a NTLMSSP AUTHENTICATE_MESSAGE structure |
85 | | */ |
86 | | |
87 | | NTSTATUS ntlmssp_pull_AUTHENTICATE_MESSAGE(const DATA_BLOB *blob, |
88 | | TALLOC_CTX *mem_ctx, |
89 | | struct AUTHENTICATE_MESSAGE *r) |
90 | 0 | { |
91 | 0 | NTLMSSP_PULL_MESSAGE(AUTHENTICATE_MESSAGE, blob, mem_ctx, r); |
92 | 0 | } |
93 | | |
94 | | /** |
95 | | * Push NTLMSSP NEGOTIATE_MESSAGE struct into a blob |
96 | | * @param blob The plain packet blob |
97 | | * @param mem_ctx A talloc context |
98 | | * @param r Pointer to a NTLMSSP NEGOTIATE_MESSAGE structure |
99 | | */ |
100 | | |
101 | | NTSTATUS ntlmssp_push_NEGOTIATE_MESSAGE(DATA_BLOB *blob, |
102 | | TALLOC_CTX *mem_ctx, |
103 | | const struct NEGOTIATE_MESSAGE *r) |
104 | 0 | { |
105 | 0 | NTLMSSP_PUSH_MESSAGE(NEGOTIATE_MESSAGE, blob, mem_ctx, r); |
106 | 0 | } |
107 | | |
108 | | /** |
109 | | * Push NTLMSSP CHALLENGE_MESSAGE struct into a blob |
110 | | * @param blob The plain packet blob |
111 | | * @param mem_ctx A talloc context |
112 | | * @param r Pointer to a NTLMSSP CHALLENGE_MESSAGE structure |
113 | | */ |
114 | | |
115 | | NTSTATUS ntlmssp_push_CHALLENGE_MESSAGE(DATA_BLOB *blob, |
116 | | TALLOC_CTX *mem_ctx, |
117 | | const struct CHALLENGE_MESSAGE *r) |
118 | 0 | { |
119 | 0 | NTLMSSP_PUSH_MESSAGE(CHALLENGE_MESSAGE, blob, mem_ctx, r); |
120 | 0 | } |
121 | | |
122 | | /** |
123 | | * Push NTLMSSP AUTHENTICATE_MESSAGE struct into a blob |
124 | | * @param blob The plain packet blob |
125 | | * @param mem_ctx A talloc context |
126 | | * @param r Pointer to a NTLMSSP AUTHENTICATE_MESSAGE structure |
127 | | */ |
128 | | |
129 | | NTSTATUS ntlmssp_push_AUTHENTICATE_MESSAGE(DATA_BLOB *blob, |
130 | | TALLOC_CTX *mem_ctx, |
131 | | const struct AUTHENTICATE_MESSAGE *r) |
132 | 0 | { |
133 | 0 | NTLMSSP_PUSH_MESSAGE(AUTHENTICATE_MESSAGE, blob, mem_ctx, r); |
134 | 0 | } |