2 * Unix SMB/CIFS implementation.
3 * NetLocalGroup testsuite
4 * Copyright (C) Guenther Deschner 2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <sys/types.h>
30 static NET_API_STATUS
test_netlocalgroupenum(const char *hostname
,
32 const char *groupname
)
34 NET_API_STATUS status
;
35 uint32_t entries_read
= 0;
36 uint32_t total_entries
= 0;
37 uint32_t resume_handle
= 0;
39 const char *current_name
= NULL
;
40 uint8_t *buffer
= NULL
;
43 struct LOCALGROUP_INFO_0
*info0
= NULL
;
44 struct LOCALGROUP_INFO_1
*info1
= NULL
;
46 printf("testing NetLocalGroupEnum level %d\n", level
);
49 status
= NetLocalGroupEnum(hostname
,
56 if (status
== 0 || status
== ERROR_MORE_DATA
) {
59 info0
= (struct LOCALGROUP_INFO_0
*)buffer
;
62 info1
= (struct LOCALGROUP_INFO_1
*)buffer
;
68 for (i
=0; i
<entries_read
; i
++) {
72 current_name
= info0
->lgrpi0_name
;
75 current_name
= info1
->lgrpi1_name
;
81 if (strcasecmp(current_name
, groupname
) == 0) {
94 NetApiBufferFree(buffer
);
96 } while (status
== ERROR_MORE_DATA
);
103 printf("failed to get group\n");
110 NET_API_STATUS
netapitest_localgroup(struct libnetapi_ctx
*ctx
,
111 const char *hostname
)
113 NET_API_STATUS status
= 0;
114 const char *groupname
, *groupname2
;
115 uint8_t *buffer
= NULL
;
116 struct LOCALGROUP_INFO_0 g0
;
117 uint32_t parm_err
= 0;
118 uint32_t levels
[] = { 0, 1, 1002 };
119 uint32_t enum_levels
[] = { 0, 1 };
122 printf("NetLocalgroup tests\n");
124 groupname
= "torture_test_localgroup";
125 groupname2
= "torture_test_localgroup2";
128 NetLocalGroupDel(hostname
, groupname
);
129 NetLocalGroupDel(hostname
, groupname2
);
131 /* add a localgroup */
133 printf("testing NetLocalGroupAdd\n");
135 g0
.lgrpi0_name
= groupname
;
137 status
= NetLocalGroupAdd(hostname
, 0, (uint8_t *)&g0
, &parm_err
);
139 NETAPI_STATUS(ctx
, status
, "NetLocalGroupAdd");
145 for (i
=0; i
<ARRAY_SIZE(enum_levels
); i
++) {
147 status
= test_netlocalgroupenum(hostname
, enum_levels
[i
], groupname
);
149 NETAPI_STATUS(ctx
, status
, "NetLocalGroupEnum");
157 for (i
=0; i
<ARRAY_SIZE(levels
); i
++) {
159 printf("testing NetLocalGroupGetInfo level %d\n", levels
[i
]);
161 status
= NetLocalGroupGetInfo(hostname
, groupname
, levels
[i
], &buffer
);
162 if (status
&& status
!= 124) {
163 NETAPI_STATUS(ctx
, status
, "NetLocalGroupGetInfo");
170 printf("testing NetLocalGroupSetInfo level 0\n");
172 g0
.lgrpi0_name
= groupname2
;
174 status
= NetLocalGroupSetInfo(hostname
, groupname
, 0, (uint8_t *)&g0
, &parm_err
);
176 NETAPI_STATUS(ctx
, status
, "NetLocalGroupSetInfo");
180 /* should not exist anymore */
182 status
= NetLocalGroupDel(hostname
, groupname
);
184 NETAPI_STATUS(ctx
, status
, "NetLocalGroupDel");
190 for (i
=0; i
<ARRAY_SIZE(levels
); i
++) {
191 status
= NetLocalGroupGetInfo(hostname
, groupname2
, levels
[i
], &buffer
);
192 if (status
&& status
!= 124) {
193 NETAPI_STATUS(ctx
, status
, "NetLocalGroupGetInfo");
200 printf("testing NetLocalGroupDel\n");
202 status
= NetLocalGroupDel(hostname
, groupname2
);
204 NETAPI_STATUS(ctx
, status
, "NetLocalGroupDel");
208 /* should not exist anymore */
210 status
= NetLocalGroupGetInfo(hostname
, groupname2
, 0, &buffer
);
212 NETAPI_STATUS(ctx
, status
, "NetLocalGroupGetInfo");
218 printf("NetLocalgroup tests succeeded\n");
221 printf("NetLocalGroup testsuite failed with: %s\n",
222 libnetapi_get_error_string(ctx
, status
));