2 Unix SMB/CIFS implementation.
6 Copyright (C) Gerald (Jerry) Carter 2007
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.
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.
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/>.
28 /* Define error types */
31 * @brief Status codes returned from wbc functions
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 WBC_ERR_UNKNOWN_USER, /**< User account cannot be found */
47 WBC_ERR_UNKNOWN_GROUP /**< Group account cannot be found */
50 typedef enum _wbcErrType wbcErr;
52 #define WBC_ERROR_IS_OK(x) ((x) == WBC_ERR_SUCCESS)
54 const char *wbcErrorString(wbcErr error);
57 * @brief Some useful details about the wbclient library
60 #define WBCLIENT_MAJOR_VERSION 0
61 #define WBCLIENT_MINOR_VERSION 1
62 #define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
63 struct wbcLibraryDetails {
64 uint16_t major_version;
65 uint16_t minor_version;
66 const char *vendor_version;
70 * @brief Some useful details about the running winbindd
73 struct wbcInterfaceDetails {
74 uint32_t interface_version;
75 const char *winbind_version;
76 char winbind_separator;
77 const char *netbios_name;
78 const char *netbios_domain;
79 const char *dns_domain;
83 * Data types used by the Winbind Client API
86 #ifndef WBC_MAXSUBAUTHS
87 #define WBC_MAXSUBAUTHS 15 /* max sub authorities in a SID */
91 * @brief Windows Security Identifier
99 uint32_t sub_auths[WBC_MAXSUBAUTHS];
103 * @brief Security Identifier type
107 WBC_SID_NAME_USE_NONE=0,
109 WBC_SID_NAME_DOM_GRP=2,
110 WBC_SID_NAME_DOMAIN=3,
111 WBC_SID_NAME_ALIAS=4,
112 WBC_SID_NAME_WKN_GRP=5,
113 WBC_SID_NAME_DELETED=6,
114 WBC_SID_NAME_INVALID=7,
115 WBC_SID_NAME_UNKNOWN=8,
116 WBC_SID_NAME_COMPUTER=9
120 * @brief Security Identifier with attributes
123 struct wbcSidWithAttr {
124 struct wbcDomainSid sid;
128 /* wbcSidWithAttr->attributes */
130 #define WBC_SID_ATTR_GROUP_MANDATORY 0x00000001
131 #define WBC_SID_ATTR_GROUP_ENABLED_BY_DEFAULT 0x00000002
132 #define WBC_SID_ATTR_GROUP_ENABLED 0x00000004
133 #define WBC_SID_ATTR_GROUP_OWNER 0x00000008
134 #define WBC_SID_ATTR_GROUP_USEFOR_DENY_ONLY 0x00000010
135 #define WBC_SID_ATTR_GROUP_RESOURCE 0x20000000
136 #define WBC_SID_ATTR_GROUP_LOGON_ID 0xC0000000
139 * @brief Domain Information
142 struct wbcDomainInfo {
145 struct wbcDomainSid sid;
146 uint32_t domain_flags;
147 uint32_t trust_flags;
151 /* wbcDomainInfo->domain_flags */
153 #define WBC_DOMINFO_DOMAIN_UNKNOWN 0x00000000
154 #define WBC_DOMINFO_DOMAIN_NATIVE 0x00000001
155 #define WBC_DOMINFO_DOMAIN_AD 0x00000002
156 #define WBC_DOMINFO_DOMAIN_PRIMARY 0x00000004
157 #define WBC_DOMINFO_DOMAIN_OFFLINE 0x00000008
159 /* wbcDomainInfo->trust_flags */
161 #define WBC_DOMINFO_TRUST_TRANSITIVE 0x00000001
162 #define WBC_DOMINFO_TRUST_INCOMING 0x00000002
163 #define WBC_DOMINFO_TRUST_OUTGOING 0x00000004
165 /* wbcDomainInfo->trust_type */
167 #define WBC_DOMINFO_TRUSTTYPE_NONE 0x00000000
168 #define WBC_DOMINFO_TRUSTTYPE_FOREST 0x00000001
169 #define WBC_DOMINFO_TRUSTTYPE_IN_FOREST 0x00000002
170 #define WBC_DOMINFO_TRUSTTYPE_EXTERNAL 0x00000003
174 * @brief Auth User Parameters
177 struct wbcAuthUserParams {
178 const char *account_name;
179 const char *domain_name;
180 const char *workstation_name;
184 uint32_t parameter_control;
186 enum wbcAuthUserLevel {
187 WBC_AUTH_USER_LEVEL_PLAIN = 1,
188 WBC_AUTH_USER_LEVEL_HASH = 2,
189 WBC_AUTH_USER_LEVEL_RESPONSE = 3
192 const char *plaintext;
198 uint8_t challenge[8];
207 /* wbcAuthUserParams->parameter_control */
209 #define WBC_MSV1_0_CLEARTEXT_PASSWORD_ALLOWED 0x00000002
210 #define WBC_MSV1_0_UPDATE_LOGON_STATISTICS 0x00000004
211 #define WBC_MSV1_0_RETURN_USER_PARAMETERS 0x00000008
212 #define WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT 0x00000020
213 #define WBC_MSV1_0_RETURN_PROFILE_PATH 0x00000200
214 #define WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT 0x00000800
216 /* wbcAuthUserParams->flags */
218 #define WBC_AUTH_PARAM_FLAGS_INTERACTIVE_LOGON 0x00000001
221 * @brief Auth User Information
223 * Some of the strings are maybe NULL
226 struct wbcAuthUserInfo {
230 char *user_principal;
233 char *dns_domain_name;
236 uint8_t user_session_key[16];
237 uint8_t lm_session_key[8];
239 uint16_t logon_count;
240 uint16_t bad_password_count;
243 uint64_t logoff_time;
244 uint64_t kickoff_time;
245 uint64_t pass_last_set_time;
246 uint64_t pass_can_change_time;
247 uint64_t pass_must_change_time;
252 char *home_directory;
256 * the 1st one is the account sid
257 * the 2nd one is the primary_group sid
258 * followed by the rest of the groups
261 struct wbcSidWithAttr *sids;
264 /* wbcAuthUserInfo->user_flags */
266 #define WBC_AUTH_USER_INFO_GUEST 0x00000001
267 #define WBC_AUTH_USER_INFO_NOENCRYPTION 0x00000002
268 #define WBC_AUTH_USER_INFO_CACHED_ACCOUNT 0x00000004
269 #define WBC_AUTH_USER_INFO_USED_LM_PASSWORD 0x00000008
270 #define WBC_AUTH_USER_INFO_EXTRA_SIDS 0x00000020
271 #define WBC_AUTH_USER_INFO_SUBAUTH_SESSION_KEY 0x00000040
272 #define WBC_AUTH_USER_INFO_SERVER_TRUST_ACCOUNT 0x00000080
273 #define WBC_AUTH_USER_INFO_NTLMV2_ENABLED 0x00000100
274 #define WBC_AUTH_USER_INFO_RESOURCE_GROUPS 0x00000200
275 #define WBC_AUTH_USER_INFO_PROFILE_PATH_RETURNED 0x00000400
276 #define WBC_AUTH_USER_INFO_GRACE_LOGON 0x01000000
278 /* wbcAuthUserInfo->acct_flags */
280 #define WBC_ACB_DISABLED 0x00000001 /* 1 User account disabled */
281 #define WBC_ACB_HOMDIRREQ 0x00000002 /* 1 Home directory required */
282 #define WBC_ACB_PWNOTREQ 0x00000004 /* 1 User password not required */
283 #define WBC_ACB_TEMPDUP 0x00000008 /* 1 Temporary duplicate account */
284 #define WBC_ACB_NORMAL 0x00000010 /* 1 Normal user account */
285 #define WBC_ACB_MNS 0x00000020 /* 1 MNS logon user account */
286 #define WBC_ACB_DOMTRUST 0x00000040 /* 1 Interdomain trust account */
287 #define WBC_ACB_WSTRUST 0x00000080 /* 1 Workstation trust account */
288 #define WBC_ACB_SVRTRUST 0x00000100 /* 1 Server trust account */
289 #define WBC_ACB_PWNOEXP 0x00000200 /* 1 User password does not expire */
290 #define WBC_ACB_AUTOLOCK 0x00000400 /* 1 Account auto locked */
291 #define WBC_ACB_ENC_TXT_PWD_ALLOWED 0x00000800 /* 1 Encryped text password is allowed */
292 #define WBC_ACB_SMARTCARD_REQUIRED 0x00001000 /* 1 Smart Card required */
293 #define WBC_ACB_TRUSTED_FOR_DELEGATION 0x00002000 /* 1 Trusted for Delegation */
294 #define WBC_ACB_NOT_DELEGATED 0x00004000 /* 1 Not delegated */
295 #define WBC_ACB_USE_DES_KEY_ONLY 0x00008000 /* 1 Use DES key only */
296 #define WBC_ACB_DONT_REQUIRE_PREAUTH 0x00010000 /* 1 Preauth not required */
297 #define WBC_ACB_PW_EXPIRED 0x00020000 /* 1 Password Expired */
298 #define WBC_ACB_NO_AUTH_DATA_REQD 0x00080000 /* 1 = No authorization data required */
300 struct wbcAuthErrorInfo {
304 char *display_string;
308 * DomainControllerInfo struct
310 struct wbcDomainControllerInfo {
320 void wbcFreeMemory(void*);
324 * Utility functions for dealing with SIDs
327 wbcErr wbcSidToString(const struct wbcDomainSid *sid,
330 wbcErr wbcStringToSid(const char *sid_string,
331 struct wbcDomainSid *sid);
333 wbcErr wbcPing(void);
335 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
337 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
340 * Name/SID conversion
343 wbcErr wbcLookupName(const char *dom_name,
345 struct wbcDomainSid *sid,
346 enum wbcSidType *name_type);
348 wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
351 enum wbcSidType *name_type);
353 wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
356 const char **domain_name,
358 enum wbcSidType **types);
360 wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
361 bool domain_groups_only,
363 struct wbcDomainSid **sids);
365 wbcErr wbcListUsers(const char *domain_name,
367 const char ***users);
369 wbcErr wbcListGroups(const char *domain_name,
370 uint32_t *num_groups,
371 const char ***groups);
374 * SID/uid/gid Mappings
377 wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
380 wbcErr wbcUidToSid(uid_t uid,
381 struct wbcDomainSid *sid);
383 wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
386 wbcErr wbcGidToSid(gid_t gid,
387 struct wbcDomainSid *sid);
389 wbcErr wbcAllocateUid(uid_t *puid);
391 wbcErr wbcAllocateGid(gid_t *pgid);
393 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid);
395 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid);
397 wbcErr wbcSetUidHwm(uid_t uid_hwm);
399 wbcErr wbcSetGidHwm(gid_t gid_hwm);
402 * NSS Lookup User/Group details
405 wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
407 wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
409 wbcErr wbcGetgrnam(const char *name, struct group **grp);
411 wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
413 wbcErr wbcSetpwent(void);
415 wbcErr wbcEndpwent(void);
417 wbcErr wbcGetpwent(struct passwd **pwd);
419 wbcErr wbcSetgrent(void);
421 wbcErr wbcEndgrent(void);
423 wbcErr wbcGetgrent(struct group **grp);
425 wbcErr wbcGetGroups(const char *account,
426 uint32_t *num_groups,
431 * Lookup Domain information
434 wbcErr wbcDomainInfo(const char *domain,
435 struct wbcDomainInfo **info);
437 wbcErr wbcListTrusts(struct wbcDomainInfo **domains,
438 size_t *num_domains);
440 /* Flags for wbcLookupDomainController */
442 #define WBC_LOOKUP_DC_FORCE_REDISCOVERY 0x00000001
443 #define WBC_LOOKUP_DC_DS_REQUIRED 0x00000010
444 #define WBC_LOOKUP_DC_DS_PREFERRED 0x00000020
445 #define WBC_LOOKUP_DC_GC_SERVER_REQUIRED 0x00000040
446 #define WBC_LOOKUP_DC_PDC_REQUIRED 0x00000080
447 #define WBC_LOOKUP_DC_BACKGROUND_ONLY 0x00000100
448 #define WBC_LOOKUP_DC_IP_REQUIRED 0x00000200
449 #define WBC_LOOKUP_DC_KDC_REQUIRED 0x00000400
450 #define WBC_LOOKUP_DC_TIMESERV_REQUIRED 0x00000800
451 #define WBC_LOOKUP_DC_WRITABLE_REQUIRED 0x00001000
452 #define WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED 0x00002000
453 #define WBC_LOOKUP_DC_AVOID_SELF 0x00004000
454 #define WBC_LOOKUP_DC_ONLY_LDAP_NEEDED 0x00008000
455 #define WBC_LOOKUP_DC_IS_FLAT_NAME 0x00010000
456 #define WBC_LOOKUP_DC_IS_DNS_NAME 0x00020000
457 #define WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE 0x00040000
458 #define WBC_LOOKUP_DC_DS_6_REQUIRED 0x00080000
459 #define WBC_LOOKUP_DC_RETURN_DNS_NAME 0x40000000
460 #define WBC_LOOKUP_DC_RETURN_FLAT_NAME 0x80000000
462 wbcErr wbcLookupDomainController(const char *domain,
464 struct wbcDomainControllerInfo **dc_info);
467 * Athenticate functions
470 wbcErr wbcAuthenticateUser(const char *username,
471 const char *password);
473 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
474 struct wbcAuthUserInfo **info,
475 struct wbcAuthErrorInfo **error);
477 wbcErr wbcLogoffUser(const char *username,
479 const char *ccfilename);
485 wbcErr wbcResolveWinsByName(const char *name, char **ip);
486 wbcErr wbcResolveWinsByIP(const char *ip, char **name);
489 * Trusted domain functions
491 wbcErr wbcCheckTrustCredentials(const char *domain,
492 struct wbcAuthErrorInfo **error);
495 #endif /* _WBCLIENT_H */