smbwrapper/smbsh is now working for Linux 2.4

Derrell.Lipman at UnwiredUniverse.com Derrell.Lipman at UnwiredUniverse.com
Tue Dec 10 18:55:02 GMT 2002


jra at dp.samba.org writes:

> On Tue, Dec 10, 2002 at 01:27:07PM -0500, Derrell.Lipman at UnwiredUniverse.com
> wrote:
>> 
>> I have smbwrapper and smbsh working on Debian/woody with the Linux 2.4
>> kernel and the default C library: libc-2.2.5.so.

> Yes, I'm interested - please post patches. Pressure of other things has made
> this a low priority but I'm really happy to apply patches that work for
> people !

Ok.  The patch is attached.  This became a high priority for me when smbmount
used with automount turned out to be way too slow.  This seems substantially
faster in terms of connection establishment.

The problems I have encountered with smbsh so far pertain to something that
Debian is doing in their build process.  smbsh works well with bash if bash is
built from source with nothing other than "./configure;make".  Using Debian's
build process or their bash binary, however, bash crashes after reading the
.bash_history file.  (Debian modifies the default build process and I haven't
spent the time to determine which change they make causes this.)  Similarly,
the program "hostname" crashes using the default binary.  (I haven't tried
rebuilding that one to see if a simple recompile fixes it.)  In both cases,
they're getting segmentation violations, and I believe there's a function
pointer not getting resolved properly with the various wrappers provided by
smbwrapper.so.  I'm sure there are other apps which will crash as well, but I
did a bunch of stuff today in bash in smbsh and it was generally working well.

If anyone fixes the above problems, please let me know about it.  I'm not
normally subscribed to samba-technical.

Jeremy, someone who knows automake/configure building may want to look at this
patch to determine which portions should be in #ifdefs for autoconfiguring for
other than Linux.

Cheers,

Derrell

------------------------------------------------------------------------------

diff -u /var/tmp/samba-2.2.3a/source/smbwrapper/realcalls.c samba-2.2.3a/source/smbwrapper/realcalls.c
--- /var/tmp/samba-2.2.3a/source/smbwrapper/realcalls.c	Wed Oct  7 06:58:12 1998
+++ samba-2.2.3a/source/smbwrapper/realcalls.c	Tue Dec 10 13:02:03 2002
@@ -22,6 +22,81 @@
 #include "includes.h"
 #include "realcalls.h"
 
+#include <dlfcn.h>
+
+/*
+ * Pointers to functions in the standard C library
+ */
+static struct
+{
+        void *          (* readdir64)(void * dir);
+        void *          (* llseek)(int fd,
+                                   unsigned long offset_high,
+                                   unsigned long offset_low,
+                                   loff_t * result,
+                                   unsigned int whence);
+        int             (* lstat64)(int ver,
+                                    char *name,
+                                    void *st64);
+        int             (* fstat64)(int ver,
+                                    int fd,
+                                    void *st64);
+        int             (* stat64)(int ver,
+                                   char *name,
+                                   void *st64);
+        ssize_t         (* pwrite)(int fd,
+                                   void *buf,
+                                   size_t size,
+                                   off_t ofs);
+        ssize_t         (* pread)(int fd,
+                                  void *buf,
+                                  size_t size,
+                                  off_t ofs);
+        void *          (* opendir)(const char *name);
+        int             (* closedir)(void *dir);
+        off_t           (* telldir)(void *dir);
+        int             (* seekdir)(void *dir,
+                                    off_t offset);
+} libc;
+
+int real_init(void)
+{
+        static void *lib = NULL;
+        char *error;
+        
+        if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL)
+                return -1;
+        
+#define GETSYM(symname, symstring)                                          \
+        libc.symname = dlsym(lib, symstring);                               \
+        if ((error = dlerror()) != NULL)                                    \
+            break;
+        
+        /*
+         * Get pointers to each of the symbols we'll need, from the C library
+         */
+        do {
+                GETSYM(readdir64, "readdir64");
+                GETSYM(llseek, "llseek");
+                GETSYM(lstat64, "__lxstat64");
+                GETSYM(fstat64, "__fxstat64");
+                GETSYM(stat64, "__xstat64");
+                GETSYM(pwrite, "pwrite");
+                GETSYM(pread, "pread");
+                GETSYM(opendir, "opendir");
+                GETSYM(closedir, "closedir");
+                GETSYM(telldir, "telldir");
+                GETSYM(seekdir, "seekdir");
+        } while (0);
+        
+        dlclose(lib);
+        
+        if (error != NULL)
+                return -1;
+        
+        return 0;
+}
+
 #ifdef REPLACE_UTIME
 int real_utime(const char *name, struct utimbuf *buf)
 {
@@ -47,3 +122,77 @@
 	return real_utime(name, &buf);
 }
 #endif
+
+#ifdef HAVE_READDIR64
+void *real_readdir64(void *dir)
+{
+        return (* libc.readdir64)(dir);
+}
+#endif
+
+void *real_llseek(int fd, unsigned long offset_high, unsigned long offset_low,
+                  loff_t * result, unsigned int whence)
+{
+        return (* libc.llseek)(fd, offset_high, offset_low, result, whence);
+}
+
+
+int real_lstat64(int ver, char *name, void *st64)
+{
+        return (* libc.lstat64)(ver, name, st64);
+}
+
+
+int real_fstat64(int ver, int fd, void *st64)
+{
+        return (* libc.fstat64)(ver, fd, st64);
+}
+
+
+int real_stat64(int ver, char *name, void *st64)
+{
+        return (* libc.stat64)(ver, name, st64);
+}
+
+
+ssize_t real_pwrite(int fd, void *buf, size_t size, off_t ofs)
+{
+        return (* libc.pwrite)(fd, buf, size, ofs);
+}
+
+
+ssize_t real_pread(int fd, void *buf, size_t size, off_t ofs)
+{
+        return (* libc.pread)(fd, buf, size, ofs);
+}
+
+
+void * real_opendir(const char *name)
+{
+        return (* libc.opendir)(name);
+}
+
+
+#if 0 /* readdir is a system call; others in the opendir family are not */
+void * real_readdir(void * dir)
+{
+}
+#endif
+
+
+int real_closedir(void * dir)
+{
+        return (* libc.closedir)(dir);
+}
+
+
+off_t real_telldir(void *dir)
+{
+        return (* libc.telldir)(dir);
+}
+
+
+int real_seekdir(void *dir, off_t offset)
+{
+        return (* libc.seekdir)(dir, offset);
+}
diff -u /var/tmp/samba-2.2.3a/source/smbwrapper/smbsh.c samba-2.2.3a/source/smbwrapper/smbsh.c
--- /var/tmp/samba-2.2.3a/source/smbwrapper/smbsh.c	Sat Feb  2 19:46:57 2002
+++ samba-2.2.3a/source/smbwrapper/smbsh.c	Tue Dec 10 13:03:05 2002
@@ -25,7 +25,7 @@
 
 static void smbsh_usage(void)
 {
-	printf("smbsh [options]\n\n");
+	printf("smbsh [options] [command [args] ...]\n\n");
 	printf(" -W workgroup\n");
 	printf(" -U username\n");
 	printf(" -P prefix\n");
@@ -115,6 +115,7 @@
 
 	slprintf(line,sizeof(line)-1,"%s/smbwrapper.so", libd);
 	smbw_setenv("LD_PRELOAD", line);
+        smbw_setenv("LD_BIND_NOW", "true");
 
 	slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd);
 
@@ -128,9 +129,11 @@
 		smbw_setenv("_RLD_LIST", line);
 	}
 
-	{
-    	char *shellpath = getenv("SHELL");
-		if(shellpath)
+        if (optind < argc) {
+                execvp(argv[optind], &argv[optind]);
+        } else {
+                char *shellpath = getenv("SHELL");
+                if(shellpath)
 			execl(shellpath,"smbsh",NULL);
 		else
 			execl("/bin/sh","smbsh",NULL);
diff -u /var/tmp/samba-2.2.3a/source/smbwrapper/smbw.c samba-2.2.3a/source/smbwrapper/smbw.c
--- /var/tmp/samba-2.2.3a/source/smbwrapper/smbw.c	Sat Feb  2 19:46:57 2002
+++ samba-2.2.3a/source/smbwrapper/smbw.c	Tue Dec 10 13:05:41 2002
@@ -45,7 +45,7 @@
 void smbw_init(void)
 {
 	extern BOOL in_client;
-	static int initialised;
+	static int initialised = 0;
 	static pstring servicesf = CONFIGFILE;
 	extern FILE *dbf;
 	char *p;
@@ -59,6 +59,10 @@
 
 	smbw_busy++;
 
+        if (real_init() != 0) {
+            exit(1);
+        }
+
 	DEBUGLEVEL = 0;
 	AllowDebugChange = False;
 	setup_logging("smbsh",True);
@@ -406,22 +410,53 @@
 	return cli_errno(c);
 }
 
-/* Return a username and password given a server and share name */
-
-void get_envvar_auth_data(char *server, char *share, char **workgroup,
+/*
+ * Return a username and password given a server and share name
+ *
+ * It is the caller's responsibility to free the memory allocated for the
+ * workgroup, username, and password.
+ *
+ * Returns 0 upon success;
+ * non-zero otherwise, and errno is set to indicate the error.
+ */
+int get_envvar_auth_data(char *server, char *share, char **workgroup,
 			  char **username, char **password)
 {
-	/* Fall back to shared memory/environment variables */
+        char *u;
+        char *p;
+        char *w;
 
-	*username = smbw_getshared("USER");
-	if (!*username) *username = getenv("USER");
-	if (!*username) *username = "guest";
+	/* Fall back to shared memory/environment variables */
 
-	*workgroup = smbw_getshared("WORKGROUP");
-	if (!*workgroup) *workgroup = lp_workgroup();
+	u = smbw_getshared("USER");
+	if (u == NULL) u = getenv("USER");
+	if (u == NULL) u = "guest";
+
+	w = smbw_getshared("WORKGROUP");
+	if (w == NULL) w = lp_workgroup();
+
+	p = smbw_getshared("PASSWORD");
+	if (p == NULL) p = "";
+
+        if ((*username = strdup(u)) == NULL) {
+                errno = ENOMEM;
+                return -1;
+        }
+
+        if ((*workgroup = strdup(w)) == NULL) {
+                errno = ENOMEM;
+                free(*username);
+                return -1;
+        }
+
+        if ((*password = strdup(p)) == NULL) {
+                errno = ENOMEM;
+                free(*workgroup);
+                free(*username);
+                return -1;
+        }
 
-	*password = smbw_getshared("PASSWORD");
-	if (!*password) *password = "";
+        return 0;
 }
 
 static smbw_get_auth_data_fn get_auth_data_fn = get_envvar_auth_data;
@@ -454,19 +489,28 @@
 	ip = ipzero;
 	ZERO_STRUCT(c);
 
-	get_auth_data_fn(server, share, &workgroup, &username, &password);
+	if (get_auth_data_fn(server, share, &workgroup,
+                             &username, &password) != 0)
+                return NULL;
 
 	/* try to use an existing connection */
 	for (srv=smbw_srvs;srv;srv=srv->next) {
 		if (strcmp(server,srv->server_name)==0 &&
 		    strcmp(share,srv->share_name)==0 &&
 		    strcmp(workgroup,srv->workgroup)==0 &&
-		    strcmp(username, srv->username) == 0) 
+		    strcmp(username, srv->username) == 0) {
+                        free(username);
+                        free(workgroup);
+                        free(password);
 			return srv;
+                }
 	}
 
 	if (server[0] == 0) {
 		errno = EPERM;
+                free(username);
+                free(workgroup);
+                free(password);
 		return NULL;
 	}
 
@@ -489,6 +533,9 @@
 		if (!(server_n = smbw_getshared(s))) {
 			if (!find_master_ip(group, &sip)) {
 				errno = ENOENT;
+                                free(username);
+                                free(workgroup);
+                                free(password);
 				return NULL;
 			}
 			fstrcpy(group, inet_ntoa(sip));
@@ -510,6 +557,9 @@
 	/* have to open a new connection */
 	if (!cli_initialise(&c) || !cli_connect(&c, server_n, &ip)) {
 		errno = ENOENT;
+                free(username);
+                free(workgroup);
+                free(password);
 		return NULL;
 	}
 
@@ -520,6 +570,9 @@
 			goto again;
 		}
 		errno = ENOENT;
+                free(username);
+                free(workgroup);
+                free(password);
 		return NULL;
 	}
 
@@ -528,6 +581,9 @@
 	if (!cli_negprot(&c)) {
 		cli_shutdown(&c);
 		errno = ENOENT;
+                free(username);
+                free(workgroup);
+                free(password);
 		return NULL;
 	}
 
@@ -539,6 +595,9 @@
 	    !cli_session_setup(&c, "", "", 1,"", 0, workgroup)) {
 		cli_shutdown(&c);
 		errno = EPERM;
+                free(username);
+                free(workgroup);
+                free(password);
 		return NULL;
 	}
 
@@ -548,9 +607,14 @@
 			    password, strlen(password)+1)) {
 		errno = smbw_errno(&c);
 		cli_shutdown(&c);
+                free(username);
+                free(workgroup);
+                free(password);
 		return NULL;
 	}
 
+        free(password);         /* not used any more so clean up now */
+
 	smbw_setshared(ipenv,inet_ntoa(ip));
 	
 	DEBUG(4,(" tconx ok\n"));
@@ -579,17 +643,8 @@
 		goto failed;
 	}
 
-	srv->workgroup = strdup(workgroup);
-	if (!srv->workgroup) {
-		errno = ENOMEM;
-		goto failed;
-	}
-
-	srv->username = strdup(username);
-	if (!srv->username) {
-		errno = ENOMEM;
-		goto failed;
-	}
+	srv->workgroup = workgroup;
+	srv->username = username;
 
 	/* some programs play with file descriptors fairly intimately. We
 	   try to get out of the way by duping to a high fd number */
@@ -609,6 +664,8 @@
 	cli_shutdown(&c);
 	if (!srv) return NULL;
 
+        free(username);
+        free(workgroup);
 	SAFE_FREE(srv->server_name);
 	SAFE_FREE(srv->share_name);
 	SAFE_FREE(srv);
@@ -640,6 +697,9 @@
 	int eno=0, fd = -1;
 	struct smbw_file *file=NULL;
 
+	DEBUG(4,("smbw_open(fname=%s, flags=%d, mode=%o\n",
+                 fname, flags, mode));
+
 	smbw_init();
 
 	if (!fname) {
@@ -695,6 +755,7 @@
 		errno = ENOMEM;
 		goto failed;
 	}
+
 	file->srv = srv;
 	file->fd = open(SMBW_DUMMY, O_WRONLY);
 	if (file->fd == -1) {
@@ -936,7 +997,7 @@
 }
 
 /***************************************************** 
-a wrapper for realink() - needed for correct errno setting
+a wrapper for readlink() - needed for correct errno setting
 *******************************************************/
 int smbw_readlink(const char *path, char *buf, size_t bufsize)
 {
diff -u /var/tmp/samba-2.2.3a/source/smbwrapper/smbw.h samba-2.2.3a/source/smbwrapper/smbw.h
--- /var/tmp/samba-2.2.3a/source/smbwrapper/smbw.h	Fri Nov 10 16:52:47 2000
+++ samba-2.2.3a/source/smbwrapper/smbw.h	Tue Dec 10 09:49:54 2002
@@ -65,8 +65,17 @@
 	char *path;
 };
 
-typedef void (*smbw_get_auth_data_fn)(char *server, char *share,
-				      char **workgroup, char **username,
-				      char **password);
+/*
+ * Return a username and password given a server and share name
+ *
+ * It is the caller's responsibility to free the memory allocated for the
+ * workgroup, username, and password.
+ *
+ * Returns 0 upon success;
+ * non-zero otherwise, and errno is set to indicate the error.
+ */
+typedef int (*smbw_get_auth_data_fn)(char *server, char *share,
+                                     char **workgroup, char **username,
+                                     char **password);
 
 #endif /* _SMBW_H */
diff -u /var/tmp/samba-2.2.3a/source/smbwrapper/wrapped.c samba-2.2.3a/source/smbwrapper/wrapped.c
--- /var/tmp/samba-2.2.3a/source/smbwrapper/wrapped.c	Sat Feb  2 19:46:57 2002
+++ samba-2.2.3a/source/smbwrapper/wrapped.c	Tue Dec 10 13:10:05 2002
@@ -20,10 +20,10 @@
 */
 
 /* NOTE: This file WILL produce compiler warnings. They are unavoidable 
-
-   Do not try and get rid of them by including other include files or
-   by including includes.h or proto.h or you will break portability. 
-  */
+   
+Do not try and get rid of them by including other include files or
+by including includes.h or proto.h or you will break portability. 
+*/
 
 #include "config.h"
 #include <sys/types.h>
@@ -34,8 +34,32 @@
 # define NULL ((void *)0)
 #endif
 
- int open(char *name, int flags, mode_t mode)
+#if 0 /* for testing */
+#define debug_write(buf)                real_write(1, "["buf"]", sizeof(buf)+1)
+#else
+#define debug_write(buf)
+#endif
+
+
+/*
+  THIS HACK IS COPIED FROM includes.h, WHICH CAN'T BE INCLUDED HERE.
+
+   This is a gross hack. 64 bit locking is completely screwed up on
+   i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
+   "fixes" the problem with the current 2.4.0test kernels 
+*/
+#define fcntl fcntl64
+#undef F_SETLKW 
+#undef F_SETLK 
+#define F_SETLK 13
+#define F_SETLKW 14
+
+int open(char *name, int flags, mode_t mode)
 {
+        /* caution: this is called to open fd=1 */
+        if (strncmp(name, "/smb", 4) == 0)
+                debug_write("wrapped open");
+
 	if (smbw_path(name)) {
 		return smbw_open(name, flags, mode);
 	}
@@ -44,46 +68,52 @@
 }
 
 #ifdef HAVE__OPEN
- int _open(char *name, int flags, mode_t mode) 
+int _open(char *name, int flags, mode_t mode) 
 {
+        debug_write("wrapped _open");
 	return open(name, flags, mode);
 }
 #elif HAVE___OPEN
- int __open(char *name, int flags, mode_t mode) 
+int __open(char *name, int flags, mode_t mode) 
 {
+        debug_write("wrapped _open");
 	return open(name, flags, mode);
 }
 #endif
 
 
 #ifdef HAVE_OPEN64
- int open64(char *name, int flags, mode_t mode)
+int open64(char *name, int flags, mode_t mode)
 {
+        debug_write("wrapped open64");
 	if (smbw_path(name)) {
 		return smbw_open(name, flags, mode);
 	}
-
+        
 	return real_open64(name, flags, mode);
 }
 #endif
 
 #ifndef NO_OPEN64_ALIAS
 #ifdef HAVE__OPEN64
- int _open64(char *name, int flags, mode_t mode) 
+int _open64(char *name, int flags, mode_t mode) 
 {
+        debug_write("wrapped _open64");
 	return open64(name, flags, mode);
 }
 #elif HAVE___OPEN64
- int __open64(char *name, int flags, mode_t mode) 
+int __open64(char *name, int flags, mode_t mode) 
 {
+        debug_write("wrapped __open64");
 	return open64(name, flags, mode);
 }
 #endif
 #endif
 
 #ifdef HAVE_PREAD
- ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
+ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
 {
+        debug_write("wrapped pread");
 	if (smbw_fd(fd)) {
 		return smbw_pread(fd, buf, size, ofs);
 	}
@@ -93,8 +123,9 @@
 #endif
 
 #if defined(HAVE_PREAD64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
- ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs)
+ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs)
 {
+        debug_write("wrapped pread64");
 	if (smbw_fd(fd)) {
 		return smbw_pread(fd, buf, size, ofs);
 	}
@@ -104,8 +135,9 @@
 #endif
 
 #ifdef HAVE_PWRITE
- ssize_t pwrite(int fd, void *buf, size_t size, off_t ofs)
+ssize_t pwrite(int fd, void *buf, size_t size, off_t ofs)
 {
+        debug_write("wrapped pwrite");
 	if (smbw_fd(fd)) {
 		return smbw_pwrite(fd, buf, size, ofs);
 	}
@@ -115,8 +147,9 @@
 #endif
 
 #if defined(HAVE_PWRITE64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
- ssize_t pwrite64(int fd, void *buf, size_t size, off64_t ofs)
+ssize_t pwrite64(int fd, void *buf, size_t size, off64_t ofs)
 {
+        debug_write("wrapped pwrite64");
 	if (smbw_fd(fd)) {
 		return smbw_pwrite(fd, buf, size, ofs);
 	}
@@ -126,26 +159,30 @@
 #endif
 
 
- int chdir(char *name)
+int chdir(char *name)
 {
+        debug_write("wrapped chdir");
 	return smbw_chdir(name);
 }
 
 #ifdef HAVE___CHDIR
- int __chdir(char *name)
+int __chdir(char *name)
 {
+        debug_write("wrapped __chdir");
 	return chdir(name);
 }
 #elif HAVE__CHDIR
- int _chdir(char *name)
+int _chdir(char *name)
 {
+        debug_write("wrapped _chdir");
 	return chdir(name);
 }
 #endif
 
 
- int close(int fd)
+int close(int fd)
 {
+        debug_write("wrapped close");
 	if (smbw_fd(fd)) {
 		return smbw_close(fd);
 	}
@@ -154,42 +191,48 @@
 		return -1;
 	}
 
-	return real_close(fd);
+        return real_close(fd);
 }
 
 #ifdef HAVE___CLOSE
- int __close(int fd)
+int __close(int fd)
 {
+        debug_write("wrapped __close");
 	return close(fd);
 }
 #elif HAVE__CLOSE
- int _close(int fd)
+int _close(int fd)
 {
+        debug_write("wrapped _close");
 	return close(fd);
 }
 #endif
 
 
- int fchdir(int fd)
+int fchdir(int fd)
 {
+        debug_write("wrapped fchdir");
 	return smbw_fchdir(fd);
 }
 
 #ifdef HAVE___FCHDIR
- int __fchdir(int fd)
+int __fchdir(int fd)
 {
+        debug_write("wrapped __fchdir");
 	return fchdir(fd);
 }
 #elif HAVE__FCHDIR
- int _fchdir(int fd)
+int _fchdir(int fd)
 {
+        debug_write("wrapped _fchdir");
 	return fchdir(fd);
 }
 #endif
 
 
- int fcntl(int fd, int cmd, long arg)
+int fcntl(int fd, int cmd, long arg)
 {
+        debug_write("wrapped fcntl");
 	if (smbw_fd(fd)) {
 		return smbw_fcntl(fd, cmd, arg);
 	}
@@ -199,13 +242,15 @@
 
 
 #ifdef HAVE___FCNTL
- int __fcntl(int fd, int cmd, long arg)
+int __fcntl(int fd, int cmd, long arg)
 {
+        debug_write("wrapped __fcntl");
 	return fcntl(fd, cmd, arg);
 }
 #elif HAVE__FCNTL
- int _fcntl(int fd, int cmd, long arg)
+int _fcntl(int fd, int cmd, long arg)
 {
+        debug_write("wrapped _fcntl");
 	return fcntl(fd, cmd, arg);
 }
 #endif
@@ -213,8 +258,9 @@
 
 
 #ifdef real_getdents
- int getdents(int fd, void *dirp, unsigned int count)
+int getdents(int fd, void *dirp, unsigned int count)
 {
+        debug_write("wrapped getdents");
 	if (smbw_fd(fd)) {
 		return smbw_getdents(fd, dirp, count);
 	}
@@ -224,20 +270,23 @@
 #endif
 
 #ifdef HAVE___GETDENTS
- int __getdents(int fd, void *dirp, unsigned int count)
+int __getdents(int fd, void *dirp, unsigned int count)
 {
+        debug_write("wrapped __getdents");
 	return getdents(fd, dirp, count);
 }
 #elif HAVE__GETDENTS
- int _getdents(int fd, void *dirp, unsigned int count)
+int _getdents(int fd, void *dirp, unsigned int count)
 {
+        debug_write("wrapped _getdents");
 	return getdents(fd, dirp, count);
 }
 #endif
 
 
- off_t lseek(int fd, off_t offset, int whence)
+off_t lseek(int fd, off_t offset, int whence)
 {
+        debug_write("wrapped lseek");
 	if (smbw_fd(fd)) {
 		return smbw_lseek(fd, offset, whence);
 	}
@@ -246,20 +295,23 @@
 }
 
 #ifdef HAVE___LSEEK
- off_t __lseek(int fd, off_t offset, int whence)
+off_t __lseek(int fd, off_t offset, int whence)
 {
+        debug_write("wrapped __lseek");
 	return lseek(fd, offset, whence);
 }
 #elif HAVE__LSEEK
- off_t _lseek(int fd, off_t offset, int whence)
+off_t _lseek(int fd, off_t offset, int whence)
 {
+        debug_write("wrapped _lseek");
 	return lseek(fd, offset, whence);
 }
 #endif
 
 
- ssize_t read(int fd, void *buf, size_t count)
+ssize_t read(int fd, void *buf, size_t count)
 {
+        debug_write("wrapped read");
 	if (smbw_fd(fd)) {
 		return smbw_read(fd, buf, count);
 	}
@@ -268,20 +320,23 @@
 }
 
 #ifdef HAVE___READ
- ssize_t __read(int fd, void *buf, size_t count)
+ssize_t __read(int fd, void *buf, size_t count)
 {
+        debug_write("wrapped __read");
 	return read(fd, buf, count);
 }
 #elif HAVE__READ
- ssize_t _read(int fd, void *buf, size_t count)
+ssize_t _read(int fd, void *buf, size_t count)
 {
+        debug_write("wrapped _read");
 	return read(fd, buf, count);
 }
 #endif
 
 
- ssize_t write(int fd, void *buf, size_t count)
+ssize_t write(int fd, void *buf, size_t count)
 {
+        debug_write("wrapped write");
 	if (smbw_fd(fd)) {
 		return smbw_write(fd, buf, count);
 	}
@@ -290,21 +345,24 @@
 }
 
 #ifdef HAVE___WRITE
- ssize_t __write(int fd, void *buf, size_t count)
+ssize_t __write(int fd, void *buf, size_t count)
 {
+        debug_write("wrapped __write");
 	return write(fd, buf, count);
 }
 #elif HAVE__WRITE
- ssize_t _write(int fd, void *buf, size_t count)
+ssize_t _write(int fd, void *buf, size_t count)
 {
+        debug_write("wrapped _write");
 	return write(fd, buf, count);
 }
 #endif
 
 
 
- int access(char *name, int mode)
+int access(char *name, int mode)
 {
+        debug_write("wrapped access");
 	if (smbw_path(name)) {
 		return smbw_access(name, mode);
 	}
@@ -314,8 +372,9 @@
 
 
 
- int chmod(char *name,mode_t mode)
+int chmod(char *name,mode_t mode)
 {
+        debug_write("wrapped chmod");
 	if (smbw_path(name)) {
 		return smbw_chmod(name, mode);
 	}
@@ -325,8 +384,9 @@
 
 
 
- int chown(char *name,uid_t owner, gid_t group)
+int chown(char *name,uid_t owner, gid_t group)
 {
+        debug_write("wrapped chown");
 	if (smbw_path(name)) {
 		return smbw_chown(name, owner, group);
 	}
@@ -335,16 +395,18 @@
 }
 
 
- char *getcwd(char *buf, size_t size)
+char *getcwd(char *buf, size_t size)
 {
+        debug_write("wrapped getcwd");
 	return (char *)smbw_getcwd(buf, size);
 }
 
 
 
 
- int mkdir(char *name, mode_t mode)
+int mkdir(char *name, mode_t mode)
 {
+        debug_write("wrapped mkdir");
 	if (smbw_path(name)) {
 		return smbw_mkdir(name, mode);
 	}
@@ -354,10 +416,11 @@
 
 
 #if HAVE___FXSTAT
- int __fxstat(int vers, int fd, void *st)
+int __fxstat(int vers, int fd, void *st)
 {
 	double xx[32];
 	int ret;
+        debug_write("wrapped __fxstat");
 
 	if (smbw_fd(fd)) {
 		return smbw_fstat(fd, st);
@@ -370,10 +433,11 @@
 #endif
 
 #if HAVE___XSTAT
- int __xstat(int vers, char *name, void *st)
+int __xstat(int vers, char *name, void *st)
 {
 	double xx[32];
 	int ret;
+        debug_write("wrapped __xstat");
 
 	if (smbw_path(name)) {
 		return smbw_stat(name, st);
@@ -387,10 +451,11 @@
 
 
 #if HAVE___LXSTAT
- int __lxstat(int vers, char *name, void *st)
+int __lxstat(int vers, char *name, void *st)
 {
 	double xx[32];
 	int ret;
+        debug_write("wrapped __lxstat");
 
 	if (smbw_path(name)) {
 		return smbw_stat(name, st);
@@ -403,8 +468,9 @@
 #endif
 
 
- int stat(char *name, void *st)
+int stat(char *name, void *st)
 {
+        debug_write("wrapped stat");
 #if HAVE___XSTAT
 	return __xstat(0, name, st);
 #else
@@ -415,20 +481,22 @@
 #endif
 }
 
- int lstat(char *name, void *st)
+int lstat(char *name, void *st)
 {
+        debug_write("wrapped lstat");
 #if HAVE___LXSTAT
 	return __lxstat(0, name, st);
 #else
 	if (smbw_path(name)) {
-		return smbw_stat(name, st);
+                return smbw_stat(name, st);
 	}
 	return real_lstat(name, st);
 #endif
 }
 
- int fstat(int fd, void *st)
+int fstat(int fd, void *st)
 {
+        debug_write("wrapped fstat");
 #if HAVE___LXSTAT
 	return __fxstat(0, fd, st);
 #else
@@ -440,8 +508,9 @@
 }
 
 
- int unlink(char *name)
+int unlink(char *name)
 {
+        debug_write("wrapped unlink");
 	if (smbw_path(name)) {
 		return smbw_unlink(name);
 	}
@@ -451,8 +520,9 @@
 
 
 #ifdef HAVE_UTIME
- int utime(char *name,void *tvp)
+int utime(char *name,void *tvp)
 {
+        debug_write("wrapped utime");
 	if (smbw_path(name)) {
 		return smbw_utime(name, tvp);
 	}
@@ -469,8 +539,9 @@
 #include <time.h>
 #endif
 
- int utimes(const char *name, const struct timeval *tvp)
+int utimes(const char *name, const struct timeval *tvp)
 {
+        debug_write("wrapped utimes");
 	if (smbw_path(name)) {
 		return smbw_utimes(name, tvp);
 	}
@@ -479,8 +550,9 @@
 }
 #endif
 
- int readlink(char *path, char *buf, size_t bufsize)
+int readlink(char *path, char *buf, size_t bufsize)
 {
+        debug_write("wrapped readlink");
 	if (smbw_path(path)) {
 		return smbw_readlink(path, buf, bufsize);
 	}
@@ -489,9 +561,10 @@
 }
 
 
- int rename(char *oldname,char *newname)
+int rename(char *oldname,char *newname)
 {
 	int p1, p2;
+        debug_write("wrapped rename");
 	p1 = smbw_path(oldname); 
 	p2 = smbw_path(newname); 
 	if (p1 ^ p2) {
@@ -506,8 +579,9 @@
 	return real_rename(oldname, newname);
 }
 
- int rmdir(char *name)
+int rmdir(char *name)
 {
+        debug_write("wrapped rmdir");
 	if (smbw_path(name)) {
 		return smbw_rmdir(name);
 	}
@@ -516,9 +590,10 @@
 }
 
 
- int symlink(char *topath,char *frompath)
+int symlink(char *topath,char *frompath)
 {
 	int p1, p2;
+        debug_write("wrapped symlink");
 	p1 = smbw_path(topath); 
 	p2 = smbw_path(frompath); 
 	if (p1 || p2) {
@@ -530,8 +605,9 @@
 	return real_symlink(topath, frompath);
 }
 
- int dup(int fd)
+int dup(int fd)
 {
+        debug_write("wrapped dup");
 	if (smbw_fd(fd)) {
 		return smbw_dup(fd);
 	}
@@ -539,12 +615,13 @@
 	return real_dup(fd);
 }
 
- int dup2(int oldfd, int newfd)
+int dup2(int oldfd, int newfd)
 {
+        debug_write("wrapped dup2");
 	if (smbw_fd(newfd)) {
 		close(newfd);
 	}
-
+        
 	if (smbw_fd(oldfd)) {
 		return smbw_dup2(oldfd, newfd);
 	}
@@ -552,53 +629,49 @@
 	return real_dup2(oldfd, newfd);
 }
 
-#ifdef real_opendir
- void *opendir(char *name)
+void *opendir(char *name)
 {
+        debug_write("wrapped *opendir");
 	if (smbw_path(name)) {
 		return (void *)smbw_opendir(name);
 	}
 
 	return (void *)real_opendir(name);
 }
-#endif
 
-#ifdef real_readdir
- void *readdir(void *dir)
+void *readdir(void *dir)
 {
+        debug_write("wrapped *readdir");
 	if (smbw_dirp(dir)) {
 		return (void *)smbw_readdir(dir);
 	}
 
 	return (void *)real_readdir(dir);
 }
-#endif
 
-#ifdef real_closedir
- int closedir(void *dir)
+int closedir(void *dir)
 {
+        debug_write("wrapped closedir");
 	if (smbw_dirp(dir)) {
 		return smbw_closedir(dir);
 	}
 
 	return real_closedir(dir);
 }
-#endif
 
-#ifdef real_telldir
- off_t telldir(void *dir)
+off_t telldir(void *dir)
 {
+        debug_write("wrapped telldir");
 	if (smbw_dirp(dir)) {
 		return smbw_telldir(dir);
 	}
 
 	return real_telldir(dir);
 }
-#endif
 
-#ifdef real_seekdir
- int seekdir(void *dir, off_t offset)
+int seekdir(void *dir, off_t offset)
 {
+        debug_write("wrapped seekdir");
 	if (smbw_dirp(dir)) {
 		smbw_seekdir(dir, offset);
 		return 0;
@@ -607,12 +680,12 @@
 	real_seekdir(dir, offset);
 	return 0;
 }
-#endif
 
 
 #ifndef NO_ACL_WRAPPER
- int  acl(char  *pathp,  int  cmd,  int  nentries, void *aclbufp)
+int  acl(char  *pathp,  int  cmd,  int  nentries, void *aclbufp)
 {
+        debug_write("wrapped  acl");
 	if (smbw_path(pathp)) {
 		return smbw_acl(pathp, cmd, nentries, aclbufp);
 	}
@@ -622,8 +695,9 @@
 #endif
 
 #ifndef NO_FACL_WRAPPER
- int  facl(int fd,  int  cmd,  int  nentries, void *aclbufp)
+int  facl(int fd,  int  cmd,  int  nentries, void *aclbufp)
 {
+        debug_write("wrapped  facl");
 	if (smbw_fd(fd)) {
 		return smbw_facl(fd, cmd, nentries, aclbufp);
 	}
@@ -632,58 +706,83 @@
 }
 #endif
 
- int creat(char *path, mode_t mode)
+int creat(char *path, mode_t mode)
 {
 	extern int creat_bits;
+        debug_write("wrapped creat");
 	return open(path, creat_bits, mode);
 }
 
 #ifdef HAVE_CREAT64
- int creat64(char *path, mode_t mode)
+int creat64(char *path, mode_t mode)
 {
 	extern int creat_bits;
+        debug_write("wrapped creat64");
 	return open64(path, creat_bits, mode);
 }
 #endif
 
 #ifdef HAVE_STAT64
-  int stat64(char *name, void *st64)
+int __xstat64(int ver, char *name, void *st64)
 {
+        debug_write("wrapped stat64");
 	if (smbw_path(name)) {
 		double xx[32];
 		int ret = stat(name, xx);
 		stat64_convert(xx, st64);
 		return ret;
 	}
-	return real_stat64(name, st64);
+	return real_stat64(ver, name, st64);
 }
 
-  int fstat64(int fd, void *st64)
+int stat64(char *name, void *st64)
 {
+        return __xstat64(0, name, st64);
+}
+#endif
+
+#ifdef HAVE_FSTAT64
+int __fxstat64(int ver, int fd, void *st64)
+{
+        debug_write("wrapped fstat64");
 	if (smbw_fd(fd)) {
 		double xx[32];
 		int ret = fstat(fd, xx);
 		stat64_convert(xx, st64);
 		return ret;
 	}
-	return real_fstat64(fd, st64);
+	return real_fstat64(ver, fd, st64);
 }
 
-  int lstat64(char *name, void *st64)
+int fstat64(int fd, void *st64)
 {
+        return __fxstat64(0, fd, st64);
+}
+#endif
+
+#ifdef HAVE_LSTAT64
+int __lxstat64(int ver, char *name, void *st64)
+{
+        debug_write("wrapped lstat64");
 	if (smbw_path(name)) {
 		double xx[32];
 		int ret = lstat(name, xx);
 		stat64_convert(xx, st64);
 		return ret;
 	}
-	return real_lstat64(name, st64);
+	return real_lstat64(ver, name, st64);
+}
+
+int lstat64(char *name, void *st64)
+{
+        return __lxstat64(0, name, st64);
 }
 #endif
 
 #ifdef HAVE_LLSEEK
-  offset_t llseek(int fd, offset_t ofs, int whence)
+offset_t llseek(int fd, offset_t ofs, int whence)
 {
+        debug_write("wrapped llseek");
 	if (smbw_fd(fd)) {
 		return lseek(fd, ofs, whence);
 	}
@@ -692,8 +791,9 @@
 #endif
 
 #ifdef HAVE_READDIR64
- void *readdir64(void *dir)
+void *readdir64(void *dir)
 {
+        debug_write("wrapped *readdir64");
 	if (smbw_dirp(dir)) {
 		static double xx[70];
 		void *d;
@@ -706,7 +806,8 @@
 }
 #endif
 
- int fork(void)
+int fork(void)
 {
+        debug_write("wrapped fork");
 	return smbw_fork();
 }



More information about the samba-technical mailing list