2 Unix SMB/Netbios implementation.
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 /* We *must have REPLACE_GETPASS defined here before the includes. */
24 #define REPLACE_GETPASS
27 extern int DEBUGLEVEL
;
29 extern pstring myname
;
32 extern int max_protocol
;
33 extern struct in_addr dest_ip
;
40 extern pstring workgroup
;
41 extern pstring service
;
42 extern pstring desthost
;
43 extern BOOL connect_as_ipc
;
45 /****************************************************************************
46 fudge for getpass function
47 ****************************************************************************/
48 char *getsmbpass(char *pass
)
50 return "dummy"; /* return anything: it should be ignored anyway */
53 /****************************************************************************
54 adds information retrieved from a NetServerEnum call
55 ****************************************************************************/
56 static BOOL
add_info(struct subnet_record
*d
, struct work_record
*work
, int servertype
)
66 /* now send a SMBtrans command with api ServerEnum? */
68 SSVAL(p
,0,0x68); /* api number */
77 SSVAL(p
,2,BUFFER_SIZE
- SAFETY_MARGIN
); /* buf length */
79 SIVAL(p
,0,servertype
);
82 pstrcpy(p
, work
->work_group
);
85 if (cli_call_api(PTR_DIFF(p
,param
),0, 8,BUFFER_SIZE
- SAFETY_MARGIN
,
86 &rprcnt
,&rdrcnt
, param
,NULL
,
89 int res
= SVAL(rparam
,0);
90 int converter
=SVAL(rparam
,2);
98 for (i
= 0;i
< count
;i
++, p
+= 26)
101 uint32 stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
102 int comment_offset
= IVAL(p
,22) & 0xFFFF;
103 char *cmnt
= comment_offset
?(rdata
+comment_offset
-converter
):"";
105 struct work_record
*w
= work
;
107 DEBUG(4, ("\t%-16.16s %08x %s\n", sname
, stype
, cmnt
));
109 if (stype
& SV_TYPE_DOMAIN_ENUM
)
111 /* creates workgroup on remote subnet */
112 if ((w
= find_workgroupstruct(d
,sname
,True
)))
114 announce_request(w
, d
->bcast_ip
);
119 add_server_entry(d
,w
,sname
,stype
,lp_max_ttl(),cmnt
,False
);
124 if (rparam
) free(rparam
);
125 if (rdata
) free(rdata
);
131 /*******************************************************************
132 synchronise browse lists with another browse server.
134 log in on the remote server's SMB port to their IPC$ service,
135 do a NetServerEnum and update our server and workgroup databases.
136 ******************************************************************/
137 void sync_browse_lists(struct subnet_record
*d
, struct work_record
*work
,
138 char *name
, int nm_type
, struct in_addr ip
, BOOL local
)
140 uint32 local_type
= local
? SV_TYPE_LOCAL_LIST_ONLY
: 0;
142 if (!d
|| !work
) return;
144 if(d
!= wins_subnet
) {
146 ("sync_browse_lists: ERROR sync requested on non-WINS subnet.\n"));
158 DEBUG(0,("sync_browse_lists: Sync browse lists with %s for %s %s\n",
159 name
, work
->work_group
, inet_ntoa(ip
)));
161 strcpy(workgroup
,work
->work_group
);
162 fstrcpy(desthost
,name
);
165 if (zero_ip(dest_ip
)) return;
168 connect_as_ipc
= True
;
170 /* connect as server and get domains, then servers */
172 sprintf(service
,"\\\\%s\\IPC$", name
);
175 if (cli_open_sockets(SMB_PORT
))
177 if (cli_send_login(NULL
,NULL
,True
,True
))
179 add_info(d
, work
, local_type
|SV_TYPE_DOMAIN_ENUM
);
181 add_info(d
, work
, SV_TYPE_LOCAL_LIST_ONLY
);
183 add_info(d
, work
, SV_TYPE_ALL
);