Merge branch 'v3-2-test' of ssh://jra@git.samba.org/data/git/samba into v3-2-test
[kai/samba.git] / source3 / nmbd / nmbd_lmhosts.c
index eba732941883cf0061d6408f93ee92006dfb6d37..75c03bb398ddde09de977c738524b83e3e4d18eb 100644 (file)
@@ -29,29 +29,39 @@ Load a lmhosts file.
 ****************************************************************************/
 
 void load_lmhosts_file(const char *fname)
-{  
-       pstring name;
+{
+       char *name = NULL;
        int name_type;
-       struct in_addr ipaddr;
+       struct sockaddr_storage ss;
+       TALLOC_CTX *ctx = talloc_init("load_lmhosts_file");
        XFILE *fp = startlmhosts( fname );
 
        if (!fp) {
                DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
                        fname, strerror(errno)));
+               TALLOC_FREE(ctx);
                return;
        }
-   
-       while (getlmhostsent(fp, name, &name_type, &ipaddr) ) {
+
+       while (getlmhostsent(ctx, fp, &name, &name_type, &ss) ) {
+               struct in_addr ipaddr;
                struct subnet_record *subrec = NULL;
                enum name_source source = LMHOSTS_NAME;
 
+               if (ss.ss_family != AF_INET) {
+                       TALLOC_FREE(name);
+                       continue;
+               }
+
+               ipaddr = ((struct sockaddr_in *)&ss)->sin_addr;
+
                /* We find a relevent subnet to put this entry on, then add it. */
                /* Go through all the broadcast subnets and see if the mask matches. */
                for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
                        if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip))
                                break;
                }
-  
+
                /* If none match add the name to the remote_broadcast_subnet. */
                if(subrec == NULL)
                        subrec = remote_broadcast_subnet;
@@ -65,7 +75,8 @@ void load_lmhosts_file(const char *fname)
                        (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
                }
        }
-   
+
+       TALLOC_FREE(ctx);
        endlmhosts(fp);
 }
 
@@ -75,7 +86,7 @@ void load_lmhosts_file(const char *fname)
   subnet it will be found by normal name query processing.
 ****************************************************************************/
 
-BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp)
+bool find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp)
 {
        struct name_record *namerec;