modules: Add dependency on tirpc to vfs_nfs4acl_xattr
[samba.git] / source3 / nmbd / nmbd_lmhosts.c
index b14e13f3a47e15da9142148ad7b8d4a0eacd1b35..042d0430a35b9c3fbda43590b645224e58cfb7e6 100644 (file)
@@ -5,7 +5,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,
@@ -14,8 +14,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/>.
 
    Revision History:
 
 */
 
 #include "includes.h"
+#include "../libcli/nbt/libnbt.h"
+#include "nmbd/nmbd.h"
 
 /****************************************************************************
 Load a lmhosts file.
 ****************************************************************************/
 
-void load_lmhosts_file(char *fname)
-{  
-       pstring name;
+void load_lmhosts_file(const char *fname)
+{
+       char *name = NULL;
        int name_type;
-       struct in_addr ipaddr;
-       XFILE *fp = startlmhosts( fname );
+       struct sockaddr_storage ss;
+       TALLOC_CTX *ctx = talloc_init("load_lmhosts_file");
+       FILE *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(ipaddr, subrec->bcast_ip, subrec->mask_ip))
+                       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;
 
                if(name_type == -1) {
                        /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
-                       (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
-                       (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
+                       (void)add_name_to_subnet(subrec,name,0x00,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
+                       (void)add_name_to_subnet(subrec,name,0x20,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
                } else {
                        /* Add the given name type to the subnet namelist. */
-                       (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
+                       (void)add_name_to_subnet(subrec,name,name_type,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
                }
        }
-   
+
+       TALLOC_FREE(ctx);
        endlmhosts(fp);
 }
 
@@ -76,7 +88,7 @@ void load_lmhosts_file(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;