nmbd/nmbd_lmhosts.c

説明を見る。
00001 /*
00002    Unix SMB/CIFS implementation.
00003    NBT netbios routines and daemon - version 2
00004    Copyright (C) Jeremy Allison 1994-1998
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 
00020    Revision History:
00021 
00022    Handle lmhosts file reading.
00023 
00024 */
00025 
00026 #include "includes.h"
00027 
00028 /****************************************************************************
00029 Load a lmhosts file.
00030 ****************************************************************************/
00031 
00032 void load_lmhosts_file(char *fname)
00033 {  
00034         pstring name;
00035         int name_type;
00036         struct in_addr ipaddr;
00037         XFILE *fp = startlmhosts( fname );
00038 
00039         if (!fp) {
00040                 DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
00041                         fname, strerror(errno)));
00042                 return;
00043         }
00044    
00045         while (getlmhostsent(fp, name, &name_type, &ipaddr) ) {
00046                 struct subnet_record *subrec = NULL;
00047                 enum name_source source = LMHOSTS_NAME;
00048 
00049                 /* We find a relevent subnet to put this entry on, then add it. */
00050                 /* Go through all the broadcast subnets and see if the mask matches. */
00051                 for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
00052                         if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
00053                                 break;
00054                 }
00055   
00056                 /* If none match add the name to the remote_broadcast_subnet. */
00057                 if(subrec == NULL)
00058                         subrec = remote_broadcast_subnet;
00059 
00060                 if(name_type == -1) {
00061                         /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
00062                         (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
00063                         (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
00064                 } else {
00065                         /* Add the given name type to the subnet namelist. */
00066                         (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
00067                 }
00068         }
00069    
00070         endlmhosts(fp);
00071 }
00072 
00073 /****************************************************************************
00074   Find a name read from the lmhosts file. We secretly check the names on
00075   the remote_broadcast_subnet as if the name was added to a regular broadcast
00076   subnet it will be found by normal name query processing.
00077 ****************************************************************************/
00078 
00079 BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp)
00080 {
00081         struct name_record *namerec;
00082 
00083         *namerecp = NULL;
00084 
00085         if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, FIND_ANY_NAME))==NULL)
00086                 return False;
00087 
00088         if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME))
00089                 return False;
00090 
00091         *namerecp = namerec;
00092         return True;
00093 }

Sambaに対してSat Aug 29 21:23:08 2009に生成されました。  doxygen 1.4.7