Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/passdb/pdb_interface.c

    r746 r988  
    2525#include "passdb.h"
    2626#include "secrets.h"
     27
    2728#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"
    2933#include "nsswitch/winbind_client.h"
    3034#include "../libcli/security/security.h"
    3135#include "../lib/util/util_pw.h"
     36
     37
     38
    3239
    3340#undef DBGC_CLASS
     
    4855}
    4956
    50 static bool lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid,
     57static bool lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid,
    5158                                  const char **name,
    5259                                  enum lsa_SidType *psid_name_use,
    53                                   union unid_t *unix_id);
     60                                  uid);
    5461
    5562NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function init)
     
    97104        return NULL;
    98105}
     106
     107
     108
     109
     110
     111
    99112
    100113/*
     
    108121 */
    109122
    110 static struct event_context *pdb_event_ctx;
    111 
    112 struct event_context *pdb_get_event_context(void)
    113 {
    114         return pdb_event_ctx;
     123static struct event_ctx;
     124
     125struct event_context(void)
     126{
     127        return pdb_event_ctx;
    115128}
    116129
     
    189202                }
    190203                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;
    199205                }
    200206        }
     
    202208        if ( !pdb ) {
    203209                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;
    212211                }
    213212        }
     
    218217static struct pdb_methods *pdb_get_methods(void)
    219218{
    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;
    221234}
    222235
     
    356369        struct passwd *pwd;
    357370        NTSTATUS result;
    358         const char *guestname = lp_guestaccount();
     371        const char *guestname = lp_guestaccount();
    359372
    360373        pwd = Get_Pwnam_alloc(talloc_tos(), guestname);
     
    448461
    449462                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);
    452464                } else {
    453                         add_script = talloc_strdup(tmp_ctx,
    454                                         lp_addmachine_script());
     465                        add_script = lp_add_machine_script(tmp_ctx);
    455466                }
    456467
     
    464475                   compatibility with previous Samba releases */
    465476                fstrcpy( name2, name );
    466                 strlower_m( name2 );
     477                if (!strlower_m( name2 )) {
     478                        return NT_STATUS_INVALID_PARAMETER;
     479                }
    467480                add_script = talloc_all_string_sub(tmp_ctx,
    468481                                        add_script,
     
    491504        /* we have a valid SID coming out of this call */
    492505
    493         status = samu_alloc_rid_unix( sam_pass, pwd );
     506        status = samu_alloc_rid_unix();
    494507
    495508        TALLOC_FREE( pwd );
     
    516529        pdb_set_acct_ctrl(sam_pass, acb_info, PDB_CHANGED);
    517530
    518         status = pdb_add_sam_account(sam_pass);
     531        status = sam_pass);
    519532
    520533        TALLOC_FREE(sam_pass);
     
    546559        }
    547560
    548         del_script = talloc_strdup(talloc_tos(), lp_deluser_script());
     561        del_script = ());
    549562        if (!del_script || !*del_script) {
    550563                return -1;
     
    574587        fstring username;
    575588
    576         status = pdb_delete_sam_account(sam_acct);
     589        status = sam_acct);
    577590        if (!NT_STATUS_IS_OK(status)) {
    578591                return status;
     
    590603
    591604        fstrcpy( username, pdb_get_username(sam_acct) );
    592         strlower_m( username );
     605        if (!strlower_m( username )) {
     606                return status;
     607        }
    593608
    594609        smb_delete_user( username );
     
    601616        struct pdb_methods *pdb = pdb_get_methods();
    602617        uid_t uid = -1;
     618
     619
     620
     621
     622
    603623
    604624        /* sanity check to make sure we don't delete root */
    605625
    606         if ( !sid_to_uid( pdb_get_user_sid(sam_acct), &uid ) ) {
     626        if ( !sid_to_uid(, &uid ) ) {
    607627                return NT_STATUS_NO_SUCH_USER;
    608628        }
     
    612632        }
    613633
    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;
    615658}
    616659
     
    633676{
    634677        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)));
    637683
    638684        return pdb->delete_sam_account(pdb, sam_acct);
     
    740786{
    741787        struct dom_sid group_sid;
    742         GROUP_MAP map;
     788        GROUP_MAP map;
    743789        NTSTATUS status;
    744790        struct group *grp;
    745791        const char *grp_name;
    746792
     793
     794
     795
     796
     797
    747798        /* coverity */
    748         map.gid = (gid_t) -1;
     799        mapgid = (gid_t) -1;
    749800
    750801        sid_compose(&group_sid, get_global_sam_sid(), rid);
    751802
    752         if (!get_domain_group_from_sid(group_sid, &map)) {
     803        if (!get_domain_group_from_sid(group_sid, map)) {
    753804                DEBUG(10, ("Could not find group for rid %d\n", rid));
    754805                return NT_STATUS_NO_SUCH_GROUP;
     
    757808        /* We need the group name for the smb_delete_group later on */
    758809
    759         if (map.gid == (gid_t)-1) {
     810        if (mapgid == (gid_t)-1) {
    760811                return NT_STATUS_NO_SUCH_GROUP;
    761812        }
    762813
    763         grp = getgrgid(map.gid);
     814        grp = getgrgid(mapgid);
    764815        if (grp == NULL) {
    765816                return NT_STATUS_NO_SUCH_GROUP;
    766817        }
     818
     819
    767820
    768821        /* Copy the name, no idea what pdb_delete_group_mapping_entry does.. */
     
    810863}
    811864
    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)
     865bool 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)
    814870{
    815871        struct pdb_methods *pdb = pdb_get_methods();
     
    917973        struct dom_sid group_sid, member_sid;
    918974        struct samu *account = NULL;
    919         GROUP_MAP map;
     975        GROUP_MAP map;
    920976        struct group *grp;
    921977        struct passwd *pwd;
     
    923979        uid_t uid;
    924980
     981
     982
     983
     984
     985
    925986        /* coverity */
    926         map.gid = (gid_t) -1;
     987        mapgid = (gid_t) -1;
    927988
    928989        sid_compose(&group_sid, get_global_sam_sid(), group_rid);
    929990        sid_compose(&member_sid, get_global_sam_sid(), member_rid);
    930991
    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)) {
    934995                return NT_STATUS_NO_SUCH_GROUP;
    935996        }
     997
     998
    936999
    9371000        group_name = talloc_strdup(mem_ctx, grp->gr_name);
     
    9821045        struct dom_sid group_sid, member_sid;
    9831046        struct samu *account = NULL;
    984         GROUP_MAP map;
     1047        GROUP_MAP map;
    9851048        struct group *grp;
    9861049        struct passwd *pwd;
     
    9881051        uid_t uid;
    9891052
     1053
     1054
     1055
     1056
     1057
    9901058        sid_compose(&group_sid, get_global_sam_sid(), group_rid);
    9911059        sid_compose(&member_sid, get_global_sam_sid(), member_rid);
    9921060
    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)) {
    9961064                return NT_STATUS_NO_SUCH_GROUP;
    9971065        }
     1066
     1067
    9981068
    9991069        group_name = talloc_strdup(mem_ctx, grp->gr_name);
     
    11051175}
    11061176
    1107 /*
    1108  * NOTE: pdb_lookup_names is currently (2007-01-12) not used anywhere
    1109  *       in the samba code.
    1110  *       Unlike _lsa_lookup_sids and _samr_lookup_rids, which eventually
    1111  *       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 come
    1113  *       down to are pdb_getsampwnam and pdb_getgrnam instead of
    1114  *       pdb_lookup_names.
    1115  *       But in principle, it the call belongs to the API and might get
    1116  *       used in this context some day.
    1117  */
    1118 #if 0
    1119 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 #endif
    1129 
    11301177bool pdb_get_account_policy(enum pdb_policy_type type, uint32_t *value)
    11311178{
     
    11581205}
    11591206
    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 */
     1215bool 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
     1229bool 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;
    11771246}
    11781247
     
    12311300                /* validate that the RID is not in use */
    12321301
    1233                 if ( lookup_global_sam_rid( ctx, allocated_rid, &name, &type, NULL ) ) {
     1302                if () {
    12341303                        allocated_rid = 0;
    12351304                }
     
    12541323 ***************************************************************/
    12551324
    1256 bool initialize_password_db(bool reload, struct event_context *event_ctx)
    1257 {
    1258         pdb_event_ctx = event_ctx;
     1325bool initialize_password_db(bool reload, struct tevent_context *tevent_ctx)
     1326{
     1327        if (tevent_ctx) {
     1328                pdb_tevent_ctx = tevent_ctx;
     1329        }
    12591330        return (pdb_get_methods_reload(reload) != NULL);
    12601331}
    1261 
    12621332
    12631333/***************************************************************************
     
    13251395        bool ret;
    13261396
    1327         unix_pw = sys_getpwuid( uid );
     1397        unix_pw = getpwuid( uid );
    13281398
    13291399        if ( !unix_pw ) {
     
    13601430                                   struct dom_sid *sid)
    13611431{
    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
     1449static 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 */
     1467bool 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;
    13701487}
    13711488
    13721489static bool pdb_default_sid_to_id(struct pdb_methods *methods,
    13731490                                  const struct dom_sid *sid,
    1374                                   union unid_t *id, enum lsa_SidType *type)
     1491                                  )
    13751492{
    13761493        TALLOC_CTX *mem_ctx;
    13771494        bool ret = False;
    1378         const char *name;
    13791495        uint32_t rid;
     1496
    13801497
    13811498        mem_ctx = talloc_new(NULL);
     
    13871504
    13881505        if (sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) {
     1506
     1507
     1508
     1509
    13891510                /* 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                }
    13911536                goto done;
    13921537        }
    13931538
    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;
    14101545        }
    14111546
     
    14151550            sid_check_is_in_wellknown_domain(sid)) {
    14161551                /* 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))) {
    14191561                        DEBUG(10, ("Could not find map for sid %s\n",
    14201562                                   sid_string_dbg(sid)));
    14211563                        goto done;
    14221564                }
    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)) {
    14251567                        DEBUG(10, ("Map for sid %s is a %s, expected an "
    14261568                                   "alias\n", sid_string_dbg(sid),
    1427                                    sid_type_lookup(map.sid_name_use)));
     1569                                   sid_type_lookup(mapsid_name_use)));
    14281570                        goto done;
    14291571                }
    14301572
    1431                 id->gid = map.gid;
    1432                 *type = SID_NAME_ALIAS;
     1573                id->gid;
     1574                ;
    14331575                ret = True;
    14341576                goto done;
     
    15211663                return NT_STATUS_OK;
    15221664
    1523         *pp_member_rids = TALLOC_ZERO_ARRAY(mem_ctx, uint32_t, num_uids);
     1665        *pp_member_rids = (mem_ctx, uint32_t, num_uids);
    15241666
    15251667        for (i=0; i<num_uids; i++) {
     
    15281670                uid_to_sid(&sid, uids[i]);
    15291671
    1530                 if (!sid_check_is_in_our_domain(&sid)) {
     1672                if (!sid_check_is_in_our_(&sid)) {
    15311673                        DEBUG(5, ("Inconsistent SAM -- group member uid not "
    15321674                                  "in our domain\n"));
     
    15731715        }
    15741716
    1575         *pp_sids = TALLOC_ARRAY(mem_ctx, struct dom_sid, *p_num_groups);
     1717        *pp_sids = (mem_ctx, struct dom_sid, *p_num_groups);
    15761718
    15771719        if (*pp_sids == NULL) {
     
    15941736                                  const char **name,
    15951737                                  enum lsa_SidType *psid_name_use,
    1596                                   union unid_t *unix_id)
     1738                                  uid)
    15971739{
    15981740        struct samu *sam_account = NULL;
    1599         GROUP_MAP map;
     1741        GROUP_MAP ;
    16001742        bool ret;
    16011743        struct dom_sid sid;
     
    16141756        }
    16151757
     1758
     1759
     1760
     1761
     1762
    16161763        /* BEING ROOT BLOCK */
    16171764        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) {
    16191778                struct passwd *pw;
    16201779
    1621                 unbecome_root();                /* -----> EXIT BECOME_ROOT() */
    16221780                *name = talloc_strdup(mem_ctx, pdb_get_username(sam_account));
    16231781                if (!*name) {
     
    16301788                TALLOC_FREE(sam_account);
    16311789
    1632                 if (unix_id == NULL) {
     1790                if (uid == NULL) {
    16331791                        return True;
    16341792                }
     
    16381796                        return False;
    16391797                }
    1640                 unix_id->uid = pw->pw_uid;
     1798                uid = pw->pw_uid;
    16411799                TALLOC_FREE(pw);
    16421800                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);
    16611815                return True;
    16621816        }
     1817
     1818
    16631819
    16641820        /* Windows will always map RID 513 to something.  On a non-domain
    16651821           controller, this gets mapped to SERVER\None. */
    16661822
    1667         if ( unix_id ) {
     1823        if () {
    16681824                DEBUG(5, ("Can't find a unix id for an unmapped group\n"));
    16691825                return False;
     
    17121868
    17131869        /* Should not happen, but better check once too many */
    1714         if (!sid_check_is_domain(domain_sid)) {
     1870        if (!sid_check_is_(domain_sid)) {
    17151871                return NT_STATUS_INVALID_HANDLE;
    17161872        }
     
    17201876
    17211877                if (lookup_global_sam_rid(names, rids[i], &name, &attrs[i],
    1722                                           NULL)) {
     1878                                          NULL)) {
    17231879                        if (name == NULL) {
    17241880                                return NT_STATUS_NO_MEMORY;
     
    17431899}
    17441900
    1745 #if 0
    1746 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 #endif
    1803 
    18041901static int pdb_search_destructor(struct pdb_search *search)
    18051902{
     
    18641961
    18651962struct group_search {
    1866         GROUP_MAP *groups;
     1963        GROUP_MAP *groups;
    18671964        size_t num_groups, current_group;
    18681965};
     
    18731970        struct group_search *state = (struct group_search *)s->private_data;
    18741971        uint32_t rid;
    1875         GROUP_MAP *map = &state->groups[state->current_group];
     1972        GROUP_MAP *map;
    18761973
    18771974        if (state->current_group == state->num_groups)
    18781975                return False;
    18791976
     1977
     1978
    18801979        sid_peek_rid(&map->sid, &rid);
    18811980
     
    18901989        struct group_search *state =
    18911990                (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
     1994static bool pdb_search_grouptype(struct pdb_methods *methods,
     1995                                 struct pdb_search *search,
    18961996                                 const struct dom_sid *sid, enum lsa_SidType type)
    18971997{
    18981998        struct group_search *state;
    18991999
    1900         state = talloc(search, struct group_search);
     2000        state = talloc(search, struct group_search);
    19012001        if (state == NULL) {
    19022002                DEBUG(0, ("talloc failed\n"));
     
    19042004        }
    19052005
    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))) {
    19082009                DEBUG(0, ("Could not enum groups\n"));
    19092010                return False;
     
    19202021                                      struct pdb_search *search)
    19212022{
    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);
    19232024}
    19242025
     
    19282029{
    19292030
    1930         return pdb_search_grouptype(search, sid, SID_NAME_ALIAS);
     2031        return pdb_search_grouptype(search, sid, SID_NAME_ALIAS);
    19312032}
    19322033
     
    20432144        return pdb->get_trusteddom_pw(pdb, domain, pwd, sid,
    20442145                        pass_last_set_time);
     2146
     2147
     2148
     2149
     2150
     2151
     2152
    20452153}
    20462154
     
    20822190}
    20832191
     2192
     2193
     2194
     2195
     2196
     2197
     2198
     2199
     2200
    20842201static bool pdb_default_set_trusteddom_pw(struct pdb_methods *methods,
    20852202                                          const char* domain,
     
    21472264                                               struct pdb_trusted_domain **td)
    21482265{
    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;
    21502330}
    21512331
     
    21582338}
    21592339
     2340
     2341
    21602342static NTSTATUS pdb_default_set_trusted_domain(struct pdb_methods *methods,
    21612343                                               const char* domain,
    21622344                                               const struct pdb_trusted_domain *td)
    21632345{
    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;
    21652388}
    21662389
     
    21832406{
    21842407        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
    21852588}
    21862589
     
    22382641        (*methods)->set_account_policy = pdb_default_set_account_policy;
    22392642        (*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;
    22422644        (*methods)->sid_to_id = pdb_default_sid_to_id;
    22432645
     
    22462648
    22472649        (*methods)->get_trusteddom_pw = pdb_default_get_trusteddom_pw;
     2650
    22482651        (*methods)->set_trusteddom_pw = pdb_default_set_trusteddom_pw;
    22492652        (*methods)->del_trusteddom_pw = pdb_default_del_trusteddom_pw;
     
    22562659        (*methods)->enum_trusted_domains = pdb_default_enum_trusted_domains;
    22572660
     2661
     2662
     2663
     2664
     2665
     2666
     2667
     2668
     2669
     2670
     2671
     2672
     2673
     2674
     2675
     2676
     2677
     2678
     2679
     2680
    22582681        return NT_STATUS_OK;
    22592682}
Note: See TracChangeset for help on using the changeset viewer.