0db89f49607b543e54df7ac705006edce72c551c
[gd/samba-autobuild/.git] / source4 / torture / libnet / groupman.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Test suite for libnet calls.
4
5    Copyright (C) Rafal Szczesniak 2007
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/rpc/rpc.h"
23 #include "torture/libnet/grouptest.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/ndr_samr_c.h"
26 #include "param/param.h"
27 #include "torture/libnet/utils.h"
28
29
30 static BOOL test_groupadd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
31                           struct policy_handle *domain_handle,
32                           const char *name)
33 {
34         NTSTATUS status;
35         BOOL ret = True;
36         struct libnet_rpc_groupadd group;
37
38         group.in.domain_handle = *domain_handle;
39         group.in.groupname     = name;
40         
41         printf("Testing libnet_rpc_groupadd\n");
42
43         status = libnet_rpc_groupadd(p, mem_ctx, &group);
44         if (!NT_STATUS_IS_OK(status)) {
45                 printf("Failed to call sync libnet_rpc_groupadd - %s\n", nt_errstr(status));
46                 return False;
47         }
48         
49         return ret;
50 }
51
52
53 BOOL torture_groupadd(struct torture_context *torture)
54 {
55         NTSTATUS status;
56         struct dcerpc_pipe *p;
57         struct policy_handle h;
58         struct lsa_String domain_name;
59         struct dom_sid2 sid;
60         const char *name = TEST_GROUPNAME;
61         TALLOC_CTX *mem_ctx;
62         BOOL ret = True;
63
64         mem_ctx = talloc_init("test_groupadd");
65
66         status = torture_rpc_connection(torture, 
67                                         &p,
68                                         &ndr_table_samr);
69         
70         if (!NT_STATUS_IS_OK(status)) {
71                 return False;
72         }
73
74         domain_name.string = lp_workgroup();
75         if (!test_opendomain(p, mem_ctx, &h, &domain_name, &sid)) {
76                 ret = False;
77                 goto done;
78         }
79
80         if (!test_groupadd(p, mem_ctx, &h, name)) {
81                 ret = False;
82                 goto done;
83         }
84
85         if (!test_group_cleanup(p, mem_ctx, &h, name)) {
86                 ret = False;
87                 goto done;
88         }
89         
90 done:
91         talloc_free(mem_ctx);
92         return ret;
93 }