cb70cbd51386f45d856848e736d8e1df55dc4f2b
[kai/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  **/
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 Auth User Parameters
201  **/
202
203 struct wbcAuthUserParams {
204         const char *account_name;
205         const char *domain_name;
206         const char *workstation_name;
207
208         uint32_t flags;
209
210         uint32_t parameter_control;
211
212         enum wbcAuthUserLevel {
213                 WBC_AUTH_USER_LEVEL_PLAIN = 1,
214                 WBC_AUTH_USER_LEVEL_HASH = 2,
215                 WBC_AUTH_USER_LEVEL_RESPONSE = 3
216         } level;
217         union {
218                 const char *plaintext;
219                 struct {
220                         uint8_t nt_hash[16];
221                         uint8_t lm_hash[16];
222                 } hash;
223                 struct {
224                         uint8_t challenge[8];
225                         uint32_t nt_length;
226                         uint8_t *nt_data;
227                         uint32_t lm_length;
228                         uint8_t *lm_data;
229                 } response;
230         } password;
231 };
232
233 /**
234  * @brief Generic Blob
235  **/
236
237 struct wbcBlob {
238         uint8_t *data;
239         size_t length;
240 };
241
242 /**
243  * @brief Named Blob
244  **/
245
246 struct wbcNamedBlob {
247         const char *name;
248         uint32_t flags;
249         struct wbcBlob blob;
250 };
251
252 /**
253  * @brief Logon User Parameters
254  **/
255
256 struct wbcLogonUserParams {
257         const char *username;
258         const char *password;
259         size_t num_blobs;
260         struct wbcNamedBlob *blobs;
261 };
262
263 /**
264  * @brief ChangePassword Parameters
265  **/
266
267 struct wbcChangePasswordParams {
268         const char *account_name;
269         const char *domain_name;
270
271         uint32_t flags;
272
273         enum wbcChangePasswordLevel {
274                 WBC_CHANGE_PASSWORD_LEVEL_PLAIN = 1,
275                 WBC_CHANGE_PASSWORD_LEVEL_RESPONSE = 2
276         } level;
277
278         union {
279                 const char *plaintext;
280                 struct {
281                         uint32_t old_nt_hash_enc_length;
282                         uint8_t *old_nt_hash_enc_data;
283                         uint32_t old_lm_hash_enc_length;
284                         uint8_t *old_lm_hash_enc_data;
285                 } response;
286         } old_password;
287         union {
288                 const char *plaintext;
289                 struct {
290                         uint32_t nt_length;
291                         uint8_t *nt_data;
292                         uint32_t lm_length;
293                         uint8_t *lm_data;
294                 } response;
295         } new_password;
296 };
297
298 /* wbcAuthUserParams->parameter_control */
299
300 #define WBC_MSV1_0_CLEARTEXT_PASSWORD_ALLOWED           0x00000002
301 #define WBC_MSV1_0_UPDATE_LOGON_STATISTICS              0x00000004
302 #define WBC_MSV1_0_RETURN_USER_PARAMETERS               0x00000008
303 #define WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT           0x00000020
304 #define WBC_MSV1_0_RETURN_PROFILE_PATH                  0x00000200
305 #define WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT      0x00000800
306
307 /* wbcAuthUserParams->flags */
308
309 #define WBC_AUTH_PARAM_FLAGS_INTERACTIVE_LOGON          0x00000001
310
311 /**
312  * @brief Auth User Information
313  *
314  * Some of the strings are maybe NULL
315  **/
316
317 struct wbcAuthUserInfo {
318         uint32_t user_flags;
319
320         char *account_name;
321         char *user_principal;
322         char *full_name;
323         char *domain_name;
324         char *dns_domain_name;
325
326         uint32_t acct_flags;
327         uint8_t user_session_key[16];
328         uint8_t lm_session_key[8];
329
330         uint16_t logon_count;
331         uint16_t bad_password_count;
332
333         uint64_t logon_time;
334         uint64_t logoff_time;
335         uint64_t kickoff_time;
336         uint64_t pass_last_set_time;
337         uint64_t pass_can_change_time;
338         uint64_t pass_must_change_time;
339
340         char *logon_server;
341         char *logon_script;
342         char *profile_path;
343         char *home_directory;
344         char *home_drive;
345
346         /*
347          * the 1st one is the account sid
348          * the 2nd one is the primary_group sid
349          * followed by the rest of the groups
350          */
351         uint32_t num_sids;
352         struct wbcSidWithAttr *sids;
353 };
354
355 /**
356  * @brief Logon User Information
357  *
358  * Some of the strings are maybe NULL
359  **/
360
361 struct wbcLogonUserInfo {
362         struct wbcAuthUserInfo *info;
363         size_t num_blobs;
364         struct wbcNamedBlob *blobs;
365 };
366
367 /* wbcAuthUserInfo->user_flags */
368
369 #define WBC_AUTH_USER_INFO_GUEST                        0x00000001
370 #define WBC_AUTH_USER_INFO_NOENCRYPTION                 0x00000002
371 #define WBC_AUTH_USER_INFO_CACHED_ACCOUNT               0x00000004
372 #define WBC_AUTH_USER_INFO_USED_LM_PASSWORD             0x00000008
373 #define WBC_AUTH_USER_INFO_EXTRA_SIDS                   0x00000020
374 #define WBC_AUTH_USER_INFO_SUBAUTH_SESSION_KEY          0x00000040
375 #define WBC_AUTH_USER_INFO_SERVER_TRUST_ACCOUNT         0x00000080
376 #define WBC_AUTH_USER_INFO_NTLMV2_ENABLED               0x00000100
377 #define WBC_AUTH_USER_INFO_RESOURCE_GROUPS              0x00000200
378 #define WBC_AUTH_USER_INFO_PROFILE_PATH_RETURNED        0x00000400
379 #define WBC_AUTH_USER_INFO_GRACE_LOGON                  0x01000000
380
381 /* wbcAuthUserInfo->acct_flags */
382
383 #define WBC_ACB_DISABLED                        0x00000001 /* 1 User account disabled */
384 #define WBC_ACB_HOMDIRREQ                       0x00000002 /* 1 Home directory required */
385 #define WBC_ACB_PWNOTREQ                        0x00000004 /* 1 User password not required */
386 #define WBC_ACB_TEMPDUP                         0x00000008 /* 1 Temporary duplicate account */
387 #define WBC_ACB_NORMAL                          0x00000010 /* 1 Normal user account */
388 #define WBC_ACB_MNS                             0x00000020 /* 1 MNS logon user account */
389 #define WBC_ACB_DOMTRUST                        0x00000040 /* 1 Interdomain trust account */
390 #define WBC_ACB_WSTRUST                         0x00000080 /* 1 Workstation trust account */
391 #define WBC_ACB_SVRTRUST                        0x00000100 /* 1 Server trust account */
392 #define WBC_ACB_PWNOEXP                         0x00000200 /* 1 User password does not expire */
393 #define WBC_ACB_AUTOLOCK                        0x00000400 /* 1 Account auto locked */
394 #define WBC_ACB_ENC_TXT_PWD_ALLOWED             0x00000800 /* 1 Encryped text password is allowed */
395 #define WBC_ACB_SMARTCARD_REQUIRED              0x00001000 /* 1 Smart Card required */
396 #define WBC_ACB_TRUSTED_FOR_DELEGATION          0x00002000 /* 1 Trusted for Delegation */
397 #define WBC_ACB_NOT_DELEGATED                   0x00004000 /* 1 Not delegated */
398 #define WBC_ACB_USE_DES_KEY_ONLY                0x00008000 /* 1 Use DES key only */
399 #define WBC_ACB_DONT_REQUIRE_PREAUTH            0x00010000 /* 1 Preauth not required */
400 #define WBC_ACB_PW_EXPIRED                      0x00020000 /* 1 Password Expired */
401 #define WBC_ACB_NO_AUTH_DATA_REQD               0x00080000   /* 1 = No authorization data required */
402
403 struct wbcAuthErrorInfo {
404         uint32_t nt_status;
405         char *nt_string;
406         int32_t pam_error;
407         char *display_string;
408 };
409
410 /**
411  * @brief User Password Policy Information
412  **/
413
414 /* wbcUserPasswordPolicyInfo->password_properties */
415
416 #define WBC_DOMAIN_PASSWORD_COMPLEX             0x00000001
417 #define WBC_DOMAIN_PASSWORD_NO_ANON_CHANGE      0x00000002
418 #define WBC_DOMAIN_PASSWORD_NO_CLEAR_CHANGE     0x00000004
419 #define WBC_DOMAIN_PASSWORD_LOCKOUT_ADMINS      0x00000008
420 #define WBC_DOMAIN_PASSWORD_STORE_CLEARTEXT     0x00000010
421 #define WBC_DOMAIN_REFUSE_PASSWORD_CHANGE       0x00000020
422
423 struct wbcUserPasswordPolicyInfo {
424         uint32_t min_length_password;
425         uint32_t password_history;
426         uint32_t password_properties;
427         uint64_t expire;
428         uint64_t min_passwordage;
429 };
430
431 /**
432  * @brief Change Password Reject Reason
433  **/
434
435 enum wbcPasswordChangeRejectReason {
436         WBC_PWD_CHANGE_NO_ERROR=0,
437         WBC_PWD_CHANGE_PASSWORD_TOO_SHORT=1,
438         WBC_PWD_CHANGE_PWD_IN_HISTORY=2,
439         WBC_PWD_CHANGE_USERNAME_IN_PASSWORD=3,
440         WBC_PWD_CHANGE_FULLNAME_IN_PASSWORD=4,
441         WBC_PWD_CHANGE_NOT_COMPLEX=5,
442         WBC_PWD_CHANGE_MACHINE_NOT_DEFAULT=6,
443         WBC_PWD_CHANGE_FAILED_BY_FILTER=7,
444         WBC_PWD_CHANGE_PASSWORD_TOO_LONG=8
445 };
446
447 /* Note: this defines exist for compatibility reasons with existing code */
448 #define WBC_PWD_CHANGE_REJECT_OTHER      WBC_PWD_CHANGE_NO_ERROR
449 #define WBC_PWD_CHANGE_REJECT_TOO_SHORT  WBC_PWD_CHANGE_PASSWORD_TOO_SHORT
450 #define WBC_PWD_CHANGE_REJECT_IN_HISTORY WBC_PWD_CHANGE_PWD_IN_HISTORY
451 #define WBC_PWD_CHANGE_REJECT_COMPLEXITY WBC_PWD_CHANGE_NOT_COMPLEX
452
453 /**
454  * @brief Logoff User Parameters
455  **/
456
457 struct wbcLogoffUserParams {
458         const char *username;
459         size_t num_blobs;
460         struct wbcNamedBlob *blobs;
461 };
462
463 /** @brief Credential cache log-on parameters
464  *
465  */
466
467 struct wbcCredentialCacheParams {
468         const char *account_name;
469         const char *domain_name;
470         enum wbcCredentialCacheLevel {
471                 WBC_CREDENTIAL_CACHE_LEVEL_NTLMSSP = 1
472         } level;
473         size_t num_blobs;
474         struct wbcNamedBlob *blobs;
475 };
476
477
478 /** @brief Info returned by credential cache auth
479  *
480  */
481
482 struct wbcCredentialCacheInfo {
483         size_t num_blobs;
484         struct wbcNamedBlob *blobs;
485 };
486
487 /*
488  * DomainControllerInfo struct
489  */
490 struct wbcDomainControllerInfo {
491         char *dc_name;
492 };
493
494 /*
495  * DomainControllerInfoEx struct
496  */
497 struct wbcDomainControllerInfoEx {
498         const char *dc_unc;
499         const char *dc_address;
500         uint16_t dc_address_type;
501         struct wbcGuid *domain_guid;
502         const char *domain_name;
503         const char *forest_name;
504         uint32_t dc_flags;
505         const char *dc_site_name;
506         const char *client_site_name;
507 };
508
509 /**********************************************************
510  * Memory Management
511  **********************************************************/
512
513 /**
514  * @brief Free library allocated memory
515  *
516  * @param * Pointer to free
517  *
518  * @return void
519  **/
520 void wbcFreeMemory(void*);
521
522
523 /*
524  * Utility functions for dealing with SIDs
525  */
526
527 /**
528  * @brief Get a string representation of the SID type
529  *
530  * @param type          type of the SID
531  *
532  * @return string representation of the SID type
533  */
534 const char* wbcSidTypeString(enum wbcSidType type);
535
536 #define WBC_SID_STRING_BUFLEN (15*11+25)
537
538 /*
539  * @brief Print a sid into a buffer
540  *
541  * @param sid           Binary Security Identifier
542  * @param buf           Target buffer
543  * @param buflen        Target buffer length
544  *
545  * @return Resulting string length.
546  */
547 int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen);
548
549 /**
550  * @brief Convert a binary SID to a character string
551  *
552  * @param sid           Binary Security Identifier
553  * @param **sid_string  Resulting character string
554  *
555  * @return #wbcErr
556  **/
557 wbcErr wbcSidToString(const struct wbcDomainSid *sid,
558                       char **sid_string);
559
560 /**
561  * @brief Convert a character string to a binary SID
562  *
563  * @param *sid_string   Character string in the form of S-...
564  * @param sid           Resulting binary SID
565  *
566  * @return #wbcErr
567  **/
568 wbcErr wbcStringToSid(const char *sid_string,
569                       struct wbcDomainSid *sid);
570
571 /*
572  * Utility functions for dealing with GUIDs
573  */
574
575 /**
576  * @brief Convert a binary GUID to a character string
577  *
578  * @param guid           Binary Guid
579  * @param **guid_string  Resulting character string
580  *
581  * @return #wbcErr
582  **/
583 wbcErr wbcGuidToString(const struct wbcGuid *guid,
584                        char **guid_string);
585
586 /**
587  * @brief Convert a character string to a binary GUID
588  *
589  * @param *guid_string  Character string
590  * @param guid          Resulting binary GUID
591  *
592  * @return #wbcErr
593  **/
594 wbcErr wbcStringToGuid(const char *guid_string,
595                        struct wbcGuid *guid);
596
597 /**
598  * @brief Ping winbindd to see if the daemon is running
599  *
600  * @return #wbcErr
601  **/
602 wbcErr wbcPing(void);
603
604 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
605
606 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
607
608 /**********************************************************
609  * Name/SID conversion
610  **********************************************************/
611
612 /**
613  * @brief Convert a domain and name to SID
614  *
615  * @param dom_name    Domain name (possibly "")
616  * @param name        User or group name
617  * @param *sid        Pointer to the resolved domain SID
618  * @param *name_type  Pointer to the SID type
619  *
620  * @return #wbcErr
621  **/
622 wbcErr wbcLookupName(const char *dom_name,
623                      const char *name,
624                      struct wbcDomainSid *sid,
625                      enum wbcSidType *name_type);
626
627 /**
628  * @brief Convert a SID to a domain and name
629  *
630  * @param *sid        Pointer to the domain SID to be resolved
631  * @param domain     Resolved Domain name (possibly "")
632  * @param name       Resolved User or group name
633  * @param *name_type Pointer to the resolved SID type
634  *
635  * @return #wbcErr
636  **/
637 wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
638                     char **domain,
639                     char **name,
640                     enum wbcSidType *name_type);
641
642 struct wbcTranslatedName {
643         enum wbcSidType type;
644         char *name;
645         int domain_index;
646 };
647
648 wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
649                      struct wbcDomainInfo **domains, int *num_domains,
650                      struct wbcTranslatedName **names);
651
652 /**
653  * @brief Translate a collection of RIDs within a domain to names
654  */
655 wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
656                      int num_rids,
657                      uint32_t *rids,
658                      const char **domain_name,
659                      const char ***names,
660                      enum wbcSidType **types);
661
662 /*
663  * @brief Get the groups a user belongs to
664  **/
665 wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
666                          bool domain_groups_only,
667                          uint32_t *num_sids,
668                          struct wbcDomainSid **sids);
669
670 /*
671  * @brief Get alias membership for sids
672  **/
673 wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
674                         struct wbcDomainSid *sids,
675                         uint32_t num_sids,
676                         uint32_t **alias_rids,
677                         uint32_t *num_alias_rids);
678
679 /**
680  * @brief Lists Users
681  **/
682 wbcErr wbcListUsers(const char *domain_name,
683                     uint32_t *num_users,
684                     const char ***users);
685
686 /**
687  * @brief Lists Groups
688  **/
689 wbcErr wbcListGroups(const char *domain_name,
690                      uint32_t *num_groups,
691                      const char ***groups);
692
693 wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
694                          char **pdomain,
695                          char **pfullname,
696                          enum wbcSidType *pname_type);
697
698 /**********************************************************
699  * SID/uid/gid Mappings
700  **********************************************************/
701
702 /**
703  * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
704  *
705  * @param *sid        Pointer to the domain SID to be resolved
706  * @param *puid       Pointer to the resolved uid_t value
707  *
708  * @return #wbcErr
709  *
710  **/
711 wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
712                    uid_t *puid);
713
714 /**
715  * @brief Convert a Windows SID to a Unix uid if there already is a mapping
716  *
717  * @param *sid        Pointer to the domain SID to be resolved
718  * @param *puid       Pointer to the resolved uid_t value
719  *
720  * @return #wbcErr
721  *
722  **/
723 wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
724                         uid_t *puid);
725
726 /**
727  * @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
728  *
729  * @param uid         Unix uid to be resolved
730  * @param *sid        Pointer to the resolved domain SID
731  *
732  * @return #wbcErr
733  *
734  **/
735 wbcErr wbcUidToSid(uid_t uid,
736                    struct wbcDomainSid *sid);
737
738 /**
739  * @brief Convert a Unix uid to a Windows SID if there already is a mapping
740  *
741  * @param uid         Unix uid to be resolved
742  * @param *sid        Pointer to the resolved domain SID
743  *
744  * @return #wbcErr
745  *
746  **/
747 wbcErr wbcQueryUidToSid(uid_t uid,
748                         struct wbcDomainSid *sid);
749
750 /**
751  * @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
752  *
753  * @param *sid        Pointer to the domain SID to be resolved
754  * @param *pgid       Pointer to the resolved gid_t value
755  *
756  * @return #wbcErr
757  *
758  **/
759 wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
760                    gid_t *pgid);
761
762 /**
763  * @brief Convert a Windows SID to a Unix gid if there already is a mapping
764  *
765  * @param *sid        Pointer to the domain SID to be resolved
766  * @param *pgid       Pointer to the resolved gid_t value
767  *
768  * @return #wbcErr
769  *
770  **/
771 wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
772                         gid_t *pgid);
773
774 /**
775  * @brief Convert a Unix gid to a Windows SID, allocating a SID if needed
776  *
777  * @param gid         Unix gid to be resolved
778  * @param *sid        Pointer to the resolved domain SID
779  *
780  * @return #wbcErr
781  *
782  **/
783 wbcErr wbcGidToSid(gid_t gid,
784                    struct wbcDomainSid *sid);
785
786 /**
787  * @brief Convert a Unix gid to a Windows SID if there already is a mapping
788  *
789  * @param gid         Unix gid to be resolved
790  * @param *sid        Pointer to the resolved domain SID
791  *
792  * @return #wbcErr
793  *
794  **/
795 wbcErr wbcQueryGidToSid(gid_t gid,
796                         struct wbcDomainSid *sid);
797
798 enum wbcIdType {
799         WBC_ID_TYPE_NOT_SPECIFIED,
800         WBC_ID_TYPE_UID,
801         WBC_ID_TYPE_GID,
802         WBC_ID_TYPE_BOTH
803 };
804
805 union wbcUnixIdContainer {
806         uid_t uid;
807         gid_t gid;
808 };
809
810 struct wbcUnixId {
811         enum wbcIdType type;
812         union wbcUnixIdContainer id;
813 };
814
815 /**
816  * @brief Convert a list of sids to unix ids
817  *
818  * @param sids        Pointer to an array of SIDs to convert
819  * @param num_sids    Number of SIDs
820  * @param ids         Preallocated output array for translated IDs
821  *
822  * @return #wbcErr
823  *
824  **/
825 wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
826                         struct wbcUnixId *ids);
827
828 /**
829  * @brief Obtain a new uid from Winbind
830  *
831  * @param *puid      *pointer to the allocated uid
832  *
833  * @return #wbcErr
834  **/
835 wbcErr wbcAllocateUid(uid_t *puid);
836
837 /**
838  * @brief Obtain a new gid from Winbind
839  *
840  * @param *pgid      Pointer to the allocated gid
841  *
842  * @return #wbcErr
843  **/
844 wbcErr wbcAllocateGid(gid_t *pgid);
845
846 /**
847  * @brief Set an user id mapping
848  *
849  * @param uid       Uid of the desired mapping.
850  * @param *sid      Pointer to the sid of the diresired mapping.
851  *
852  * @return #wbcErr
853  *
854  * @deprecated      This method is not impemented any more and should
855  *                  be removed in the next major version change.
856  **/
857 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid);
858
859 /**
860  * @brief Set a group id mapping
861  *
862  * @param gid       Gid of the desired mapping.
863  * @param *sid      Pointer to the sid of the diresired mapping.
864  *
865  * @return #wbcErr
866  *
867  * @deprecated      This method is not impemented any more and should
868  *                  be removed in the next major version change.
869  **/
870 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid);
871
872 /**
873  * @brief Remove a user id mapping
874  *
875  * @param uid       Uid of the mapping to remove.
876  * @param *sid      Pointer to the sid of the mapping to remove.
877  *
878  * @return #wbcErr
879  *
880  * @deprecated      This method is not impemented any more and should
881  *                  be removed in the next major version change.
882  **/
883 wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid);
884
885 /**
886  * @brief Remove a group id mapping
887  *
888  * @param gid       Gid of the mapping to remove.
889  * @param *sid      Pointer to the sid of the mapping to remove.
890  *
891  * @return #wbcErr
892  *
893  * @deprecated      This method is not impemented any more and should
894  *                  be removed in the next major version change.
895  **/
896 wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid);
897
898 /**
899  * @brief Set the highwater mark for allocated uids.
900  *
901  * @param uid_hwm      The new uid highwater mark value
902  *
903  * @return #wbcErr
904  *
905  * @deprecated      This method is not impemented any more and should
906  *                  be removed in the next major version change.
907  **/
908 wbcErr wbcSetUidHwm(uid_t uid_hwm);
909
910 /**
911  * @brief Set the highwater mark for allocated gids.
912  *
913  * @param gid_hwm      The new gid highwater mark value
914  *
915  * @return #wbcErr
916  *
917  * @deprecated      This method is not impemented any more and should
918  *                  be removed in the next major version change.
919  **/
920 wbcErr wbcSetGidHwm(gid_t gid_hwm);
921
922 /**********************************************************
923  * NSS Lookup User/Group details
924  **********************************************************/
925
926 /**
927  * @brief Fill in a struct passwd* for a domain user based
928  *   on username
929  *
930  * @param *name     Username to lookup
931  * @param **pwd     Pointer to resulting struct passwd* from the query.
932  *
933  * @return #wbcErr
934  **/
935 wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
936
937 /**
938  * @brief Fill in a struct passwd* for a domain user based
939  *   on uid
940  *
941  * @param uid       Uid to lookup
942  * @param **pwd     Pointer to resulting struct passwd* from the query.
943  *
944  * @return #wbcErr
945  **/
946 wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
947
948 /**
949  * @brief Fill in a struct passwd* for a domain user based
950  *   on sid
951  *
952  * @param sid       Sid to lookup
953  * @param **pwd     Pointer to resulting struct passwd* from the query.
954  *
955  * @return #wbcErr
956  **/
957 wbcErr wbcGetpwsid(struct wbcDomainSid * sid, struct passwd **pwd);
958
959 /**
960  * @brief Fill in a struct passwd* for a domain user based
961  *   on username
962  *
963  * @param *name     Username to lookup
964  * @param **grp     Pointer to resulting struct group* from the query.
965  *
966  * @return #wbcErr
967  **/
968 wbcErr wbcGetgrnam(const char *name, struct group **grp);
969
970 /**
971  * @brief Fill in a struct passwd* for a domain user based
972  *   on uid
973  *
974  * @param gid       Uid to lookup
975  * @param **grp     Pointer to resulting struct group* from the query.
976  *
977  * @return #wbcErr
978  **/
979 wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
980
981 /**
982  * @brief Reset the passwd iterator
983  *
984  * @return #wbcErr
985  **/
986 wbcErr wbcSetpwent(void);
987
988 /**
989  * @brief Close the passwd iterator
990  *
991  * @return #wbcErr
992  **/
993 wbcErr wbcEndpwent(void);
994
995 /**
996  * @brief Return the next struct passwd* entry from the pwent iterator
997  *
998  * @param **pwd       Pointer to resulting struct passwd* from the query.
999  *
1000  * @return #wbcErr
1001  **/
1002 wbcErr wbcGetpwent(struct passwd **pwd);
1003
1004 /**
1005  * @brief Reset the group iterator
1006  *
1007  * @return #wbcErr
1008  **/
1009 wbcErr wbcSetgrent(void);
1010
1011 /**
1012  * @brief Close the group iterator
1013  *
1014  * @return #wbcErr
1015  **/
1016 wbcErr wbcEndgrent(void);
1017
1018 /**
1019  * @brief Return the next struct group* entry from the pwent iterator
1020  *
1021  * @param **grp       Pointer to resulting struct group* from the query.
1022  *
1023  * @return #wbcErr
1024  **/
1025 wbcErr wbcGetgrent(struct group **grp);
1026
1027 /**
1028  * @brief Return the next struct group* entry from the pwent iterator
1029  *
1030  * This is similar to #wbcGetgrent, just that the member list is empty
1031  *
1032  * @param **grp       Pointer to resulting struct group* from the query.
1033  *
1034  * @return #wbcErr
1035  **/
1036 wbcErr wbcGetgrlist(struct group **grp);
1037
1038 /**
1039  * @brief Return the unix group array belonging to the given user
1040  *
1041  * @param *account       The given user name
1042  * @param *num_groups    Number of elements returned in the groups array
1043  * @param **_groups      Pointer to resulting gid_t array.
1044  *
1045  * @return #wbcErr
1046  **/
1047 wbcErr wbcGetGroups(const char *account,
1048                     uint32_t *num_groups,
1049                     gid_t **_groups);
1050
1051
1052 /**********************************************************
1053  * Lookup Domain information
1054  **********************************************************/
1055
1056 /**
1057  * @brief Lookup the current status of a trusted domain
1058  *
1059  * @param domain        The domain to query
1060  *
1061  * @param dinfo          A pointer to store the returned domain_info struct.
1062  *
1063  * @return #wbcErr
1064  **/
1065 wbcErr wbcDomainInfo(const char *domain,
1066                      struct wbcDomainInfo **dinfo);
1067
1068 /**
1069  * @brief Lookup the currently contacted DCs
1070  *
1071  * @param domain        The domain to query
1072  *
1073  * @param num_dcs       Number of DCs currently known
1074  * @param dc_names      Names of the currently known DCs
1075  * @param dc_ips        IP addresses of the currently known DCs
1076  *
1077  * @return #wbcErr
1078  **/
1079 wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
1080                  const char ***dc_names, const char ***dc_ips);
1081
1082 /**
1083  * @brief Enumerate the domain trusts known by Winbind
1084  *
1085  * @param **domains     Pointer to the allocated domain list array
1086  * @param *num_domains  Pointer to number of domains returned
1087  *
1088  * @return #wbcErr
1089  **/
1090 wbcErr wbcListTrusts(struct wbcDomainInfo **domains,
1091                      size_t *num_domains);
1092
1093 /* Flags for wbcLookupDomainController */
1094
1095 #define WBC_LOOKUP_DC_FORCE_REDISCOVERY        0x00000001
1096 #define WBC_LOOKUP_DC_DS_REQUIRED              0x00000010
1097 #define WBC_LOOKUP_DC_DS_PREFERRED             0x00000020
1098 #define WBC_LOOKUP_DC_GC_SERVER_REQUIRED       0x00000040
1099 #define WBC_LOOKUP_DC_PDC_REQUIRED             0x00000080
1100 #define WBC_LOOKUP_DC_BACKGROUND_ONLY          0x00000100
1101 #define WBC_LOOKUP_DC_IP_REQUIRED              0x00000200
1102 #define WBC_LOOKUP_DC_KDC_REQUIRED             0x00000400
1103 #define WBC_LOOKUP_DC_TIMESERV_REQUIRED        0x00000800
1104 #define WBC_LOOKUP_DC_WRITABLE_REQUIRED        0x00001000
1105 #define WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED  0x00002000
1106 #define WBC_LOOKUP_DC_AVOID_SELF               0x00004000
1107 #define WBC_LOOKUP_DC_ONLY_LDAP_NEEDED         0x00008000
1108 #define WBC_LOOKUP_DC_IS_FLAT_NAME             0x00010000
1109 #define WBC_LOOKUP_DC_IS_DNS_NAME              0x00020000
1110 #define WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE     0x00040000
1111 #define WBC_LOOKUP_DC_DS_6_REQUIRED            0x00080000
1112 #define WBC_LOOKUP_DC_RETURN_DNS_NAME          0x40000000
1113 #define WBC_LOOKUP_DC_RETURN_FLAT_NAME         0x80000000
1114
1115 /**
1116  * @brief Enumerate the domain trusts known by Winbind
1117  *
1118  * @param domain        Name of the domain to query for a DC
1119  * @param flags         Bit flags used to control the domain location query
1120  * @param *dc_info      Pointer to the returned domain controller information
1121  *
1122  * @return #wbcErr
1123  **/
1124 wbcErr wbcLookupDomainController(const char *domain,
1125                                  uint32_t flags,
1126                                  struct wbcDomainControllerInfo **dc_info);
1127
1128 /**
1129  * @brief Get extended domain controller information
1130  *
1131  * @param domain        Name of the domain to query for a DC
1132  * @param guid          Guid of the domain to query for a DC
1133  * @param site          Site of the domain to query for a DC
1134  * @param flags         Bit flags used to control the domain location query
1135  * @param *dc_info      Pointer to the returned extended domain controller information
1136  *
1137  * @return #wbcErr
1138  **/
1139 wbcErr wbcLookupDomainControllerEx(const char *domain,
1140                                    struct wbcGuid *guid,
1141                                    const char *site,
1142                                    uint32_t flags,
1143                                    struct wbcDomainControllerInfoEx **dc_info);
1144
1145 /**********************************************************
1146  * Athenticate functions
1147  **********************************************************/
1148
1149 /**
1150  * @brief Authenticate a username/password pair
1151  *
1152  * @param username     Name of user to authenticate
1153  * @param password     Clear text password os user
1154  *
1155  * @return #wbcErr
1156  **/
1157 wbcErr wbcAuthenticateUser(const char *username,
1158                            const char *password);
1159
1160 /**
1161  * @brief Authenticate with more detailed information
1162  *
1163  * @param params       Input parameters, WBC_AUTH_USER_LEVEL_HASH
1164  *                     is not supported yet
1165  * @param info         Output details on WBC_ERR_SUCCESS
1166  * @param error        Output details on WBC_ERR_AUTH_ERROR
1167  *
1168  * @return #wbcErr
1169  **/
1170 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
1171                              struct wbcAuthUserInfo **info,
1172                              struct wbcAuthErrorInfo **error);
1173
1174 /**
1175  * @brief Logon a User
1176  *
1177  * @param[in]  params      Pointer to a wbcLogonUserParams structure
1178  * @param[out] info        Pointer to a pointer to a wbcLogonUserInfo structure
1179  * @param[out] error       Pointer to a pointer to a wbcAuthErrorInfo structure
1180  * @param[out] policy      Pointer to a pointer to a wbcUserPasswordPolicyInfo structure
1181  *
1182  * @return #wbcErr
1183  **/
1184 wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
1185                     struct wbcLogonUserInfo **info,
1186                     struct wbcAuthErrorInfo **error,
1187                     struct wbcUserPasswordPolicyInfo **policy);
1188
1189 /**
1190  * @brief Trigger a logoff notification to Winbind for a specific user
1191  *
1192  * @param username    Name of user to remove from Winbind's list of
1193  *                    logged on users.
1194  * @param uid         Uid assigned to the username
1195  * @param ccfilename  Absolute path to the Krb5 credentials cache to
1196  *                    be removed
1197  *
1198  * @return #wbcErr
1199  **/
1200 wbcErr wbcLogoffUser(const char *username,
1201                      uid_t uid,
1202                      const char *ccfilename);
1203
1204 /**
1205  * @brief Trigger an extended logoff notification to Winbind for a specific user
1206  *
1207  * @param params      A wbcLogoffUserParams structure
1208  * @param error       User output details on error
1209  *
1210  * @return #wbcErr
1211  **/
1212 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
1213                        struct wbcAuthErrorInfo **error);
1214
1215 /**
1216  * @brief Change a password for a user
1217  *
1218  * @param username      Name of user to authenticate
1219  * @param old_password  Old clear text password of user
1220  * @param new_password  New clear text password of user
1221  *
1222  * @return #wbcErr
1223  **/
1224 wbcErr wbcChangeUserPassword(const char *username,
1225                              const char *old_password,
1226                              const char *new_password);
1227
1228 /**
1229  * @brief Change a password for a user with more detailed information upon
1230  *   failure
1231  *
1232  * @param params                Input parameters
1233  * @param error                 User output details on WBC_ERR_PWD_CHANGE_FAILED
1234  * @param reject_reason         New password reject reason on WBC_ERR_PWD_CHANGE_FAILED
1235  * @param policy                Password policy output details on WBC_ERR_PWD_CHANGE_FAILED
1236  *
1237  * @return #wbcErr
1238  **/
1239 wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
1240                                struct wbcAuthErrorInfo **error,
1241                                enum wbcPasswordChangeRejectReason *reject_reason,
1242                                struct wbcUserPasswordPolicyInfo **policy);
1243
1244 /**
1245  * @brief Authenticate a user with cached credentials
1246  *
1247  * @param *params    Pointer to a wbcCredentialCacheParams structure
1248  * @param **info     Pointer to a pointer to a wbcCredentialCacheInfo structure
1249  * @param **error    Pointer to a pointer to a wbcAuthErrorInfo structure
1250  *
1251  * @return #wbcErr
1252  **/
1253 wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
1254                           struct wbcCredentialCacheInfo **info,
1255                           struct wbcAuthErrorInfo **error);
1256
1257 /**
1258  * @brief Save a password with winbind for doing wbcCredentialCache() later
1259  *
1260  * @param *user      Username
1261  * @param *password  Password
1262  *
1263  * @return #wbcErr
1264  **/
1265 wbcErr wbcCredentialSave(const char *user, const char *password);
1266
1267 /**********************************************************
1268  * Resolve functions
1269  **********************************************************/
1270
1271 /**
1272  * @brief Resolve a NetbiosName via WINS
1273  *
1274  * @param name         Name to resolve
1275  * @param *ip          Pointer to the ip address string
1276  *
1277  * @return #wbcErr
1278  **/
1279 wbcErr wbcResolveWinsByName(const char *name, char **ip);
1280
1281 /**
1282  * @brief Resolve an IP address via WINS into a NetbiosName
1283  *
1284  * @param ip          The ip address string
1285  * @param *name       Pointer to the name
1286  *
1287  * @return #wbcErr
1288  *
1289  **/
1290 wbcErr wbcResolveWinsByIP(const char *ip, char **name);
1291
1292 /**********************************************************
1293  * Trusted domain functions
1294  **********************************************************/
1295
1296 /**
1297  * @brief Trigger a verification of the trust credentials of a specific domain
1298  *
1299  * @param *domain      The name of the domain.
1300  * @param error        Output details on WBC_ERR_AUTH_ERROR
1301  *
1302  * @return #wbcErr
1303  **/
1304 wbcErr wbcCheckTrustCredentials(const char *domain,
1305                                 struct wbcAuthErrorInfo **error);
1306
1307 /**
1308  * @brief Trigger a change of the trust credentials for a specific domain
1309  *
1310  * @param *domain      The name of the domain.
1311  * @param error        Output details on WBC_ERR_AUTH_ERROR
1312  *
1313  * @return #wbcErr
1314  **/
1315 wbcErr wbcChangeTrustCredentials(const char *domain,
1316                                  struct wbcAuthErrorInfo **error);
1317
1318 /**
1319  * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
1320  *        version of wbcCheckTrustCredentials
1321  *
1322  * @param *domain      The name of the domain, only NULL for the default domain is
1323  *                     supported yet. Other values than NULL will result in
1324  *                     WBC_ERR_NOT_IMPLEMENTED.
1325  * @param error        Output details on WBC_ERR_AUTH_ERROR
1326  *
1327  * @return #wbcErr
1328  **/
1329 wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error);
1330
1331 /**
1332  * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
1333  *        version of wbcCheckTrustCredentials
1334  *
1335  * @param *domain      The name of the domain, only NULL for the default domain is
1336  *                     supported yet. Other values than NULL will result in
1337  *                     WBC_ERR_NOT_IMPLEMENTED.
1338  * @param error        Output details on WBC_ERR_AUTH_ERROR
1339  * @param dcname       DC that was attempted to ping
1340  *
1341  * @return #wbcErr
1342  **/
1343 wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
1344                   char **dcname);
1345
1346 /**********************************************************
1347  * Helper functions
1348  **********************************************************/
1349
1350 /**
1351  * @brief Initialize a named blob and add to list of blobs
1352  *
1353  * @param[in,out] num_blobs     Pointer to the number of blobs
1354  * @param[in,out] blobs         Pointer to an array of blobs
1355  * @param[in]     name          Name of the new named blob
1356  * @param[in]     flags         Flags of the new named blob
1357  * @param[in]     data          Blob data of new blob
1358  * @param[in]     length        Blob data length of new blob
1359  *
1360  * @return #wbcErr
1361  **/
1362 wbcErr wbcAddNamedBlob(size_t *num_blobs,
1363                        struct wbcNamedBlob **blobs,
1364                        const char *name,
1365                        uint32_t flags,
1366                        uint8_t *data,
1367                        size_t length);
1368
1369 #endif      /* _WBCLIENT_H */