r23779: Change from v2 or later to v3 or later.
[samba.git] / source3 / lib / wins_srv.c
index 328350f2be7f4eb45522bbb6986540bf7366e5be..bbde3f85b8c492a9761a81fde38c588744c41549 100644 (file)
@@ -7,7 +7,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,
@@ -22,6 +22,8 @@
 
 #include "includes.h"
 
+extern struct in_addr loopback_ip;
+
 /*
   This is pretty much a complete rewrite of the earlier code. The main
   aim of the rewrite is to add support for having multiple wins server
 #define DEATH_TIME 600
 
 /* The list of dead wins servers is stored in gencache.tdb.  Each server is
-   marked dead m the point of view of a given source address. We keep a 
+   marked dead from the point of view of a given source address. We keep a 
    separate dead list for each src address to cope with multiple interfaces 
    that are not routable to each other.
   */
 
 #define WINS_SRV_FMT "WINS_SRV_DEAD/%s,%s" /* wins_ip,src_ip */
 
-/*
-  see if an ip is on the dead list
-*/
-
 static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip)
 {
-       char *keystr;
+       char *keystr = NULL, *wins_ip_addr = NULL, *src_ip_addr = NULL;
 
-       if (asprintf(&keystr, WINS_SRV_FMT, inet_ntoa(wins_ip),
-                    inet_ntoa(src_ip)) == -1) {
-               DEBUG(0, ("wins_srv_is_dead: malloc error\n"));
-               return NULL;
+       wins_ip_addr = SMB_STRDUP(inet_ntoa(wins_ip));
+       src_ip_addr = SMB_STRDUP(inet_ntoa(src_ip));
+
+       if ( !wins_ip_addr || !src_ip_addr ) {
+               DEBUG(0,("wins_srv_keystr: malloc error\n"));
+               goto done;
        }
 
+       if (asprintf(&keystr, WINS_SRV_FMT, wins_ip_addr, src_ip_addr) == -1) {
+               DEBUG(0, (": ns_srv_keystr: malloc error for key string\n"));
+       }
+
+done:
+       SAFE_FREE(wins_ip_addr);
+       SAFE_FREE(src_ip_addr);
+
        return keystr;
 }
 
+/*
+  see if an ip is on the dead list
+*/
+
 BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip)
 {
        char *keystr = wins_srv_keystr(wins_ip, src_ip);
@@ -202,9 +214,9 @@ char **wins_srv_tags(void)
        if (lp_wins_support()) {
                /* give the caller something to chew on. This makes
                   the rest of the logic simpler (ie. less special cases) */
-               ret = (char **)malloc(sizeof(char *)*2);
+               ret = SMB_MALLOC_ARRAY(char *, 2);
                if (!ret) return NULL;
-               ret[0] = strdup("*");
+               ret[0] = SMB_STRDUP("*");
                ret[1] = NULL;
                return ret;
        }
@@ -232,8 +244,11 @@ char **wins_srv_tags(void)
                }
 
                /* add it to the list */
-               ret = (char **)Realloc(ret, (count+2) * sizeof(char *));
-               ret[count] = strdup(t_ip.tag);
+               ret = SMB_REALLOC_ARRAY(ret, char *, count+2);
+               if (!ret) {
+                       return NULL;
+               }
+               ret[count] = SMB_STRDUP(t_ip.tag);
                if (!ret[count]) break;
                count++;
        }
@@ -270,7 +285,6 @@ struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip)
 
        /* if we are a wins server then we always just talk to ourselves */
        if (lp_wins_support()) {
-               extern struct in_addr loopback_ip;
                return loopback_ip;
        }