winbind: Extend wbcAuthenticateUserEx to provide PAC
[Samba/gebeck_regimport.git] / nsswitch / libwbclient / wbclient.h
blob473c9019d6755f1089c3a7dd59728908aa0922b0
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind client API
6 Copyright (C) Gerald (Jerry) Carter 2007
7 Copyright (C) Volker Lendecke 2009
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 3 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _WBCLIENT_H
24 #define _WBCLIENT_H
26 #include <pwd.h>
27 #include <grp.h>
29 /* Define error types */
31 /**
32 * @brief Status codes returned from wbc functions
33 **/
35 enum _wbcErrType {
36 WBC_ERR_SUCCESS = 0, /**< Successful completion **/
37 WBC_ERR_NOT_IMPLEMENTED,/**< Function not implemented **/
38 WBC_ERR_UNKNOWN_FAILURE,/**< General failure **/
39 WBC_ERR_NO_MEMORY, /**< Memory allocation error **/
40 WBC_ERR_INVALID_SID, /**< Invalid SID format **/
41 WBC_ERR_INVALID_PARAM, /**< An Invalid parameter was supplied **/
42 WBC_ERR_WINBIND_NOT_AVAILABLE, /**< Winbind daemon is not available **/
43 WBC_ERR_DOMAIN_NOT_FOUND, /**< Domain is not trusted or cannot be found **/
44 WBC_ERR_INVALID_RESPONSE, /**< Winbind returned an invalid response **/
45 WBC_ERR_NSS_ERROR, /**< NSS_STATUS error **/
46 WBC_ERR_AUTH_ERROR, /**< Authentication failed **/
47 WBC_ERR_UNKNOWN_USER, /**< User account cannot be found */
48 WBC_ERR_UNKNOWN_GROUP, /**< Group account cannot be found */
49 WBC_ERR_PWD_CHANGE_FAILED /**< Password Change has failed */
52 typedef enum _wbcErrType wbcErr;
54 #define WBC_ERROR_IS_OK(x) ((x) == WBC_ERR_SUCCESS)
56 const char *wbcErrorString(wbcErr error);
58 /**
59 * @brief Some useful details about the wbclient library
61 * 0.1: Initial version
62 * 0.2: Added wbcRemoveUidMapping()
63 * Added wbcRemoveGidMapping()
64 * 0.3: Added wbcGetpwsid()
65 * Added wbcGetSidAliases()
66 * 0.4: Added wbcSidTypeString()
67 * 0.5: Added wbcChangeTrustCredentials()
68 * 0.6: Made struct wbcInterfaceDetails char* members non-const
69 * 0.7: Added wbcSidToStringBuf()
70 * 0.8: Added wbcSidsToUnixIds() and wbcLookupSids()
71 * 0.9: Added support for WBC_ID_TYPE_BOTH
72 * 0.10: Added wbcPingDc2()
73 **/
74 #define WBCLIENT_MAJOR_VERSION 0
75 #define WBCLIENT_MINOR_VERSION 10
76 #define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
77 struct wbcLibraryDetails {
78 uint16_t major_version;
79 uint16_t minor_version;
80 const char *vendor_version;
83 /**
84 * @brief Some useful details about the running winbindd
86 **/
87 struct wbcInterfaceDetails {
88 uint32_t interface_version;
89 char *winbind_version;
90 char winbind_separator;
91 char *netbios_name;
92 char *netbios_domain;
93 char *dns_domain;
97 * Data types used by the Winbind Client API
100 #ifndef WBC_MAXSUBAUTHS
101 #define WBC_MAXSUBAUTHS 15 /* max sub authorities in a SID */
102 #endif
105 * @brief Windows Security Identifier
109 struct wbcDomainSid {
110 uint8_t sid_rev_num;
111 uint8_t num_auths;
112 uint8_t id_auth[6];
113 uint32_t sub_auths[WBC_MAXSUBAUTHS];
117 * @brief Security Identifier type
120 enum wbcSidType {
121 WBC_SID_NAME_USE_NONE=0,
122 WBC_SID_NAME_USER=1,
123 WBC_SID_NAME_DOM_GRP=2,
124 WBC_SID_NAME_DOMAIN=3,
125 WBC_SID_NAME_ALIAS=4,
126 WBC_SID_NAME_WKN_GRP=5,
127 WBC_SID_NAME_DELETED=6,
128 WBC_SID_NAME_INVALID=7,
129 WBC_SID_NAME_UNKNOWN=8,
130 WBC_SID_NAME_COMPUTER=9
134 * @brief Security Identifier with attributes
137 struct wbcSidWithAttr {
138 struct wbcDomainSid sid;
139 uint32_t attributes;
142 /* wbcSidWithAttr->attributes */
144 #define WBC_SID_ATTR_GROUP_MANDATORY 0x00000001
145 #define WBC_SID_ATTR_GROUP_ENABLED_BY_DEFAULT 0x00000002
146 #define WBC_SID_ATTR_GROUP_ENABLED 0x00000004
147 #define WBC_SID_ATTR_GROUP_OWNER 0x00000008
148 #define WBC_SID_ATTR_GROUP_USEFOR_DENY_ONLY 0x00000010
149 #define WBC_SID_ATTR_GROUP_RESOURCE 0x20000000
150 #define WBC_SID_ATTR_GROUP_LOGON_ID 0xC0000000
153 * @brief Windows GUID
157 struct wbcGuid {
158 uint32_t time_low;
159 uint16_t time_mid;
160 uint16_t time_hi_and_version;
161 uint8_t clock_seq[2];
162 uint8_t node[6];
166 * @brief Domain Information
169 struct wbcDomainInfo {
170 char *short_name;
171 char *dns_name;
172 struct wbcDomainSid sid;
173 uint32_t domain_flags;
174 uint32_t trust_flags;
175 uint32_t trust_type;
178 /* wbcDomainInfo->domain_flags */
180 #define WBC_DOMINFO_DOMAIN_UNKNOWN 0x00000000
181 #define WBC_DOMINFO_DOMAIN_NATIVE 0x00000001
182 #define WBC_DOMINFO_DOMAIN_AD 0x00000002
183 #define WBC_DOMINFO_DOMAIN_PRIMARY 0x00000004
184 #define WBC_DOMINFO_DOMAIN_OFFLINE 0x00000008
186 /* wbcDomainInfo->trust_flags */
188 #define WBC_DOMINFO_TRUST_TRANSITIVE 0x00000001
189 #define WBC_DOMINFO_TRUST_INCOMING 0x00000002
190 #define WBC_DOMINFO_TRUST_OUTGOING 0x00000004
192 /* wbcDomainInfo->trust_type */
194 #define WBC_DOMINFO_TRUSTTYPE_NONE 0x00000000
195 #define WBC_DOMINFO_TRUSTTYPE_FOREST 0x00000001
196 #define WBC_DOMINFO_TRUSTTYPE_IN_FOREST 0x00000002
197 #define WBC_DOMINFO_TRUSTTYPE_EXTERNAL 0x00000003
200 * @brief Generic Blob
203 struct wbcBlob {
204 uint8_t *data;
205 size_t length;
209 * @brief Named Blob
212 struct wbcNamedBlob {
213 const char *name;
214 uint32_t flags;
215 struct wbcBlob blob;
219 * @brief Auth User Parameters
222 struct wbcAuthUserParams {
223 const char *account_name;
224 const char *domain_name;
225 const char *workstation_name;
227 uint32_t flags;
229 uint32_t parameter_control;
231 enum wbcAuthUserLevel {
232 WBC_AUTH_USER_LEVEL_PLAIN = 1,
233 WBC_AUTH_USER_LEVEL_HASH = 2,
234 WBC_AUTH_USER_LEVEL_RESPONSE = 3,
235 WBC_AUTH_USER_LEVEL_PAC = 4
236 } level;
237 union {
238 const char *plaintext;
239 struct {
240 uint8_t nt_hash[16];
241 uint8_t lm_hash[16];
242 } hash;
243 struct {
244 uint8_t challenge[8];
245 uint32_t nt_length;
246 uint8_t *nt_data;
247 uint32_t lm_length;
248 uint8_t *lm_data;
249 } response;
250 struct wbcBlob pac;
251 } password;
255 * @brief Logon User Parameters
258 struct wbcLogonUserParams {
259 const char *username;
260 const char *password;
261 size_t num_blobs;
262 struct wbcNamedBlob *blobs;
266 * @brief ChangePassword Parameters
269 struct wbcChangePasswordParams {
270 const char *account_name;
271 const char *domain_name;
273 uint32_t flags;
275 enum wbcChangePasswordLevel {
276 WBC_CHANGE_PASSWORD_LEVEL_PLAIN = 1,
277 WBC_CHANGE_PASSWORD_LEVEL_RESPONSE = 2
278 } level;
280 union {
281 const char *plaintext;
282 struct {
283 uint32_t old_nt_hash_enc_length;
284 uint8_t *old_nt_hash_enc_data;
285 uint32_t old_lm_hash_enc_length;
286 uint8_t *old_lm_hash_enc_data;
287 } response;
288 } old_password;
289 union {
290 const char *plaintext;
291 struct {
292 uint32_t nt_length;
293 uint8_t *nt_data;
294 uint32_t lm_length;
295 uint8_t *lm_data;
296 } response;
297 } new_password;
300 /* wbcAuthUserParams->parameter_control */
302 #define WBC_MSV1_0_CLEARTEXT_PASSWORD_ALLOWED 0x00000002
303 #define WBC_MSV1_0_UPDATE_LOGON_STATISTICS 0x00000004
304 #define WBC_MSV1_0_RETURN_USER_PARAMETERS 0x00000008
305 #define WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT 0x00000020
306 #define WBC_MSV1_0_RETURN_PROFILE_PATH 0x00000200
307 #define WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT 0x00000800
309 /* wbcAuthUserParams->flags */
311 #define WBC_AUTH_PARAM_FLAGS_INTERACTIVE_LOGON 0x00000001
314 * @brief Auth User Information
316 * Some of the strings are maybe NULL
319 struct wbcAuthUserInfo {
320 uint32_t user_flags;
322 char *account_name;
323 char *user_principal;
324 char *full_name;
325 char *domain_name;
326 char *dns_domain_name;
328 uint32_t acct_flags;
329 uint8_t user_session_key[16];
330 uint8_t lm_session_key[8];
332 uint16_t logon_count;
333 uint16_t bad_password_count;
335 uint64_t logon_time;
336 uint64_t logoff_time;
337 uint64_t kickoff_time;
338 uint64_t pass_last_set_time;
339 uint64_t pass_can_change_time;
340 uint64_t pass_must_change_time;
342 char *logon_server;
343 char *logon_script;
344 char *profile_path;
345 char *home_directory;
346 char *home_drive;
349 * the 1st one is the account sid
350 * the 2nd one is the primary_group sid
351 * followed by the rest of the groups
353 uint32_t num_sids;
354 struct wbcSidWithAttr *sids;
358 * @brief Logon User Information
360 * Some of the strings are maybe NULL
363 struct wbcLogonUserInfo {
364 struct wbcAuthUserInfo *info;
365 size_t num_blobs;
366 struct wbcNamedBlob *blobs;
369 /* wbcAuthUserInfo->user_flags */
371 #define WBC_AUTH_USER_INFO_GUEST 0x00000001
372 #define WBC_AUTH_USER_INFO_NOENCRYPTION 0x00000002
373 #define WBC_AUTH_USER_INFO_CACHED_ACCOUNT 0x00000004
374 #define WBC_AUTH_USER_INFO_USED_LM_PASSWORD 0x00000008
375 #define WBC_AUTH_USER_INFO_EXTRA_SIDS 0x00000020
376 #define WBC_AUTH_USER_INFO_SUBAUTH_SESSION_KEY 0x00000040
377 #define WBC_AUTH_USER_INFO_SERVER_TRUST_ACCOUNT 0x00000080
378 #define WBC_AUTH_USER_INFO_NTLMV2_ENABLED 0x00000100
379 #define WBC_AUTH_USER_INFO_RESOURCE_GROUPS 0x00000200
380 #define WBC_AUTH_USER_INFO_PROFILE_PATH_RETURNED 0x00000400
381 #define WBC_AUTH_USER_INFO_GRACE_LOGON 0x01000000
383 /* wbcAuthUserInfo->acct_flags */
385 #define WBC_ACB_DISABLED 0x00000001 /* 1 User account disabled */
386 #define WBC_ACB_HOMDIRREQ 0x00000002 /* 1 Home directory required */
387 #define WBC_ACB_PWNOTREQ 0x00000004 /* 1 User password not required */
388 #define WBC_ACB_TEMPDUP 0x00000008 /* 1 Temporary duplicate account */
389 #define WBC_ACB_NORMAL 0x00000010 /* 1 Normal user account */
390 #define WBC_ACB_MNS 0x00000020 /* 1 MNS logon user account */
391 #define WBC_ACB_DOMTRUST 0x00000040 /* 1 Interdomain trust account */
392 #define WBC_ACB_WSTRUST 0x00000080 /* 1 Workstation trust account */
393 #define WBC_ACB_SVRTRUST 0x00000100 /* 1 Server trust account */
394 #define WBC_ACB_PWNOEXP 0x00000200 /* 1 User password does not expire */
395 #define WBC_ACB_AUTOLOCK 0x00000400 /* 1 Account auto locked */
396 #define WBC_ACB_ENC_TXT_PWD_ALLOWED 0x00000800 /* 1 Encryped text password is allowed */
397 #define WBC_ACB_SMARTCARD_REQUIRED 0x00001000 /* 1 Smart Card required */
398 #define WBC_ACB_TRUSTED_FOR_DELEGATION 0x00002000 /* 1 Trusted for Delegation */
399 #define WBC_ACB_NOT_DELEGATED 0x00004000 /* 1 Not delegated */
400 #define WBC_ACB_USE_DES_KEY_ONLY 0x00008000 /* 1 Use DES key only */
401 #define WBC_ACB_DONT_REQUIRE_PREAUTH 0x00010000 /* 1 Preauth not required */
402 #define WBC_ACB_PW_EXPIRED 0x00020000 /* 1 Password Expired */
403 #define WBC_ACB_NO_AUTH_DATA_REQD 0x00080000 /* 1 = No authorization data required */
405 struct wbcAuthErrorInfo {
406 uint32_t nt_status;
407 char *nt_string;
408 int32_t pam_error;
409 char *display_string;
413 * @brief User Password Policy Information
416 /* wbcUserPasswordPolicyInfo->password_properties */
418 #define WBC_DOMAIN_PASSWORD_COMPLEX 0x00000001
419 #define WBC_DOMAIN_PASSWORD_NO_ANON_CHANGE 0x00000002
420 #define WBC_DOMAIN_PASSWORD_NO_CLEAR_CHANGE 0x00000004
421 #define WBC_DOMAIN_PASSWORD_LOCKOUT_ADMINS 0x00000008
422 #define WBC_DOMAIN_PASSWORD_STORE_CLEARTEXT 0x00000010
423 #define WBC_DOMAIN_REFUSE_PASSWORD_CHANGE 0x00000020
425 struct wbcUserPasswordPolicyInfo {
426 uint32_t min_length_password;
427 uint32_t password_history;
428 uint32_t password_properties;
429 uint64_t expire;
430 uint64_t min_passwordage;
434 * @brief Change Password Reject Reason
437 enum wbcPasswordChangeRejectReason {
438 WBC_PWD_CHANGE_NO_ERROR=0,
439 WBC_PWD_CHANGE_PASSWORD_TOO_SHORT=1,
440 WBC_PWD_CHANGE_PWD_IN_HISTORY=2,
441 WBC_PWD_CHANGE_USERNAME_IN_PASSWORD=3,
442 WBC_PWD_CHANGE_FULLNAME_IN_PASSWORD=4,
443 WBC_PWD_CHANGE_NOT_COMPLEX=5,
444 WBC_PWD_CHANGE_MACHINE_NOT_DEFAULT=6,
445 WBC_PWD_CHANGE_FAILED_BY_FILTER=7,
446 WBC_PWD_CHANGE_PASSWORD_TOO_LONG=8
449 /* Note: this defines exist for compatibility reasons with existing code */
450 #define WBC_PWD_CHANGE_REJECT_OTHER WBC_PWD_CHANGE_NO_ERROR
451 #define WBC_PWD_CHANGE_REJECT_TOO_SHORT WBC_PWD_CHANGE_PASSWORD_TOO_SHORT
452 #define WBC_PWD_CHANGE_REJECT_IN_HISTORY WBC_PWD_CHANGE_PWD_IN_HISTORY
453 #define WBC_PWD_CHANGE_REJECT_COMPLEXITY WBC_PWD_CHANGE_NOT_COMPLEX
456 * @brief Logoff User Parameters
459 struct wbcLogoffUserParams {
460 const char *username;
461 size_t num_blobs;
462 struct wbcNamedBlob *blobs;
465 /** @brief Credential cache log-on parameters
469 struct wbcCredentialCacheParams {
470 const char *account_name;
471 const char *domain_name;
472 enum wbcCredentialCacheLevel {
473 WBC_CREDENTIAL_CACHE_LEVEL_NTLMSSP = 1
474 } level;
475 size_t num_blobs;
476 struct wbcNamedBlob *blobs;
480 /** @brief Info returned by credential cache auth
484 struct wbcCredentialCacheInfo {
485 size_t num_blobs;
486 struct wbcNamedBlob *blobs;
490 * DomainControllerInfo struct
492 struct wbcDomainControllerInfo {
493 char *dc_name;
497 * DomainControllerInfoEx struct
499 struct wbcDomainControllerInfoEx {
500 const char *dc_unc;
501 const char *dc_address;
502 uint16_t dc_address_type;
503 struct wbcGuid *domain_guid;
504 const char *domain_name;
505 const char *forest_name;
506 uint32_t dc_flags;
507 const char *dc_site_name;
508 const char *client_site_name;
511 /**********************************************************
512 * Memory Management
513 **********************************************************/
516 * @brief Free library allocated memory
518 * @param * Pointer to free
520 * @return void
522 void wbcFreeMemory(void*);
526 * Utility functions for dealing with SIDs
530 * @brief Get a string representation of the SID type
532 * @param type type of the SID
534 * @return string representation of the SID type
536 const char* wbcSidTypeString(enum wbcSidType type);
538 #define WBC_SID_STRING_BUFLEN (15*11+25)
541 * @brief Print a sid into a buffer
543 * @param sid Binary Security Identifier
544 * @param buf Target buffer
545 * @param buflen Target buffer length
547 * @return Resulting string length.
549 int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen);
552 * @brief Convert a binary SID to a character string
554 * @param sid Binary Security Identifier
555 * @param **sid_string Resulting character string
557 * @return #wbcErr
559 wbcErr wbcSidToString(const struct wbcDomainSid *sid,
560 char **sid_string);
563 * @brief Convert a character string to a binary SID
565 * @param *sid_string Character string in the form of S-...
566 * @param sid Resulting binary SID
568 * @return #wbcErr
570 wbcErr wbcStringToSid(const char *sid_string,
571 struct wbcDomainSid *sid);
574 * Utility functions for dealing with GUIDs
578 * @brief Convert a binary GUID to a character string
580 * @param guid Binary Guid
581 * @param **guid_string Resulting character string
583 * @return #wbcErr
585 wbcErr wbcGuidToString(const struct wbcGuid *guid,
586 char **guid_string);
589 * @brief Convert a character string to a binary GUID
591 * @param *guid_string Character string
592 * @param guid Resulting binary GUID
594 * @return #wbcErr
596 wbcErr wbcStringToGuid(const char *guid_string,
597 struct wbcGuid *guid);
600 * @brief Ping winbindd to see if the daemon is running
602 * @return #wbcErr
604 wbcErr wbcPing(void);
606 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
608 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
610 /**********************************************************
611 * Name/SID conversion
612 **********************************************************/
615 * @brief Convert a domain and name to SID
617 * @param dom_name Domain name (possibly "")
618 * @param name User or group name
619 * @param *sid Pointer to the resolved domain SID
620 * @param *name_type Pointer to the SID type
622 * @return #wbcErr
624 wbcErr wbcLookupName(const char *dom_name,
625 const char *name,
626 struct wbcDomainSid *sid,
627 enum wbcSidType *name_type);
630 * @brief Convert a SID to a domain and name
632 * @param *sid Pointer to the domain SID to be resolved
633 * @param domain Resolved Domain name (possibly "")
634 * @param name Resolved User or group name
635 * @param *name_type Pointer to the resolved SID type
637 * @return #wbcErr
639 wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
640 char **domain,
641 char **name,
642 enum wbcSidType *name_type);
644 struct wbcTranslatedName {
645 enum wbcSidType type;
646 char *name;
647 int domain_index;
650 wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
651 struct wbcDomainInfo **domains, int *num_domains,
652 struct wbcTranslatedName **names);
655 * @brief Translate a collection of RIDs within a domain to names
657 wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
658 int num_rids,
659 uint32_t *rids,
660 const char **domain_name,
661 const char ***names,
662 enum wbcSidType **types);
665 * @brief Get the groups a user belongs to
667 wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
668 bool domain_groups_only,
669 uint32_t *num_sids,
670 struct wbcDomainSid **sids);
673 * @brief Get alias membership for sids
675 wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
676 struct wbcDomainSid *sids,
677 uint32_t num_sids,
678 uint32_t **alias_rids,
679 uint32_t *num_alias_rids);
682 * @brief Lists Users
684 wbcErr wbcListUsers(const char *domain_name,
685 uint32_t *num_users,
686 const char ***users);
689 * @brief Lists Groups
691 wbcErr wbcListGroups(const char *domain_name,
692 uint32_t *num_groups,
693 const char ***groups);
695 wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
696 char **pdomain,
697 char **pfullname,
698 enum wbcSidType *pname_type);
700 /**********************************************************
701 * SID/uid/gid Mappings
702 **********************************************************/
705 * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
707 * @param *sid Pointer to the domain SID to be resolved
708 * @param *puid Pointer to the resolved uid_t value
710 * @return #wbcErr
713 wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
714 uid_t *puid);
717 * @brief Convert a Windows SID to a Unix uid if there already is a mapping
719 * @param *sid Pointer to the domain SID to be resolved
720 * @param *puid Pointer to the resolved uid_t value
722 * @return #wbcErr
725 wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
726 uid_t *puid);
729 * @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
731 * @param uid Unix uid to be resolved
732 * @param *sid Pointer to the resolved domain SID
734 * @return #wbcErr
737 wbcErr wbcUidToSid(uid_t uid,
738 struct wbcDomainSid *sid);
741 * @brief Convert a Unix uid to a Windows SID if there already is a mapping
743 * @param uid Unix uid to be resolved
744 * @param *sid Pointer to the resolved domain SID
746 * @return #wbcErr
749 wbcErr wbcQueryUidToSid(uid_t uid,
750 struct wbcDomainSid *sid);
753 * @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
755 * @param *sid Pointer to the domain SID to be resolved
756 * @param *pgid Pointer to the resolved gid_t value
758 * @return #wbcErr
761 wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
762 gid_t *pgid);
765 * @brief Convert a Windows SID to a Unix gid if there already is a mapping
767 * @param *sid Pointer to the domain SID to be resolved
768 * @param *pgid Pointer to the resolved gid_t value
770 * @return #wbcErr
773 wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
774 gid_t *pgid);
777 * @brief Convert a Unix gid to a Windows SID, allocating a SID if needed
779 * @param gid Unix gid to be resolved
780 * @param *sid Pointer to the resolved domain SID
782 * @return #wbcErr
785 wbcErr wbcGidToSid(gid_t gid,
786 struct wbcDomainSid *sid);
789 * @brief Convert a Unix gid to a Windows SID if there already is a mapping
791 * @param gid Unix gid to be resolved
792 * @param *sid Pointer to the resolved domain SID
794 * @return #wbcErr
797 wbcErr wbcQueryGidToSid(gid_t gid,
798 struct wbcDomainSid *sid);
800 enum wbcIdType {
801 WBC_ID_TYPE_NOT_SPECIFIED,
802 WBC_ID_TYPE_UID,
803 WBC_ID_TYPE_GID,
804 WBC_ID_TYPE_BOTH
807 union wbcUnixIdContainer {
808 uid_t uid;
809 gid_t gid;
812 struct wbcUnixId {
813 enum wbcIdType type;
814 union wbcUnixIdContainer id;
818 * @brief Convert a list of sids to unix ids
820 * @param sids Pointer to an array of SIDs to convert
821 * @param num_sids Number of SIDs
822 * @param ids Preallocated output array for translated IDs
824 * @return #wbcErr
827 wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
828 struct wbcUnixId *ids);
831 * @brief Obtain a new uid from Winbind
833 * @param *puid *pointer to the allocated uid
835 * @return #wbcErr
837 wbcErr wbcAllocateUid(uid_t *puid);
840 * @brief Obtain a new gid from Winbind
842 * @param *pgid Pointer to the allocated gid
844 * @return #wbcErr
846 wbcErr wbcAllocateGid(gid_t *pgid);
849 * @brief Set an user id mapping
851 * @param uid Uid of the desired mapping.
852 * @param *sid Pointer to the sid of the diresired mapping.
854 * @return #wbcErr
856 * @deprecated This method is not impemented any more and should
857 * be removed in the next major version change.
859 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid);
862 * @brief Set a group id mapping
864 * @param gid Gid of the desired mapping.
865 * @param *sid Pointer to the sid of the diresired mapping.
867 * @return #wbcErr
869 * @deprecated This method is not impemented any more and should
870 * be removed in the next major version change.
872 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid);
875 * @brief Remove a user id mapping
877 * @param uid Uid of the mapping to remove.
878 * @param *sid Pointer to the sid of the mapping to remove.
880 * @return #wbcErr
882 * @deprecated This method is not impemented any more and should
883 * be removed in the next major version change.
885 wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid);
888 * @brief Remove a group id mapping
890 * @param gid Gid of the mapping to remove.
891 * @param *sid Pointer to the sid of the mapping to remove.
893 * @return #wbcErr
895 * @deprecated This method is not impemented any more and should
896 * be removed in the next major version change.
898 wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid);
901 * @brief Set the highwater mark for allocated uids.
903 * @param uid_hwm The new uid highwater mark value
905 * @return #wbcErr
907 * @deprecated This method is not impemented any more and should
908 * be removed in the next major version change.
910 wbcErr wbcSetUidHwm(uid_t uid_hwm);
913 * @brief Set the highwater mark for allocated gids.
915 * @param gid_hwm The new gid highwater mark value
917 * @return #wbcErr
919 * @deprecated This method is not impemented any more and should
920 * be removed in the next major version change.
922 wbcErr wbcSetGidHwm(gid_t gid_hwm);
924 /**********************************************************
925 * NSS Lookup User/Group details
926 **********************************************************/
929 * @brief Fill in a struct passwd* for a domain user based
930 * on username
932 * @param *name Username to lookup
933 * @param **pwd Pointer to resulting struct passwd* from the query.
935 * @return #wbcErr
937 wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
940 * @brief Fill in a struct passwd* for a domain user based
941 * on uid
943 * @param uid Uid to lookup
944 * @param **pwd Pointer to resulting struct passwd* from the query.
946 * @return #wbcErr
948 wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
951 * @brief Fill in a struct passwd* for a domain user based
952 * on sid
954 * @param sid Sid to lookup
955 * @param **pwd Pointer to resulting struct passwd* from the query.
957 * @return #wbcErr
959 wbcErr wbcGetpwsid(struct wbcDomainSid * sid, struct passwd **pwd);
962 * @brief Fill in a struct passwd* for a domain user based
963 * on username
965 * @param *name Username to lookup
966 * @param **grp Pointer to resulting struct group* from the query.
968 * @return #wbcErr
970 wbcErr wbcGetgrnam(const char *name, struct group **grp);
973 * @brief Fill in a struct passwd* for a domain user based
974 * on uid
976 * @param gid Uid to lookup
977 * @param **grp Pointer to resulting struct group* from the query.
979 * @return #wbcErr
981 wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
984 * @brief Reset the passwd iterator
986 * @return #wbcErr
988 wbcErr wbcSetpwent(void);
991 * @brief Close the passwd iterator
993 * @return #wbcErr
995 wbcErr wbcEndpwent(void);
998 * @brief Return the next struct passwd* entry from the pwent iterator
1000 * @param **pwd Pointer to resulting struct passwd* from the query.
1002 * @return #wbcErr
1004 wbcErr wbcGetpwent(struct passwd **pwd);
1007 * @brief Reset the group iterator
1009 * @return #wbcErr
1011 wbcErr wbcSetgrent(void);
1014 * @brief Close the group iterator
1016 * @return #wbcErr
1018 wbcErr wbcEndgrent(void);
1021 * @brief Return the next struct group* entry from the pwent iterator
1023 * @param **grp Pointer to resulting struct group* from the query.
1025 * @return #wbcErr
1027 wbcErr wbcGetgrent(struct group **grp);
1030 * @brief Return the next struct group* entry from the pwent iterator
1032 * This is similar to #wbcGetgrent, just that the member list is empty
1034 * @param **grp Pointer to resulting struct group* from the query.
1036 * @return #wbcErr
1038 wbcErr wbcGetgrlist(struct group **grp);
1041 * @brief Return the unix group array belonging to the given user
1043 * @param *account The given user name
1044 * @param *num_groups Number of elements returned in the groups array
1045 * @param **_groups Pointer to resulting gid_t array.
1047 * @return #wbcErr
1049 wbcErr wbcGetGroups(const char *account,
1050 uint32_t *num_groups,
1051 gid_t **_groups);
1054 /**********************************************************
1055 * Lookup Domain information
1056 **********************************************************/
1059 * @brief Lookup the current status of a trusted domain
1061 * @param domain The domain to query
1063 * @param dinfo A pointer to store the returned domain_info struct.
1065 * @return #wbcErr
1067 wbcErr wbcDomainInfo(const char *domain,
1068 struct wbcDomainInfo **dinfo);
1071 * @brief Lookup the currently contacted DCs
1073 * @param domain The domain to query
1075 * @param num_dcs Number of DCs currently known
1076 * @param dc_names Names of the currently known DCs
1077 * @param dc_ips IP addresses of the currently known DCs
1079 * @return #wbcErr
1081 wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
1082 const char ***dc_names, const char ***dc_ips);
1085 * @brief Enumerate the domain trusts known by Winbind
1087 * @param **domains Pointer to the allocated domain list array
1088 * @param *num_domains Pointer to number of domains returned
1090 * @return #wbcErr
1092 wbcErr wbcListTrusts(struct wbcDomainInfo **domains,
1093 size_t *num_domains);
1095 /* Flags for wbcLookupDomainController */
1097 #define WBC_LOOKUP_DC_FORCE_REDISCOVERY 0x00000001
1098 #define WBC_LOOKUP_DC_DS_REQUIRED 0x00000010
1099 #define WBC_LOOKUP_DC_DS_PREFERRED 0x00000020
1100 #define WBC_LOOKUP_DC_GC_SERVER_REQUIRED 0x00000040
1101 #define WBC_LOOKUP_DC_PDC_REQUIRED 0x00000080
1102 #define WBC_LOOKUP_DC_BACKGROUND_ONLY 0x00000100
1103 #define WBC_LOOKUP_DC_IP_REQUIRED 0x00000200
1104 #define WBC_LOOKUP_DC_KDC_REQUIRED 0x00000400
1105 #define WBC_LOOKUP_DC_TIMESERV_REQUIRED 0x00000800
1106 #define WBC_LOOKUP_DC_WRITABLE_REQUIRED 0x00001000
1107 #define WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED 0x00002000
1108 #define WBC_LOOKUP_DC_AVOID_SELF 0x00004000
1109 #define WBC_LOOKUP_DC_ONLY_LDAP_NEEDED 0x00008000
1110 #define WBC_LOOKUP_DC_IS_FLAT_NAME 0x00010000
1111 #define WBC_LOOKUP_DC_IS_DNS_NAME 0x00020000
1112 #define WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE 0x00040000
1113 #define WBC_LOOKUP_DC_DS_6_REQUIRED 0x00080000
1114 #define WBC_LOOKUP_DC_RETURN_DNS_NAME 0x40000000
1115 #define WBC_LOOKUP_DC_RETURN_FLAT_NAME 0x80000000
1118 * @brief Enumerate the domain trusts known by Winbind
1120 * @param domain Name of the domain to query for a DC
1121 * @param flags Bit flags used to control the domain location query
1122 * @param *dc_info Pointer to the returned domain controller information
1124 * @return #wbcErr
1126 wbcErr wbcLookupDomainController(const char *domain,
1127 uint32_t flags,
1128 struct wbcDomainControllerInfo **dc_info);
1131 * @brief Get extended domain controller information
1133 * @param domain Name of the domain to query for a DC
1134 * @param guid Guid of the domain to query for a DC
1135 * @param site Site of the domain to query for a DC
1136 * @param flags Bit flags used to control the domain location query
1137 * @param *dc_info Pointer to the returned extended domain controller information
1139 * @return #wbcErr
1141 wbcErr wbcLookupDomainControllerEx(const char *domain,
1142 struct wbcGuid *guid,
1143 const char *site,
1144 uint32_t flags,
1145 struct wbcDomainControllerInfoEx **dc_info);
1147 /**********************************************************
1148 * Athenticate functions
1149 **********************************************************/
1152 * @brief Authenticate a username/password pair
1154 * @param username Name of user to authenticate
1155 * @param password Clear text password os user
1157 * @return #wbcErr
1159 wbcErr wbcAuthenticateUser(const char *username,
1160 const char *password);
1163 * @brief Authenticate with more detailed information
1165 * @param params Input parameters, WBC_AUTH_USER_LEVEL_HASH
1166 * is not supported yet
1167 * @param info Output details on WBC_ERR_SUCCESS
1168 * @param error Output details on WBC_ERR_AUTH_ERROR
1170 * @return #wbcErr
1172 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
1173 struct wbcAuthUserInfo **info,
1174 struct wbcAuthErrorInfo **error);
1177 * @brief Logon a User
1179 * @param[in] params Pointer to a wbcLogonUserParams structure
1180 * @param[out] info Pointer to a pointer to a wbcLogonUserInfo structure
1181 * @param[out] error Pointer to a pointer to a wbcAuthErrorInfo structure
1182 * @param[out] policy Pointer to a pointer to a wbcUserPasswordPolicyInfo structure
1184 * @return #wbcErr
1186 wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
1187 struct wbcLogonUserInfo **info,
1188 struct wbcAuthErrorInfo **error,
1189 struct wbcUserPasswordPolicyInfo **policy);
1192 * @brief Trigger a logoff notification to Winbind for a specific user
1194 * @param username Name of user to remove from Winbind's list of
1195 * logged on users.
1196 * @param uid Uid assigned to the username
1197 * @param ccfilename Absolute path to the Krb5 credentials cache to
1198 * be removed
1200 * @return #wbcErr
1202 wbcErr wbcLogoffUser(const char *username,
1203 uid_t uid,
1204 const char *ccfilename);
1207 * @brief Trigger an extended logoff notification to Winbind for a specific user
1209 * @param params A wbcLogoffUserParams structure
1210 * @param error User output details on error
1212 * @return #wbcErr
1214 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
1215 struct wbcAuthErrorInfo **error);
1218 * @brief Change a password for a user
1220 * @param username Name of user to authenticate
1221 * @param old_password Old clear text password of user
1222 * @param new_password New clear text password of user
1224 * @return #wbcErr
1226 wbcErr wbcChangeUserPassword(const char *username,
1227 const char *old_password,
1228 const char *new_password);
1231 * @brief Change a password for a user with more detailed information upon
1232 * failure
1234 * @param params Input parameters
1235 * @param error User output details on WBC_ERR_PWD_CHANGE_FAILED
1236 * @param reject_reason New password reject reason on WBC_ERR_PWD_CHANGE_FAILED
1237 * @param policy Password policy output details on WBC_ERR_PWD_CHANGE_FAILED
1239 * @return #wbcErr
1241 wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
1242 struct wbcAuthErrorInfo **error,
1243 enum wbcPasswordChangeRejectReason *reject_reason,
1244 struct wbcUserPasswordPolicyInfo **policy);
1247 * @brief Authenticate a user with cached credentials
1249 * @param *params Pointer to a wbcCredentialCacheParams structure
1250 * @param **info Pointer to a pointer to a wbcCredentialCacheInfo structure
1251 * @param **error Pointer to a pointer to a wbcAuthErrorInfo structure
1253 * @return #wbcErr
1255 wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
1256 struct wbcCredentialCacheInfo **info,
1257 struct wbcAuthErrorInfo **error);
1260 * @brief Save a password with winbind for doing wbcCredentialCache() later
1262 * @param *user Username
1263 * @param *password Password
1265 * @return #wbcErr
1267 wbcErr wbcCredentialSave(const char *user, const char *password);
1269 /**********************************************************
1270 * Resolve functions
1271 **********************************************************/
1274 * @brief Resolve a NetbiosName via WINS
1276 * @param name Name to resolve
1277 * @param *ip Pointer to the ip address string
1279 * @return #wbcErr
1281 wbcErr wbcResolveWinsByName(const char *name, char **ip);
1284 * @brief Resolve an IP address via WINS into a NetbiosName
1286 * @param ip The ip address string
1287 * @param *name Pointer to the name
1289 * @return #wbcErr
1292 wbcErr wbcResolveWinsByIP(const char *ip, char **name);
1294 /**********************************************************
1295 * Trusted domain functions
1296 **********************************************************/
1299 * @brief Trigger a verification of the trust credentials of a specific domain
1301 * @param *domain The name of the domain.
1302 * @param error Output details on WBC_ERR_AUTH_ERROR
1304 * @return #wbcErr
1306 wbcErr wbcCheckTrustCredentials(const char *domain,
1307 struct wbcAuthErrorInfo **error);
1310 * @brief Trigger a change of the trust credentials for a specific domain
1312 * @param *domain The name of the domain.
1313 * @param error Output details on WBC_ERR_AUTH_ERROR
1315 * @return #wbcErr
1317 wbcErr wbcChangeTrustCredentials(const char *domain,
1318 struct wbcAuthErrorInfo **error);
1321 * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
1322 * version of wbcCheckTrustCredentials
1324 * @param *domain The name of the domain, only NULL for the default domain is
1325 * supported yet. Other values than NULL will result in
1326 * WBC_ERR_NOT_IMPLEMENTED.
1327 * @param error Output details on WBC_ERR_AUTH_ERROR
1329 * @return #wbcErr
1331 wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error);
1334 * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
1335 * version of wbcCheckTrustCredentials
1337 * @param *domain The name of the domain, only NULL for the default domain is
1338 * supported yet. Other values than NULL will result in
1339 * WBC_ERR_NOT_IMPLEMENTED.
1340 * @param error Output details on WBC_ERR_AUTH_ERROR
1341 * @param dcname DC that was attempted to ping
1343 * @return #wbcErr
1345 wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
1346 char **dcname);
1348 /**********************************************************
1349 * Helper functions
1350 **********************************************************/
1353 * @brief Initialize a named blob and add to list of blobs
1355 * @param[in,out] num_blobs Pointer to the number of blobs
1356 * @param[in,out] blobs Pointer to an array of blobs
1357 * @param[in] name Name of the new named blob
1358 * @param[in] flags Flags of the new named blob
1359 * @param[in] data Blob data of new blob
1360 * @param[in] length Blob data length of new blob
1362 * @return #wbcErr
1364 wbcErr wbcAddNamedBlob(size_t *num_blobs,
1365 struct wbcNamedBlob **blobs,
1366 const char *name,
1367 uint32_t flags,
1368 uint8_t *data,
1369 size_t length);
1371 #endif /* _WBCLIENT_H */