libwbclient: Add placeholder functions for wbcQuery[GSU]idTo[GSU]id
[Samba/gebeck_regimport.git] / source3 / nsswitch / libwbclient / wbc_idmap.c
blob81b369c87ccf4bf05c9e003cdab5f6e59b3a63fd
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind client API
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
32 * @return #wbcErr
34 **/
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;
43 if (!sid || !puid) {
44 wbc_status = WBC_ERR_INVALID_PARAM;
45 BAIL_ON_WBC_ERROR(wbc_status);
48 /* Initialize request */
50 ZERO_STRUCT(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);
59 /* Make request */
61 wbc_status = wbcRequestResponse(WINBINDD_SID_TO_UID,
62 &request,
63 &response);
64 BAIL_ON_WBC_ERROR(wbc_status);
66 *puid = response.data.uid;
68 wbc_status = WBC_ERR_SUCCESS;
70 done:
71 return wbc_status;
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
79 * @return #wbcErr
81 **/
83 wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
84 uid_t *puid)
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
94 * @return #wbcErr
96 **/
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;
104 if (!sid) {
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;
116 /* Make request */
118 wbc_status = wbcRequestResponse(WINBINDD_UID_TO_SID,
119 &request,
120 &response);
121 BAIL_ON_WBC_ERROR(wbc_status);
123 wbc_status = wbcStringToSid(response.data.sid.sid, sid);
124 BAIL_ON_WBC_ERROR(wbc_status);
126 done:
127 return 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
135 * @return #wbcErr
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
150 * @return #wbcErr
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;
161 if (!sid || !pgid) {
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);
177 /* Make request */
179 wbc_status = wbcRequestResponse(WINBINDD_SID_TO_GID,
180 &request,
181 &response);
182 BAIL_ON_WBC_ERROR(wbc_status);
184 *pgid = response.data.gid;
186 wbc_status = WBC_ERR_SUCCESS;
188 done:
189 return wbc_status;
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
197 * @return #wbcErr
201 wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
202 gid_t *pgid)
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
212 * @return #wbcErr
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;
222 if (!sid) {
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;
234 /* Make request */
236 wbc_status = wbcRequestResponse(WINBINDD_GID_TO_SID,
237 &request,
238 &response);
239 BAIL_ON_WBC_ERROR(wbc_status);
241 wbc_status = wbcStringToSid(response.data.sid.sid, sid);
242 BAIL_ON_WBC_ERROR(wbc_status);
244 done:
245 return 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
253 * @return #wbcErr
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
267 * @return #wbcErr
270 wbcErr wbcAllocateUid(uid_t *puid)
272 struct winbindd_request request;
273 struct winbindd_response response;
274 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
276 if (!puid)
277 return WBC_ERR_INVALID_PARAM;
279 /* Initialise request */
281 ZERO_STRUCT(request);
282 ZERO_STRUCT(response);
284 /* Make request */
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;
295 done:
296 return wbc_status;
299 /** @brief Obtain a new gid from Winbind
301 * @param *pgid Pointer to the allocated gid
303 * @return #wbcErr
306 wbcErr wbcAllocateGid(gid_t *pgid)
308 struct winbindd_request request;
309 struct winbindd_response response;
310 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
312 if (!pgid)
313 return WBC_ERR_INVALID_PARAM;
315 /* Initialise request */
317 ZERO_STRUCT(request);
318 ZERO_STRUCT(response);
320 /* Make request */
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;
331 done:
332 return wbc_status;
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.
344 * @return #wbcErr
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;
353 if (!sid) {
354 return WBC_ERR_INVALID_PARAM;
357 /* Initialise request */
359 ZERO_STRUCT(request);
360 ZERO_STRUCT(response);
362 /* Make request */
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);
378 done:
379 return 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.
387 * @return #wbcErr
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;
396 if (!sid) {
397 return WBC_ERR_INVALID_PARAM;
400 /* Initialise request */
402 ZERO_STRUCT(request);
403 ZERO_STRUCT(response);
405 /* Make request */
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);
421 done:
422 return 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.
430 * @return #wbcErr
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;
439 if (!sid) {
440 return WBC_ERR_INVALID_PARAM;
443 /* Initialise request */
445 ZERO_STRUCT(request);
446 ZERO_STRUCT(response);
448 /* Make request */
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);
464 done:
465 return 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.
473 * @return #wbcErr
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;
482 if (!sid) {
483 return WBC_ERR_INVALID_PARAM;
486 /* Initialise request */
488 ZERO_STRUCT(request);
489 ZERO_STRUCT(response);
491 /* Make request */
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);
507 done:
508 return wbc_status;
511 /** @brief Set the highwater mark for allocated uids.
513 * @param uid_hwm The new uid highwater mark value
515 * @return #wbcErr
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);
528 /* Make request */
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);
537 done:
538 return wbc_status;
541 /** @brief Set the highwater mark for allocated gids.
543 * @param gid_hwm The new gid highwater mark value
545 * @return #wbcErr
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);
558 /* Make request */
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);
567 done:
568 return wbc_status;