This commit was manufactured by cvs2svn to create tag
[Samba.git] / source / nmbsync.c
blobc1db37ff5ccd74a358283fd991fa1cca72efaf0a
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 NBT netbios routines to synchronise browse lists
5 Copyright (C) Andrew Tridgell 1994-1997
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
25 extern int DEBUGLEVEL;
27 static struct work_record *call_w;
28 static struct subnet_record *call_d;
30 /*******************************************************************
31 This is the NetServerEnum callback
32 ******************************************************************/
33 static void callback(char *sname, uint32 stype, char *comment)
35 struct work_record *w = call_w;
37 stype &= ~SV_TYPE_LOCAL_LIST_ONLY;
39 if (stype & SV_TYPE_DOMAIN_ENUM) {
40 /* creates workgroup on remote subnet */
41 if ((w = find_workgroupstruct(call_d,sname,True))) {
42 announce_request(w, call_d->bcast_ip);
46 if (w) {
47 add_server_entry(call_d,w,sname,stype,
48 lp_max_ttl(),comment,False);
53 /*******************************************************************
54 synchronise browse lists with another browse server.
56 log in on the remote server's SMB port to their IPC$ service,
57 do a NetServerEnum and update our server and workgroup databases.
58 ******************************************************************/
59 void sync_browse_lists(struct subnet_record *d, struct work_record *work,
60 char *name, int nm_type, struct in_addr ip, BOOL local)
62 extern fstring local_machine;
63 static struct cli_state cli;
64 uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0;
66 if (!d || !work ) return;
68 if(d != wins_client_subnet) {
69 DEBUG(0,("sync_browse_lists: ERROR sync requested on non-WINS subnet.\n"));
70 return;
73 DEBUG(2,("sync_browse_lists: Sync browse lists with %s for %s %s\n",
74 name, work->work_group, inet_ntoa(ip)));
76 if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) {
77 DEBUG(1,("Failed to start browse sync with %s\n", name));
80 if (!cli_session_request(&cli, name, nm_type, local_machine)) {
81 DEBUG(1,("%s rejected the browse sync session\n",name));
82 cli_shutdown(&cli);
83 return;
86 if (!cli_negprot(&cli)) {
87 DEBUG(1,("%s rejected the negprot\n",name));
88 cli_shutdown(&cli);
89 return;
92 if (!cli_session_setup(&cli, "", "", 1, "", 0, work->work_group)) {
93 DEBUG(1,("%s rejected the browse sync sessionsetup\n",
94 name));
95 cli_shutdown(&cli);
96 return;
99 if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
100 DEBUG(1,("%s refused browse sync IPC$ connect\n", name));
101 cli_shutdown(&cli);
102 return;
105 call_w = work;
106 call_d = d;
108 cli_NetServerEnum(&cli, work->work_group,
109 local_type|SV_TYPE_DOMAIN_ENUM,
110 callback);
112 cli_NetServerEnum(&cli, work->work_group,
113 local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL,
114 callback);
116 cli_shutdown(&cli);