nmbd/nmbd_mynames.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    NBT netbios routines and daemon - version 2
00004    Copyright (C) Andrew Tridgell 1994-1998
00005    Copyright (C) Luke Kenneth Casson Leighton 1994-1998
00006    Copyright (C) Jeremy Allison 1994-2003
00007    
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2 of the License, or
00011    (at your option) any later version.
00012    
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017    
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021    
00022 */
00023 
00024 #include "includes.h"
00025 
00026 extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
00027 
00028 /****************************************************************************
00029  Fail funtion when registering my netbios names.
00030 **************************************************************************/
00031 
00032 static void my_name_register_failed(struct subnet_record *subrec,
00033                               struct response_record *rrec, struct nmb_name *nmbname)
00034 {
00035         DEBUG(0,("my_name_register_failed: Failed to register my name %s on subnet %s.\n",
00036                 nmb_namestr(nmbname), subrec->subnet_name));
00037 }
00038 
00039 
00040 /****************************************************************************
00041   Add my workgroup and my given names to one subnet
00042   Also add the magic Samba names.
00043 **************************************************************************/
00044 
00045 void register_my_workgroup_one_subnet(struct subnet_record *subrec)
00046 {
00047         int i;
00048 
00049         struct work_record *work;
00050 
00051         /* Create the workgroup on the subnet. */
00052         if((work = create_workgroup_on_subnet(subrec, lp_workgroup(), 
00053                                               PERMANENT_TTL)) == NULL) {
00054                 DEBUG(0,("register_my_workgroup_and_names: Failed to create my workgroup %s on subnet %s. \
00055 Exiting.\n", lp_workgroup(), subrec->subnet_name));
00056                 return;
00057         }
00058 
00059         /* Each subnet entry, except for the wins_server_subnet has
00060            the magic Samba names. */
00061         add_samba_names_to_subnet(subrec);
00062 
00063         /* Register all our names including aliases. */
00064         for (i=0; my_netbios_names(i); i++) {
00065                 register_name(subrec, my_netbios_names(i),0x20,samba_nb_type,
00066                               NULL,
00067                               my_name_register_failed, NULL);
00068                 register_name(subrec, my_netbios_names(i),0x03,samba_nb_type,
00069                               NULL,
00070                               my_name_register_failed, NULL);
00071                 register_name(subrec, my_netbios_names(i),0x00,samba_nb_type,
00072                               NULL,
00073                               my_name_register_failed, NULL);
00074         }
00075         
00076         /* Initiate election processing, register the workgroup names etc. */
00077         initiate_myworkgroup_startup(subrec, work);
00078 }
00079 
00080 /*******************************************************************
00081  Utility function to add a name to the unicast subnet, or add in
00082  our IP address if it already exists.
00083 ******************************************************************/
00084 
00085 static void insert_refresh_name_into_unicast( struct subnet_record *subrec,
00086                                                 struct nmb_name *nmbname, uint16 nb_type )
00087 {
00088         struct name_record *namerec;
00089 
00090         if (!we_are_a_wins_client()) {
00091                 insert_permanent_name_into_unicast(subrec, nmbname, nb_type);
00092                 return;
00093         }
00094 
00095         if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) {
00096                 unstring name;
00097                 pull_ascii_nstring(name, sizeof(name), nmbname->name);
00098                 /* The name needs to be created on the unicast subnet. */
00099                 (void)add_name_to_subnet( unicast_subnet, name,
00100                                 nmbname->name_type, nb_type,
00101                                 MIN(lp_max_ttl(), MAX_REFRESH_TIME), SELF_NAME, 1, &subrec->myip);
00102         } else {
00103                 /* The name already exists on the unicast subnet. Add our local
00104                         IP for the given broadcast subnet to the name. */
00105                 add_ip_to_name_record( namerec, subrec->myip);
00106         }
00107 }
00108 
00109 /****************************************************************************
00110   Add my workgroup and my given names to the subnet lists.
00111   Also add the magic Samba names.
00112 **************************************************************************/
00113 
00114 BOOL register_my_workgroup_and_names(void)
00115 {
00116         struct subnet_record *subrec;
00117         int i;
00118 
00119         for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
00120                 register_my_workgroup_one_subnet(subrec);
00121         }
00122 
00123         /* We still need to add the magic Samba
00124                 names and the netbios names to the unicast subnet directly. This is
00125                 to allow unicast node status requests and queries to still work
00126                 in a broadcast only environment. */
00127 
00128         add_samba_names_to_subnet(unicast_subnet);
00129 
00130         for (i=0; my_netbios_names(i); i++) {
00131                 for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
00132                         /*
00133                          * Ensure all the IP addresses are added if we are multihomed.
00134                          */
00135                         struct nmb_name nmbname;
00136 
00137                         make_nmb_name(&nmbname, my_netbios_names(i),0x20);
00138                         insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
00139 
00140                         make_nmb_name(&nmbname, my_netbios_names(i),0x3);
00141                         insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
00142 
00143                         make_nmb_name(&nmbname, my_netbios_names(i),0x0);
00144                         insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
00145                 }
00146         }
00147 
00148         /*
00149          * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet
00150          * also for the same reasons.
00151          */
00152 
00153         for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
00154                 /*
00155                  * Ensure all the IP addresses are added if we are multihomed.
00156                  */
00157                 struct nmb_name nmbname;
00158 
00159                 make_nmb_name(&nmbname, lp_workgroup(), 0x0);
00160                 insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
00161 
00162                 make_nmb_name(&nmbname, lp_workgroup(), 0x1e);
00163                 insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
00164         }
00165 
00166         /*
00167          * We need to add the Samba names to the remote broadcast subnet,
00168          * as NT 4.x does directed broadcast requests to the *<0x0> name.
00169          */
00170 
00171         add_samba_names_to_subnet(remote_broadcast_subnet);
00172 
00173         return True;
00174 }
00175 
00176 /****************************************************************************
00177   Remove all the names we registered.
00178 **************************************************************************/
00179 
00180 void release_wins_names(void)
00181 {
00182         struct subnet_record *subrec = unicast_subnet;
00183         struct name_record *namerec, *nextnamerec;
00184 
00185         for (namerec = subrec->namelist; namerec; namerec = nextnamerec) {
00186                 nextnamerec = namerec->next;
00187                 if( (namerec->data.source == SELF_NAME)
00188                     && !NAME_IS_DEREGISTERING(namerec) )
00189                         release_name( subrec, namerec, standard_success_release,
00190                                       NULL, NULL);
00191         }
00192 }
00193 
00194 /*******************************************************************
00195   Refresh our registered names with WINS
00196 ******************************************************************/
00197 
00198 void refresh_my_names(time_t t)
00199 {
00200         struct name_record *namerec;
00201 
00202         if (wins_srv_count() < 1)
00203                 return;
00204 
00205         for (namerec = unicast_subnet->namelist; namerec; namerec = namerec->next) {
00206                 /* Each SELF name has an individual time to be refreshed. */
00207                 if ((namerec->data.source == SELF_NAME) &&
00208                     (namerec->data.refresh_time < t) &&
00209                     (namerec->data.death_time != PERMANENT_TTL)) {
00210                         /* We cheat here and pretend the refresh is going to be
00211                            successful & update the refresh times. This stops
00212                            multiple refresh calls being done. We actually
00213                            deal with refresh failure in the fail_fn.
00214                         */
00215                         if (!is_refresh_already_queued(unicast_subnet, namerec)) {
00216                                 wins_refresh_name(namerec);
00217                         }
00218                         namerec->data.death_time = t + lp_max_ttl();
00219                         namerec->data.refresh_time = t + MIN(lp_max_ttl()/2, MAX_REFRESH_TIME);
00220                 }
00221         }
00222 }

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