Merge branch 'v3-2-test' of git://git.samba.org/samba into v3-2-test
[ira/wip.git] / source3 / nsswitch / libwbclient / wbclient.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    Winbind client API
5
6    Copyright (C) Gerald (Jerry) Carter 2007
7
8    This library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public
10    License as published by the Free Software Foundation; either
11    version 3 of the License, or (at your option) any later version.
12
13    This library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _WBCLIENT_H
23 #define _WBCLIENT_H
24
25 #include <pwd.h>
26 #include <grp.h>
27
28 /* Define error types */
29
30 /**
31  *  @brief Status codes returned from wbc functions
32  **/
33
34 enum _wbcErrType {
35         WBC_ERR_SUCCESS = 0,    /**< Successful completion **/
36         WBC_ERR_NOT_IMPLEMENTED,/**< Function not implemented **/
37         WBC_ERR_UNKNOWN_FAILURE,/**< General failure **/
38         WBC_ERR_NO_MEMORY,      /**< Memory allocation error **/
39         WBC_ERR_INVALID_SID,    /**< Invalid SID format **/
40         WBC_ERR_INVALID_PARAM,  /**< An Invalid parameter was supplied **/
41         WBC_ERR_WINBIND_NOT_AVAILABLE,   /**< Winbind daemon is not available **/
42         WBC_ERR_DOMAIN_NOT_FOUND,        /**< Domain is not trusted or cannot be found **/
43         WBC_INVALID_RESPONSE,        /**< Winbind returned an invalid response **/
44         WBC_ERR_NSS_ERROR            /**< NSS_STATUS error **/
45 };
46
47 typedef enum _wbcErrType wbcErr;
48
49 #define WBC_ERROR_IS_OK(x) ((x) == WBC_ERR_SUCCESS)
50
51 char *wbcErrorString(wbcErr error);
52
53 /*
54  * Data types used by the Winbind Client API
55  */
56
57 #ifndef MAXSUBAUTHS
58 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
59 #endif
60
61 /**
62  *  @brief Windows Security Identifier
63  *
64  **/
65
66 struct wbcDomainSid {
67         uint8_t   sid_rev_num;
68         uint8_t   num_auths;
69         uint8_t   id_auth[6];
70         uint32_t  sub_auths[MAXSUBAUTHS];
71 };
72
73 /**
74  * @brief Security Identifier type
75  **/
76
77 enum wbcSidType {
78         WBC_SID_NAME_USE_NONE=0,
79         WBC_SID_NAME_USER=1,
80         WBC_SID_NAME_DOM_GRP=2,
81         WBC_SID_NAME_DOMAIN=3,
82         WBC_SID_NAME_ALIAS=4,
83         WBC_SID_NAME_WKN_GRP=5,
84         WBC_SID_NAME_DELETED=6,
85         WBC_SID_NAME_INVALID=7,
86         WBC_SID_NAME_UNKNOWN=8,
87         WBC_SID_NAME_COMPUTER=9
88 };
89
90 /**
91  * @brief Domain Information
92  **/
93
94 struct wbcDomainInfo {
95         char *short_name;
96         char *dns_name;
97         struct wbcDomainSid sid;
98         uint32_t flags;
99 };
100
101 /* wbcDomainInfo->flags */
102
103 #define WBC_DOMINFO_NATIVE            0x00000001
104 #define WBC_DOMINFO_AD                0x00000002
105 #define WBC_DOMINFO_PRIMARY           0x00000004
106
107 /*
108  * Memory Management
109  */
110
111 void wbcFreeMemory(void*);
112
113
114 /*
115  * Utility functions for dealing with SIDs
116  */
117
118 wbcErr wbcSidToString(const struct wbcDomainSid *sid,
119                       char **sid_string);
120
121 wbcErr wbcStringToSid(const char *sid_string,
122                       struct wbcDomainSid *sid);
123
124 wbcErr wbcPing(void);
125
126 /*
127  * Name/SID conversion
128  */
129
130 wbcErr wbcLookupName(const char *dom_name,
131                      const char *name,
132                      struct wbcDomainSid *sid,
133                      enum wbcSidType *name_type);
134
135 wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
136                     char **domain,
137                     char **name,
138                     enum wbcSidType *name_type);
139
140 wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
141                      int num_rids,
142                      uint32_t *rids,
143                      const char **domain_name,
144                      const char ***names,
145                      enum wbcSidType **types);
146
147 /*
148  * SID/uid/gid Mappings
149  */
150
151 wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
152                    uid_t *puid);
153
154 wbcErr wbcUidToSid(uid_t uid,
155                    struct wbcDomainSid *sid);
156
157 wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
158                    gid_t *pgid);
159
160 wbcErr wbcGidToSid(gid_t gid,
161                    struct wbcDomainSid *sid);
162
163 wbcErr wbcAllocateUid(uid_t *puid);
164
165 wbcErr wbcAllocateGid(uid_t *pgid);
166
167 /*
168  * NSS Lookup User/Group details
169  */
170
171 wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
172
173 wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
174
175 wbcErr wbcGetgrnam(const char *name, struct group **grp);
176
177 wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
178
179 wbcErr wbcSetpwent(void);
180
181 wbcErr wbcEndpwent(void);
182
183 wbcErr wbcGetpwent(struct passwd **pwd);
184
185 wbcErr wbcSetgrent(void);
186
187 wbcErr wbcEndgrent(void);
188
189 wbcErr wbcGetgrent(struct group **grp);
190
191
192 /*
193  * Lookup Domain information
194  */
195
196 wbcErr wbcDomainInfo(const char *domain,
197                      struct wbcDomainInfo **info);
198
199 wbcErr wbcDomainSequenceNumbers(void);
200
201 /*
202  * Athenticate functions
203  */
204
205 wbcErr wbcAuthenticateUser(const char *username,
206                            const char *password);
207
208
209 #endif      /* _WBCLIENT_H */