2 Unix SMB/CIFS implementation.
4 Copyright (C) Guenther Deschner 2009
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/>.
21 #include "nsswitch/libwbclient/wbclient.h"
22 #include "torture/smbtorture.h"
23 #include "torture/winbind/proto.h"
25 #define WBC_ERROR_EQUAL(x,y) (x == y)
27 #define torture_assert_wbc_equal(torture_ctx, got, expected, cmt) \
28 do { wbcErr __got = got, __expected = expected; \
29 if (!WBC_ERROR_EQUAL(__got, __expected)) { \
30 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", wbcErrorString(__got), wbcErrorString(__expected), cmt); \
35 #define torture_assert_wbc_ok(torture_ctx,expr,cmt) \
36 torture_assert_wbc_equal(torture_ctx,expr,WBC_ERR_SUCCESS,cmt)
38 static bool test_wbc_ping(struct torture_context
*tctx
)
40 torture_assert_wbc_ok(tctx
, wbcPing(),
46 static bool test_wbc_library_details(struct torture_context
*tctx
)
48 struct wbcLibraryDetails
*details
;
50 torture_assert_wbc_ok(tctx
, wbcLibraryDetails(&details
),
51 "wbcLibraryDetails failed");
52 torture_assert(tctx
, details
,
53 "wbcLibraryDetails returned NULL pointer");
55 wbcFreeMemory(details
);
60 static bool test_wbc_interface_details(struct torture_context
*tctx
)
62 struct wbcInterfaceDetails
*details
;
64 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
65 "wbcInterfaceDetails failed");
66 torture_assert(tctx
, details
,
67 "wbcInterfaceDetails returned NULL pointer");
69 wbcFreeMemory(details
);
74 static bool test_wbc_sidtypestring(struct torture_context
*tctx
)
76 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_USE_NONE
),
77 "SID_NONE", "SID_NONE failed");
78 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_USER
),
79 "SID_USER", "SID_USER failed");
80 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_DOM_GRP
),
81 "SID_DOM_GROUP", "SID_DOM_GROUP failed");
82 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_DOMAIN
),
83 "SID_DOMAIN", "SID_DOMAIN failed");
84 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_ALIAS
),
85 "SID_ALIAS", "SID_ALIAS failed");
86 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_WKN_GRP
),
87 "SID_WKN_GROUP", "SID_WKN_GROUP failed");
88 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_DELETED
),
89 "SID_DELETED", "SID_DELETED failed");
90 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_INVALID
),
91 "SID_INVALID", "SID_INVALID failed");
92 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_UNKNOWN
),
93 "SID_UNKNOWN", "SID_UNKNOWN failed");
94 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_COMPUTER
),
95 "SID_COMPUTER", "SID_COMPUTER failed");
99 static bool test_wbc_domain_info(struct torture_context
*tctx
)
101 const char *domain_name
= NULL
;
102 struct wbcDomainInfo
*info
;
103 struct wbcInterfaceDetails
*details
;
105 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
106 "wbcInterfaceDetails failed");
108 domain_name
= talloc_strdup(tctx
, details
->netbios_domain
);
109 wbcFreeMemory(details
);
111 torture_assert_wbc_ok(tctx
, wbcDomainInfo(domain_name
, &info
),
112 "wbcDomainInfo failed");
113 torture_assert(tctx
, info
,
114 "wbcDomainInfo returned NULL pointer");
119 static bool test_wbc_users(struct torture_context
*tctx
)
121 const char *domain_name
= NULL
;
125 struct wbcInterfaceDetails
*details
;
127 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
128 "wbcInterfaceDetails failed");
130 domain_name
= talloc_strdup(tctx
, details
->netbios_domain
);
131 wbcFreeMemory(details
);
133 torture_assert_wbc_ok(tctx
, wbcListUsers(domain_name
, &num_users
, &users
),
134 "wbcListUsers failed");
135 torture_assert(tctx
, !(num_users
> 0 && !users
),
136 "wbcListUsers returned invalid results");
138 for (i
=0; i
< MIN(num_users
,100); i
++) {
140 struct wbcDomainSid sid
;
141 enum wbcSidType name_type
;
145 torture_assert_wbc_ok(tctx
, wbcLookupName(domain_name
, users
[i
], &sid
, &name_type
),
146 "wbcLookupName failed");
147 torture_assert_int_equal(tctx
, name_type
, WBC_SID_NAME_USER
,
148 "wbcLookupName expected WBC_SID_NAME_USER");
149 torture_assert_wbc_ok(tctx
, wbcLookupSid(&sid
, &domain
, &name
, &name_type
),
150 "wbcLookupSid failed");
151 torture_assert_int_equal(tctx
, name_type
, WBC_SID_NAME_USER
,
152 "wbcLookupSid expected WBC_SID_NAME_USER");
153 torture_assert(tctx
, name
,
154 "wbcLookupSid returned no name");
160 static bool test_wbc_groups(struct torture_context
*tctx
)
162 const char *domain_name
= NULL
;
166 struct wbcInterfaceDetails
*details
;
168 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
169 "wbcInterfaceDetails failed");
171 domain_name
= talloc_strdup(tctx
, details
->netbios_domain
);
172 wbcFreeMemory(details
);
174 torture_assert_wbc_ok(tctx
, wbcListGroups(domain_name
, &num_groups
, &groups
),
175 "wbcListGroups failed");
176 torture_assert(tctx
, !(num_groups
> 0 && !groups
),
177 "wbcListGroups returned invalid results");
179 for (i
=0; i
< MIN(num_groups
,100); i
++) {
181 struct wbcDomainSid sid
;
182 enum wbcSidType name_type
;
186 torture_assert_wbc_ok(tctx
, wbcLookupName(domain_name
, groups
[i
], &sid
, &name_type
),
187 "wbcLookupName failed");
188 torture_assert_wbc_ok(tctx
, wbcLookupSid(&sid
, &domain
, &name
, &name_type
),
189 "wbcLookupSid failed");
190 torture_assert(tctx
, name
,
191 "wbcLookupSid returned no name");
197 static bool test_wbc_trusts(struct torture_context
*tctx
)
199 struct wbcDomainInfo
*domains
;
203 torture_assert_wbc_ok(tctx
, wbcListTrusts(&domains
, &num_domains
),
204 "wbcListTrusts failed");
205 torture_assert(tctx
, !(num_domains
> 0 && !domains
),
206 "wbcListTrusts returned invalid results");
208 for (i
=0; i
< MIN(num_domains
,100); i
++) {
210 struct wbcAuthErrorInfo
*error
;
212 struct wbcDomainSid sid;
213 enum wbcSidType name_type;
217 torture_assert_wbc_ok(tctx
, wbcCheckTrustCredentials(domains
[i
].short_name
, &error
),
218 "wbcCheckTrustCredentials failed");
220 torture_assert_wbc_ok(tctx, wbcLookupName(domains[i].short_name, NULL, &sid, &name_type),
221 "wbcLookupName failed");
222 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_DOMAIN,
223 "wbcLookupName expected WBC_SID_NAME_DOMAIN");
224 torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
225 "wbcLookupSid failed");
226 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_DOMAIN,
227 "wbcLookupSid expected WBC_SID_NAME_DOMAIN");
228 torture_assert(tctx, name,
229 "wbcLookupSid returned no name");
238 struct torture_suite
*torture_wbclient(void)
240 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "WBCLIENT");
242 torture_suite_add_simple_test(suite
, "wbcPing", test_wbc_ping
);
243 torture_suite_add_simple_test(suite
, "wbcLibraryDetails", test_wbc_library_details
);
244 torture_suite_add_simple_test(suite
, "wbcInterfaceDetails", test_wbc_interface_details
);
245 torture_suite_add_simple_test(suite
, "wbcSidTypeString", test_wbc_sidtypestring
);
246 torture_suite_add_simple_test(suite
, "wbcDomainInfo", test_wbc_domain_info
);
247 torture_suite_add_simple_test(suite
, "wbcListUsers", test_wbc_users
);
248 torture_suite_add_simple_test(suite
, "wbcListGroups", test_wbc_groups
);
249 torture_suite_add_simple_test(suite
, "wbcListTrusts", test_wbc_trusts
);