Changeset 751 for trunk/server/source3/winbindd/winbindd_cache.c
- Timestamp:
- Nov 29, 2012, 1:59:04 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/source3/winbindd/winbindd_cache.c
r745 r751 39 39 #define DBGC_CLASS DBGC_WINBIND 40 40 41 #define WINBINDD_CACHE_VERSION 2 41 #define WINBINDD_CACHE_VER1 1 /* initial db version */ 42 #define WINBINDD_CACHE_VER2 2 /* second version with timeouts for NDR entries */ 43 44 #define WINBINDD_CACHE_VERSION WINBINDD_CACHE_VER2 42 45 #define WINBINDD_CACHE_VERSION_KEYSTR "WINBINDD_CACHE_VERSION" 43 46 … … 4082 4085 } 4083 4086 4087 static int wbcache_update_centry_fn(TDB_CONTEXT *tdb, 4088 TDB_DATA key, 4089 TDB_DATA data, 4090 void *state) 4091 { 4092 uint64_t ctimeout; 4093 TDB_DATA blob; 4094 4095 if (is_non_centry_key(key)) { 4096 return 0; 4097 } 4098 4099 if (data.dptr == NULL || data.dsize == 0) { 4100 if (tdb_delete(tdb, key) < 0) { 4101 DEBUG(0, ("tdb_delete for [%s] failed!\n", 4102 key.dptr)); 4103 return 1; 4104 } 4105 } 4106 4107 /* add timeout to blob (uint64_t) */ 4108 blob.dsize = data.dsize + 8; 4109 4110 blob.dptr = SMB_XMALLOC_ARRAY(uint8_t, blob.dsize); 4111 if (blob.dptr == NULL) { 4112 return 1; 4113 } 4114 memset(blob.dptr, 0, blob.dsize); 4115 4116 /* copy status and seqnum */ 4117 memcpy(blob.dptr, data.dptr, 8); 4118 4119 /* add timeout */ 4120 ctimeout = lp_winbind_cache_time() + time(NULL); 4121 SBVAL(blob.dptr, 8, ctimeout); 4122 4123 /* copy the rest */ 4124 memcpy(blob.dptr + 16, data.dptr + 8, data.dsize - 8); 4125 4126 if (tdb_store(tdb, key, blob, TDB_REPLACE) < 0) { 4127 DEBUG(0, ("tdb_store to update [%s] failed!\n", 4128 key.dptr)); 4129 SAFE_FREE(blob.dptr); 4130 return 1; 4131 } 4132 4133 SAFE_FREE(blob.dptr); 4134 return 0; 4135 } 4136 4137 static bool wbcache_upgrade_v1_to_v2(TDB_CONTEXT *tdb) 4138 { 4139 int rc; 4140 4141 DEBUG(1, ("Upgrade to version 2 of the winbindd_cache.tdb\n")); 4142 4143 rc = tdb_traverse(tdb, wbcache_update_centry_fn, NULL); 4144 if (rc < 0) { 4145 return false; 4146 } 4147 4148 return true; 4149 } 4150 4084 4151 /*********************************************************************** 4085 4152 Try and validate every entry in the winbindd cache. If we fail here, … … 4092 4159 const char *tdb_path = cache_path("winbindd_cache.tdb"); 4093 4160 TDB_CONTEXT *tdb = NULL; 4161 uint32_t vers_id; 4162 bool ok; 4094 4163 4095 4164 DEBUG(10, ("winbindd_validate_cache: replacing panic function\n")); 4096 4165 smb_panic_fn = validate_panic; 4097 4098 4166 4099 4167 tdb = tdb_open_log(tdb_path, … … 4110 4178 goto done; 4111 4179 } 4180 4181 /* Version check and upgrade code. */ 4182 if (!tdb_fetch_uint32(tdb, WINBINDD_CACHE_VERSION_KEYSTR, &vers_id)) { 4183 DEBUG(10, ("Fresh database\n")); 4184 tdb_store_uint32(tdb, WINBINDD_CACHE_VERSION_KEYSTR, WINBINDD_CACHE_VERSION); 4185 vers_id = WINBINDD_CACHE_VERSION; 4186 } 4187 4188 if (vers_id != WINBINDD_CACHE_VERSION) { 4189 if (vers_id == WINBINDD_CACHE_VER1) { 4190 ok = wbcache_upgrade_v1_to_v2(tdb); 4191 if (!ok) { 4192 DEBUG(10, ("winbindd_validate_cache: upgrade to version 2 failed.\n")); 4193 unlink(tdb_path); 4194 goto done; 4195 } 4196 4197 tdb_store_uint32(tdb, 4198 WINBINDD_CACHE_VERSION_KEYSTR, 4199 WINBINDD_CACHE_VERSION); 4200 vers_id = WINBINDD_CACHE_VER2; 4201 } 4202 } 4203 4112 4204 tdb_close(tdb); 4113 4205 … … 4804 4896 } 4805 4897 entry_timeout = BVAL(data.dptr, 4); 4806 if ( entry_timeout > time(NULL)) {4898 if (time(NULL) > entry_timeout) { 4807 4899 DEBUG(10, ("Entry has timed out\n")); 4808 4900 goto fail;
Note:
See TracChangeset
for help on using the changeset viewer.