r22045: As Volker noticed, skip_string's last argument is
[samba.git] / source3 / nmbd / nmbd_workgroupdb.c
index 3efef49c042deb8e24a6cabd6146e8b98b1dcf16..ca665bdf4f5ef5366a99dd22b584061293f6ecc7 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "includes.h"
 
-extern int ClientNMB;
-
 extern uint16 samba_nb_type;
 
 int workgroup_count = 0; /* unique index key: one for each workgroup */
@@ -40,6 +38,27 @@ static void add_workgroup(struct subnet_record *subrec, struct work_record *work
        subrec->work_changed = True;
 }
 
+/****************************************************************************
+ Copy name to unstring. Used by create_workgroup() and find_workgroup_on_subnet().
+**************************************************************************/
+
+static void name_to_unstring(unstring unname, const char *name)
+{
+        nstring nname;
+
+       errno = 0;
+       push_ascii_nstring(nname, name);
+       if (errno == E2BIG) {
+               unstring tname;
+               pull_ascii_nstring(tname, sizeof(tname), nname);
+               unstrcpy(unname, tname);
+               DEBUG(0,("name_to_nstring: workgroup name %s is too long. Truncating to %s\n",
+                       name, tname));
+       } else {
+               unstrcpy(unname, name);
+       }
+}
+               
 /****************************************************************************
   Create an empty workgroup.
 **************************************************************************/
@@ -48,27 +67,16 @@ static struct work_record *create_workgroup(const char *name, int ttl)
 {
        struct work_record *work;
        struct subnet_record *subrec;
-        nstring nname;
-                                                                                                                         
        int t = -1;
   
-       if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) {
+       if((work = SMB_MALLOC_P(struct work_record)) == NULL) {
                DEBUG(0,("create_workgroup: malloc fail !\n"));
                return NULL;
        }
        memset((char *)work, '\0', sizeof(*work));
 
-        errno = 0;
-        push_ascii_nstring(nname, name);
-        if (errno == E2BIG) {
-               fstring tname;
-                pull_ascii_nstring(tname, sizeof(tname), nname);
-               fstrcpy(work->work_group,tname);
-                DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n",
-                       name, tname));
-        } else {
-               fstrcpy(work->work_group,name);
-        }
+       name_to_unstring(work->work_group, name);
+
        work->serverlist = NULL;
   
        work->RunningElection = False;
@@ -157,12 +165,15 @@ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec,
                                              const char *name)
 {
        struct work_record *ret;
-  
+       unstring un_name;
        DEBUG(4, ("find_workgroup_on_subnet: workgroup search for %s on subnet %s: ",
                name, subrec->subnet_name));
   
+       name_to_unstring(un_name, name);
+
        for (ret = subrec->workgrouplist; ret; ret = ret->next) {
-               if (strequal(ret->work_group,name)) {
+               if (strequal(ret->work_group,un_name)) {
                        DEBUGADD(4, ("found.\n"));
                        return(ret);
                }
@@ -309,7 +320,7 @@ void expire_workgroups_and_servers(time_t t)
                        expire_servers(work, t);
 
                        if ((work->serverlist == NULL) && (work->death_time != PERMANENT_TTL) && 
-                                       ((t == -1) || (work->death_time < t))) {
+                                       ((t == (time_t)-1) || (work->death_time < t))) {
                                DEBUG(3,("expire_workgroups_and_servers: Removing timed out workgroup %s\n",
                                                work->work_group));
                                remove_workgroup_from_subnet(subrec, work);