Changeset 745 for trunk/server/nsswitch/libwbclient/wbc_sid.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_sid.c
r414 r745 5 5 6 6 Copyright (C) Gerald (Jerry) Carter 2007 7 Copyright (C) Volker Lendecke 2010 7 8 8 9 … … 25 26 #include "replace.h" 26 27 #include "libwbclient.h" 27 28 29 /* Convert a binary SID to a character string */30 wbcErr wbcSidToString(const struct wbcDomainSid *sid, 31 char **sid_string) 32 { 33 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 28 #include "../winbind_client.h" 29 30 /* Convert a sid to a string into a buffer. Return the string 31 * length. If buflen is too small, return the string length that would 32 * result if it was long enough. */ 33 int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen) 34 { 34 35 uint32_t id_auth; 35 int i; 36 char *tmp = NULL; 36 int i, ofs; 37 37 38 38 if (!sid) { 39 wbc_status = WBC_ERR_INVALID_SID; 40 BAIL_ON_WBC_ERROR(wbc_status); 41 } 39 strlcpy(buf, "(NULL SID)", buflen); 40 return 10; /* strlen("(NULL SID)") */ 41 } 42 43 /* 44 * BIG NOTE: this function only does SIDS where the identauth is not 45 * >= ^32 in a range of 2^48. 46 */ 42 47 43 48 id_auth = sid->id_auth[5] + … … 46 51 (sid->id_auth[2] << 24); 47 52 48 tmp = talloc_asprintf(NULL, "S-%d-%d", sid->sid_rev_num, id_auth); 49 BAIL_ON_PTR_ERROR(tmp, wbc_status); 50 51 for (i=0; i<sid->num_auths; i++) { 52 char *tmp2; 53 tmp2 = talloc_asprintf_append(tmp, "-%u", sid->sub_auths[i]); 54 BAIL_ON_PTR_ERROR(tmp2, wbc_status); 55 56 tmp = tmp2; 57 } 58 59 *sid_string = tmp; 60 tmp = NULL; 61 62 wbc_status = WBC_ERR_SUCCESS; 63 64 done: 65 talloc_free(tmp); 66 67 return wbc_status; 53 ofs = snprintf(buf, buflen, "S-%u-%lu", 54 (unsigned int)sid->sid_rev_num, (unsigned long)id_auth); 55 56 for (i = 0; i < sid->num_auths; i++) { 57 ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%lu", 58 (unsigned long)sid->sub_auths[i]); 59 } 60 return ofs; 61 } 62 63 /* Convert a binary SID to a character string */ 64 wbcErr wbcSidToString(const struct wbcDomainSid *sid, 65 char **sid_string) 66 { 67 char buf[WBC_SID_STRING_BUFLEN]; 68 char *result; 69 int len; 70 71 if (!sid) { 72 return WBC_ERR_INVALID_SID; 73 } 74 75 len = wbcSidToStringBuf(sid, buf, sizeof(buf)); 76 77 if (len+1 > sizeof(buf)) { 78 return WBC_ERR_INVALID_SID; 79 } 80 81 result = (char *)wbcAllocateMemory(len+1, 1, NULL); 82 if (result == NULL) { 83 return WBC_ERR_NO_MEMORY; 84 } 85 memcpy(result, buf, len+1); 86 87 *sid_string = result; 88 return WBC_ERR_SUCCESS; 68 89 } 69 90 … … 132 153 sid->sub_auths[sid->num_auths++] = x; 133 154 134 if ( (*q!='-') || (*q=='\0'))155 if (*q != '-') { 135 156 break; 157 } 136 158 p = q + 1; 137 159 } … … 150 172 151 173 } 174 152 175 153 176 /* Convert a domain and name to SID */ … … 194 217 } 195 218 219 196 220 /* Convert a SID to a domain and name */ 197 221 wbcErr wbcLookupSid(const struct wbcDomainSid *sid, … … 203 227 struct winbindd_response response; 204 228 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 205 char *sid_string = NULL; 206 char *domain = NULL; 207 char *name = NULL; 208 enum wbcSidType name_type = WBC_SID_NAME_USE_NONE; 229 char *domain, *name; 209 230 210 231 if (!sid) { 211 wbc_status = WBC_ERR_INVALID_PARAM; 212 BAIL_ON_WBC_ERROR(wbc_status); 232 return WBC_ERR_INVALID_PARAM; 213 233 } 214 234 … … 218 238 ZERO_STRUCT(response); 219 239 220 /* dst is already null terminated from the memset above */ 221 222 wbc_status = wbcSidToString(sid, &sid_string); 223 BAIL_ON_WBC_ERROR(wbc_status); 224 225 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 226 wbcFreeMemory(sid_string); 240 wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid)); 227 241 228 242 /* Make request */ 229 243 230 wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSID, 231 &request, 232 &response); 233 BAIL_ON_WBC_ERROR(wbc_status); 244 wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSID, &request, 245 &response); 246 if (!WBC_ERROR_IS_OK(wbc_status)) { 247 return wbc_status; 248 } 234 249 235 250 /* Copy out result */ 236 251 237 domain = talloc_strdup(NULL, response.data.name.dom_name); 238 BAIL_ON_PTR_ERROR(domain, wbc_status); 239 240 name = talloc_strdup(NULL, response.data.name.name); 241 BAIL_ON_PTR_ERROR(name, wbc_status); 242 243 name_type = (enum wbcSidType)response.data.name.type; 244 252 wbc_status = WBC_ERR_NO_MEMORY; 253 domain = NULL; 254 name = NULL; 255 256 domain = wbcStrDup(response.data.name.dom_name); 257 if (domain == NULL) { 258 goto done; 259 } 260 name = wbcStrDup(response.data.name.name); 261 if (name == NULL) { 262 goto done; 263 } 264 if (pdomain != NULL) { 265 *pdomain = domain; 266 domain = NULL; 267 } 268 if (pname != NULL) { 269 *pname = name; 270 name = NULL; 271 } 272 if (pname_type != NULL) { 273 *pname_type = (enum wbcSidType)response.data.name.type; 274 } 245 275 wbc_status = WBC_ERR_SUCCESS; 246 247 done: 248 if (WBC_ERROR_IS_OK(wbc_status)) { 249 if (pdomain != NULL) { 250 *pdomain = domain; 251 } else { 252 TALLOC_FREE(domain); 253 } 254 if (pname != NULL) { 255 *pname = name; 256 } else { 257 TALLOC_FREE(name); 258 } 259 if (pname_type != NULL) { 260 *pname_type = name_type; 261 } 262 } 263 else { 264 #if 0 265 /* 266 * Found by Coverity: In this particular routine we can't end 267 * up here with a non-NULL name. Further up there are just two 268 * exit paths that lead here, neither of which leave an 269 * allocated name. If you add more paths up there, re-activate 270 * this. 271 */ 272 if (name != NULL) { 273 talloc_free(name); 274 } 275 #endif 276 if (domain != NULL) { 277 talloc_free(domain); 278 } 279 } 280 276 done: 277 wbcFreeMemory(name); 278 wbcFreeMemory(domain); 279 return wbc_status; 280 } 281 282 static void wbcDomainInfosDestructor(void *ptr) 283 { 284 struct wbcDomainInfo *i = (struct wbcDomainInfo *)ptr; 285 286 while (i->short_name != NULL) { 287 wbcFreeMemory(i->short_name); 288 wbcFreeMemory(i->dns_name); 289 i += 1; 290 } 291 } 292 293 static void wbcTranslatedNamesDestructor(void *ptr) 294 { 295 struct wbcTranslatedName *n = (struct wbcTranslatedName *)ptr; 296 297 while (n->name != NULL) { 298 free(n->name); 299 n += 1; 300 } 301 } 302 303 wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids, 304 struct wbcDomainInfo **pdomains, int *pnum_domains, 305 struct wbcTranslatedName **pnames) 306 { 307 struct winbindd_request request; 308 struct winbindd_response response; 309 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 310 int buflen, i, extra_len, num_domains, num_names; 311 char *sidlist, *p, *q, *extra_data; 312 struct wbcDomainInfo *domains = NULL; 313 struct wbcTranslatedName *names = NULL; 314 315 buflen = num_sids * (WBC_SID_STRING_BUFLEN + 1) + 1; 316 317 sidlist = (char *)malloc(buflen); 318 if (sidlist == NULL) { 319 return WBC_ERR_NO_MEMORY; 320 } 321 322 p = sidlist; 323 324 for (i=0; i<num_sids; i++) { 325 int remaining; 326 int len; 327 328 remaining = buflen - (p - sidlist); 329 330 len = wbcSidToStringBuf(&sids[i], p, remaining); 331 if (len > remaining) { 332 free(sidlist); 333 return WBC_ERR_UNKNOWN_FAILURE; 334 } 335 336 p += len; 337 *p++ = '\n'; 338 } 339 *p++ = '\0'; 340 341 ZERO_STRUCT(request); 342 ZERO_STRUCT(response); 343 344 request.extra_data.data = sidlist; 345 request.extra_len = p - sidlist; 346 347 wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSIDS, 348 &request, &response); 349 free(sidlist); 350 if (!WBC_ERROR_IS_OK(wbc_status)) { 351 return wbc_status; 352 } 353 354 extra_len = response.length - sizeof(struct winbindd_response); 355 extra_data = (char *)response.extra_data.data; 356 357 if ((extra_len <= 0) || (extra_data[extra_len-1] != '\0')) { 358 goto wbc_err_invalid; 359 } 360 361 p = extra_data; 362 363 num_domains = strtoul(p, &q, 10); 364 if (*q != '\n') { 365 goto wbc_err_invalid; 366 } 367 p = q+1; 368 369 domains = (struct wbcDomainInfo *)wbcAllocateMemory( 370 num_domains+1, sizeof(struct wbcDomainInfo), 371 wbcDomainInfosDestructor); 372 if (domains == NULL) { 373 wbc_status = WBC_ERR_NO_MEMORY; 374 goto fail; 375 } 376 377 for (i=0; i<num_domains; i++) { 378 379 q = strchr(p, ' '); 380 if (q == NULL) { 381 goto wbc_err_invalid; 382 } 383 *q = '\0'; 384 wbc_status = wbcStringToSid(p, &domains[i].sid); 385 if (!WBC_ERROR_IS_OK(wbc_status)) { 386 goto fail; 387 } 388 p = q+1; 389 390 q = strchr(p, '\n'); 391 if (q == NULL) { 392 goto wbc_err_invalid; 393 } 394 *q = '\0'; 395 domains[i].short_name = wbcStrDup(p); 396 if (domains[i].short_name == NULL) { 397 wbc_status = WBC_ERR_NO_MEMORY; 398 goto fail; 399 } 400 p = q+1; 401 } 402 403 num_names = strtoul(p, &q, 10); 404 if (*q != '\n') { 405 goto wbc_err_invalid; 406 } 407 p = q+1; 408 409 if (num_names != num_sids) { 410 goto wbc_err_invalid; 411 } 412 413 names = (struct wbcTranslatedName *)wbcAllocateMemory( 414 num_names+1, sizeof(struct wbcTranslatedName), 415 wbcTranslatedNamesDestructor); 416 if (names == NULL) { 417 wbc_status = WBC_ERR_NO_MEMORY; 418 goto fail; 419 } 420 421 for (i=0; i<num_names; i++) { 422 423 names[i].domain_index = strtoul(p, &q, 10); 424 if (*q != ' ') { 425 goto wbc_err_invalid; 426 } 427 p = q+1; 428 429 names[i].type = strtoul(p, &q, 10); 430 if (*q != ' ') { 431 goto wbc_err_invalid; 432 } 433 p = q+1; 434 435 q = strchr(p, '\n'); 436 if (q == NULL) { 437 goto wbc_err_invalid; 438 } 439 *q = '\0'; 440 names[i].name = wbcStrDup(p); 441 if (names[i].name == NULL) { 442 wbc_status = WBC_ERR_NO_MEMORY; 443 goto fail; 444 } 445 p = q+1; 446 } 447 if (*p != '\0') { 448 goto wbc_err_invalid; 449 } 450 451 *pdomains = domains; 452 *pnames = names; 453 winbindd_free_response(&response); 454 return WBC_ERR_SUCCESS; 455 456 wbc_err_invalid: 457 wbc_status = WBC_ERR_INVALID_RESPONSE; 458 fail: 459 winbindd_free_response(&response); 460 wbcFreeMemory(domains); 461 wbcFreeMemory(names); 281 462 return wbc_status; 282 463 } … … 296 477 struct winbindd_request request; 297 478 struct winbindd_response response; 298 char *sid_string = NULL;299 479 char *domain_name = NULL; 300 480 const char **names = NULL; … … 312 492 } 313 493 314 wbc_status = wbcSidToString(dom_sid, &sid_string); 315 BAIL_ON_WBC_ERROR(wbc_status); 316 317 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 318 wbcFreeMemory(sid_string); 494 wbcSidToStringBuf(dom_sid, request.data.sid, sizeof(request.data.sid)); 319 495 320 496 /* Even if all the Rids were of maximum 32bit values, … … 325 501 ridbuf_size = (sizeof(char)*11) * num_rids + 1; 326 502 327 ridlist = talloc_zero_array(NULL, char,ridbuf_size);503 ridlist = (char *)malloc(ridbuf_size); 328 504 BAIL_ON_PTR_ERROR(ridlist, wbc_status); 329 505 330 506 len = 0; 331 for (i=0; i<num_rids && (len-1)>0; i++) { 332 char ridstr[12]; 333 334 len = strlen(ridlist); 335 p = ridlist + len; 336 337 snprintf( ridstr, sizeof(ridstr)-1, "%u\n", rids[i]); 338 strncat(p, ridstr, ridbuf_size-len-1); 339 } 507 for (i=0; i<num_rids; i++) { 508 len += snprintf(ridlist + len, ridbuf_size - len, "%u\n", 509 rids[i]); 510 } 511 ridlist[len] = '\0'; 512 len += 1; 340 513 341 514 request.extra_data.data = ridlist; 342 request.extra_len = strlen(ridlist)+1;515 request.extra_len = len; 343 516 344 517 wbc_status = wbcRequestResponse(WINBINDD_LOOKUPRIDS, 345 518 &request, 346 519 &response); 347 talloc_free(ridlist);520 free(ridlist); 348 521 BAIL_ON_WBC_ERROR(wbc_status); 349 522 350 domain_name = talloc_strdup(NULL,response.data.domain_name);523 domain_name = wbcStrDup(response.data.domain_name); 351 524 BAIL_ON_PTR_ERROR(domain_name, wbc_status); 352 525 353 names = talloc_array(NULL, const char*,num_rids);526 names = wbcAllocateStringArray(num_rids); 354 527 BAIL_ON_PTR_ERROR(names, wbc_status); 355 528 356 types = talloc_array(NULL, enum wbcSidType, num_rids); 529 types = (enum wbcSidType *)wbcAllocateMemory( 530 num_rids, sizeof(enum wbcSidType), NULL); 357 531 BAIL_ON_PTR_ERROR(types, wbc_status); 358 532 … … 364 538 if (*p == '\0') { 365 539 wbc_status = WBC_ERR_INVALID_RESPONSE; 366 BAIL_ON_WBC_ERROR(wbc_status);540 goto done; 367 541 } 368 542 … … 371 545 if (*q != ' ') { 372 546 wbc_status = WBC_ERR_INVALID_RESPONSE; 373 BAIL_ON_WBC_ERROR(wbc_status);547 goto done; 374 548 } 375 549 … … 378 552 if ((q = strchr(p, '\n')) == NULL) { 379 553 wbc_status = WBC_ERR_INVALID_RESPONSE; 380 BAIL_ON_WBC_ERROR(wbc_status);554 goto done; 381 555 } 382 556 383 557 *q = '\0'; 384 558 385 names[i] = talloc_strdup(names,p);559 names[i] = strdup(p); 386 560 BAIL_ON_PTR_ERROR(names[i], wbc_status); 387 561 … … 391 565 if (*p != '\0') { 392 566 wbc_status = WBC_ERR_INVALID_RESPONSE; 393 BAIL_ON_WBC_ERROR(wbc_status);567 goto done; 394 568 } 395 569 … … 397 571 398 572 done: 399 if (response.extra_data.data) { 400 free(response.extra_data.data); 401 } 573 winbindd_free_response(&response); 402 574 403 575 if (WBC_ERROR_IS_OK(wbc_status)) { … … 407 579 } 408 580 else { 409 if (domain_name) 410 talloc_free(domain_name); 411 if (names) 412 talloc_free(names); 413 if (types) 414 talloc_free(types); 581 wbcFreeMemory(domain_name); 582 wbcFreeMemory(names); 583 wbcFreeMemory(types); 415 584 } 416 585 … … 428 597 struct winbindd_request request; 429 598 struct winbindd_response response; 430 char *sid_string = NULL;431 599 struct wbcDomainSid *sids = NULL; 432 600 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; … … 443 611 } 444 612 445 wbc_status = wbcSidToString(user_sid, &sid_string); 446 BAIL_ON_WBC_ERROR(wbc_status); 447 448 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 449 wbcFreeMemory(sid_string); 613 wbcSidToStringBuf(user_sid, request.data.sid, sizeof(request.data.sid)); 450 614 451 615 if (domain_groups_only) { … … 466 630 } 467 631 468 sids = talloc_array(NULL, struct wbcDomainSid, 469 response.data.num_entries); 632 sids = (struct wbcDomainSid *)wbcAllocateMemory( 633 response.data.num_entries, sizeof(struct wbcDomainSid), 634 NULL); 470 635 BAIL_ON_PTR_ERROR(sids, wbc_status); 471 636 … … 487 652 488 653 done: 489 if (response.extra_data.data) { 490 free(response.extra_data.data); 491 } 654 winbindd_free_response(&response); 492 655 if (sids) { 493 talloc_free(sids);656 wbcFreeMemory(sids); 494 657 } 495 658 … … 519 682 struct winbindd_request request; 520 683 struct winbindd_response response; 521 char *sid_string = NULL;522 ssize_t sid_len;523 684 ssize_t extra_data_len = 0; 524 685 char * extra_data = NULL; … … 535 696 if (!dom_sid) { 536 697 wbc_status = WBC_ERR_INVALID_PARAM; 537 BAIL_ON_WBC_ERROR(wbc_status); 538 } 539 540 wbc_status = wbcSidToString(dom_sid, &sid_string); 541 BAIL_ON_WBC_ERROR(wbc_status); 542 543 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 544 wbcFreeMemory(sid_string); 545 sid_string = NULL; 546 547 /* Lets assume each sid is around 54 characters 548 * S-1-5-AAAAAAAAAAA-BBBBBBBBBBB-CCCCCCCCCCC-DDDDDDDDDDD\n */ 549 buflen = 54 * num_sids; 550 extra_data = talloc_array(NULL, char, buflen); 698 goto done; 699 } 700 701 wbcSidToStringBuf(dom_sid, request.data.sid, sizeof(request.data.sid)); 702 703 /* Lets assume each sid is around 57 characters 704 * S-1-5-21-AAAAAAAAAAA-BBBBBBBBBBB-CCCCCCCCCCC-DDDDDDDDDDD\n */ 705 buflen = 57 * num_sids; 706 extra_data = (char *)malloc(buflen); 551 707 if (!extra_data) { 552 708 wbc_status = WBC_ERR_NO_MEMORY; 553 BAIL_ON_WBC_ERROR(wbc_status);709 goto done; 554 710 } 555 711 556 712 /* Build the sid list */ 557 713 for (i=0; i<num_sids; i++) { 558 if (sid_string) { 559 wbcFreeMemory(sid_string); 560 sid_string = NULL; 561 } 562 wbc_status = wbcSidToString(&sids[i], &sid_string); 563 BAIL_ON_WBC_ERROR(wbc_status); 564 565 sid_len = strlen(sid_string); 714 char sid_str[WBC_SID_STRING_BUFLEN]; 715 size_t sid_len; 716 717 sid_len = wbcSidToStringBuf(&sids[i], sid_str, sizeof(sid_str)); 566 718 567 719 if (buflen < extra_data_len + sid_len + 2) { 568 720 buflen *= 2; 569 extra_data = talloc_realloc(NULL, extra_data, 570 char, buflen); 721 extra_data = (char *)realloc(extra_data, buflen); 571 722 if (!extra_data) { 572 723 wbc_status = WBC_ERR_NO_MEMORY; … … 575 726 } 576 727 577 strncpy(&extra_data[extra_data_len], sid_str ing,728 strncpy(&extra_data[extra_data_len], sid_str, 578 729 buflen - extra_data_len); 579 730 extra_data_len += sid_len; … … 581 732 extra_data[extra_data_len] = '\0'; 582 733 } 734 extra_data_len += 1; 583 735 584 736 request.extra_data.data = extra_data; … … 593 745 !response.extra_data.data) { 594 746 wbc_status = WBC_ERR_INVALID_RESPONSE; 595 BAIL_ON_WBC_ERROR(wbc_status);596 } 597 598 rids = talloc_array(NULL, uint32_t,599 response.data.num_entries);747 goto done; 748 } 749 750 rids = (uint32_t *)wbcAllocateMemory(response.data.num_entries, 751 sizeof(uint32_t), NULL); 600 752 BAIL_ON_PTR_ERROR(sids, wbc_status); 601 753 … … 619 771 620 772 done: 621 if (sid_string) { 622 wbcFreeMemory(sid_string); 623 } 624 if (extra_data) { 625 talloc_free(extra_data); 626 } 627 if (response.extra_data.data) { 628 free(response.extra_data.data); 629 } 630 if (rids) { 631 talloc_free(rids); 632 } 633 773 free(extra_data); 774 winbindd_free_response(&response); 775 wbcFreeMemory(rids); 634 776 return wbc_status; 635 777 } … … 663 805 BAIL_ON_WBC_ERROR(wbc_status); 664 806 807 users = wbcAllocateStringArray(response.data.num_entries); 808 if (users == NULL) { 809 return WBC_ERR_NO_MEMORY; 810 } 811 665 812 /* Look through extra data */ 666 813 667 814 next = (const char *)response.extra_data.data; 668 815 while (next) { 669 const char **tmp; 670 const char *current = next; 671 char *k = strchr(next, ','); 816 const char *current; 817 char *k; 818 819 if (num_users >= response.data.num_entries) { 820 wbc_status = WBC_ERR_INVALID_RESPONSE; 821 goto done; 822 } 823 824 current = next; 825 k = strchr(next, ','); 826 672 827 if (k) { 673 828 k[0] = '\0'; … … 677 832 } 678 833 679 tmp = talloc_realloc(NULL, users, 680 const char *, 681 num_users+1); 682 BAIL_ON_PTR_ERROR(tmp, wbc_status); 683 users = tmp; 684 685 users[num_users] = talloc_strdup(users, current); 834 users[num_users] = strdup(current); 686 835 BAIL_ON_PTR_ERROR(users[num_users], wbc_status); 687 688 num_users++; 689 } 690 691 *_num_users = num_users; 836 num_users += 1; 837 } 838 if (num_users != response.data.num_entries) { 839 wbc_status = WBC_ERR_INVALID_RESPONSE; 840 goto done; 841 } 842 843 *_num_users = response.data.num_entries; 692 844 *_users = users; 693 845 users = NULL; … … 695 847 696 848 done: 697 if (response.extra_data.data) { 698 free(response.extra_data.data); 699 } 700 if (users) { 701 talloc_free(users); 702 } 849 winbindd_free_response(&response); 850 wbcFreeMemory(users); 703 851 return wbc_status; 704 852 } … … 731 879 BAIL_ON_WBC_ERROR(wbc_status); 732 880 881 groups = wbcAllocateStringArray(response.data.num_entries); 882 if (groups == NULL) { 883 return WBC_ERR_NO_MEMORY; 884 } 885 733 886 /* Look through extra data */ 734 887 735 888 next = (const char *)response.extra_data.data; 736 889 while (next) { 737 const char **tmp; 738 const char *current = next; 739 char *k = strchr(next, ','); 890 const char *current; 891 char *k; 892 893 if (num_groups >= response.data.num_entries) { 894 wbc_status = WBC_ERR_INVALID_RESPONSE; 895 goto done; 896 } 897 898 current = next; 899 k = strchr(next, ','); 900 740 901 if (k) { 741 902 k[0] = '\0'; … … 745 906 } 746 907 747 tmp = talloc_realloc(NULL, groups, 748 const char *, 749 num_groups+1); 750 BAIL_ON_PTR_ERROR(tmp, wbc_status); 751 groups = tmp; 752 753 groups[num_groups] = talloc_strdup(groups, current); 908 groups[num_groups] = strdup(current); 754 909 BAIL_ON_PTR_ERROR(groups[num_groups], wbc_status); 755 756 num_groups++; 757 } 758 759 *_num_groups = num_groups; 910 num_groups += 1; 911 } 912 if (num_groups != response.data.num_entries) { 913 wbc_status = WBC_ERR_INVALID_RESPONSE; 914 goto done; 915 } 916 917 *_num_groups = response.data.num_entries; 760 918 *_groups = groups; 761 919 groups = NULL; … … 763 921 764 922 done: 765 if (response.extra_data.data) { 766 free(response.extra_data.data); 767 } 768 if (groups) { 769 talloc_free(groups); 770 } 923 winbindd_free_response(&response); 924 wbcFreeMemory(groups); 771 925 return wbc_status; 772 926 } … … 797 951 wbcFreeMemory(name); 798 952 799 name = talloc_strdup(NULL, pwd->pw_gecos); 953 name = wbcStrDup(pwd->pw_gecos); 954 wbcFreeMemory(pwd); 800 955 BAIL_ON_PTR_ERROR(name, wbc_status); 801 956 }
Note:
See TracChangeset
for help on using the changeset viewer.