Changeset 745 for trunk/server/nsswitch/libwbclient/wbc_idmap.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/nsswitch/libwbclient/wbc_idmap.c
r480 r745 5 5 6 6 Copyright (C) Gerald (Jerry) Carter 2007 7 8 7 9 8 This library is free software; you can redistribute it and/or … … 25 24 #include "replace.h" 26 25 #include "libwbclient.h" 26 #include "../winbind_client.h" 27 27 28 28 /* Convert a Windows SID to a Unix uid, allocating an uid if needed */ … … 31 31 struct winbindd_request request; 32 32 struct winbindd_response response; 33 char *sid_string = NULL;34 33 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 35 34 … … 44 43 ZERO_STRUCT(response); 45 44 46 wbc_status = wbcSidToString(sid, &sid_string); 47 BAIL_ON_WBC_ERROR(wbc_status); 48 49 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 50 wbcFreeMemory(sid_string); 45 wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid)); 51 46 52 47 /* Make request */ … … 126 121 struct winbindd_response response; 127 122 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 128 char *sid_string = NULL;129 123 130 124 if (!sid || !pgid) { … … 138 132 ZERO_STRUCT(response); 139 133 140 wbc_status = wbcSidToString(sid, &sid_string); 141 BAIL_ON_WBC_ERROR(wbc_status); 142 143 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 144 wbcFreeMemory(sid_string); 134 wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid)); 145 135 146 136 /* Make request */ … … 159 149 } 160 150 151 161 152 /* Convert a Windows SID to a Unix gid if there already is a mapping */ 162 153 … … 166 157 return WBC_ERR_NOT_IMPLEMENTED; 167 158 } 159 168 160 169 161 /* Convert a Unix gid to a Windows SID, allocating a SID if needed */ … … 271 263 #define _ID_TYPE_GID 2 272 264 273 /* Set an user id mapping */265 /* Set an user id mapping - not implemented any more */ 274 266 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid) 275 267 { 276 struct winbindd_request request; 277 struct winbindd_response response; 278 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 279 char *sid_string = NULL; 280 281 if (!sid) { 282 return WBC_ERR_INVALID_PARAM; 283 } 284 285 /* Initialise request */ 286 287 ZERO_STRUCT(request); 288 ZERO_STRUCT(response); 289 290 /* Make request */ 291 292 request.data.dual_idmapset.id = uid; 293 request.data.dual_idmapset.type = _ID_TYPE_UID; 294 295 wbc_status = wbcSidToString(sid, &sid_string); 296 BAIL_ON_WBC_ERROR(wbc_status); 297 298 strncpy(request.data.dual_idmapset.sid, sid_string, 299 sizeof(request.data.dual_idmapset.sid)-1); 300 wbcFreeMemory(sid_string); 301 302 wbc_status = wbcRequestResponsePriv(WINBINDD_SET_MAPPING, 303 &request, &response); 304 BAIL_ON_WBC_ERROR(wbc_status); 305 306 done: 307 return wbc_status; 308 } 309 310 /* Set a group id mapping */ 268 return WBC_ERR_NOT_IMPLEMENTED; 269 } 270 271 /* Set a group id mapping - not implemented any more */ 311 272 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid) 312 273 { 313 struct winbindd_request request; 314 struct winbindd_response response; 315 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 316 char *sid_string = NULL; 317 318 if (!sid) { 319 return WBC_ERR_INVALID_PARAM; 320 } 321 322 /* Initialise request */ 323 324 ZERO_STRUCT(request); 325 ZERO_STRUCT(response); 326 327 /* Make request */ 328 329 request.data.dual_idmapset.id = gid; 330 request.data.dual_idmapset.type = _ID_TYPE_GID; 331 332 wbc_status = wbcSidToString(sid, &sid_string); 333 BAIL_ON_WBC_ERROR(wbc_status); 334 335 strncpy(request.data.dual_idmapset.sid, sid_string, 336 sizeof(request.data.dual_idmapset.sid)-1); 337 wbcFreeMemory(sid_string); 338 339 wbc_status = wbcRequestResponsePriv(WINBINDD_SET_MAPPING, 340 &request, &response); 341 BAIL_ON_WBC_ERROR(wbc_status); 342 343 done: 344 return wbc_status; 345 } 346 347 /* Remove a user id mapping */ 274 return WBC_ERR_NOT_IMPLEMENTED; 275 } 276 277 /* Remove a user id mapping - not implemented any more */ 348 278 wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid) 349 279 { 350 struct winbindd_request request; 351 struct winbindd_response response; 352 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 353 char *sid_string = NULL; 354 355 if (!sid) { 356 return WBC_ERR_INVALID_PARAM; 357 } 358 359 /* Initialise request */ 360 361 ZERO_STRUCT(request); 362 ZERO_STRUCT(response); 363 364 /* Make request */ 365 366 request.data.dual_idmapset.id = uid; 367 request.data.dual_idmapset.type = _ID_TYPE_UID; 368 369 wbc_status = wbcSidToString(sid, &sid_string); 370 BAIL_ON_WBC_ERROR(wbc_status); 371 372 strncpy(request.data.dual_idmapset.sid, sid_string, 373 sizeof(request.data.dual_idmapset.sid)-1); 374 wbcFreeMemory(sid_string); 375 376 wbc_status = wbcRequestResponsePriv(WINBINDD_REMOVE_MAPPING, 377 &request, &response); 378 BAIL_ON_WBC_ERROR(wbc_status); 379 380 done: 381 return wbc_status; 382 } 383 384 /* Remove a group id mapping */ 280 return WBC_ERR_NOT_IMPLEMENTED; 281 } 282 283 /* Remove a group id mapping - not implemented any more */ 385 284 wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid) 386 285 { 387 struct winbindd_request request; 388 struct winbindd_response response; 389 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 390 char *sid_string = NULL; 391 392 if (!sid) { 393 return WBC_ERR_INVALID_PARAM; 394 } 395 396 /* Initialise request */ 397 398 ZERO_STRUCT(request); 399 ZERO_STRUCT(response); 400 401 /* Make request */ 402 403 request.data.dual_idmapset.id = gid; 404 request.data.dual_idmapset.type = _ID_TYPE_GID; 405 406 wbc_status = wbcSidToString(sid, &sid_string); 407 BAIL_ON_WBC_ERROR(wbc_status); 408 409 strncpy(request.data.dual_idmapset.sid, sid_string, 410 sizeof(request.data.dual_idmapset.sid)-1); 411 wbcFreeMemory(sid_string); 412 413 wbc_status = wbcRequestResponsePriv(WINBINDD_REMOVE_MAPPING, 414 &request, &response); 415 BAIL_ON_WBC_ERROR(wbc_status); 416 417 done: 418 return wbc_status; 419 } 420 421 /* Set the highwater mark for allocated uids. */ 286 return WBC_ERR_NOT_IMPLEMENTED; 287 } 288 289 /* Set the highwater mark for allocated uids - not implemented any more */ 422 290 wbcErr wbcSetUidHwm(uid_t uid_hwm) 423 291 { 424 struct winbindd_request request; 425 struct winbindd_response response; 426 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 427 428 /* Initialise request */ 429 430 ZERO_STRUCT(request); 431 ZERO_STRUCT(response); 432 433 /* Make request */ 434 435 request.data.dual_idmapset.id = uid_hwm; 436 request.data.dual_idmapset.type = _ID_TYPE_UID; 437 438 wbc_status = wbcRequestResponsePriv(WINBINDD_SET_HWM, 439 &request, &response); 440 BAIL_ON_WBC_ERROR(wbc_status); 441 442 done: 443 return wbc_status; 444 } 445 446 /* Set the highwater mark for allocated gids. */ 292 return WBC_ERR_NOT_IMPLEMENTED; 293 } 294 295 /* Set the highwater mark for allocated gids - not implemented any more */ 447 296 wbcErr wbcSetGidHwm(gid_t gid_hwm) 448 297 { 449 struct winbindd_request request; 450 struct winbindd_response response; 451 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 452 453 /* Initialise request */ 454 455 ZERO_STRUCT(request); 456 ZERO_STRUCT(response); 457 458 /* Make request */ 459 460 request.data.dual_idmapset.id = gid_hwm; 461 request.data.dual_idmapset.type = _ID_TYPE_GID; 462 463 wbc_status = wbcRequestResponsePriv(WINBINDD_SET_HWM, 464 &request, &response); 465 BAIL_ON_WBC_ERROR(wbc_status); 466 467 done: 468 return wbc_status; 469 } 298 return WBC_ERR_NOT_IMPLEMENTED; 299 } 300 301 /* Convert a list of SIDs */ 302 wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids, 303 struct wbcUnixId *ids) 304 { 305 struct winbindd_request request; 306 struct winbindd_response response; 307 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 308 int buflen, extra_len; 309 uint32_t i; 310 char *sidlist, *p, *extra_data; 311 312 buflen = num_sids * (WBC_SID_STRING_BUFLEN + 1) + 1; 313 314 sidlist = (char *)malloc(buflen); 315 if (sidlist == NULL) { 316 return WBC_ERR_NO_MEMORY; 317 } 318 319 p = sidlist; 320 321 for (i=0; i<num_sids; i++) { 322 int remaining; 323 int len; 324 325 remaining = buflen - (p - sidlist); 326 327 len = wbcSidToStringBuf(&sids[i], p, remaining); 328 if (len > remaining) { 329 free(sidlist); 330 return WBC_ERR_UNKNOWN_FAILURE; 331 } 332 333 p += len; 334 *p++ = '\n'; 335 } 336 *p++ = '\0'; 337 338 ZERO_STRUCT(request); 339 ZERO_STRUCT(response); 340 341 request.extra_data.data = sidlist; 342 request.extra_len = p - sidlist; 343 344 wbc_status = wbcRequestResponse(WINBINDD_SIDS_TO_XIDS, 345 &request, &response); 346 free(sidlist); 347 if (!WBC_ERROR_IS_OK(wbc_status)) { 348 return wbc_status; 349 } 350 351 extra_len = response.length - sizeof(struct winbindd_response); 352 extra_data = (char *)response.extra_data.data; 353 354 if ((extra_len <= 0) || (extra_data[extra_len-1] != '\0')) { 355 goto wbc_err_invalid; 356 } 357 358 p = extra_data; 359 360 for (i=0; i<num_sids; i++) { 361 struct wbcUnixId *id = &ids[i]; 362 char *q; 363 364 switch (p[0]) { 365 case 'U': 366 id->type = WBC_ID_TYPE_UID; 367 id->id.uid = strtoul(p+1, &q, 10); 368 break; 369 case 'G': 370 id->type = WBC_ID_TYPE_GID; 371 id->id.gid = strtoul(p+1, &q, 10); 372 break; 373 default: 374 id->type = WBC_ID_TYPE_NOT_SPECIFIED; 375 q = p; 376 break; 377 }; 378 if (q[0] != '\n') { 379 goto wbc_err_invalid; 380 } 381 p = q+1; 382 } 383 wbc_status = WBC_ERR_SUCCESS; 384 goto done; 385 386 wbc_err_invalid: 387 wbc_status = WBC_ERR_INVALID_RESPONSE; 388 done: 389 winbindd_free_response(&response); 390 return wbc_status; 391 }
Note:
See TracChangeset
for help on using the changeset viewer.