r22195: fix compiler warnings and convert the whole torture/rpc/unixinfo.c code
[samba.git] / source4 / torture / rpc / unixinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for unixinfo rpc operations
4
5    Copyright (C) Volker Lendecke 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 "torture/torture.h"
24 #include "torture/rpc/rpc.h"
25 #include "librpc/gen_ndr/ndr_unixinfo_c.h"
26 #include "libcli/security/security.h"
27
28 /**
29   test the SidToUid interface
30 */
31 static bool test_sidtouid(struct torture_context *tctx, struct dcerpc_pipe *p)
32 {
33         NTSTATUS status;
34         struct unixinfo_SidToUid r;
35         struct dom_sid *sid;
36         
37         sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-5432");
38         r.in.sid = *sid;
39
40         status = dcerpc_unixinfo_SidToUid(p, tctx, &r);
41         if (NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED, status)) {
42         } else torture_assert_ntstatus_ok(tctx, status, "SidToUid failed");
43
44         return True;
45 }
46
47 /*
48   test the UidToSid interface
49 */
50 static bool test_uidtosid(struct torture_context *tctx, struct dcerpc_pipe *p)
51 {
52         struct unixinfo_UidToSid r;
53         struct dom_sid sid;
54
55         r.in.uid = 1000;
56         r.out.sid = &sid;
57
58         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_UidToSid(p, tctx, &r), 
59                                    "UidToSid failed");
60
61         return true;
62 }
63
64 static bool test_getpwuid(struct torture_context *tctx, 
65                           struct dcerpc_pipe *p)
66 {
67         uint64_t uids[512];
68         uint32_t num_uids = ARRAY_SIZE(uids);
69         uint32_t i;
70         struct unixinfo_GetPWUid r;
71         NTSTATUS result;
72
73         for (i=0; i<num_uids; i++) {
74                 uids[i] = i;
75         }
76         
77         r.in.count = &num_uids;
78         r.in.uids = uids;
79         r.out.count = &num_uids;
80         r.out.infos = talloc_array(tctx, struct unixinfo_GetPWUidInfo, num_uids);
81
82         result = dcerpc_unixinfo_GetPWUid(p, tctx, &r);
83
84         torture_assert_ntstatus_ok(tctx, result, "GetPWUid failed");
85         
86         return true;
87 }
88
89 /*
90   test the SidToGid interface
91 */
92 static bool test_sidtogid(struct torture_context *tctx, struct dcerpc_pipe *p)
93 {
94         NTSTATUS status;
95         struct unixinfo_SidToGid r;
96         struct dom_sid *sid;
97
98         sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-5432");
99         r.in.sid = *sid;
100
101         status = dcerpc_unixinfo_SidToGid(p, tctx, &r);
102         if (NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED, status)) {
103         } else torture_assert_ntstatus_ok(tctx, status, "SidToGid failed");
104
105         return true;
106 }
107
108 /*
109   test the GidToSid interface
110 */
111 static bool test_gidtosid(struct torture_context *tctx, struct dcerpc_pipe *p)
112 {
113         struct unixinfo_GidToSid r;
114         struct dom_sid sid;
115
116         r.in.gid = 1000;
117         r.out.sid = &sid;
118
119         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_GidToSid(p, tctx, &r), 
120                                    "GidToSid failed");
121
122         return true;
123 }
124
125 struct torture_suite *torture_rpc_unixinfo(void)
126 {
127         struct torture_suite *suite;
128         struct torture_tcase *tcase;
129
130         suite = torture_suite_create(talloc_autofree_context(), "UNIXINFO");
131         tcase = torture_suite_add_rpc_iface_tcase(suite, "unixinfo", 
132                                                   &dcerpc_table_unixinfo);
133
134         torture_rpc_tcase_add_test(tcase, "sidtouid", test_sidtouid);
135         torture_rpc_tcase_add_test(tcase, "uidtosid", test_uidtosid);
136         torture_rpc_tcase_add_test(tcase, "getpwuid", test_getpwuid);
137         torture_rpc_tcase_add_test(tcase, "sidtogid", test_sidtogid);
138         torture_rpc_tcase_add_test(tcase, "gidtosid", test_gidtosid);
139
140         return suite;
141 }