s3:winbind: Factor out wcache_store_seqnum()
authorVolker Lendecke <vl@samba.org>
Tue, 25 Aug 2009 09:26:14 +0000 (11:26 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 27 Aug 2009 13:04:09 +0000 (15:04 +0200)
source3/winbindd/winbindd_cache.c
source3/winbindd/winbindd_proto.h

index e8f928867b53e5d089c971a2368fb43f0d9c1bc2..cc1f095919c6e4a4fd82b48f3faeb23f17b4aa27 100644 (file)
@@ -458,34 +458,47 @@ static NTSTATUS fetch_cache_seqnum( struct winbindd_domain *domain, time_t now )
        return NT_STATUS_OK;
 }
 
-static NTSTATUS store_cache_seqnum( struct winbindd_domain *domain )
+bool wcache_store_seqnum(const char *domain_name, uint32_t seqnum,
+                        time_t last_seq_check)
 {
-       TDB_DATA data;
-       fstring key_str;
-       uint8 buf[8];
+       char *key_str;
+       uint8_t buf[8];
+       int ret;
 
-       if (!wcache->tdb) {
-               DEBUG(10,("store_cache_seqnum: tdb == NULL\n"));
-               return NT_STATUS_UNSUCCESSFUL;
+       if (wcache->tdb == NULL) {
+               DEBUG(10, ("wcache_store_seqnum: wcache->tdb == NULL\n"));
+               return false;
        }
 
-       fstr_sprintf( key_str, "SEQNUM/%s", domain->name );
+       key_str = talloc_asprintf(talloc_tos(), "SEQNUM/%s", domain_name);
+       if (key_str == NULL) {
+               DEBUG(10, ("talloc_asprintf failed\n"));
+               return false;
+       }
 
-       SIVAL(buf, 0, domain->sequence_number);
-       SIVAL(buf, 4, domain->last_seq_check);
-       data.dptr = buf;
-       data.dsize = 8;
+       SIVAL(buf, 0, seqnum);
+       SIVAL(buf, 4, last_seq_check);
 
-       if ( tdb_store_bystring( wcache->tdb, key_str, data, TDB_REPLACE) == -1 ) {
-               DEBUG(10,("store_cache_seqnum: tdb_store fail key [%s]\n", key_str ));
-               return NT_STATUS_UNSUCCESSFUL;
+       ret = tdb_store_bystring(wcache->tdb, key_str,
+                                make_tdb_data(buf, sizeof(buf)), TDB_REPLACE);
+       TALLOC_FREE(key_str);
+       if (ret == -1) {
+               DEBUG(10, ("tdb_store_bystring failed: %s\n",
+                          tdb_errorstr(wcache->tdb)));
+               TALLOC_FREE(key_str);
+               return false;
        }
 
-       DEBUG(10,("store_cache_seqnum: success [%s][%u @ %u]\n", 
-               domain->name, domain->sequence_number, 
-               (uint32)domain->last_seq_check));
+       DEBUG(10, ("wcache_store_seqnum: success [%s][%u @ %u]\n",
+                  domain_name, seqnum, (unsigned)last_seq_check));
 
-       return NT_STATUS_OK;
+       return true;
+}
+
+static bool store_cache_seqnum( struct winbindd_domain *domain )
+{
+       return wcache_store_seqnum(domain->name, domain->sequence_number,
+                                  domain->last_seq_check);
 }
 
 /*
index 3ab95c1ba64a2ca04827e78bcd2734deeeaa846c..3faf25a75124f930383228e940eb15d84c0dee89 100644 (file)
@@ -210,6 +210,8 @@ NTSTATUS nss_get_info_cached( struct winbindd_domain *domain,
                              ADS_STRUCT *ads, LDAPMessage *msg,
                              const char **homedir, const char **shell,
                              const char **gecos, gid_t *p_gid);
+bool wcache_store_seqnum(const char *domain_name, uint32_t seqnum,
+                        time_t last_seq_check);
 bool wcache_fetch_ndr(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain,
                      uint32_t opnum, const DATA_BLOB *req, DATA_BLOB *resp);
 void wcache_store_ndr(struct winbindd_domain *domain, uint32_t opnum,