diff options
author | Jeremy Allison <jra@samba.org> | 2001-01-08 20:37:48 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2001-01-08 20:37:48 +0000 |
commit | 3a50ad16c5b51d0d812e50cfb65ff43a5786d131 (patch) | |
tree | 444489de7c547a2009316359f12e418ec5c39d6c /source/smbwrapper | |
parent | 4afc02447d4de9aaa329e4ec59d36f91716835c0 (diff) | |
download | samba-3a50ad16c5b51d0d812e50cfb65ff43a5786d131.tar.gz samba-3a50ad16c5b51d0d812e50cfb65ff43a5786d131.tar.xz samba-3a50ad16c5b51d0d812e50cfb65ff43a5786d131.zip |
Big merge to sync up appliance-head and 2.2.
Jeremy.
Diffstat (limited to 'source/smbwrapper')
-rw-r--r-- | source/smbwrapper/smbw.c | 138 | ||||
-rw-r--r-- | source/smbwrapper/smbw_dir.c | 36 | ||||
-rw-r--r-- | source/smbwrapper/smbw_stat.c | 24 |
3 files changed, 121 insertions, 77 deletions
diff --git a/source/smbwrapper/smbw.c b/source/smbwrapper/smbw.c index 07b450505ec..91009af1c58 100644 --- a/source/smbwrapper/smbw.c +++ b/source/smbwrapper/smbw.c @@ -79,6 +79,10 @@ void smbw_init(void) load_interfaces(); + if ((p=smbw_getshared("SERVICESF"))) { + pstrcpy(servicesf, p); + } + lp_load(servicesf,True,False,False); get_myname(global_myname); @@ -246,87 +250,106 @@ void clean_fname(char *name) } + +/***************************************************** +find a workgroup (any workgroup!) that has a master +browser on the local network +*******************************************************/ +static char *smbw_find_workgroup(void) +{ + fstring server; + char *p; + struct in_addr *ip_list = NULL; + int count = 0; + int i; + + /* first off see if an existing workgroup name exists */ + p = smbw_getshared("WORKGROUP"); + if (!p) p = lp_workgroup(); + + slprintf(server, sizeof(server), "%s#1D", p); + if (smbw_server(server, "IPC$")) return p; + + /* go looking for workgroups */ + if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) { + DEBUG(1,("No workgroups found!")); + return p; + } + + for (i=0;i<count;i++) { + static fstring name; + if (name_status_find(0x1d, ip_list[i], name)) { + slprintf(server, sizeof(server), "%s#1D", name); + if (smbw_server(server, "IPC$")) { + free(ip_list); + return name; + } + } + } + + free(ip_list); + + return p; +} + /***************************************************** parse a smb path into its components. +server is one of + 1) the name of the SMB server + 2) WORKGROUP#1D for share listing + 3) WORKGROUP#__ for workgroup listing +share is the share on the server to query +path is the SMB path on the server +return the full path (ie. add cwd if needed) *******************************************************/ char *smbw_parse_path(const char *fname, char *server, char *share, char *path) { static pstring s; - char *p, *p2; - int len = strlen(smbw_prefix)-1; - - *server = *share = *path = 0; + char *p; + int len; + fstring workgroup; - if (fname[0] == '/') { - pstrcpy(s, fname); + /* add cwd if necessary */ + if (fname[0] != '/') { + slprintf(s, sizeof(s), "%s/%s", smbw_cwd, fname); } else { - slprintf(s,sizeof(s)-1, "%s/%s", smbw_cwd, fname); + pstrcpy(s, fname); } clean_fname(s); - DEBUG(5,("cleaned %s (fname=%s cwd=%s)\n", - s, fname, smbw_cwd)); - + /* see if it has the right prefix */ + len = strlen(smbw_prefix)-1; if (strncmp(s,smbw_prefix,len) || (s[len] != '/' && s[len] != 0)) return s; - p = s + len; + /* ok, its for us. Now parse out the workgroup, share etc. */ + p = s+len; if (*p == '/') p++; - - p2 = strchr(p,'/'); - - if (p2) { - len = (int)(p2-p); - } else { - len = strlen(p); - } - - len = MIN(len,sizeof(fstring)-1); - - strncpy(server, p, len); - server[len] = 0; - - p = p2; - if (!p) { - if (len == 0) { - char *workgroup = smbw_getshared("WORKGROUP"); - if (!workgroup) workgroup = lp_workgroup(); - slprintf(server,sizeof(fstring)-1, "%s#1D", workgroup); - } + if (!next_token(&p, workgroup, "/", sizeof(fstring))) { + /* we're in /smb - give a list of workgroups */ + slprintf(server,sizeof(fstring), "%s#01", smbw_find_workgroup()); fstrcpy(share,"IPC$"); pstrcpy(path,""); - goto ok; + return s; } - p++; - p2 = strchr(p,'/'); - - if (p2) { - len = (int)(p2-p); - } else { - len = strlen(p); + if (!next_token(&p, server, "/", sizeof(fstring))) { + /* we are in /smb/WORKGROUP */ + slprintf(server,sizeof(fstring), "%s#1D", workgroup); + fstrcpy(share,"IPC$"); + pstrcpy(path,""); } - len = MIN(len,sizeof(fstring)-1); - - strncpy(share, p, len); - share[len] = 0; - - p = p2; - if (!p) { - pstrcpy(path,"\\"); - goto ok; + if (!next_token(&p, share, "/", sizeof(fstring))) { + /* we are in /smb/WORKGROUP/SERVER */ + fstrcpy(share,"IPC$"); + pstrcpy(path,""); } - pstrcpy(path,p); + pstrcpy(path, p); all_string_sub(path, "/", "\\", 0); - ok: - DEBUG(4,("parsed path name=%s cwd=%s [%s] [%s] [%s]\n", - fname, smbw_cwd, - server, share, path)); - return s; } @@ -437,7 +460,7 @@ struct smbw_server *smbw_server(char *server, char *share) ip = ipzero; ZERO_STRUCT(c); - + get_auth_data_fn(server, share, &workgroup, &username, &password); /* try to use an existing connection */ @@ -459,7 +482,8 @@ struct smbw_server *smbw_server(char *server, char *share) DEBUG(4,("server_n=[%s] server=[%s]\n", server_n, server)); - if ((p=strchr(server_n,'#')) && strcmp(p+1,"1D")==0) { + if ((p=strchr(server_n,'#')) && + (strcmp(p+1,"1D")==0 || strcmp(p+1,"01")==0)) { struct in_addr sip; pstring s; diff --git a/source/smbwrapper/smbw_dir.c b/source/smbwrapper/smbw_dir.c index 09294282736..89d137473f3 100644 --- a/source/smbwrapper/smbw_dir.c +++ b/source/smbwrapper/smbw_dir.c @@ -78,7 +78,7 @@ static struct smbw_dir *cur_dir; /***************************************************** add a entry to a directory listing *******************************************************/ -static void smbw_dir_add(struct file_info *finfo, const char *mask) +static void smbw_dir_add(struct file_info *finfo, const char *mask, void * NULL) { DEBUG(5,("%s\n", finfo->name)); @@ -100,7 +100,8 @@ static void smbw_dir_add(struct file_info *finfo, const char *mask) /***************************************************** add a entry to a directory listing *******************************************************/ -static void smbw_share_add(const char *share, uint32 type, const char *comment) +static void smbw_share_add(const char *share, uint32 type, + const char *comment, void *state) { struct file_info finfo; @@ -119,7 +120,7 @@ static void smbw_share_add(const char *share, uint32 type, const char *comment) add a server to a directory listing *******************************************************/ static void smbw_server_add(const char *name, uint32 type, - const char *comment) + const char *comment, void *state) { struct file_info finfo; @@ -199,36 +200,45 @@ int smbw_dir_open(const char *fname) slprintf(mask, sizeof(mask)-1, "%s\\*", path); all_string_sub(mask,"\\\\","\\",0); - if ((p=strstr(srv->server_name,"#1D"))) { + if ((p=strstr(srv->server_name,"#01"))) { + *p = 0; + smbw_server_add(".",0,"", NULL); + smbw_server_add("..",0,"", NULL); + cli_NetServerEnum(&srv->cli, srv->server_name, SV_TYPE_DOMAIN_ENUM, + smbw_server_add, NULL); + *p = '#'; + } else if ((p=strstr(srv->server_name,"#1D"))) { DEBUG(4,("doing NetServerEnum\n")); *p = 0; - smbw_server_add(".",0,""); - smbw_server_add("..",0,""); + smbw_server_add(".",0,"", NULL); + smbw_server_add("..",0,"", NULL); cli_NetServerEnum(&srv->cli, srv->server_name, SV_TYPE_ALL, - smbw_server_add); + smbw_server_add, NULL); *p = '#'; } else if (strcmp(srv->cli.dev,"IPC") == 0) { DEBUG(4,("doing NetShareEnum\n")); - smbw_share_add(".",0,""); - smbw_share_add("..",0,""); - if (cli_RNetShareEnum(&srv->cli, smbw_share_add) < 0) { + smbw_share_add(".",0,"", NULL); + smbw_share_add("..",0,"", NULL); + if (cli_RNetShareEnum(&srv->cli, smbw_share_add, NULL) < 0) { errno = smbw_errno(&srv->cli); goto failed; } } else if (strncmp(srv->cli.dev,"LPT",3) == 0) { - smbw_share_add(".",0,""); - smbw_share_add("..",0,""); + smbw_share_add(".",0,"", NULL); + smbw_share_add("..",0,"", NULL); if (cli_print_queue(&srv->cli, smbw_printjob_add) < 0) { errno = smbw_errno(&srv->cli); goto failed; } } else { +#if 0 if (strcmp(path,"\\") == 0) { smbw_share_add(".",0,""); smbw_share_add("..",0,""); } +#endif if (cli_list(&srv->cli, mask, aHIDDEN|aSYSTEM|aDIR, - smbw_dir_add) < 0) { + smbw_dir_add, NULL) < 0) { errno = smbw_errno(&srv->cli); goto failed; } diff --git a/source/smbwrapper/smbw_stat.c b/source/smbwrapper/smbw_stat.c index c84140f3629..926075c864f 100644 --- a/source/smbwrapper/smbw_stat.c +++ b/source/smbwrapper/smbw_stat.c @@ -180,6 +180,7 @@ int smbw_stat(const char *fname, struct stat *st) size_t size=0; uint16 mode=0; SMB_INO_T ino = 0; + int result = 0; ZERO_STRUCTP(st); @@ -200,8 +201,19 @@ int smbw_stat(const char *fname, struct stat *st) /* get a connection to the server */ srv = smbw_server(server, share); if (!srv) { + + /* For shares we aren't allowed to connect to, return + an empty directory */ + + if (server[0] && share[0] && !path[0] && errno == EACCES) { + mode = aDIR | aRONLY; + smbw_setup_stat(st, path, size, mode); + goto done; + } + /* smbw_server sets errno */ - goto failed; + result = -1; + goto done; } DEBUG(4,("smbw_stat\n")); @@ -221,7 +233,8 @@ int smbw_stat(const char *fname, struct stat *st) &mode, &size, &c_time, &a_time, &m_time, &ino)) { errno = smbw_errno(&srv->cli); - goto failed; + result = -1; + goto done; } } @@ -234,10 +247,7 @@ int smbw_stat(const char *fname, struct stat *st) st->st_mtime = m_time; st->st_dev = srv->dev; + done: smbw_busy--; - return 0; - - failed: - smbw_busy--; - return -1; + return result; } |