s3:winbindd: s/struct event_context/struct tevent_context
[Samba/gebeck_regimport.git] / nsswitch / libwbclient / wbclient.h
bloba72d09e1d300ba31c0c16c5e515e066957cc496c
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 * 0.11: Extended wbcAuthenticateUserEx to provide PAC parsing
74 **/
75 #define WBCLIENT_MAJOR_VERSION 0
76 #define WBCLIENT_MINOR_VERSION 11
77 #define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
78 struct wbcLibraryDetails {
79 uint16_t major_version;
80 uint16_t minor_version;
81 const char *vendor_version;
84 /**
85 * @brief Some useful details about the running winbindd
87 **/
88 struct wbcInterfaceDetails {
89 uint32_t interface_version;
90 char *winbind_version;
91 char winbind_separator;
92 char *netbios_name;
93 char *netbios_domain;
94 char *dns_domain;
98 * Data types used by the Winbind Client API
101 #ifndef WBC_MAXSUBAUTHS
102 #define WBC_MAXSUBAUTHS 15 /* max sub authorities in a SID */
103 #endif
106 * @brief Windows Security Identifier
110 struct wbcDomainSid {
111 uint8_t sid_rev_num;
112 uint8_t num_auths;
113 uint8_t id_auth[6];
114 uint32_t sub_auths[WBC_MAXSUBAUTHS];
118 * @brief Security Identifier type
121 enum wbcSidType {
122 WBC_SID_NAME_USE_NONE=0,
123 WBC_SID_NAME_USER=1,
124 WBC_SID_NAME_DOM_GRP=2,
125 WBC_SID_NAME_DOMAIN=3,
126 WBC_SID_NAME_ALIAS=4,
127 WBC_SID_NAME_WKN_GRP=5,
128 WBC_SID_NAME_DELETED=6,
129 WBC_SID_NAME_INVALID=7,
130 WBC_SID_NAME_UNKNOWN=8,
131 WBC_SID_NAME_COMPUTER=9
135 * @brief Security Identifier with attributes
138 struct wbcSidWithAttr {
139 struct wbcDomainSid sid;
140 uint32_t attributes;
143 /* wbcSidWithAttr->attributes */
145 #define WBC_SID_ATTR_GROUP_MANDATORY 0x00000001
146 #define WBC_SID_ATTR_GROUP_ENABLED_BY_DEFAULT 0x00000002
147 #define WBC_SID_ATTR_GROUP_ENABLED 0x00000004
148 #define WBC_SID_ATTR_GROUP_OWNER 0x00000008
149 #define WBC_SID_ATTR_GROUP_USEFOR_DENY_ONLY 0x00000010
150 #define WBC_SID_ATTR_GROUP_RESOURCE 0x20000000
151 #define WBC_SID_ATTR_GROUP_LOGON_ID 0xC0000000
154 * @brief Windows GUID
158 struct wbcGuid {
159 uint32_t time_low;
160 uint16_t time_mid;
161 uint16_t time_hi_and_version;
162 uint8_t clock_seq[2];
163 uint8_t node[6];
167 * @brief Domain Information
170 struct wbcDomainInfo {
171 char *short_name;
172 char *dns_name;
173 struct wbcDomainSid sid;
174 uint32_t domain_flags;
175 uint32_t trust_flags;
176 uint32_t trust_type;
179 /* wbcDomainInfo->domain_flags */
181 #define WBC_DOMINFO_DOMAIN_UNKNOWN 0x00000000
182 #define WBC_DOMINFO_DOMAIN_NATIVE 0x00000001
183 #define WBC_DOMINFO_DOMAIN_AD 0x00000002
184 #define WBC_DOMINFO_DOMAIN_PRIMARY 0x00000004
185 #define WBC_DOMINFO_DOMAIN_OFFLINE 0x00000008
187 /* wbcDomainInfo->trust_flags */
189 #define WBC_DOMINFO_TRUST_TRANSITIVE 0x00000001
190 #define WBC_DOMINFO_TRUST_INCOMING 0x00000002
191 #define WBC_DOMINFO_TRUST_OUTGOING 0x00000004
193 /* wbcDomainInfo->trust_type */
195 #define WBC_DOMINFO_TRUSTTYPE_NONE 0x00000000
196 #define WBC_DOMINFO_TRUSTTYPE_FOREST 0x00000001
197 #define WBC_DOMINFO_TRUSTTYPE_IN_FOREST 0x00000002
198 #define WBC_DOMINFO_TRUSTTYPE_EXTERNAL 0x00000003
201 * @brief Generic Blob
204 struct wbcBlob {
205 uint8_t *data;
206 size_t length;
210 * @brief Named Blob
213 struct wbcNamedBlob {
214 const char *name;
215 uint32_t flags;
216 struct wbcBlob blob;
220 * @brief Auth User Parameters
223 struct wbcAuthUserParams {
224 const char *account_name;
225 const char *domain_name;
226 const char *workstation_name;
228 uint32_t flags;
230 uint32_t parameter_control;
232 enum wbcAuthUserLevel {
233 WBC_AUTH_USER_LEVEL_PLAIN = 1,
234 WBC_AUTH_USER_LEVEL_HASH = 2,
235 WBC_AUTH_USER_LEVEL_RESPONSE = 3,
236 WBC_AUTH_USER_LEVEL_PAC = 4
237 } level;
238 union {
239 const char *plaintext;
240 struct {
241 uint8_t nt_hash[16];
242 uint8_t lm_hash[16];
243 } hash;
244 struct {
245 uint8_t challenge[8];
246 uint32_t nt_length;
247 uint8_t *nt_data;
248 uint32_t lm_length;
249 uint8_t *lm_data;
250 } response;
251 struct wbcBlob pac;
252 } password;
256 * @brief Logon User Parameters
259 struct wbcLogonUserParams {
260 const char *username;
261 const char *password;
262 size_t num_blobs;
263 struct wbcNamedBlob *blobs;
267 * @brief ChangePassword Parameters
270 struct wbcChangePasswordParams {
271 const char *account_name;
272 const char *domain_name;
274 uint32_t flags;
276 enum wbcChangePasswordLevel {
277 WBC_CHANGE_PASSWORD_LEVEL_PLAIN = 1,
278 WBC_CHANGE_PASSWORD_LEVEL_RESPONSE = 2
279 } level;
281 union {
282 const char *plaintext;
283 struct {
284 uint32_t old_nt_hash_enc_length;
285 uint8_t *old_nt_hash_enc_data;
286 uint32_t old_lm_hash_enc_length;
287 uint8_t *old_lm_hash_enc_data;
288 } response;
289 } old_password;
290 union {
291 const char *plaintext;
292 struct {
293 uint32_t nt_length;
294 uint8_t *nt_data;
295 uint32_t lm_length;
296 uint8_t *lm_data;
297 } response;
298 } new_password;
301 /* wbcAuthUserParams->parameter_control */
303 #define WBC_MSV1_0_CLEARTEXT_PASSWORD_ALLOWED 0x00000002
304 #define WBC_MSV1_0_UPDATE_LOGON_STATISTICS 0x00000004
305 #define WBC_MSV1_0_RETURN_USER_PARAMETERS 0x00000008
306 #define WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT 0x00000020
307 #define WBC_MSV1_0_RETURN_PROFILE_PATH 0x00000200
308 #define WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT 0x00000800
310 /* wbcAuthUserParams->flags */
312 #define WBC_AUTH_PARAM_FLAGS_INTERACTIVE_LOGON 0x00000001
315 * @brief Auth User Information
317 * Some of the strings are maybe NULL
320 struct wbcAuthUserInfo {
321 uint32_t user_flags;
323 char *account_name;
324 char *user_principal;
325 char *full_name;
326 char *domain_name;
327 char *dns_domain_name;
329 uint32_t acct_flags;
330 uint8_t user_session_key[16];
331 uint8_t lm_session_key[8];
333 uint16_t logon_count;
334 uint16_t bad_password_count;
336 uint64_t logon_time;
337 uint64_t logoff_time;
338 uint64_t kickoff_time;
339 uint64_t pass_last_set_time;
340 uint64_t pass_can_change_time;
341 uint64_t pass_must_change_time;
343 char *logon_server;
344 char *logon_script;
345 char *profile_path;
346 char *home_directory;
347 char *home_drive;
350 * the 1st one is the account sid
351 * the 2nd one is the primary_group sid
352 * followed by the rest of the groups
354 uint32_t num_sids;
355 struct wbcSidWithAttr *sids;
359 * @brief Logon User Information
361 * Some of the strings are maybe NULL
364 struct wbcLogonUserInfo {
365 struct wbcAuthUserInfo *info;
366 size_t num_blobs;
367 struct wbcNamedBlob *blobs;
370 /* wbcAuthUserInfo->user_flags */
372 #define WBC_AUTH_USER_INFO_GUEST 0x00000001
373 #define WBC_AUTH_USER_INFO_NOENCRYPTION 0x00000002
374 #define WBC_AUTH_USER_INFO_CACHED_ACCOUNT 0x00000004
375 #define WBC_AUTH_USER_INFO_USED_LM_PASSWORD 0x00000008
376 #define WBC_AUTH_USER_INFO_EXTRA_SIDS 0x00000020
377 #define WBC_AUTH_USER_INFO_SUBAUTH_SESSION_KEY 0x00000040
378 #define WBC_AUTH_USER_INFO_SERVER_TRUST_ACCOUNT 0x00000080
379 #define WBC_AUTH_USER_INFO_NTLMV2_ENABLED 0x00000100
380 #define WBC_AUTH_USER_INFO_RESOURCE_GROUPS 0x00000200
381 #define WBC_AUTH_USER_INFO_PROFILE_PATH_RETURNED 0x00000400
382 #define WBC_AUTH_USER_INFO_GRACE_LOGON 0x01000000
384 /* wbcAuthUserInfo->acct_flags */
386 #define WBC_ACB_DISABLED 0x00000001 /* 1 User account disabled */
387 #define WBC_ACB_HOMDIRREQ 0x00000002 /* 1 Home directory required */
388 #define WBC_ACB_PWNOTREQ 0x00000004 /* 1 User password not required */
389 #define WBC_ACB_TEMPDUP 0x00000008 /* 1 Temporary duplicate account */
390 #define WBC_ACB_NORMAL 0x00000010 /* 1 Normal user account */
391 #define WBC_ACB_MNS 0x00000020 /* 1 MNS logon user account */
392 #define WBC_ACB_DOMTRUST 0x00000040 /* 1 Interdomain trust account */
393 #define WBC_ACB_WSTRUST 0x00000080 /* 1 Workstation trust account */
394 #define WBC_ACB_SVRTRUST 0x00000100 /* 1 Server trust account */
395 #define WBC_ACB_PWNOEXP 0x00000200 /* 1 User password does not expire */
396 #define WBC_ACB_AUTOLOCK 0x00000400 /* 1 Account auto locked */
397 #define WBC_ACB_ENC_TXT_PWD_ALLOWED 0x00000800 /* 1 Encryped text password is allowed */
398 #define WBC_ACB_SMARTCARD_REQUIRED 0x00001000 /* 1 Smart Card required */
399 #define WBC_ACB_TRUSTED_FOR_DELEGATION 0x00002000 /* 1 Trusted for Delegation */
400 #define WBC_ACB_NOT_DELEGATED 0x00004000 /* 1 Not delegated */
401 #define WBC_ACB_USE_DES_KEY_ONLY 0x00008000 /* 1 Use DES key only */
402 #define WBC_ACB_DONT_REQUIRE_PREAUTH 0x00010000 /* 1 Preauth not required */
403 #define WBC_ACB_PW_EXPIRED 0x00020000 /* 1 Password Expired */
404 #define WBC_ACB_NO_AUTH_DATA_REQD 0x00080000 /* 1 = No authorization data required */
406 struct wbcAuthErrorInfo {
407 uint32_t nt_status;
408 char *nt_string;
409 int32_t pam_error;
410 char *display_string;
414 * @brief User Password Policy Information
417 /* wbcUserPasswordPolicyInfo->password_properties */
419 #define WBC_DOMAIN_PASSWORD_COMPLEX 0x00000001
420 #define WBC_DOMAIN_PASSWORD_NO_ANON_CHANGE 0x00000002
421 #define WBC_DOMAIN_PASSWORD_NO_CLEAR_CHANGE 0x00000004
422 #define WBC_DOMAIN_PASSWORD_LOCKOUT_ADMINS 0x00000008
423 #define WBC_DOMAIN_PASSWORD_STORE_CLEARTEXT 0x00000010
424 #define WBC_DOMAIN_REFUSE_PASSWORD_CHANGE 0x00000020
426 struct wbcUserPasswordPolicyInfo {
427 uint32_t min_length_password;
428 uint32_t password_history;
429 uint32_t password_properties;
430 uint64_t expire;
431 uint64_t min_passwordage;
435 * @brief Change Password Reject Reason
438 enum wbcPasswordChangeRejectReason {
439 WBC_PWD_CHANGE_NO_ERROR=0,
440 WBC_PWD_CHANGE_PASSWORD_TOO_SHORT=1,
441 WBC_PWD_CHANGE_PWD_IN_HISTORY=2,
442 WBC_PWD_CHANGE_USERNAME_IN_PASSWORD=3,
443 WBC_PWD_CHANGE_FULLNAME_IN_PASSWORD=4,
444 WBC_PWD_CHANGE_NOT_COMPLEX=5,
445 WBC_PWD_CHANGE_MACHINE_NOT_DEFAULT=6,
446 WBC_PWD_CHANGE_FAILED_BY_FILTER=7,
447 WBC_PWD_CHANGE_PASSWORD_TOO_LONG=8
450 /* Note: this defines exist for compatibility reasons with existing code */
451 #define WBC_PWD_CHANGE_REJECT_OTHER WBC_PWD_CHANGE_NO_ERROR
452 #define WBC_PWD_CHANGE_REJECT_TOO_SHORT WBC_PWD_CHANGE_PASSWORD_TOO_SHORT
453 #define WBC_PWD_CHANGE_REJECT_IN_HISTORY WBC_PWD_CHANGE_PWD_IN_HISTORY
454 #define WBC_PWD_CHANGE_REJECT_COMPLEXITY WBC_PWD_CHANGE_NOT_COMPLEX
457 * @brief Logoff User Parameters
460 struct wbcLogoffUserParams {
461 const char *username;
462 size_t num_blobs;
463 struct wbcNamedBlob *blobs;
466 /** @brief Credential cache log-on parameters
470 struct wbcCredentialCacheParams {
471 const char *account_name;
472 const char *domain_name;
473 enum wbcCredentialCacheLevel {
474 WBC_CREDENTIAL_CACHE_LEVEL_NTLMSSP = 1
475 } level;
476 size_t num_blobs;
477 struct wbcNamedBlob *blobs;
481 /** @brief Info returned by credential cache auth
485 struct wbcCredentialCacheInfo {
486 size_t num_blobs;
487 struct wbcNamedBlob *blobs;
491 * DomainControllerInfo struct
493 struct wbcDomainControllerInfo {
494 char *dc_name;
498 * DomainControllerInfoEx struct
500 struct wbcDomainControllerInfoEx {
501 const char *dc_unc;
502 const char *dc_address;
503 uint16_t dc_address_type;
504 struct wbcGuid *domain_guid;
505 const char *domain_name;
506 const char *forest_name;
507 uint32_t dc_flags;
508 const char *dc_site_name;
509 const char *client_site_name;
512 /**********************************************************
513 * Memory Management
514 **********************************************************/
517 * @brief Free library allocated memory
519 * @param * Pointer to free
521 * @return void
523 void wbcFreeMemory(void*);
527 * Utility functions for dealing with SIDs
531 * @brief Get a string representation of the SID type
533 * @param type type of the SID
535 * @return string representation of the SID type
537 const char* wbcSidTypeString(enum wbcSidType type);
539 #define WBC_SID_STRING_BUFLEN (15*11+25)
542 * @brief Print a sid into a buffer
544 * @param sid Binary Security Identifier
545 * @param buf Target buffer
546 * @param buflen Target buffer length
548 * @return Resulting string length.
550 int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen);
553 * @brief Convert a binary SID to a character string
555 * @param sid Binary Security Identifier
556 * @param **sid_string Resulting character string
558 * @return #wbcErr
560 wbcErr wbcSidToString(const struct wbcDomainSid *sid,
561 char **sid_string);
564 * @brief Convert a character string to a binary SID
566 * @param *sid_string Character string in the form of S-...
567 * @param sid Resulting binary SID
569 * @return #wbcErr
571 wbcErr wbcStringToSid(const char *sid_string,
572 struct wbcDomainSid *sid);
575 * Utility functions for dealing with GUIDs
579 * @brief Convert a binary GUID to a character string
581 * @param guid Binary Guid
582 * @param **guid_string Resulting character string
584 * @return #wbcErr
586 wbcErr wbcGuidToString(const struct wbcGuid *guid,
587 char **guid_string);
590 * @brief Convert a character string to a binary GUID
592 * @param *guid_string Character string
593 * @param guid Resulting binary GUID
595 * @return #wbcErr
597 wbcErr wbcStringToGuid(const char *guid_string,
598 struct wbcGuid *guid);
601 * @brief Ping winbindd to see if the daemon is running
603 * @return #wbcErr
605 wbcErr wbcPing(void);
607 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
609 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
611 /**********************************************************
612 * Name/SID conversion
613 **********************************************************/
616 * @brief Convert a domain and name to SID
618 * @param dom_name Domain name (possibly "")
619 * @param name User or group name
620 * @param *sid Pointer to the resolved domain SID
621 * @param *name_type Pointer to the SID type
623 * @return #wbcErr
625 wbcErr wbcLookupName(const char *dom_name,
626 const char *name,
627 struct wbcDomainSid *sid,
628 enum wbcSidType *name_type);
631 * @brief Convert a SID to a domain and name
633 * @param *sid Pointer to the domain SID to be resolved
634 * @param domain Resolved Domain name (possibly "")
635 * @param name Resolved User or group name
636 * @param *name_type Pointer to the resolved SID type
638 * @return #wbcErr
640 wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
641 char **domain,
642 char **name,
643 enum wbcSidType *name_type);
645 struct wbcTranslatedName {
646 enum wbcSidType type;
647 char *name;
648 int domain_index;
651 wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
652 struct wbcDomainInfo **domains, int *num_domains,
653 struct wbcTranslatedName **names);
656 * @brief Translate a collection of RIDs within a domain to names
658 wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
659 int num_rids,
660 uint32_t *rids,
661 const char **domain_name,
662 const char ***names,
663 enum wbcSidType **types);
666 * @brief Get the groups a user belongs to
668 wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
669 bool domain_groups_only,
670 uint32_t *num_sids,
671 struct wbcDomainSid **sids);
674 * @brief Get alias membership for sids
676 wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
677 struct wbcDomainSid *sids,
678 uint32_t num_sids,
679 uint32_t **alias_rids,
680 uint32_t *num_alias_rids);
683 * @brief Lists Users
685 wbcErr wbcListUsers(const char *domain_name,
686 uint32_t *num_users,
687 const char ***users);
690 * @brief Lists Groups
692 wbcErr wbcListGroups(const char *domain_name,
693 uint32_t *num_groups,
694 const char ***groups);
696 wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
697 char **pdomain,
698 char **pfullname,
699 enum wbcSidType *pname_type);
701 /**********************************************************
702 * SID/uid/gid Mappings
703 **********************************************************/
706 * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
708 * @param *sid Pointer to the domain SID to be resolved
709 * @param *puid Pointer to the resolved uid_t value
711 * @return #wbcErr
714 wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
715 uid_t *puid);
718 * @brief Convert a Windows SID to a Unix uid if there already is a mapping
720 * @param *sid Pointer to the domain SID to be resolved
721 * @param *puid Pointer to the resolved uid_t value
723 * @return #wbcErr
726 wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
727 uid_t *puid);
730 * @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
732 * @param uid Unix uid to be resolved
733 * @param *sid Pointer to the resolved domain SID
735 * @return #wbcErr
738 wbcErr wbcUidToSid(uid_t uid,
739 struct wbcDomainSid *sid);
742 * @brief Convert a Unix uid to a Windows SID if there already is a mapping
744 * @param uid Unix uid to be resolved
745 * @param *sid Pointer to the resolved domain SID
747 * @return #wbcErr
750 wbcErr wbcQueryUidToSid(uid_t uid,
751 struct wbcDomainSid *sid);
754 * @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
756 * @param *sid Pointer to the domain SID to be resolved
757 * @param *pgid Pointer to the resolved gid_t value
759 * @return #wbcErr
762 wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
763 gid_t *pgid);
766 * @brief Convert a Windows SID to a Unix gid if there already is a mapping
768 * @param *sid Pointer to the domain SID to be resolved
769 * @param *pgid Pointer to the resolved gid_t value
771 * @return #wbcErr
774 wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
775 gid_t *pgid);
778 * @brief Convert a Unix gid to a Windows SID, allocating a SID if needed
780 * @param gid Unix gid to be resolved
781 * @param *sid Pointer to the resolved domain SID
783 * @return #wbcErr
786 wbcErr wbcGidToSid(gid_t gid,
787 struct wbcDomainSid *sid);
790 * @brief Convert a Unix gid to a Windows SID if there already is a mapping
792 * @param gid Unix gid to be resolved
793 * @param *sid Pointer to the resolved domain SID
795 * @return #wbcErr
798 wbcErr wbcQueryGidToSid(gid_t gid,
799 struct wbcDomainSid *sid);
801 enum wbcIdType {
802 WBC_ID_TYPE_NOT_SPECIFIED,
803 WBC_ID_TYPE_UID,
804 WBC_ID_TYPE_GID,
805 WBC_ID_TYPE_BOTH
808 union wbcUnixIdContainer {
809 uid_t uid;
810 gid_t gid;
813 struct wbcUnixId {
814 enum wbcIdType type;
815 union wbcUnixIdContainer id;
819 * @brief Convert a list of sids to unix ids
821 * @param sids Pointer to an array of SIDs to convert
822 * @param num_sids Number of SIDs
823 * @param ids Preallocated output array for translated IDs
825 * @return #wbcErr
828 wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
829 struct wbcUnixId *ids);
832 * @brief Obtain a new uid from Winbind
834 * @param *puid *pointer to the allocated uid
836 * @return #wbcErr
838 wbcErr wbcAllocateUid(uid_t *puid);
841 * @brief Obtain a new gid from Winbind
843 * @param *pgid Pointer to the allocated gid
845 * @return #wbcErr
847 wbcErr wbcAllocateGid(gid_t *pgid);
850 * @brief Set an user id mapping
852 * @param uid Uid of the desired mapping.
853 * @param *sid Pointer to the sid of the diresired mapping.
855 * @return #wbcErr
857 * @deprecated This method is not impemented any more and should
858 * be removed in the next major version change.
860 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid);
863 * @brief Set a group id mapping
865 * @param gid Gid of the desired mapping.
866 * @param *sid Pointer to the sid of the diresired mapping.
868 * @return #wbcErr
870 * @deprecated This method is not impemented any more and should
871 * be removed in the next major version change.
873 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid);
876 * @brief Remove a user id mapping
878 * @param uid Uid of the mapping to remove.
879 * @param *sid Pointer to the sid of the mapping to remove.
881 * @return #wbcErr
883 * @deprecated This method is not impemented any more and should
884 * be removed in the next major version change.
886 wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid);
889 * @brief Remove a group id mapping
891 * @param gid Gid of the mapping to remove.
892 * @param *sid Pointer to the sid of the mapping to remove.
894 * @return #wbcErr
896 * @deprecated This method is not impemented any more and should
897 * be removed in the next major version change.
899 wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid);
902 * @brief Set the highwater mark for allocated uids.
904 * @param uid_hwm The new uid highwater mark value
906 * @return #wbcErr
908 * @deprecated This method is not impemented any more and should
909 * be removed in the next major version change.
911 wbcErr wbcSetUidHwm(uid_t uid_hwm);
914 * @brief Set the highwater mark for allocated gids.
916 * @param gid_hwm The new gid highwater mark value
918 * @return #wbcErr
920 * @deprecated This method is not impemented any more and should
921 * be removed in the next major version change.
923 wbcErr wbcSetGidHwm(gid_t gid_hwm);
925 /**********************************************************
926 * NSS Lookup User/Group details
927 **********************************************************/
930 * @brief Fill in a struct passwd* for a domain user based
931 * on username
933 * @param *name Username to lookup
934 * @param **pwd Pointer to resulting struct passwd* from the query.
936 * @return #wbcErr
938 wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
941 * @brief Fill in a struct passwd* for a domain user based
942 * on uid
944 * @param uid Uid to lookup
945 * @param **pwd Pointer to resulting struct passwd* from the query.
947 * @return #wbcErr
949 wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
952 * @brief Fill in a struct passwd* for a domain user based
953 * on sid
955 * @param sid Sid to lookup
956 * @param **pwd Pointer to resulting struct passwd* from the query.
958 * @return #wbcErr
960 wbcErr wbcGetpwsid(struct wbcDomainSid * sid, struct passwd **pwd);
963 * @brief Fill in a struct passwd* for a domain user based
964 * on username
966 * @param *name Username to lookup
967 * @param **grp Pointer to resulting struct group* from the query.
969 * @return #wbcErr
971 wbcErr wbcGetgrnam(const char *name, struct group **grp);
974 * @brief Fill in a struct passwd* for a domain user based
975 * on uid
977 * @param gid Uid to lookup
978 * @param **grp Pointer to resulting struct group* from the query.
980 * @return #wbcErr
982 wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
985 * @brief Reset the passwd iterator
987 * @return #wbcErr
989 wbcErr wbcSetpwent(void);
992 * @brief Close the passwd iterator
994 * @return #wbcErr
996 wbcErr wbcEndpwent(void);
999 * @brief Return the next struct passwd* entry from the pwent iterator
1001 * @param **pwd Pointer to resulting struct passwd* from the query.
1003 * @return #wbcErr
1005 wbcErr wbcGetpwent(struct passwd **pwd);
1008 * @brief Reset the group iterator
1010 * @return #wbcErr
1012 wbcErr wbcSetgrent(void);
1015 * @brief Close the group iterator
1017 * @return #wbcErr
1019 wbcErr wbcEndgrent(void);
1022 * @brief Return the next struct group* entry from the pwent iterator
1024 * @param **grp Pointer to resulting struct group* from the query.
1026 * @return #wbcErr
1028 wbcErr wbcGetgrent(struct group **grp);
1031 * @brief Return the next struct group* entry from the pwent iterator
1033 * This is similar to #wbcGetgrent, just that the member list is empty
1035 * @param **grp Pointer to resulting struct group* from the query.
1037 * @return #wbcErr
1039 wbcErr wbcGetgrlist(struct group **grp);
1042 * @brief Return the unix group array belonging to the given user
1044 * @param *account The given user name
1045 * @param *num_groups Number of elements returned in the groups array
1046 * @param **_groups Pointer to resulting gid_t array.
1048 * @return #wbcErr
1050 wbcErr wbcGetGroups(const char *account,
1051 uint32_t *num_groups,
1052 gid_t **_groups);
1055 /**********************************************************
1056 * Lookup Domain information
1057 **********************************************************/
1060 * @brief Lookup the current status of a trusted domain
1062 * @param domain The domain to query
1064 * @param dinfo A pointer to store the returned domain_info struct.
1066 * @return #wbcErr
1068 wbcErr wbcDomainInfo(const char *domain,
1069 struct wbcDomainInfo **dinfo);
1072 * @brief Lookup the currently contacted DCs
1074 * @param domain The domain to query
1076 * @param num_dcs Number of DCs currently known
1077 * @param dc_names Names of the currently known DCs
1078 * @param dc_ips IP addresses of the currently known DCs
1080 * @return #wbcErr
1082 wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
1083 const char ***dc_names, const char ***dc_ips);
1086 * @brief Enumerate the domain trusts known by Winbind
1088 * @param **domains Pointer to the allocated domain list array
1089 * @param *num_domains Pointer to number of domains returned
1091 * @return #wbcErr
1093 wbcErr wbcListTrusts(struct wbcDomainInfo **domains,
1094 size_t *num_domains);
1096 /* Flags for wbcLookupDomainController */
1098 #define WBC_LOOKUP_DC_FORCE_REDISCOVERY 0x00000001
1099 #define WBC_LOOKUP_DC_DS_REQUIRED 0x00000010
1100 #define WBC_LOOKUP_DC_DS_PREFERRED 0x00000020
1101 #define WBC_LOOKUP_DC_GC_SERVER_REQUIRED 0x00000040
1102 #define WBC_LOOKUP_DC_PDC_REQUIRED 0x00000080
1103 #define WBC_LOOKUP_DC_BACKGROUND_ONLY 0x00000100
1104 #define WBC_LOOKUP_DC_IP_REQUIRED 0x00000200
1105 #define WBC_LOOKUP_DC_KDC_REQUIRED 0x00000400
1106 #define WBC_LOOKUP_DC_TIMESERV_REQUIRED 0x00000800
1107 #define WBC_LOOKUP_DC_WRITABLE_REQUIRED 0x00001000
1108 #define WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED 0x00002000
1109 #define WBC_LOOKUP_DC_AVOID_SELF 0x00004000
1110 #define WBC_LOOKUP_DC_ONLY_LDAP_NEEDED 0x00008000
1111 #define WBC_LOOKUP_DC_IS_FLAT_NAME 0x00010000
1112 #define WBC_LOOKUP_DC_IS_DNS_NAME 0x00020000
1113 #define WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE 0x00040000
1114 #define WBC_LOOKUP_DC_DS_6_REQUIRED 0x00080000
1115 #define WBC_LOOKUP_DC_RETURN_DNS_NAME 0x40000000
1116 #define WBC_LOOKUP_DC_RETURN_FLAT_NAME 0x80000000
1119 * @brief Enumerate the domain trusts known by Winbind
1121 * @param domain Name of the domain to query for a DC
1122 * @param flags Bit flags used to control the domain location query
1123 * @param *dc_info Pointer to the returned domain controller information
1125 * @return #wbcErr
1127 wbcErr wbcLookupDomainController(const char *domain,
1128 uint32_t flags,
1129 struct wbcDomainControllerInfo **dc_info);
1132 * @brief Get extended domain controller information
1134 * @param domain Name of the domain to query for a DC
1135 * @param guid Guid of the domain to query for a DC
1136 * @param site Site of the domain to query for a DC
1137 * @param flags Bit flags used to control the domain location query
1138 * @param *dc_info Pointer to the returned extended domain controller information
1140 * @return #wbcErr
1142 wbcErr wbcLookupDomainControllerEx(const char *domain,
1143 struct wbcGuid *guid,
1144 const char *site,
1145 uint32_t flags,
1146 struct wbcDomainControllerInfoEx **dc_info);
1148 /**********************************************************
1149 * Athenticate functions
1150 **********************************************************/
1153 * @brief Authenticate a username/password pair
1155 * @param username Name of user to authenticate
1156 * @param password Clear text password os user
1158 * @return #wbcErr
1160 wbcErr wbcAuthenticateUser(const char *username,
1161 const char *password);
1164 * @brief Authenticate with more detailed information
1166 * @param params Input parameters, WBC_AUTH_USER_LEVEL_HASH
1167 * is not supported yet
1168 * @param info Output details on WBC_ERR_SUCCESS
1169 * @param error Output details on WBC_ERR_AUTH_ERROR
1171 * @return #wbcErr
1173 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
1174 struct wbcAuthUserInfo **info,
1175 struct wbcAuthErrorInfo **error);
1178 * @brief Logon a User
1180 * @param[in] params Pointer to a wbcLogonUserParams structure
1181 * @param[out] info Pointer to a pointer to a wbcLogonUserInfo structure
1182 * @param[out] error Pointer to a pointer to a wbcAuthErrorInfo structure
1183 * @param[out] policy Pointer to a pointer to a wbcUserPasswordPolicyInfo structure
1185 * @return #wbcErr
1187 wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
1188 struct wbcLogonUserInfo **info,
1189 struct wbcAuthErrorInfo **error,
1190 struct wbcUserPasswordPolicyInfo **policy);
1193 * @brief Trigger a logoff notification to Winbind for a specific user
1195 * @param username Name of user to remove from Winbind's list of
1196 * logged on users.
1197 * @param uid Uid assigned to the username
1198 * @param ccfilename Absolute path to the Krb5 credentials cache to
1199 * be removed
1201 * @return #wbcErr
1203 wbcErr wbcLogoffUser(const char *username,
1204 uid_t uid,
1205 const char *ccfilename);
1208 * @brief Trigger an extended logoff notification to Winbind for a specific user
1210 * @param params A wbcLogoffUserParams structure
1211 * @param error User output details on error
1213 * @return #wbcErr
1215 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
1216 struct wbcAuthErrorInfo **error);
1219 * @brief Change a password for a user
1221 * @param username Name of user to authenticate
1222 * @param old_password Old clear text password of user
1223 * @param new_password New clear text password of user
1225 * @return #wbcErr
1227 wbcErr wbcChangeUserPassword(const char *username,
1228 const char *old_password,
1229 const char *new_password);
1232 * @brief Change a password for a user with more detailed information upon
1233 * failure
1235 * @param params Input parameters
1236 * @param error User output details on WBC_ERR_PWD_CHANGE_FAILED
1237 * @param reject_reason New password reject reason on WBC_ERR_PWD_CHANGE_FAILED
1238 * @param policy Password policy output details on WBC_ERR_PWD_CHANGE_FAILED
1240 * @return #wbcErr
1242 wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
1243 struct wbcAuthErrorInfo **error,
1244 enum wbcPasswordChangeRejectReason *reject_reason,
1245 struct wbcUserPasswordPolicyInfo **policy);
1248 * @brief Authenticate a user with cached credentials
1250 * @param *params Pointer to a wbcCredentialCacheParams structure
1251 * @param **info Pointer to a pointer to a wbcCredentialCacheInfo structure
1252 * @param **error Pointer to a pointer to a wbcAuthErrorInfo structure
1254 * @return #wbcErr
1256 wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
1257 struct wbcCredentialCacheInfo **info,
1258 struct wbcAuthErrorInfo **error);
1261 * @brief Save a password with winbind for doing wbcCredentialCache() later
1263 * @param *user Username
1264 * @param *password Password
1266 * @return #wbcErr
1268 wbcErr wbcCredentialSave(const char *user, const char *password);
1270 /**********************************************************
1271 * Resolve functions
1272 **********************************************************/
1275 * @brief Resolve a NetbiosName via WINS
1277 * @param name Name to resolve
1278 * @param *ip Pointer to the ip address string
1280 * @return #wbcErr
1282 wbcErr wbcResolveWinsByName(const char *name, char **ip);
1285 * @brief Resolve an IP address via WINS into a NetbiosName
1287 * @param ip The ip address string
1288 * @param *name Pointer to the name
1290 * @return #wbcErr
1293 wbcErr wbcResolveWinsByIP(const char *ip, char **name);
1295 /**********************************************************
1296 * Trusted domain functions
1297 **********************************************************/
1300 * @brief Trigger a verification of the trust credentials of a specific domain
1302 * @param *domain The name of the domain.
1303 * @param error Output details on WBC_ERR_AUTH_ERROR
1305 * @return #wbcErr
1307 wbcErr wbcCheckTrustCredentials(const char *domain,
1308 struct wbcAuthErrorInfo **error);
1311 * @brief Trigger a change of the trust credentials for a specific domain
1313 * @param *domain The name of the domain.
1314 * @param error Output details on WBC_ERR_AUTH_ERROR
1316 * @return #wbcErr
1318 wbcErr wbcChangeTrustCredentials(const char *domain,
1319 struct wbcAuthErrorInfo **error);
1322 * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
1323 * version of wbcCheckTrustCredentials
1325 * @param *domain The name of the domain, only NULL for the default domain is
1326 * supported yet. Other values than NULL will result in
1327 * WBC_ERR_NOT_IMPLEMENTED.
1328 * @param error Output details on WBC_ERR_AUTH_ERROR
1330 * @return #wbcErr
1332 wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error);
1335 * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
1336 * version of wbcCheckTrustCredentials
1338 * @param *domain The name of the domain, only NULL for the default domain is
1339 * supported yet. Other values than NULL will result in
1340 * WBC_ERR_NOT_IMPLEMENTED.
1341 * @param error Output details on WBC_ERR_AUTH_ERROR
1342 * @param dcname DC that was attempted to ping
1344 * @return #wbcErr
1346 wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
1347 char **dcname);
1349 /**********************************************************
1350 * Helper functions
1351 **********************************************************/
1354 * @brief Initialize a named blob and add to list of blobs
1356 * @param[in,out] num_blobs Pointer to the number of blobs
1357 * @param[in,out] blobs Pointer to an array of blobs
1358 * @param[in] name Name of the new named blob
1359 * @param[in] flags Flags of the new named blob
1360 * @param[in] data Blob data of new blob
1361 * @param[in] length Blob data length of new blob
1363 * @return #wbcErr
1365 wbcErr wbcAddNamedBlob(size_t *num_blobs,
1366 struct wbcNamedBlob **blobs,
1367 const char *name,
1368 uint32_t flags,
1369 uint8_t *data,
1370 size_t length);
1372 #endif /* _WBCLIENT_H */