r5661: Be a little stricter on syntax regarding arrays. A pointer to an
[jelmer/samba4-debian.git] / source / torture / libnet / userinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Test suite for libnet calls.
4
5    Copyright (C) Rafal Szczesniak 2005
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_samr.h"
24
25
26 static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
27                             struct policy_handle *handle, struct samr_String *domname)
28 {
29         NTSTATUS status;
30         struct policy_handle h, domain_handle;
31         struct samr_Connect r1;
32         struct samr_LookupDomain r2;
33         struct samr_OpenDomain r3;
34         
35         printf("connecting\n");
36         
37         r1.in.system_name = 0;
38         r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
39         r1.out.connect_handle = &h;
40         
41         status = dcerpc_samr_Connect(p, mem_ctx, &r1);
42         if (!NT_STATUS_IS_OK(status)) {
43                 printf("Connect failed - %s\n", nt_errstr(status));
44                 return False;
45         }
46         
47         r2.in.connect_handle = &h;
48         r2.in.domain_name = domname;
49
50         printf("domain lookup\n");
51
52         status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2);
53         if (!NT_STATUS_IS_OK(status)) {
54                 printf("LookupDomain failed - %s\n", nt_errstr(status));
55                 return False;
56         }
57
58         r3.in.connect_handle = &h;
59         r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
60         r3.in.sid = r2.out.sid;
61         r3.out.domain_handle = &domain_handle;
62
63         printf("opening domain\n");
64
65         status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3);
66         if (!NT_STATUS_IS_OK(status)) {
67                 printf("OpenDomain failed - %s\n", nt_errstr(status));
68                 return False;
69         } else {
70                 *handle = domain_handle;
71         }
72
73         return True;
74 }
75
76
77 BOOL torture_userinfo(void)
78 {
79         NTSTATUS status;
80         const char *binding;
81         struct dcerpc_pipe *p;
82         struct dcerpc_binding b;
83         TALLOC_CTX *mem_ctx;
84         BOOL ret = True;
85         struct policy_handle h;
86         struct samr_String name;
87
88         mem_ctx = talloc_init("test_userinfo");
89         binding = lp_parm_string(-1, "torture", "binding");
90
91         status = torture_rpc_connection(&p,
92                                         DCERPC_SAMR_NAME,
93                                         DCERPC_SAMR_UUID,
94                                         DCERPC_SAMR_VERSION);
95         
96         if (!NT_STATUS_IS_OK(status)) {
97                 return False;
98         }
99
100         status = dcerpc_parse_binding(mem_ctx, binding, &b);
101         if (!NT_STATUS_IS_OK(status)) {
102                 printf("failed to parse dcerpc binding '%s'\n", binding);
103                 talloc_free(mem_ctx);
104                 ret = False;
105                 goto done;
106         }
107         name.string = b.host;
108
109         if (!test_opendomain(p, mem_ctx, &h, &name)) {
110                 ret = False;
111         }
112
113 done:
114         talloc_free(mem_ctx);
115         torture_rpc_close(p);
116
117         return ret;
118 }