r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[tprouty/samba.git] / source / libsmb / namecache.c
index e3e7ac4e3c289e3cf40548bb7d83fa11b681d8c0..aeca5673c002d984db5708b45b7002c4f4c89c51 100644 (file)
@@ -8,7 +8,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -126,6 +125,10 @@ BOOL namecache_store(const char *name, int name_type,
         */
        if (!gencache_init()) return False;
 
+       if (name_type > 255) {
+               return False; /* Don't store non-real name types. */
+       }
+
        if ( DEBUGLEVEL >= 5 ) {
                DEBUG(5, ("namecache_store: storing %d address%s for %s#%02x: ",
                        num_names, num_names == 1 ? "": "es", name, name_type));
@@ -138,6 +141,10 @@ BOOL namecache_store(const char *name, int name_type,
        }
        
        key = namecache_key(name, name_type);
+       if (!key) {
+               return False;
+       }
+
        expiry = time(NULL) + lp_name_cache_timeout();
 
        /*
@@ -178,24 +185,29 @@ BOOL namecache_fetch(const char *name, int name_type, struct ip_service **ip_lis
        char *key, *value;
        time_t timeout;
 
-       *num_names = 0;
-
        /* exit now if null pointers were passed as they're required further */
        if (!ip_list || !num_names) return False;
 
        if (!gencache_init())
                return False;
 
+       if (name_type > 255) {
+               return False; /* Don't fetch non-real name types. */
+       }
+
+       *num_names = 0;
+
        /* 
         * Use gencache interface - lookup the key
         */
        key = namecache_key(name, name_type);
+       if (!key) {
+               return False;
+       }
 
        if (!gencache_get(key, &value, &timeout)) {
                DEBUG(5, ("no entry for %s#%02X found.\n", name, name_type));
-               gencache_del(key);
                SAFE_FREE(key);
-               SAFE_FREE(value);                
                return False;
        } else {
                DEBUG(5, ("name %s#%02X found.\n", name, name_type));
@@ -212,6 +224,31 @@ BOOL namecache_fetch(const char *name, int name_type, struct ip_service **ip_lis
        return *num_names > 0;          /* true only if some ip has been fetched */
 }
 
+/**
+ * Remove a namecache entry. Needed for site support.
+ *
+ **/
+
+BOOL namecache_delete(const char *name, int name_type)
+{
+       BOOL ret;
+       char *key;
+
+       if (!gencache_init())
+               return False;
+
+       if (name_type > 255) {
+               return False; /* Don't fetch non-real name types. */
+       }
+
+       key = namecache_key(name, name_type);
+       if (!key) {
+               return False;
+       }
+       ret = gencache_del(key);
+       SAFE_FREE(key);
+       return ret;
+}
 
 /**
  * Delete single namecache entry. Look at the
@@ -306,9 +343,7 @@ BOOL namecache_status_fetch(const char *keyname, int keyname_type,
 
        if (!gencache_get(key, &value, &timeout)) {
                DEBUG(5, ("namecache_status_fetch: no entry for %s found.\n", key));
-               gencache_del(key);
                SAFE_FREE(key);
-               SAFE_FREE(value);
                return False;
        } else {
                DEBUG(5, ("namecache_status_fetch: key %s -> %s\n", key, value ));