diff options
author | Volker Lendecke <vl@samba.org> | 2009-08-24 00:08:14 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2009-08-27 15:04:09 +0200 |
commit | 3532c8b9d831c8122de871db62d17608ff24f409 (patch) | |
tree | d632d714b6cb7c13fd6b1a8a59f94cccd9087415 /source3/winbindd | |
parent | 3f0c8772f15517134ef2c5805119f197aa1f69ed (diff) | |
download | samba-3532c8b9d831c8122de871db62d17608ff24f409.tar.gz samba-3532c8b9d831c8122de871db62d17608ff24f409.tar.bz2 samba-3532c8b9d831c8122de871db62d17608ff24f409.zip |
s3:winbind: Factor out wcache_fetch_seqnum
Diffstat (limited to 'source3/winbindd')
-rw-r--r-- | source3/winbindd/winbindd_cache.c | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c index c947254e81..0fab04c02a 100644 --- a/source3/winbindd/winbindd_cache.c +++ b/source3/winbindd/winbindd_cache.c @@ -392,30 +392,55 @@ static bool wcache_server_down(struct winbindd_domain *domain) return ret; } -static NTSTATUS fetch_cache_seqnum( struct winbindd_domain *domain, time_t now ) +static bool wcache_fetch_seqnum(const char *domain_name, uint32_t *seqnum, + uint32_t *last_seq_check) { + char *key; TDB_DATA data; - fstring key; - uint32 time_diff; - if (!wcache->tdb) { - DEBUG(10,("fetch_cache_seqnum: tdb == NULL\n")); - return NT_STATUS_UNSUCCESSFUL; + if (wcache->tdb == NULL) { + DEBUG(10,("wcache_fetch_seqnum: tdb == NULL\n")); + return false; } - fstr_sprintf( key, "SEQNUM/%s", domain->name ); - - data = tdb_fetch_bystring( wcache->tdb, key ); - if ( !data.dptr || data.dsize!=8 ) { - DEBUG(10,("fetch_cache_seqnum: invalid data size key [%s]\n", key )); - return NT_STATUS_UNSUCCESSFUL; + key = talloc_asprintf(talloc_tos(), "SEQNUM/%s", domain_name); + if (key == NULL) { + DEBUG(10, ("talloc failed\n")); + return false; } - domain->sequence_number = IVAL(data.dptr, 0); - domain->last_seq_check = IVAL(data.dptr, 4); + data = tdb_fetch_bystring(wcache->tdb, key); + TALLOC_FREE(key); + if (data.dptr == NULL) { + DEBUG(10, ("wcache_fetch_seqnum: %s not found\n", + domain_name)); + return false; + } + if (data.dsize != 8) { + DEBUG(10, ("wcache_fetch_seqnum: invalid data size %d\n", + (int)data.dsize)); + SAFE_FREE(data.dptr); + return false; + } + + *seqnum = IVAL(data.dptr, 0); + *last_seq_check = IVAL(data.dptr, 4); SAFE_FREE(data.dptr); + return true; +} + +static NTSTATUS fetch_cache_seqnum( struct winbindd_domain *domain, time_t now ) +{ + uint32 last_check, time_diff; + + if (!wcache_fetch_seqnum(domain->name, &domain->sequence_number, + &last_check)) { + return NT_STATUS_UNSUCCESSFUL; + } + domain->last_seq_check = last_check; + /* have we expired? */ time_diff = now - domain->last_seq_check; |