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