2 Unix SMB/CIFS implementation.
3 NBT netbios routines and daemon - version 2
4 Copyright (C) Jeremy Allison 1994-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 Handle lmhosts file reading.
27 /****************************************************************************
29 ****************************************************************************/
31 void load_lmhosts_file(const char *fname)
35 struct in_addr ipaddr;
36 XFILE *fp = startlmhosts( fname );
39 DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
40 fname, strerror(errno)));
44 while (getlmhostsent(fp, name, &name_type, &ipaddr) ) {
45 struct subnet_record *subrec = NULL;
46 enum name_source source = LMHOSTS_NAME;
48 /* We find a relevent subnet to put this entry on, then add it. */
49 /* Go through all the broadcast subnets and see if the mask matches. */
50 for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
51 if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip))
55 /* If none match add the name to the remote_broadcast_subnet. */
57 subrec = remote_broadcast_subnet;
60 /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
61 (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
62 (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
64 /* Add the given name type to the subnet namelist. */
65 (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
72 /****************************************************************************
73 Find a name read from the lmhosts file. We secretly check the names on
74 the remote_broadcast_subnet as if the name was added to a regular broadcast
75 subnet it will be found by normal name query processing.
76 ****************************************************************************/
78 bool find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp)
80 struct name_record *namerec;
84 if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, FIND_ANY_NAME))==NULL)
87 if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME))