Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Test conversion form struct lsa_TrustDomainInfoAuthInfo to
4 : struct trustAuthInOutBlob and back
5 : Copyright (C) Sumit Bose 2011
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 "torture/proto.h"
23 : #include "librpc/gen_ndr/lsa.h"
24 : #include "libcli/lsarpc/util_lsarpc.h"
25 :
26 0 : static bool cmp_TrustDomainInfoBuffer(struct lsa_TrustDomainInfoBuffer a,
27 : struct lsa_TrustDomainInfoBuffer b)
28 : {
29 0 : if (a.last_update_time != b. last_update_time ||
30 0 : a.AuthType != b.AuthType ||
31 0 : a.data.size != b.data.size ||
32 0 : memcmp(a.data.data, b.data.data, a.data.size) !=0) {
33 0 : return false;
34 : }
35 :
36 0 : return true;
37 : }
38 :
39 0 : static bool cmp_auth_info(struct lsa_TrustDomainInfoAuthInfo *a,
40 : struct lsa_TrustDomainInfoAuthInfo *b)
41 : {
42 : size_t c;
43 :
44 0 : if (a->incoming_count != b->incoming_count ||
45 0 : a->outgoing_count != b->outgoing_count) {
46 0 : return false;
47 : }
48 :
49 0 : for (c = 0; c < a->incoming_count; c++) {
50 0 : if (!cmp_TrustDomainInfoBuffer(a->incoming_current_auth_info[c],
51 0 : b->incoming_current_auth_info[c])) {
52 0 : return false;
53 : }
54 :
55 0 : if (a->incoming_previous_auth_info != NULL &&
56 0 : b->incoming_previous_auth_info != NULL) {
57 0 : if (!cmp_TrustDomainInfoBuffer(a->incoming_previous_auth_info[c],
58 0 : b->incoming_previous_auth_info[c])) {
59 0 : return false;
60 : }
61 0 : } else if (a->incoming_previous_auth_info == NULL &&
62 0 : b->incoming_previous_auth_info == NULL) {
63 0 : continue;
64 : } else {
65 0 : return false;
66 : }
67 : }
68 :
69 0 : for (c = 0; c < a->outgoing_count; c++) {
70 0 : if (!cmp_TrustDomainInfoBuffer(a->outgoing_current_auth_info[c],
71 0 : b->outgoing_current_auth_info[c])) {
72 0 : return false;
73 : }
74 :
75 0 : if (a->outgoing_previous_auth_info != NULL &&
76 0 : b->outgoing_previous_auth_info != NULL) {
77 0 : if (!cmp_TrustDomainInfoBuffer(a->outgoing_previous_auth_info[c],
78 0 : b->outgoing_previous_auth_info[c])) {
79 0 : return false;
80 : }
81 0 : } else if (a->outgoing_previous_auth_info == NULL &&
82 0 : b->outgoing_previous_auth_info == NULL) {
83 0 : continue;
84 : } else {
85 0 : return false;
86 : }
87 : }
88 :
89 0 : return true;
90 : }
91 :
92 0 : static bool covert_and_compare(struct lsa_TrustDomainInfoAuthInfo *auth_info)
93 : {
94 : NTSTATUS status;
95 : TALLOC_CTX *tmp_ctx;
96 : DATA_BLOB incoming;
97 : DATA_BLOB outgoing;
98 : struct lsa_TrustDomainInfoAuthInfo auth_info_out;
99 0 : bool result = false;
100 :
101 0 : tmp_ctx = talloc_new(NULL);
102 0 : if (tmp_ctx == NULL) {
103 0 : return false;
104 : }
105 :
106 0 : status = auth_info_2_auth_blob(tmp_ctx, auth_info, &incoming, &outgoing);
107 0 : if (!NT_STATUS_IS_OK(status)) {
108 0 : talloc_free(tmp_ctx);
109 0 : return false;
110 : }
111 :
112 0 : status = auth_blob_2_auth_info(tmp_ctx, incoming, outgoing,
113 : &auth_info_out);
114 0 : if (!NT_STATUS_IS_OK(status)) {
115 0 : talloc_free(tmp_ctx);
116 0 : return false;
117 : }
118 :
119 0 : result = cmp_auth_info(auth_info, &auth_info_out);
120 0 : talloc_free(tmp_ctx);
121 :
122 0 : return result;
123 : }
124 :
125 0 : bool run_local_conv_auth_info(int dummy)
126 : {
127 : struct lsa_TrustDomainInfoAuthInfo auth_info;
128 : struct lsa_TrustDomainInfoBuffer ic[1];
129 : struct lsa_TrustDomainInfoBuffer ip[1];
130 : struct lsa_TrustDomainInfoBuffer oc[2];
131 : struct lsa_TrustDomainInfoBuffer op[2];
132 0 : uint32_t version = 3;
133 :
134 0 : ic[0].last_update_time = 12345;
135 0 : ic[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
136 0 : ic[0].data.size = strlen("iPaSsWoRd");
137 0 : ic[0].data.data = discard_const_p(uint8_t, "iPaSsWoRd");
138 :
139 0 : ip[0].last_update_time = 67890;
140 0 : ip[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
141 0 : ip[0].data.size = strlen("OlDiPaSsWoRd");
142 0 : ip[0].data.data = discard_const_p(uint8_t, "OlDiPaSsWoRd");
143 :
144 0 : oc[0].last_update_time = 24580;
145 0 : oc[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
146 0 : oc[0].data.size = strlen("oPaSsWoRd");
147 0 : oc[0].data.data = discard_const_p(uint8_t, "oPaSsWoRd");
148 0 : oc[1].last_update_time = 24580;
149 0 : oc[1].AuthType = TRUST_AUTH_TYPE_VERSION;
150 0 : oc[1].data.size = 4;
151 0 : oc[1].data.data = (uint8_t *) &version;
152 :
153 0 : op[0].last_update_time = 13579;
154 0 : op[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
155 0 : op[0].data.size = strlen("OlDoPaSsWoRd");
156 0 : op[0].data.data = discard_const_p(uint8_t, "OlDoPaSsWoRd");
157 0 : op[1].last_update_time = 24580;
158 0 : op[1].AuthType = TRUST_AUTH_TYPE_VERSION;
159 0 : op[1].data.size = 4;
160 0 : op[1].data.data = (uint8_t *) &version;
161 :
162 0 : auth_info.incoming_count = 0;
163 0 : auth_info.incoming_current_auth_info = NULL;
164 0 : auth_info.incoming_previous_auth_info = NULL;
165 0 : auth_info.outgoing_count = 0;
166 0 : auth_info.outgoing_current_auth_info = NULL;
167 0 : auth_info.outgoing_previous_auth_info = NULL;
168 :
169 0 : if (!covert_and_compare(&auth_info)) {
170 0 : return false;
171 : }
172 :
173 0 : auth_info.incoming_count = 1;
174 0 : auth_info.incoming_current_auth_info = ic;
175 0 : auth_info.incoming_previous_auth_info = NULL;
176 0 : auth_info.outgoing_count = 0;
177 0 : auth_info.outgoing_current_auth_info = NULL;
178 0 : auth_info.outgoing_previous_auth_info = NULL;
179 :
180 0 : if (!covert_and_compare(&auth_info)) {
181 0 : return false;
182 : }
183 :
184 0 : auth_info.incoming_count = 0;
185 0 : auth_info.incoming_current_auth_info = NULL;
186 0 : auth_info.incoming_previous_auth_info = NULL;
187 0 : auth_info.outgoing_count = 2;
188 0 : auth_info.outgoing_current_auth_info = oc;
189 0 : auth_info.outgoing_previous_auth_info = NULL;
190 :
191 0 : if (!covert_and_compare(&auth_info)) {
192 0 : return false;
193 : }
194 :
195 0 : auth_info.incoming_count = 1;
196 0 : auth_info.incoming_current_auth_info = ic;
197 0 : auth_info.incoming_previous_auth_info = NULL;
198 0 : auth_info.outgoing_count = 2;
199 0 : auth_info.outgoing_current_auth_info = oc;
200 0 : auth_info.outgoing_previous_auth_info = NULL;
201 :
202 0 : if (!covert_and_compare(&auth_info)) {
203 0 : return false;
204 : }
205 :
206 0 : auth_info.incoming_count = 1;
207 0 : auth_info.incoming_current_auth_info = ic;
208 0 : auth_info.incoming_previous_auth_info = ip;
209 0 : auth_info.outgoing_count = 2;
210 0 : auth_info.outgoing_current_auth_info = oc;
211 0 : auth_info.outgoing_previous_auth_info = op;
212 :
213 0 : if (!covert_and_compare(&auth_info)) {
214 0 : return false;
215 : }
216 :
217 0 : return true;
218 : }
|