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/winbindd/winbindd_cache.c

    r599 r745  
    2525
    2626#include "includes.h"
     27#include "system/filesys.h"
    2728#include "winbindd.h"
    2829#include "tdb_validate.h"
    2930#include "../libcli/auth/libcli_auth.h"
    3031#include "../librpc/gen_ndr/ndr_wbint.h"
     32#include "ads.h"
     33#include "nss_info.h"
     34#include "../libcli/security/security.h"
     35#include "passdb/machine_sid.h"
     36#include "util_tdb.h"
    3137
    3238#undef DBGC_CLASS
    3339#define DBGC_CLASS DBGC_WINBIND
    3440
    35 #define WINBINDD_CACHE_VERSION 1
     41#define WINBINDD_CACHE_VERSION 2
    3642#define WINBINDD_CACHE_VERSION_KEYSTR "WINBINDD_CACHE_VERSION"
    3743
     
    4147#endif
    4248extern struct winbindd_methods builtin_passdb_methods;
     49extern struct winbindd_methods sam_passdb_methods;
    4350
    4451/*
     
    93100        NTSTATUS status;
    94101        uint32 sequence_number;
     102        uint64_t timeout;
    95103        uint8 *data;
    96104        uint32 len, ofs;
     
    103111static struct winbind_cache *wcache;
    104112
    105 void winbindd_check_cache_size(time_t t)
    106 {
    107         static time_t last_check_time;
    108         struct stat st;
    109 
    110         if (last_check_time == (time_t)0)
    111                 last_check_time = t;
    112 
    113         if (t - last_check_time < 60 && t - last_check_time > 0)
    114                 return;
    115 
    116         if (wcache == NULL || wcache->tdb == NULL) {
    117                 DEBUG(0, ("Unable to check size of tdb cache - cache not open !\n"));
    118                 return;
    119         }
    120 
    121         if (fstat(tdb_fd(wcache->tdb), &st) == -1) {
    122                 DEBUG(0, ("Unable to check size of tdb cache %s!\n", strerror(errno) ));
    123                 return;
    124         }
    125 
    126         if (st.st_size > WINBINDD_MAX_CACHE_SIZE) {
    127                 DEBUG(10,("flushing cache due to size (%lu) > (%lu)\n",
    128                         (unsigned long)st.st_size,
    129                         (unsigned long)WINBINDD_MAX_CACHE_SIZE));
    130                 wcache_flush_cache();
    131         }
    132 }
    133 
    134113/* get the winbind_cache structure */
    135114static struct winbind_cache *get_cache(struct winbindd_domain *domain)
     
    143122                domain->initialized = True;
    144123        }
     124
     125        if (strequal(domain->name, get_global_sam_name()) &&
     126            sid_check_is_domain(&domain->sid)) {
     127                domain->backend = &sam_passdb_methods;
     128                domain->initialized = True;
     129        }
     130
    145131        if ( !domain->initialized ) {
    146132                init_dc_connection( domain );
     
    224210
    225211/*
     212  pull a uint64_t from a cache entry
     213*/
     214static uint64_t centry_uint64_t(struct cache_entry *centry)
     215{
     216        uint64_t ret;
     217
     218        if (!centry_check_bytes(centry, 8)) {
     219                smb_panic_fn("centry_uint64_t");
     220        }
     221        ret = BVAL(centry->data, centry->ofs);
     222        centry->ofs += 8;
     223        return ret;
     224}
     225
     226/*
    226227  pull a uint32 from a cache entry
    227228*/
     
    277278        ret = IVAL(centry->data, centry->ofs);
    278279        centry->ofs += 4;
    279         ret += (uint64_t)IVAL(centry->data, centry->ofs) << 32;
     280        ret += (uint64)IVAL(centry->data, centry->ofs) << 32;
    280281        centry->ofs += 4;
    281282        return ret;
     
    615616
    616617        /* if the server is down or the cache entry is not older than the
    617            current sequence number then it is OK */
    618         if (wcache_server_down(domain) ||
    619             centry->sequence_number == domain->sequence_number) {
     618           current sequence number or it did not timeout then it is OK */
     619        if (wcache_server_down(domain)
     620            || ((centry->sequence_number == domain->sequence_number)
     621                && (centry->timeout > time(NULL)))) {
    620622                DEBUG(10,("centry_expired: Key %s for domain %s is good.\n",
    621623                        keystr, domain->name ));
     
    648650        centry->ofs = 0;
    649651
    650         if (centry->len < 8) {
     652        if (centry->len < 16) {
    651653                /* huh? corrupt cache? */
    652                 DEBUG(10,("wcache_fetch_raw: Corrupt cache for key %s (len < 8) ?\n", kstr));
     654                DEBUG(10,("wcache_fetch_raw: Corrupt cache for key %s "
     655                          "(len < 16)?\n", kstr));
    653656                centry_free(centry);
    654657                return NULL;
     
    657660        centry->status = centry_ntstatus(centry);
    658661        centry->sequence_number = centry_uint32(centry);
     662        centry->timeout = centry_uint64_t(centry);
    659663
    660664        return centry;
     665}
     666
     667static bool is_my_own_sam_domain(struct winbindd_domain *domain)
     668{
     669        if (strequal(domain->name, get_global_sam_name()) &&
     670            sid_check_is_domain(&domain->sid)) {
     671                return true;
     672        }
     673
     674        return false;
     675}
     676
     677static bool is_builtin_domain(struct winbindd_domain *domain)
     678{
     679        if (strequal(domain->name, "BUILTIN") &&
     680            sid_check_is_builtin(&domain->sid)) {
     681                return true;
     682        }
     683
     684        return false;
    661685}
    662686
     
    676700        struct cache_entry *centry;
    677701
    678         if (!winbindd_use_cache()) {
     702        if (!winbindd_use_cache() ||
     703            is_my_own_sam_domain(domain) ||
     704            is_builtin_domain(domain)) {
    679705                return NULL;
    680706        }
     
    743769
    744770/*
     771  push a uint64_t into a centry
     772*/
     773static void centry_put_uint64_t(struct cache_entry *centry, uint64_t v)
     774{
     775        centry_expand(centry, 8);
     776        SBVAL(centry->data, centry->ofs, v);
     777        centry->ofs += 8;
     778}
     779
     780/*
    745781  push a uint32 into a centry
    746782*/
     
    808844}
    809845
    810 static void centry_put_sid(struct cache_entry *centry, const DOM_SID *sid)
     846static void centry_put_sid(struct cache_entry *centry, const struct dom_sid *sid)
    811847{
    812848        fstring sid_string;
     
    863899        centry->ofs = 0;
    864900        centry->sequence_number = domain->sequence_number;
     901        centry->timeout = lp_winbind_cache_time() + time(NULL);
    865902        centry_put_ntstatus(centry, status);
    866903        centry_put_uint32(centry, centry->sequence_number);
     904        centry_put_uint64_t(centry, centry->timeout);
    867905        return centry;
    868906}
     
    896934static void wcache_save_name_to_sid(struct winbindd_domain *domain,
    897935                                    NTSTATUS status, const char *domain_name,
    898                                     const char *name, const DOM_SID *sid,
     936                                    const char *name, const struct dom_sid *sid,
    899937                                    enum lsa_SidType type)
    900938{
     
    916954
    917955static void wcache_save_sid_to_name(struct winbindd_domain *domain, NTSTATUS status,
    918                                     const DOM_SID *sid, const char *domain_name, const char *name, enum lsa_SidType type)
     956                                    const struct dom_sid *sid, const char *domain_name, const char *name, enum lsa_SidType type)
    919957{
    920958        struct cache_entry *centry;
     
    12131251}
    12141252
    1215 NTSTATUS wcache_cached_creds_exist(struct winbindd_domain *domain, const DOM_SID *sid)
     1253NTSTATUS wcache_cached_creds_exist(struct winbindd_domain *domain, const struct dom_sid *sid)
    12161254{
    12171255        struct winbind_cache *cache = get_cache(domain);
     
    12481286NTSTATUS wcache_get_creds(struct winbindd_domain *domain,
    12491287                          TALLOC_CTX *mem_ctx,
    1250                           const DOM_SID *sid,
     1288                          const struct dom_sid *sid,
    12511289                          const uint8 **cached_nt_pass,
    12521290                          const uint8 **cached_salt)
     
    13281366
    13291367NTSTATUS wcache_save_creds(struct winbindd_domain *domain,
    1330                            TALLOC_CTX *mem_ctx,
    1331                            const DOM_SID *sid,
     1368                           const struct dom_sid *sid,
    13321369                           const uint8 nt_pass[NT_HASH_LEN])
    13331370{
     
    15261563                                TALLOC_CTX *mem_ctx,
    15271564                                uint32 *num_entries,
    1528                                 struct acct_info **info)
     1565                                struct wb_acct_info **info)
    15291566{
    15301567        struct winbind_cache *cache = get_cache(domain);
     
    15481585                goto do_cached;
    15491586
    1550         (*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
     1587        (*info) = TALLOC_ARRAY(mem_ctx, struct wb_acct_info, *num_entries);
    15511588        if (! (*info)) {
    15521589                smb_panic_fn("enum_dom_groups out of memory");
     
    16211658                                TALLOC_CTX *mem_ctx,
    16221659                                uint32 *num_entries,
    1623                                 struct acct_info **info)
     1660                                struct wb_acct_info **info)
    16241661{
    16251662        struct winbind_cache *cache = get_cache(domain);
     
    16431680                goto do_cached;
    16441681
    1645         (*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
     1682        (*info) = TALLOC_ARRAY(mem_ctx, struct wb_acct_info, *num_entries);
    16461683        if (! (*info)) {
    16471684                smb_panic_fn("enum_dom_groups out of memory");
     
    17671804                            const char *name,
    17681805                            uint32_t flags,
    1769                             DOM_SID *sid,
     1806                            struct dom_sid *sid,
    17701807                            enum lsa_SidType *type)
    17711808{
     
    18761913static NTSTATUS sid_to_name(struct winbindd_domain *domain,
    18771914                            TALLOC_CTX *mem_ctx,
    1878                             const DOM_SID *sid,
     1915                            const struct dom_sid *sid,
    18791916                            char **domain_name,
    18801917                            char **name,
     
    19391976static NTSTATUS rids_to_names(struct winbindd_domain *domain,
    19401977                              TALLOC_CTX *mem_ctx,
    1941                               const DOM_SID *domain_sid,
     1978                              const struct dom_sid *domain_sid,
    19421979                              uint32 *rids,
    19431980                              size_t num_rids,
     
    19772014
    19782015        for (i=0; i<num_rids; i++) {
    1979                 DOM_SID sid;
     2016                struct dom_sid sid;
    19802017                struct cache_entry *centry;
    19812018                fstring tmp;
     
    20092046                        (*names)[i] = centry_string(centry, *names);
    20102047
    2011                 } else if (NT_STATUS_EQUAL(centry->status, NT_STATUS_NONE_MAPPED)) {
     2048                } else if (NT_STATUS_EQUAL(centry->status, NT_STATUS_NONE_MAPPED)
     2049                           || NT_STATUS_EQUAL(centry->status, STATUS_SOME_UNMAPPED)) {
    20122050                        have_unmapped = true;
    20132051
     
    20502088
    20512089                        for (i=0; i<num_rids; i++) {
    2052                                 DOM_SID sid;
     2090                                struct dom_sid sid;
    20532091                                struct cache_entry *centry;
    20542092                                fstring tmp;
     
    21102148        if (NT_STATUS_EQUAL(result, NT_STATUS_NONE_MAPPED)) {
    21112149                for (i = 0; i < num_rids; i++) {
    2112                         DOM_SID sid;
     2150                        struct dom_sid sid;
    21132151                        const char *name = "";
    21142152                        const enum lsa_SidType type = SID_NAME_UNKNOWN;
     
    21372175
    21382176        for (i=0; i<num_rids; i++) {
    2139                 DOM_SID sid;
     2177                struct dom_sid sid;
    21402178                NTSTATUS status;
    21412179
     
    22232261static NTSTATUS query_user(struct winbindd_domain *domain,
    22242262                           TALLOC_CTX *mem_ctx,
    2225                            const DOM_SID *user_sid,
     2263                           const struct dom_sid *user_sid,
    22262264                           struct wbint_userinfo *info)
    22272265{
     
    23322370static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
    23332371                                  TALLOC_CTX *mem_ctx,
    2334                                   const DOM_SID *user_sid,
    2335                                   uint32 *num_groups, DOM_SID **user_gids)
     2372                                  const struct dom_sid *user_sid,
     2373                                  uint32 *num_groups, struct dom_sid **user_gids)
    23362374{
    23372375        struct cache_entry *centry = NULL;
     
    24832521static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
    24842522                                   TALLOC_CTX *mem_ctx,
    2485                                    uint32 num_sids, const DOM_SID *sids,
     2523                                   uint32 num_sids, const struct dom_sid *sids,
    24862524                                   uint32 *num_aliases, uint32 **alias_rids)
    24872525{
     
    25872625        }
    25882626
    2589         *sid_mem = talloc_array(mem_ctx, DOM_SID, *num_names);
     2627        *sid_mem = talloc_array(mem_ctx, struct dom_sid, *num_names);
    25902628        *names = talloc_array(mem_ctx, char *, *num_names);
    25912629        *name_types = talloc_array(mem_ctx, uint32, *num_names);
     
    26162654static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
    26172655                                TALLOC_CTX *mem_ctx,
    2618                                 const DOM_SID *group_sid,
     2656                                const struct dom_sid *group_sid,
    26192657                                enum lsa_SidType type,
    26202658                                uint32 *num_names,
    2621                                 DOM_SID **sid_mem, char ***names,
     2659                                struct dom_sid **sid_mem, char ***names,
    26222660                                uint32 **name_types)
    26232661{
     
    29663004
    29673005void wcache_invalidate_samlogon(struct winbindd_domain *domain,
    2968                                 struct netr_SamInfo3 *info3)
    2969 {
    2970         DOM_SID sid;
     3006                                const struct dom_sid *sid)
     3007{
    29713008        fstring key_str, sid_string;
    29723009        struct winbind_cache *cache;
     
    29883025        }
    29893026
    2990         sid_copy(&sid, info3->base.domain_sid);
    2991         sid_append_rid(&sid, info3->base.rid);
    2992 
    29933027        /* Clear U/SID cache entry */
    2994         fstr_sprintf(key_str, "U/%s", sid_to_fstring(sid_string, &sid));
     3028        fstr_sprintf(key_str, "U/%s", sid_to_fstring(sid_string, sid));
    29953029        DEBUG(10, ("wcache_invalidate_samlogon: clearing %s\n", key_str));
    29963030        tdb_delete(cache->tdb, string_tdb_data(key_str));
    29973031
    29983032        /* Clear UG/SID cache entry */
    2999         fstr_sprintf(key_str, "UG/%s", sid_to_fstring(sid_string, &sid));
     3033        fstr_sprintf(key_str, "UG/%s", sid_to_fstring(sid_string, sid));
    30003034        DEBUG(10, ("wcache_invalidate_samlogon: clearing %s\n", key_str));
    30013035        tdb_delete(cache->tdb, string_tdb_data(key_str));
    30023036
    30033037        /* Samba/winbindd never needs this. */
    3004         netsamlogon_clear_cached_user(info3);
     3038        netsamlogon_clear_cached_user(sid);
    30053039}
    30063040
     
    30253059}
    30263060
     3061bool wcache_invalidate_cache_noinit(void)
     3062{
     3063        struct winbindd_domain *domain;
     3064
     3065        for (domain = domain_list(); domain; domain = domain->next) {
     3066                struct winbind_cache *cache;
     3067
     3068                /* Skip uninitialized domains. */
     3069                if (!domain->initialized && !domain->internal) {
     3070                        continue;
     3071                }
     3072
     3073                cache = get_cache(domain);
     3074
     3075                DEBUG(10, ("wcache_invalidate_cache: invalidating cache "
     3076                           "entries for %s\n", domain->name));
     3077                if (cache) {
     3078                        if (cache->tdb) {
     3079                                tdb_traverse(cache->tdb, traverse_fn, NULL);
     3080                                /*
     3081                                 * Flushing cache has nothing to with domains.
     3082                                 * return here if we successfully flushed once.
     3083                                 * To avoid unnecessary traversing the cache.
     3084                                 */
     3085                                return true;
     3086                        } else {
     3087                                return false;
     3088                        }
     3089                }
     3090        }
     3091        return true;
     3092}
     3093
    30273094bool init_wcache(void)
    30283095{
     
    30383105        wcache->tdb = tdb_open_log(cache_path("winbindd_cache.tdb"),
    30393106                                WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
    3040                                 lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST),
     3107                                TDB_INCOMPATIBLE_HASH |
     3108                                        (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)),
    30413109                                O_RDWR|O_CREAT, 0600);
    30423110
     
    31153183}
    31163184
    3117 bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
     3185bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
    31183186                       char **domain_name, char **name,
    31193187                       enum lsa_SidType *type)
     
    31313199}
    31323200
    3133 bool lookup_cached_name(TALLOC_CTX *mem_ctx,
    3134                         const char *domain_name,
     3201bool lookup_cached_name(const char *domain_name,
    31353202                        const char *name,
    3136                         DOM_SID *sid,
     3203                        struct dom_sid *sid,
    31373204                        enum lsa_SidType *type)
    31383205{
     
    31593226void cache_name2sid(struct winbindd_domain *domain,
    31603227                    const char *domain_name, const char *name,
    3161                     enum lsa_SidType type, const DOM_SID *sid)
     3228                    enum lsa_SidType type, const struct dom_sid *sid)
    31623229{
    31633230        refresh_sequence_number(domain, false);
     
    32113278        wcache->tdb = tdb_open_log(cache_path("winbindd_cache.tdb"),
    32123279                                WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
    3213                                 lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST),
     3280                                TDB_INCOMPATIBLE_HASH |
     3281                                (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)),
    32143282                                O_RDWR|O_CREAT, 0600);
    32153283
     
    32843352}
    32853353
    3286 NTSTATUS wcache_remove_oldest_cached_creds(struct winbindd_domain *domain, const DOM_SID *sid)
     3354NTSTATUS wcache_remove_oldest_cached_creds(struct winbindd_domain *domain, const struct dom_sid *sid)
    32873355{
    32883356        struct winbind_cache *cache = get_cache(domain);
     
    34493517        centry->ofs = 0;
    34503518
    3451         if (centry->len < 8) {
     3519        if (centry->len < 16) {
    34523520                /* huh? corrupt cache? */
    3453                 DEBUG(0,("create_centry_validate: Corrupt cache for key %s (len < 8) ?\n", kstr));
     3521                DEBUG(0,("create_centry_validate: Corrupt cache for key %s "
     3522                         "(len < 16) ?\n", kstr));
    34543523                centry_free(centry);
    34553524                state->bad_entry = true;
     
    34603529        centry->status = NT_STATUS(centry_uint32(centry));
    34613530        centry->sequence_number = centry_uint32(centry);
     3531        centry->timeout = centry_uint64_t(centry);
    34623532        return centry;
    34633533}
     
    34853555        (void)centry_uint32(centry);
    34863556        if (NT_STATUS_IS_OK(centry->status)) {
    3487                 DOM_SID sid;
     3557                struct dom_sid sid;
    34883558                (void)centry_sid(centry, &sid);
    34893559        }
     
    35253595{
    35263596        struct cache_entry *centry = create_centry_validate(keystr, dbuf, state);
    3527         DOM_SID sid;
     3597        struct dom_sid sid;
    35283598
    35293599        if (!centry) {
     
    36333703
    36343704        for (i=0; i< num_entries; i++) {
    3635                 DOM_SID sid;
     3705                struct dom_sid sid;
    36363706                (void)centry_string(centry, mem_ctx);
    36373707                (void)centry_string(centry, mem_ctx);
     
    36913761
    36923762        for (i=0; i< num_groups; i++) {
    3693                 DOM_SID sid;
     3763                struct dom_sid sid;
    36943764                centry_sid(centry, &sid);
    36953765        }
     
    37423812
    37433813        for (i=0; i< num_names; i++) {
    3744                 DOM_SID sid;
     3814                struct dom_sid sid;
    37453815                centry_sid(centry, &sid);
    37463816                (void)centry_string(centry, mem_ctx);
     
    40294099        tdb = tdb_open_log(tdb_path,
    40304100                           WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
     4101                           TDB_INCOMPATIBLE_HASH |
    40314102                           ( lp_winbind_offline_logon()
    40324103                             ? TDB_DEFAULT
     
    44734544}
    44744545
    4475 
    44764546/*********************************************************************
    44774547 ********************************************************************/
    44784548
     4549struct winbindd_tdc_domain*
     4550        wcache_tdc_fetch_domainbysid(TALLOC_CTX *ctx,
     4551                                     const struct dom_sid *sid)
     4552{
     4553        struct winbindd_tdc_domain *dom_list = NULL;
     4554        size_t num_domains = 0;
     4555        int i;
     4556        struct winbindd_tdc_domain *d = NULL;
     4557
     4558        DEBUG(10,("wcache_tdc_fetch_domainbysid: Searching for domain %s\n",
     4559                  sid_string_dbg(sid)));
     4560
     4561        if (!init_wcache()) {
     4562                return false;
     4563        }
     4564
     4565        /* fetch the list */
     4566
     4567        wcache_tdc_fetch_list(&dom_list, &num_domains);
     4568
     4569        for (i = 0; i<num_domains; i++) {
     4570                if (sid_equal(sid, &(dom_list[i].sid))) {
     4571                        DEBUG(10, ("wcache_tdc_fetch_domainbysid: "
     4572                                   "Found domain %s for SID %s\n",
     4573                                   dom_list[i].domain_name,
     4574                                   sid_string_dbg(sid)));
     4575
     4576                        d = TALLOC_P(ctx, struct winbindd_tdc_domain);
     4577                        if (!d)
     4578                                break;
     4579
     4580                        d->domain_name = talloc_strdup(d,
     4581                                                       dom_list[i].domain_name);
     4582
     4583                        d->dns_name = talloc_strdup(d, dom_list[i].dns_name);
     4584                        sid_copy(&d->sid, &dom_list[i].sid);
     4585                        d->trust_flags = dom_list[i].trust_flags;
     4586                        d->trust_type = dom_list[i].trust_type;
     4587                        d->trust_attribs = dom_list[i].trust_attribs;
     4588
     4589                        break;
     4590                }
     4591        }
     4592
     4593        TALLOC_FREE(dom_list);
     4594
     4595        return d;
     4596}
     4597
     4598
     4599/*********************************************************************
     4600 ********************************************************************/
     4601
    44794602void wcache_tdc_clear( void )
    44804603{
     
    44934616static void wcache_save_user_pwinfo(struct winbindd_domain *domain,
    44944617                                    NTSTATUS status,
    4495                                     const DOM_SID *user_sid,
     4618                                    const struct dom_sid *user_sid,
    44964619                                    const char *homedir,
    44974620                                    const char *shell,
     
    45174640}
    45184641
     4642#ifdef HAVE_ADS
     4643
    45194644NTSTATUS nss_get_info_cached( struct winbindd_domain *domain,
    4520                               const DOM_SID *user_sid,
     4645                              const struct dom_sid *user_sid,
    45214646                              TALLOC_CTX *ctx,
    4522                               ADS_STRUCT *ads, LDAPMessage *msg,
    45234647                              const char **homedir, const char **shell,
    45244648                              const char **gecos, gid_t *p_gid)
     
    45524676do_query:
    45534677
    4554         nt_status = nss_get_info( domain->name, user_sid, ctx, ads, msg,
     4678        nt_status = nss_get_info( domain->name, user_sid, ctx,
    45554679                                  homedir, shell, gecos, p_gid );
    45564680
     
    45764700}
    45774701
     4702#endif
    45784703
    45794704/* the cache backend methods are exposed via this structure */
     
    46414766        bool ret = false;
    46424767
    4643         if (!wcache_opnum_cacheable(opnum)) {
     4768        if (!wcache_opnum_cacheable(opnum) ||
     4769            is_my_own_sam_domain(domain) ||
     4770            is_builtin_domain(domain)) {
    46444771                return false;
    46454772        }
     
    46584785                return false;
    46594786        }
    4660         if (data.dsize < 4) {
     4787        if (data.dsize < 12) {
    46614788                goto fail;
    46624789        }
     
    46644791        if (!is_domain_offline(domain)) {
    46654792                uint32_t entry_seqnum, dom_seqnum, last_check;
     4793                uint64_t entry_timeout;
    46664794
    46674795                if (!wcache_fetch_seqnum(domain->name, &dom_seqnum,
     
    46754803                        goto fail;
    46764804                }
    4677         }
    4678 
    4679         resp->data = (uint8_t *)talloc_memdup(mem_ctx, data.dptr + 4,
    4680                                               data.dsize - 4);
     4805                entry_timeout = BVAL(data.dptr, 4);
     4806                if (entry_timeout > time(NULL)) {
     4807                        DEBUG(10, ("Entry has timed out\n"));
     4808                        goto fail;
     4809                }
     4810        }
     4811
     4812        resp->data = (uint8_t *)talloc_memdup(mem_ctx, data.dptr + 12,
     4813                                              data.dsize - 12);
    46814814        if (resp->data == NULL) {
    46824815                DEBUG(10, ("talloc failed\n"));
    46834816                goto fail;
    46844817        }
    4685         resp->length = data.dsize - 4;
     4818        resp->length = data.dsize - 12;
    46864819
    46874820        ret = true;
     
    46964829        TDB_DATA key, data;
    46974830        uint32_t dom_seqnum, last_check;
    4698 
    4699         if (!wcache_opnum_cacheable(opnum)) {
     4831        uint64_t timeout;
     4832
     4833        if (!wcache_opnum_cacheable(opnum) ||
     4834            is_my_own_sam_domain(domain) ||
     4835            is_builtin_domain(domain)) {
    47004836                return;
    47014837        }
     
    47154851        }
    47164852
    4717         data.dsize = resp->length + 4;
     4853        timeout = time(NULL) + lp_winbind_cache_time();
     4854
     4855        data.dsize = resp->length + 12;
    47184856        data.dptr = talloc_array(key.dptr, uint8_t, data.dsize);
    47194857        if (data.dptr == NULL) {
     
    47224860
    47234861        SIVAL(data.dptr, 0, dom_seqnum);
    4724         memcpy(data.dptr+4, resp->data, resp->length);
     4862        SBVAL(data.dptr, 4, timeout);
     4863        memcpy(data.dptr + 12, resp->data, resp->length);
    47254864
    47264865        tdb_store(wcache->tdb, key, data, 0);
Note: See TracChangeset for help on using the changeset viewer.