nmbd/nmbd_logonnames.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 struct in_addr allones_ip;
00027 
00028 extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
00029 
00030 /****************************************************************************
00031   Fail to become a Logon server on a subnet.
00032 ****************************************************************************/
00033 
00034 static void become_logon_server_fail(struct subnet_record *subrec,
00035                                       struct response_record *rrec,
00036                                       struct nmb_name *fail_name)
00037 {
00038         unstring failname;
00039         struct work_record *work;
00040         struct server_record *servrec;
00041 
00042         pull_ascii_nstring(failname, sizeof(failname), fail_name->name);
00043         work = find_workgroup_on_subnet(subrec, failname);
00044         if(!work) {
00045                 DEBUG(0,("become_logon_server_fail: Error - cannot find \
00046 workgroup %s on subnet %s\n", failname, subrec->subnet_name));
00047                 return;
00048         }
00049 
00050         if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) {
00051                 DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \
00052 in workgroup %s on subnet %s\n",
00053                         global_myname(), failname, subrec->subnet_name));
00054                 work->log_state = LOGON_NONE;
00055                 return;
00056         }
00057 
00058         /* Set the state back to LOGON_NONE. */
00059         work->log_state = LOGON_NONE;
00060 
00061         servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL;
00062 
00063         DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \
00064 workgroup %s on subnet %s. Couldn't register name %s.\n",
00065                 work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
00066 
00067 }
00068 
00069 /****************************************************************************
00070   Become a Logon server on a subnet.
00071   ****************************************************************************/
00072 
00073 static void become_logon_server_success(struct subnet_record *subrec,
00074                                         struct userdata_struct *userdata,
00075                                         struct nmb_name *registered_name,
00076                                         uint16 nb_flags,
00077                                         int ttl, struct in_addr registered_ip)
00078 {
00079         unstring reg_name;
00080         struct work_record *work;
00081         struct server_record *servrec;
00082 
00083         pull_ascii_nstring(reg_name, sizeof(reg_name), registered_name->name);
00084         work = find_workgroup_on_subnet( subrec, reg_name);
00085         if(!work) {
00086                 DEBUG(0,("become_logon_server_success: Error - cannot find \
00087 workgroup %s on subnet %s\n", reg_name, subrec->subnet_name));
00088                 return;
00089         }
00090 
00091         if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) {
00092                 DEBUG(0,("become_logon_server_success: Error - cannot find server %s \
00093 in workgroup %s on subnet %s\n",
00094                         global_myname(), reg_name, subrec->subnet_name));
00095                 work->log_state = LOGON_NONE;
00096                 return;
00097         }
00098 
00099         /* Set the state in the workgroup structure. */
00100         work->log_state = LOGON_SRV; /* Become domain master. */
00101 
00102         /* Update our server status. */
00103         servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER);
00104         /* To allow Win95 policies to load we need to set type domain
00105                 controller.
00106         */
00107         servrec->serv.type |= SV_TYPE_DOMAIN_CTRL;
00108 
00109         /* Tell the namelist writer to write out a change. */
00110         subrec->work_changed = True;
00111 
00112         /*
00113          * Add the WORKGROUP<1C> name to the UNICAST subnet with the IP address
00114          * for this subnet so we will respond to queries on this name.
00115          */
00116 
00117         {
00118                 struct nmb_name nmbname;
00119                 make_nmb_name(&nmbname,lp_workgroup(),0x1c);
00120                 insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c);
00121         }
00122 
00123         DEBUG(0,("become_logon_server_success: Samba is now a logon server \
00124 for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name));
00125 }
00126 
00127 /*******************************************************************
00128   Become a logon server by attempting to register the WORKGROUP<1c>
00129   group name.
00130 ******************************************************************/
00131 
00132 static void become_logon_server(struct subnet_record *subrec,
00133                                 struct work_record *work)
00134 {
00135         DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \
00136 on subnet %s\n", work->work_group,subrec->subnet_name));
00137 
00138         DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n",
00139                 work->work_group));
00140         work->log_state = LOGON_WAIT;
00141 
00142         register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP,
00143                         become_logon_server_success,
00144                         become_logon_server_fail, NULL);
00145 }
00146 
00147 /*****************************************************************************
00148   Add the internet group <1c> logon names by unicast and broadcast.
00149   ****************************************************************************/
00150 
00151 void add_logon_names(void)
00152 {
00153         struct subnet_record *subrec;
00154 
00155         for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
00156                 struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
00157 
00158                 if (work && (work->log_state == LOGON_NONE)) {
00159                         struct nmb_name nmbname;
00160                         make_nmb_name(&nmbname,lp_workgroup(),0x1c);
00161 
00162                         if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) {
00163                                 if( DEBUGLVL( 0 ) ) {
00164                                         dbgtext( "add_domain_logon_names:\n" );
00165                                         dbgtext( "Attempting to become logon server " );
00166                                         dbgtext( "for workgroup %s ", lp_workgroup() );
00167                                         dbgtext( "on subnet %s\n", subrec->subnet_name );
00168                                 }
00169                                 become_logon_server(subrec, work);
00170                         }
00171                 }
00172         }
00173 }

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