summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-10-06 10:24:22 +0000
committerAndrew Tridgell <tridge@samba.org>1998-10-06 10:24:22 +0000
commited75bab8e22c1cbebe0238a689f7994f3817ee8f (patch)
tree5efa137d65ae8c31dd9482110a0422bc610f98f8
parent3d21f0359590050145fd877a7ec3efc56975d3bd (diff)
downloadsamba-ed75bab8e22c1cbebe0238a689f7994f3817ee8f.tar.gz
samba-ed75bab8e22c1cbebe0238a689f7994f3817ee8f.tar.bz2
samba-ed75bab8e22c1cbebe0238a689f7994f3817ee8f.zip
added SMBW_PREFIX environment variable (allowing you to specify root
of smb filesystem) fixed "cd /smb" bug updated README with full list of environment variables. (This used to be commit 71acf338d721b106af8d80e7b3a6f318ab75da8b)
-rw-r--r--source3/smbwrapper/README30
-rw-r--r--source3/smbwrapper/smbw.c42
-rw-r--r--source3/smbwrapper/smbw_dir.c37
3 files changed, 77 insertions, 32 deletions
diff --git a/source3/smbwrapper/README b/source3/smbwrapper/README
index 7f699dc8be..e9a52fb247 100644
--- a/source3/smbwrapper/README
+++ b/source3/smbwrapper/README
@@ -2,6 +2,8 @@ This is a prelodable shared library that provides SMB client services
for existing executables. Using this you can simulate a smb
filesystem.
+*** This is code under development. Some things don't work yet ***
+
Currently this code has only been tested on:
- Linux 2.0 with glibc2 (RH5.1)
@@ -28,9 +30,33 @@ happens. If you set SMBW_WORKGROUP to your workgroup or have workgroup
set in yoru smb.conf then listing /smb/ should list all SMB servers in
your workgroup.
-For debugging you can set SMBW_DEBUG to an integer debug level.
+Environment variables
+---------------------
+
+SMBW_USER
+ This is usually set by smbsh but you can set it manually. It
+ specifies the username you will connect to servers with.
+
+SMBW_PASSWORD
+ This is usually set by smbsh but you can set it manually. It
+ specifies the password used to connect to smb servers.
+
+SMBW_DEBUG
+ This is an integer that controls the internal debug level of smbw. It
+ defaults to 0, which means no debug info.
+
+SMBW_LOGFILE
+ The place where smbw debug logs are put. If this is not set then
+ stderr is used.
+
+SMBW_PREFIX
+ The root of the SMB filesystem. This defaults to /smb/ but you can
+ set it to any name you like.
+
+SMBW_WORKGROUP
+ This is the workgroup used for browsing (ie. listing machines in the
+ /smb/ directory). It defaults to the one set in smb.conf.
-This is code under development. Lots of things don't work yet.
Things that I have tried and do seem to work include:
diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c
index 93bbc078ea..d6b377a0b5 100644
--- a/source3/smbwrapper/smbw.c
+++ b/source3/smbwrapper/smbw.c
@@ -22,7 +22,7 @@
#include "includes.h"
#include "wrapper.h"
-pstring smb_cwd;
+pstring smbw_cwd;
static struct smbw_file *smbw_files;
static struct smbw_server *smbw_srvs;
@@ -31,6 +31,8 @@ struct bitmap *smbw_file_bmap;
extern pstring global_myname;
extern int DEBUGLEVEL;
+fstring smbw_prefix = SMBW_PREFIX;
+
int smbw_busy=0;
/*****************************************************
@@ -77,12 +79,18 @@ void smbw_init(void)
DEBUGLEVEL = atoi(p);
}
+ if ((p=getenv("SMBW_PREFIX"))) {
+ slprintf(smbw_prefix,sizeof(fstring)-1, "/%s/", p);
+ string_sub(smbw_prefix,"//", "/");
+ DEBUG(2,("SMBW_PREFIX is %s\n", smbw_prefix));
+ }
+
if ((p=getenv(SMBW_PWD_ENV))) {
- pstrcpy(smb_cwd, p);
- DEBUG(4,("Initial cwd from smb_cwd is %s\n", smb_cwd));
+ pstrcpy(smbw_cwd, p);
+ DEBUG(4,("Initial cwd from smbw_cwd is %s\n", smbw_cwd));
} else {
- sys_getwd(smb_cwd);
- DEBUG(4,("Initial cwd from getwd is %s\n", smb_cwd));
+ sys_getwd(smbw_cwd);
+ DEBUG(4,("Initial cwd from getwd is %s\n", smbw_cwd));
}
smbw_busy--;
@@ -207,21 +215,21 @@ 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;
+ int len = strlen(smbw_prefix)-1;
*server = *share = *path = 0;
if (fname[0] == '/') {
pstrcpy(s, fname);
} else {
- slprintf(s,sizeof(s)-1, "%s/%s", smb_cwd, fname);
+ slprintf(s,sizeof(s)-1, "%s/%s", smbw_cwd, fname);
}
clean_fname(s);
DEBUG(5,("cleaned %s (fname=%s cwd=%s)\n",
- s, fname, smb_cwd));
+ s, fname, smbw_cwd));
- if (strncmp(s,SMBW_PREFIX,len) ||
+ if (strncmp(s,smbw_prefix,len) ||
(s[len] != '/' && s[len] != 0)) return s;
p = s + len;
@@ -278,7 +286,7 @@ char *smbw_parse_path(const char *fname, char *server, char *share, char *path)
ok:
DEBUG(5,("parsed path name=%s cwd=%s [%s] [%s] [%s]\n",
- fname, smb_cwd,
+ fname, smbw_cwd,
server, share, path));
return s;
@@ -293,22 +301,24 @@ int smbw_path(const char *path)
fstring server, share;
pstring s;
char *cwd;
- int l=strlen(SMBW_PREFIX)-1;
+ int len;
+
+ smbw_init();
+
+ len = strlen(smbw_prefix)-1;
- if (path[0] == '/' && strncmp(path,SMBW_PREFIX,l)) {
+ if (path[0] == '/' && strncmp(path,smbw_prefix,len)) {
return 0;
}
if (smbw_busy) return 0;
- smbw_init();
-
DEBUG(3,("smbw_path(%s)\n", path));
cwd = smbw_parse_path(path, server, share, s);
- if (strncmp(cwd,SMBW_PREFIX,l) == 0 &&
- (cwd[l] == '/' || cwd[l] == 0)) {
+ if (strncmp(cwd,smbw_prefix,len) == 0 &&
+ (cwd[len] == '/' || cwd[len] == 0)) {
return 1;
}
diff --git a/source3/smbwrapper/smbw_dir.c b/source3/smbwrapper/smbw_dir.c
index c21c9b4983..5223183d56 100644
--- a/source3/smbwrapper/smbw_dir.c
+++ b/source3/smbwrapper/smbw_dir.c
@@ -22,7 +22,8 @@
#include "includes.h"
#include "wrapper.h"
-extern pstring smb_cwd;
+extern pstring smbw_cwd;
+extern fstring smbw_prefix;
static struct smbw_dir *smbw_dirs;
@@ -350,9 +351,12 @@ int smbw_chdir(const char *name)
pstring path;
uint32 mode = aDIR;
char *cwd;
+ int len;
smbw_init();
+ len = strlen(smbw_prefix);
+
if (smbw_busy) return real_chdir(name);
smbw_busy++;
@@ -362,16 +366,19 @@ int smbw_chdir(const char *name)
goto failed;
}
+ DEBUG(4,("smbw_chdir(%s)\n", name));
+
/* work out what server they are after */
cwd = smbw_parse_path(name, server, share, path);
- if (strncmp(cwd,SMBW_PREFIX,strlen(SMBW_PREFIX))) {
+ /* a special case - accept cd to /smb */
+ if (strncmp(cwd, smbw_prefix, len-1) == 0 &&
+ cwd[len-1] == 0) {
+ goto success;
+ }
+
+ if (strncmp(cwd,smbw_prefix,strlen(smbw_prefix))) {
if (real_chdir(cwd) == 0) {
- DEBUG(4,("set SMBW_CWD to %s\n", cwd));
- pstrcpy(smb_cwd, cwd);
- if (setenv(SMBW_PWD_ENV, smb_cwd, 1)) {
- DEBUG(4,("setenv failed\n"));
- }
goto success;
}
errno = ENOENT;
@@ -398,16 +405,18 @@ int smbw_chdir(const char *name)
goto failed;
}
- DEBUG(4,("set SMBW_CWD2 to %s\n", cwd));
- pstrcpy(smb_cwd, cwd);
- if (setenv(SMBW_PWD_ENV, smb_cwd, 1)) {
+ success:
+
+ DEBUG(4,("set SMBW_CWD to %s\n", cwd));
+
+ pstrcpy(smbw_cwd, cwd);
+ if (setenv(SMBW_PWD_ENV, smbw_cwd, 1)) {
DEBUG(4,("setenv failed\n"));
}
/* we don't want the old directory to be busy */
real_chdir("/");
- success:
smbw_busy--;
return 0;
@@ -549,7 +558,7 @@ char *smbw_getcwd(char *buf, size_t size)
smbw_busy++;
if (!buf) {
- if (size <= 0) size = strlen(smb_cwd)+1;
+ if (size <= 0) size = strlen(smbw_cwd)+1;
buf = (char *)malloc(size);
if (!buf) {
errno = ENOMEM;
@@ -558,13 +567,13 @@ char *smbw_getcwd(char *buf, size_t size)
}
}
- if (strlen(smb_cwd) > size-1) {
+ if (strlen(smbw_cwd) > size-1) {
errno = ERANGE;
smbw_busy--;
return NULL;
}
- safe_strcpy(buf, smb_cwd, size);
+ safe_strcpy(buf, smbw_cwd, size);
smbw_busy--;
return buf;