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