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 */
25 #include "libwbclient.h"
27 /** @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
29 * @param *sid Pointer to the domain SID to be resolved
30 * @param *puid Pointer to the resolved uid_t value
36 wbcErr
wbcSidToUid(const struct wbcDomainSid
*sid
, uid_t
*puid
)
38 struct winbindd_request request
;
39 struct winbindd_response response
;
40 char *sid_string
= NULL
;
41 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
44 wbc_status
= WBC_ERR_INVALID_PARAM
;
45 BAIL_ON_WBC_ERROR(wbc_status
);
48 /* Initialize request */
51 ZERO_STRUCT(response
);
53 wbc_status
= wbcSidToString(sid
, &sid_string
);
54 BAIL_ON_WBC_ERROR(wbc_status
);
56 strncpy(request
.data
.sid
, sid_string
, sizeof(request
.data
.sid
)-1);
57 wbcFreeMemory(sid_string
);
61 wbc_status
= wbcRequestResponse(WINBINDD_SID_TO_UID
,
64 BAIL_ON_WBC_ERROR(wbc_status
);
66 *puid
= response
.data
.uid
;
68 wbc_status
= WBC_ERR_SUCCESS
;
74 /** @brief Convert a Windows SID to a Unix uid if there already is a mapping
76 * @param *sid Pointer to the domain SID to be resolved
77 * @param *puid Pointer to the resolved uid_t value
83 wbcErr
wbcQuerySidToUid(const struct wbcDomainSid
*sid
,
86 return WBC_ERR_NOT_IMPLEMENTED
;
89 /** @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
91 * @param uid Unix uid to be resolved
92 * @param *sid Pointer to the resolved domain SID
98 wbcErr
wbcUidToSid(uid_t uid
, struct wbcDomainSid
*sid
)
100 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
101 struct winbindd_request request
;
102 struct winbindd_response response
;
105 wbc_status
= WBC_ERR_INVALID_PARAM
;
106 BAIL_ON_WBC_ERROR(wbc_status
);
109 /* Initialize request */
111 ZERO_STRUCT(request
);
112 ZERO_STRUCT(response
);
114 request
.data
.uid
= uid
;
118 wbc_status
= wbcRequestResponse(WINBINDD_UID_TO_SID
,
121 BAIL_ON_WBC_ERROR(wbc_status
);
123 wbc_status
= wbcStringToSid(response
.data
.sid
.sid
, sid
);
124 BAIL_ON_WBC_ERROR(wbc_status
);
130 /** @brief Convert a Unix uid to a Windows SID if there already is a mapping
132 * @param uid Unix uid to be resolved
133 * @param *sid Pointer to the resolved domain SID
139 wbcErr
wbcQueryUidToSid(uid_t uid
,
140 struct wbcDomainSid
*sid
)
142 return WBC_ERR_NOT_IMPLEMENTED
;
145 /** @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
147 * @param *sid Pointer to the domain SID to be resolved
148 * @param *pgid Pointer to the resolved gid_t value
154 wbcErr
wbcSidToGid(const struct wbcDomainSid
*sid
, gid_t
*pgid
)
156 struct winbindd_request request
;
157 struct winbindd_response response
;
158 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
159 char *sid_string
= NULL
;
162 wbc_status
= WBC_ERR_INVALID_PARAM
;
163 BAIL_ON_WBC_ERROR(wbc_status
);
166 /* Initialize request */
168 ZERO_STRUCT(request
);
169 ZERO_STRUCT(response
);
171 wbc_status
= wbcSidToString(sid
, &sid_string
);
172 BAIL_ON_WBC_ERROR(wbc_status
);
174 strncpy(request
.data
.sid
, sid_string
, sizeof(request
.data
.sid
)-1);
175 wbcFreeMemory(sid_string
);
179 wbc_status
= wbcRequestResponse(WINBINDD_SID_TO_GID
,
182 BAIL_ON_WBC_ERROR(wbc_status
);
184 *pgid
= response
.data
.gid
;
186 wbc_status
= WBC_ERR_SUCCESS
;
192 /** @brief Convert a Windows SID to a Unix gid if there already is a mapping
194 * @param *sid Pointer to the domain SID to be resolved
195 * @param *pgid Pointer to the resolved gid_t value
201 wbcErr
wbcQuerySidToGid(const struct wbcDomainSid
*sid
,
204 return WBC_ERR_NOT_IMPLEMENTED
;
207 /** @brief Convert a Unix gid to a Windows SID, allocating a SID if needed
209 * @param gid Unix gid to be resolved
210 * @param *sid Pointer to the resolved domain SID
216 wbcErr
wbcGidToSid(gid_t gid
, struct wbcDomainSid
*sid
)
218 struct winbindd_request request
;
219 struct winbindd_response response
;
220 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
223 wbc_status
= WBC_ERR_INVALID_PARAM
;
224 BAIL_ON_WBC_ERROR(wbc_status
);
227 /* Initialize request */
229 ZERO_STRUCT(request
);
230 ZERO_STRUCT(response
);
232 request
.data
.gid
= gid
;
236 wbc_status
= wbcRequestResponse(WINBINDD_GID_TO_SID
,
239 BAIL_ON_WBC_ERROR(wbc_status
);
241 wbc_status
= wbcStringToSid(response
.data
.sid
.sid
, sid
);
242 BAIL_ON_WBC_ERROR(wbc_status
);
248 /** @brief Convert a Unix gid to a Windows SID if there already is a mapping
250 * @param gid Unix gid to be resolved
251 * @param *sid Pointer to the resolved domain SID
257 wbcErr
wbcQueryGidToSid(gid_t gid
,
258 struct wbcDomainSid
*sid
)
260 return WBC_ERR_NOT_IMPLEMENTED
;
263 /** @brief Obtain a new uid from Winbind
265 * @param *puid *pointer to the allocated uid
270 wbcErr
wbcAllocateUid(uid_t
*puid
)
272 struct winbindd_request request
;
273 struct winbindd_response response
;
274 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
277 return WBC_ERR_INVALID_PARAM
;
279 /* Initialise request */
281 ZERO_STRUCT(request
);
282 ZERO_STRUCT(response
);
286 wbc_status
= wbcRequestResponse(WINBINDD_ALLOCATE_UID
,
287 &request
, &response
);
288 BAIL_ON_WBC_ERROR(wbc_status
);
290 /* Copy out result */
291 *puid
= response
.data
.uid
;
293 wbc_status
= WBC_ERR_SUCCESS
;
299 /** @brief Obtain a new gid from Winbind
301 * @param *pgid Pointer to the allocated gid
306 wbcErr
wbcAllocateGid(gid_t
*pgid
)
308 struct winbindd_request request
;
309 struct winbindd_response response
;
310 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
313 return WBC_ERR_INVALID_PARAM
;
315 /* Initialise request */
317 ZERO_STRUCT(request
);
318 ZERO_STRUCT(response
);
322 wbc_status
= wbcRequestResponse(WINBINDD_ALLOCATE_GID
,
323 &request
, &response
);
324 BAIL_ON_WBC_ERROR(wbc_status
);
326 /* Copy out result */
327 *pgid
= response
.data
.gid
;
329 wbc_status
= WBC_ERR_SUCCESS
;
335 /* we can't include smb.h here... */
336 #define _ID_TYPE_UID 1
337 #define _ID_TYPE_GID 2
339 /** @brief Set an user id mapping
341 * @param uid Uid of the desired mapping.
342 * @param *sid Pointer to the sid of the diresired mapping.
346 wbcErr
wbcSetUidMapping(uid_t uid
, const struct wbcDomainSid
*sid
)
348 struct winbindd_request request
;
349 struct winbindd_response response
;
350 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
351 char *sid_string
= NULL
;
354 return WBC_ERR_INVALID_PARAM
;
357 /* Initialise request */
359 ZERO_STRUCT(request
);
360 ZERO_STRUCT(response
);
364 request
.data
.dual_idmapset
.id
= uid
;
365 request
.data
.dual_idmapset
.type
= _ID_TYPE_UID
;
367 wbc_status
= wbcSidToString(sid
, &sid_string
);
368 BAIL_ON_WBC_ERROR(wbc_status
);
370 strncpy(request
.data
.dual_idmapset
.sid
, sid_string
,
371 sizeof(request
.data
.dual_idmapset
.sid
)-1);
372 wbcFreeMemory(sid_string
);
374 wbc_status
= wbcRequestResponse(WINBINDD_SET_MAPPING
,
375 &request
, &response
);
376 BAIL_ON_WBC_ERROR(wbc_status
);
382 /** @brief Set a group id mapping
384 * @param gid Gid of the desired mapping.
385 * @param *sid Pointer to the sid of the diresired mapping.
389 wbcErr
wbcSetGidMapping(gid_t gid
, const struct wbcDomainSid
*sid
)
391 struct winbindd_request request
;
392 struct winbindd_response response
;
393 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
394 char *sid_string
= NULL
;
397 return WBC_ERR_INVALID_PARAM
;
400 /* Initialise request */
402 ZERO_STRUCT(request
);
403 ZERO_STRUCT(response
);
407 request
.data
.dual_idmapset
.id
= gid
;
408 request
.data
.dual_idmapset
.type
= _ID_TYPE_GID
;
410 wbc_status
= wbcSidToString(sid
, &sid_string
);
411 BAIL_ON_WBC_ERROR(wbc_status
);
413 strncpy(request
.data
.dual_idmapset
.sid
, sid_string
,
414 sizeof(request
.data
.dual_idmapset
.sid
)-1);
415 wbcFreeMemory(sid_string
);
417 wbc_status
= wbcRequestResponse(WINBINDD_SET_MAPPING
,
418 &request
, &response
);
419 BAIL_ON_WBC_ERROR(wbc_status
);
425 /** @brief Remove a user id mapping
427 * @param uid Uid of the mapping to remove.
428 * @param *sid Pointer to the sid of the mapping to remove.
432 wbcErr
wbcRemoveUidMapping(uid_t uid
, const struct wbcDomainSid
*sid
)
434 struct winbindd_request request
;
435 struct winbindd_response response
;
436 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
437 char *sid_string
= NULL
;
440 return WBC_ERR_INVALID_PARAM
;
443 /* Initialise request */
445 ZERO_STRUCT(request
);
446 ZERO_STRUCT(response
);
450 request
.data
.dual_idmapset
.id
= uid
;
451 request
.data
.dual_idmapset
.type
= _ID_TYPE_UID
;
453 wbc_status
= wbcSidToString(sid
, &sid_string
);
454 BAIL_ON_WBC_ERROR(wbc_status
);
456 strncpy(request
.data
.dual_idmapset
.sid
, sid_string
,
457 sizeof(request
.data
.dual_idmapset
.sid
)-1);
458 wbcFreeMemory(sid_string
);
460 wbc_status
= wbcRequestResponse(WINBINDD_REMOVE_MAPPING
,
461 &request
, &response
);
462 BAIL_ON_WBC_ERROR(wbc_status
);
468 /** @brief Remove a group id mapping
470 * @param gid Gid of the mapping to remove.
471 * @param *sid Pointer to the sid of the mapping to remove.
475 wbcErr
wbcRemoveGidMapping(gid_t gid
, const struct wbcDomainSid
*sid
)
477 struct winbindd_request request
;
478 struct winbindd_response response
;
479 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
480 char *sid_string
= NULL
;
483 return WBC_ERR_INVALID_PARAM
;
486 /* Initialise request */
488 ZERO_STRUCT(request
);
489 ZERO_STRUCT(response
);
493 request
.data
.dual_idmapset
.id
= gid
;
494 request
.data
.dual_idmapset
.type
= _ID_TYPE_GID
;
496 wbc_status
= wbcSidToString(sid
, &sid_string
);
497 BAIL_ON_WBC_ERROR(wbc_status
);
499 strncpy(request
.data
.dual_idmapset
.sid
, sid_string
,
500 sizeof(request
.data
.dual_idmapset
.sid
)-1);
501 wbcFreeMemory(sid_string
);
503 wbc_status
= wbcRequestResponse(WINBINDD_REMOVE_MAPPING
,
504 &request
, &response
);
505 BAIL_ON_WBC_ERROR(wbc_status
);
511 /** @brief Set the highwater mark for allocated uids.
513 * @param uid_hwm The new uid highwater mark value
517 wbcErr
wbcSetUidHwm(uid_t uid_hwm
)
519 struct winbindd_request request
;
520 struct winbindd_response response
;
521 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
523 /* Initialise request */
525 ZERO_STRUCT(request
);
526 ZERO_STRUCT(response
);
530 request
.data
.dual_idmapset
.id
= uid_hwm
;
531 request
.data
.dual_idmapset
.type
= _ID_TYPE_UID
;
533 wbc_status
= wbcRequestResponse(WINBINDD_SET_HWM
,
534 &request
, &response
);
535 BAIL_ON_WBC_ERROR(wbc_status
);
541 /** @brief Set the highwater mark for allocated gids.
543 * @param gid_hwm The new gid highwater mark value
547 wbcErr
wbcSetGidHwm(gid_t gid_hwm
)
549 struct winbindd_request request
;
550 struct winbindd_response response
;
551 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
553 /* Initialise request */
555 ZERO_STRUCT(request
);
556 ZERO_STRUCT(response
);
560 request
.data
.dual_idmapset
.id
= gid_hwm
;
561 request
.data
.dual_idmapset
.type
= _ID_TYPE_GID
;
563 wbc_status
= wbcRequestResponse(WINBINDD_SET_HWM
,
564 &request
, &response
);
565 BAIL_ON_WBC_ERROR(wbc_status
);