1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

the guts of the smbwrapper code. I may change the layout of this at

some stage.
(This used to be commit 3f34a3cac8)
This commit is contained in:
Andrew Tridgell 1998-10-02 12:37:31 +00:00
parent 019c8d2fdd
commit 24bf006d52
19 changed files with 1700 additions and 0 deletions

26
source3/smbwrapper/README Normal file
View File

@ -0,0 +1,26 @@
This is a prelodable shared library that provides SMB client services
for existing executables. Using this you can simulate a smb
filesystem.
Currently this code only works on Linux with glibc2. Eventually I hope
to make it portable to lots of OSes but at the moment if you don't
have Linux then don't even try to use it.
To use it you need to do this:
export SMBW_USER=username
export SMBW_PASSWORD=username
export LD_PRELOAD=full_path_to_smbwrapper.so
then try to access /smb/SERVER/SHARE/ and see what happens.
For debugging you can set SMBW_DEBUG to an integer debug level.
This is code under development. Lots of things don't work yet. Quite a
few things do though, for example I've successfully run tar, less, ls,
bash, cmp, cat, du and a bunch of other utilities on files accessed
via this library.
If you want to help with the development of this code then join the
samba-technical mailing list.

View File

@ -0,0 +1,32 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
int access(__const char *name, int mode)
{
if (smbw_path(name)) {
return smbw_access(name, mode);
}
return real_access(name, mode);
}

View File

@ -0,0 +1,28 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
int chdir(__const char *name)
{
return smbw_chdir(name);
}

View File

@ -0,0 +1,35 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
#ifdef linux
__asm__(".globl __close; __close = close");
#endif
ssize_t close(int fd)
{
if (smbw_fd(fd)) {
return smbw_close(fd);
}
return real_close(fd);
}

View File

@ -0,0 +1,35 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
#ifdef linux
__asm__(".globl __fcntl; __fcntl = fcntl");
#endif
int fcntl(int fd, int cmd, long arg)
{
if (smbw_fd(fd)) {
return smbw_fcntl(fd);
}
return real_fcntl(fd, cmd, arg);
}

View File

@ -0,0 +1,84 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
int __fxstat(int vers, int fd, struct stat *st)
{
struct kernel_stat kbuf;
int ret;
if (smbw_fd(fd)) {
return smbw_fstat(fd, st);
}
switch (vers) {
case _STAT_VER_LINUX_OLD:
/* Nothing to do. The struct is in the form the kernel expects
it to be. */
return real_fstat(fd, (struct kernel_stat *)st);
break;
case _STAT_VER_LINUX:
/* Do the system call. */
ret = real_fstat(fd, &kbuf);
st->st_dev = kbuf.st_dev;
#ifdef _HAVE___PAD1
st->__pad1 = 0;
#endif
st->st_ino = kbuf.st_ino;
st->st_mode = kbuf.st_mode;
st->st_nlink = kbuf.st_nlink;
st->st_uid = kbuf.st_uid;
st->st_gid = kbuf.st_gid;
st->st_rdev = kbuf.st_rdev;
#ifdef _HAVE___PAD2
st->__pad2 = 0;
#endif
st->st_size = kbuf.st_size;
st->st_blksize = kbuf.st_blksize;
st->st_blocks = kbuf.st_blocks;
st->st_atime = kbuf.st_atime;
#ifdef _HAVE___UNUSED1
st->__unused1 = 0;
#endif
st->st_mtime = kbuf.st_mtime;
#ifdef _HAVE___UNUSED2
st->__unused2 = 0;
#endif
st->st_ctime = kbuf.st_ctime;
#ifdef _HAVE___UNUSED3
st->__unused3 = 0;
#endif
#ifdef _HAVE___UNUSED4
st->__unused4 = 0;
#endif
#ifdef _HAVE___UNUSED5
st->__unused5 = 0;
#endif
return ret;
default:
errno = EINVAL;
return -1;
}
}

View File

@ -0,0 +1,36 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
#ifdef linux
__asm__(".globl __getdents; __getdents = getdents");
#endif
int getdents(unsigned int fd, struct dirent *dirp, unsigned int count)
{
if (smbw_fd(fd)) {
return smbw_getdents(fd, dirp, count);
}
return real_getdents(fd, dirp, count);
}

22
source3/smbwrapper/init.c Normal file
View File

@ -0,0 +1,22 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
initialise connections in smbwrapper
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"

View File

@ -0,0 +1,31 @@
/* Definition of `struct stat' used in the kernel.. */
struct kernel_stat
{
unsigned short int st_dev;
unsigned short int __pad1;
#define _HAVE___PAD1
unsigned long int st_ino;
unsigned short int st_mode;
unsigned short int st_nlink;
unsigned short int st_uid;
unsigned short int st_gid;
unsigned short int st_rdev;
unsigned short int __pad2;
#define _HAVE___PAD2
unsigned long int st_size;
unsigned long int st_blksize;
unsigned long int st_blocks;
unsigned long int st_atime;
unsigned long int __unused1;
#define _HAVE___UNUSED1
unsigned long int st_mtime;
unsigned long int __unused2;
#define _HAVE___UNUSED2
unsigned long int st_ctime;
unsigned long int __unused3;
#define _HAVE___UNUSED3
unsigned long int __unused4;
#define _HAVE___UNUSED4
unsigned long int __unused5;
#define _HAVE___UNUSED5
};

View File

@ -0,0 +1,85 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
int __lxstat(int vers, __const char *name, struct stat *st)
{
struct kernel_stat kbuf;
int ret;
if (smbw_path(name)) {
return smbw_stat(name, st);
}
switch (vers) {
case _STAT_VER_LINUX_OLD:
/* Nothing to do. The struct is in the form the kernel expects
it to be. */
return real_lstat(name, (struct kernel_stat *)st);
break;
case _STAT_VER_LINUX:
/* Do the system call. */
ret = real_lstat(name, &kbuf);
st->st_dev = kbuf.st_dev;
#ifdef _HAVE___PAD1
st->__pad1 = 0;
#endif
st->st_ino = kbuf.st_ino;
st->st_mode = kbuf.st_mode;
st->st_nlink = kbuf.st_nlink;
st->st_uid = kbuf.st_uid;
st->st_gid = kbuf.st_gid;
st->st_rdev = kbuf.st_rdev;
#ifdef _HAVE___PAD2
st->__pad2 = 0;
#endif
st->st_size = kbuf.st_size;
st->st_blksize = kbuf.st_blksize;
st->st_blocks = kbuf.st_blocks;
st->st_atime = kbuf.st_atime;
#ifdef _HAVE___UNUSED1
st->__unused1 = 0;
#endif
st->st_mtime = kbuf.st_mtime;
#ifdef _HAVE___UNUSED2
st->__unused2 = 0;
#endif
st->st_ctime = kbuf.st_ctime;
#ifdef _HAVE___UNUSED3
st->__unused3 = 0;
#endif
#ifdef _HAVE___UNUSED4
st->__unused4 = 0;
#endif
#ifdef _HAVE___UNUSED5
st->__unused5 = 0;
#endif
return ret;
default:
errno = EINVAL;
return -1;
}
}

36
source3/smbwrapper/open.c Normal file
View File

@ -0,0 +1,36 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
#ifdef linux
__asm__(".globl __open; __open = open");
#endif
int open(__const char *name, int flags, mode_t mode)
{
if (smbw_path(name)) {
return smbw_open(name, flags, mode);
}
return real_open(name, flags, mode);
}

35
source3/smbwrapper/read.c Normal file
View File

@ -0,0 +1,35 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
#ifdef linux
__asm__(".globl __read; __read = read");
#endif
ssize_t read(int fd, void *buf, size_t count)
{
if (smbw_fd(fd)) {
return smbw_read(fd, buf, count);
}
return real_read(fd, buf, count);
}

View File

@ -0,0 +1,44 @@
#ifdef aix
#include "aix-syscall.h"
#else
#define real_access(fn, mode) (syscall(SYS_access, (fn), (mode)))
#define real_chdir(fn) (syscall(SYS_chdir, (fn)))
#define real_chmod(fn, mode) (syscall(SYS_chmod,(fn), (mode)))
#define real_chown(fn, owner, group) (syscall(SYS_chown,(fn),(owner),(group)))
#define real_getdents(fd, dirp, count) (syscall(SYS_getdents, (fd), (dirp), (count)))
/* if needed define SYS_getdents so that getdents gets compiled */
#define real_link(fn1, fn2) (syscall(SYS_link, (fn1), (fn2)))
#define real_lstat(fn, buf ) (syscall(SYS_lstat, (fn), (buf)))
#define real_open(fn,flags,mode) (syscall(SYS_open, (fn), (flags), (mode)))
#define real_prev_lstat(fn, buf ) (syscall(SYS_prev_lstat, (fn), (buf)))
#define real_prev_stat(fn, buf ) (syscall(SYS_prev_stat, (fn), (buf)))
#ifdef linux
struct dirent *__libc_readdir(DIR * dir);
#define real_readdir(dir) (__libc_readdir(dirp))
#else
#define real_readdir(dirp) ((struct dirent *)syscall(SYS_readdir,(dirp)))
/* if needed define SYS_readdir so that readdir gets compiled */
#endif
#define real_readlink(fn,buf,len) (syscall(SYS_readlink, (fn), (buf), (len)))
#define real_rename(fn1, fn2) (syscall(SYS_rename, (fn1), (fn2)))
#define real_stat(fn, buf ) (syscall(SYS_stat, (fn), (buf)))
#define real_fstat(fd, buf ) (syscall(SYS_fstat, (fd), (buf)))
#define real_read(fd, buf, count ) (syscall(SYS_read, (fd), (buf), (count)))
#define real_write(fd, buf, count ) (syscall(SYS_write, (fd), (buf), (count)))
#define real_close(fd) (syscall(SYS_close, (fd)))
#define real_fcntl(fd,cmd,arg) (syscall(SYS_fcntl, (fd), (cmd), (arg)))
#define real_symlink(fn1, fn2) (syscall(SYS_symlink, (fn1), (fn2)))
#define real_unlink(fn) (syscall(SYS_unlink, (fn)))
#define real_utime(fn, buf) (syscall(SYS_utime, (fn), (buf)))
#define real_utimes(fn, buf) (syscall(SYS_utimes, (fn), (buf)))
#endif

6
source3/smbwrapper/smbsh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# a simple launcher for the smbwrapper.so preloadde library
export LD_PRELOAD=$PWD/smbwrapper/smbwrapper.so
bash

1005
source3/smbwrapper/smbw.c Normal file

File diff suppressed because it is too large Load Diff

28
source3/smbwrapper/smbw.h Normal file
View File

@ -0,0 +1,28 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions - definitions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define SMBW_PREFIX "/smb/"
#define SMBW_FD_OFFSET 1024
#define SMBW_MAX_OPEN 2048
#define SMBW_FILE_MODE (S_IFREG | 0644)
#define SMBW_DIR_MODE (S_IFDIR | 0755)

89
source3/smbwrapper/stat.c Normal file
View File

@ -0,0 +1,89 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
int __xstat(int vers, __const char *name, struct stat *st)
{
struct kernel_stat kbuf;
int ret;
if (smbw_path(name)) {
return smbw_stat(name, st);
}
switch (vers) {
case _STAT_VER_LINUX_OLD:
/* Nothing to do. The struct is in the form the kernel expects
it to be. */
return real_stat(name, (struct kernel_stat *)st);
break;
case _STAT_VER_LINUX:
/* Do the system call. */
ret = real_stat(name, &kbuf);
st->st_dev = kbuf.st_dev;
#ifdef _HAVE___PAD1
st->__pad1 = 0;
#endif
st->st_ino = kbuf.st_ino;
st->st_mode = kbuf.st_mode;
st->st_nlink = kbuf.st_nlink;
st->st_uid = kbuf.st_uid;
st->st_gid = kbuf.st_gid;
st->st_rdev = kbuf.st_rdev;
#ifdef _HAVE___PAD2
st->__pad2 = 0;
#endif
st->st_size = kbuf.st_size;
st->st_blksize = kbuf.st_blksize;
st->st_blocks = kbuf.st_blocks;
st->st_atime = kbuf.st_atime;
#ifdef _HAVE___UNUSED1
st->__unused1 = 0;
#endif
st->st_mtime = kbuf.st_mtime;
#ifdef _HAVE___UNUSED2
st->__unused2 = 0;
#endif
st->st_ctime = kbuf.st_ctime;
#ifdef _HAVE___UNUSED3
st->__unused3 = 0;
#endif
#ifdef _HAVE___UNUSED4
st->__unused4 = 0;
#endif
#ifdef _HAVE___UNUSED5
st->__unused5 = 0;
#endif
return ret;
default:
errno = EINVAL;
return -1;
}
}
int stat(__const char *name, struct stat *st)
{
return __xstat(_STAT_VER, name, st);
}

View File

@ -0,0 +1,8 @@
#include <syscall.h>
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "kernel_stat.h"
#include "realcalls.h"

View File

@ -0,0 +1,35 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
#ifdef linux
__asm__(".globl __write; __write = write");
#endif
ssize_t write(int fd, void *buf, size_t count)
{
if (smbw_fd(fd)) {
return smbw_write(fd, buf, count);
}
return real_write(fd, buf, count);
}