LCOV - code coverage report
Current view: top level - source3/nmbd - nmbd_logonnames.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 31 49 63.3 %
Date: 2024-04-21 15:09:00 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    NBT netbios routines and daemon - version 2
       4             :    Copyright (C) Andrew Tridgell 1994-1998
       5             :    Copyright (C) Luke Kenneth Casson Leighton 1994-1998
       6             :    Copyright (C) Jeremy Allison 1994-2003
       7             :    
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             :    
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "../librpc/gen_ndr/svcctl.h"
      25             : #include "nmbd/nmbd.h"
      26             : 
      27             : extern uint16_t samba_nb_type; /* Samba's NetBIOS type. */
      28             : 
      29             : /****************************************************************************
      30             :   Fail to become a Logon server on a subnet.
      31             : ****************************************************************************/
      32             : 
      33           0 : static void become_logon_server_fail(struct subnet_record *subrec,
      34             :                                       struct response_record *rrec,
      35             :                                       struct nmb_name *fail_name)
      36             : {
      37             :         unstring failname;
      38             :         struct work_record *work;
      39             :         struct server_record *servrec;
      40             : 
      41           0 :         pull_ascii_nstring(failname, sizeof(failname), fail_name->name);
      42           0 :         work = find_workgroup_on_subnet(subrec, failname);
      43           0 :         if(!work) {
      44           0 :                 DEBUG(0,("become_logon_server_fail: Error - cannot find \
      45             : workgroup %s on subnet %s\n", failname, subrec->subnet_name));
      46           0 :                 return;
      47             :         }
      48             : 
      49           0 :         if((servrec = find_server_in_workgroup( work, lp_netbios_name())) == NULL) {
      50           0 :                 DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \
      51             : in workgroup %s on subnet %s\n",
      52             :                         lp_netbios_name(), failname, subrec->subnet_name));
      53           0 :                 work->log_state = LOGON_NONE;
      54           0 :                 return;
      55             :         }
      56             : 
      57             :         /* Set the state back to LOGON_NONE. */
      58           0 :         work->log_state = LOGON_NONE;
      59             : 
      60           0 :         servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL;
      61             : 
      62           0 :         DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \
      63             : workgroup %s on subnet %s. Couldn't register name %s.\n",
      64             :                 work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
      65             : 
      66             : }
      67             : 
      68             : /****************************************************************************
      69             :   Become a Logon server on a subnet.
      70             :   ****************************************************************************/
      71             : 
      72          14 : static void become_logon_server_success(struct subnet_record *subrec,
      73             :                                         struct userdata_struct *userdata,
      74             :                                         struct nmb_name *registered_name,
      75             :                                         uint16_t nb_flags,
      76             :                                         int ttl, struct in_addr registered_ip)
      77             : {
      78             :         unstring reg_name;
      79             :         struct work_record *work;
      80             :         struct server_record *servrec;
      81             : 
      82          14 :         pull_ascii_nstring(reg_name, sizeof(reg_name), registered_name->name);
      83          14 :         work = find_workgroup_on_subnet( subrec, reg_name);
      84          14 :         if(!work) {
      85           0 :                 DEBUG(0,("become_logon_server_success: Error - cannot find \
      86             : workgroup %s on subnet %s\n", reg_name, subrec->subnet_name));
      87           0 :                 return;
      88             :         }
      89             : 
      90          14 :         if((servrec = find_server_in_workgroup( work, lp_netbios_name())) == NULL) {
      91           0 :                 DEBUG(0,("become_logon_server_success: Error - cannot find server %s \
      92             : in workgroup %s on subnet %s\n",
      93             :                         lp_netbios_name(), reg_name, subrec->subnet_name));
      94           0 :                 work->log_state = LOGON_NONE;
      95           0 :                 return;
      96             :         }
      97             : 
      98             :         /* Set the state in the workgroup structure. */
      99          14 :         work->log_state = LOGON_SRV; /* Become domain master. */
     100             : 
     101             :         /* Update our server status. */
     102          14 :         servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER);
     103             :         /* To allow Win95 policies to load we need to set type domain
     104             :                 controller.
     105             :         */
     106          14 :         servrec->serv.type |= SV_TYPE_DOMAIN_CTRL;
     107             : 
     108             :         /* Tell the namelist writer to write out a change. */
     109          14 :         subrec->work_changed = True;
     110             : 
     111             :         /*
     112             :          * Add the WORKGROUP<1C> name to the UNICAST subnet with the IP address
     113             :          * for this subnet so we will respond to queries on this name.
     114             :          */
     115             : 
     116             :         {
     117             :                 struct nmb_name nmbname;
     118          14 :                 make_nmb_name(&nmbname,lp_workgroup(),0x1c);
     119          14 :                 insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c);
     120             :         }
     121             : 
     122          14 :         DEBUG(0,("become_logon_server_success: Samba is now a logon server \
     123             : for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name));
     124             : }
     125             : 
     126             : /*******************************************************************
     127             :   Become a logon server by attempting to register the WORKGROUP<1c>
     128             :   group name.
     129             : ******************************************************************/
     130             : 
     131          14 : static void become_logon_server(struct subnet_record *subrec,
     132             :                                 struct work_record *work)
     133             : {
     134          14 :         DEBUG(2,("become_logon_server: Attempting to become logon server for workgroup %s \
     135             : on subnet %s\n", work->work_group,subrec->subnet_name));
     136             : 
     137          14 :         DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n",
     138             :                 work->work_group));
     139          14 :         work->log_state = LOGON_WAIT;
     140             : 
     141          14 :         register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP,
     142             :                         become_logon_server_success,
     143             :                         become_logon_server_fail, NULL);
     144          14 : }
     145             : 
     146             : /*****************************************************************************
     147             :   Add the internet group <1c> logon names by unicast and broadcast.
     148             :   ****************************************************************************/
     149             : 
     150          61 : void add_logon_names(void)
     151             : {
     152             :         struct subnet_record *subrec;
     153             : 
     154         122 :         for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
     155          61 :                 struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
     156             : 
     157          61 :                 if (work && (work->log_state == LOGON_NONE)) {
     158             :                         struct nmb_name nmbname;
     159          14 :                         make_nmb_name(&nmbname,lp_workgroup(),0x1c);
     160             : 
     161          14 :                         if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) {
     162          14 :                                 if( DEBUGLVL( 0 ) ) {
     163          14 :                                         dbgtext( "add_domain_logon_names:\n" );
     164          14 :                                         dbgtext( "Attempting to become logon server " );
     165          14 :                                         dbgtext( "for workgroup %s ", lp_workgroup() );
     166          14 :                                         dbgtext( "on subnet %s\n", subrec->subnet_name );
     167             :                                 }
     168          14 :                                 become_logon_server(subrec, work);
     169             :                         }
     170             :                 }
     171             :         }
     172          61 : }

Generated by: LCOV version 1.14