1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-24 13:57:43 +03:00

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)
This commit is contained in:
Derrell Lipman 2006-01-07 20:43:36 +00:00 committed by Gerald (Jerry) Carter
parent f396e2248a
commit 96d0d186db
10 changed files with 479 additions and 287 deletions

View File

@ -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

View File

@ -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 */
}

View File

@ -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 */
}

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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;
}

File diff suppressed because it is too large Load Diff

View File

@ -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];