Changeset 988 for vendor/current/source3/groupdb
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- Location:
- vendor/current/source3/groupdb
- Files:
-
- 1 added
- 1 deleted
- 3 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 } -
vendor/current/source3/groupdb/mapping.h
r740 r988 46 46 bool (*group_map_remove)(const struct dom_sid *sid); 47 47 bool (*enum_group_mapping)(const struct dom_sid *domsid, enum lsa_SidType sid_name_use, 48 GROUP_MAP ** pp_rmap,48 GROUP_MAP ***pp_rmap, 49 49 size_t *p_num_entries, bool unix_only); 50 50 NTSTATUS (*one_alias_membership)(const struct dom_sid *member, -
vendor/current/source3/groupdb/mapping_tdb.c
r740 r988 25 25 #include "passdb.h" 26 26 #include "groupdb/mapping.h" 27 #include "dbwrap.h" 27 #include "dbwrap/dbwrap.h" 28 #include "dbwrap/dbwrap_open.h" 28 29 #include "util_tdb.h" 29 30 #include "../libcli/security/security.h" 31 #include "groupdb/mapping_tdb.h" 30 32 31 33 static struct db_context *db; /* used for driver files */ … … 33 35 static bool enum_group_mapping(const struct dom_sid *domsid, 34 36 enum lsa_SidType sid_name_use, 35 GROUP_MAP ** pp_rmap,37 GROUP_MAP ***pp_rmap, 36 38 size_t *p_num_entries, 37 39 bool unix_only); … … 45 47 static bool init_group_mapping(void) 46 48 { 47 const char *ldb_path; 49 char *tdb_path; 50 char *ldb_path; 48 51 49 52 if (db != NULL) { … … 51 54 } 52 55 53 db = db_open(NULL, state_path("group_mapping.tdb"), 0, 54 TDB_DEFAULT, O_RDWR|O_CREAT, 0600); 56 tdb_path = state_path("group_mapping.tdb"); 57 if (tdb_path == NULL) { 58 return false; 59 } 60 db = db_open(NULL, tdb_path, 0, 61 TDB_DEFAULT, O_RDWR|O_CREAT, 0600, 62 DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE); 55 63 if (db == NULL) { 56 64 DEBUG(0, ("Failed to open group mapping database: %s\n", 57 65 strerror(errno))); 66 talloc_free(tdb_path); 58 67 return false; 59 68 } 60 69 61 70 ldb_path = state_path("group_mapping.ldb"); 71 if (ldb_path == NULL) { 72 talloc_free(tdb_path); 73 return false; 74 } 62 75 if (file_exist(ldb_path) && !mapping_switch(ldb_path)) { 63 unlink(state_path("group_mapping.tdb")); 76 unlink(tdb_path); 77 talloc_free(tdb_path); 78 talloc_free(ldb_path); 64 79 return false; 65 80 … … 87 102 } 88 103 89 /* if its an unknown version we remove ever thing in the db */104 /* if its an unknown version we remove everything in the db */ 90 105 91 106 if (vers_id != DATABASE_VERSION_V2) { … … 112 127 #endif 113 128 } 129 talloc_free(tdb_path); 130 talloc_free(ldb_path); 114 131 return true; 115 132 } … … 117 134 static char *group_mapping_key(TALLOC_CTX *mem_ctx, const struct dom_sid *sid) 118 135 { 119 char *sidstr, *result; 120 121 sidstr = sid_string_talloc(talloc_tos(), sid); 122 if (sidstr == NULL) { 136 char sidstr[DOM_SID_STR_BUFLEN]; 137 int len; 138 139 len = dom_sid_string_buf(sid, sidstr, sizeof(sidstr)); 140 if (len >= sizeof(sidstr)) { 123 141 return NULL; 124 142 } 125 143 126 result = talloc_asprintf(mem_ctx, "%s%s", GROUP_PREFIX, sidstr); 127 128 TALLOC_FREE(sidstr); 129 return result; 144 return talloc_asprintf(mem_ctx, "%s%s", GROUP_PREFIX, sidstr); 130 145 } 131 146 … … 146 161 map->gid, map->sid_name_use, map->nt_name, map->comment); 147 162 148 buf = TALLOC_ARRAY(key, char, len);163 buf = talloc_array(key, char, len); 149 164 if (!buf) { 150 165 TALLOC_FREE(key); 151 166 return false; 152 167 } 153 len = tdb_pack((uint8 *)buf, len, "ddff", map->gid,168 len = tdb_pack((uint8_t *)buf, len, "ddff", map->gid, 154 169 map->sid_name_use, map->nt_name, map->comment); 155 170 … … 173 188 char *key; 174 189 int ret = 0; 190 NTSTATUS status; 191 fstring nt_name; 192 fstring comment; 175 193 176 194 /* the key is the SID, retrieving is direct */ … … 181 199 } 182 200 183 dbuf = dbwrap_fetch_bystring(db, key, key);184 if ( dbuf.dptr == NULL) {201 status = dbwrap_fetch_bystring(db, key, key, &dbuf); 202 if (!NT_STATUS_IS_OK(status)) { 185 203 TALLOC_FREE(key); 186 204 return false; … … 189 207 ret = tdb_unpack(dbuf.dptr, dbuf.dsize, "ddff", 190 208 &map->gid, &map->sid_name_use, 191 & map->nt_name, &map->comment);209 &nt_name, &comment); 192 210 193 211 TALLOC_FREE(key); … … 200 218 sid_copy(&map->sid, &sid); 201 219 220 map->nt_name = talloc_strdup(map, nt_name); 221 if (!map->nt_name) { 222 return false; 223 } 224 map->comment = talloc_strdup(map, comment); 225 if (!map->comment) { 226 return false; 227 } 228 202 229 return true; 203 230 } … … 205 232 static bool dbrec2map(const struct db_record *rec, GROUP_MAP *map) 206 233 { 207 if ((rec->key.dsize < strlen(GROUP_PREFIX)) 208 || (strncmp((char *)rec->key.dptr, GROUP_PREFIX, 234 TDB_DATA key = dbwrap_record_get_key(rec); 235 TDB_DATA value = dbwrap_record_get_value(rec); 236 int ret = 0; 237 fstring nt_name; 238 fstring comment; 239 240 if ((key.dsize < strlen(GROUP_PREFIX)) 241 || (strncmp((char *)key.dptr, GROUP_PREFIX, 209 242 GROUP_PREFIX_LEN) != 0)) { 210 243 return False; 211 244 } 212 245 213 if (!string_to_sid(&map->sid, (const char *) rec->key.dptr246 if (!string_to_sid(&map->sid, (const char *)key.dptr 214 247 + GROUP_PREFIX_LEN)) { 215 248 return False; 216 249 } 217 250 218 return tdb_unpack(rec->value.dptr, rec->value.dsize, "ddff", 219 &map->gid, &map->sid_name_use, &map->nt_name, 220 &map->comment) != -1; 251 ret = tdb_unpack(value.dptr, value.dsize, "ddff", 252 &map->gid, &map->sid_name_use, 253 &nt_name, &comment); 254 255 if (ret == -1) { 256 DEBUG(3, ("dbrec2map: tdb_unpack failure\n")); 257 return false; 258 } 259 260 map->nt_name = talloc_strdup(map, nt_name); 261 if (!map->nt_name) { 262 return false; 263 } 264 map->comment = talloc_strdup(map, comment); 265 if (!map->comment) { 266 return false; 267 } 268 269 return true; 221 270 } 222 271 … … 266 315 state.map = map; 267 316 268 db ->traverse_read(db, find_map, (void *)&state);317 dbwrap_traverse_read(db, find_map, (void *)&state, NULL); 269 318 270 319 return state.found; … … 283 332 state.map = map; 284 333 285 db ->traverse_read(db, find_map, (void *)&state);334 dbwrap_traverse_read(db, find_map, (void *)&state, NULL); 286 335 287 336 return state.found; … … 318 367 319 368 size_t num_maps; 320 GROUP_MAP * maps;369 GROUP_MAP **maps; 321 370 }; 322 371 … … 324 373 { 325 374 struct enum_map_state *state = (struct enum_map_state *)private_data; 326 GROUP_MAP map; 327 GROUP_MAP *tmp; 328 329 if (!dbrec2map(rec, &map)) { 375 GROUP_MAP *map; 376 GROUP_MAP **tmp; 377 378 map = talloc_zero(NULL, GROUP_MAP); 379 if (!map) { 380 DEBUG(0, ("Unable to allocate group map!\n")); 381 return 1; 382 } 383 384 if (!dbrec2map(rec, map)) { 385 TALLOC_FREE(map); 330 386 return 0; 331 387 } 332 388 /* list only the type or everything if UNKNOWN */ 333 389 if (state->sid_name_use != SID_NAME_UNKNOWN 334 && state->sid_name_use != map .sid_name_use) {390 && state->sid_name_use != map->sid_name_use) { 335 391 DEBUG(11,("enum_group_mapping: group %s is not of the " 336 "requested type\n", map.nt_name)); 392 "requested type\n", map->nt_name)); 393 TALLOC_FREE(map); 337 394 return 0; 338 395 } 339 396 340 if ((state->unix_only == ENUM_ONLY_MAPPED) && (map .gid == -1)) {397 if ((state->unix_only == ENUM_ONLY_MAPPED) && (map->gid == -1)) { 341 398 DEBUG(11,("enum_group_mapping: group %s is non mapped\n", 342 map.nt_name)); 399 map->nt_name)); 400 TALLOC_FREE(map); 343 401 return 0; 344 402 } 345 403 346 404 if ((state->domsid != NULL) && 347 (dom_sid_compare_domain(state->domsid, &map .sid) != 0)) {405 (dom_sid_compare_domain(state->domsid, &map->sid) != 0)) { 348 406 DEBUG(11,("enum_group_mapping: group %s is not in domain\n", 349 sid_string_dbg(&map.sid))); 407 sid_string_dbg(&map->sid))); 408 TALLOC_FREE(map); 350 409 return 0; 351 410 } 352 411 353 if (!(tmp = SMB_REALLOC_ARRAY(state->maps, GROUP_MAP, 354 state->num_maps+1))) { 412 tmp = talloc_realloc(NULL, state->maps, GROUP_MAP *, 413 state->num_maps + 1); 414 if (!tmp) { 355 415 DEBUG(0,("enum_group_mapping: Unable to enlarge group " 356 416 "map!\n")); 417 TALLOC_FREE(map); 357 418 return 1; 358 419 } 359 420 360 421 state->maps = tmp; 361 state->maps[state->num_maps] = map;422 state->maps[state->num_maps] = talloc_move(state->maps, &map); 362 423 state->num_maps++; 363 424 return 0; … … 366 427 static bool enum_group_mapping(const struct dom_sid *domsid, 367 428 enum lsa_SidType sid_name_use, 368 GROUP_MAP ** pp_rmap,429 GROUP_MAP ***pp_rmap, 369 430 size_t *p_num_entries, bool unix_only) 370 431 { 371 432 struct enum_map_state state; 433 NTSTATUS status; 372 434 373 435 state.domsid = domsid; … … 377 439 state.maps = NULL; 378 440 379 if (db->traverse_read(db, collect_map, (void *)&state) < 0) { 441 status = dbwrap_traverse_read(db, collect_map, (void *)&state, NULL); 442 if (!NT_STATUS_IS_OK(status)) { 443 TALLOC_FREE(state.maps); 380 444 return false; 381 445 } … … 404 468 sid_to_fstring(tmp, member)); 405 469 406 dbuf = dbwrap_fetch_bystring(db, frame, key);407 if ( dbuf.dptr == NULL) {470 status = dbwrap_fetch_bystring(db, frame, key, &dbuf); 471 if (!NT_STATUS_IS_OK(status)) { 408 472 TALLOC_FREE(frame); 409 473 return NT_STATUS_OK; … … 472 536 static NTSTATUS add_aliasmem(const struct dom_sid *alias, const struct dom_sid *member) 473 537 { 474 GROUP_MAP map;538 GROUP_MAP *map; 475 539 char *key; 476 540 fstring string_sid; … … 478 542 struct db_record *rec; 479 543 NTSTATUS status; 480 481 if (!get_group_map_from_sid(*alias, &map)) 544 TDB_DATA value; 545 546 map = talloc_zero(talloc_tos(), GROUP_MAP); 547 if (!map) { 548 return NT_STATUS_NO_MEMORY; 549 } 550 551 if (!get_group_map_from_sid(*alias, map)) { 552 TALLOC_FREE(map); 482 553 return NT_STATUS_NO_SUCH_ALIAS; 483 484 if ( (map.sid_name_use != SID_NAME_ALIAS) && 485 (map.sid_name_use != SID_NAME_WKN_GRP) ) 554 } 555 556 if ((map->sid_name_use != SID_NAME_ALIAS) && 557 (map->sid_name_use != SID_NAME_WKN_GRP)) { 558 TALLOC_FREE(map); 486 559 return NT_STATUS_NO_SUCH_ALIAS; 560 } 561 562 TALLOC_FREE(map); 487 563 488 564 if (is_aliasmem(alias, member)) … … 497 573 } 498 574 499 if (db ->transaction_start(db) != 0) {575 if (dbwrap_transaction_start(db) != 0) { 500 576 DEBUG(0, ("transaction_start failed\n")); 501 577 return NT_STATUS_INTERNAL_DB_CORRUPTION; 502 578 } 503 579 504 rec = db ->fetch_locked(db, key, string_term_tdb_data(key));580 rec = dbwrap_fetch_locked(db, key, string_term_tdb_data(key)); 505 581 506 582 if (rec == NULL) { … … 511 587 } 512 588 589 value = dbwrap_record_get_value(rec); 590 513 591 sid_to_fstring(string_sid, alias); 514 592 515 if ( rec->value.dptr != NULL) {593 if (value.dptr != NULL) { 516 594 new_memberstring = talloc_asprintf( 517 key, "%s %s", (char *)( rec->value.dptr), string_sid);595 key, "%s %s", (char *)(value.dptr), string_sid); 518 596 } else { 519 597 new_memberstring = talloc_strdup(key, string_sid); … … 526 604 } 527 605 528 status = rec->store(rec, string_term_tdb_data(new_memberstring), 0);606 status = dbwrap_record_store(rec, string_term_tdb_data(new_memberstring), 0); 529 607 530 608 TALLOC_FREE(key); … … 535 613 } 536 614 537 if (db ->transaction_commit(db) != 0) {615 if (dbwrap_transaction_commit(db) != 0) { 538 616 DEBUG(0, ("transaction_commit failed\n")); 539 617 status = NT_STATUS_INTERNAL_DB_CORRUPTION; … … 544 622 545 623 cancel: 546 if (db ->transaction_cancel(db) != 0) {624 if (dbwrap_transaction_cancel(db) != 0) { 547 625 smb_panic("transaction_cancel failed"); 548 626 } … … 564 642 char *alias_string; 565 643 TALLOC_CTX *frame; 566 567 if (strncmp((const char *)rec->key.dptr, MEMBEROF_PREFIX, 644 TDB_DATA key = dbwrap_record_get_key(rec); 645 TDB_DATA value = dbwrap_record_get_value(rec); 646 647 if (strncmp((const char *)key.dptr, MEMBEROF_PREFIX, 568 648 MEMBEROF_PREFIX_LEN) != 0) 569 649 return 0; 570 650 571 p = (const char *) rec->value.dptr;651 p = (const char *)value.dptr; 572 652 573 653 frame = talloc_stackframe(); … … 588 668 * member. Add that. */ 589 669 590 member_string = strchr((const char *) rec->key.dptr, '/');670 member_string = strchr((const char *)key.dptr, '/'); 591 671 592 672 /* Above we tested for MEMBEROF_PREFIX which includes the … … 617 697 struct dom_sid **sids, size_t *num) 618 698 { 619 GROUP_MAP map;699 GROUP_MAP *map; 620 700 struct aliasmem_state state; 621 701 622 if (!get_group_map_from_sid(*alias, &map)) 702 map = talloc_zero(talloc_tos(), GROUP_MAP); 703 if (!map) { 704 return NT_STATUS_NO_MEMORY; 705 } 706 707 if (!get_group_map_from_sid(*alias, map)) { 708 TALLOC_FREE(map); 623 709 return NT_STATUS_NO_SUCH_ALIAS; 624 625 if ( (map.sid_name_use != SID_NAME_ALIAS) && 626 (map.sid_name_use != SID_NAME_WKN_GRP) ) 710 } 711 712 if ((map->sid_name_use != SID_NAME_ALIAS) && 713 (map->sid_name_use != SID_NAME_WKN_GRP)) { 714 TALLOC_FREE(map); 627 715 return NT_STATUS_NO_SUCH_ALIAS; 716 } 717 718 TALLOC_FREE(map); 628 719 629 720 *sids = NULL; … … 635 726 state.mem_ctx = mem_ctx; 636 727 637 db ->traverse_read(db, collect_aliasmem, &state);728 dbwrap_traverse_read(db, collect_aliasmem, &state, NULL); 638 729 return NT_STATUS_OK; 639 730 } … … 649 740 fstring sid_string; 650 741 651 if (db ->transaction_start(db) != 0) {742 if (dbwrap_transaction_start(db) != 0) { 652 743 DEBUG(0, ("transaction_start failed\n")); 653 744 return NT_STATUS_INTERNAL_DB_CORRUPTION; … … 724 815 } 725 816 726 if (db ->transaction_commit(db) != 0) {817 if (dbwrap_transaction_commit(db) != 0) { 727 818 DEBUG(0, ("transaction_commit failed\n")); 728 819 status = NT_STATUS_INTERNAL_DB_CORRUPTION; … … 733 824 734 825 cancel: 735 if (db ->transaction_cancel(db) != 0) {826 if (dbwrap_transaction_cancel(db) != 0) { 736 827 smb_panic("transaction_cancel failed"); 737 828 } … … 762 853 { 763 854 TALLOC_CTX *tmp_ctx = talloc_tos(); 764 GROUP_MAP map;855 GROUP_MAP *map = NULL; 765 856 uint8_t *p; 766 857 uint32_t format; … … 827 918 } 828 919 829 ZERO_STRUCT(map); 920 map = talloc_zero(NULL, GROUP_MAP); 921 if (!map) { 922 errno = ENOMEM; 923 goto failed; 924 } 830 925 831 926 for (i = 0; i < num_el; i++) { … … 850 945 851 946 num_vals = pull_uint32(p, 0); 852 if ( StrCaseCmp(name, "member") == 0) {947 if (strcasecmp_m(name, "member") == 0) { 853 948 num_mem = num_vals; 854 949 members = talloc_array(tmp_ctx, struct dom_sid, num_mem); … … 883 978 /* we ignore unknown or uninteresting attributes 884 979 * (objectclass, etc.) */ 885 if ( StrCaseCmp(name, "gidNumber") == 0) {886 map .gid = strtoul(val, &q, 10);980 if (strcasecmp_m(name, "gidNumber") == 0) { 981 map->gid = strtoul(val, &q, 10); 887 982 if (*q) { 888 983 errno = EIO; 889 984 goto failed; 890 985 } 891 } else if ( StrCaseCmp(name, "sid") == 0) {892 if (!string_to_sid(&map .sid, val)) {986 } else if (strcasecmp_m(name, "sid") == 0) { 987 if (!string_to_sid(&map->sid, val)) { 893 988 errno = EIO; 894 989 goto failed; 895 990 } 896 } else if ( StrCaseCmp(name, "sidNameUse") == 0) {897 map .sid_name_use = strtoul(val, &q, 10);991 } else if (strcasecmp_m(name, "sidNameUse") == 0) { 992 map->sid_name_use = strtoul(val, &q, 10); 898 993 if (*q) { 899 994 errno = EIO; 900 995 goto failed; 901 996 } 902 } else if (StrCaseCmp(name, "ntname") == 0) { 903 strlcpy(map.nt_name, val, 904 sizeof(map.nt_name)); 905 } else if (StrCaseCmp(name, "comment") == 0) { 906 strlcpy(map.comment, val, 907 sizeof(map.comment)); 908 } else if (StrCaseCmp(name, "member") == 0) { 997 } else if (strcasecmp_m(name, "ntname") == 0) { 998 map->nt_name = talloc_strdup(map, val); 999 if (!map->nt_name) { 1000 errno = ENOMEM; 1001 goto failed; 1002 } 1003 } else if (strcasecmp_m(name, "comment") == 0) { 1004 map->comment = talloc_strdup(map, val); 1005 if (!map->comment) { 1006 errno = ENOMEM; 1007 goto failed; 1008 } 1009 } else if (strcasecmp_m(name, "member") == 0) { 909 1010 if (!string_to_sid(&members[j], val)) { 910 1011 errno = EIO; … … 919 1020 } 920 1021 921 if (!add_mapping_entry(&map, 0)) { 1022 if (map->nt_name == NULL) { 1023 errno = EIO; 1024 goto failed; 1025 } 1026 1027 if (map->comment == NULL) { 1028 map->comment = talloc_strdup(map, ""); 1029 } 1030 if (map->comment == NULL) { 1031 errno = ENOMEM; 1032 goto failed; 1033 } 1034 1035 if (!add_mapping_entry(map, 0)) { 922 1036 errno = EIO; 923 1037 goto failed; … … 927 1041 for (j = 0; j < num_mem; j++) { 928 1042 NTSTATUS status; 929 status = add_aliasmem(&map .sid, &members[j]);1043 status = add_aliasmem(&map->sid, &members[j]); 930 1044 if (!NT_STATUS_IS_OK(status)) { 931 1045 errno = EIO; … … 940 1054 } 941 1055 1056 TALLOC_FREE(map); 942 1057 return 0; 943 1058 944 1059 failed: 1060 TALLOC_FREE(map); 945 1061 return -1; 946 1062 } … … 961 1077 * conversion */ 962 1078 ret = tdb_traverse(ltdb, convert_ldb_record, NULL); 963 if (ret == -1) goto failed;1079 if (ret < 0) goto failed; 964 1080 965 1081 if (ltdb) {
Note:
See TracChangeset
for help on using the changeset viewer.