Changeset 988 for vendor/current/source3/groupdb/mapping.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/groupdb/mapping.c
r740 r988 28 28 #include "lib/winbind_util.h" 29 29 #include <tdb.h> 30 #include "groupdb/mapping_tdb.h" 30 31 31 32 static const struct mapping_backend *backend; … … 51 52 NTSTATUS add_initial_entry(gid_t gid, const char *sid, enum lsa_SidType sid_name_use, const char *nt_name, const char *comment) 52 53 { 53 GROUP_MAP map; 54 NTSTATUS status; 55 GROUP_MAP *map; 54 56 55 57 if(!init_group_mapping()) { … … 58 60 } 59 61 60 map.gid=gid; 61 if (!string_to_sid(&map.sid, sid)) { 62 map = talloc_zero(NULL, GROUP_MAP); 63 if (!map) { 64 return NT_STATUS_NO_MEMORY; 65 } 66 67 map->gid=gid; 68 if (!string_to_sid(&map->sid, sid)) { 62 69 DEBUG(0, ("string_to_sid failed: %s", sid)); 63 return NT_STATUS_UNSUCCESSFUL; 64 } 65 66 map.sid_name_use=sid_name_use; 67 fstrcpy(map.nt_name, nt_name); 68 fstrcpy(map.comment, comment); 69 70 return pdb_add_group_mapping_entry(&map); 70 status = NT_STATUS_UNSUCCESSFUL; 71 goto done; 72 } 73 74 map->sid_name_use=sid_name_use; 75 map->nt_name = talloc_strdup(map, nt_name); 76 if (!map->nt_name) { 77 status = NT_STATUS_NO_MEMORY; 78 goto done; 79 } 80 81 if (comment) { 82 map->comment = talloc_strdup(map, comment); 83 } else { 84 map->comment = talloc_strdup(map, ""); 85 } 86 if (!map->comment) { 87 status = NT_STATUS_NO_MEMORY; 88 goto done; 89 } 90 91 status = pdb_add_group_mapping_entry(map); 92 93 done: 94 TALLOC_FREE(map); 95 return status; 71 96 } 72 97 … … 128 153 129 154 if ( !ret ) { 130 uint32 rid;155 uint32_t rid; 131 156 132 157 sid_peek_rid( &sid, &rid ); 133 158 134 159 if ( rid == DOMAIN_RID_USERS ) { 135 fstrcpy( map->nt_name, "None" ); 136 fstrcpy( map->comment, "Ordinary Users" ); 160 map->nt_name = talloc_strdup(map, "None"); 161 if (!map->nt_name) { 162 return false; 163 } 164 map->comment = talloc_strdup(map, "Ordinary Users"); 165 if (!map->comment) { 166 return false; 167 } 137 168 sid_copy( &map->sid, &sid ); 138 169 map->sid_name_use = SID_NAME_DOM_GRP; … … 183 214 /* defer to scripts */ 184 215 185 if ( *lp_add group_script() ) {216 if ( *lp_add_group_script(talloc_tos()) ) { 186 217 TALLOC_CTX *ctx = talloc_tos(); 187 218 188 219 add_script = talloc_strdup(ctx, 189 lp_add group_script());220 lp_add_group_script(ctx)); 190 221 if (!add_script) { 191 222 return -1; … … 239 270 /* defer to scripts */ 240 271 241 if ( *lp_del group_script() ) {272 if ( *lp_delete_group_script(talloc_tos()) ) { 242 273 TALLOC_CTX *ctx = talloc_tos(); 243 274 244 275 del_script = talloc_strdup(ctx, 245 lp_del group_script());276 lp_delete_group_script(ctx)); 246 277 if (!del_script) { 247 278 return -1; … … 274 305 /* defer to scripts */ 275 306 276 if ( *lp_set primarygroup_script() ) {307 if ( *lp_set_primary_group_script(talloc_tos()) ) { 277 308 TALLOC_CTX *ctx = talloc_tos(); 278 309 279 310 add_script = talloc_strdup(ctx, 280 lp_set primarygroup_script());311 lp_set_primary_group_script(ctx)); 281 312 if (!add_script) { 282 313 return -1; … … 316 347 /* defer to scripts */ 317 348 318 if ( *lp_add usertogroup_script() ) {349 if ( *lp_add_user_to_group_script(talloc_tos()) ) { 319 350 TALLOC_CTX *ctx = talloc_tos(); 320 351 321 352 add_script = talloc_strdup(ctx, 322 lp_add usertogroup_script());353 lp_add_user_to_group_script(ctx)); 323 354 if (!add_script) { 324 355 return -1; … … 356 387 /* defer to scripts */ 357 388 358 if ( *lp_del userfromgroup_script() ) {389 if ( *lp_delete_user_from_group_script(talloc_tos()) ) { 359 390 TALLOC_CTX *ctx = talloc_tos(); 360 391 361 392 del_script = talloc_strdup(ctx, 362 lp_del userfromgroup_script());393 lp_delete_user_from_group_script(ctx)); 363 394 if (!del_script) { 364 395 return -1; … … 453 484 454 485 NTSTATUS pdb_default_enum_group_mapping(struct pdb_methods *methods, 455 const struct dom_sid *sid, enum lsa_SidType sid_name_use, 456 GROUP_MAP **pp_rmap, size_t *p_num_entries, 457 bool unix_only) 486 const struct dom_sid *sid, 487 enum lsa_SidType sid_name_use, 488 GROUP_MAP ***pp_rmap, 489 size_t *p_num_entries, 490 bool unix_only) 458 491 { 459 492 if (!init_group_mapping()) { … … 466 499 467 500 NTSTATUS pdb_default_create_alias(struct pdb_methods *methods, 468 const char *name, uint32 *rid)501 const char *name, uint32_t *rid) 469 502 { 470 503 struct dom_sid sid; 471 504 enum lsa_SidType type; 472 uint32 new_rid;505 uint32_t new_rid; 473 506 gid_t gid; 474 507 bool exists; 475 GROUP_MAP map;508 GROUP_MAP *map; 476 509 TALLOC_CTX *mem_ctx; 477 510 NTSTATUS status; … … 486 519 exists = lookup_name(mem_ctx, name, LOOKUP_NAME_LOCAL, 487 520 NULL, NULL, &sid, &type); 488 TALLOC_FREE(mem_ctx);489 521 490 522 if (exists) { 491 return NT_STATUS_ALIAS_EXISTS; 523 status = NT_STATUS_ALIAS_EXISTS; 524 goto done; 492 525 } 493 526 494 527 if (!pdb_new_rid(&new_rid)) { 495 528 DEBUG(0, ("Could not allocate a RID.\n")); 496 return NT_STATUS_ACCESS_DENIED; 529 status = NT_STATUS_ACCESS_DENIED; 530 goto done; 497 531 } 498 532 … … 502 536 DEBUG(3, ("Could not get a gid out of winbind - " 503 537 "wasted a rid :-(\n")); 504 return NT_STATUS_ACCESS_DENIED; 538 status = NT_STATUS_ACCESS_DENIED; 539 goto done; 505 540 } 506 541 … … 508 543 name, (unsigned int)gid, (unsigned int)new_rid)); 509 544 510 map.gid = gid; 511 sid_copy(&map.sid, &sid); 512 map.sid_name_use = SID_NAME_ALIAS; 513 fstrcpy(map.nt_name, name); 514 fstrcpy(map.comment, ""); 515 516 status = pdb_add_group_mapping_entry(&map); 545 map = talloc_zero(mem_ctx, GROUP_MAP); 546 if (!map) { 547 status = NT_STATUS_NO_MEMORY; 548 goto done; 549 } 550 551 map->gid = gid; 552 sid_copy(&map->sid, &sid); 553 map->sid_name_use = SID_NAME_ALIAS; 554 map->nt_name = talloc_strdup(map, name); 555 if (!map->nt_name) { 556 status = NT_STATUS_NO_MEMORY; 557 goto done; 558 } 559 map->comment = talloc_strdup(map, ""); 560 if (!map->comment) { 561 status = NT_STATUS_NO_MEMORY; 562 goto done; 563 } 564 565 status = pdb_add_group_mapping_entry(map); 517 566 518 567 if (!NT_STATUS_IS_OK(status)) { 519 568 DEBUG(0, ("Could not add group mapping entry for alias %s " 520 569 "(%s)\n", name, nt_errstr(status))); 521 return status;570 goto done; 522 571 } 523 572 524 573 *rid = new_rid; 525 574 526 return NT_STATUS_OK; 575 done: 576 TALLOC_FREE(mem_ctx); 577 return status; 527 578 } 528 579 … … 537 588 struct acct_info *info) 538 589 { 539 GROUP_MAP map; 540 541 if (!pdb_getgrsid(&map, *sid)) 542 return NT_STATUS_NO_SUCH_ALIAS; 543 544 if ((map.sid_name_use != SID_NAME_ALIAS) && 545 (map.sid_name_use != SID_NAME_WKN_GRP)) { 590 NTSTATUS status = NT_STATUS_OK; 591 GROUP_MAP *map; 592 593 map = talloc_zero(NULL, GROUP_MAP); 594 if (!map) { 595 return NT_STATUS_NO_MEMORY; 596 } 597 598 if (!pdb_getgrsid(map, *sid)) { 599 status = NT_STATUS_NO_SUCH_ALIAS; 600 goto done; 601 } 602 603 if ((map->sid_name_use != SID_NAME_ALIAS) && 604 (map->sid_name_use != SID_NAME_WKN_GRP)) { 546 605 DEBUG(2, ("%s is a %s, expected an alias\n", 547 606 sid_string_dbg(sid), 548 sid_type_lookup(map.sid_name_use))); 549 return NT_STATUS_NO_SUCH_ALIAS; 550 } 551 552 fstrcpy(info->acct_name, map.nt_name); 553 fstrcpy(info->acct_desc, map.comment); 554 sid_peek_rid(&map.sid, &info->rid); 555 return NT_STATUS_OK; 607 sid_type_lookup(map->sid_name_use))); 608 status = NT_STATUS_NO_SUCH_ALIAS; 609 goto done; 610 } 611 612 info->acct_name = talloc_move(info, &map->nt_name); 613 if (!info->acct_name) { 614 status = NT_STATUS_NO_MEMORY; 615 goto done; 616 } 617 info->acct_desc = talloc_move(info, &map->comment); 618 if (!info->acct_desc) { 619 status = NT_STATUS_NO_MEMORY; 620 goto done; 621 } 622 sid_peek_rid(&map->sid, &info->rid); 623 624 done: 625 TALLOC_FREE(map); 626 return status; 556 627 } 557 628 … … 560 631 struct acct_info *info) 561 632 { 562 GROUP_MAP map; 563 564 if (!pdb_getgrsid(&map, *sid)) 565 return NT_STATUS_NO_SUCH_ALIAS; 566 567 fstrcpy(map.nt_name, info->acct_name); 568 fstrcpy(map.comment, info->acct_desc); 569 570 return pdb_update_group_mapping_entry(&map); 633 NTSTATUS status = NT_STATUS_OK; 634 GROUP_MAP *map; 635 636 map = talloc_zero(NULL, GROUP_MAP); 637 if (!map) { 638 return NT_STATUS_NO_MEMORY; 639 } 640 641 if (!pdb_getgrsid(map, *sid)) { 642 status = NT_STATUS_NO_SUCH_ALIAS; 643 goto done; 644 } 645 646 map->nt_name = talloc_strdup(map, info->acct_name); 647 if (!map->nt_name) { 648 status = NT_STATUS_NO_MEMORY; 649 goto done; 650 } 651 map->comment = talloc_strdup(map, info->acct_desc); 652 if (!map->comment) { 653 status = NT_STATUS_NO_MEMORY; 654 goto done; 655 } 656 657 status = pdb_update_group_mapping_entry(map); 658 659 done: 660 TALLOC_FREE(map); 661 return status; 571 662 } 572 663 … … 608 699 const struct dom_sid *members, 609 700 size_t num_members, 610 uint32 **pp_alias_rids,701 uint32_t **pp_alias_rids, 611 702 size_t *p_num_alias_rids) 612 703 { … … 636 727 } 637 728 638 *pp_alias_rids = TALLOC_ARRAY(mem_ctx, uint32, num_alias_sids);729 *pp_alias_rids = talloc_array(mem_ctx, uint32_t, num_alias_sids); 639 730 if (*pp_alias_rids == NULL) 640 731 return NT_STATUS_NO_MEMORY; … … 700 791 } 701 792 702 /**************************************************************************** 703 These need to be redirected through pdb_interface.c 704 ****************************************************************************/ 705 bool pdb_get_dom_grp_info(const struct dom_sid *sid, struct acct_info *info) 706 { 707 GROUP_MAP map; 708 bool res; 709 710 become_root(); 711 res = get_domain_group_from_sid(*sid, &map); 712 unbecome_root(); 713 714 if (!res) 715 return False; 716 717 fstrcpy(info->acct_name, map.nt_name); 718 fstrcpy(info->acct_desc, map.comment); 719 sid_peek_rid(sid, &info->rid); 720 return True; 721 } 722 723 bool pdb_set_dom_grp_info(const struct dom_sid *sid, const struct acct_info *info) 724 { 725 GROUP_MAP map; 726 727 if (!get_domain_group_from_sid(*sid, &map)) 728 return False; 729 730 fstrcpy(map.nt_name, info->acct_name); 731 fstrcpy(map.comment, info->acct_desc); 732 733 return NT_STATUS_IS_OK(pdb_update_group_mapping_entry(&map)); 734 } 735 736 /******************************************************************** 737 Really just intended to be called by smbd 738 ********************************************************************/ 739 740 NTSTATUS pdb_create_builtin_alias(uint32 rid) 793 /** 794 * @brief Add a new group mapping 795 * 796 * @param[in] gid gid to use to store the mapping. If gid is 0, 797 * new gid will be allocated from winbind 798 * 799 * @return Normal NTSTATUS return 800 */ 801 NTSTATUS pdb_create_builtin_alias(uint32_t rid, gid_t gid) 741 802 { 742 803 struct dom_sid sid; 743 804 enum lsa_SidType type; 744 gid_t gid; 745 GROUP_MAP map; 746 TALLOC_CTX *mem_ctx; 805 gid_t gidformap; 806 GROUP_MAP *map; 747 807 NTSTATUS status; 748 808 const char *name = NULL; 749 fstring groupname;750 809 751 810 DEBUG(10, ("Trying to create builtin alias %d\n", rid)); … … 755 814 } 756 815 757 if ( (mem_ctx = talloc_new(NULL)) == NULL ) { 816 /* use map as overall temp mem context */ 817 map = talloc_zero(NULL, GROUP_MAP); 818 if (!map) { 758 819 return NT_STATUS_NO_MEMORY; 759 820 } 760 821 761 if ( !lookup_sid(mem_ctx, &sid, NULL, &name, &type) ) { 762 TALLOC_FREE( mem_ctx ); 763 return NT_STATUS_NO_SUCH_ALIAS; 764 } 765 766 /* validate RID so copy the name and move on */ 767 768 fstrcpy( groupname, name ); 769 TALLOC_FREE( mem_ctx ); 770 771 if (!winbind_allocate_gid(&gid)) { 772 DEBUG(3, ("pdb_create_builtin_alias: Could not get a gid out of winbind\n")); 773 return NT_STATUS_ACCESS_DENIED; 774 } 775 776 DEBUG(10,("Creating alias %s with gid %u\n", groupname, (unsigned int)gid)); 777 778 map.gid = gid; 779 sid_copy(&map.sid, &sid); 780 map.sid_name_use = SID_NAME_ALIAS; 781 fstrcpy(map.nt_name, groupname); 782 fstrcpy(map.comment, ""); 783 784 status = pdb_add_group_mapping_entry(&map); 822 if (!lookup_sid(map, &sid, NULL, &name, &type)) { 823 status = NT_STATUS_NO_SUCH_ALIAS; 824 goto done; 825 } 826 827 if (gid == 0) { 828 if (!winbind_allocate_gid(&gidformap)) { 829 DEBUG(3, ("pdb_create_builtin_alias: Could not get a " 830 "gid out of winbind\n")); 831 status = NT_STATUS_ACCESS_DENIED; 832 goto done; 833 } 834 } else { 835 gidformap = gid; 836 } 837 838 DEBUG(10, ("Creating alias %s with gid %u\n", name, 839 (unsigned) gidformap)); 840 841 map->gid = gidformap; 842 sid_copy(&map->sid, &sid); 843 map->sid_name_use = SID_NAME_ALIAS; 844 map->nt_name = talloc_strdup(map, name); 845 if (!map->nt_name) { 846 status = NT_STATUS_NO_MEMORY; 847 goto done; 848 } 849 map->comment = talloc_strdup(map, ""); 850 if (!map->comment) { 851 status = NT_STATUS_NO_MEMORY; 852 goto done; 853 } 854 855 status = pdb_add_group_mapping_entry(map); 785 856 786 857 if (!NT_STATUS_IS_OK(status)) { … … 789 860 } 790 861 862 done: 863 TALLOC_FREE(map); 791 864 return status; 792 865 }
Note:
See TracChangeset
for help on using the changeset viewer.