source: trunk/server/source3/nmbd/nmbd_lmhosts.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 3.4 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 NBT netbios routines and daemon - version 2
4 Copyright (C) Jeremy Allison 1994-1998
5
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.
10
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.
15
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/>.
18
19 Revision History:
20
21 Handle lmhosts file reading.
22
23*/
24
25#include "includes.h"
26#include "../libcli/nbt/libnbt.h"
27#include "nmbd/nmbd.h"
28
29/****************************************************************************
30Load a lmhosts file.
31****************************************************************************/
32
33void load_lmhosts_file(const char *fname)
34{
35 char *name = NULL;
36 int name_type;
37 struct sockaddr_storage ss;
38 TALLOC_CTX *ctx = talloc_init("load_lmhosts_file");
39 XFILE *fp = startlmhosts( fname );
40
41 if (!fp) {
42 DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
43 fname, strerror(errno)));
44 TALLOC_FREE(ctx);
45 return;
46 }
47
48 while (getlmhostsent(ctx, fp, &name, &name_type, &ss) ) {
49 struct in_addr ipaddr;
50 struct subnet_record *subrec = NULL;
51 enum name_source source = LMHOSTS_NAME;
52
53 if (ss.ss_family != AF_INET) {
54 TALLOC_FREE(name);
55 continue;
56 }
57
58 ipaddr = ((struct sockaddr_in *)&ss)->sin_addr;
59
60 /* We find a relevent subnet to put this entry on, then add it. */
61 /* Go through all the broadcast subnets and see if the mask matches. */
62 for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
63 if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip))
64 break;
65 }
66
67 /* If none match add the name to the remote_broadcast_subnet. */
68 if(subrec == NULL)
69 subrec = remote_broadcast_subnet;
70
71 if(name_type == -1) {
72 /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
73 (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
74 (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
75 } else {
76 /* Add the given name type to the subnet namelist. */
77 (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
78 }
79 }
80
81 TALLOC_FREE(ctx);
82 endlmhosts(fp);
83}
84
85/****************************************************************************
86 Find a name read from the lmhosts file. We secretly check the names on
87 the remote_broadcast_subnet as if the name was added to a regular broadcast
88 subnet it will be found by normal name query processing.
89****************************************************************************/
90
91bool find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp)
92{
93 struct name_record *namerec;
94
95 *namerecp = NULL;
96
97 if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, FIND_ANY_NAME))==NULL)
98 return False;
99
100 if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME))
101 return False;
102
103 *namerecp = namerec;
104 return True;
105}
Note: See TracBrowser for help on using the repository browser.