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