2 Unix SMB/CIFS implementation.
6 Copyright (C) Gerald (Jerry) Carter 2007
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.
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.
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/>.
23 /* Required Headers */
26 #include "libwbclient.h"
28 /* Convert a Windows SID to a Unix uid, allocating an uid if needed */
29 wbcErr
wbcSidToUid(const struct wbcDomainSid
*sid
, uid_t
*puid
)
31 struct winbindd_request request
;
32 struct winbindd_response response
;
33 char *sid_string
= NULL
;
34 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
37 wbc_status
= WBC_ERR_INVALID_PARAM
;
38 BAIL_ON_WBC_ERROR(wbc_status
);
41 /* Initialize request */
44 ZERO_STRUCT(response
);
46 wbc_status
= wbcSidToString(sid
, &sid_string
);
47 BAIL_ON_WBC_ERROR(wbc_status
);
49 strncpy(request
.data
.sid
, sid_string
, sizeof(request
.data
.sid
)-1);
50 wbcFreeMemory(sid_string
);
54 wbc_status
= wbcRequestResponse(WINBINDD_SID_TO_UID
,
57 BAIL_ON_WBC_ERROR(wbc_status
);
59 *puid
= response
.data
.uid
;
61 wbc_status
= WBC_ERR_SUCCESS
;
67 /* Convert a Windows SID to a Unix uid if there already is a mapping */
68 wbcErr
wbcQuerySidToUid(const struct wbcDomainSid
*sid
,
71 return WBC_ERR_NOT_IMPLEMENTED
;
74 /* Convert a Unix uid to a Windows SID, allocating a SID if needed */
75 wbcErr
wbcUidToSid(uid_t uid
, struct wbcDomainSid
*sid
)
77 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
78 struct winbindd_request request
;
79 struct winbindd_response response
;
82 wbc_status
= WBC_ERR_INVALID_PARAM
;
83 BAIL_ON_WBC_ERROR(wbc_status
);
86 /* Initialize request */
89 ZERO_STRUCT(response
);
91 request
.data
.uid
= uid
;
95 wbc_status
= wbcRequestResponse(WINBINDD_UID_TO_SID
,
98 BAIL_ON_WBC_ERROR(wbc_status
);
100 wbc_status
= wbcStringToSid(response
.data
.sid
.sid
, sid
);
101 BAIL_ON_WBC_ERROR(wbc_status
);
107 /* Convert a Unix uid to a Windows SID if there already is a mapping */
108 wbcErr
wbcQueryUidToSid(uid_t uid
,
109 struct wbcDomainSid
*sid
)
111 return WBC_ERR_NOT_IMPLEMENTED
;
114 /** @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
116 * @param *sid Pointer to the domain SID to be resolved
117 * @param *pgid Pointer to the resolved gid_t value
123 wbcErr
wbcSidToGid(const struct wbcDomainSid
*sid
, gid_t
*pgid
)
125 struct winbindd_request request
;
126 struct winbindd_response response
;
127 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
128 char *sid_string
= NULL
;
131 wbc_status
= WBC_ERR_INVALID_PARAM
;
132 BAIL_ON_WBC_ERROR(wbc_status
);
135 /* Initialize request */
137 ZERO_STRUCT(request
);
138 ZERO_STRUCT(response
);
140 wbc_status
= wbcSidToString(sid
, &sid_string
);
141 BAIL_ON_WBC_ERROR(wbc_status
);
143 strncpy(request
.data
.sid
, sid_string
, sizeof(request
.data
.sid
)-1);
144 wbcFreeMemory(sid_string
);
148 wbc_status
= wbcRequestResponse(WINBINDD_SID_TO_GID
,
151 BAIL_ON_WBC_ERROR(wbc_status
);
153 *pgid
= response
.data
.gid
;
155 wbc_status
= WBC_ERR_SUCCESS
;
161 /* Convert a Windows SID to a Unix gid if there already is a mapping */
163 wbcErr
wbcQuerySidToGid(const struct wbcDomainSid
*sid
,
166 return WBC_ERR_NOT_IMPLEMENTED
;
169 /* Convert a Unix gid to a Windows SID, allocating a SID if needed */
170 wbcErr
wbcGidToSid(gid_t gid
, struct wbcDomainSid
*sid
)
172 struct winbindd_request request
;
173 struct winbindd_response response
;
174 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
177 wbc_status
= WBC_ERR_INVALID_PARAM
;
178 BAIL_ON_WBC_ERROR(wbc_status
);
181 /* Initialize request */
183 ZERO_STRUCT(request
);
184 ZERO_STRUCT(response
);
186 request
.data
.gid
= gid
;
190 wbc_status
= wbcRequestResponse(WINBINDD_GID_TO_SID
,
193 BAIL_ON_WBC_ERROR(wbc_status
);
195 wbc_status
= wbcStringToSid(response
.data
.sid
.sid
, sid
);
196 BAIL_ON_WBC_ERROR(wbc_status
);
202 /* Convert a Unix gid to a Windows SID if there already is a mapping */
203 wbcErr
wbcQueryGidToSid(gid_t gid
,
204 struct wbcDomainSid
*sid
)
206 return WBC_ERR_NOT_IMPLEMENTED
;
209 /* Obtain a new uid from Winbind */
210 wbcErr
wbcAllocateUid(uid_t
*puid
)
212 struct winbindd_request request
;
213 struct winbindd_response response
;
214 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
217 return WBC_ERR_INVALID_PARAM
;
219 /* Initialise request */
221 ZERO_STRUCT(request
);
222 ZERO_STRUCT(response
);
226 wbc_status
= wbcRequestResponsePriv(WINBINDD_ALLOCATE_UID
,
227 &request
, &response
);
228 BAIL_ON_WBC_ERROR(wbc_status
);
230 /* Copy out result */
231 *puid
= response
.data
.uid
;
233 wbc_status
= WBC_ERR_SUCCESS
;
239 /* Obtain a new gid from Winbind */
240 wbcErr
wbcAllocateGid(gid_t
*pgid
)
242 struct winbindd_request request
;
243 struct winbindd_response response
;
244 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
247 return WBC_ERR_INVALID_PARAM
;
249 /* Initialise request */
251 ZERO_STRUCT(request
);
252 ZERO_STRUCT(response
);
256 wbc_status
= wbcRequestResponsePriv(WINBINDD_ALLOCATE_GID
,
257 &request
, &response
);
258 BAIL_ON_WBC_ERROR(wbc_status
);
260 /* Copy out result */
261 *pgid
= response
.data
.gid
;
263 wbc_status
= WBC_ERR_SUCCESS
;
269 /* we can't include smb.h here... */
270 #define _ID_TYPE_UID 1
271 #define _ID_TYPE_GID 2
273 /* Set an user id mapping */
274 wbcErr
wbcSetUidMapping(uid_t uid
, const struct wbcDomainSid
*sid
)
276 struct winbindd_request request
;
277 struct winbindd_response response
;
278 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
279 char *sid_string
= NULL
;
282 return WBC_ERR_INVALID_PARAM
;
285 /* Initialise request */
287 ZERO_STRUCT(request
);
288 ZERO_STRUCT(response
);
292 request
.data
.dual_idmapset
.id
= uid
;
293 request
.data
.dual_idmapset
.type
= _ID_TYPE_UID
;
295 wbc_status
= wbcSidToString(sid
, &sid_string
);
296 BAIL_ON_WBC_ERROR(wbc_status
);
298 strncpy(request
.data
.dual_idmapset
.sid
, sid_string
,
299 sizeof(request
.data
.dual_idmapset
.sid
)-1);
300 wbcFreeMemory(sid_string
);
302 wbc_status
= wbcRequestResponsePriv(WINBINDD_SET_MAPPING
,
303 &request
, &response
);
304 BAIL_ON_WBC_ERROR(wbc_status
);
310 /* Set a group id mapping */
311 wbcErr
wbcSetGidMapping(gid_t gid
, const struct wbcDomainSid
*sid
)
313 struct winbindd_request request
;
314 struct winbindd_response response
;
315 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
316 char *sid_string
= NULL
;
319 return WBC_ERR_INVALID_PARAM
;
322 /* Initialise request */
324 ZERO_STRUCT(request
);
325 ZERO_STRUCT(response
);
329 request
.data
.dual_idmapset
.id
= gid
;
330 request
.data
.dual_idmapset
.type
= _ID_TYPE_GID
;
332 wbc_status
= wbcSidToString(sid
, &sid_string
);
333 BAIL_ON_WBC_ERROR(wbc_status
);
335 strncpy(request
.data
.dual_idmapset
.sid
, sid_string
,
336 sizeof(request
.data
.dual_idmapset
.sid
)-1);
337 wbcFreeMemory(sid_string
);
339 wbc_status
= wbcRequestResponsePriv(WINBINDD_SET_MAPPING
,
340 &request
, &response
);
341 BAIL_ON_WBC_ERROR(wbc_status
);
347 /* Remove a user id mapping */
348 wbcErr
wbcRemoveUidMapping(uid_t uid
, const struct wbcDomainSid
*sid
)
350 struct winbindd_request request
;
351 struct winbindd_response response
;
352 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
353 char *sid_string
= NULL
;
356 return WBC_ERR_INVALID_PARAM
;
359 /* Initialise request */
361 ZERO_STRUCT(request
);
362 ZERO_STRUCT(response
);
366 request
.data
.dual_idmapset
.id
= uid
;
367 request
.data
.dual_idmapset
.type
= _ID_TYPE_UID
;
369 wbc_status
= wbcSidToString(sid
, &sid_string
);
370 BAIL_ON_WBC_ERROR(wbc_status
);
372 strncpy(request
.data
.dual_idmapset
.sid
, sid_string
,
373 sizeof(request
.data
.dual_idmapset
.sid
)-1);
374 wbcFreeMemory(sid_string
);
376 wbc_status
= wbcRequestResponsePriv(WINBINDD_REMOVE_MAPPING
,
377 &request
, &response
);
378 BAIL_ON_WBC_ERROR(wbc_status
);
384 /* Remove a group id mapping */
385 wbcErr
wbcRemoveGidMapping(gid_t gid
, const struct wbcDomainSid
*sid
)
387 struct winbindd_request request
;
388 struct winbindd_response response
;
389 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
390 char *sid_string
= NULL
;
393 return WBC_ERR_INVALID_PARAM
;
396 /* Initialise request */
398 ZERO_STRUCT(request
);
399 ZERO_STRUCT(response
);
403 request
.data
.dual_idmapset
.id
= gid
;
404 request
.data
.dual_idmapset
.type
= _ID_TYPE_GID
;
406 wbc_status
= wbcSidToString(sid
, &sid_string
);
407 BAIL_ON_WBC_ERROR(wbc_status
);
409 strncpy(request
.data
.dual_idmapset
.sid
, sid_string
,
410 sizeof(request
.data
.dual_idmapset
.sid
)-1);
411 wbcFreeMemory(sid_string
);
413 wbc_status
= wbcRequestResponsePriv(WINBINDD_REMOVE_MAPPING
,
414 &request
, &response
);
415 BAIL_ON_WBC_ERROR(wbc_status
);
421 /* Set the highwater mark for allocated uids. */
422 wbcErr
wbcSetUidHwm(uid_t uid_hwm
)
424 struct winbindd_request request
;
425 struct winbindd_response response
;
426 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
428 /* Initialise request */
430 ZERO_STRUCT(request
);
431 ZERO_STRUCT(response
);
435 request
.data
.dual_idmapset
.id
= uid_hwm
;
436 request
.data
.dual_idmapset
.type
= _ID_TYPE_UID
;
438 wbc_status
= wbcRequestResponsePriv(WINBINDD_SET_HWM
,
439 &request
, &response
);
440 BAIL_ON_WBC_ERROR(wbc_status
);
446 /* Set the highwater mark for allocated gids. */
447 wbcErr
wbcSetGidHwm(gid_t gid_hwm
)
449 struct winbindd_request request
;
450 struct winbindd_response response
;
451 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
453 /* Initialise request */
455 ZERO_STRUCT(request
);
456 ZERO_STRUCT(response
);
460 request
.data
.dual_idmapset
.id
= gid_hwm
;
461 request
.data
.dual_idmapset
.type
= _ID_TYPE_GID
;
463 wbc_status
= wbcRequestResponsePriv(WINBINDD_SET_HWM
,
464 &request
, &response
);
465 BAIL_ON_WBC_ERROR(wbc_status
);