Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/passdb/lookup_sid.c

    r414 r745  
    55   Copyright (C) Gerald (Jerry) Carter   2003
    66   Copyright (C) Volker Lendecke         2005
    7    
     7
    88   This program is free software; you can redistribute it and/or modify
    99   it under the terms of the GNU General Public License as published by
    1010   the Free Software Foundation; either version 3 of the License, or
    1111   (at your option) any later version.
    12    
     12
    1313   This program is distributed in the hope that it will be useful,
    1414   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1515   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1616   GNU General Public License for more details.
    17    
     17
    1818   You should have received a copy of the GNU General Public License
    1919   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2121
    2222#include "includes.h"
     23#include "passdb.h"
     24#include "../librpc/gen_ndr/ndr_security.h"
     25#include "secrets.h"
     26#include "memcache.h"
     27#include "idmap_cache.h"
     28#include "../libcli/security/security.h"
     29#include "lib/winbind_util.h"
    2330
    2431/*****************************************************************
     
    3340                 const char *full_name, int flags,
    3441                 const char **ret_domain, const char **ret_name,
    35                  DOM_SID *ret_sid, enum lsa_SidType *ret_type)
     42                 struct dom_sid *ret_sid, enum lsa_SidType *ret_type)
    3643{
    3744        char *p;
     
    4047        const char *name = NULL;
    4148        uint32 rid;
    42         DOM_SID sid;
     49        struct dom_sid sid;
    4350        enum lsa_SidType type;
    4451        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
     
    6673        }
    6774
    68         DEBUG(10,("lookup_name: %s => %s (domain), %s (name)\n",
     75        DEBUG(10,("lookup_name: %s => domain=[%s], name=[%s]\n",
    6976                full_name, domain, name));
    7077        DEBUG(10, ("lookup_name: flags = 0x0%x\n", flags));
     
    7683                /* It's our own domain, lookup the name in passdb */
    7784                if (lookup_global_sam_name(name, flags, &rid, &type)) {
    78                         sid_copy(&sid, get_global_sam_sid());
    79                         sid_append_rid(&sid, rid);
     85                        sid_compose(&sid, get_global_sam_sid(), rid);
    8086                        goto ok;
    8187                }
     
    97103                /* Explicit request for a name in BUILTIN */
    98104                if (lookup_builtin_name(name, &rid)) {
    99                         sid_copy(&sid, &global_sid_Builtin);
    100                         sid_append_rid(&sid, rid);
     105                        sid_compose(&sid, &global_sid_Builtin, rid);
    101106                        type = SID_NAME_ALIAS;
    102107                        goto ok;
     
    216221        {
    217222                domain = talloc_strdup(tmp_ctx, builtin_domain_name());
    218                 sid_copy(&sid, &global_sid_Builtin);
    219                 sid_append_rid(&sid, rid);
     223                sid_compose(&sid, &global_sid_Builtin, rid);
    220224                type = SID_NAME_ALIAS;
    221225                goto ok;
     
    231235        {
    232236                domain = talloc_strdup(tmp_ctx, get_global_sam_name());
    233                 sid_copy(&sid, get_global_sam_sid());
    234                 sid_append_rid(&sid, rid);
     237                sid_compose(&sid, get_global_sam_sid(), rid);
    235238                goto ok;
    236239        }
     
    258261
    259262        if (IS_DC && winbind_lookup_name("", name, &sid, &type)) {
    260                 DOM_SID dom_sid;
    261                 uint32 tmp_rid;
     263                struct dom_sid dom_sid;
    262264                enum lsa_SidType domain_type;
    263                
     265
    264266                if (type == SID_NAME_DOMAIN) {
    265267                        /* Swap name and type */
     
    273275
    274276                sid_copy(&dom_sid, &sid);
    275                 sid_split_rid(&dom_sid, &tmp_rid);
     277                sid_split_rid(&dom_sid, NULL);
    276278
    277279                if (!winbind_lookup_sid(tmp_ctx, &dom_sid, &domain, NULL,
     
    362364                 const char *full_name, int flags,
    363365                 const char **ret_domain, const char **ret_name,
    364                  DOM_SID *ret_sid, enum lsa_SidType *ret_type)
     366                 struct dom_sid *ret_sid, enum lsa_SidType *ret_type)
    365367{
    366368        char *qualified_name;
     
    403405                return true;
    404406        }
    405        
     407
    406408        /* Finally try with "Unix Users" or "Unix Group" */
    407409        qualified_name = talloc_asprintf(mem_ctx, "%s\\%s",
     
    420422
    421423static bool wb_lookup_rids(TALLOC_CTX *mem_ctx,
    422                            const DOM_SID *domain_sid,
     424                           const struct dom_sid *domain_sid,
    423425                           int num_rids, uint32 *rids,
    424426                           const char **domain_name,
     
    470472}
    471473
    472 static bool lookup_rids(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid,
     474static bool lookup_rids(TALLOC_CTX *mem_ctx, const struct dom_sid *domain_sid,
    473475                        int num_rids, uint32_t *rids,
    474476                        const char **domain_name,
     
    544546        if (sid_check_is_wellknown_domain(domain_sid, NULL)) {
    545547                for (i=0; i<num_rids; i++) {
    546                         DOM_SID sid;
    547                         sid_copy(&sid, domain_sid);
    548                         sid_append_rid(&sid, rids[i]);
     548                        struct dom_sid sid;
     549                        sid_compose(&sid, domain_sid, rids[i]);
    549550                        if (lookup_wellknown_sid(mem_ctx, &sid,
    550551                                                 domain_name, &(*names)[i])) {
     
    606607 */
    607608
    608 static bool lookup_as_domain(const DOM_SID *sid, TALLOC_CTX *mem_ctx,
     609static bool lookup_as_domain(const struct dom_sid *sid, TALLOC_CTX *mem_ctx,
    609610                             const char **name)
    610611{
     
    657658
    658659                for (i=0; i<num_domains; i++) {
    659                         if (sid_equal(sid, &domains[i]->sid)) {
     660                        if (dom_sid_equal(sid, &domains[i]->sid)) {
    660661                                *name = talloc_strdup(mem_ctx,
    661662                                                      domains[i]->name);
     
    694695 */
    695696
    696 static bool check_dom_sid_to_level(const DOM_SID *sid, int level)
     697static bool check_dom_sid_to_level(const struct dom_sid *sid, int level)
    697698{
    698699        int ret = false;
     
    729730 * belonging to a domain and hands them in bulk to the appropriate lookup
    730731 * function. In particular pdb_lookup_rids with ldapsam_trusted benefits
    731  * *hugely* from this. Winbind is going to be extended with a lookup_rids
    732  * interface as well, so on a DC we can do a bulk lsa_lookuprids to the
    733  * appropriate DC.
     732 * *hugely* from this.
    734733 */
    735734
    736735NTSTATUS lookup_sids(TALLOC_CTX *mem_ctx, int num_sids,
    737                      const DOM_SID **sids, int level,
     736                     const struct dom_sid **sids, int level,
    738737                     struct lsa_dom_info **ret_domains,
    739738                     struct lsa_name_info **ret_names)
     
    783782
    784783        for (i=0; i<num_sids; i++) {
    785                 DOM_SID sid;
    786                 uint32 rid;
     784                struct dom_sid sid;
     785                uint32_t rid = 0;
    787786                const char *domain_name = NULL;
    788787
     
    802801                                goto fail;
    803802                        }
    804                                
     803
    805804                        name_infos[i].rid = 0;
    806805                        name_infos[i].type = SID_NAME_DOMAIN;
     
    836835                                break;
    837836                        }
    838                         if (sid_equal(&sid, &dom_infos[j].sid)) {
     837                        if (dom_sid_equal(&sid, &dom_infos[j].sid)) {
    839838                                break;
    840839                        }
     
    921920                        goto fail;
    922921                }
    923                        
     922
    924923                for (j=0; j<dom->num_idxs; j++) {
    925924                        int idx = dom->idxs[j];
     
    954953*****************************************************************/ 
    955954
    956 bool lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
     955bool lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
    957956                const char **ret_domain, const char **ret_name,
    958957                enum lsa_SidType *ret_type)
     
    10181017*****************************************************************/
    10191018
    1020 static bool fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid)
     1019static bool fetch_sid_from_uid_cache(struct dom_sid *psid, uid_t uid)
    10211020{
    10221021        DATA_BLOB cache_value;
     
    10301029        memcpy(psid, cache_value.data, MIN(sizeof(*psid), cache_value.length));
    10311030        SMB_ASSERT(cache_value.length >= offsetof(struct dom_sid, id_auth));
    1032         SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, NULL, 0));
     1031        SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, 0));
    10331032
    10341033        return true;
     
    10391038*****************************************************************/
    10401039
    1041 static bool fetch_uid_from_cache( uid_t *puid, const DOM_SID *psid )
     1040static bool fetch_uid_from_cache( uid_t *puid, const struct dom_sid *psid )
    10421041{
    10431042        DATA_BLOB cache_value;
    10441043
    10451044        if (!memcache_lookup(NULL, SID_UID_CACHE,
    1046                              data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)),
     1045                             data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
    10471046                             &cache_value)) {
    10481047                return false;
     
    10591058*****************************************************************/
    10601059
    1061 void store_uid_sid_cache(const DOM_SID *psid, uid_t uid)
     1060void store_uid_sid_cache(const struct dom_sid *psid, uid_t uid)
    10621061{
    10631062        memcache_add(NULL, SID_UID_CACHE,
    1064                      data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)),
     1063                     data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
    10651064                     data_blob_const(&uid, sizeof(uid)));
    10661065        memcache_add(NULL, UID_SID_CACHE,
    10671066                     data_blob_const(&uid, sizeof(uid)),
    1068                      data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)));
     1067                     data_blob_const(psid, ndr_size_dom_sid(psid, 0)));
    10691068}
    10701069
     
    10731072*****************************************************************/
    10741073
    1075 static bool fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid)
     1074static bool fetch_sid_from_gid_cache(struct dom_sid *psid, gid_t gid)
    10761075{
    10771076        DATA_BLOB cache_value;
     
    10851084        memcpy(psid, cache_value.data, MIN(sizeof(*psid), cache_value.length));
    10861085        SMB_ASSERT(cache_value.length >= offsetof(struct dom_sid, id_auth));
    1087         SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, NULL, 0));
     1086        SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, 0));
    10881087
    10891088        return true;
     
    10941093*****************************************************************/
    10951094
    1096 static bool fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid)
     1095static bool fetch_gid_from_cache(gid_t *pgid, const struct dom_sid *psid)
    10971096{
    10981097        DATA_BLOB cache_value;
    10991098
    11001099        if (!memcache_lookup(NULL, SID_GID_CACHE,
    1101                              data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)),
     1100                             data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
    11021101                             &cache_value)) {
    11031102                return false;
     
    11141113*****************************************************************/
    11151114
    1116 void store_gid_sid_cache(const DOM_SID *psid, gid_t gid)
     1115void store_gid_sid_cache(const struct dom_sid *psid, gid_t gid)
    11171116{
    11181117        memcache_add(NULL, SID_GID_CACHE,
    1119                      data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)),
     1118                     data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
    11201119                     data_blob_const(&gid, sizeof(gid)));
    11211120        memcache_add(NULL, GID_SID_CACHE,
    11221121                     data_blob_const(&gid, sizeof(gid)),
    1123                      data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)));
     1122                     data_blob_const(psid, ndr_size_dom_sid(psid, 0)));
    11241123}
    11251124
     
    11281127*****************************************************************/ 
    11291128
    1130 static void legacy_uid_to_sid(DOM_SID *psid, uid_t uid)
     1129static void legacy_uid_to_sid(struct dom_sid *psid, uid_t uid)
    11311130{
    11321131        bool ret;
     
    11591158*****************************************************************/ 
    11601159
    1161 static void legacy_gid_to_sid(DOM_SID *psid, gid_t gid)
     1160static void legacy_gid_to_sid(struct dom_sid *psid, gid_t gid)
    11621161{
    11631162        bool ret;
     
    11731172                goto done;
    11741173        }
    1175        
     1174
    11761175        /* This is an unmapped group */
    11771176
     
    11901189*****************************************************************/ 
    11911190
    1192 static bool legacy_sid_to_uid(const DOM_SID *psid, uid_t *puid)
     1191static bool legacy_sid_to_uid(const struct dom_sid *psid, uid_t *puid)
    11931192{
    11941193        enum lsa_SidType type;
    1195         uint32 rid;
    1196 
    1197         if (sid_peek_check_rid(get_global_sam_sid(), psid, &rid)) {
     1194
     1195        if (sid_check_is_in_our_domain(psid)) {
    11981196                union unid_t id;
    11991197                bool ret;
     
    12341232*****************************************************************/ 
    12351233
    1236 static bool legacy_sid_to_gid(const DOM_SID *psid, gid_t *pgid)
    1237 {
    1238         uint32 rid;
     1234static bool legacy_sid_to_gid(const struct dom_sid *psid, gid_t *pgid)
     1235{
    12391236        GROUP_MAP map;
    12401237        union unid_t id;
     
    12581255        }
    12591256
    1260         if (sid_peek_check_rid(get_global_sam_sid(), psid, &rid)) {
     1257        if (sid_check_is_in_our_domain(psid)) {
    12611258                bool ret;
    12621259
     
    12761273                        goto done;
    12771274                }
    1278        
     1275
    12791276                /* This was ours, but it was not mapped.  Fail */
    12801277        }
     
    12831280                  sid_string_dbg(psid)));
    12841281        return false;
    1285        
     1282
    12861283 done:
    12871284        DEBUG(10,("LEGACY: sid %s -> gid %u\n", sid_string_dbg(psid),
     
    12971294*****************************************************************/ 
    12981295
    1299 void uid_to_sid(DOM_SID *psid, uid_t uid)
     1296void uid_to_sid(struct dom_sid *psid, uid_t uid)
    13001297{
    13011298        bool expired = true;
     
    13501347*****************************************************************/ 
    13511348
    1352 void gid_to_sid(DOM_SID *psid, gid_t gid)
     1349void gid_to_sid(struct dom_sid *psid, gid_t gid)
    13531350{
    13541351        bool expired = true;
     
    13991396}
    14001397
     1398bool sids_to_unix_ids(const struct dom_sid *sids, uint32_t num_sids,
     1399                      struct wbcUnixId *ids)
     1400{
     1401        struct wbcDomainSid *wbc_sids = NULL;
     1402        struct wbcUnixId *wbc_ids = NULL;
     1403        uint32_t i, num_not_cached;
     1404        wbcErr err;
     1405        bool ret = false;
     1406
     1407        wbc_sids = TALLOC_ARRAY(talloc_tos(), struct wbcDomainSid, num_sids);
     1408        if (wbc_sids == NULL) {
     1409                return false;
     1410        }
     1411
     1412        num_not_cached = 0;
     1413
     1414        for (i=0; i<num_sids; i++) {
     1415                bool expired;
     1416                uint32_t rid;
     1417
     1418                if (fetch_uid_from_cache(&ids[i].id.uid, &sids[i])) {
     1419                        ids[i].type = WBC_ID_TYPE_UID;
     1420                        continue;
     1421                }
     1422                if (fetch_gid_from_cache(&ids[i].id.gid, &sids[i])) {
     1423                        ids[i].type = WBC_ID_TYPE_GID;
     1424                        continue;
     1425                }
     1426                if (sid_peek_check_rid(&global_sid_Unix_Users,
     1427                                       &sids[i], &rid)) {
     1428                        ids[i].type = WBC_ID_TYPE_UID;
     1429                        ids[i].id.uid = rid;
     1430                        continue;
     1431                }
     1432                if (sid_peek_check_rid(&global_sid_Unix_Groups,
     1433                                       &sids[i], &rid)) {
     1434                        ids[i].type = WBC_ID_TYPE_GID;
     1435                        ids[i].id.gid = rid;
     1436                        continue;
     1437                }
     1438                if (idmap_cache_find_sid2uid(&sids[i], &ids[i].id.uid,
     1439                                             &expired)
     1440                    && !expired) {
     1441                        ids[i].type = WBC_ID_TYPE_UID;
     1442                        continue;
     1443                }
     1444                if (idmap_cache_find_sid2gid(&sids[i], &ids[i].id.gid,
     1445                                             &expired)
     1446                    && !expired) {
     1447                        ids[i].type = WBC_ID_TYPE_GID;
     1448                        continue;
     1449                }
     1450                ids[i].type = WBC_ID_TYPE_NOT_SPECIFIED;
     1451                memcpy(&wbc_sids[num_not_cached], &sids[i],
     1452                       ndr_size_dom_sid(&sids[i], 0));
     1453                num_not_cached += 1;
     1454        }
     1455        if (num_not_cached == 0) {
     1456                goto done;
     1457        }
     1458        wbc_ids = TALLOC_ARRAY(talloc_tos(), struct wbcUnixId, num_not_cached);
     1459        if (wbc_ids == NULL) {
     1460                goto fail;
     1461        }
     1462        for (i=0; i<num_not_cached; i++) {
     1463                wbc_ids[i].type = WBC_ID_TYPE_NOT_SPECIFIED;
     1464        }
     1465        err = wbcSidsToUnixIds(wbc_sids, num_not_cached, wbc_ids);
     1466        if (!WBC_ERROR_IS_OK(err)) {
     1467                DEBUG(10, ("wbcSidsToUnixIds returned %s\n",
     1468                           wbcErrorString(err)));
     1469        }
     1470
     1471        num_not_cached = 0;
     1472
     1473        for (i=0; i<num_sids; i++) {
     1474                if (ids[i].type == WBC_ID_TYPE_NOT_SPECIFIED) {
     1475                        ids[i] = wbc_ids[num_not_cached];
     1476                        num_not_cached += 1;
     1477                }
     1478        }
     1479
     1480        for (i=0; i<num_sids; i++) {
     1481                if (ids[i].type != WBC_ID_TYPE_NOT_SPECIFIED) {
     1482                        continue;
     1483                }
     1484                if (legacy_sid_to_gid(&sids[i], &ids[i].id.gid)) {
     1485                        ids[i].type = WBC_ID_TYPE_GID;
     1486                        continue;
     1487                }
     1488                if (legacy_sid_to_uid(&sids[i], &ids[i].id.uid)) {
     1489                        ids[i].type = WBC_ID_TYPE_UID;
     1490                        continue;
     1491                }
     1492        }
     1493done:
     1494        ret = true;
     1495fail:
     1496        TALLOC_FREE(wbc_ids);
     1497        TALLOC_FREE(wbc_sids);
     1498        return ret;
     1499}
     1500
    14011501/*****************************************************************
    14021502 *THE CANONICAL* convert SID to uid function.
    14031503*****************************************************************/ 
    14041504
    1405 bool sid_to_uid(const DOM_SID *psid, uid_t *puid)
     1505bool sid_to_uid(const struct dom_sid *psid, uid_t *puid)
    14061506{
    14071507        bool expired = true;
     
    14651565*****************************************************************/ 
    14661566
    1467 bool sid_to_gid(const DOM_SID *psid, gid_t *pgid)
     1567bool sid_to_gid(const struct dom_sid *psid, gid_t *pgid)
    14681568{
    14691569        bool expired = true;
     
    15211621        return true;
    15221622}
     1623
     1624/**
     1625 * @brief This function gets the primary group SID mapping the primary
     1626 *        GID of the user as obtained by an actual getpwnam() call.
     1627 *        This is necessary to avoid issues with arbitrary group SIDs
     1628 *        stored in passdb. We try as hard as we can to get the SID
     1629 *        corresponding to the GID, including trying group mapping.
     1630 *        If nothing else works, we will force "Domain Users" as the
     1631 *        primary group.
     1632 *        This is needed because we must always be able to lookup the
     1633 *        primary group SID, so we cannot settle for an arbitrary SID.
     1634 *
     1635 *        This call can be expensive. Use with moderation.
     1636 *        If you have a "samu" struct around use pdb_get_group_sid()
     1637 *        instead as it does properly cache results.
     1638 *
     1639 * @param mem_ctx[in]     The memory context iused to allocate the result.
     1640 * @param username[in]    The user's name
     1641 * @param _pwd[in|out]    If available, pass in user's passwd struct.
     1642 *                        It will contain a tallocated passwd if NULL was
     1643 *                        passed in.
     1644 * @param _group_sid[out] The user's Primary Group SID
     1645 *
     1646 * @return NTSTATUS error code.
     1647 */
     1648NTSTATUS get_primary_group_sid(TALLOC_CTX *mem_ctx,
     1649                                const char *username,
     1650                                struct passwd **_pwd,
     1651                                struct dom_sid **_group_sid)
     1652{
     1653        TALLOC_CTX *tmp_ctx;
     1654        bool need_lookup_sid = false;
     1655        struct dom_sid *group_sid;
     1656        struct passwd *pwd = *_pwd;
     1657
     1658        tmp_ctx = talloc_new(mem_ctx);
     1659        if (!tmp_ctx) {
     1660                return NT_STATUS_NO_MEMORY;
     1661        }
     1662
     1663        if (!pwd) {
     1664                pwd = Get_Pwnam_alloc(mem_ctx, username);
     1665                if (!pwd) {
     1666                        DEBUG(0, ("Failed to find a Unix account for %s",
     1667                                  username));
     1668                        TALLOC_FREE(tmp_ctx);
     1669                        return NT_STATUS_NO_SUCH_USER;
     1670                }
     1671        }
     1672
     1673        group_sid = talloc_zero(mem_ctx, struct dom_sid);
     1674        if (!group_sid) {
     1675                TALLOC_FREE(tmp_ctx);
     1676                return NT_STATUS_NO_MEMORY;
     1677        }
     1678
     1679        gid_to_sid(group_sid, pwd->pw_gid);
     1680        if (!is_null_sid(group_sid)) {
     1681                struct dom_sid domain_sid;
     1682                uint32_t rid;
     1683
     1684                /* We need a sid within our domain */
     1685                sid_copy(&domain_sid, group_sid);
     1686                sid_split_rid(&domain_sid, &rid);
     1687                if (dom_sid_equal(&domain_sid, get_global_sam_sid())) {
     1688                        /*
     1689                         * As shortcut for the expensive lookup_sid call
     1690                         * compare the domain sid part
     1691                         */
     1692                        switch (rid) {
     1693                        case DOMAIN_RID_ADMINS:
     1694                        case DOMAIN_RID_USERS:
     1695                                goto done;
     1696                        default:
     1697                                need_lookup_sid = true;
     1698                                break;
     1699                        }
     1700                } else {
     1701                        /* Try group mapping */
     1702                        ZERO_STRUCTP(group_sid);
     1703                        if (pdb_gid_to_sid(pwd->pw_gid, group_sid)) {
     1704                                need_lookup_sid = true;
     1705                        }
     1706                }
     1707        }
     1708
     1709        /* We must verify that this is a valid SID that resolves to a
     1710         * group of the correct type */
     1711        if (need_lookup_sid) {
     1712                enum lsa_SidType type = SID_NAME_UNKNOWN;
     1713                bool lookup_ret;
     1714
     1715                DEBUG(10, ("do lookup_sid(%s) for group of user %s\n",
     1716                           sid_string_dbg(group_sid), username));
     1717
     1718                /* Now check that it's actually a domain group and
     1719                 * not something else */
     1720                lookup_ret = lookup_sid(tmp_ctx, group_sid,
     1721                                        NULL, NULL, &type);
     1722
     1723                if (lookup_ret && (type == SID_NAME_DOM_GRP)) {
     1724                        goto done;
     1725                }
     1726
     1727                DEBUG(3, ("Primary group %s for user %s is"
     1728                          " a %s and not a domain group\n",
     1729                          sid_string_dbg(group_sid), username,
     1730                          sid_type_lookup(type)));
     1731        }
     1732
     1733        /* Everything else, failed.
     1734         * Just set it to the 'Domain Users' RID of 513 which will
     1735           always resolve to a name */
     1736        DEBUG(3, ("Forcing Primary Group to 'Domain Users' for %s\n",
     1737                  username));
     1738
     1739        sid_compose(group_sid, get_global_sam_sid(), DOMAIN_RID_USERS);
     1740
     1741done:
     1742        *_pwd = talloc_move(mem_ctx, &pwd);
     1743        *_group_sid = talloc_move(mem_ctx, &group_sid);
     1744        TALLOC_FREE(tmp_ctx);
     1745        return NT_STATUS_OK;
     1746}
     1747
     1748bool delete_uid_cache(uid_t puid)
     1749{
     1750        DATA_BLOB uid = data_blob_const(&puid, sizeof(puid));
     1751        DATA_BLOB sid;
     1752
     1753        if (!memcache_lookup(NULL, UID_SID_CACHE, uid, &sid)) {
     1754                DEBUG(3, ("UID %d is not memcached!\n", (int)puid));
     1755                return false;
     1756        }
     1757        DEBUG(3, ("Delete mapping UID %d <-> %s from memcache\n", (int)puid,
     1758                  sid_string_dbg((struct dom_sid*)sid.data)));
     1759        memcache_delete(NULL, SID_UID_CACHE, sid);
     1760        memcache_delete(NULL, UID_SID_CACHE, uid);
     1761        return true;
     1762}
     1763
     1764bool delete_gid_cache(gid_t pgid)
     1765{
     1766        DATA_BLOB gid = data_blob_const(&pgid, sizeof(pgid));
     1767        DATA_BLOB sid;
     1768        if (!memcache_lookup(NULL, GID_SID_CACHE, gid, &sid)) {
     1769                DEBUG(3, ("GID %d is not memcached!\n", (int)pgid));
     1770                return false;
     1771        }
     1772        DEBUG(3, ("Delete mapping GID %d <-> %s from memcache\n", (int)pgid,
     1773                  sid_string_dbg((struct dom_sid*)sid.data)));
     1774        memcache_delete(NULL, SID_GID_CACHE, sid);
     1775        memcache_delete(NULL, GID_SID_CACHE, gid);
     1776        return true;
     1777}
     1778
     1779bool delete_sid_cache(const struct dom_sid* psid)
     1780{
     1781        DATA_BLOB sid = data_blob_const(psid, ndr_size_dom_sid(psid, 0));
     1782        DATA_BLOB id;
     1783        if (memcache_lookup(NULL, SID_GID_CACHE, sid, &id)) {
     1784                DEBUG(3, ("Delete mapping %s <-> GID %d from memcache\n",
     1785                          sid_string_dbg(psid), *(int*)id.data));
     1786                memcache_delete(NULL, SID_GID_CACHE, sid);
     1787                memcache_delete(NULL, GID_SID_CACHE, id);
     1788        } else if (memcache_lookup(NULL, SID_UID_CACHE, sid, &id)) {
     1789                DEBUG(3, ("Delete mapping %s <-> UID %d from memcache\n",
     1790                          sid_string_dbg(psid), *(int*)id.data));
     1791                memcache_delete(NULL, SID_UID_CACHE, sid);
     1792                memcache_delete(NULL, UID_SID_CACHE, id);
     1793        } else {
     1794                DEBUG(3, ("SID %s is not memcached!\n", sid_string_dbg(psid)));
     1795                return false;
     1796        }
     1797        return true;
     1798}
     1799
     1800void flush_gid_cache(void)
     1801{
     1802        DEBUG(3, ("Flush GID <-> SID memcache\n"));
     1803        memcache_flush(NULL, SID_GID_CACHE);
     1804        memcache_flush(NULL, GID_SID_CACHE);
     1805}
     1806
     1807void flush_uid_cache(void)
     1808{
     1809        DEBUG(3, ("Flush UID <-> SID memcache\n"));
     1810        memcache_flush(NULL, SID_UID_CACHE);
     1811        memcache_flush(NULL, UID_SID_CACHE);
     1812}
Note: See TracChangeset for help on using the changeset viewer.