2 Unix SMB/Netbios implementation.
4 NBT netbios routines to synchronise browse lists
5 Copyright (C) Andrew Tridgell 1994-1995
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.
28 extern int DEBUGLEVEL;
30 extern pstring myname;
31 extern struct in_addr bcast_ip;
32 extern struct in_addr Netmask;
35 extern int max_protocol;
36 extern struct in_addr dest_ip;
43 extern pstring workgroup;
44 extern pstring service;
45 extern pstring desthost;
46 extern BOOL connect_as_ipc;
48 /****************************************************************************
49 fudge for getpass function
50 ****************************************************************************/
51 char *getsmbpass(char *pass)
53 return "dummy"; /* return anything: it should be ignored anyway */
56 /****************************************************************************
57 adds information retrieved from a NetServerEnum call
58 ****************************************************************************/
59 static BOOL add_info(struct domain_record *d, struct work_record *work, int servertype)
69 /* now send a SMBtrans command with api ServerEnum? */
71 SSVAL(p,0,0x68); /* api number */
80 SSVAL(p,2,0x2000); /* buf length */
82 SIVAL(p,0,servertype);
85 strcpy(p, work->work_group);
88 if (cli_call_api(PTR_DIFF(p,param),0, 8,10000,
89 &rprcnt,&rdrcnt, param,NULL,
92 int res = SVAL(rparam,0);
93 int converter=SVAL(rparam,2);
101 for (i = 0;i < count;i++, p += 26)
104 uint32 stype = IVAL(p,18);
105 int comment_offset = IVAL(p,22) & 0xFFFF;
106 char *cmnt = comment_offset?(rdata+comment_offset-converter):"";
108 struct work_record *w = work;
110 DEBUG(4, ("\t%-16.16s %08x %s\n", sname, stype, cmnt));
112 if (stype & SV_TYPE_DOMAIN_ENUM)
114 /* creates workgroup on remote subnet */
115 if ((w = find_workgroupstruct(d,sname, False)))
117 if (ip_equal(bcast_ip, d->bcast_ip))
119 announce_request(w, d->bcast_ip);
124 add_server_entry(d,w,sname,stype,lp_max_ttl(),cmnt,False);
129 if (rparam) free(rparam);
130 if (rdata) free(rdata);
136 /*******************************************************************
137 synchronise browse lists with another browse server.
139 log in on the remote server's SMB port to their IPC$ service,
140 do a NetServerEnum and update our server and workgroup databases.
141 ******************************************************************/
142 void sync_browse_lists(struct work_record *work, char *name, int nm_type,
145 struct domain_record *d;
154 DEBUG(4, ("sync browse lists with %s for %s %s\n",
155 work->work_group, name, inet_ntoa(ip)));
157 strcpy(workgroup,work->work_group);
158 strcpy(desthost,name);
161 if (zero_ip(dest_ip)) return;
164 if (!(d = find_domain(ip))) return;
166 connect_as_ipc = True;
168 /* connect as server and get domains, then servers */
170 sprintf(service,"\\\\%s\\IPC$", name);
173 if (cli_open_sockets(SMB_PORT))
175 if (cli_send_login(NULL,NULL,True,True))
177 add_info(d, work, SV_TYPE_DOMAIN_ENUM);
178 add_info(d, work, SV_TYPE_ALL&~SV_TYPE_DOMAIN_ENUM);