always compile before commit :-)
[Samba.git] / source / nmbd / nmbd_logonnames.c
blobc63de56a34a734bc57e2b68c50903366edfe9fcf
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1994-1998
7 Copyright (C) Jeremy Allison 1994-1998
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
27 extern int DEBUGLEVEL;
29 extern pstring global_myname;
30 extern fstring global_myworkgroup;
31 extern char **my_netbios_names;
32 extern struct in_addr ipzero;
33 extern struct in_addr allones_ip;
35 extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
37 /****************************************************************************
38 Fail to become a Logon server on a subnet.
39 ****************************************************************************/
40 static void become_logon_server_fail(struct subnet_record *subrec,
41 struct response_record *rrec,
42 struct nmb_name *fail_name)
44 struct work_record *work = find_workgroup_on_subnet(subrec, fail_name->name);
45 struct server_record *servrec;
47 if(!work)
49 DEBUG(0,("become_logon_server_fail: Error - cannot find \
50 workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name));
51 return;
54 if((servrec = find_server_in_workgroup( work, global_myname)) == NULL)
56 DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \
57 in workgroup %s on subnet %s\n",
58 global_myname, fail_name->name, subrec->subnet_name));
59 work->log_state = LOGON_NONE;
60 return;
63 /* Set the state back to LOGON_NONE. */
64 work->log_state = LOGON_NONE;
66 servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL;
68 DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \
69 workgroup %s on subnet %s. Couldn't register name %s.\n",
70 work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
74 /****************************************************************************
75 Become a Logon server on a subnet.
76 ****************************************************************************/
78 static void become_logon_server_success(struct subnet_record *subrec,
79 struct userdata_struct *userdata,
80 struct nmb_name *registered_name,
81 uint16 nb_flags,
82 int ttl, struct in_addr registered_ip)
84 struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name);
85 struct server_record *servrec;
87 if(!work)
89 DEBUG(0,("become_logon_server_success: Error - cannot find \
90 workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name));
91 return;
94 if((servrec = find_server_in_workgroup( work, global_myname)) == NULL)
96 DEBUG(0,("become_logon_server_success: Error - cannot find server %s \
97 in workgroup %s on subnet %s\n",
98 global_myname, registered_name->name, subrec->subnet_name));
99 work->log_state = LOGON_NONE;
100 return;
103 /* Set the state in the workgroup structure. */
104 work->log_state = LOGON_SRV; /* Become domain master. */
106 /* Update our server status. */
107 servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER);
108 /* To allow Win95 policies to load we need to set type domain
109 controller.
111 servrec->serv.type |= SV_TYPE_DOMAIN_CTRL;
113 /* Tell the namelist writer to write out a change. */
114 subrec->work_changed = True;
116 DEBUG(0,("become_logon_server_success: Samba is now a logon server \
117 for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name));
120 /*******************************************************************
121 Become a logon server by attempting to register the WORKGROUP<1c>
122 group name.
123 ******************************************************************/
125 static void become_logon_server(struct subnet_record *subrec,
126 struct work_record *work)
128 DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \
129 on subnet %s\n", work->work_group,subrec->subnet_name));
131 DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n",
132 work->work_group));
133 work->log_state = LOGON_WAIT;
135 register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP,
136 become_logon_server_success,
137 become_logon_server_fail, NULL);
140 /*****************************************************************************
141 Add the internet group <1c> logon names by unicast and broadcast.
142 ****************************************************************************/
143 void add_logon_names(void)
145 struct subnet_record *subrec;
147 for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
149 struct work_record *work = find_workgroup_on_subnet(subrec, global_myworkgroup);
151 if (work && (work->log_state == LOGON_NONE))
153 struct nmb_name nmbname;
154 make_nmb_name(&nmbname,global_myworkgroup,0x1c);
156 if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL)
158 if( DEBUGLVL( 0 ) )
160 dbgtext( "add_domain_logon_names:\n" );
161 dbgtext( "Attempting to become logon server " );
162 dbgtext( "for workgroup %s ", global_myworkgroup );
163 dbgtext( "on subnet %s\n", subrec->subnet_name );
165 become_logon_server(subrec, work);