1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | Winbind client API
|
---|
5 |
|
---|
6 | Copyright (C) Gerald (Jerry) Carter 2007
|
---|
7 |
|
---|
8 | This library is free software; you can redistribute it and/or
|
---|
9 | modify it under the terms of the GNU Lesser General Public
|
---|
10 | License as published by the Free Software Foundation; either
|
---|
11 | version 3 of the License, or (at your option) any later version.
|
---|
12 |
|
---|
13 | This library is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
16 | Library General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU Lesser General Public License
|
---|
19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef _WBCLIENT_H
|
---|
23 | #define _WBCLIENT_H
|
---|
24 |
|
---|
25 | #include <pwd.h>
|
---|
26 | #include <grp.h>
|
---|
27 |
|
---|
28 | /* Define error types */
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * @brief Status codes returned from wbc functions
|
---|
32 | **/
|
---|
33 |
|
---|
34 | enum _wbcErrType {
|
---|
35 | WBC_ERR_SUCCESS = 0, /**< Successful completion **/
|
---|
36 | WBC_ERR_NOT_IMPLEMENTED,/**< Function not implemented **/
|
---|
37 | WBC_ERR_UNKNOWN_FAILURE,/**< General failure **/
|
---|
38 | WBC_ERR_NO_MEMORY, /**< Memory allocation error **/
|
---|
39 | WBC_ERR_INVALID_SID, /**< Invalid SID format **/
|
---|
40 | WBC_ERR_INVALID_PARAM, /**< An Invalid parameter was supplied **/
|
---|
41 | WBC_ERR_WINBIND_NOT_AVAILABLE, /**< Winbind daemon is not available **/
|
---|
42 | WBC_ERR_DOMAIN_NOT_FOUND, /**< Domain is not trusted or cannot be found **/
|
---|
43 | WBC_ERR_INVALID_RESPONSE, /**< Winbind returned an invalid response **/
|
---|
44 | WBC_ERR_NSS_ERROR, /**< NSS_STATUS error **/
|
---|
45 | WBC_ERR_AUTH_ERROR /**< Authentication failed **/
|
---|
46 | };
|
---|
47 |
|
---|
48 | typedef enum _wbcErrType wbcErr;
|
---|
49 |
|
---|
50 | #define WBC_ERROR_IS_OK(x) ((x) == WBC_ERR_SUCCESS)
|
---|
51 |
|
---|
52 | const char *wbcErrorString(wbcErr error);
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * @brief Some useful details about the wbclient library
|
---|
56 | *
|
---|
57 | **/
|
---|
58 | #define WBCLIENT_MAJOR_VERSION 0
|
---|
59 | #define WBCLIENT_MINOR_VERSION 1
|
---|
60 | #define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
|
---|
61 | struct wbcLibraryDetails {
|
---|
62 | uint16_t major_version;
|
---|
63 | uint16_t minor_version;
|
---|
64 | const char *vendor_version;
|
---|
65 | };
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * @brief Some useful details about the running winbindd
|
---|
69 | *
|
---|
70 | **/
|
---|
71 | struct wbcInterfaceDetails {
|
---|
72 | uint32_t interface_version;
|
---|
73 | const char *winbind_version;
|
---|
74 | char winbind_separator;
|
---|
75 | const char *netbios_name;
|
---|
76 | const char *netbios_domain;
|
---|
77 | const char *dns_domain;
|
---|
78 | };
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * Data types used by the Winbind Client API
|
---|
82 | */
|
---|
83 |
|
---|
84 | #ifndef WBC_MAXSUBAUTHS
|
---|
85 | #define WBC_MAXSUBAUTHS 15 /* max sub authorities in a SID */
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * @brief Windows Security Identifier
|
---|
90 | *
|
---|
91 | **/
|
---|
92 |
|
---|
93 | struct wbcDomainSid {
|
---|
94 | uint8_t sid_rev_num;
|
---|
95 | uint8_t num_auths;
|
---|
96 | uint8_t id_auth[6];
|
---|
97 | uint32_t sub_auths[WBC_MAXSUBAUTHS];
|
---|
98 | };
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * @brief Security Identifier type
|
---|
102 | **/
|
---|
103 |
|
---|
104 | enum wbcSidType {
|
---|
105 | WBC_SID_NAME_USE_NONE=0,
|
---|
106 | WBC_SID_NAME_USER=1,
|
---|
107 | WBC_SID_NAME_DOM_GRP=2,
|
---|
108 | WBC_SID_NAME_DOMAIN=3,
|
---|
109 | WBC_SID_NAME_ALIAS=4,
|
---|
110 | WBC_SID_NAME_WKN_GRP=5,
|
---|
111 | WBC_SID_NAME_DELETED=6,
|
---|
112 | WBC_SID_NAME_INVALID=7,
|
---|
113 | WBC_SID_NAME_UNKNOWN=8,
|
---|
114 | WBC_SID_NAME_COMPUTER=9
|
---|
115 | };
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * @brief Security Identifier with attributes
|
---|
119 | **/
|
---|
120 |
|
---|
121 | struct wbcSidWithAttr {
|
---|
122 | struct wbcDomainSid sid;
|
---|
123 | uint32_t attributes;
|
---|
124 | };
|
---|
125 |
|
---|
126 | /* wbcSidWithAttr->attributes */
|
---|
127 |
|
---|
128 | #define WBC_SID_ATTR_GROUP_MANDATORY 0x00000001
|
---|
129 | #define WBC_SID_ATTR_GROUP_ENABLED_BY_DEFAULT 0x00000002
|
---|
130 | #define WBC_SID_ATTR_GROUP_ENABLED 0x00000004
|
---|
131 | #define WBC_SID_ATTR_GROUP_OWNER 0x00000008
|
---|
132 | #define WBC_SID_ATTR_GROUP_USEFOR_DENY_ONLY 0x00000010
|
---|
133 | #define WBC_SID_ATTR_GROUP_RESOURCE 0x20000000
|
---|
134 | #define WBC_SID_ATTR_GROUP_LOGON_ID 0xC0000000
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * @brief Domain Information
|
---|
138 | **/
|
---|
139 |
|
---|
140 | struct wbcDomainInfo {
|
---|
141 | char *short_name;
|
---|
142 | char *dns_name;
|
---|
143 | struct wbcDomainSid sid;
|
---|
144 | uint32_t domain_flags;
|
---|
145 | uint32_t trust_flags;
|
---|
146 | uint32_t trust_type;
|
---|
147 | };
|
---|
148 |
|
---|
149 | /* wbcDomainInfo->domain_flags */
|
---|
150 |
|
---|
151 | #define WBC_DOMINFO_DOMAIN_UNKNOWN 0x00000000
|
---|
152 | #define WBC_DOMINFO_DOMAIN_NATIVE 0x00000001
|
---|
153 | #define WBC_DOMINFO_DOMAIN_AD 0x00000002
|
---|
154 | #define WBC_DOMINFO_DOMAIN_PRIMARY 0x00000004
|
---|
155 | #define WBC_DOMINFO_DOMAIN_OFFLINE 0x00000008
|
---|
156 |
|
---|
157 | /* wbcDomainInfo->trust_flags */
|
---|
158 |
|
---|
159 | #define WBC_DOMINFO_TRUST_TRANSITIVE 0x00000001
|
---|
160 | #define WBC_DOMINFO_TRUST_INCOMING 0x00000002
|
---|
161 | #define WBC_DOMINFO_TRUST_OUTGOING 0x00000004
|
---|
162 |
|
---|
163 | /* wbcDomainInfo->trust_type */
|
---|
164 |
|
---|
165 | #define WBC_DOMINFO_TRUSTTYPE_NONE 0x00000000
|
---|
166 | #define WBC_DOMINFO_TRUSTTYPE_FOREST 0x00000001
|
---|
167 | #define WBC_DOMINFO_TRUSTTYPE_IN_FOREST 0x00000002
|
---|
168 | #define WBC_DOMINFO_TRUSTTYPE_EXTERNAL 0x00000003
|
---|
169 |
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * @brief Auth User Parameters
|
---|
173 | **/
|
---|
174 |
|
---|
175 | struct wbcAuthUserParams {
|
---|
176 | const char *account_name;
|
---|
177 | const char *domain_name;
|
---|
178 | const char *workstation_name;
|
---|
179 |
|
---|
180 | uint32_t flags;
|
---|
181 |
|
---|
182 | uint32_t parameter_control;
|
---|
183 |
|
---|
184 | enum wbcAuthUserLevel {
|
---|
185 | WBC_AUTH_USER_LEVEL_PLAIN = 1,
|
---|
186 | WBC_AUTH_USER_LEVEL_HASH = 2,
|
---|
187 | WBC_AUTH_USER_LEVEL_RESPONSE = 3
|
---|
188 | } level;
|
---|
189 | union {
|
---|
190 | const char *plaintext;
|
---|
191 | struct {
|
---|
192 | uint8_t nt_hash[16];
|
---|
193 | uint8_t lm_hash[16];
|
---|
194 | } hash;
|
---|
195 | struct {
|
---|
196 | uint8_t challenge[8];
|
---|
197 | uint32_t nt_length;
|
---|
198 | uint8_t *nt_data;
|
---|
199 | uint32_t lm_length;
|
---|
200 | uint8_t *lm_data;
|
---|
201 | } response;
|
---|
202 | } password;
|
---|
203 | };
|
---|
204 |
|
---|
205 | /* wbcAuthUserParams->parameter_control */
|
---|
206 |
|
---|
207 | #define WBC_MSV1_0_CLEARTEXT_PASSWORD_ALLOWED 0x00000002
|
---|
208 | #define WBC_MSV1_0_UPDATE_LOGON_STATISTICS 0x00000004
|
---|
209 | #define WBC_MSV1_0_RETURN_USER_PARAMETERS 0x00000008
|
---|
210 | #define WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT 0x00000020
|
---|
211 | #define WBC_MSV1_0_RETURN_PROFILE_PATH 0x00000200
|
---|
212 | #define WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT 0x00000800
|
---|
213 |
|
---|
214 | /* wbcAuthUserParams->flags */
|
---|
215 |
|
---|
216 | #define WBC_AUTH_PARAM_FLAGS_INTERACTIVE_LOGON 0x00000001
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * @brief Auth User Information
|
---|
220 | *
|
---|
221 | * Some of the strings are maybe NULL
|
---|
222 | **/
|
---|
223 |
|
---|
224 | struct wbcAuthUserInfo {
|
---|
225 | uint32_t user_flags;
|
---|
226 |
|
---|
227 | char *account_name;
|
---|
228 | char *user_principal;
|
---|
229 | char *full_name;
|
---|
230 | char *domain_name;
|
---|
231 | char *dns_domain_name;
|
---|
232 |
|
---|
233 | uint32_t acct_flags;
|
---|
234 | uint8_t user_session_key[16];
|
---|
235 | uint8_t lm_session_key[8];
|
---|
236 |
|
---|
237 | uint16_t logon_count;
|
---|
238 | uint16_t bad_password_count;
|
---|
239 |
|
---|
240 | uint64_t logon_time;
|
---|
241 | uint64_t logoff_time;
|
---|
242 | uint64_t kickoff_time;
|
---|
243 | uint64_t pass_last_set_time;
|
---|
244 | uint64_t pass_can_change_time;
|
---|
245 | uint64_t pass_must_change_time;
|
---|
246 |
|
---|
247 | char *logon_server;
|
---|
248 | char *logon_script;
|
---|
249 | char *profile_path;
|
---|
250 | char *home_directory;
|
---|
251 | char *home_drive;
|
---|
252 |
|
---|
253 | /*
|
---|
254 | * the 1st one is the account sid
|
---|
255 | * the 2nd one is the primary_group sid
|
---|
256 | * followed by the rest of the groups
|
---|
257 | */
|
---|
258 | uint32_t num_sids;
|
---|
259 | struct wbcSidWithAttr *sids;
|
---|
260 | };
|
---|
261 |
|
---|
262 | /* wbcAuthUserInfo->user_flags */
|
---|
263 |
|
---|
264 | #define WBC_AUTH_USER_INFO_GUEST 0x00000001
|
---|
265 | #define WBC_AUTH_USER_INFO_NOENCRYPTION 0x00000002
|
---|
266 | #define WBC_AUTH_USER_INFO_CACHED_ACCOUNT 0x00000004
|
---|
267 | #define WBC_AUTH_USER_INFO_USED_LM_PASSWORD 0x00000008
|
---|
268 | #define WBC_AUTH_USER_INFO_EXTRA_SIDS 0x00000020
|
---|
269 | #define WBC_AUTH_USER_INFO_SUBAUTH_SESSION_KEY 0x00000040
|
---|
270 | #define WBC_AUTH_USER_INFO_SERVER_TRUST_ACCOUNT 0x00000080
|
---|
271 | #define WBC_AUTH_USER_INFO_NTLMV2_ENABLED 0x00000100
|
---|
272 | #define WBC_AUTH_USER_INFO_RESOURCE_GROUPS 0x00000200
|
---|
273 | #define WBC_AUTH_USER_INFO_PROFILE_PATH_RETURNED 0x00000400
|
---|
274 | #define WBC_AUTH_USER_INFO_GRACE_LOGON 0x01000000
|
---|
275 |
|
---|
276 | /* wbcAuthUserInfo->acct_flags */
|
---|
277 |
|
---|
278 | #define WBC_ACB_DISABLED 0x00000001 /* 1 User account disabled */
|
---|
279 | #define WBC_ACB_HOMDIRREQ 0x00000002 /* 1 Home directory required */
|
---|
280 | #define WBC_ACB_PWNOTREQ 0x00000004 /* 1 User password not required */
|
---|
281 | #define WBC_ACB_TEMPDUP 0x00000008 /* 1 Temporary duplicate account */
|
---|
282 | #define WBC_ACB_NORMAL 0x00000010 /* 1 Normal user account */
|
---|
283 | #define WBC_ACB_MNS 0x00000020 /* 1 MNS logon user account */
|
---|
284 | #define WBC_ACB_DOMTRUST 0x00000040 /* 1 Interdomain trust account */
|
---|
285 | #define WBC_ACB_WSTRUST 0x00000080 /* 1 Workstation trust account */
|
---|
286 | #define WBC_ACB_SVRTRUST 0x00000100 /* 1 Server trust account */
|
---|
287 | #define WBC_ACB_PWNOEXP 0x00000200 /* 1 User password does not expire */
|
---|
288 | #define WBC_ACB_AUTOLOCK 0x00000400 /* 1 Account auto locked */
|
---|
289 | #define WBC_ACB_ENC_TXT_PWD_ALLOWED 0x00000800 /* 1 Encryped text password is allowed */
|
---|
290 | #define WBC_ACB_SMARTCARD_REQUIRED 0x00001000 /* 1 Smart Card required */
|
---|
291 | #define WBC_ACB_TRUSTED_FOR_DELEGATION 0x00002000 /* 1 Trusted for Delegation */
|
---|
292 | #define WBC_ACB_NOT_DELEGATED 0x00004000 /* 1 Not delegated */
|
---|
293 | #define WBC_ACB_USE_DES_KEY_ONLY 0x00008000 /* 1 Use DES key only */
|
---|
294 | #define WBC_ACB_DONT_REQUIRE_PREAUTH 0x00010000 /* 1 Preauth not required */
|
---|
295 | #define WBC_ACB_PW_EXPIRED 0x00020000 /* 1 Password Expired */
|
---|
296 | #define WBC_ACB_NO_AUTH_DATA_REQD 0x00080000 /* 1 = No authorization data required */
|
---|
297 |
|
---|
298 | struct wbcAuthErrorInfo {
|
---|
299 | uint32_t nt_status;
|
---|
300 | char *nt_string;
|
---|
301 | int32_t pam_error;
|
---|
302 | char *display_string;
|
---|
303 | };
|
---|
304 |
|
---|
305 | /*
|
---|
306 | * Memory Management
|
---|
307 | */
|
---|
308 |
|
---|
309 | void wbcFreeMemory(void*);
|
---|
310 |
|
---|
311 |
|
---|
312 | /*
|
---|
313 | * Utility functions for dealing with SIDs
|
---|
314 | */
|
---|
315 |
|
---|
316 | wbcErr wbcSidToString(const struct wbcDomainSid *sid,
|
---|
317 | char **sid_string);
|
---|
318 |
|
---|
319 | wbcErr wbcStringToSid(const char *sid_string,
|
---|
320 | struct wbcDomainSid *sid);
|
---|
321 |
|
---|
322 | wbcErr wbcPing(void);
|
---|
323 |
|
---|
324 | wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
|
---|
325 |
|
---|
326 | wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
|
---|
327 |
|
---|
328 | /*
|
---|
329 | * Name/SID conversion
|
---|
330 | */
|
---|
331 |
|
---|
332 | wbcErr wbcLookupName(const char *dom_name,
|
---|
333 | const char *name,
|
---|
334 | struct wbcDomainSid *sid,
|
---|
335 | enum wbcSidType *name_type);
|
---|
336 |
|
---|
337 | wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
|
---|
338 | char **domain,
|
---|
339 | char **name,
|
---|
340 | enum wbcSidType *name_type);
|
---|
341 |
|
---|
342 | wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
|
---|
343 | int num_rids,
|
---|
344 | uint32_t *rids,
|
---|
345 | const char **domain_name,
|
---|
346 | const char ***names,
|
---|
347 | enum wbcSidType **types);
|
---|
348 |
|
---|
349 | wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
|
---|
350 | bool domain_groups_only,
|
---|
351 | uint32_t *num_sids,
|
---|
352 | struct wbcDomainSid **sids);
|
---|
353 |
|
---|
354 | wbcErr wbcListUsers(const char *domain_name,
|
---|
355 | uint32_t *num_users,
|
---|
356 | const char ***users);
|
---|
357 |
|
---|
358 | wbcErr wbcListGroups(const char *domain_name,
|
---|
359 | uint32_t *num_groups,
|
---|
360 | const char ***groups);
|
---|
361 |
|
---|
362 | /*
|
---|
363 | * SID/uid/gid Mappings
|
---|
364 | */
|
---|
365 |
|
---|
366 | wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
|
---|
367 | uid_t *puid);
|
---|
368 |
|
---|
369 | wbcErr wbcUidToSid(uid_t uid,
|
---|
370 | struct wbcDomainSid *sid);
|
---|
371 |
|
---|
372 | wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
|
---|
373 | gid_t *pgid);
|
---|
374 |
|
---|
375 | wbcErr wbcGidToSid(gid_t gid,
|
---|
376 | struct wbcDomainSid *sid);
|
---|
377 |
|
---|
378 | wbcErr wbcAllocateUid(uid_t *puid);
|
---|
379 |
|
---|
380 | wbcErr wbcAllocateGid(gid_t *pgid);
|
---|
381 |
|
---|
382 | wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid);
|
---|
383 |
|
---|
384 | wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid);
|
---|
385 |
|
---|
386 | wbcErr wbcSetUidHwm(uid_t uid_hwm);
|
---|
387 |
|
---|
388 | wbcErr wbcSetGidHwm(gid_t gid_hwm);
|
---|
389 |
|
---|
390 | /*
|
---|
391 | * NSS Lookup User/Group details
|
---|
392 | */
|
---|
393 |
|
---|
394 | wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
|
---|
395 |
|
---|
396 | wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
|
---|
397 |
|
---|
398 | wbcErr wbcGetgrnam(const char *name, struct group **grp);
|
---|
399 |
|
---|
400 | wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
|
---|
401 |
|
---|
402 | wbcErr wbcSetpwent(void);
|
---|
403 |
|
---|
404 | wbcErr wbcEndpwent(void);
|
---|
405 |
|
---|
406 | wbcErr wbcGetpwent(struct passwd **pwd);
|
---|
407 |
|
---|
408 | wbcErr wbcSetgrent(void);
|
---|
409 |
|
---|
410 | wbcErr wbcEndgrent(void);
|
---|
411 |
|
---|
412 | wbcErr wbcGetgrent(struct group **grp);
|
---|
413 |
|
---|
414 | wbcErr wbcGetGroups(const char *account,
|
---|
415 | uint32_t *num_groups,
|
---|
416 | gid_t **_groups);
|
---|
417 |
|
---|
418 |
|
---|
419 | /*
|
---|
420 | * Lookup Domain information
|
---|
421 | */
|
---|
422 |
|
---|
423 | wbcErr wbcDomainInfo(const char *domain,
|
---|
424 | struct wbcDomainInfo **info);
|
---|
425 |
|
---|
426 | wbcErr wbcListTrusts(struct wbcDomainInfo **domains,
|
---|
427 | size_t *num_domains);
|
---|
428 |
|
---|
429 |
|
---|
430 | /*
|
---|
431 | * Athenticate functions
|
---|
432 | */
|
---|
433 |
|
---|
434 | wbcErr wbcAuthenticateUser(const char *username,
|
---|
435 | const char *password);
|
---|
436 |
|
---|
437 | wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
|
---|
438 | struct wbcAuthUserInfo **info,
|
---|
439 | struct wbcAuthErrorInfo **error);
|
---|
440 |
|
---|
441 | /*
|
---|
442 | * Resolve functions
|
---|
443 | */
|
---|
444 | wbcErr wbcResolveWinsByName(const char *name, char **ip);
|
---|
445 | wbcErr wbcResolveWinsByIP(const char *ip, char **name);
|
---|
446 |
|
---|
447 | /*
|
---|
448 | * Trusted domain functions
|
---|
449 | */
|
---|
450 | wbcErr wbcCheckTrustCredentials(const char *domain,
|
---|
451 | struct wbcAuthErrorInfo **error);
|
---|
452 |
|
---|
453 | #endif /* _WBCLIENT_H */
|
---|