r21976: make use of tdb_*_bystring() and string_term_tdb_data() in lib/
authorStefan Metzmacher <metze@samba.org>
Tue, 27 Mar 2007 09:59:32 +0000 (09:59 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:18:54 +0000 (12:18 -0500)
to avoid creating the TDB_DATA struct from strings "by hand"

metze
(This used to be commit c22b86595a502eb48c9d0038faee8a9ee41b8438)

source3/lib/gencache.c
source3/lib/privileges.c

index c58642553c09caf5fa0d4dc5f95644741beb04e8..d6f5584c12fd94b228ee364d9ad1db6de0bfdd64 100644 (file)
@@ -114,7 +114,7 @@ BOOL gencache_shutdown(void)
 BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
 {
        int ret;
-       TDB_DATA keybuf, databuf;
+       TDB_DATA databuf;
        char* valstr = NULL;
        
        /* fail completely if get null pointers passed */
@@ -130,16 +130,13 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
        if (!valstr)
                return False;
 
-       keybuf.dptr = CONST_DISCARD(char *, keystr);
-       keybuf.dsize = strlen(keystr)+1;
-       databuf.dptr = valstr;
-       databuf.dsize = strlen(valstr)+1;
+       databuf = string_term_tdb_data(valstr);
        DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
-                  " %s (%d seconds %s)\n", keybuf.dptr, value,ctime(&timeout),
+                  " %s (%d seconds %s)\n", keystr, value,ctime(&timeout),
                   (int)(timeout - time(NULL)), 
                   timeout > time(NULL) ? "ahead" : "in the past"));
 
-       ret = tdb_store(cache, keybuf, databuf, 0);
+       ret = tdb_store_bystring(cache, keystr, databuf, 0);
        SAFE_FREE(valstr);
        
        return ret == 0;
@@ -157,7 +154,6 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
 BOOL gencache_del(const char *keystr)
 {
        int ret;
-       TDB_DATA keybuf;
        
        /* fail completely if get null pointers passed */
        SMB_ASSERT(keystr);
@@ -168,10 +164,8 @@ BOOL gencache_del(const char *keystr)
                return False;
        }
 
-       keybuf.dptr = CONST_DISCARD(char *, keystr);
-       keybuf.dsize = strlen(keystr)+1;
        DEBUG(10, ("Deleting cache entry (key = %s)\n", keystr));
-       ret = tdb_delete(cache, keybuf);
+       ret = tdb_delete_bystring(cache, keystr);
        
        return ret == 0;
 }
@@ -192,7 +186,7 @@ BOOL gencache_del(const char *keystr)
 
 BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
 {
-       TDB_DATA keybuf, databuf;
+       TDB_DATA databuf;
        time_t t;
        char *endptr;
 
@@ -202,10 +196,8 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
        if (!gencache_init()) {
                return False;
        }
-       
-       keybuf.dptr = CONST_DISCARD(char *, keystr);
-       keybuf.dsize = strlen(keystr)+1;
-       databuf = tdb_fetch(cache, keybuf);
+
+       databuf = tdb_fetch_bystring(cache, keystr);
 
        if (databuf.dptr == NULL) {
                DEBUG(10, ("Cache entry with key = %s couldn't be found\n",
@@ -228,7 +220,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
        if (t <= time(NULL)) {
 
                /* We're expired, delete the entry */
-               tdb_delete(cache, keybuf);
+               tdb_delete_bystring(cache, keystr);
 
                SAFE_FREE(databuf.dptr);
                return False;
index c0f7857c95b8c231504a7b39035da86fb1b1dfc2..2348995dc85fd79ab8e00fbe3a2fdf2803fd424a 100644 (file)
@@ -237,7 +237,7 @@ static BOOL get_privileges( const DOM_SID *sid, SE_PRIV *mask )
 {
        TDB_CONTEXT *tdb = get_account_pol_tdb();
        fstring keystr;
-       TDB_DATA key, data;
+       TDB_DATA data;
 
        /* Fail if the admin has not enable privileges */
        
@@ -251,10 +251,8 @@ static BOOL get_privileges( const DOM_SID *sid, SE_PRIV *mask )
        /* PRIV_<SID> (NULL terminated) as the key */
        
        fstr_sprintf( keystr, "%s%s", PRIVPREFIX, sid_string_static(sid) );
-       key.dptr = keystr;
-       key.dsize = strlen(keystr) + 1;
 
-       data = tdb_fetch( tdb, key );
+       data = tdb_fetch_bystring( tdb, keystr );
        
        if ( !data.dptr ) {
                DEBUG(3,("get_privileges: No privileges assigned to SID [%s]\n",
@@ -278,7 +276,7 @@ static BOOL set_privileges( const DOM_SID *sid, SE_PRIV *mask )
 {
        TDB_CONTEXT *tdb = get_account_pol_tdb();
        fstring keystr;
-       TDB_DATA key, data;
+       TDB_DATA data;
        
        if ( !lp_enable_privileges() )
                return False;
@@ -294,15 +292,13 @@ static BOOL set_privileges( const DOM_SID *sid, SE_PRIV *mask )
        /* PRIV_<SID> (NULL terminated) as the key */
        
        fstr_sprintf( keystr, "%s%s", PRIVPREFIX, sid_string_static(sid) );
-       key.dptr = keystr;
-       key.dsize = strlen(keystr) + 1;
        
        /* no packing.  static size structure, just write it out */
        
        data.dptr  = (char*)mask;
        data.dsize = sizeof(SE_PRIV);
 
-       return ( tdb_store(tdb, key, data, TDB_REPLACE) != -1 );
+       return ( tdb_store_bystring(tdb, keystr, data, TDB_REPLACE) != -1 );
 }
 
 /****************************************************************************