s3: Remove unused comparison fn from "struct sorted_tree"
[Samba/kamenim.git] / nsswitch / libwbclient / wbc_idmap.c
blobe1bb6f2d594aa45f44eb7fd2291ebce5dd68f7a3
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind client API
6 Copyright (C) Gerald (Jerry) Carter 2007
7 Copyright (C) Kai Blin 2009
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 3 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /* Required Headers */
26 #include "replace.h"
27 #include "libwbclient.h"
29 struct wbc_sid_to_uid_state {
30 struct winbindd_request req;
31 uid_t uid;
34 static void wbcSidToUid_done(struct tevent_req *subreq);
36 /**
37 * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
39 * @param mem_ctx talloc context to allocate the request from
40 * @param ev tevent context to use for async operation
41 * @param wb_ctx winbind context to use
42 * @param *sid pointer to the domain SID to be resolved
44 * @return tevent_req on success, NULL on error
47 struct tevent_req *wbcSidToUid_send(TALLOC_CTX *mem_ctx,
48 struct tevent_context *ev,
49 struct wb_context *wb_ctx,
50 const struct wbcDomainSid *sid)
52 struct tevent_req *req, *subreq;
53 struct wbc_sid_to_uid_state *state;
54 char *sid_string;
55 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
57 req = tevent_req_create(mem_ctx, &state, struct wbc_sid_to_uid_state);
58 if (req == NULL) {
59 return NULL;
62 ZERO_STRUCT(state->req);
64 state->req.cmd = WINBINDD_SID_TO_UID;
65 wbc_status = wbcSidToString(sid, &sid_string);
66 if (!WBC_ERROR_IS_OK(wbc_status)) {
67 return tevent_req_post(req, ev);
69 strncpy(state->req.data.sid, sid_string, sizeof(state->req.data.sid)-1);
70 wbcFreeMemory(sid_string);
72 subreq = wb_trans_send(state, ev, wb_ctx, false, &state->req);
73 if (tevent_req_nomem(subreq, req)) {
74 return tevent_req_post(req, ev);
77 tevent_req_set_callback(subreq, wbcSidToUid_done, req);
78 return req;
81 static void wbcSidToUid_done(struct tevent_req *subreq)
83 struct tevent_req *req = tevent_req_callback_data(
84 subreq, struct tevent_req);
85 struct wbc_sid_to_uid_state *state = tevent_req_data(
86 req, struct wbc_sid_to_uid_state);
87 struct winbindd_response *resp;
88 wbcErr wbc_status;
90 wbc_status = wb_trans_recv(subreq, state, &resp);
91 TALLOC_FREE(subreq);
92 if (!WBC_ERROR_IS_OK(wbc_status)) {
93 tevent_req_error(req, wbc_status);
94 return;
96 state->uid = resp->data.uid;
97 TALLOC_FREE(resp);
99 tevent_req_done(req);
103 * @brief Receive a Unix uid mapped to a Windows SID
105 * @param req tevent_req containing the request
106 * @param *puid pointer to hold the resolved uid_t value
108 * @return #wbcErr
111 wbcErr wbcSidToUid_recv(struct tevent_req *req, uid_t *puid)
113 struct wbc_sid_to_uid_state *state = tevent_req_data(
114 req, struct wbc_sid_to_uid_state);
115 wbcErr wbc_status;
117 if (tevent_req_is_wbcerr(req, &wbc_status)) {
118 tevent_req_received(req);
119 return wbc_status;
122 *puid = state->uid;
124 tevent_req_received(req);
125 return WBC_ERR_SUCCESS;
128 /* Convert a Windows SID to a Unix uid, allocating an uid if needed */
129 wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t *puid)
131 struct winbindd_request request;
132 struct winbindd_response response;
133 char *sid_string = NULL;
134 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
136 if (!sid || !puid) {
137 wbc_status = WBC_ERR_INVALID_PARAM;
138 BAIL_ON_WBC_ERROR(wbc_status);
141 /* Initialize request */
143 ZERO_STRUCT(request);
144 ZERO_STRUCT(response);
146 wbc_status = wbcSidToString(sid, &sid_string);
147 BAIL_ON_WBC_ERROR(wbc_status);
149 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
150 wbcFreeMemory(sid_string);
152 /* Make request */
154 wbc_status = wbcRequestResponse(WINBINDD_SID_TO_UID,
155 &request,
156 &response);
157 BAIL_ON_WBC_ERROR(wbc_status);
159 *puid = response.data.uid;
161 wbc_status = WBC_ERR_SUCCESS;
163 done:
164 return wbc_status;
167 /* Convert a Windows SID to a Unix uid if there already is a mapping */
168 wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
169 uid_t *puid)
171 return WBC_ERR_NOT_IMPLEMENTED;
174 struct wbc_uid_to_sid_state {
175 struct winbindd_request req;
176 struct wbcDomainSid *sid;
179 static void wbcUidToSid_done(struct tevent_req *subreq);
182 * @brief Request a Windows SID for an Unix uid, allocating an SID if needed
184 * @param mem_ctx talloc context to allocate the request from
185 * @param ev tevent context to use for async operation
186 * @param wb_ctx winbind context to use
187 * @param uid uid to be resolved to a SID
189 * @return tevent_req on success, NULL on error
192 struct tevent_req *wbcUidToSid_send(TALLOC_CTX *mem_ctx,
193 struct tevent_context *ev,
194 struct wb_context *wb_ctx,
195 uid_t uid)
197 struct tevent_req *req, *subreq;
198 struct wbc_uid_to_sid_state *state;
200 req = tevent_req_create(mem_ctx, &state, struct wbc_uid_to_sid_state);
201 if (req == NULL) {
202 return NULL;
205 ZERO_STRUCT(state->req);
207 state->req.cmd = WINBINDD_UID_TO_SID;
208 state->req.data.uid = uid;
210 subreq = wb_trans_send(state, ev, wb_ctx, false, &state->req);
211 if (tevent_req_nomem(subreq, req)) {
212 return tevent_req_post(req, ev);
215 tevent_req_set_callback(subreq, wbcUidToSid_done, req);
216 return req;
219 static void wbcUidToSid_done(struct tevent_req *subreq)
221 struct tevent_req *req = tevent_req_callback_data(
222 subreq, struct tevent_req);
223 struct wbc_uid_to_sid_state *state = tevent_req_data(
224 req, struct wbc_uid_to_sid_state);
225 struct winbindd_response *resp;
226 wbcErr wbc_status;
228 wbc_status = wb_trans_recv(subreq, state, &resp);
229 TALLOC_FREE(subreq);
230 if (!WBC_ERROR_IS_OK(wbc_status)) {
231 tevent_req_error(req, wbc_status);
232 return;
235 state->sid = talloc(state, struct wbcDomainSid);
236 if (state->sid == NULL) {
237 TALLOC_FREE(resp);
238 tevent_req_error(req, WBC_ERR_NO_MEMORY);
239 return;
242 wbc_status = wbcStringToSid(resp->data.sid.sid, state->sid);
243 TALLOC_FREE(resp);
245 if (!WBC_ERROR_IS_OK(wbc_status)) {
246 tevent_req_error(req, wbc_status);
247 return;
250 tevent_req_done(req);
254 * @brief Receive a Unix uid mapped to a Windows SID
256 * @param req tevent_req containing the request
257 * @param *psid pointer to hold the resolved SID
259 * @return #wbcErr
262 wbcErr wbcUidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid)
264 struct wbc_uid_to_sid_state *state = tevent_req_data(
265 req, struct wbc_uid_to_sid_state);
266 wbcErr wbc_status;
268 if (psid == NULL) {
269 tevent_req_received(req);
270 return WBC_ERR_INVALID_PARAM;
273 if (tevent_req_is_wbcerr(req, &wbc_status)) {
274 tevent_req_received(req);
275 return wbc_status;
278 memcpy(psid, state->sid, sizeof(struct wbcDomainSid));
280 tevent_req_received(req);
281 return WBC_ERR_SUCCESS;
284 /* Convert a Unix uid to a Windows SID, allocating a SID if needed */
285 wbcErr wbcUidToSid(uid_t uid, struct wbcDomainSid *sid)
287 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
288 struct winbindd_request request;
289 struct winbindd_response response;
291 if (!sid) {
292 wbc_status = WBC_ERR_INVALID_PARAM;
293 BAIL_ON_WBC_ERROR(wbc_status);
296 /* Initialize request */
298 ZERO_STRUCT(request);
299 ZERO_STRUCT(response);
301 request.data.uid = uid;
303 /* Make request */
305 wbc_status = wbcRequestResponse(WINBINDD_UID_TO_SID,
306 &request,
307 &response);
308 BAIL_ON_WBC_ERROR(wbc_status);
310 wbc_status = wbcStringToSid(response.data.sid.sid, sid);
311 BAIL_ON_WBC_ERROR(wbc_status);
313 done:
314 return wbc_status;
317 /* Convert a Unix uid to a Windows SID if there already is a mapping */
318 wbcErr wbcQueryUidToSid(uid_t uid,
319 struct wbcDomainSid *sid)
321 return WBC_ERR_NOT_IMPLEMENTED;
324 struct wbc_sid_to_gid_state {
325 struct winbindd_request req;
326 gid_t gid;
329 static void wbcSidToGid_done(struct tevent_req *subreq);
332 * @brief Request to convert a Windows SID to a Unix gid,
333 * allocating a gid if needed
335 * @param mem_ctx talloc context to allocate the request from
336 * @param ev tevent context to use for async operation
337 * @param wb_ctx winbind context to use
338 * @param *sid pointer to the domain SID to be resolved
340 * @return tevent_req on success, NULL on error
343 struct tevent_req *wbcSidToGid_send(TALLOC_CTX *mem_ctx,
344 struct tevent_context *ev,
345 struct wb_context *wb_ctx,
346 const struct wbcDomainSid *sid)
348 struct tevent_req *req, *subreq;
349 struct wbc_sid_to_gid_state *state;
350 char *sid_string;
351 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
353 req = tevent_req_create(mem_ctx, &state, struct wbc_sid_to_gid_state);
354 if (req == NULL) {
355 return NULL;
358 ZERO_STRUCT(state->req);
360 state->req.cmd = WINBINDD_SID_TO_GID;
361 wbc_status = wbcSidToString(sid, &sid_string);
362 if (!WBC_ERROR_IS_OK(wbc_status)) {
363 return tevent_req_post(req, ev);
365 strncpy(state->req.data.sid, sid_string, sizeof(state->req.data.sid)-1);
366 wbcFreeMemory(sid_string);
368 subreq = wb_trans_send(state, ev, wb_ctx, false, &state->req);
369 if (tevent_req_nomem(subreq, req)) {
370 return tevent_req_post(req, ev);
373 tevent_req_set_callback(subreq, wbcSidToGid_done, req);
374 return req;
377 static void wbcSidToGid_done(struct tevent_req *subreq)
379 struct tevent_req *req = tevent_req_callback_data(
380 subreq, struct tevent_req);
381 struct wbc_sid_to_gid_state *state = tevent_req_data(
382 req, struct wbc_sid_to_gid_state);
383 struct winbindd_response *resp;
384 wbcErr wbc_status;
386 wbc_status = wb_trans_recv(subreq, state, &resp);
387 TALLOC_FREE(subreq);
388 if (!WBC_ERROR_IS_OK(wbc_status)) {
389 tevent_req_error(req, wbc_status);
390 return;
392 state->gid = resp->data.gid;
393 TALLOC_FREE(resp);
395 tevent_req_done(req);
399 * @brief Receive a Unix gid mapped to a Windows SID
401 * @param req tevent_req containing the request
402 * @param *pgid pointer to hold the resolved gid_t value
404 * @return #wbcErr
407 wbcErr wbcSidToGid_recv(struct tevent_req *req, gid_t *pgid)
409 struct wbc_sid_to_gid_state *state = tevent_req_data(
410 req, struct wbc_sid_to_gid_state);
411 wbcErr wbc_status;
413 if (tevent_req_is_wbcerr(req, &wbc_status)) {
414 tevent_req_received(req);
415 return wbc_status;
418 *pgid = state->gid;
420 tevent_req_received(req);
421 return WBC_ERR_SUCCESS;
424 /** @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
426 * @param *sid Pointer to the domain SID to be resolved
427 * @param *pgid Pointer to the resolved gid_t value
429 * @return #wbcErr
433 wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t *pgid)
435 struct winbindd_request request;
436 struct winbindd_response response;
437 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
438 char *sid_string = NULL;
440 if (!sid || !pgid) {
441 wbc_status = WBC_ERR_INVALID_PARAM;
442 BAIL_ON_WBC_ERROR(wbc_status);
445 /* Initialize request */
447 ZERO_STRUCT(request);
448 ZERO_STRUCT(response);
450 wbc_status = wbcSidToString(sid, &sid_string);
451 BAIL_ON_WBC_ERROR(wbc_status);
453 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
454 wbcFreeMemory(sid_string);
456 /* Make request */
458 wbc_status = wbcRequestResponse(WINBINDD_SID_TO_GID,
459 &request,
460 &response);
461 BAIL_ON_WBC_ERROR(wbc_status);
463 *pgid = response.data.gid;
465 wbc_status = WBC_ERR_SUCCESS;
467 done:
468 return wbc_status;
472 /* Convert a Windows SID to a Unix gid if there already is a mapping */
474 wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
475 gid_t *pgid)
477 return WBC_ERR_NOT_IMPLEMENTED;
480 struct wbc_gid_to_sid_state {
481 struct winbindd_request req;
482 struct wbcDomainSid *sid;
485 static void wbcGidToSid_done(struct tevent_req *subreq);
488 * @brief Request a Windows SID for an Unix Gid, allocating an SID if needed
490 * @param mem_ctx talloc context to allocate the request from
491 * @param ev tevent context to use for async operation
492 * @param wb_ctx winbind context to use
493 * @param gid gid to be resolved to a SID
495 * @return tevent_req on success, NULL on error
498 struct tevent_req *wbcGidToSid_send(TALLOC_CTX *mem_ctx,
499 struct tevent_context *ev,
500 struct wb_context *wb_ctx,
501 gid_t gid)
503 struct tevent_req *req, *subreq;
504 struct wbc_gid_to_sid_state *state;
506 req = tevent_req_create(mem_ctx, &state, struct wbc_gid_to_sid_state);
507 if (req == NULL) {
508 return NULL;
511 ZERO_STRUCT(state->req);
513 state->req.cmd = WINBINDD_GID_TO_SID;
514 state->req.data.gid = gid;
516 subreq = wb_trans_send(state, ev, wb_ctx, false, &state->req);
517 if (tevent_req_nomem(subreq, req)) {
518 return tevent_req_post(req, ev);
521 tevent_req_set_callback(subreq, wbcGidToSid_done, req);
522 return req;
525 static void wbcGidToSid_done(struct tevent_req *subreq)
527 struct tevent_req *req = tevent_req_callback_data(
528 subreq, struct tevent_req);
529 struct wbc_gid_to_sid_state *state = tevent_req_data(
530 req, struct wbc_gid_to_sid_state);
531 struct winbindd_response *resp;
532 wbcErr wbc_status;
534 wbc_status = wb_trans_recv(subreq, state, &resp);
535 TALLOC_FREE(subreq);
536 if (!WBC_ERROR_IS_OK(wbc_status)) {
537 tevent_req_error(req, wbc_status);
538 return;
541 state->sid = talloc(state, struct wbcDomainSid);
542 if (state->sid == NULL) {
543 TALLOC_FREE(resp);
544 tevent_req_error(req, WBC_ERR_NO_MEMORY);
545 return;
548 wbc_status = wbcStringToSid(resp->data.sid.sid, state->sid);
549 TALLOC_FREE(resp);
551 if (!WBC_ERROR_IS_OK(wbc_status)) {
552 tevent_req_error(req, wbc_status);
553 return;
556 tevent_req_done(req);
560 * @brief Receive a Unix gid mapped to a Windows SID
562 * @param req tevent_req containing the request
563 * @param *psid pointer to hold the resolved SID
565 * @return #wbcErr
568 wbcErr wbcGidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid)
570 struct wbc_gid_to_sid_state *state = tevent_req_data(
571 req, struct wbc_gid_to_sid_state);
572 wbcErr wbc_status;
574 if (psid == NULL) {
575 tevent_req_received(req);
576 return WBC_ERR_INVALID_PARAM;
579 if (tevent_req_is_wbcerr(req, &wbc_status)) {
580 tevent_req_received(req);
581 return wbc_status;
584 memcpy(psid, state->sid, sizeof(struct wbcDomainSid));
586 tevent_req_received(req);
587 return WBC_ERR_SUCCESS;
591 /* Convert a Unix gid to a Windows SID, allocating a SID if needed */
592 wbcErr wbcGidToSid(gid_t gid, struct wbcDomainSid *sid)
594 struct winbindd_request request;
595 struct winbindd_response response;
596 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
598 if (!sid) {
599 wbc_status = WBC_ERR_INVALID_PARAM;
600 BAIL_ON_WBC_ERROR(wbc_status);
603 /* Initialize request */
605 ZERO_STRUCT(request);
606 ZERO_STRUCT(response);
608 request.data.gid = gid;
610 /* Make request */
612 wbc_status = wbcRequestResponse(WINBINDD_GID_TO_SID,
613 &request,
614 &response);
615 BAIL_ON_WBC_ERROR(wbc_status);
617 wbc_status = wbcStringToSid(response.data.sid.sid, sid);
618 BAIL_ON_WBC_ERROR(wbc_status);
620 done:
621 return wbc_status;
624 /* Convert a Unix gid to a Windows SID if there already is a mapping */
625 wbcErr wbcQueryGidToSid(gid_t gid,
626 struct wbcDomainSid *sid)
628 return WBC_ERR_NOT_IMPLEMENTED;
631 /* Obtain a new uid from Winbind */
632 wbcErr wbcAllocateUid(uid_t *puid)
634 struct winbindd_request request;
635 struct winbindd_response response;
636 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
638 if (!puid)
639 return WBC_ERR_INVALID_PARAM;
641 /* Initialise request */
643 ZERO_STRUCT(request);
644 ZERO_STRUCT(response);
646 /* Make request */
648 wbc_status = wbcRequestResponse(WINBINDD_ALLOCATE_UID,
649 &request, &response);
650 BAIL_ON_WBC_ERROR(wbc_status);
652 /* Copy out result */
653 *puid = response.data.uid;
655 wbc_status = WBC_ERR_SUCCESS;
657 done:
658 return wbc_status;
661 /* Obtain a new gid from Winbind */
662 wbcErr wbcAllocateGid(gid_t *pgid)
664 struct winbindd_request request;
665 struct winbindd_response response;
666 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
668 if (!pgid)
669 return WBC_ERR_INVALID_PARAM;
671 /* Initialise request */
673 ZERO_STRUCT(request);
674 ZERO_STRUCT(response);
676 /* Make request */
678 wbc_status = wbcRequestResponse(WINBINDD_ALLOCATE_GID,
679 &request, &response);
680 BAIL_ON_WBC_ERROR(wbc_status);
682 /* Copy out result */
683 *pgid = response.data.gid;
685 wbc_status = WBC_ERR_SUCCESS;
687 done:
688 return wbc_status;
691 /* we can't include smb.h here... */
692 #define _ID_TYPE_UID 1
693 #define _ID_TYPE_GID 2
695 /* Set an user id mapping */
696 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid)
698 struct winbindd_request request;
699 struct winbindd_response response;
700 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
701 char *sid_string = NULL;
703 if (!sid) {
704 return WBC_ERR_INVALID_PARAM;
707 /* Initialise request */
709 ZERO_STRUCT(request);
710 ZERO_STRUCT(response);
712 /* Make request */
714 request.data.dual_idmapset.id = uid;
715 request.data.dual_idmapset.type = _ID_TYPE_UID;
717 wbc_status = wbcSidToString(sid, &sid_string);
718 BAIL_ON_WBC_ERROR(wbc_status);
720 strncpy(request.data.dual_idmapset.sid, sid_string,
721 sizeof(request.data.dual_idmapset.sid)-1);
722 wbcFreeMemory(sid_string);
724 wbc_status = wbcRequestResponse(WINBINDD_SET_MAPPING,
725 &request, &response);
726 BAIL_ON_WBC_ERROR(wbc_status);
728 done:
729 return wbc_status;
732 /* Set a group id mapping */
733 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid)
735 struct winbindd_request request;
736 struct winbindd_response response;
737 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
738 char *sid_string = NULL;
740 if (!sid) {
741 return WBC_ERR_INVALID_PARAM;
744 /* Initialise request */
746 ZERO_STRUCT(request);
747 ZERO_STRUCT(response);
749 /* Make request */
751 request.data.dual_idmapset.id = gid;
752 request.data.dual_idmapset.type = _ID_TYPE_GID;
754 wbc_status = wbcSidToString(sid, &sid_string);
755 BAIL_ON_WBC_ERROR(wbc_status);
757 strncpy(request.data.dual_idmapset.sid, sid_string,
758 sizeof(request.data.dual_idmapset.sid)-1);
759 wbcFreeMemory(sid_string);
761 wbc_status = wbcRequestResponse(WINBINDD_SET_MAPPING,
762 &request, &response);
763 BAIL_ON_WBC_ERROR(wbc_status);
765 done:
766 return wbc_status;
769 /* Remove a user id mapping */
770 wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid)
772 struct winbindd_request request;
773 struct winbindd_response response;
774 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
775 char *sid_string = NULL;
777 if (!sid) {
778 return WBC_ERR_INVALID_PARAM;
781 /* Initialise request */
783 ZERO_STRUCT(request);
784 ZERO_STRUCT(response);
786 /* Make request */
788 request.data.dual_idmapset.id = uid;
789 request.data.dual_idmapset.type = _ID_TYPE_UID;
791 wbc_status = wbcSidToString(sid, &sid_string);
792 BAIL_ON_WBC_ERROR(wbc_status);
794 strncpy(request.data.dual_idmapset.sid, sid_string,
795 sizeof(request.data.dual_idmapset.sid)-1);
796 wbcFreeMemory(sid_string);
798 wbc_status = wbcRequestResponse(WINBINDD_REMOVE_MAPPING,
799 &request, &response);
800 BAIL_ON_WBC_ERROR(wbc_status);
802 done:
803 return wbc_status;
806 /* Remove a group id mapping */
807 wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid)
809 struct winbindd_request request;
810 struct winbindd_response response;
811 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
812 char *sid_string = NULL;
814 if (!sid) {
815 return WBC_ERR_INVALID_PARAM;
818 /* Initialise request */
820 ZERO_STRUCT(request);
821 ZERO_STRUCT(response);
823 /* Make request */
825 request.data.dual_idmapset.id = gid;
826 request.data.dual_idmapset.type = _ID_TYPE_GID;
828 wbc_status = wbcSidToString(sid, &sid_string);
829 BAIL_ON_WBC_ERROR(wbc_status);
831 strncpy(request.data.dual_idmapset.sid, sid_string,
832 sizeof(request.data.dual_idmapset.sid)-1);
833 wbcFreeMemory(sid_string);
835 wbc_status = wbcRequestResponse(WINBINDD_REMOVE_MAPPING,
836 &request, &response);
837 BAIL_ON_WBC_ERROR(wbc_status);
839 done:
840 return wbc_status;
843 /* Set the highwater mark for allocated uids. */
844 wbcErr wbcSetUidHwm(uid_t uid_hwm)
846 struct winbindd_request request;
847 struct winbindd_response response;
848 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
850 /* Initialise request */
852 ZERO_STRUCT(request);
853 ZERO_STRUCT(response);
855 /* Make request */
857 request.data.dual_idmapset.id = uid_hwm;
858 request.data.dual_idmapset.type = _ID_TYPE_UID;
860 wbc_status = wbcRequestResponse(WINBINDD_SET_HWM,
861 &request, &response);
862 BAIL_ON_WBC_ERROR(wbc_status);
864 done:
865 return wbc_status;
868 /* Set the highwater mark for allocated gids. */
869 wbcErr wbcSetGidHwm(gid_t gid_hwm)
871 struct winbindd_request request;
872 struct winbindd_response response;
873 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
875 /* Initialise request */
877 ZERO_STRUCT(request);
878 ZERO_STRUCT(response);
880 /* Make request */
882 request.data.dual_idmapset.id = gid_hwm;
883 request.data.dual_idmapset.type = _ID_TYPE_GID;
885 wbc_status = wbcRequestResponse(WINBINDD_SET_HWM,
886 &request, &response);
887 BAIL_ON_WBC_ERROR(wbc_status);
889 done:
890 return wbc_status;