diff options
author | Derrell Lipman <derrell@samba.org> | 2006-01-07 20:43:36 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:06:03 -0500 |
commit | 96d0d186db42c61fa907b9b24f412b834359e2d8 (patch) | |
tree | 6d6207822f15e93d4c2a207a1150439b5f1e148e /examples/libsmbclient | |
parent | f396e2248ad36e4ac24792f6278366b0c737f8d7 (diff) | |
download | samba-96d0d186db42c61fa907b9b24f412b834359e2d8.tar.gz samba-96d0d186db42c61fa907b9b24f412b834359e2d8.tar.bz2 samba-96d0d186db42c61fa907b9b24f412b834359e2d8.zip |
r12759: r12128@cabra: derrell | 2006-01-07 15:34:01 -0500
Incorporate a number of changes suggested by David Collier-Brown Thanks, David!
(This used to be commit 0ae65b9af566e02eece9bb7865047c037468d470)
Diffstat (limited to 'examples/libsmbclient')
-rw-r--r-- | examples/libsmbclient/smbwrapper/Makefile | 7 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/bsd-strlcat.c | 71 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/bsd-strlcpy.c | 67 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/bsd-strlfunc.h | 7 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/smbsh.c | 25 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/smbw.c | 37 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/smbw.h | 4 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/smbw_dir.c | 29 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/wrapper.c | 515 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/wrapper.h | 4 |
10 files changed, 479 insertions, 287 deletions
diff --git a/examples/libsmbclient/smbwrapper/Makefile b/examples/libsmbclient/smbwrapper/Makefile index 8e7070cb59..c94ef8fa6a 100644 --- a/examples/libsmbclient/smbwrapper/Makefile +++ b/examples/libsmbclient/smbwrapper/Makefile @@ -10,8 +10,11 @@ CFLAGS= -fpic -g -O0 $(DEFS) $(SMBINCLUDE) BIN = . -SMBWRAPPER_OBJS = smbw.o smbw_dir.o smbw_stat.o wrapper.o select.o -SMBSH_OBJS = smbsh.o +STRFUNC = bsd-strlcat.o bsd-strlcpy.o + + +SMBWRAPPER_OBJS = smbw.o smbw_dir.o smbw_stat.o wrapper.o select.o $(STRFUNC) +SMBSH_OBJS = smbsh.o $(STRFUNC) all: $(BIN)/smbwrapper.so $(BIN)/smbsh diff --git a/examples/libsmbclient/smbwrapper/bsd-strlcat.c b/examples/libsmbclient/smbwrapper/bsd-strlcat.c new file mode 100644 index 0000000000..d82ced3e8a --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlcat.c @@ -0,0 +1,71 @@ +/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This version has been modified for inclusion in Samba. + * It has been converted to ANSI C from old-style K&R C. + */ + +#include <sys/types.h> +#include <string.h> + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +smbw_strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/examples/libsmbclient/smbwrapper/bsd-strlcpy.c b/examples/libsmbclient/smbwrapper/bsd-strlcpy.c new file mode 100644 index 0000000000..9f7e55da8e --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlcpy.c @@ -0,0 +1,67 @@ +/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This version has been modified for inclusion in Samba. + * It has been converted to ANSI C from old-style K&R C. + */ + +#include <sys/types.h> +#include <string.h> + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +smbw_strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/examples/libsmbclient/smbwrapper/bsd-strlfunc.h b/examples/libsmbclient/smbwrapper/bsd-strlfunc.h new file mode 100644 index 0000000000..fb3a045ac6 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlfunc.h @@ -0,0 +1,7 @@ +#ifndef __BSD_STRLFUNC_H__ + +extern size_t strlcpy(char *dst, const char *src, size_t siz); +extern size_t strlcat(char *dst, const char *src, size_t siz); + +#define __BSD_STRLFUNC_H__ +#endif diff --git a/examples/libsmbclient/smbwrapper/smbsh.c b/examples/libsmbclient/smbwrapper/smbsh.c index 7b33de766f..23b1ac26c7 100644 --- a/examples/libsmbclient/smbwrapper/smbsh.c +++ b/examples/libsmbclient/smbwrapper/smbsh.c @@ -28,6 +28,7 @@ #include <limits.h> #include <string.h> #include <libsmbclient.h> +#include "bsd-strlfunc.h" #ifndef FALSE # define FALSE (0) @@ -67,13 +68,13 @@ int main(int argc, char *argv[]) switch (opt) { case 'p': /* prepend library before smbwrapper.so */ if (*pre != '\0') - strncat(pre, " ", PATH_MAX - strlen(pre)); - strncat(pre, optarg, PATH_MAX - strlen(pre)); + smbw_strlcat(pre, " ", sizeof(pre)); + smbw_strlcat(pre, optarg, sizeof(pre)); break; case 'a': /* append library after smbwrapper.so */ - strncat(post, " ", PATH_MAX - strlen(post)); - strncat(post, optarg, PATH_MAX - strlen(post)); + smbw_strlcat(post, " ", sizeof(post)); + smbw_strlcat(post, optarg, sizeof(post)); break; case 'd': @@ -121,20 +122,22 @@ int main(int argc, char *argv[]) } } - strncpy(line, pre, PATH_MAX - strlen(line)); - strncat(line, " ", PATH_MAX - strlen(line)); - strncat(line, libd, PATH_MAX - strlen(line)); - strncat(line, "/smbwrapper.so", PATH_MAX - strlen(line)); - strncat(line, post, PATH_MAX - strlen(line)); + smbw_strlcpy(line, pre, PATH_MAX - strlen(line)); + smbw_strlcat(line, " ", sizeof(line)); + smbw_strlcat(line, libd, sizeof(line)); + smbw_strlcat(line, "/smbwrapper.so", sizeof(line)); + smbw_strlcat(line, post, sizeof(line)); setenv("LD_PRELOAD", line, TRUE); setenv("LD_BIND_NOW", "true", TRUE); snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd); if (stat(line, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) { - snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd); + snprintf(line, sizeof(line)-1, + "%s/smbwrapper.32.so:DEFAULT", libd); setenv("_RLD_LIST", line, TRUE); - snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); + snprintf(line, sizeof(line)-1, + "%s/smbwrapper.so:DEFAULT", libd); setenv("_RLDN32_LIST", line, TRUE); } else { snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c index d2f1c18695..a44f2f4046 100644 --- a/examples/libsmbclient/smbwrapper/smbw.c +++ b/examples/libsmbclient/smbwrapper/smbw.c @@ -26,6 +26,13 @@ #include <stdarg.h> #include <assert.h> #include "smbw.h" +#include "bsd-strlfunc.h" + +typedef enum StartupType +{ + StartupType_Fake, + StartupType_Real +} StartupType; int smbw_fd_map[__FD_SETSIZE]; int smbw_ref_count[__FD_SETSIZE]; @@ -44,6 +51,9 @@ static SMBCCTX *smbw_ctx; extern int smbw_debug; +/***************************************************** +smbw_ref -- manipulate reference counts +******************************************************/ int smbw_ref(int client_fd, Ref_Count_Type type, ...) { va_list ap; @@ -100,9 +110,9 @@ static void get_envvar_auth_data(const char *srv, p = getenv("PASSWORD"); if (p == NULL) p = ""; - strncpy(wg, w, wglen); - strncpy(un, u, unlen); - strncpy(pw, p, pwlen); + smbw_strlcpy(wg, w, wglen); + smbw_strlcpy(un, u, unlen); + smbw_strlcpy(pw, p, pwlen); } static smbc_get_auth_data_fn get_auth_data_fn = get_envvar_auth_data; @@ -130,7 +140,7 @@ static void do_shutdown(void) /***************************************************** initialise structures *******************************************************/ -static void do_init(int is_real_startup) +static void do_init(StartupType startupType) { int i; char *p; @@ -147,7 +157,7 @@ static void do_init(int is_real_startup) /* See if we've been told to start in a particular directory */ if ((p=getenv("SMBW_DIR")) != NULL) { - strncpy(smbw_cwd, p, PATH_MAX); + smbw_strlcpy(smbw_cwd, p, PATH_MAX); /* we don't want the old directory to be busy */ (* smbw_libc.chdir)("/"); @@ -161,6 +171,7 @@ static void do_init(int is_real_startup) } if ((smbw_ctx = smbc_new_context()) == NULL) { + fprintf(stderr, "Could not create a context.\n"); exit(1); } @@ -169,16 +180,16 @@ static void do_init(int is_real_startup) smbw_ctx->options.browse_max_lmb_count = 0; smbw_ctx->options.urlencode_readdir_entries = 1; smbw_ctx->options.one_share_per_server = 1; -// smbw_cache_functions(smbw_ctx); if (smbc_init_context(smbw_ctx) == NULL) { + fprintf(stderr, "Could not initialize context.\n"); exit(1); } smbc_set_context(smbw_ctx); /* if not real startup, exit handler has already been established */ - if (is_real_startup) { + if (startupType == StartupType_Real) { atexit(do_shutdown); } } @@ -188,7 +199,7 @@ initialise structures, real start up vs a fork() *******************************************************/ void smbw_init(void) { - do_init(1); + do_init(StartupType_Real); } @@ -407,6 +418,10 @@ ssize_t smbw_pread(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs) int saved_errno; SMBW_OFF_T old_ofs; + if (count == 0) { + return 0; + } + client_fd = smbw_fd_map[smbw_fd]; if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 || @@ -460,6 +475,10 @@ ssize_t smbw_pwrite(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs) ssize_t ret; SMBW_OFF_T old_ofs; + if (count == 0) { + return 0; + } + client_fd = smbw_fd_map[smbw_fd]; if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 || @@ -731,7 +750,7 @@ int smbw_fork(void) } /* Re-initialize this library for the child */ - do_init(0); + do_init(StartupType_Fake); /* and continue in the child */ return 0; diff --git a/examples/libsmbclient/smbwrapper/smbw.h b/examples/libsmbclient/smbwrapper/smbw.h index 717b5c2f1c..161d57ebbb 100644 --- a/examples/libsmbclient/smbwrapper/smbw.h +++ b/examples/libsmbclient/smbwrapper/smbw.h @@ -34,6 +34,10 @@ #include "libsmbclient.h" #include "wrapper.h" +#ifndef __restrict +# define __restrict +#endif + #undef DEBUG #define DEBUG(level, s) do { if (level <= debug_level) printf s; } while (0) diff --git a/examples/libsmbclient/smbwrapper/smbw_dir.c b/examples/libsmbclient/smbwrapper/smbw_dir.c index f3ec03e5a8..986b7f8220 100644 --- a/examples/libsmbclient/smbwrapper/smbw_dir.c +++ b/examples/libsmbclient/smbwrapper/smbw_dir.c @@ -21,6 +21,7 @@ */ #include "smbw.h" +#include "bsd-strlfunc.h" /***************************************************** determine if a directory handle is a smb one @@ -70,12 +71,12 @@ int smbw_getdents(unsigned int fd_smbw, dirent_external->d_reclen = sizeof(struct SMBW_dirent); dirent_external->d_type = dirent_internal->smbc_type; - strncpy(dirent_external->d_name, - dirent_internal->name, - sizeof(dirent_external->d_name) - 1); - strncpy(dirent_external->d_comment, - dirent_internal->comment, - sizeof(dirent_external->d_comment) - 1); + smbw_strlcpy(dirent_external->d_name, + dirent_internal->name, + sizeof(dirent_external->d_name) - 1); + smbw_strlcpy(dirent_external->d_comment, + dirent_internal->comment, + sizeof(dirent_external->d_comment) - 1); } return(count - remaining); @@ -128,7 +129,7 @@ int smbw_chdir(const char *name) } } - strncpy(smbw_cwd, path, PATH_MAX); + smbw_strlcpy(smbw_cwd, path, PATH_MAX); /* we don't want the old directory to be busy */ (* smbw_libc.chdir)("/"); @@ -196,7 +197,7 @@ char *smbw_getcwd(char *buf, size_t size) } } - strncpy(buf, smbw_cwd, size); + smbw_strlcpy(buf, smbw_cwd, size); buf[size-1] = '\0'; return buf; } @@ -278,12 +279,12 @@ struct SMBW_dirent *smbw_readdir(DIR *dirp) dirent_external.d_off = smbc_telldir(fd_client); dirent_external.d_reclen = sizeof(struct SMBW_dirent); dirent_external.d_type = dirent_internal->smbc_type; - strncpy(dirent_external.d_name, - dirent_internal->name, - sizeof(dirent_external.d_name) - 1); - strncpy(dirent_external.d_comment, - dirent_internal->comment, - sizeof(dirent_external.d_comment) - 1); + smbw_strlcpy(dirent_external.d_name, + dirent_internal->name, + sizeof(dirent_external.d_name) - 1); + smbw_strlcpy(dirent_external.d_comment, + dirent_internal->comment, + sizeof(dirent_external.d_comment) - 1); return &dirent_external; } diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c index 71d6f203ad..12904c3073 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.c +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -65,6 +65,7 @@ #include <dlfcn.h> #include <errno.h> #include "libsmbclient.h" +#include "bsd-strlfunc.h" #include "wrapper.h" /* @@ -106,12 +107,12 @@ static int debugFd = 2; if (! initialized) initialize(); \ (* smbw_libc.write)(debugFd, "["buf"]", sizeof(buf)+1); \ errno = saved_errno; \ - } while (0); + } while (0) #else # define check_init(buf) \ do { \ if (! initialized) smbw_initialize(); \ - } while (0); + } while (0) #endif static void initialize(void); @@ -135,17 +136,20 @@ static void initialize(void) #if SMBW_DEBUG & 0x1 char *error; #endif - + saved_errno = errno; if (initialized) { - errno = saved_errno; return; } initialized = 1; if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { +#ifdef RTLD_NEXT + lib = RTLD_NEXT; +#else exit(1); +#endif } #if SMBW_DEBUG & 0x1 @@ -171,117 +175,122 @@ static void initialize(void) * C library doesn't support them, then the wrapper function will * never be called, and the null pointer will never be dereferenced. */ - do { - GETSYM(write, "write"); /* first, to allow debugging */ - GETSYM(open, "open"); - GETSYM(_open, "_open"); - GETSYM(__open, "__open"); - GETSYM(open64, "open64"); - GETSYM(_open64, "_open64"); - GETSYM(__open64, "__open64"); - GETSYM(pread, "pread"); - GETSYM(pread64, "pread64"); - GETSYM(pwrite, "pwrite"); - GETSYM(pwrite64, "pwrite64"); - GETSYM(close, "close"); - GETSYM(__close, "__close"); - GETSYM(_close, "_close"); - GETSYM(fcntl, "fcntl"); - GETSYM(__fcntl, "__fcntl"); - GETSYM(_fcntl, "_fcntl"); - GETSYM(getdents, "getdents"); - GETSYM(__getdents, "__getdents"); - GETSYM(_getdents, "_getdents"); - GETSYM(getdents64, "getdents64"); - GETSYM(lseek, "lseek"); - GETSYM(__lseek, "__lseek"); - GETSYM(_lseek, "_lseek"); - GETSYM(lseek64, "lseek64"); - GETSYM(__lseek64, "__lseek64"); - GETSYM(_lseek64, "_lseek64"); - GETSYM(read, "read"); - GETSYM(__read, "__read"); - GETSYM(_read, "_read"); - GETSYM(__write, "__write"); - GETSYM(_write, "_write"); - GETSYM(access, "access"); - GETSYM(chmod, "chmod"); - GETSYM(fchmod, "fchmod"); - GETSYM(chown, "chown"); - GETSYM(fchown, "fchown"); - GETSYM(__xstat, "__xstat"); - GETSYM(getcwd, "getcwd"); - GETSYM(mkdir, "mkdir"); - GETSYM(__fxstat, "__fxstat"); - GETSYM(__lxstat, "__lxstat"); - GETSYM(stat, "stat"); - GETSYM(lstat, "lstat"); - GETSYM(fstat, "fstat"); - GETSYM(unlink, "unlink"); - GETSYM(utime, "utime"); - GETSYM(utimes, "utimes"); - GETSYM(readlink, "readlink"); - GETSYM(rename, "rename"); - GETSYM(rmdir, "rmdir"); - GETSYM(symlink, "symlink"); - GETSYM(dup, "dup"); - GETSYM(dup2, "dup2"); - GETSYM(opendir, "opendir"); - GETSYM(readdir, "readdir"); - GETSYM(closedir, "closedir"); - GETSYM(telldir, "telldir"); - GETSYM(seekdir, "seekdir"); - GETSYM(creat, "creat"); - GETSYM(creat64, "creat64"); - GETSYM(__xstat64, "__xstat64"); - GETSYM(stat64, "stat64"); - GETSYM(__fxstat64, "__fxstat64"); - GETSYM(fstat64, "fstat64"); - GETSYM(__lxstat64, "__lxstat64"); - GETSYM(lstat64, "lstat64"); - GETSYM(_llseek, "_llseek"); - GETSYM(readdir64, "readdir64"); - GETSYM(readdir_r, "readdir_r"); - GETSYM(readdir64_r, "readdir64_r"); - GETSYM(setxattr, "setxattr"); - GETSYM(lsetxattr, "lsetxattr"); - GETSYM(fsetxattr, "fsetxattr"); - GETSYM(getxattr, "getxattr"); - GETSYM(lgetxattr, "lgetxattr"); - GETSYM(fgetxattr, "fgetxattr"); - GETSYM(removexattr, "removexattr"); - GETSYM(lremovexattr, "lremovexattr"); - GETSYM(fremovexattr, "fremovexattr"); - GETSYM(listxattr, "listxattr"); - GETSYM(llistxattr, "llistxattr"); - GETSYM(flistxattr, "flistxattr"); - GETSYM(chdir, "chdir"); - GETSYM(fchdir, "fchdir"); - GETSYM(fork, "fork"); - GETSYM(select, "select"); - GETSYM(_select, "_select"); - GETSYM(__select, "__select"); - } while (0); + GETSYM(write, "write"); /* first, to allow debugging */ + GETSYM(open, "open"); + GETSYM(_open, "_open"); + GETSYM(__open, "__open"); + GETSYM(open64, "open64"); + GETSYM(_open64, "_open64"); + GETSYM(__open64, "__open64"); + GETSYM(pread, "pread"); + GETSYM(pread64, "pread64"); + GETSYM(pwrite, "pwrite"); + GETSYM(pwrite64, "pwrite64"); + GETSYM(close, "close"); + GETSYM(__close, "__close"); + GETSYM(_close, "_close"); + GETSYM(fcntl, "fcntl"); + GETSYM(__fcntl, "__fcntl"); + GETSYM(_fcntl, "_fcntl"); + GETSYM(getdents, "getdents"); + GETSYM(__getdents, "__getdents"); + GETSYM(_getdents, "_getdents"); + GETSYM(getdents64, "getdents64"); + GETSYM(lseek, "lseek"); + GETSYM(__lseek, "__lseek"); + GETSYM(_lseek, "_lseek"); + GETSYM(lseek64, "lseek64"); + GETSYM(__lseek64, "__lseek64"); + GETSYM(_lseek64, "_lseek64"); + GETSYM(read, "read"); + GETSYM(__read, "__read"); + GETSYM(_read, "_read"); + GETSYM(__write, "__write"); + GETSYM(_write, "_write"); + GETSYM(access, "access"); + GETSYM(chmod, "chmod"); + GETSYM(fchmod, "fchmod"); + GETSYM(chown, "chown"); + GETSYM(fchown, "fchown"); + GETSYM(__xstat, "__xstat"); + GETSYM(getcwd, "getcwd"); + GETSYM(mkdir, "mkdir"); + GETSYM(__fxstat, "__fxstat"); + GETSYM(__lxstat, "__lxstat"); + GETSYM(stat, "stat"); + GETSYM(lstat, "lstat"); + GETSYM(fstat, "fstat"); + GETSYM(unlink, "unlink"); + GETSYM(utime, "utime"); + GETSYM(utimes, "utimes"); + GETSYM(readlink, "readlink"); + GETSYM(rename, "rename"); + GETSYM(rmdir, "rmdir"); + GETSYM(symlink, "symlink"); + GETSYM(dup, "dup"); + GETSYM(dup2, "dup2"); + GETSYM(opendir, "opendir"); + GETSYM(readdir, "readdir"); + GETSYM(closedir, "closedir"); + GETSYM(telldir, "telldir"); + GETSYM(seekdir, "seekdir"); + GETSYM(creat, "creat"); + GETSYM(creat64, "creat64"); + GETSYM(__xstat64, "__xstat64"); + GETSYM(stat64, "stat64"); + GETSYM(__fxstat64, "__fxstat64"); + GETSYM(fstat64, "fstat64"); + GETSYM(__lxstat64, "__lxstat64"); + GETSYM(lstat64, "lstat64"); + GETSYM(_llseek, "_llseek"); + GETSYM(readdir64, "readdir64"); + GETSYM(readdir_r, "readdir_r"); + GETSYM(readdir64_r, "readdir64_r"); + GETSYM(setxattr, "setxattr"); + GETSYM(lsetxattr, "lsetxattr"); + GETSYM(fsetxattr, "fsetxattr"); + GETSYM(getxattr, "getxattr"); + GETSYM(lgetxattr, "lgetxattr"); + GETSYM(fgetxattr, "fgetxattr"); + GETSYM(removexattr, "removexattr"); + GETSYM(lremovexattr, "lremovexattr"); + GETSYM(fremovexattr, "fremovexattr"); + GETSYM(listxattr, "listxattr"); + GETSYM(llistxattr, "llistxattr"); + GETSYM(flistxattr, "flistxattr"); + GETSYM(chdir, "chdir"); + GETSYM(fchdir, "fchdir"); + GETSYM(fork, "fork"); + GETSYM(select, "select"); + GETSYM(_select, "_select"); + GETSYM(__select, "__select"); +#ifdef RTLD_NEXT + if (lib != RTLD_NEXT) { + dlclose(lib); + } +#else dlclose(lib); - +#endif + + /* Ensure that the C library is immediately available */ if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { exit(1); } #if SMBW_DEBUG & 4 { - if ((debugFd = - open(SMBW_DEBUG_FILE, O_WRONLY | O_CREAT | O_APPEND)) < 0) - { + if ((debugFd = + open(SMBW_DEBUG_FILE, O_WRONLY | O_CREAT | O_APPEND)) < 0) + { # define SMBW_MESSAGE "Could not create " SMBW_DEBUG_FILE "\n" - (* smbw_libc.write)(1, SMBW_MESSAGE, sizeof(SMBW_MESSAGE)); + (* smbw_libc.write)(1, SMBW_MESSAGE, sizeof(SMBW_MESSAGE)); # undef SMBW_MESSAGE - exit(1); - } + exit(1); + } } #endif - + errno = saved_errno; } @@ -328,11 +337,11 @@ static void stat64_convert(struct SMBW_stat *src, struct stat64 *dest) static void dirent_convert(struct SMBW_dirent *src, struct dirent *dest) { char *p; - + memset(dest, '\0', sizeof(*dest)); dest->d_ino = src->d_ino; dest->d_off = src->d_off; - + switch(src->d_type) { case SMBC_WORKGROUP: @@ -362,21 +371,23 @@ static void dirent_convert(struct SMBW_dirent *src, struct dirent *dest) dest->d_type = DT_LNK; break; } - + dest->d_reclen = src->d_reclen; - strncpy(dest->d_name, src->d_name, sizeof(dest->d_name)); + smbw_strlcpy(dest->d_name, src->d_name, sizeof(dest->d_name)); p = dest->d_name + strlen(dest->d_name) + 1; - strncpy(p, src->d_comment, sizeof(dest->d_name) - (p - dest->d_name)); + smbw_strlcpy(p, + src->d_comment, + sizeof(dest->d_name) - (p - dest->d_name)); } static void dirent64_convert(struct SMBW_dirent *src, struct dirent64 *dest) { char *p; - + memset(dest, '\0', sizeof(*dest)); dest->d_ino = src->d_ino; dest->d_off = src->d_off; - + switch(src->d_type) { case SMBC_WORKGROUP: @@ -406,11 +417,13 @@ static void dirent64_convert(struct SMBW_dirent *src, struct dirent64 *dest) dest->d_type = DT_LNK; break; } - + dest->d_reclen = src->d_reclen; - strncpy(dest->d_name, src->d_name, sizeof(dest->d_name)); + smbw_strlcpy(dest->d_name, src->d_name, sizeof(dest->d_name)); p = dest->d_name + strlen(dest->d_name) + 1; - strncpy(p, src->d_comment, sizeof(dest->d_name) - (p - dest->d_name)); + smbw_strlcpy(p, + src->d_comment, + sizeof(dest->d_name) - (p - dest->d_name)); } static int openx(char *name, int flags, mode_t mode, int (* f)(char *, int, mode_t)) @@ -418,7 +431,7 @@ static int openx(char *name, int flags, mode_t mode, int (* f)(char *, int, mode if (smbw_path(name)) { return smbw_open(name, flags, mode); } - + return (* f)(name, flags, mode); } @@ -427,7 +440,7 @@ static int closex(int fd, int (* f)(int fd)) if (smbw_fd(fd)) { return smbw_close(fd); } - + return (* f)(fd); } @@ -436,7 +449,7 @@ static int fcntlx(int fd, int cmd, long arg, int (* f)(int, int, long)) if (smbw_fd(fd)) { return smbw_fcntl(fd, cmd, arg); } - + return (* f)(fd, cmd, arg); } @@ -448,14 +461,14 @@ static int getdentsx(int fd, struct dirent *external, unsigned int count, int (* struct SMBW_dirent *internal; int ret; int n; - + /* * LIMITATION: If they pass a count which is not a multiple of * the size of struct dirent, they will not get a partial * structure; we ignore the excess count. */ n = (count / sizeof(struct dirent)); - + internal_count = sizeof(struct SMBW_dirent) * n; internal = malloc(internal_count); if (internal == NULL) { @@ -465,15 +478,15 @@ static int getdentsx(int fd, struct dirent *external, unsigned int count, int (* ret = smbw_getdents(fd, internal, internal_count); if (ret <= 0) return ret; - + ret = sizeof(struct dirent) * n; for (i = 0; i < n; i++) dirent_convert(&internal[i], &external[i]); - + return ret; } - + return (* f)(fd, external, count); } @@ -483,7 +496,7 @@ static off_t lseekx(int fd, off_t (* f)(int, off_t, int)) { off_t ret; - + /* * We have left the definitions of the smbw_ functions undefined, * because types such as off_t can differ in meaning betweent his @@ -491,11 +504,11 @@ static off_t lseekx(int fd, * integer value, however, MUST have their return value defined. */ off64_t smbw_lseek(); - + if (smbw_fd(fd)) { return (off_t) smbw_lseek(fd, offset, whence); } - + ret = (* f)(fd, offset, whence); if (smbw_debug) { @@ -513,7 +526,7 @@ static off64_t lseek64x(int fd, off64_t (* f)(int, off64_t, int)) { off64_t ret; - + /* * We have left the definitions of the smbw_ functions undefined, * because types such as off_t can differ in meaning betweent his @@ -521,7 +534,7 @@ static off64_t lseek64x(int fd, * integer value, however, MUST have their return value defined. */ off64_t smbw_lseek(); - + if (smbw_fd(fd)) ret = smbw_lseek(fd, offset, whence); else @@ -541,7 +554,7 @@ static ssize_t readx(int fd, void *buf, size_t count, ssize_t (* f)(int, void *, if (smbw_fd(fd)) { return smbw_read(fd, buf, count); } - + return (* f)(fd, buf, count); } @@ -550,7 +563,7 @@ static ssize_t writex(int fd, void *buf, size_t count, ssize_t (* f)(int, void * if (smbw_fd(fd)) { return smbw_write(fd, buf, count); } - + return (* f)(fd, buf, count); } @@ -563,27 +576,27 @@ int open(__const char *name, int flags, ...) { va_list ap; mode_t mode; - + va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); - + check_init("open"); - + return openx((char *) name, flags, mode, smbw_libc.open); } int _open(char *name, int flags, mode_t mode) { check_init("open"); - + return openx(name, flags, mode, smbw_libc._open); } int __open(char *name, int flags, mode_t mode) { check_init("open"); - + return openx(name, flags, mode, smbw_libc.__open); } @@ -591,11 +604,11 @@ int open64 (__const char *name, int flags, ...) { va_list ap; mode_t mode; - + va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); - + check_init("open64"); return openx((char *) name, flags, mode, smbw_libc.open64); } @@ -615,44 +628,44 @@ int __open64(char *name, int flags, mode_t mode) ssize_t pread(int fd, void *buf, size_t size, off_t ofs) { check_init("pread"); - + if (smbw_fd(fd)) { return smbw_pread(fd, buf, size, ofs); } - + return (* smbw_libc.pread)(fd, buf, size, ofs); } ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs) { check_init("pread64"); - + if (smbw_fd(fd)) { return smbw_pread(fd, buf, size, (off_t) ofs); } - + return (* smbw_libc.pread64)(fd, buf, size, ofs); } ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) { check_init("pwrite"); - + if (smbw_fd(fd)) { return smbw_pwrite(fd, (void *) buf, size, ofs); } - + return (* smbw_libc.pwrite)(fd, (void *) buf, size, ofs); } ssize_t pwrite64(int fd, const void *buf, size_t size, off64_t ofs) { check_init("pwrite64"); - + if (smbw_fd(fd)) { return smbw_pwrite(fd, (void *) buf, size, (off_t) ofs); } - + return (* smbw_libc.pwrite64)(fd, (void *) buf, size, ofs); } @@ -714,11 +727,11 @@ int fcntl (int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("fcntl"); return fcntlx(fd, cmd, arg, smbw_libc.fcntl); } @@ -727,11 +740,11 @@ int __fcntl(int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("__fcntl"); return fcntlx(fd, cmd, arg, smbw_libc.__fcntl); } @@ -740,11 +753,11 @@ int _fcntl(int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("_fcntl"); return fcntlx(fd, cmd, arg, smbw_libc._fcntl); } @@ -775,14 +788,14 @@ int getdents64(int fd, struct dirent64 *external, unsigned int count) struct SMBW_dirent *internal; int ret; int n; - + /* * LIMITATION: If they pass a count which is not a multiple of * the size of struct dirent, they will not get a partial * structure; we ignore the excess count. */ n = (count / sizeof(struct dirent64)); - + internal = malloc(sizeof(struct SMBW_dirent) * n); if (internal == NULL) { errno = ENOMEM; @@ -791,15 +804,15 @@ int getdents64(int fd, struct dirent64 *external, unsigned int count) ret = smbw_getdents(fd, internal, count); if (ret <= 0) return ret; - + ret = sizeof(struct dirent) * count; for (i = 0; count; i++, count--) dirent64_convert(&internal[i], &external[i]); - + return ret; } - + return (* smbw_libc.getdents64)(fd, external, count); } @@ -923,57 +936,57 @@ ssize_t _write(int fd, const void *buf, size_t count) int access(const char *name, int mode) { check_init("access"); - + if (smbw_path((char *) name)) { return smbw_access((char *) name, mode); } - + return (* smbw_libc.access)((char *) name, mode); } int chmod(const char *name, mode_t mode) { check_init("chmod"); - + if (smbw_path((char *) name)) { return smbw_chmod((char *) name, mode); } - + return (* smbw_libc.chmod)((char *) name, mode); } int fchmod(int fd, mode_t mode) { check_init("fchmod"); - + if (smbw_fd(fd)) { /* Not yet implemented in libsmbclient */ return ENOTSUP; } - + return (* smbw_libc.fchmod)(fd, mode); } int chown(const char *name, uid_t owner, gid_t group) { check_init("chown"); - + if (smbw_path((char *) name)) { return smbw_chown((char *) name, owner, group); } - + return (* smbw_libc.chown)((char *) name, owner, group); } int fchown(int fd, uid_t owner, gid_t group) { check_init("fchown"); - + if (smbw_fd(fd)) { /* Not yet implemented in libsmbclient */ return ENOTSUP; } - + return (* smbw_libc.fchown)(fd, owner, group); } @@ -986,148 +999,148 @@ char *getcwd(char *buf, size_t size) int mkdir(const char *name, mode_t mode) { check_init("mkdir"); - + if (smbw_path((char *) name)) { return smbw_mkdir((char *) name, mode); } - + return (* smbw_libc.mkdir)((char *) name, mode); } int __fxstat(int vers, int fd, struct stat *st) { check_init("__fxstat"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__fxstat)(vers, fd, st); } int __xstat(int vers, const char *name, struct stat *st) { check_init("__xstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__xstat)(vers, (char *) name, st); } int __lxstat(int vers, const char *name, struct stat *st) { check_init("__lxstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__lxstat)(vers, (char *) name, st); } int stat(const char *name, struct stat *st) { check_init("stat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.stat)((char *) name, st); } int lstat(const char *name, struct stat *st) { check_init("lstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.lstat)((char *) name, st); } int fstat(int fd, struct stat *st) { check_init("fstat"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.fstat)(fd, st); } int unlink(const char *name) { check_init("unlink"); - + if (smbw_path((char *) name)) { return smbw_unlink((char *) name); } - + return (* smbw_libc.unlink)((char *) name); } int utime(const char *name, const struct utimbuf *tvp) { check_init("utime"); - + if (smbw_path(name)) { return smbw_utime(name, (struct utimbuf *) tvp); } - + return (* smbw_libc.utime)((char *) name, (struct utimbuf *) tvp); } int utimes(const char *name, const struct timeval *tvp) { check_init("utimes"); - + if (smbw_path(name)) { return smbw_utimes(name, (struct timeval *) tvp); } - + return (* smbw_libc.utimes)((char *) name, (struct timeval *) tvp); } int readlink(const char *path, char *buf, size_t bufsize) { check_init("readlink"); - + if (smbw_path((char *) path)) { return smbw_readlink(path, (char *) buf, bufsize); } - + return (* smbw_libc.readlink)((char *) path, buf, bufsize); } int rename(const char *oldname, const char *newname) { int p1, p2; - + check_init("rename"); - + p1 = smbw_path((char *) oldname); p2 = smbw_path((char *) newname); if (p1 ^ p2) { @@ -1138,27 +1151,27 @@ int rename(const char *oldname, const char *newname) if (p1 && p2) { return smbw_rename((char *) oldname, (char *) newname); } - + return (* smbw_libc.rename)((char *) oldname, (char *) newname); } int rmdir(const char *name) { check_init("rmdir"); - + if (smbw_path((char *) name)) { return smbw_rmdir((char *) name); } - + return (* smbw_libc.rmdir)((char *) name); } int symlink(const char *topath, const char *frompath) { int p1, p2; - + check_init("symlink"); - + p1 = smbw_path((char *) topath); p2 = smbw_path((char *) frompath); if (p1 || p2) { @@ -1166,25 +1179,25 @@ int symlink(const char *topath, const char *frompath) errno = EPERM; return -1; } - + return (* smbw_libc.symlink)((char *) topath, (char *) frompath); } int dup(int fd) { check_init("dup"); - + if (smbw_fd(fd)) { return smbw_dup(fd); } - + return (* smbw_libc.dup)(fd); } int dup2(int oldfd, int newfd) { check_init("dup2"); - + if (smbw_fd(newfd)) { (* smbw_libc.close)(newfd); } @@ -1192,7 +1205,7 @@ int dup2(int oldfd, int newfd) if (smbw_fd(oldfd)) { return smbw_dup2(oldfd, newfd); } - + return (* smbw_libc.dup2)(oldfd, newfd); } @@ -1200,18 +1213,18 @@ int dup2(int oldfd, int newfd) DIR *opendir(const char *name) { check_init("opendir"); - + if (smbw_path((char *) name)) { return (void *)smbw_opendir((char *) name); } - + return (* smbw_libc.opendir)((char *) name); } struct dirent *readdir(DIR *dir) { check_init("readdir"); - + if (smbw_dirp(dir)) { static struct dirent external; struct SMBW_dirent * internal = (void *)smbw_readdir(dir); @@ -1227,41 +1240,41 @@ struct dirent *readdir(DIR *dir) int closedir(DIR *dir) { check_init("closedir"); - + if (smbw_dirp(dir)) { return smbw_closedir(dir); } - + return (* smbw_libc.closedir)(dir); } long telldir(DIR *dir) { check_init("telldir"); - + if (smbw_dirp(dir)) { return (long) smbw_telldir(dir); } - + return (* smbw_libc.telldir)(dir); } void seekdir(DIR *dir, long offset) { check_init("seekdir"); - + if (smbw_dirp(dir)) { smbw_seekdir(dir, (long long) offset); return; } - + (* smbw_libc.seekdir)(dir, offset); } int creat(const char *path, mode_t mode) { extern int creat_bits; - + check_init("creat"); return openx((char *) path, creat_bits, mode, smbw_libc.open); } @@ -1269,7 +1282,7 @@ int creat(const char *path, mode_t mode) int creat64(const char *path, mode_t mode) { extern int creat_bits; - + check_init("creat64"); return openx((char *) path, creat_bits, mode, smbw_libc.open64); } @@ -1277,103 +1290,103 @@ int creat64(const char *path, mode_t mode) int __xstat64 (int ver, const char *name, struct stat64 *st64) { check_init("__xstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__xstat64)(ver, (char *) name, st64); } int stat64(const char *name, struct stat64 *st64) { check_init("stat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.stat64)((char *) name, st64); } int __fxstat64(int ver, int fd, struct stat64 *st64) { check_init("__fxstat64"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__fxstat64)(ver, fd, st64); } int fstat64(int fd, struct stat64 *st64) { check_init("fstat64"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.fstat64)(fd, st64); } int __lxstat64(int ver, const char *name, struct stat64 *st64) { check_init("__lxstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat(name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__lxstat64)(ver, (char *) name, st64); } int lstat64(const char *name, struct stat64 *st64) { check_init("lstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.lstat64)((char *) name, st64); } int _llseek(unsigned int fd, unsigned long offset_high, unsigned long offset_low, loff_t *result, unsigned int whence) { check_init("_llseek"); - + if (smbw_fd(fd)) { *result = lseek(fd, offset_low, whence); return (*result < 0 ? -1 : 0); } - + return (* smbw_libc._llseek)(fd, offset_high, offset_low, result, whence); } struct dirent64 *readdir64(DIR *dir) { check_init("readdir64"); - + if (smbw_dirp(dir)) { static struct dirent64 external; struct SMBW_dirent * internal = (void *)smbw_readdir(dir); @@ -1383,14 +1396,14 @@ struct dirent64 *readdir64(DIR *dir) } return NULL; } - + return (* smbw_libc.readdir64)(dir); } int readdir_r(DIR *dir, struct dirent *external, struct dirent **result) { check_init("readdir_r"); - + if (smbw_dirp(dir)) { struct SMBW_dirent internal; int ret = smbw_readdir_r(dir, &internal, NULL); @@ -1400,14 +1413,14 @@ int readdir_r(DIR *dir, struct dirent *external, struct dirent **result) } return ret; } - + return (* smbw_libc.readdir_r)(dir, external, result); } int readdir64_r(DIR *dir, struct dirent64 *external, struct dirent64 **result) { check_init("readdir64_r"); - + if (smbw_dirp(dir)) { struct SMBW_dirent internal; int ret = smbw_readdir_r(dir, &internal, NULL); @@ -1417,7 +1430,7 @@ int readdir64_r(DIR *dir, struct dirent64 *external, struct dirent64 **result) } return ret; } - + return (* smbw_libc.readdir64_r)(dir, external, result); } @@ -1436,7 +1449,7 @@ int setxattr(const char *fname, if (smbw_path(fname)) { return smbw_setxattr(fname, name, value, size, flags); } - + return (* smbw_libc.setxattr)(fname, name, value, size, flags); } @@ -1449,7 +1462,7 @@ int lsetxattr(const char *fname, if (smbw_path(fname)) { return smbw_lsetxattr(fname, name, value, size, flags); } - + return (* smbw_libc.lsetxattr)(fname, name, value, size, flags); } @@ -1462,7 +1475,7 @@ int fsetxattr(int fd, if (smbw_fd(fd)) { return smbw_fsetxattr(fd, name, value, size, flags); } - + return (* smbw_libc.fsetxattr)(fd, name, value, size, flags); } @@ -1474,7 +1487,7 @@ int getxattr(const char *fname, if (smbw_path(fname)) { return smbw_getxattr(fname, name, value, size); } - + return (* smbw_libc.getxattr)(fname, name, value, size); } @@ -1486,7 +1499,7 @@ int lgetxattr(const char *fname, if (smbw_path(fname)) { return smbw_lgetxattr(fname, name, value, size); } - + return (* smbw_libc.lgetxattr)(fname, name, value, size); } @@ -1498,7 +1511,7 @@ int fgetxattr(int fd, if (smbw_fd(fd)) { return smbw_fgetxattr(fd, name, value, size); } - + return (* smbw_libc.fgetxattr)(fd, name, value, size); } @@ -1508,7 +1521,7 @@ int removexattr(const char *fname, if (smbw_path(fname)) { return smbw_removexattr(fname, name); } - + return (* smbw_libc.removexattr)(fname, name); } @@ -1518,7 +1531,7 @@ int lremovexattr(const char *fname, if (smbw_path(fname)) { return smbw_lremovexattr(fname, name); } - + return (* smbw_libc.lremovexattr)(fname, name); } @@ -1528,7 +1541,7 @@ int fremovexattr(int fd, if (smbw_fd(fd)) { return smbw_fremovexattr(fd, name); } - + return (* smbw_libc.fremovexattr)(fd, name); } @@ -1539,7 +1552,7 @@ int listxattr(const char *fname, if (smbw_path(fname)) { return smbw_listxattr(fname, list, size); } - + return (* smbw_libc.listxattr)(fname, list, size); } @@ -1550,7 +1563,7 @@ int llistxattr(const char *fname, if (smbw_path(fname)) { return smbw_llistxattr(fname, list, size); } - + return (* smbw_libc.llistxattr)(fname, list, size); } @@ -1561,7 +1574,7 @@ int flistxattr(int fd, if (smbw_fd(fd)) { return smbw_flistxattr(fd, list, size); } - + return (* smbw_libc.flistxattr)(fd, list, size); } @@ -1609,7 +1622,7 @@ void free(void *ptr) { static int in_progress = 0; void __libc_free(void *ptr); - + if (in_progress) return; in_progress = 1; __libc_free(ptr); @@ -1628,7 +1641,7 @@ smbw_sigaction_handler(int signum, { /* Our entire purpose for trapping signals is to call this! */ sys_select_signal(); - + /* Call the user's handler */ if (user_action[signum].sa_handler != SIG_IGN && user_action[signum].sa_handler != SIG_DFL && @@ -1660,14 +1673,14 @@ do_select(int n, int saved_errno; sigset_t sigset; struct sigaction new_action; - + saved_errno = errno; for (i=1; i<_NSIG; i++) { sigemptyset(&sigset); new_action.sa_mask = sigset; new_action.sa_flags = SA_SIGINFO; new_action.sa_sigaction = smbw_sigaction_handler; - + if (sigaction(i, &new_action, &user_action[i]) < 0) { if (errno != EINVAL) { return -1; @@ -1675,14 +1688,14 @@ do_select(int n, } } errno = saved_errno; - + ret = (* select_fn)(n, readfds, writefds, exceptfds, timeout); saved_errno = errno; - + for (i=0; i<_NSIG; i++) { (void) sigaction(i, &user_action[i], NULL); } - + errno = saved_errno; return ret; } @@ -1695,7 +1708,7 @@ select(int n, struct timeval *timeout) { check_init("select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc.select); } @@ -1708,7 +1721,7 @@ _select(int n, struct timeval *timeout) { check_init("_select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc._select); } @@ -1721,7 +1734,7 @@ __select(int n, struct timeval *timeout) { check_init("__select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc.__select); } diff --git a/examples/libsmbclient/smbwrapper/wrapper.h b/examples/libsmbclient/smbwrapper/wrapper.h index 6d0d9f527a..5a18b9d76c 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.h +++ b/examples/libsmbclient/smbwrapper/wrapper.h @@ -32,6 +32,10 @@ #include <signal.h> #include <stdio.h> +#ifndef __FD_SETSIZE +# define __FD_SETSIZE 256 +#endif + extern int smbw_fd_map[__FD_SETSIZE]; extern int smbw_ref_count[__FD_SETSIZE]; extern char smbw_cwd[PATH_MAX]; |