diff options
Diffstat (limited to 'source3/smbwrapper')
-rw-r--r-- | source3/smbwrapper/smbw.c | 123 | ||||
-rw-r--r-- | source3/smbwrapper/smbw_dir.c | 11 |
2 files changed, 77 insertions, 57 deletions
diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c index 0764bc28ad..51e4b4cb65 100644 --- a/source3/smbwrapper/smbw.c +++ b/source3/smbwrapper/smbw.c @@ -246,87 +246,97 @@ 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; + + } + + free((char *)ip_list); + + DEBUG(0,("Need to do node status code")); + 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; } @@ -459,7 +469,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/source3/smbwrapper/smbw_dir.c b/source3/smbwrapper/smbw_dir.c index 0929428273..cc0e2ec748 100644 --- a/source3/smbwrapper/smbw_dir.c +++ b/source3/smbwrapper/smbw_dir.c @@ -199,7 +199,14 @@ 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,""); + smbw_server_add("..",0,""); + cli_NetServerEnum(&srv->cli, srv->server_name, SV_TYPE_DOMAIN_ENUM, + smbw_server_add); + *p = '#'; + } else if ((p=strstr(srv->server_name,"#1D"))) { DEBUG(4,("doing NetServerEnum\n")); *p = 0; smbw_server_add(".",0,""); @@ -223,10 +230,12 @@ int smbw_dir_open(const char *fname) 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) { errno = smbw_errno(&srv->cli); |