r5610: Starting libnet test of userinfo call. Unfinished yet, though
[ira/wip.git] / source4 / 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         status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2);
51         if (!NT_STATUS_IS_OK(status)) {
52                 printf("LookupDomain failed - %s\n", nt_errstr(status));
53                 return False;
54         }
55
56         r3.in.connect_handle = &h;
57         r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
58         r3.in.sid = r2.out.sid;
59         r3.out.domain_handle = &domain_handle;
60
61         status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3);
62         if (!NT_STATUS_IS_OK(status)) {
63                 printf("OpenDomain failed - %s\n", nt_errstr(status));
64                 return False;
65         } else {
66                 *handle = domain_handle;
67         }
68 }
69
70
71 BOOL torture_userinfo(void)
72 {
73         NTSTATUS status;
74         struct dcerpc_pipe *p;
75         TALLOC_CTX *mem_ctx;
76         BOOL ret = True;
77         struct policy_handle h;
78         struct samr_String name = { 4, 4, "TEST" };
79
80         mem_ctx = talloc_init("test_userinfo");
81         
82         status = torture_rpc_connection(&p,
83                                         DCERPC_SAMR_NAME,
84                                         DCERPC_SAMR_UUID,
85                                         DCERPC_SAMR_VERSION);
86         
87         if (!NT_STATUS_IS_OK(status)) {
88                 return False;
89         }
90
91         if (!test_opendomain(p, mem_ctx, &h, &name)) {
92                 ret = False;
93         }
94
95         talloc_free(mem_ctx);
96         
97         torture_rpc_close(p);
98
99         return ret;
100 }