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 */
48 WBC_ERR_PWD_CHANGE_FAILED /**< Password Change has failed */
51 typedef enum _wbcErrType wbcErr;
53 #define WBC_ERROR_IS_OK(x) ((x) == WBC_ERR_SUCCESS)
55 const char *wbcErrorString(wbcErr error);
58 * @brief Some useful details about the wbclient library
61 #define WBCLIENT_MAJOR_VERSION 0
62 #define WBCLIENT_MINOR_VERSION 1
63 #define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
64 struct wbcLibraryDetails {
65 uint16_t major_version;
66 uint16_t minor_version;
67 const char *vendor_version;
71 * @brief Some useful details about the running winbindd
74 struct wbcInterfaceDetails {
75 uint32_t interface_version;
76 const char *winbind_version;
77 char winbind_separator;
78 const char *netbios_name;
79 const char *netbios_domain;
80 const char *dns_domain;
84 * Data types used by the Winbind Client API
87 #ifndef WBC_MAXSUBAUTHS
88 #define WBC_MAXSUBAUTHS 15 /* max sub authorities in a SID */
92 * @brief Windows Security Identifier
100 uint32_t sub_auths[WBC_MAXSUBAUTHS];
104 * @brief Security Identifier type
108 WBC_SID_NAME_USE_NONE=0,
110 WBC_SID_NAME_DOM_GRP=2,
111 WBC_SID_NAME_DOMAIN=3,
112 WBC_SID_NAME_ALIAS=4,
113 WBC_SID_NAME_WKN_GRP=5,
114 WBC_SID_NAME_DELETED=6,
115 WBC_SID_NAME_INVALID=7,
116 WBC_SID_NAME_UNKNOWN=8,
117 WBC_SID_NAME_COMPUTER=9
121 * @brief Security Identifier with attributes
124 struct wbcSidWithAttr {
125 struct wbcDomainSid sid;
129 /* wbcSidWithAttr->attributes */
131 #define WBC_SID_ATTR_GROUP_MANDATORY 0x00000001
132 #define WBC_SID_ATTR_GROUP_ENABLED_BY_DEFAULT 0x00000002
133 #define WBC_SID_ATTR_GROUP_ENABLED 0x00000004
134 #define WBC_SID_ATTR_GROUP_OWNER 0x00000008
135 #define WBC_SID_ATTR_GROUP_USEFOR_DENY_ONLY 0x00000010
136 #define WBC_SID_ATTR_GROUP_RESOURCE 0x20000000
137 #define WBC_SID_ATTR_GROUP_LOGON_ID 0xC0000000
140 * @brief Windows GUID
147 uint16_t time_hi_and_version;
148 uint8_t clock_seq[2];
153 * @brief Domain Information
156 struct wbcDomainInfo {
159 struct wbcDomainSid sid;
160 uint32_t domain_flags;
161 uint32_t trust_flags;
165 /* wbcDomainInfo->domain_flags */
167 #define WBC_DOMINFO_DOMAIN_UNKNOWN 0x00000000
168 #define WBC_DOMINFO_DOMAIN_NATIVE 0x00000001
169 #define WBC_DOMINFO_DOMAIN_AD 0x00000002
170 #define WBC_DOMINFO_DOMAIN_PRIMARY 0x00000004
171 #define WBC_DOMINFO_DOMAIN_OFFLINE 0x00000008
173 /* wbcDomainInfo->trust_flags */
175 #define WBC_DOMINFO_TRUST_TRANSITIVE 0x00000001
176 #define WBC_DOMINFO_TRUST_INCOMING 0x00000002
177 #define WBC_DOMINFO_TRUST_OUTGOING 0x00000004
179 /* wbcDomainInfo->trust_type */
181 #define WBC_DOMINFO_TRUSTTYPE_NONE 0x00000000
182 #define WBC_DOMINFO_TRUSTTYPE_FOREST 0x00000001
183 #define WBC_DOMINFO_TRUSTTYPE_IN_FOREST 0x00000002
184 #define WBC_DOMINFO_TRUSTTYPE_EXTERNAL 0x00000003
188 * @brief Auth User Parameters
191 struct wbcAuthUserParams {
192 const char *account_name;
193 const char *domain_name;
194 const char *workstation_name;
198 uint32_t parameter_control;
200 enum wbcAuthUserLevel {
201 WBC_AUTH_USER_LEVEL_PLAIN = 1,
202 WBC_AUTH_USER_LEVEL_HASH = 2,
203 WBC_AUTH_USER_LEVEL_RESPONSE = 3
206 const char *plaintext;
212 uint8_t challenge[8];
222 * @brief Generic Blob
234 struct wbcNamedBlob {
241 * @brief Logon User Parameters
244 struct wbcLogonUserParams {
245 const char *username;
246 const char *password;
248 struct wbcNamedBlob *blobs;
252 * @brief ChangePassword Parameters
255 struct wbcChangePasswordParams {
256 const char *account_name;
257 const char *domain_name;
261 enum wbcChangePasswordLevel {
262 WBC_CHANGE_PASSWORD_LEVEL_PLAIN = 1,
263 WBC_CHANGE_PASSWORD_LEVEL_RESPONSE = 2
267 const char *plaintext;
269 uint32_t old_nt_hash_enc_length;
270 uint8_t *old_nt_hash_enc_data;
271 uint32_t old_lm_hash_enc_length;
272 uint8_t *old_lm_hash_enc_data;
276 const char *plaintext;
286 /* wbcAuthUserParams->parameter_control */
288 #define WBC_MSV1_0_CLEARTEXT_PASSWORD_ALLOWED 0x00000002
289 #define WBC_MSV1_0_UPDATE_LOGON_STATISTICS 0x00000004
290 #define WBC_MSV1_0_RETURN_USER_PARAMETERS 0x00000008
291 #define WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT 0x00000020
292 #define WBC_MSV1_0_RETURN_PROFILE_PATH 0x00000200
293 #define WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT 0x00000800
295 /* wbcAuthUserParams->flags */
297 #define WBC_AUTH_PARAM_FLAGS_INTERACTIVE_LOGON 0x00000001
300 * @brief Auth User Information
302 * Some of the strings are maybe NULL
305 struct wbcAuthUserInfo {
309 char *user_principal;
312 char *dns_domain_name;
315 uint8_t user_session_key[16];
316 uint8_t lm_session_key[8];
318 uint16_t logon_count;
319 uint16_t bad_password_count;
322 uint64_t logoff_time;
323 uint64_t kickoff_time;
324 uint64_t pass_last_set_time;
325 uint64_t pass_can_change_time;
326 uint64_t pass_must_change_time;
331 char *home_directory;
335 * the 1st one is the account sid
336 * the 2nd one is the primary_group sid
337 * followed by the rest of the groups
340 struct wbcSidWithAttr *sids;
344 * @brief Logon User Information
346 * Some of the strings are maybe NULL
349 struct wbcLogonUserInfo {
350 struct wbcAuthUserInfo *info;
352 struct wbcNamedBlob *blobs;
355 /* wbcAuthUserInfo->user_flags */
357 #define WBC_AUTH_USER_INFO_GUEST 0x00000001
358 #define WBC_AUTH_USER_INFO_NOENCRYPTION 0x00000002
359 #define WBC_AUTH_USER_INFO_CACHED_ACCOUNT 0x00000004
360 #define WBC_AUTH_USER_INFO_USED_LM_PASSWORD 0x00000008
361 #define WBC_AUTH_USER_INFO_EXTRA_SIDS 0x00000020
362 #define WBC_AUTH_USER_INFO_SUBAUTH_SESSION_KEY 0x00000040
363 #define WBC_AUTH_USER_INFO_SERVER_TRUST_ACCOUNT 0x00000080
364 #define WBC_AUTH_USER_INFO_NTLMV2_ENABLED 0x00000100
365 #define WBC_AUTH_USER_INFO_RESOURCE_GROUPS 0x00000200
366 #define WBC_AUTH_USER_INFO_PROFILE_PATH_RETURNED 0x00000400
367 #define WBC_AUTH_USER_INFO_GRACE_LOGON 0x01000000
369 /* wbcAuthUserInfo->acct_flags */
371 #define WBC_ACB_DISABLED 0x00000001 /* 1 User account disabled */
372 #define WBC_ACB_HOMDIRREQ 0x00000002 /* 1 Home directory required */
373 #define WBC_ACB_PWNOTREQ 0x00000004 /* 1 User password not required */
374 #define WBC_ACB_TEMPDUP 0x00000008 /* 1 Temporary duplicate account */
375 #define WBC_ACB_NORMAL 0x00000010 /* 1 Normal user account */
376 #define WBC_ACB_MNS 0x00000020 /* 1 MNS logon user account */
377 #define WBC_ACB_DOMTRUST 0x00000040 /* 1 Interdomain trust account */
378 #define WBC_ACB_WSTRUST 0x00000080 /* 1 Workstation trust account */
379 #define WBC_ACB_SVRTRUST 0x00000100 /* 1 Server trust account */
380 #define WBC_ACB_PWNOEXP 0x00000200 /* 1 User password does not expire */
381 #define WBC_ACB_AUTOLOCK 0x00000400 /* 1 Account auto locked */
382 #define WBC_ACB_ENC_TXT_PWD_ALLOWED 0x00000800 /* 1 Encryped text password is allowed */
383 #define WBC_ACB_SMARTCARD_REQUIRED 0x00001000 /* 1 Smart Card required */
384 #define WBC_ACB_TRUSTED_FOR_DELEGATION 0x00002000 /* 1 Trusted for Delegation */
385 #define WBC_ACB_NOT_DELEGATED 0x00004000 /* 1 Not delegated */
386 #define WBC_ACB_USE_DES_KEY_ONLY 0x00008000 /* 1 Use DES key only */
387 #define WBC_ACB_DONT_REQUIRE_PREAUTH 0x00010000 /* 1 Preauth not required */
388 #define WBC_ACB_PW_EXPIRED 0x00020000 /* 1 Password Expired */
389 #define WBC_ACB_NO_AUTH_DATA_REQD 0x00080000 /* 1 = No authorization data required */
391 struct wbcAuthErrorInfo {
395 char *display_string;
399 * @brief User Password Policy Information
402 /* wbcUserPasswordPolicyInfo->password_properties */
404 #define WBC_DOMAIN_PASSWORD_COMPLEX 0x00000001
405 #define WBC_DOMAIN_PASSWORD_NO_ANON_CHANGE 0x00000002
406 #define WBC_DOMAIN_PASSWORD_NO_CLEAR_CHANGE 0x00000004
407 #define WBC_DOMAIN_PASSWORD_LOCKOUT_ADMINS 0x00000008
408 #define WBC_DOMAIN_PASSWORD_STORE_CLEARTEXT 0x00000010
409 #define WBC_DOMAIN_REFUSE_PASSWORD_CHANGE 0x00000020
411 struct wbcUserPasswordPolicyInfo {
412 uint32_t min_length_password;
413 uint32_t password_history;
414 uint32_t password_properties;
416 uint64_t min_passwordage;
420 * @brief Change Password Reject Reason
423 enum wbcPasswordChangeRejectReason {
424 WBC_PWD_CHANGE_REJECT_OTHER=0,
425 WBC_PWD_CHANGE_REJECT_TOO_SHORT=1,
426 WBC_PWD_CHANGE_REJECT_IN_HISTORY=2,
427 WBC_PWD_CHANGE_REJECT_COMPLEXITY=5
431 * @brief Logoff User Parameters
434 struct wbcLogoffUserParams {
435 const char *username;
437 struct wbcNamedBlob *blobs;
441 * DomainControllerInfo struct
443 struct wbcDomainControllerInfo {
448 * DomainControllerInfoEx struct
450 struct wbcDomainControllerInfoEx {
452 const char *dc_address;
453 uint16_t dc_address_type;
454 struct wbcGuid *domain_guid;
455 const char *domain_name;
456 const char *forest_name;
458 const char *dc_site_name;
459 const char *client_site_name;
466 void wbcFreeMemory(void*);
470 * Utility functions for dealing with SIDs
473 wbcErr wbcSidToString(const struct wbcDomainSid *sid,
476 wbcErr wbcStringToSid(const char *sid_string,
477 struct wbcDomainSid *sid);
480 * Utility functions for dealing with GUIDs
483 wbcErr wbcGuidToString(const struct wbcGuid *guid,
486 wbcErr wbcStringToGuid(const char *guid_string,
487 struct wbcGuid *guid);
489 wbcErr wbcPing(void);
491 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
493 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
496 * Name/SID conversion
499 wbcErr wbcLookupName(const char *dom_name,
501 struct wbcDomainSid *sid,
502 enum wbcSidType *name_type);
504 wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
507 enum wbcSidType *name_type);
509 wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
512 const char **domain_name,
514 enum wbcSidType **types);
516 wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
517 bool domain_groups_only,
519 struct wbcDomainSid **sids);
521 wbcErr wbcListUsers(const char *domain_name,
523 const char ***users);
525 wbcErr wbcListGroups(const char *domain_name,
526 uint32_t *num_groups,
527 const char ***groups);
530 * SID/uid/gid Mappings
533 wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
536 wbcErr wbcUidToSid(uid_t uid,
537 struct wbcDomainSid *sid);
539 wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
542 wbcErr wbcGidToSid(gid_t gid,
543 struct wbcDomainSid *sid);
545 wbcErr wbcAllocateUid(uid_t *puid);
547 wbcErr wbcAllocateGid(gid_t *pgid);
549 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid);
551 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid);
553 wbcErr wbcSetUidHwm(uid_t uid_hwm);
555 wbcErr wbcSetGidHwm(gid_t gid_hwm);
558 * NSS Lookup User/Group details
561 wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
563 wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
565 wbcErr wbcGetgrnam(const char *name, struct group **grp);
567 wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
569 wbcErr wbcSetpwent(void);
571 wbcErr wbcEndpwent(void);
573 wbcErr wbcGetpwent(struct passwd **pwd);
575 wbcErr wbcSetgrent(void);
577 wbcErr wbcEndgrent(void);
579 wbcErr wbcGetgrent(struct group **grp);
581 wbcErr wbcGetGroups(const char *account,
582 uint32_t *num_groups,
587 * Lookup Domain information
590 wbcErr wbcDomainInfo(const char *domain,
591 struct wbcDomainInfo **info);
593 wbcErr wbcListTrusts(struct wbcDomainInfo **domains,
594 size_t *num_domains);
596 /* Flags for wbcLookupDomainController */
598 #define WBC_LOOKUP_DC_FORCE_REDISCOVERY 0x00000001
599 #define WBC_LOOKUP_DC_DS_REQUIRED 0x00000010
600 #define WBC_LOOKUP_DC_DS_PREFERRED 0x00000020
601 #define WBC_LOOKUP_DC_GC_SERVER_REQUIRED 0x00000040
602 #define WBC_LOOKUP_DC_PDC_REQUIRED 0x00000080
603 #define WBC_LOOKUP_DC_BACKGROUND_ONLY 0x00000100
604 #define WBC_LOOKUP_DC_IP_REQUIRED 0x00000200
605 #define WBC_LOOKUP_DC_KDC_REQUIRED 0x00000400
606 #define WBC_LOOKUP_DC_TIMESERV_REQUIRED 0x00000800
607 #define WBC_LOOKUP_DC_WRITABLE_REQUIRED 0x00001000
608 #define WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED 0x00002000
609 #define WBC_LOOKUP_DC_AVOID_SELF 0x00004000
610 #define WBC_LOOKUP_DC_ONLY_LDAP_NEEDED 0x00008000
611 #define WBC_LOOKUP_DC_IS_FLAT_NAME 0x00010000
612 #define WBC_LOOKUP_DC_IS_DNS_NAME 0x00020000
613 #define WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE 0x00040000
614 #define WBC_LOOKUP_DC_DS_6_REQUIRED 0x00080000
615 #define WBC_LOOKUP_DC_RETURN_DNS_NAME 0x40000000
616 #define WBC_LOOKUP_DC_RETURN_FLAT_NAME 0x80000000
618 wbcErr wbcLookupDomainController(const char *domain,
620 struct wbcDomainControllerInfo **dc_info);
622 wbcErr wbcLookupDomainControllerEx(const char *domain,
623 struct wbcGuid *guid,
626 struct wbcDomainControllerInfoEx **dc_info);
629 * Athenticate functions
632 wbcErr wbcAuthenticateUser(const char *username,
633 const char *password);
635 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
636 struct wbcAuthUserInfo **info,
637 struct wbcAuthErrorInfo **error);
639 wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
640 struct wbcLogonUserInfo **info,
641 struct wbcAuthErrorInfo **error,
642 struct wbcUserPasswordPolicyInfo **policy);
644 wbcErr wbcLogoffUser(const char *username,
646 const char *ccfilename);
648 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
649 struct wbcAuthErrorInfo **error);
651 wbcErr wbcChangeUserPassword(const char *username,
652 const char *old_password,
653 const char *new_password);
655 wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
656 struct wbcAuthErrorInfo **error,
657 enum wbcPasswordChangeRejectReason *reject_reason,
658 struct wbcUserPasswordPolicyInfo **policy);
663 wbcErr wbcResolveWinsByName(const char *name, char **ip);
664 wbcErr wbcResolveWinsByIP(const char *ip, char **name);
667 * Trusted domain functions
669 wbcErr wbcCheckTrustCredentials(const char *domain,
670 struct wbcAuthErrorInfo **error);
674 wbcErr wbcAddNamedBlob(size_t *num_blobs,
675 struct wbcNamedBlob **blobs,
681 #endif /* _WBCLIENT_H */