Ignore:
Timestamp:
Apr 25, 2007, 9:44:55 AM (14 years ago)
Author:
Paul Smedley
Message:

Code updated to Samba 3.0.25rc2 level

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/samba/source/nsswitch/winbindd_cache.c

    r1 r30  
    3030#define DBGC_CLASS DBGC_WINBIND
    3131
     32#define WINBINDD_CACHE_VERSION 1
     33#define WINBINDD_CACHE_VERSION_KEYSTR "WINBINDD_CACHE_VERSION"
     34
    3235extern struct winbindd_methods reconnect_methods;
    3336extern BOOL opt_nocache;
     
    3538extern struct winbindd_methods ads_methods;
    3639#endif
     40
     41/*
     42 * JRA. KEEP THIS LIST UP TO DATE IF YOU ADD CACHE ENTRIES.
     43 * Here are the list of entry types that are *not* stored
     44 * as form struct cache_entry in the cache.
     45 */
     46
     47static const char *non_centry_keys[] = {
     48        "SEQNUM/",
     49        "DR/",
     50        "DE/",
     51        "WINBINDD_OFFLINE",
     52        WINBINDD_CACHE_VERSION_KEYSTR,
     53        NULL
     54};
     55
     56/************************************************************************
     57 Is this key a non-centry type ?
     58************************************************************************/
     59
     60static BOOL is_non_centry_key(TDB_DATA kbuf)
     61{
     62        int i;
     63
     64        if (kbuf.dptr == NULL || kbuf.dsize == 0) {
     65                return False;
     66        }
     67        for (i = 0; non_centry_keys[i] != NULL; i++) {
     68                size_t namelen = strlen(non_centry_keys[i]);
     69                if (kbuf.dsize < namelen) {
     70                        continue;
     71                }
     72                if (strncmp(non_centry_keys[i], (const char *)kbuf.dptr, namelen) == 0) {
     73                        return True;
     74                }
     75        }
     76        return False;
     77}
    3778
    3879/* Global online/offline state - False when online. winbindd starts up online
     
    228269
    229270/*
    230   pull a time_t from a cache entry 
     271  pull a time_t from a cache entry. time_t stored portably as a 64-bit time.
    231272*/
    232273static time_t centry_time(struct cache_entry *centry)
    233274{
    234         time_t ret;
    235         if (centry->len - centry->ofs < sizeof(time_t)) {
    236                 DEBUG(0,("centry corruption? needed %u bytes, have %u\n",
    237                          (unsigned int)sizeof(time_t), (unsigned int)(centry->len - centry->ofs)));
    238                 smb_panic("centry_time");
    239         }
    240         ret = IVAL(centry->data, centry->ofs); /* FIXME: correct ? */
    241         centry->ofs += sizeof(time_t);
    242         return ret;
     275        return (time_t)centry_nttime(centry);
    243276}
    244277
     
    714747
    715748/*
    716   push a time_t into a centry
     749  push a time_t into a centry - use a 64 bit size.
     750  NTTIME here is being used as a convenient 64-bit size.
    717751*/
    718752static void centry_put_time(struct cache_entry *centry, time_t t)
    719753{
    720         centry_expand(centry, sizeof(time_t));
    721         SIVAL(centry->data, centry->ofs, t); /* FIXME: is this correct ?? */
    722         centry->ofs += sizeof(time_t);
     754        NTTIME nt = (NTTIME)t;
     755        centry_put_nttime(centry, nt);
    723756}
    724757
     
    21202153}
    21212154
    2122 BOOL init_wcache(void)
     2155static BOOL init_wcache(void)
    21232156{
    21242157        if (wcache == NULL) {
     
    21412174        }
    21422175
     2176        return True;
     2177}
     2178
     2179/************************************************************************
     2180 This is called by the parent to initialize the cache file.
     2181 We don't need sophisticated locking here as we know we're the
     2182 only opener.
     2183************************************************************************/
     2184
     2185BOOL initialize_winbindd_cache(void)
     2186{
     2187        BOOL cache_bad = True;
     2188        uint32 vers;
     2189
     2190        if (!init_wcache()) {
     2191                DEBUG(0,("initialize_winbindd_cache: init_wcache failed.\n"));
     2192                return False;
     2193        }
     2194
     2195        /* Check version number. */
     2196        if (tdb_fetch_uint32(wcache->tdb, WINBINDD_CACHE_VERSION_KEYSTR, &vers) &&
     2197                        vers == WINBINDD_CACHE_VERSION) {
     2198                cache_bad = False;
     2199        }
     2200
     2201        if (cache_bad) {
     2202                DEBUG(0,("initialize_winbindd_cache: clearing cache "
     2203                        "and re-creating with version number %d\n",
     2204                        WINBINDD_CACHE_VERSION ));
     2205
     2206                tdb_close(wcache->tdb);
     2207                wcache->tdb = NULL;
     2208
     2209                if (unlink(lock_path("winbindd_cache.tdb")) == -1) {
     2210                        DEBUG(0,("initialize_winbindd_cache: unlink %s failed %s ",
     2211                                lock_path("winbindd_cache.tdb"),
     2212                                strerror(errno) ));
     2213                        return False;
     2214                }
     2215                if (!init_wcache()) {
     2216                        DEBUG(0,("initialize_winbindd_cache: re-initialization "
     2217                                        "init_wcache failed.\n"));
     2218                        return False;
     2219                }
     2220
     2221                /* Write the version. */
     2222                if (!tdb_store_uint32(wcache->tdb, WINBINDD_CACHE_VERSION_KEYSTR, WINBINDD_CACHE_VERSION)) {
     2223                        DEBUG(0,("initialize_winbindd_cache: version number store failed %s\n",
     2224                                tdb_errorstr(wcache->tdb) ));
     2225                        return False;
     2226                }
     2227        }
     2228
     2229        tdb_close(wcache->tdb);
     2230        wcache->tdb = NULL;
    21432231        return True;
    21442232}
     
    23412429
    23422430/* delete all centries that don't have NT_STATUS_OK set */
     2431/*
     2432 * The original idea that this cache only contains centries has
     2433 * been blurred - now other stuff gets put in here. Ensure we
     2434 * ignore these things on cleanup.
     2435 */
     2436
    23432437static int traverse_fn_cleanup(TDB_CONTEXT *the_tdb, TDB_DATA kbuf,
    23442438                               TDB_DATA dbuf, void *state)
    23452439{
    23462440        struct cache_entry *centry;
     2441
     2442        if (is_non_centry_key(kbuf)) {
     2443                return 0;
     2444        }
    23472445
    23482446        centry = wcache_fetch_raw(kbuf.dptr);
Note: See TracChangeset for help on using the changeset viewer.