diff options
author | Andrew Tridgell <tridge@samba.org> | 1997-10-26 07:32:02 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1997-10-26 07:32:02 +0000 |
commit | a342ff5bf407679918a1a5d0c2faaf0a3465d303 (patch) | |
tree | 99e7bf3368f00c21a04960598804bac4af516742 | |
parent | 326da272da002677c48e3ee7caae3c0b00da1bde (diff) | |
download | samba-a342ff5bf407679918a1a5d0c2faaf0a3465d303.tar.gz samba-a342ff5bf407679918a1a5d0c2faaf0a3465d303.tar.bz2 samba-a342ff5bf407679918a1a5d0c2faaf0a3465d303.zip |
The browse synchronisation code in nmbsync.c now uses the clientgen.c
code, which means we don't have to link with a fake getpass routine
and we don't have a whole pile of global variables that really have
nothing to do with nmbd and were there to keep the client code happy.
The code should function identically to what it did before (hopefully
it was correct)
The only thing that now uses the horrible clientutil.c code is
smbclient.
(This used to be commit 4bf5c03b18f88b566f3ac12cc4b3a9c5c96fd35d)
-rw-r--r-- | source3/client/clientutil.c | 9 | ||||
-rw-r--r-- | source3/include/proto.h | 9 | ||||
-rw-r--r-- | source3/libsmb/clientgen.c | 73 | ||||
-rw-r--r-- | source3/nmbsync.c | 228 |
4 files changed, 160 insertions, 159 deletions
diff --git a/source3/client/clientutil.c b/source3/client/clientutil.c index 9919f0a2d3..47cb78f0ce 100644 --- a/source3/client/clientutil.c +++ b/source3/client/clientutil.c @@ -683,12 +683,13 @@ BOOL cli_send_login(char *inbuf,char *outbuf,BOOL start_session,BOOL use_setup) uid = SVAL(inbuf,smb_uid); } - if (SVAL(inbuf, smb_vwv2) & 1) - DEBUG(1,("connected as guest ")); - if (sec_mode & 1) + if (sec_mode & 1) { + if (SVAL(inbuf, smb_vwv2) & 1) + DEBUG(1,("connected as guest ")); DEBUG(1,("security=user\n")); - else + } else { DEBUG(1,("security=share\n")); + } /* now we've got a connection - send a tcon message */ bzero(outbuf,smb_size); diff --git a/source3/include/proto.h b/source3/include/proto.h index 037438f97d..6489e87561 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -43,6 +43,8 @@ void cmd_help(void); /*The following definitions come from clientgen.c */ BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation); +BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype, + void (*fn)(char *, uint32, char *)); BOOL cli_session_setup(struct cli_state *cli, char *user, char *pass, int passlen, @@ -632,9 +634,8 @@ int main(int argc,char *argv[]); /*The following definitions come from nmbsync.c */ -char *getsmbpass(char *pass); void sync_browse_lists(struct subnet_record *d, struct work_record *work, - char *name, int nm_type, struct in_addr ip, BOOL local); + char *name, int nm_type, struct in_addr ip, BOOL local); /*The following definitions come from ntclient.c */ @@ -928,12 +929,12 @@ void make_arc4_owf(ARC4_OWF *hash, char data[16]); char* smb_io_arc4_owf(BOOL io, ARC4_OWF *hash, char *q, char *base, int align, int depth); void make_id_info1(DOM_ID_INFO_1 *id, char *domain_name, uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high, - char *user_name, char *workgroup_name, + char *user_name, char *wksta_name, char arc4_lm_owf[16], char arc4_nt_owf[16]); char* smb_io_id_info1(BOOL io, DOM_ID_INFO_1 *id, char *q, char *base, int align, int depth); void make_sam_info(DOM_SAM_INFO *sam, char *logon_srv, char *comp_name, DOM_CRED *clnt_cred, - DOM_CRED *rtn_cred, uint16 switch_value, uint16 logon_level, + DOM_CRED *rtn_cred, uint16 logon_level, uint16 switch_value, DOM_ID_INFO_1 *id1); char* smb_io_sam_info(BOOL io, DOM_SAM_INFO *sam, char *q, char *base, int align, int depth); char* smb_io_gid(BOOL io, DOM_GID *gid, char *q, char *base, int align, int depth); diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 7cd2ef6903..b6ad1611ac 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -313,6 +313,79 @@ BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation) } +/**************************************************************************** +call a NetServerEnum for the specified workgroup and servertype mask. +This function then calls the specified callback function for each name returned. + +The callback function takes 3 arguments: the machine name, the server type and +the comment. +****************************************************************************/ +BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype, + void (*fn)(char *, uint32, char *)) +{ + char *rparam = NULL; + char *rdata = NULL; + int rdrcnt,rprcnt; + char *p; + pstring param; + int uLevel = 1; + int count = -1; + + /* send a SMBtrans command with api NetServerEnum */ + p = param; + SSVAL(p,0,0x68); /* api number */ + p += 2; + strcpy(p,"WrLehDz"); + p = skip_string(p,1); + + strcpy(p,"B16BBDz"); + + p = skip_string(p,1); + SSVAL(p,0,uLevel); + SSVAL(p,2,BUFFER_SIZE); + p += 4; + SIVAL(p,0,stype); + p += 4; + + pstrcpy(p, workgroup); + p = skip_string(p,1); + + if (cli_api(cli, + PTR_DIFF(p,param), /* param count */ + 8, /*data count */ + 0, /* mprcount */ + BUFFER_SIZE, /* mdrcount */ + &rprcnt,&rdrcnt, + param, NULL, + &rparam,&rdata)) { + int res = SVAL(rparam,0); + int converter=SVAL(rparam,2); + int i; + + if (res == 0) { + count=SVAL(rparam,4); + p = rdata; + + for (i = 0;i < count;i++, p += 26) { + char *sname = p; + int comment_offset = IVAL(p,22) & 0xFFFF; + char *cmnt = comment_offset?(rdata+comment_offset-converter):""; + + stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY; + + fn(sname, stype, cmnt); + } + } + } + + if (rparam) free(rparam); + if (rdata) free(rdata); + + return(count > 0); +} + + + static struct { int prot; diff --git a/source3/nmbsync.c b/source3/nmbsync.c index e0c36d5961..5fa41e127a 100644 --- a/source3/nmbsync.c +++ b/source3/nmbsync.c @@ -20,117 +20,33 @@ */ -/* We *must have REPLACE_GETPASS defined here before the includes. */ -#define REPLACE_GETPASS #include "includes.h" extern int DEBUGLEVEL; -extern pstring myname; - -extern int name_type; -extern int max_protocol; -extern struct in_addr dest_ip; -extern int pid; -extern int gid; -extern int uid; -extern int mid; -extern BOOL got_pass; -extern BOOL have_ip; -extern pstring workgroup; -extern pstring service; -extern pstring desthost; -extern BOOL connect_as_ipc; - -/**************************************************************************** -fudge for getpass function -****************************************************************************/ -char *getsmbpass(char *pass) -{ - return "dummy"; /* return anything: it should be ignored anyway */ -} +static struct work_record *call_w; +static struct subnet_record *call_d; -/**************************************************************************** -adds information retrieved from a NetServerEnum call -****************************************************************************/ -static BOOL add_info(struct subnet_record *d, struct work_record *work, int servertype) +/******************************************************************* + This is the NetServerEnum callback + ******************************************************************/ +static void callback(char *sname, uint32 stype, char *comment) { - char *rparam = NULL; - char *rdata = NULL; - int rdrcnt,rprcnt; - char *p; - pstring param; - int uLevel = 1; - int count = -1; - - /* now send a SMBtrans command with api ServerEnum? */ - p = param; - SSVAL(p,0,0x68); /* api number */ - p += 2; - strcpy(p,"WrLehDz"); - p = skip_string(p,1); - - strcpy(p,"B16BBDz"); - - p = skip_string(p,1); - SSVAL(p,0,uLevel); - SSVAL(p,2,BUFFER_SIZE - SAFETY_MARGIN); /* buf length */ - p += 4; - SIVAL(p,0,servertype); - p += 4; - - pstrcpy(p, work->work_group); - p = skip_string(p,1); - - if (cli_call_api(PIPE_LANMAN, - PTR_DIFF(p,param), /* param count */ - 8, /*data count */ - 0, /* setup count */ - 0, /* mprcount - whatever that is */ - BUFFER_SIZE - SAFETY_MARGIN, /* mdrcount - whatever that is */ - &rprcnt,&rdrcnt, - param,NULL, NULL, - &rparam,&rdata)) - { - int res = SVAL(rparam,0); - int converter=SVAL(rparam,2); - int i; - - if (res == 0) - { - count=SVAL(rparam,4); - p = rdata; - - for (i = 0;i < count;i++, p += 26) - { - char *sname = p; - uint32 stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY; - int comment_offset = IVAL(p,22) & 0xFFFF; - char *cmnt = comment_offset?(rdata+comment_offset-converter):""; - - struct work_record *w = work; - - DEBUG(4, ("\t%-16.16s %08x %s\n", sname, stype, cmnt)); - - if (stype & SV_TYPE_DOMAIN_ENUM) - { - /* creates workgroup on remote subnet */ - if ((w = find_workgroupstruct(d,sname,True))) - { - announce_request(w, d->bcast_ip); - } + struct work_record *w = call_w; + + stype &= ~SV_TYPE_LOCAL_LIST_ONLY; + + if (stype & SV_TYPE_DOMAIN_ENUM) { + /* creates workgroup on remote subnet */ + if ((w = find_workgroupstruct(call_d,sname,True))) { + announce_request(w, call_d->bcast_ip); } + } - if (w) - add_server_entry(d,w,sname,stype,lp_max_ttl(),cmnt,False); - } + if (w) { + add_server_entry(call_d,w,sname,stype, + lp_max_ttl(),comment,False); } - } - - if (rparam) free(rparam); - if (rdata) free(rdata); - - return(True); } @@ -141,54 +57,64 @@ static BOOL add_info(struct subnet_record *d, struct work_record *work, int serv do a NetServerEnum and update our server and workgroup databases. ******************************************************************/ void sync_browse_lists(struct subnet_record *d, struct work_record *work, - char *name, int nm_type, struct in_addr ip, BOOL local) + char *name, int nm_type, struct in_addr ip, BOOL local) { - uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; - - if (!d || !work ) return; - - if(d != wins_client_subnet) { - DEBUG(0, - ("sync_browse_lists: ERROR sync requested on non-WINS subnet.\n")); - return; - } - - pid = getpid(); - uid = getuid(); - gid = getgid(); - mid = pid + 100; - name_type = nm_type; - - got_pass = True; - - DEBUG(0,("sync_browse_lists: Sync browse lists with %s for %s %s\n", - name, work->work_group, inet_ntoa(ip))); - - strcpy(workgroup,work->work_group); - fstrcpy(desthost,name); - dest_ip = ip; - - if (zero_ip(dest_ip)) return; - have_ip = True; - - connect_as_ipc = True; - - /* connect as server and get domains, then servers */ - - sprintf(service,"\\\\%s\\IPC$", name); - strupper(service); - - if (cli_open_sockets(SMB_PORT)) - { - if (cli_send_login(NULL,NULL,True,True)) - { - add_info(d, work, local_type|SV_TYPE_DOMAIN_ENUM); - if(local) - add_info(d, work, SV_TYPE_LOCAL_LIST_ONLY); - else - add_info(d, work, SV_TYPE_ALL); - } - - close_sockets(); - } + extern fstring local_machine; + fstring share; + static struct cli_state cli; + uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; + + if (!d || !work ) return; + + if(d != wins_client_subnet) { + DEBUG(0,("sync_browse_lists: ERROR sync requested on non-WINS subnet.\n")); + return; + } + + DEBUG(2,("sync_browse_lists: Sync browse lists with %s for %s %s\n", + name, work->work_group, inet_ntoa(ip))); + + if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) { + DEBUG(1,("Failed to start browse sync with %s\n", name)); + } + + if (!cli_session_request(&cli, name, nm_type, local_machine)) { + DEBUG(1,("%s rejected the browse sync session\n",name)); + cli_shutdown(&cli); + return; + } + + if (!cli_negprot(&cli)) { + DEBUG(1,("%s rejected the negprot\n",name)); + cli_shutdown(&cli); + return; + } + + if (!cli_session_setup(&cli, "", "", 1, "", 0, work->work_group)) { + DEBUG(1,("%s rejected the browse sync sessionsetup\n", + name)); + cli_shutdown(&cli); + return; + } + + sprintf(share,"\\\\%s\\IPC$", name); + + if (!cli_send_tconX(&cli, share, "IPC", "", 1)) { + DEBUG(1,("%s refused browse sync IPC$ connect\n", name)); + cli_shutdown(&cli); + return; + } + + call_w = work; + call_d = d; + + cli_NetServerEnum(&cli, work->work_group, + local_type|SV_TYPE_DOMAIN_ENUM, + callback); + + cli_NetServerEnum(&cli, work->work_group, + local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, + callback); + + cli_shutdown(&cli); } |