Changeset 988 for vendor/current/source3/passdb/pdb_interface.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
-
vendor/current/source3/passdb/pdb_interface.c (modified) (57 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/passdb/pdb_interface.c
r746 r988 25 25 #include "passdb.h" 26 26 #include "secrets.h" 27 27 28 #include "../librpc/gen_ndr/samr.h" 28 #include "memcache.h" 29 #include "../librpc/gen_ndr/drsblobs.h" 30 #include "../librpc/gen_ndr/ndr_drsblobs.h" 31 #include "../librpc/gen_ndr/idmap.h" 32 #include "../lib/util/memcache.h" 29 33 #include "nsswitch/winbind_client.h" 30 34 #include "../libcli/security/security.h" 31 35 #include "../lib/util/util_pw.h" 36 37 38 32 39 33 40 #undef DBGC_CLASS … … 48 55 } 49 56 50 static bool lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid,57 static bool lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid, 51 58 const char **name, 52 59 enum lsa_SidType *psid_name_use, 53 u nion unid_t *unix_id);60 uid); 54 61 55 62 NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function init) … … 97 104 return NULL; 98 105 } 106 107 108 109 110 111 99 112 100 113 /* … … 108 121 */ 109 122 110 static struct event_context *pdb_event_ctx;111 112 struct event_context *pdb_get_event_context(void)113 { 114 return pdb_ event_ctx;123 static struct event_ctx; 124 125 struct event_context(void) 126 { 127 return pdb_event_ctx; 115 128 } 116 129 … … 189 202 } 190 203 if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) { 191 char *msg = NULL; 192 if (asprintf(&msg, "pdb_get_methods_reload: " 193 "failed to get pdb methods for backend %s\n", 194 lp_passdb_backend()) > 0) { 195 smb_panic(msg); 196 } else { 197 smb_panic("pdb_get_methods_reload"); 198 } 204 return NULL; 199 205 } 200 206 } … … 202 208 if ( !pdb ) { 203 209 if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) { 204 char *msg = NULL; 205 if (asprintf(&msg, "pdb_get_methods_reload: " 206 "failed to get pdb methods for backend %s\n", 207 lp_passdb_backend()) > 0) { 208 smb_panic(msg); 209 } else { 210 smb_panic("pdb_get_methods_reload"); 211 } 210 return NULL; 212 211 } 213 212 } … … 218 217 static struct pdb_methods *pdb_get_methods(void) 219 218 { 220 return pdb_get_methods_reload(False); 219 struct pdb_methods *pdb; 220 221 pdb = pdb_get_methods_reload(false); 222 if (!pdb) { 223 char *msg = NULL; 224 if (asprintf(&msg, "pdb_get_methods: " 225 "failed to get pdb methods for backend %s\n", 226 lp_passdb_backend()) > 0) { 227 smb_panic(msg); 228 } else { 229 smb_panic("pdb_get_methods"); 230 } 231 } 232 233 return pdb; 221 234 } 222 235 … … 356 369 struct passwd *pwd; 357 370 NTSTATUS result; 358 const char *guestname = lp_guest account();371 const char *guestname = lp_guestaccount(); 359 372 360 373 pwd = Get_Pwnam_alloc(talloc_tos(), guestname); … … 448 461 449 462 if ((acb_info & ACB_NORMAL) && name[strlen(name)-1] != '$') { 450 add_script = talloc_strdup(tmp_ctx, 451 lp_adduser_script()); 463 add_script = lp_add_user_script(tmp_ctx); 452 464 } else { 453 add_script = talloc_strdup(tmp_ctx, 454 lp_addmachine_script()); 465 add_script = lp_add_machine_script(tmp_ctx); 455 466 } 456 467 … … 464 475 compatibility with previous Samba releases */ 465 476 fstrcpy( name2, name ); 466 strlower_m( name2 ); 477 if (!strlower_m( name2 )) { 478 return NT_STATUS_INVALID_PARAMETER; 479 } 467 480 add_script = talloc_all_string_sub(tmp_ctx, 468 481 add_script, … … 491 504 /* we have a valid SID coming out of this call */ 492 505 493 status = samu_alloc_rid_unix( sam_pass, pwd);506 status = samu_alloc_rid_unix(); 494 507 495 508 TALLOC_FREE( pwd ); … … 516 529 pdb_set_acct_ctrl(sam_pass, acb_info, PDB_CHANGED); 517 530 518 status = pdb_add_sam_account(sam_pass);531 status = sam_pass); 519 532 520 533 TALLOC_FREE(sam_pass); … … 546 559 } 547 560 548 del_script = talloc_strdup(talloc_tos(), lp_deluser_script());561 del_script = ()); 549 562 if (!del_script || !*del_script) { 550 563 return -1; … … 574 587 fstring username; 575 588 576 status = pdb_delete_sam_account(sam_acct);589 status = sam_acct); 577 590 if (!NT_STATUS_IS_OK(status)) { 578 591 return status; … … 590 603 591 604 fstrcpy( username, pdb_get_username(sam_acct) ); 592 strlower_m( username ); 605 if (!strlower_m( username )) { 606 return status; 607 } 593 608 594 609 smb_delete_user( username ); … … 601 616 struct pdb_methods *pdb = pdb_get_methods(); 602 617 uid_t uid = -1; 618 619 620 621 622 603 623 604 624 /* sanity check to make sure we don't delete root */ 605 625 606 if ( !sid_to_uid( pdb_get_user_sid(sam_acct), &uid ) ) {626 if ( !sid_to_uid(, &uid ) ) { 607 627 return NT_STATUS_NO_SUCH_USER; 608 628 } … … 612 632 } 613 633 614 return pdb->delete_user(pdb, mem_ctx, sam_acct); 634 memcache_delete(NULL, 635 PDB_GETPWSID_CACHE, 636 data_blob_const(user_sid, sizeof(*user_sid))); 637 638 status = pdb->delete_user(pdb, mem_ctx, sam_acct); 639 if (!NT_STATUS_IS_OK(status)) { 640 return status; 641 } 642 643 msg_data = talloc_asprintf(mem_ctx, "USER %s", 644 pdb_get_username(sam_acct)); 645 if (!msg_data) { 646 /* not fatal, and too late to rollback, 647 * just return */ 648 return status; 649 } 650 message_send_all(server_messaging_context(), 651 ID_CACHE_DELETE, 652 msg_data, 653 strlen(msg_data) + 1, 654 NULL); 655 656 TALLOC_FREE(msg_data); 657 return status; 615 658 } 616 659 … … 633 676 { 634 677 struct pdb_methods *pdb = pdb_get_methods(); 635 636 memcache_flush(NULL, PDB_GETPWSID_CACHE); 678 const struct dom_sid *user_sid = pdb_get_user_sid(sam_acct); 679 680 memcache_delete(NULL, 681 PDB_GETPWSID_CACHE, 682 data_blob_const(user_sid, sizeof(*user_sid))); 637 683 638 684 return pdb->delete_sam_account(pdb, sam_acct); … … 740 786 { 741 787 struct dom_sid group_sid; 742 GROUP_MAP map;788 GROUP_MAP map; 743 789 NTSTATUS status; 744 790 struct group *grp; 745 791 const char *grp_name; 746 792 793 794 795 796 797 747 798 /* coverity */ 748 map .gid = (gid_t) -1;799 mapgid = (gid_t) -1; 749 800 750 801 sid_compose(&group_sid, get_global_sam_sid(), rid); 751 802 752 if (!get_domain_group_from_sid(group_sid, &map)) {803 if (!get_domain_group_from_sid(group_sid, map)) { 753 804 DEBUG(10, ("Could not find group for rid %d\n", rid)); 754 805 return NT_STATUS_NO_SUCH_GROUP; … … 757 808 /* We need the group name for the smb_delete_group later on */ 758 809 759 if (map .gid == (gid_t)-1) {810 if (mapgid == (gid_t)-1) { 760 811 return NT_STATUS_NO_SUCH_GROUP; 761 812 } 762 813 763 grp = getgrgid(map .gid);814 grp = getgrgid(mapgid); 764 815 if (grp == NULL) { 765 816 return NT_STATUS_NO_SUCH_GROUP; 766 817 } 818 819 767 820 768 821 /* Copy the name, no idea what pdb_delete_group_mapping_entry does.. */ … … 810 863 } 811 864 812 bool pdb_enum_group_mapping(const struct dom_sid *sid, enum lsa_SidType sid_name_use, GROUP_MAP **pp_rmap, 813 size_t *p_num_entries, bool unix_only) 865 bool pdb_enum_group_mapping(const struct dom_sid *sid, 866 enum lsa_SidType sid_name_use, 867 GROUP_MAP ***pp_rmap, 868 size_t *p_num_entries, 869 bool unix_only) 814 870 { 815 871 struct pdb_methods *pdb = pdb_get_methods(); … … 917 973 struct dom_sid group_sid, member_sid; 918 974 struct samu *account = NULL; 919 GROUP_MAP map;975 GROUP_MAP map; 920 976 struct group *grp; 921 977 struct passwd *pwd; … … 923 979 uid_t uid; 924 980 981 982 983 984 985 925 986 /* coverity */ 926 map .gid = (gid_t) -1;987 mapgid = (gid_t) -1; 927 988 928 989 sid_compose(&group_sid, get_global_sam_sid(), group_rid); 929 990 sid_compose(&member_sid, get_global_sam_sid(), member_rid); 930 991 931 if (!get_domain_group_from_sid(group_sid, &map) ||932 (map .gid == (gid_t)-1) ||933 ((grp = getgrgid(map .gid)) == NULL)) {992 if (!get_domain_group_from_sid(group_sid, map) || 993 (mapgid == (gid_t)-1) || 994 ((grp = getgrgid(mapgid)) == NULL)) { 934 995 return NT_STATUS_NO_SUCH_GROUP; 935 996 } 997 998 936 999 937 1000 group_name = talloc_strdup(mem_ctx, grp->gr_name); … … 982 1045 struct dom_sid group_sid, member_sid; 983 1046 struct samu *account = NULL; 984 GROUP_MAP map;1047 GROUP_MAP map; 985 1048 struct group *grp; 986 1049 struct passwd *pwd; … … 988 1051 uid_t uid; 989 1052 1053 1054 1055 1056 1057 990 1058 sid_compose(&group_sid, get_global_sam_sid(), group_rid); 991 1059 sid_compose(&member_sid, get_global_sam_sid(), member_rid); 992 1060 993 if (!get_domain_group_from_sid(group_sid, &map) ||994 (map .gid == (gid_t)-1) ||995 ((grp = getgrgid(map .gid)) == NULL)) {1061 if (!get_domain_group_from_sid(group_sid, map) || 1062 (mapgid == (gid_t)-1) || 1063 ((grp = getgrgid(mapgid)) == NULL)) { 996 1064 return NT_STATUS_NO_SUCH_GROUP; 997 1065 } 1066 1067 998 1068 999 1069 group_name = talloc_strdup(mem_ctx, grp->gr_name); … … 1105 1175 } 1106 1176 1107 /*1108 * NOTE: pdb_lookup_names is currently (2007-01-12) not used anywhere1109 * in the samba code.1110 * Unlike _lsa_lookup_sids and _samr_lookup_rids, which eventually1111 * also ask pdb_lookup_rids, thus looking up a bunch of rids at a time,1112 * the pdb_ calls _lsa_lookup_names and _samr_lookup_names come1113 * down to are pdb_getsampwnam and pdb_getgrnam instead of1114 * pdb_lookup_names.1115 * But in principle, it the call belongs to the API and might get1116 * used in this context some day.1117 */1118 #if 01119 NTSTATUS pdb_lookup_names(const struct dom_sid *domain_sid,1120 int num_names,1121 const char **names,1122 uint32_t *rids,1123 enum lsa_SidType *attrs)1124 {1125 struct pdb_methods *pdb = pdb_get_methods();1126 return pdb->lookup_names(pdb, domain_sid, num_names, names, rids, attrs);1127 }1128 #endif1129 1130 1177 bool pdb_get_account_policy(enum pdb_policy_type type, uint32_t *value) 1131 1178 { … … 1158 1205 } 1159 1206 1160 bool pdb_uid_to_sid(uid_t uid, struct dom_sid *sid) 1161 { 1162 struct pdb_methods *pdb = pdb_get_methods(); 1163 return pdb->uid_to_sid(pdb, uid, sid); 1164 } 1165 1166 bool pdb_gid_to_sid(gid_t gid, struct dom_sid *sid) 1167 { 1168 struct pdb_methods *pdb = pdb_get_methods(); 1169 return pdb->gid_to_sid(pdb, gid, sid); 1170 } 1171 1172 bool pdb_sid_to_id(const struct dom_sid *sid, union unid_t *id, 1173 enum lsa_SidType *type) 1174 { 1175 struct pdb_methods *pdb = pdb_get_methods(); 1176 return pdb->sid_to_id(pdb, sid, id, type); 1207 /* 1208 * Instead of passing down a gid or uid, this function sends down a pointer 1209 * to a unixid. 1210 * 1211 * This acts as an in-out variable so that the idmap functions can correctly 1212 * receive ID_TYPE_BOTH, filling in cache details correctly rather than forcing 1213 * the cache to store ID_TYPE_UID or ID_TYPE_GID. 1214 */ 1215 bool pdb_id_to_sid(struct unixid *id, struct dom_sid *sid) 1216 { 1217 struct pdb_methods *pdb = pdb_get_methods(); 1218 bool ret; 1219 1220 ret = pdb->id_to_sid(pdb, id, sid); 1221 1222 if (ret == true) { 1223 idmap_cache_set_sid2unixid(sid, id); 1224 } 1225 1226 return ret; 1227 } 1228 1229 bool pdb_sid_to_id(const struct dom_sid *sid, struct unixid *id) 1230 { 1231 struct pdb_methods *pdb = pdb_get_methods(); 1232 bool ret; 1233 1234 /* only ask the backend if it is responsible */ 1235 if (!sid_check_object_is_for_passdb(sid)) { 1236 return false; 1237 } 1238 1239 ret = pdb->sid_to_id(pdb, sid, id); 1240 1241 if (ret == true) { 1242 idmap_cache_set_sid2unixid(sid, id); 1243 } 1244 1245 return ret; 1177 1246 } 1178 1247 … … 1231 1300 /* validate that the RID is not in use */ 1232 1301 1233 if ( lookup_global_sam_rid( ctx, allocated_rid, &name, &type, NULL )) {1302 if () { 1234 1303 allocated_rid = 0; 1235 1304 } … … 1254 1323 ***************************************************************/ 1255 1324 1256 bool initialize_password_db(bool reload, struct event_context *event_ctx) 1257 { 1258 pdb_event_ctx = event_ctx; 1325 bool initialize_password_db(bool reload, struct tevent_context *tevent_ctx) 1326 { 1327 if (tevent_ctx) { 1328 pdb_tevent_ctx = tevent_ctx; 1329 } 1259 1330 return (pdb_get_methods_reload(reload) != NULL); 1260 1331 } 1261 1262 1332 1263 1333 /*************************************************************************** … … 1325 1395 bool ret; 1326 1396 1327 unix_pw = sys_getpwuid( uid );1397 unix_pw = getpwuid( uid ); 1328 1398 1329 1399 if ( !unix_pw ) { … … 1360 1430 struct dom_sid *sid) 1361 1431 { 1362 GROUP_MAP map; 1363 1364 if (!NT_STATUS_IS_OK(methods->getgrgid(methods, &map, gid))) { 1365 return False; 1366 } 1367 1368 sid_copy(sid, &map.sid); 1369 return True; 1432 GROUP_MAP *map; 1433 1434 map = talloc_zero(NULL, GROUP_MAP); 1435 if (!map) { 1436 return false; 1437 } 1438 1439 if (!NT_STATUS_IS_OK(methods->getgrgid(methods, map, gid))) { 1440 TALLOC_FREE(map); 1441 return false; 1442 } 1443 1444 sid_copy(sid, &map->sid); 1445 TALLOC_FREE(map); 1446 return true; 1447 } 1448 1449 static bool pdb_default_id_to_sid(struct pdb_methods *methods, struct unixid *id, 1450 struct dom_sid *sid) 1451 { 1452 switch (id->type) { 1453 case ID_TYPE_UID: 1454 return pdb_default_uid_to_sid(methods, id->id, sid); 1455 1456 case ID_TYPE_GID: 1457 return pdb_default_gid_to_sid(methods, id->id, sid); 1458 1459 default: 1460 return false; 1461 } 1462 } 1463 /** 1464 * The "Unix User" and "Unix Group" domains have a special 1465 * id mapping that is a rid-algorithm with range starting at 0. 1466 */ 1467 bool pdb_sid_to_id_unix_users_and_groups(const struct dom_sid *sid, 1468 struct unixid *id) 1469 { 1470 uint32_t rid; 1471 1472 id->id = -1; 1473 1474 if (sid_peek_check_rid(&global_sid_Unix_Users, sid, &rid)) { 1475 id->id = rid; 1476 id->type = ID_TYPE_UID; 1477 return true; 1478 } 1479 1480 if (sid_peek_check_rid(&global_sid_Unix_Groups, sid, &rid)) { 1481 id->id = rid; 1482 id->type = ID_TYPE_GID; 1483 return true; 1484 } 1485 1486 return false; 1370 1487 } 1371 1488 1372 1489 static bool pdb_default_sid_to_id(struct pdb_methods *methods, 1373 1490 const struct dom_sid *sid, 1374 union unid_t *id, enum lsa_SidType *type)1491 ) 1375 1492 { 1376 1493 TALLOC_CTX *mem_ctx; 1377 1494 bool ret = False; 1378 const char *name;1379 1495 uint32_t rid; 1496 1380 1497 1381 1498 mem_ctx = talloc_new(NULL); … … 1387 1504 1388 1505 if (sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) { 1506 1507 1508 1509 1389 1510 /* Here we might have users as well as groups and aliases */ 1390 ret = lookup_global_sam_rid(mem_ctx, rid, &name, type, id); 1511 ret = lookup_global_sam_rid(mem_ctx, rid, &name, &type, &uid, &gid); 1512 if (ret) { 1513 switch (type) { 1514 case SID_NAME_DOM_GRP: 1515 case SID_NAME_ALIAS: 1516 id->type = ID_TYPE_GID; 1517 id->id = gid; 1518 break; 1519 case SID_NAME_USER: 1520 id->type = ID_TYPE_UID; 1521 id->id = uid; 1522 break; 1523 default: 1524 DEBUG(5, ("SID %s belongs to our domain, and " 1525 "an object exists in the database, " 1526 "but it is neither a user nor a " 1527 "group (got type %d).\n", 1528 sid_string_dbg(sid), type)); 1529 ret = false; 1530 } 1531 } else { 1532 DEBUG(5, ("SID %s belongs to our domain, but there is " 1533 "no corresponding object in the database.\n", 1534 sid_string_dbg(sid))); 1535 } 1391 1536 goto done; 1392 1537 } 1393 1538 1394 /* check for "Unix User" */ 1395 1396 if ( sid_peek_check_rid(&global_sid_Unix_Users, sid, &rid) ) { 1397 id->uid = rid; 1398 *type = SID_NAME_USER; 1399 ret = True; 1400 goto done; 1401 } 1402 1403 /* check for "Unix Group" */ 1404 1405 if ( sid_peek_check_rid(&global_sid_Unix_Groups, sid, &rid) ) { 1406 id->gid = rid; 1407 *type = SID_NAME_ALIAS; 1408 ret = True; 1409 goto done; 1539 /* 1540 * "Unix User" and "Unix Group" 1541 */ 1542 ret = pdb_sid_to_id_unix_users_and_groups(sid, id); 1543 if (ret == true) { 1544 goto done; 1410 1545 } 1411 1546 … … 1415 1550 sid_check_is_in_wellknown_domain(sid)) { 1416 1551 /* Here we only have aliases */ 1417 GROUP_MAP map; 1418 if (!NT_STATUS_IS_OK(methods->getgrsid(methods, &map, *sid))) { 1552 GROUP_MAP *map; 1553 1554 map = talloc_zero(mem_ctx, GROUP_MAP); 1555 if (!map) { 1556 ret = false; 1557 goto done; 1558 } 1559 1560 if (!NT_STATUS_IS_OK(methods->getgrsid(methods, map, *sid))) { 1419 1561 DEBUG(10, ("Could not find map for sid %s\n", 1420 1562 sid_string_dbg(sid))); 1421 1563 goto done; 1422 1564 } 1423 if ((map .sid_name_use != SID_NAME_ALIAS) &&1424 (map .sid_name_use != SID_NAME_WKN_GRP)) {1565 if ((mapsid_name_use != SID_NAME_ALIAS) && 1566 (mapsid_name_use != SID_NAME_WKN_GRP)) { 1425 1567 DEBUG(10, ("Map for sid %s is a %s, expected an " 1426 1568 "alias\n", sid_string_dbg(sid), 1427 sid_type_lookup(map .sid_name_use)));1569 sid_type_lookup(mapsid_name_use))); 1428 1570 goto done; 1429 1571 } 1430 1572 1431 id-> gid = map.gid;1432 *type = SID_NAME_ALIAS;1573 id->gid; 1574 ; 1433 1575 ret = True; 1434 1576 goto done; … … 1521 1663 return NT_STATUS_OK; 1522 1664 1523 *pp_member_rids = TALLOC_ZERO_ARRAY(mem_ctx, uint32_t, num_uids);1665 *pp_member_rids = (mem_ctx, uint32_t, num_uids); 1524 1666 1525 1667 for (i=0; i<num_uids; i++) { … … 1528 1670 uid_to_sid(&sid, uids[i]); 1529 1671 1530 if (!sid_check_is_in_our_ domain(&sid)) {1672 if (!sid_check_is_in_our_(&sid)) { 1531 1673 DEBUG(5, ("Inconsistent SAM -- group member uid not " 1532 1674 "in our domain\n")); … … 1573 1715 } 1574 1716 1575 *pp_sids = TALLOC_ARRAY(mem_ctx, struct dom_sid, *p_num_groups);1717 *pp_sids = (mem_ctx, struct dom_sid, *p_num_groups); 1576 1718 1577 1719 if (*pp_sids == NULL) { … … 1594 1736 const char **name, 1595 1737 enum lsa_SidType *psid_name_use, 1596 u nion unid_t *unix_id)1738 uid) 1597 1739 { 1598 1740 struct samu *sam_account = NULL; 1599 GROUP_MAP map;1741 GROUP_MAP ; 1600 1742 bool ret; 1601 1743 struct dom_sid sid; … … 1614 1756 } 1615 1757 1758 1759 1760 1761 1762 1616 1763 /* BEING ROOT BLOCK */ 1617 1764 become_root(); 1618 if (pdb_getsampwsid(sam_account, &sid)) { 1765 ret = pdb_getsampwsid(sam_account, &sid); 1766 if (!ret) { 1767 TALLOC_FREE(sam_account); 1768 ret = pdb_getgrsid(map, sid); 1769 } 1770 unbecome_root(); 1771 /* END BECOME_ROOT BLOCK */ 1772 1773 if (sam_account || !ret) { 1774 TALLOC_FREE(map); 1775 } 1776 1777 if (sam_account) { 1619 1778 struct passwd *pw; 1620 1779 1621 unbecome_root(); /* -----> EXIT BECOME_ROOT() */1622 1780 *name = talloc_strdup(mem_ctx, pdb_get_username(sam_account)); 1623 1781 if (!*name) { … … 1630 1788 TALLOC_FREE(sam_account); 1631 1789 1632 if (u nix_id == NULL) {1790 if (uid == NULL) { 1633 1791 return True; 1634 1792 } … … 1638 1796 return False; 1639 1797 } 1640 unix_id->uid = pw->pw_uid;1798 uid = pw->pw_uid; 1641 1799 TALLOC_FREE(pw); 1642 1800 return True; 1643 } 1644 TALLOC_FREE(sam_account); 1645 1646 ret = pdb_getgrsid(&map, sid); 1647 unbecome_root(); 1648 /* END BECOME_ROOT BLOCK */ 1649 1650 /* do not resolve SIDs to a name unless there is a valid 1651 gid associated with it */ 1652 1653 if ( ret && (map.gid != (gid_t)-1) ) { 1654 *name = talloc_strdup(mem_ctx, map.nt_name); 1655 *psid_name_use = map.sid_name_use; 1656 1657 if ( unix_id ) { 1658 unix_id->gid = map.gid; 1659 } 1660 1801 1802 } else if (map && (map->gid != (gid_t)-1)) { 1803 1804 /* do not resolve SIDs to a name unless there is a valid 1805 gid associated with it */ 1806 1807 *name = talloc_steal(mem_ctx, map->nt_name); 1808 *psid_name_use = map->sid_name_use; 1809 1810 if (gid) { 1811 *gid = map->gid; 1812 } 1813 1814 TALLOC_FREE(map); 1661 1815 return True; 1662 1816 } 1817 1818 1663 1819 1664 1820 /* Windows will always map RID 513 to something. On a non-domain 1665 1821 controller, this gets mapped to SERVER\None. */ 1666 1822 1667 if ( unix_id) {1823 if () { 1668 1824 DEBUG(5, ("Can't find a unix id for an unmapped group\n")); 1669 1825 return False; … … 1712 1868 1713 1869 /* Should not happen, but better check once too many */ 1714 if (!sid_check_is_ domain(domain_sid)) {1870 if (!sid_check_is_(domain_sid)) { 1715 1871 return NT_STATUS_INVALID_HANDLE; 1716 1872 } … … 1720 1876 1721 1877 if (lookup_global_sam_rid(names, rids[i], &name, &attrs[i], 1722 NULL )) {1878 NULL)) { 1723 1879 if (name == NULL) { 1724 1880 return NT_STATUS_NO_MEMORY; … … 1743 1899 } 1744 1900 1745 #if 01746 static NTSTATUS pdb_default_lookup_names(struct pdb_methods *methods,1747 const struct dom_sid *domain_sid,1748 int num_names,1749 const char **names,1750 uint32_t *rids,1751 enum lsa_SidType *attrs)1752 {1753 int i;1754 NTSTATUS result;1755 bool have_mapped = False;1756 bool have_unmapped = False;1757 1758 if (sid_check_is_builtin(domain_sid)) {1759 1760 for (i=0; i<num_names; i++) {1761 uint32_t rid;1762 1763 if (lookup_builtin_name(names[i], &rid)) {1764 attrs[i] = SID_NAME_ALIAS;1765 rids[i] = rid;1766 DEBUG(5,("lookup_rids: %s:%d\n",1767 names[i], attrs[i]));1768 have_mapped = True;1769 } else {1770 have_unmapped = True;1771 attrs[i] = SID_NAME_UNKNOWN;1772 }1773 }1774 goto done;1775 }1776 1777 /* Should not happen, but better check once too many */1778 if (!sid_check_is_domain(domain_sid)) {1779 return NT_STATUS_INVALID_HANDLE;1780 }1781 1782 for (i = 0; i < num_names; i++) {1783 if (lookup_global_sam_name(names[i], 0, &rids[i], &attrs[i])) {1784 DEBUG(5,("lookup_names: %s-> %d:%d\n", names[i],1785 rids[i], attrs[i]));1786 have_mapped = True;1787 } else {1788 have_unmapped = True;1789 attrs[i] = SID_NAME_UNKNOWN;1790 }1791 }1792 1793 done:1794 1795 result = NT_STATUS_NONE_MAPPED;1796 1797 if (have_mapped)1798 result = have_unmapped ? STATUS_SOME_UNMAPPED : NT_STATUS_OK;1799 1800 return result;1801 }1802 #endif1803 1804 1901 static int pdb_search_destructor(struct pdb_search *search) 1805 1902 { … … 1864 1961 1865 1962 struct group_search { 1866 GROUP_MAP * groups;1963 GROUP_MAP *groups; 1867 1964 size_t num_groups, current_group; 1868 1965 }; … … 1873 1970 struct group_search *state = (struct group_search *)s->private_data; 1874 1971 uint32_t rid; 1875 GROUP_MAP *map = &state->groups[state->current_group];1972 GROUP_MAP *map; 1876 1973 1877 1974 if (state->current_group == state->num_groups) 1878 1975 return False; 1879 1976 1977 1978 1880 1979 sid_peek_rid(&map->sid, &rid); 1881 1980 … … 1890 1989 struct group_search *state = 1891 1990 (struct group_search *)search->private_data; 1892 SAFE_FREE(state->groups); 1893 } 1894 1895 static bool pdb_search_grouptype(struct pdb_search *search, 1991 TALLOC_FREE(state->groups); 1992 } 1993 1994 static bool pdb_search_grouptype(struct pdb_methods *methods, 1995 struct pdb_search *search, 1896 1996 const struct dom_sid *sid, enum lsa_SidType type) 1897 1997 { 1898 1998 struct group_search *state; 1899 1999 1900 state = talloc (search, struct group_search);2000 state = talloc(search, struct group_search); 1901 2001 if (state == NULL) { 1902 2002 DEBUG(0, ("talloc failed\n")); … … 1904 2004 } 1905 2005 1906 if (!pdb_enum_group_mapping(sid, type, &state->groups, &state->num_groups, 1907 True)) { 2006 if (!NT_STATUS_IS_OK(methods->enum_group_mapping(methods, sid, type, 2007 &state->groups, &state->num_groups, 2008 True))) { 1908 2009 DEBUG(0, ("Could not enum groups\n")); 1909 2010 return False; … … 1920 2021 struct pdb_search *search) 1921 2022 { 1922 return pdb_search_grouptype( search, get_global_sam_sid(), SID_NAME_DOM_GRP);2023 return pdb_search_grouptype(search, get_global_sam_sid(), SID_NAME_DOM_GRP); 1923 2024 } 1924 2025 … … 1928 2029 { 1929 2030 1930 return pdb_search_grouptype( search, sid, SID_NAME_ALIAS);2031 return pdb_search_grouptype(search, sid, SID_NAME_ALIAS); 1931 2032 } 1932 2033 … … 2043 2144 return pdb->get_trusteddom_pw(pdb, domain, pwd, sid, 2044 2145 pass_last_set_time); 2146 2147 2148 2149 2150 2151 2152 2045 2153 } 2046 2154 … … 2082 2190 } 2083 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2084 2201 static bool pdb_default_set_trusteddom_pw(struct pdb_methods *methods, 2085 2202 const char* domain, … … 2147 2264 struct pdb_trusted_domain **td) 2148 2265 { 2149 return NT_STATUS_NOT_IMPLEMENTED; 2266 struct trustAuthInOutBlob taiob; 2267 struct AuthenticationInformation aia; 2268 struct pdb_trusted_domain *tdom; 2269 enum ndr_err_code ndr_err; 2270 time_t last_set_time; 2271 char *pwd; 2272 bool ok; 2273 2274 tdom = talloc(mem_ctx, struct pdb_trusted_domain); 2275 if (!tdom) { 2276 return NT_STATUS_NO_MEMORY; 2277 } 2278 2279 tdom->domain_name = talloc_strdup(tdom, domain); 2280 tdom->netbios_name = talloc_strdup(tdom, domain); 2281 if (!tdom->domain_name || !tdom->netbios_name) { 2282 talloc_free(tdom); 2283 return NT_STATUS_NO_MEMORY; 2284 } 2285 2286 tdom->trust_auth_incoming = data_blob_null; 2287 2288 ok = pdb_get_trusteddom_pw(domain, &pwd, &tdom->security_identifier, 2289 &last_set_time); 2290 if (!ok) { 2291 talloc_free(tdom); 2292 return NT_STATUS_UNSUCCESSFUL; 2293 } 2294 2295 ZERO_STRUCT(taiob); 2296 ZERO_STRUCT(aia); 2297 taiob.count = 1; 2298 taiob.current.count = 1; 2299 taiob.current.array = &aia; 2300 unix_to_nt_time(&aia.LastUpdateTime, last_set_time); 2301 2302 aia.AuthType = TRUST_AUTH_TYPE_CLEAR; 2303 aia.AuthInfo.clear.size = strlen(pwd); 2304 aia.AuthInfo.clear.password = (uint8_t *)talloc_memdup(tdom, pwd, 2305 aia.AuthInfo.clear.size); 2306 SAFE_FREE(pwd); 2307 if (aia.AuthInfo.clear.password == NULL) { 2308 talloc_free(tdom); 2309 return NT_STATUS_NO_MEMORY; 2310 } 2311 2312 taiob.previous.count = 0; 2313 taiob.previous.array = NULL; 2314 2315 ndr_err = ndr_push_struct_blob(&tdom->trust_auth_outgoing, 2316 tdom, &taiob, 2317 (ndr_push_flags_fn_t)ndr_push_trustAuthInOutBlob); 2318 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 2319 talloc_free(tdom); 2320 return NT_STATUS_UNSUCCESSFUL; 2321 } 2322 2323 tdom->trust_direction = LSA_TRUST_DIRECTION_OUTBOUND; 2324 tdom->trust_type = LSA_TRUST_TYPE_DOWNLEVEL; 2325 tdom->trust_attributes = 0; 2326 tdom->trust_forest_trust_info = data_blob_null; 2327 2328 *td = tdom; 2329 return NT_STATUS_OK; 2150 2330 } 2151 2331 … … 2158 2338 } 2159 2339 2340 2341 2160 2342 static NTSTATUS pdb_default_set_trusted_domain(struct pdb_methods *methods, 2161 2343 const char* domain, 2162 2344 const struct pdb_trusted_domain *td) 2163 2345 { 2164 return NT_STATUS_NOT_IMPLEMENTED; 2346 struct trustAuthInOutBlob taiob; 2347 struct AuthenticationInformation *aia; 2348 enum ndr_err_code ndr_err; 2349 char *pwd; 2350 bool ok; 2351 2352 if (td->trust_attributes != 0 || 2353 td->trust_type != LSA_TRUST_TYPE_DOWNLEVEL || 2354 td->trust_direction != LSA_TRUST_DIRECTION_OUTBOUND || 2355 !IS_NULL_DATA_BLOB(td->trust_auth_incoming) || 2356 !IS_NULL_DATA_BLOB(td->trust_forest_trust_info)) { 2357 return NT_STATUS_NOT_IMPLEMENTED; 2358 } 2359 2360 ZERO_STRUCT(taiob); 2361 ndr_err = ndr_pull_struct_blob(&td->trust_auth_outgoing, talloc_tos(), 2362 &taiob, 2363 (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob); 2364 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 2365 return NT_STATUS_UNSUCCESSFUL; 2366 } 2367 2368 aia = (struct AuthenticationInformation *) taiob.current.array; 2369 2370 if (taiob.count != 1 || taiob.current.count != 1 || 2371 taiob.previous.count != 0 || 2372 aia->AuthType != TRUST_AUTH_TYPE_CLEAR) { 2373 return NT_STATUS_NOT_IMPLEMENTED; 2374 } 2375 2376 pwd = talloc_strndup(talloc_tos(), (char *) aia->AuthInfo.clear.password, 2377 aia->AuthInfo.clear.size); 2378 if (!pwd) { 2379 return NT_STATUS_NO_MEMORY; 2380 } 2381 2382 ok = pdb_set_trusteddom_pw(domain, pwd, &td->security_identifier); 2383 if (!ok) { 2384 return NT_STATUS_UNSUCCESSFUL; 2385 } 2386 2387 return NT_STATUS_OK; 2165 2388 } 2166 2389 … … 2183 2406 { 2184 2407 return NULL; 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2185 2588 } 2186 2589 … … 2238 2641 (*methods)->set_account_policy = pdb_default_set_account_policy; 2239 2642 (*methods)->get_seq_num = pdb_default_get_seq_num; 2240 (*methods)->uid_to_sid = pdb_default_uid_to_sid; 2241 (*methods)->gid_to_sid = pdb_default_gid_to_sid; 2643 (*methods)->id_to_sid = pdb_default_id_to_sid; 2242 2644 (*methods)->sid_to_id = pdb_default_sid_to_id; 2243 2645 … … 2246 2648 2247 2649 (*methods)->get_trusteddom_pw = pdb_default_get_trusteddom_pw; 2650 2248 2651 (*methods)->set_trusteddom_pw = pdb_default_set_trusteddom_pw; 2249 2652 (*methods)->del_trusteddom_pw = pdb_default_del_trusteddom_pw; … … 2256 2659 (*methods)->enum_trusted_domains = pdb_default_enum_trusted_domains; 2257 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2258 2681 return NT_STATUS_OK; 2259 2682 }
Note:
See TracChangeset
for help on using the changeset viewer.
