wbclient: fix conversion logic in wbcStringToSid
[gd/samba-autobuild/.git] / nsswitch / libwbclient / wbclient.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    Winbind client API
5
6    Copyright (C) Gerald (Jerry) Carter 2007
7    Copyright (C) Volker Lendecke 2009
8
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.
13
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.
18
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/>.
21 */
22
23 #ifndef _WBCLIENT_H
24 #define _WBCLIENT_H
25
26 #include <pwd.h>
27 #include <grp.h>
28
29 /* Define error types */
30
31 /**
32  *  @brief Status codes returned from wbc functions
33  **/
34
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 */
50 };
51
52 typedef enum _wbcErrType wbcErr;
53
54 #define WBC_ERROR_IS_OK(x) ((x) == WBC_ERR_SUCCESS)
55
56 const char *wbcErrorString(wbcErr error);
57
58 /**
59  *  @brief Some useful details about the wbclient library
60  *
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;
82 };
83
84 /**
85  *  @brief Some useful details about the running winbindd
86  *
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;
95 };
96
97 /*
98  * Data types used by the Winbind Client API
99  */
100
101 #ifndef WBC_MAXSUBAUTHS
102 #define WBC_MAXSUBAUTHS 15 /* max sub authorities in a SID */
103 #endif
104
105 /**
106  *  @brief Windows Security Identifier
107  *
108  **/
109
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];
115 };
116
117 /**
118  * @brief Security Identifier type
119  **/
120
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
132 };
133
134 /**
135  * @brief Security Identifier with attributes
136  **/
137
138 struct wbcSidWithAttr {
139         struct wbcDomainSid sid;
140         uint32_t attributes;
141 };
142
143 /* wbcSidWithAttr->attributes */
144
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
152
153 /**
154  *  @brief Windows GUID
155  *
156  **/
157
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];
164 };
165
166 /**
167  * @brief Domain Information
168  **/
169
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;
177 };
178
179 /* wbcDomainInfo->domain_flags */
180
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
186
187 /* wbcDomainInfo->trust_flags */
188
189 #define WBC_DOMINFO_TRUST_TRANSITIVE  0x00000001
190 #define WBC_DOMINFO_TRUST_INCOMING    0x00000002
191 #define WBC_DOMINFO_TRUST_OUTGOING    0x00000004
192
193 /* wbcDomainInfo->trust_type */
194
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
199
200 /**
201  * @brief Generic Blob
202  **/
203
204 struct wbcBlob {
205         uint8_t *data;
206         size_t length;
207 };
208
209 /**
210  * @brief Named Blob
211  **/
212
213 struct wbcNamedBlob {
214         const char *name;
215         uint32_t flags;
216         struct wbcBlob blob;
217 };
218
219 /**
220  * @brief Auth User Parameters
221  **/
222
223 struct wbcAuthUserParams {
224         const char *account_name;
225         const char *domain_name;
226         const char *workstation_name;
227
228         uint32_t flags;
229
230         uint32_t parameter_control;
231
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;
253 };
254
255 /**
256  * @brief Logon User Parameters
257  **/
258
259 struct wbcLogonUserParams {
260         const char *username;
261         const char *password;
262         size_t num_blobs;
263         struct wbcNamedBlob *blobs;
264 };
265
266 /**
267  * @brief ChangePassword Parameters
268  **/
269
270 struct wbcChangePasswordParams {
271         const char *account_name;
272         const char *domain_name;
273
274         uint32_t flags;
275
276         enum wbcChangePasswordLevel {
277                 WBC_CHANGE_PASSWORD_LEVEL_PLAIN = 1,
278                 WBC_CHANGE_PASSWORD_LEVEL_RESPONSE = 2
279         } level;
280
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;
299 };
300
301 /* wbcAuthUserParams->parameter_control */
302
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
309
310 /* wbcAuthUserParams->flags */
311
312 #define WBC_AUTH_PARAM_FLAGS_INTERACTIVE_LOGON          0x00000001
313
314 /**
315  * @brief Auth User Information
316  *
317  * Some of the strings are maybe NULL
318  **/
319
320 struct wbcAuthUserInfo {
321         uint32_t user_flags;
322
323         char *account_name;
324         char *user_principal;
325         char *full_name;
326         char *domain_name;
327         char *dns_domain_name;
328
329         uint32_t acct_flags;
330         uint8_t user_session_key[16];
331         uint8_t lm_session_key[8];
332
333         uint16_t logon_count;
334         uint16_t bad_password_count;
335
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;
342
343         char *logon_server;
344         char *logon_script;
345         char *profile_path;
346         char *home_directory;
347         char *home_drive;
348
349         /*
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
353          */
354         uint32_t num_sids;
355         struct wbcSidWithAttr *sids;
356 };
357
358 /**
359  * @brief Logon User Information
360  *
361  * Some of the strings are maybe NULL
362  **/
363
364 struct wbcLogonUserInfo {
365         struct wbcAuthUserInfo *info;
366         size_t num_blobs;
367         struct wbcNamedBlob *blobs;
368 };
369
370 /* wbcAuthUserInfo->user_flags */
371
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
383
384 /* wbcAuthUserInfo->acct_flags */
385
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 */
405
406 struct wbcAuthErrorInfo {
407         uint32_t nt_status;
408         char *nt_string;
409         int32_t pam_error;
410         char *display_string;
411 };
412
413 /**
414  * @brief User Password Policy Information
415  **/
416
417 /* wbcUserPasswordPolicyInfo->password_properties */
418
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
425
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;
432 };
433
434 /**
435  * @brief Change Password Reject Reason
436  **/
437
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
448 };
449
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
455
456 /**
457  * @brief Logoff User Parameters
458  **/
459
460 struct wbcLogoffUserParams {
461         const char *username;
462         size_t num_blobs;
463         struct wbcNamedBlob *blobs;
464 };
465
466 /** @brief Credential cache log-on parameters
467  *
468  */
469
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;
478 };
479
480
481 /** @brief Info returned by credential cache auth
482  *
483  */
484
485 struct wbcCredentialCacheInfo {
486         size_t num_blobs;
487         struct wbcNamedBlob *blobs;
488 };
489
490 /*
491  * DomainControllerInfo struct
492  */
493 struct wbcDomainControllerInfo {
494         char *dc_name;
495 };
496
497 /*
498  * DomainControllerInfoEx struct
499  */
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;
510 };
511
512 /**********************************************************
513  * Memory Management
514  **********************************************************/
515
516 /**
517  * @brief Free library allocated memory
518  *
519  * @param * Pointer to free
520  *
521  * @return void
522  **/
523 void wbcFreeMemory(void*);
524
525
526 /*
527  * Utility functions for dealing with SIDs
528  */
529
530 /**
531  * @brief Get a string representation of the SID type
532  *
533  * @param type          type of the SID
534  *
535  * @return string representation of the SID type
536  */
537 const char* wbcSidTypeString(enum wbcSidType type);
538
539 #define WBC_SID_STRING_BUFLEN (15*11+25)
540
541 /*
542  * @brief Print a sid into a buffer
543  *
544  * @param sid           Binary Security Identifier
545  * @param buf           Target buffer
546  * @param buflen        Target buffer length
547  *
548  * @return Resulting string length.
549  */
550 int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen);
551
552 /**
553  * @brief Convert a binary SID to a character string
554  *
555  * @param sid           Binary Security Identifier
556  * @param **sid_string  Resulting character string
557  *
558  * @return #wbcErr
559  **/
560 wbcErr wbcSidToString(const struct wbcDomainSid *sid,
561                       char **sid_string);
562
563 /**
564  * @brief Convert a character string to a binary SID
565  *
566  * @param *sid_string   Character string in the form of S-...
567  * @param sid           Resulting binary SID
568  *
569  * @return #wbcErr
570  **/
571 wbcErr wbcStringToSid(const char *sid_string,
572                       struct wbcDomainSid *sid);
573
574 /*
575  * Utility functions for dealing with GUIDs
576  */
577
578 /**
579  * @brief Convert a binary GUID to a character string
580  *
581  * @param guid           Binary Guid
582  * @param **guid_string  Resulting character string
583  *
584  * @return #wbcErr
585  **/
586 wbcErr wbcGuidToString(const struct wbcGuid *guid,
587                        char **guid_string);
588
589 /**
590  * @brief Convert a character string to a binary GUID
591  *
592  * @param *guid_string  Character string
593  * @param guid          Resulting binary GUID
594  *
595  * @return #wbcErr
596  **/
597 wbcErr wbcStringToGuid(const char *guid_string,
598                        struct wbcGuid *guid);
599
600 /**
601  * @brief Ping winbindd to see if the daemon is running
602  *
603  * @return #wbcErr
604  **/
605 wbcErr wbcPing(void);
606
607 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
608
609 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
610
611 /**********************************************************
612  * Name/SID conversion
613  **********************************************************/
614
615 /**
616  * @brief Convert a domain and name to SID
617  *
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
622  *
623  * @return #wbcErr
624  **/
625 wbcErr wbcLookupName(const char *dom_name,
626                      const char *name,
627                      struct wbcDomainSid *sid,
628                      enum wbcSidType *name_type);
629
630 /**
631  * @brief Convert a SID to a domain and name
632  *
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
637  *
638  * @return #wbcErr
639  **/
640 wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
641                     char **domain,
642                     char **name,
643                     enum wbcSidType *name_type);
644
645 struct wbcTranslatedName {
646         enum wbcSidType type;
647         char *name;
648         int domain_index;
649 };
650
651 wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
652                      struct wbcDomainInfo **domains, int *num_domains,
653                      struct wbcTranslatedName **names);
654
655 /**
656  * @brief Translate a collection of RIDs within a domain to names
657  */
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);
664
665 /*
666  * @brief Get the groups a user belongs to
667  **/
668 wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
669                          bool domain_groups_only,
670                          uint32_t *num_sids,
671                          struct wbcDomainSid **sids);
672
673 /*
674  * @brief Get alias membership for sids
675  **/
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);
681
682 /**
683  * @brief Lists Users
684  **/
685 wbcErr wbcListUsers(const char *domain_name,
686                     uint32_t *num_users,
687                     const char ***users);
688
689 /**
690  * @brief Lists Groups
691  **/
692 wbcErr wbcListGroups(const char *domain_name,
693                      uint32_t *num_groups,
694                      const char ***groups);
695
696 wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
697                          char **pdomain,
698                          char **pfullname,
699                          enum wbcSidType *pname_type);
700
701 /**********************************************************
702  * SID/uid/gid Mappings
703  **********************************************************/
704
705 /**
706  * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
707  *
708  * @param *sid        Pointer to the domain SID to be resolved
709  * @param *puid       Pointer to the resolved uid_t value
710  *
711  * @return #wbcErr
712  *
713  **/
714 wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
715                    uid_t *puid);
716
717 /**
718  * @brief Convert a Windows SID to a Unix uid if there already is a mapping
719  *
720  * @param *sid        Pointer to the domain SID to be resolved
721  * @param *puid       Pointer to the resolved uid_t value
722  *
723  * @return #wbcErr
724  *
725  **/
726 wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
727                         uid_t *puid);
728
729 /**
730  * @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
731  *
732  * @param uid         Unix uid to be resolved
733  * @param *sid        Pointer to the resolved domain SID
734  *
735  * @return #wbcErr
736  *
737  **/
738 wbcErr wbcUidToSid(uid_t uid,
739                    struct wbcDomainSid *sid);
740
741 /**
742  * @brief Convert a Unix uid to a Windows SID if there already is a mapping
743  *
744  * @param uid         Unix uid to be resolved
745  * @param *sid        Pointer to the resolved domain SID
746  *
747  * @return #wbcErr
748  *
749  **/
750 wbcErr wbcQueryUidToSid(uid_t uid,
751                         struct wbcDomainSid *sid);
752
753 /**
754  * @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
755  *
756  * @param *sid        Pointer to the domain SID to be resolved
757  * @param *pgid       Pointer to the resolved gid_t value
758  *
759  * @return #wbcErr
760  *
761  **/
762 wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
763                    gid_t *pgid);
764
765 /**
766  * @brief Convert a Windows SID to a Unix gid if there already is a mapping
767  *
768  * @param *sid        Pointer to the domain SID to be resolved
769  * @param *pgid       Pointer to the resolved gid_t value
770  *
771  * @return #wbcErr
772  *
773  **/
774 wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
775                         gid_t *pgid);
776
777 /**
778  * @brief Convert a Unix gid to a Windows SID, allocating a SID if needed
779  *
780  * @param gid         Unix gid to be resolved
781  * @param *sid        Pointer to the resolved domain SID
782  *
783  * @return #wbcErr
784  *
785  **/
786 wbcErr wbcGidToSid(gid_t gid,
787                    struct wbcDomainSid *sid);
788
789 /**
790  * @brief Convert a Unix gid to a Windows SID if there already is a mapping
791  *
792  * @param gid         Unix gid to be resolved
793  * @param *sid        Pointer to the resolved domain SID
794  *
795  * @return #wbcErr
796  *
797  **/
798 wbcErr wbcQueryGidToSid(gid_t gid,
799                         struct wbcDomainSid *sid);
800
801 enum wbcIdType {
802         WBC_ID_TYPE_NOT_SPECIFIED,
803         WBC_ID_TYPE_UID,
804         WBC_ID_TYPE_GID,
805         WBC_ID_TYPE_BOTH
806 };
807
808 union wbcUnixIdContainer {
809         uid_t uid;
810         gid_t gid;
811 };
812
813 struct wbcUnixId {
814         enum wbcIdType type;
815         union wbcUnixIdContainer id;
816 };
817
818 /**
819  * @brief Convert a list of sids to unix ids
820  *
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
824  *
825  * @return #wbcErr
826  *
827  **/
828 wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
829                         struct wbcUnixId *ids);
830
831 /**
832  * @brief Obtain a new uid from Winbind
833  *
834  * @param *puid      *pointer to the allocated uid
835  *
836  * @return #wbcErr
837  **/
838 wbcErr wbcAllocateUid(uid_t *puid);
839
840 /**
841  * @brief Obtain a new gid from Winbind
842  *
843  * @param *pgid      Pointer to the allocated gid
844  *
845  * @return #wbcErr
846  **/
847 wbcErr wbcAllocateGid(gid_t *pgid);
848
849 /**
850  * @brief Set an user id mapping
851  *
852  * @param uid       Uid of the desired mapping.
853  * @param *sid      Pointer to the sid of the desired mapping.
854  *
855  * @return #wbcErr
856  *
857  * @deprecated      This method is not impemented any more and should
858  *                  be removed in the next major version change.
859  **/
860 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid);
861
862 /**
863  * @brief Set a group id mapping
864  *
865  * @param gid       Gid of the desired mapping.
866  * @param *sid      Pointer to the sid of the desired mapping.
867  *
868  * @return #wbcErr
869  *
870  * @deprecated      This method is not impemented any more and should
871  *                  be removed in the next major version change.
872  **/
873 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid);
874
875 /**
876  * @brief Remove a user id mapping
877  *
878  * @param uid       Uid of the mapping to remove.
879  * @param *sid      Pointer to the sid of the mapping to remove.
880  *
881  * @return #wbcErr
882  *
883  * @deprecated      This method is not impemented any more and should
884  *                  be removed in the next major version change.
885  **/
886 wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid);
887
888 /**
889  * @brief Remove a group id mapping
890  *
891  * @param gid       Gid of the mapping to remove.
892  * @param *sid      Pointer to the sid of the mapping to remove.
893  *
894  * @return #wbcErr
895  *
896  * @deprecated      This method is not impemented any more and should
897  *                  be removed in the next major version change.
898  **/
899 wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid);
900
901 /**
902  * @brief Set the highwater mark for allocated uids.
903  *
904  * @param uid_hwm      The new uid highwater mark value
905  *
906  * @return #wbcErr
907  *
908  * @deprecated      This method is not impemented any more and should
909  *                  be removed in the next major version change.
910  **/
911 wbcErr wbcSetUidHwm(uid_t uid_hwm);
912
913 /**
914  * @brief Set the highwater mark for allocated gids.
915  *
916  * @param gid_hwm      The new gid highwater mark value
917  *
918  * @return #wbcErr
919  *
920  * @deprecated      This method is not impemented any more and should
921  *                  be removed in the next major version change.
922  **/
923 wbcErr wbcSetGidHwm(gid_t gid_hwm);
924
925 /**********************************************************
926  * NSS Lookup User/Group details
927  **********************************************************/
928
929 /**
930  * @brief Fill in a struct passwd* for a domain user based
931  *   on username
932  *
933  * @param *name     Username to lookup
934  * @param **pwd     Pointer to resulting struct passwd* from the query.
935  *
936  * @return #wbcErr
937  **/
938 wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
939
940 /**
941  * @brief Fill in a struct passwd* for a domain user based
942  *   on uid
943  *
944  * @param uid       Uid to lookup
945  * @param **pwd     Pointer to resulting struct passwd* from the query.
946  *
947  * @return #wbcErr
948  **/
949 wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
950
951 /**
952  * @brief Fill in a struct passwd* for a domain user based
953  *   on sid
954  *
955  * @param sid       Sid to lookup
956  * @param **pwd     Pointer to resulting struct passwd* from the query.
957  *
958  * @return #wbcErr
959  **/
960 wbcErr wbcGetpwsid(struct wbcDomainSid * sid, struct passwd **pwd);
961
962 /**
963  * @brief Fill in a struct passwd* for a domain user based
964  *   on username
965  *
966  * @param *name     Username to lookup
967  * @param **grp     Pointer to resulting struct group* from the query.
968  *
969  * @return #wbcErr
970  **/
971 wbcErr wbcGetgrnam(const char *name, struct group **grp);
972
973 /**
974  * @brief Fill in a struct passwd* for a domain user based
975  *   on uid
976  *
977  * @param gid       Uid to lookup
978  * @param **grp     Pointer to resulting struct group* from the query.
979  *
980  * @return #wbcErr
981  **/
982 wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
983
984 /**
985  * @brief Reset the passwd iterator
986  *
987  * @return #wbcErr
988  **/
989 wbcErr wbcSetpwent(void);
990
991 /**
992  * @brief Close the passwd iterator
993  *
994  * @return #wbcErr
995  **/
996 wbcErr wbcEndpwent(void);
997
998 /**
999  * @brief Return the next struct passwd* entry from the pwent iterator
1000  *
1001  * @param **pwd       Pointer to resulting struct passwd* from the query.
1002  *
1003  * @return #wbcErr
1004  **/
1005 wbcErr wbcGetpwent(struct passwd **pwd);
1006
1007 /**
1008  * @brief Reset the group iterator
1009  *
1010  * @return #wbcErr
1011  **/
1012 wbcErr wbcSetgrent(void);
1013
1014 /**
1015  * @brief Close the group iterator
1016  *
1017  * @return #wbcErr
1018  **/
1019 wbcErr wbcEndgrent(void);
1020
1021 /**
1022  * @brief Return the next struct group* entry from the pwent iterator
1023  *
1024  * @param **grp       Pointer to resulting struct group* from the query.
1025  *
1026  * @return #wbcErr
1027  **/
1028 wbcErr wbcGetgrent(struct group **grp);
1029
1030 /**
1031  * @brief Return the next struct group* entry from the pwent iterator
1032  *
1033  * This is similar to #wbcGetgrent, just that the member list is empty
1034  *
1035  * @param **grp       Pointer to resulting struct group* from the query.
1036  *
1037  * @return #wbcErr
1038  **/
1039 wbcErr wbcGetgrlist(struct group **grp);
1040
1041 /**
1042  * @brief Return the unix group array belonging to the given user
1043  *
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.
1047  *
1048  * @return #wbcErr
1049  **/
1050 wbcErr wbcGetGroups(const char *account,
1051                     uint32_t *num_groups,
1052                     gid_t **_groups);
1053
1054
1055 /**********************************************************
1056  * Lookup Domain information
1057  **********************************************************/
1058
1059 /**
1060  * @brief Lookup the current status of a trusted domain
1061  *
1062  * @param domain        The domain to query
1063  *
1064  * @param dinfo          A pointer to store the returned domain_info struct.
1065  *
1066  * @return #wbcErr
1067  **/
1068 wbcErr wbcDomainInfo(const char *domain,
1069                      struct wbcDomainInfo **dinfo);
1070
1071 /**
1072  * @brief Lookup the currently contacted DCs
1073  *
1074  * @param domain        The domain to query
1075  *
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
1079  *
1080  * @return #wbcErr
1081  **/
1082 wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
1083                  const char ***dc_names, const char ***dc_ips);
1084
1085 /**
1086  * @brief Enumerate the domain trusts known by Winbind
1087  *
1088  * @param **domains     Pointer to the allocated domain list array
1089  * @param *num_domains  Pointer to number of domains returned
1090  *
1091  * @return #wbcErr
1092  **/
1093 wbcErr wbcListTrusts(struct wbcDomainInfo **domains,
1094                      size_t *num_domains);
1095
1096 /* Flags for wbcLookupDomainController */
1097
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
1117
1118 /**
1119  * @brief Enumerate the domain trusts known by Winbind
1120  *
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
1124  *
1125  * @return #wbcErr
1126  **/
1127 wbcErr wbcLookupDomainController(const char *domain,
1128                                  uint32_t flags,
1129                                  struct wbcDomainControllerInfo **dc_info);
1130
1131 /**
1132  * @brief Get extended domain controller information
1133  *
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
1139  *
1140  * @return #wbcErr
1141  **/
1142 wbcErr wbcLookupDomainControllerEx(const char *domain,
1143                                    struct wbcGuid *guid,
1144                                    const char *site,
1145                                    uint32_t flags,
1146                                    struct wbcDomainControllerInfoEx **dc_info);
1147
1148 /**********************************************************
1149  * Athenticate functions
1150  **********************************************************/
1151
1152 /**
1153  * @brief Authenticate a username/password pair
1154  *
1155  * @param username     Name of user to authenticate
1156  * @param password     Clear text password os user
1157  *
1158  * @return #wbcErr
1159  **/
1160 wbcErr wbcAuthenticateUser(const char *username,
1161                            const char *password);
1162
1163 /**
1164  * @brief Authenticate with more detailed information
1165  *
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
1170  *
1171  * @return #wbcErr
1172  **/
1173 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
1174                              struct wbcAuthUserInfo **info,
1175                              struct wbcAuthErrorInfo **error);
1176
1177 /**
1178  * @brief Logon a User
1179  *
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
1184  *
1185  * @return #wbcErr
1186  **/
1187 wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
1188                     struct wbcLogonUserInfo **info,
1189                     struct wbcAuthErrorInfo **error,
1190                     struct wbcUserPasswordPolicyInfo **policy);
1191
1192 /**
1193  * @brief Trigger a logoff notification to Winbind for a specific user
1194  *
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
1200  *
1201  * @return #wbcErr
1202  **/
1203 wbcErr wbcLogoffUser(const char *username,
1204                      uid_t uid,
1205                      const char *ccfilename);
1206
1207 /**
1208  * @brief Trigger an extended logoff notification to Winbind for a specific user
1209  *
1210  * @param params      A wbcLogoffUserParams structure
1211  * @param error       User output details on error
1212  *
1213  * @return #wbcErr
1214  **/
1215 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
1216                        struct wbcAuthErrorInfo **error);
1217
1218 /**
1219  * @brief Change a password for a user
1220  *
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
1224  *
1225  * @return #wbcErr
1226  **/
1227 wbcErr wbcChangeUserPassword(const char *username,
1228                              const char *old_password,
1229                              const char *new_password);
1230
1231 /**
1232  * @brief Change a password for a user with more detailed information upon
1233  *   failure
1234  *
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
1239  *
1240  * @return #wbcErr
1241  **/
1242 wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
1243                                struct wbcAuthErrorInfo **error,
1244                                enum wbcPasswordChangeRejectReason *reject_reason,
1245                                struct wbcUserPasswordPolicyInfo **policy);
1246
1247 /**
1248  * @brief Authenticate a user with cached credentials
1249  *
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
1253  *
1254  * @return #wbcErr
1255  **/
1256 wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
1257                           struct wbcCredentialCacheInfo **info,
1258                           struct wbcAuthErrorInfo **error);
1259
1260 /**
1261  * @brief Save a password with winbind for doing wbcCredentialCache() later
1262  *
1263  * @param *user      Username
1264  * @param *password  Password
1265  *
1266  * @return #wbcErr
1267  **/
1268 wbcErr wbcCredentialSave(const char *user, const char *password);
1269
1270 /**********************************************************
1271  * Resolve functions
1272  **********************************************************/
1273
1274 /**
1275  * @brief Resolve a NetbiosName via WINS
1276  *
1277  * @param name         Name to resolve
1278  * @param *ip          Pointer to the ip address string
1279  *
1280  * @return #wbcErr
1281  **/
1282 wbcErr wbcResolveWinsByName(const char *name, char **ip);
1283
1284 /**
1285  * @brief Resolve an IP address via WINS into a NetbiosName
1286  *
1287  * @param ip          The ip address string
1288  * @param *name       Pointer to the name
1289  *
1290  * @return #wbcErr
1291  *
1292  **/
1293 wbcErr wbcResolveWinsByIP(const char *ip, char **name);
1294
1295 /**********************************************************
1296  * Trusted domain functions
1297  **********************************************************/
1298
1299 /**
1300  * @brief Trigger a verification of the trust credentials of a specific domain
1301  *
1302  * @param *domain      The name of the domain.
1303  * @param error        Output details on WBC_ERR_AUTH_ERROR
1304  *
1305  * @return #wbcErr
1306  **/
1307 wbcErr wbcCheckTrustCredentials(const char *domain,
1308                                 struct wbcAuthErrorInfo **error);
1309
1310 /**
1311  * @brief Trigger a change of the trust credentials for a specific domain
1312  *
1313  * @param *domain      The name of the domain.
1314  * @param error        Output details on WBC_ERR_AUTH_ERROR
1315  *
1316  * @return #wbcErr
1317  **/
1318 wbcErr wbcChangeTrustCredentials(const char *domain,
1319                                  struct wbcAuthErrorInfo **error);
1320
1321 /**
1322  * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
1323  *        version of wbcCheckTrustCredentials
1324  *
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
1329  *
1330  * @return #wbcErr
1331  **/
1332 wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error);
1333
1334 /**
1335  * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
1336  *        version of wbcCheckTrustCredentials
1337  *
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
1343  *
1344  * @return #wbcErr
1345  **/
1346 wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
1347                   char **dcname);
1348
1349 /**********************************************************
1350  * Helper functions
1351  **********************************************************/
1352
1353 /**
1354  * @brief Initialize a named blob and add to list of blobs
1355  *
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
1362  *
1363  * @return #wbcErr
1364  **/
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);
1371
1372 #endif      /* _WBCLIENT_H */