s4:torture/rpc/handles: check the correct last_fault_code
[kai/samba.git] / source4 / torture / rpc / handles.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    test suite for behaviour of rpc policy handles
5
6    Copyright (C) Andrew Tridgell 2007
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_samr_c.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
26 #include "torture/rpc/rpc.h"
27
28 /*
29   this tests the use of policy handles between connections
30 */
31
32 static bool test_handles_lsa(struct torture_context *torture)
33 {
34         NTSTATUS status;
35         struct dcerpc_pipe *p1, *p2;
36         struct policy_handle handle;
37         struct policy_handle handle2;
38         struct lsa_ObjectAttribute attr;
39         struct lsa_QosInfo qos;
40         struct lsa_OpenPolicy r;
41         struct lsa_Close c;
42         uint16_t system_name = '\\';
43         TALLOC_CTX *mem_ctx = talloc_new(torture);
44
45         torture_comment(torture, "RPC-HANDLE-LSARPC\n");
46
47         status = torture_rpc_connection(torture, &p1, &ndr_table_lsarpc);
48         torture_assert_ntstatus_ok(torture, status, "opening lsa pipe1");
49
50         status = torture_rpc_connection(torture, &p2, &ndr_table_lsarpc);
51         torture_assert_ntstatus_ok(torture, status, "opening lsa pipe1");
52
53         qos.len = 0;
54         qos.impersonation_level = 2;
55         qos.context_mode = 1;
56         qos.effective_only = 0;
57
58         attr.len = 0;
59         attr.root_dir = NULL;
60         attr.object_name = NULL;
61         attr.attributes = 0;
62         attr.sec_desc = NULL;
63         attr.sec_qos = &qos;
64
65         r.in.system_name = &system_name;
66         r.in.attr = &attr;
67         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
68         r.out.handle = &handle;
69
70         status = dcerpc_lsa_OpenPolicy(p1, mem_ctx, &r);
71         if (!NT_STATUS_IS_OK(status)) {
72                 torture_comment(torture, "lsa_OpenPolicy not supported - skipping\n");
73                 talloc_free(mem_ctx);
74                 return true;
75         }
76
77         c.in.handle = &handle;
78         c.out.handle = &handle2;
79
80         status = dcerpc_lsa_Close(p2, mem_ctx, &c);
81         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
82                                       "closing policy handle on p2");
83         torture_assert_int_equal(torture, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
84                                       "closing policy handle on p2");
85
86         status = dcerpc_lsa_Close(p1, mem_ctx, &c);
87         torture_assert_ntstatus_ok(torture, status, "closing policy handle on p1");
88
89         status = dcerpc_lsa_Close(p1, mem_ctx, &c);
90         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
91                                       "closing policy handle on p1 again");
92         torture_assert_int_equal(torture, p1->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
93                                       "closing policy handle on p1 again");
94         
95         talloc_free(mem_ctx);
96
97         return true;
98 }
99
100 static bool test_handles_lsa_shared(struct torture_context *torture)
101 {
102         NTSTATUS status;
103         struct dcerpc_pipe *p1, *p2, *p3, *p4, *p5;
104         struct policy_handle handle;
105         struct policy_handle handle2;
106         struct lsa_ObjectAttribute attr;
107         struct lsa_QosInfo qos;
108         struct lsa_OpenPolicy r;
109         struct lsa_Close c;
110         struct lsa_QuerySecurity qsec;
111         struct sec_desc_buf *sdbuf = NULL;
112         uint16_t system_name = '\\';
113         TALLOC_CTX *mem_ctx = talloc_new(torture);
114         enum dcerpc_transport_t transport;
115         uint32_t assoc_group_id;
116
117         torture_comment(torture, "RPC-HANDLE-LSARPC-SHARED\n");
118
119         torture_comment(torture, "connect lsa pipe1\n");
120         status = torture_rpc_connection(torture, &p1, &ndr_table_lsarpc);
121         torture_assert_ntstatus_ok(torture, status, "opening lsa pipe1");
122
123         transport       = p1->conn->transport.transport;
124         assoc_group_id  = p1->assoc_group_id;
125
126         torture_comment(torture, "use assoc_group_id[0x%08X] for new connections\n", assoc_group_id);
127
128         torture_comment(torture, "connect lsa pipe2\n");
129         status = torture_rpc_connection_transport(torture, &p2, &ndr_table_lsarpc,
130                                                   transport,
131                                                   assoc_group_id);
132         torture_assert_ntstatus_ok(torture, status, "opening lsa pipe2");
133
134         torture_comment(torture, "got assoc_group_id[0x%08X] for p2\n", 
135                         p2->assoc_group_id);
136
137         qos.len = 0;
138         qos.impersonation_level = 2;
139         qos.context_mode = 1;
140         qos.effective_only = 0;
141
142         attr.len = 0;
143         attr.root_dir = NULL;
144         attr.object_name = NULL;
145         attr.attributes = 0;
146         attr.sec_desc = NULL;
147         attr.sec_qos = &qos;
148
149         r.in.system_name = &system_name;
150         r.in.attr = &attr;
151         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
152         r.out.handle = &handle;
153
154         torture_comment(torture, "open lsa policy handle\n");
155         status = dcerpc_lsa_OpenPolicy(p1, mem_ctx, &r);
156         if (!NT_STATUS_IS_OK(status)) {
157                 torture_comment(torture, "lsa_OpenPolicy not supported - skipping\n");
158                 talloc_free(mem_ctx);
159                 return true;
160         }
161
162         /*
163          * connect p3 after the policy handle is opened
164          */
165         torture_comment(torture, "connect lsa pipe3 after the policy handle is opened\n");
166         status = torture_rpc_connection_transport(torture, &p3, &ndr_table_lsarpc,
167                                                   transport,
168                                                   assoc_group_id);
169         torture_assert_ntstatus_ok(torture, status, "opening lsa pipe3");
170
171         qsec.in.handle          = &handle;
172         qsec.in.sec_info        = 0;
173         qsec.out.sdbuf          = &sdbuf;
174         c.in.handle = &handle;
175         c.out.handle = &handle2;
176
177         /*
178          * use policy handle on all 3 connections
179          */
180         torture_comment(torture, "use the policy handle on p1,p2,p3\n");
181         status = dcerpc_lsa_QuerySecurity(p1, mem_ctx, &qsec);
182         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
183                                       "use policy handle on p1");
184
185         status = dcerpc_lsa_QuerySecurity(p2, mem_ctx, &qsec);
186         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
187                                       "use policy handle on p2");
188
189         status = dcerpc_lsa_QuerySecurity(p3, mem_ctx, &qsec);
190         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
191                                       "use policy handle on p3");
192
193         /*
194          * close policy handle on connection 2 and the others get a fault
195          */
196         torture_comment(torture, "close the policy handle on p2 others get a fault\n");
197         status = dcerpc_lsa_Close(p2, mem_ctx, &c);
198         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
199                                       "closing policy handle on p2");
200
201         status = dcerpc_lsa_Close(p1, mem_ctx, &c);
202         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
203                                       "closing policy handle on p1 again");
204         torture_assert_int_equal(torture, p1->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
205                                       "closing policy handle on p1 again");
206
207         status = dcerpc_lsa_Close(p3, mem_ctx, &c);
208         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
209                                       "closing policy handle on p3");
210         torture_assert_int_equal(torture, p3->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
211                                       "closing policy handle on p3");
212
213         status = dcerpc_lsa_Close(p2, mem_ctx, &c);
214         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
215                                       "closing policy handle on p2 again");
216         torture_assert_int_equal(torture, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
217                                       "closing policy handle on p2 again");
218
219         /*
220          * open a new policy handle on p3
221          */
222         torture_comment(torture, "open a new policy handle on p3\n");
223         status = dcerpc_lsa_OpenPolicy(p3, mem_ctx, &r);
224         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
225                                       "open policy handle on p3");
226
227         /*
228          * use policy handle on all 3 connections
229          */
230         torture_comment(torture, "use the policy handle on p1,p2,p3\n");
231         status = dcerpc_lsa_QuerySecurity(p1, mem_ctx, &qsec);
232         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
233                                       "use policy handle on p1");
234
235         status = dcerpc_lsa_QuerySecurity(p2, mem_ctx, &qsec);
236         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
237                                       "use policy handle on p2");
238
239         status = dcerpc_lsa_QuerySecurity(p3, mem_ctx, &qsec);
240         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
241                                       "use policy handle on p3");
242
243         /*
244          * close policy handle on connection 2 and the others get a fault
245          */
246         torture_comment(torture, "close the policy handle on p2 others get a fault\n");
247         status = dcerpc_lsa_Close(p2, mem_ctx, &c);
248         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
249                                       "closing policy handle on p2");
250
251         status = dcerpc_lsa_Close(p1, mem_ctx, &c);
252         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
253                                       "closing policy handle on p1 again");
254         torture_assert_int_equal(torture, p1->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
255                                       "closing policy handle on p1 again");
256
257         status = dcerpc_lsa_Close(p3, mem_ctx, &c);
258         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
259                                       "closing policy handle on p3");
260         torture_assert_int_equal(torture, p3->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
261                                       "closing policy handle on p3");
262
263         status = dcerpc_lsa_Close(p2, mem_ctx, &c);
264         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
265                                       "closing policy handle on p2 again");
266         torture_assert_int_equal(torture, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
267                                       "closing policy handle on p2 again");
268
269         /*
270          * open a new policy handle
271          */
272         torture_comment(torture, "open a new policy handle on p1 and use it\n");
273         status = dcerpc_lsa_OpenPolicy(p1, mem_ctx, &r);
274         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
275                                       "open 2nd policy handle on p1");
276
277         status = dcerpc_lsa_QuerySecurity(p1, mem_ctx, &qsec);
278         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
279                                       "QuerySecurity handle on p1");
280
281         /* close first connection */
282         torture_comment(torture, "disconnect p1\n");
283         talloc_free(p1);
284         msleep(5);
285
286         /*
287          * and it's still available on p2,p3
288          */
289         torture_comment(torture, "use policy handle on p2,p3\n");
290         status = dcerpc_lsa_QuerySecurity(p2, mem_ctx, &qsec);
291         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
292                                       "QuerySecurity handle on p2 after p1 was disconnected");
293
294         status = dcerpc_lsa_QuerySecurity(p3, mem_ctx, &qsec);
295         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
296                                       "QuerySecurity handle on p3 after p1 was disconnected");
297
298         /*
299          * now open p4
300          * and use the handle on it
301          */
302         torture_comment(torture, "connect lsa pipe4 and use policy handle\n");
303         status = torture_rpc_connection_transport(torture, &p4, &ndr_table_lsarpc,
304                                                   transport,
305                                                   assoc_group_id);
306         torture_assert_ntstatus_ok(torture, status, "opening lsa pipe4");
307
308         status = dcerpc_lsa_QuerySecurity(p4, mem_ctx, &qsec);
309         torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK, 
310                                       "using policy handle on p4");
311
312         /*
313          * now close p2,p3,p4
314          * without closing the policy handle
315          */
316         torture_comment(torture, "disconnect p2,p3,p4\n");
317         talloc_free(p2);
318         talloc_free(p3);
319         talloc_free(p4);
320         msleep(10);
321
322         /*
323          * now open p5
324          */
325         torture_comment(torture, "connect lsa pipe5 - should fail\n");
326         status = torture_rpc_connection_transport(torture, &p5, &ndr_table_lsarpc,
327                                                   transport,
328                                                   assoc_group_id);
329         torture_assert_ntstatus_equal(torture, status, NT_STATUS_UNSUCCESSFUL,
330                                       "opening lsa pipe5");
331
332         talloc_free(mem_ctx);
333
334         return true;
335 }
336
337
338 static bool test_handles_samr(struct torture_context *torture)
339 {
340         NTSTATUS status;
341         struct dcerpc_pipe *p1, *p2;
342         struct policy_handle handle;
343         struct policy_handle handle2;
344         struct samr_Connect r;
345         struct samr_Close c;
346         TALLOC_CTX *mem_ctx = talloc_new(torture);
347
348         torture_comment(torture, "RPC-HANDLE-SAMR\n");
349
350         status = torture_rpc_connection(torture, &p1, &ndr_table_samr);
351         torture_assert_ntstatus_ok(torture, status, "opening samr pipe1");
352
353         status = torture_rpc_connection(torture, &p2, &ndr_table_samr);
354         torture_assert_ntstatus_ok(torture, status, "opening samr pipe1");
355
356         r.in.system_name = 0;
357         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
358         r.out.connect_handle = &handle;
359
360         status = dcerpc_samr_Connect(p1, mem_ctx, &r);
361         torture_assert_ntstatus_ok(torture, status, "opening policy handle on p1");
362
363         c.in.handle = &handle;
364         c.out.handle = &handle2;
365
366         status = dcerpc_samr_Close(p2, mem_ctx, &c);
367         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
368                                       "closing policy handle on p2");
369         torture_assert_int_equal(torture, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
370                                       "closing policy handle on p2");
371
372         status = dcerpc_samr_Close(p1, mem_ctx, &c);
373         torture_assert_ntstatus_ok(torture, status, "closing policy handle on p1");
374
375         status = dcerpc_samr_Close(p1, mem_ctx, &c);
376         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
377                                       "closing policy handle on p1 again");
378         torture_assert_int_equal(torture, p1->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
379                                       "closing policy handle on p1 again");
380         
381         talloc_free(mem_ctx);
382
383         return true;
384 }
385
386 static bool test_handles_mixed_shared(struct torture_context *torture)
387 {
388         NTSTATUS status;
389         struct dcerpc_pipe *p1, *p2, *p3, *p4, *p5, *p6;
390         struct policy_handle handle;
391         struct policy_handle handle2;
392         struct samr_Connect r;
393         struct lsa_Close lc;
394         struct samr_Close sc;
395         TALLOC_CTX *mem_ctx = talloc_new(torture);
396         enum dcerpc_transport_t transport;
397         uint32_t assoc_group_id;
398
399         torture_comment(torture, "RPC-HANDLE-MIXED-SHARED\n");
400
401         torture_comment(torture, "connect samr pipe1\n");
402         status = torture_rpc_connection(torture, &p1, &ndr_table_samr);
403         torture_assert_ntstatus_ok(torture, status, "opening samr pipe1");
404
405         transport       = p1->conn->transport.transport;
406         assoc_group_id  = p1->assoc_group_id;
407
408         torture_comment(torture, "use assoc_group_id[0x%08X] for new connections\n", assoc_group_id);
409
410         torture_comment(torture, "connect lsa pipe2\n");
411         status = torture_rpc_connection_transport(torture, &p2, &ndr_table_lsarpc,
412                                                   transport,
413                                                   assoc_group_id);
414         torture_assert_ntstatus_ok(torture, status, "opening lsa pipe2");
415
416         torture_comment(torture, "got assoc_group_id[0x%08X] for p2\n", 
417                         p2->assoc_group_id);
418         r.in.system_name = 0;
419         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
420         r.out.connect_handle = &handle;
421
422         torture_comment(torture, "samr_Connect to open a policy handle on samr p1\n");
423         status = dcerpc_samr_Connect(p1, mem_ctx, &r);
424         torture_assert_ntstatus_ok(torture, status, "opening policy handle on p1");
425
426         lc.in.handle            = &handle;
427         lc.out.handle           = &handle2;
428         sc.in.handle            = &handle;
429         sc.out.handle           = &handle2;
430
431         torture_comment(torture, "use policy handle on lsa p2 - should fail\n");
432         status = dcerpc_lsa_Close(p2, mem_ctx, &lc);
433         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
434                                       "closing handle on lsa p2");
435         torture_assert_int_equal(torture, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
436                                       "closing handle on lsa p2");
437
438         torture_comment(torture, "closing policy handle on samr p1\n");
439         status = dcerpc_samr_Close(p1, mem_ctx, &sc);
440         torture_assert_ntstatus_ok(torture, status, "closing policy handle on p1");
441
442         talloc_free(p1);
443         talloc_free(p2);
444         msleep(10);
445
446         torture_comment(torture, "connect samr pipe3 - should fail\n");
447         status = torture_rpc_connection_transport(torture, &p3, &ndr_table_samr,
448                                                   transport,
449                                                   assoc_group_id);
450         torture_assert_ntstatus_equal(torture, status, NT_STATUS_UNSUCCESSFUL,
451                                       "opening samr pipe3");
452
453         torture_comment(torture, "connect lsa pipe4 - should fail\n");
454         status = torture_rpc_connection_transport(torture, &p4, &ndr_table_lsarpc,
455                                                   transport,
456                                                   assoc_group_id);
457         torture_assert_ntstatus_equal(torture, status, NT_STATUS_UNSUCCESSFUL,
458                                       "opening lsa pipe4");
459
460         torture_comment(torture, "connect samr pipe5 with assoc_group_id[0x%08X]- should fail\n", ++assoc_group_id);
461         status = torture_rpc_connection_transport(torture, &p5, &ndr_table_samr,
462                                                   transport,
463                                                   assoc_group_id);
464         torture_assert_ntstatus_equal(torture, status, NT_STATUS_UNSUCCESSFUL,
465                                       "opening samr pipe5");
466
467         torture_comment(torture, "connect lsa pipe6 with assoc_group_id[0x%08X]- should fail\n", ++assoc_group_id);
468         status = torture_rpc_connection_transport(torture, &p6, &ndr_table_lsarpc,
469                                                   transport,
470                                                   assoc_group_id);
471         torture_assert_ntstatus_equal(torture, status, NT_STATUS_UNSUCCESSFUL,
472                                       "opening lsa pipe6");
473
474         talloc_free(mem_ctx);
475
476         return true;
477 }
478
479 static bool test_handles_random_assoc(struct torture_context *torture)
480 {
481         NTSTATUS status;
482         struct dcerpc_pipe *p1, *p2, *p3;
483         TALLOC_CTX *mem_ctx = talloc_new(torture);
484         enum dcerpc_transport_t transport;
485         uint32_t assoc_group_id;
486
487         torture_comment(torture, "RPC-HANDLE-RANDOM-ASSOC\n");
488
489         torture_comment(torture, "connect samr pipe1\n");
490         status = torture_rpc_connection(torture, &p1, &ndr_table_samr);
491         torture_assert_ntstatus_ok(torture, status, "opening samr pipe1");
492
493         transport       = p1->conn->transport.transport;
494         assoc_group_id  = p1->assoc_group_id;
495
496         torture_comment(torture, "pip1 use assoc_group_id[0x%08X]\n", assoc_group_id);
497
498         torture_comment(torture, "connect samr pipe2 with assoc_group_id[0x%08X]- should fail\n", ++assoc_group_id);
499         status = torture_rpc_connection_transport(torture, &p2, &ndr_table_samr,
500                                                   transport,
501                                                   assoc_group_id);
502         torture_assert_ntstatus_equal(torture, status, NT_STATUS_UNSUCCESSFUL,
503                                       "opening samr pipe2");
504
505         torture_comment(torture, "connect samr pipe3 with assoc_group_id[0x%08X]- should fail\n", ++assoc_group_id);
506         status = torture_rpc_connection_transport(torture, &p3, &ndr_table_samr,
507                                                   transport,
508                                                   assoc_group_id);
509         torture_assert_ntstatus_equal(torture, status, NT_STATUS_UNSUCCESSFUL,
510                                       "opening samr pipe3");
511
512         talloc_free(mem_ctx);
513
514         return true;
515 }
516
517
518 static bool test_handles_drsuapi(struct torture_context *torture)
519 {
520         NTSTATUS status;
521         struct dcerpc_pipe *p1, *p2;
522         struct policy_handle handle;
523         struct policy_handle handle2;
524         struct GUID bind_guid;
525         struct drsuapi_DsBind r;
526         struct drsuapi_DsUnbind c;
527         TALLOC_CTX *mem_ctx = talloc_new(torture);
528
529         torture_comment(torture, "RPC-HANDLE-DRSUAPI\n");
530
531         status = torture_rpc_connection(torture, &p1, &ndr_table_drsuapi);
532         torture_assert_ntstatus_ok(torture, status, "opening drsuapi pipe1");
533
534         status = torture_rpc_connection(torture, &p2, &ndr_table_drsuapi);
535         torture_assert_ntstatus_ok(torture, status, "opening drsuapi pipe1");
536
537         GUID_from_string(DRSUAPI_DS_BIND_GUID, &bind_guid);
538
539         r.in.bind_guid = &bind_guid;
540         r.in.bind_info = NULL;
541         r.out.bind_handle = &handle;
542
543         status = dcerpc_drsuapi_DsBind(p1, mem_ctx, &r);
544         if (!NT_STATUS_IS_OK(status)) {
545                 torture_comment(torture, "drsuapi_DsBind not supported - skipping\n");
546                 talloc_free(mem_ctx);
547                 return true;
548         }
549
550         c.in.bind_handle = &handle;
551         c.out.bind_handle = &handle2;
552
553         status = dcerpc_drsuapi_DsUnbind(p2, mem_ctx, &c);
554         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
555                                       "closing policy handle on p2");
556         torture_assert_int_equal(torture, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
557                                       "closing policy handle on p2");
558
559         status = dcerpc_drsuapi_DsUnbind(p1, mem_ctx, &c);
560         torture_assert_ntstatus_ok(torture, status, "closing policy handle on p1");
561
562         status = dcerpc_drsuapi_DsUnbind(p1, mem_ctx, &c);
563         torture_assert_ntstatus_equal(torture, status, NT_STATUS_NET_WRITE_FAULT, 
564                                       "closing policy handle on p1 again");
565         torture_assert_int_equal(torture, p1->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH, 
566                                       "closing policy handle on p1 again");
567         
568         talloc_free(mem_ctx);
569
570         return true;
571 }
572
573 struct torture_suite *torture_rpc_handles(TALLOC_CTX *mem_ctx)
574 {
575         struct torture_suite *suite;
576
577         suite = torture_suite_create(mem_ctx, "HANDLES");
578         torture_suite_add_simple_test(suite, "lsarpc", test_handles_lsa);
579         torture_suite_add_simple_test(suite, "lsarpc-shared", test_handles_lsa_shared);
580         torture_suite_add_simple_test(suite, "samr", test_handles_samr);
581         torture_suite_add_simple_test(suite, "mixed-shared", test_handles_mixed_shared);
582         torture_suite_add_simple_test(suite, "random-assoc", test_handles_random_assoc);
583         torture_suite_add_simple_test(suite, "drsuapi", test_handles_drsuapi);
584         return suite;
585 }