]> git.samba.org - garming/samba-autobuild/.git/blob - source4/torture/libnet/libnet_user.c
r8079: Dcerpc pipe in libnet_context is just pipe now, instead of explicit samr.
[garming/samba-autobuild/.git] / source4 / torture / libnet / libnet_user.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 #include "lib/cmdline/popt_common.h"
25 #include "libnet/libnet.h"
26 #include "libnet/composite.h"
27 #include "libcli/composite/monitor.h"
28
29
30 #define TEST_USERNAME  "libnetusertest"
31
32
33 static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
34                          struct policy_handle *domain_handle, const char *username)
35 {
36         NTSTATUS status;
37         struct samr_LookupNames r1;
38         struct samr_OpenUser r2;
39         struct samr_DeleteUser r3;
40         struct samr_Close r4;
41         struct samr_String names[2];
42         uint32_t rid;
43         struct policy_handle user_handle;
44
45         names[0].string = username;
46
47         r1.in.domain_handle  = domain_handle;
48         r1.in.num_names      = 1;
49         r1.in.names          = names;
50         
51         printf("user account lookup '%s'\n", username);
52
53         status = dcerpc_samr_LookupNames(p, mem_ctx, &r1);
54         if (!NT_STATUS_IS_OK(status)) {
55                 printf("LookupNames failed - %s\n", nt_errstr(status));
56                 return False;
57         }
58
59         rid = r1.out.rids.ids[0];
60         
61         r2.in.domain_handle  = domain_handle;
62         r2.in.access_mask    = SEC_FLAG_MAXIMUM_ALLOWED;
63         r2.in.rid            = rid;
64         r2.out.user_handle   = &user_handle;
65
66         printf("opening user account\n");
67
68         status = dcerpc_samr_OpenUser(p, mem_ctx, &r2);
69         if (!NT_STATUS_IS_OK(status)) {
70                 printf("OpenUser failed - %s\n", nt_errstr(status));
71                 return False;
72         }
73
74         r3.in.user_handle  = &user_handle;
75         r3.out.user_handle = &user_handle;
76
77         printf("deleting user account\n");
78         
79         status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3);
80         if (!NT_STATUS_IS_OK(status)) {
81                 printf("DeleteUser failed - %s\n", nt_errstr(status));
82                 return False;
83         }
84
85         r4.in.handle = domain_handle;
86         r4.out.handle = domain_handle;
87
88         status = dcerpc_samr_Close(p, mem_ctx, &r4);
89         if (!NT_STATUS_IS_OK(status)) {
90                 printf("Close failed - %s\n", nt_errstr(status));
91                 return False;
92         }
93         
94         return True;
95 }
96
97
98 BOOL torture_createuser(void)
99 {
100         NTSTATUS status;
101         const char *binding;
102         TALLOC_CTX *mem_ctx;
103         struct libnet_context *ctx;
104         struct libnet_CreateUser req;
105
106         mem_ctx = talloc_init("test_createuser");
107         binding = lp_parm_string(-1, "torture", "binding");
108
109         ctx = libnet_context_init(NULL);
110         ctx->cred = cmdline_credentials;
111
112         req.in.user_name = TEST_USERNAME;
113         req.in.domain_name = lp_workgroup();
114
115         status = libnet_CreateUser(ctx, mem_ctx, &req);
116         if (!NT_STATUS_IS_OK(status)) {
117                 printf("libnet_CreateUser call failed: %s\n", nt_errstr(status));
118                 return False;
119         }
120
121         if (!test_cleanup(ctx->pipe, mem_ctx, &ctx->domain_handle, TEST_USERNAME)) {
122                 printf("cleanup failed\n");
123                 return False;
124         }
125
126         return True;
127 }