diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/Makefile.in | 10 | ||||
-rw-r--r-- | source3/include/includes.h | 1 | ||||
-rw-r--r-- | source3/include/proto.h | 56 | ||||
-rw-r--r-- | source3/smbwrapper/smbw.c | 155 | ||||
-rw-r--r-- | source3/smbwrapper/smbw.h | 1 | ||||
-rw-r--r-- | source3/smbwrapper/smbw_dir.c | 13 | ||||
-rw-r--r-- | source3/smbwrapper/smbw_stat.c | 179 | ||||
-rw-r--r-- | source3/smbwrapper/wrapped.c | 4 | ||||
-rw-r--r-- | source3/smbwrapper/wrapper.h | 36 |
9 files changed, 288 insertions, 167 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index 2ae810ae2b..466b73e6c4 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -63,7 +63,7 @@ SMBRUN = $(BINDIR)/smbrun PASSWD_FLAGS = -DSMB_PASSWD=\"$(SMB_PASSWD)\" -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" -FLAGS1 = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -DSMBLOGFILE=\"$(SMBLOGFILE)\" -DNMBLOGFILE=\"$(NMBLOGFILE)\" +FLAGS1 = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper -DSMBLOGFILE=\"$(SMBLOGFILE)\" -DNMBLOGFILE=\"$(NMBLOGFILE)\" FLAGS2 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\" FLAGS3 = -DSWATDIR=\"$(SWATDIR)\" -DSBINDIR=\"$(SBINDIR)\" -DLOCKDIR=\"$(LOCKDIR)\" -DSMBRUN=\"$(SMBRUN)\" -DCODEPAGEDIR=\"$(CODEPAGEDIR)\" FLAGS4 = -DDRIVERFILE=\"$(DRIVERFILE)\" @@ -194,6 +194,7 @@ RPCCLIENT_OBJ = rpcclient/rpcclient.o \ # rpcclient/cmd_srvsvc.o SMBWRAPPER_OBJ = smbwrapper/smbw.o smbwrapper/wrapped.o \ + smbwrapper/smbw_dir.o smbwrapper/smbw_stat.o \ $(LIBSMB_OBJ) $(PARAM_OBJ) \ $(UBIQX_OBJ) $(LIB_OBJ) @@ -215,7 +216,8 @@ NMBLOOKUP_OBJ = utils/nmblookup.o $(PARAM_OBJ) $(UBIQX_OBJ) \ SMBTORTURE_OBJ = utils/torture.o $(LIBSMB_OBJ) $(PARAM_OBJ) \ $(UBIQX_OBJ) $(LIB_OBJ) -PROTO_OBJ = $(SMBD_OBJ) $(NMBD_OBJ) $(SWAT_OBJ) $(CLIENT_OBJ) $(RPCCLIENT_OBJ) +PROTO_OBJ = $(SMBD_OBJ) $(NMBD_OBJ) $(SWAT_OBJ) $(CLIENT_OBJ) \ + $(RPCCLIENT_OBJ) $(SMBWRAPPER_OBJ) PICOBJS = $(SMBWRAPPER_OBJ:%.o=%.p) @@ -396,9 +398,9 @@ uninstallcp: clean: -rm -f core */*~ *~ */*.o */*.p -proto: +proto: @echo rebuilding include/proto.h - @cd $(srcdir) && $(AWK) -f script/mkproto.awk `echo $(PROTO_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u | grep -v "ubiqx/"` > include/proto.h + @cd $(srcdir) && $(AWK) -f script/mkproto.awk `echo $(PROTO_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u | egrep -v 'ubiqx/|wrapped'` > include/proto.h etags: etags `find . -name "*.[ch]"` diff --git a/source3/include/includes.h b/source3/include/includes.h index ecd7e0e1ab..be41db4d43 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -467,6 +467,7 @@ extern int errno; #include "version.h" #include "smb.h" +#include "smbw.h" #include "nameserv.h" #include "byteorder.h" diff --git a/source3/include/proto.h b/source3/include/proto.h index b246289fd6..932621ce9a 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -389,7 +389,7 @@ BOOL cli_getattrE(struct cli_state *cli, int fd, BOOL cli_getatr(struct cli_state *cli, char *fname, uint32 *attr, size_t *size, time_t *t); BOOL cli_setatr(struct cli_state *cli, char *fname, int attr, time_t t); -BOOL cli_qpathinfo(struct cli_state *cli, char *fname, +BOOL cli_qpathinfo(struct cli_state *cli, const char *fname, time_t *c_time, time_t *a_time, time_t *m_time, size_t *size, uint32 *mode); BOOL cli_qpathinfo2(struct cli_state *cli, char *fname, @@ -2269,6 +2269,60 @@ BOOL unbecome_user(void ); void become_root(BOOL save_dir) ; void unbecome_root(BOOL restore_dir); +/*The following definitions come from smbwrapper/smbw.c */ + +void smbw_init(void); +int smbw_fd(int fd); +ino_t smbw_inode(const char *name); +void clean_fname(char *name); +char *smbw_parse_path(const char *fname, char *server, char *share, char *path); +int smbw_path(const char *path); +int smbw_errno(struct cli_state *c); +struct smbw_server *smbw_server(char *server, char *share); +struct smbw_file *smbw_file(int fd); +int smbw_open(const char *fname, int flags, mode_t mode); +ssize_t smbw_read(int fd, void *buf, size_t count); +ssize_t smbw_write(int fd, void *buf, size_t count); +int smbw_close(int fd); +int smbw_fcntl(int fd, int cmd, long arg); +int smbw_access(const char *name, int mode); +int smbw_readlink(const char *path, char *buf, size_t bufsize); +int smbw_unlink(const char *fname); +int smbw_rename(const char *oldname, const char *newname); +int smbw_utime(const char *fname, void *buf); +int smbw_chown(const char *fname, uid_t owner, gid_t group); +int smbw_chmod(const char *fname, mode_t newmode); +off_t smbw_lseek(int fd, off_t offset, int whence); + +/*The following definitions come from smbwrapper/smbw_dir.c */ + +struct smbw_dir *smbw_dir(int fd); +int smbw_dirp(DIR *dirp); +int smbw_dir_open(const char *fname); +int smbw_dir_fstat(int fd, struct stat *st); +int smbw_dir_close(int fd); +int smbw_getdents(unsigned int fd, struct dirent *dirp, int count); +int smbw_chdir(const char *name); +off_t smbw_dir_lseek(int fd, off_t offset, int whence); +int smbw_mkdir(const char *fname, mode_t mode); +int smbw_rmdir(const char *fname); +char *smbw_getcwd(char *buf, size_t size); +int smbw_fchdir(unsigned int fd); +DIR *smbw_opendir(const char *fname); +struct dirent *smbw_readdir(DIR *dirp); +int smbw_closedir(DIR *dirp); +void smbw_seekdir(DIR *dirp, off_t offset); +off_t smbw_telldir(DIR *dirp); + +/*The following definitions come from smbwrapper/smbw_stat.c */ + +void smbw_setup_stat(struct stat *st, char *fname, size_t size, int mode); +BOOL smbw_getatr(struct smbw_server *srv, char *path, + uint32 *mode, size_t *size, + time_t *c_time, time_t *a_time, time_t *m_time); +int smbw_fstat(int fd, struct stat *st); +int smbw_stat(const char *fname, struct stat *st); + /*The following definitions come from web/cgi.c */ void cgi_load_variables(FILE *f1); diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c index 5a954d2fed..d79131a8ea 100644 --- a/source3/smbwrapper/smbw.c +++ b/source3/smbwrapper/smbw.c @@ -20,7 +20,6 @@ */ #include "includes.h" -#include "smbw.h" #include "wrapper.h" pstring smb_cwd; @@ -461,54 +460,6 @@ struct smbw_file *smbw_file(int fd) return NULL; } - -/***************************************************** -setup basic info in a stat structure -*******************************************************/ -void smbw_setup_stat(struct stat *st, char *fname, size_t size, int mode) -{ - ZERO_STRUCTP(st); - - if (IS_DOS_DIR(mode)) { - st->st_mode = SMBW_DIR_MODE; - } else { - st->st_mode = SMBW_FILE_MODE; - } - - st->st_size = size; - st->st_blksize = 512; - st->st_blocks = (size+511)/512; - st->st_uid = getuid(); - st->st_gid = getgid(); - st->st_ino = smbw_inode(fname); -} - - -/***************************************************** -try to do a QPATHINFO and if that fails then do a getatr -this is needed because win95 sometimes refuses the qpathinfo -*******************************************************/ -BOOL smbw_getatr(struct smbw_server *srv, char *path, - uint32 *mode, size_t *size, - time_t *c_time, time_t *a_time, time_t *m_time) -{ - DEBUG(5,("sending qpathinfo\n")); - - if (cli_qpathinfo(&srv->cli, path, c_time, a_time, m_time, - size, mode)) return True; - - DEBUG(5,("qpathinfo OK\n")); - - /* if this is NT then don't bother with the getatr */ - if (srv->cli.capabilities & CAP_NT_SMBS) return False; - - if (cli_getatr(&srv->cli, path, mode, size, m_time)) { - a_time = c_time = m_time; - return True; - } - return False; -} - /***************************************************** a wrapper for open() *******************************************************/ @@ -604,107 +555,6 @@ int smbw_open(const char *fname, int flags, mode_t mode) return -1; } -/***************************************************** -a wrapper for fstat() -*******************************************************/ -int smbw_fstat(int fd, struct stat *st) -{ - struct smbw_file *file; - time_t c_time, a_time, m_time; - uint32 size; - int mode; - - DEBUG(4,("%s\n", __FUNCTION__)); - - smbw_busy++; - - file = smbw_file(fd); - if (!file) { - int ret = smbw_dir_fstat(fd, st); - smbw_busy--; - return ret; - } - - if (!cli_qfileinfo(&file->srv->cli, file->cli_fd, - &mode, &size, &c_time, &a_time, &m_time) && - !cli_getattrE(&file->srv->cli, file->cli_fd, - &mode, &size, &c_time, &a_time, &m_time)) { - errno = EINVAL; - smbw_busy--; - return -1; - } - - smbw_setup_stat(st, file->fname, size, mode); - - st->st_atime = a_time; - st->st_ctime = c_time; - st->st_mtime = m_time; - st->st_dev = file->srv->dev; - - DEBUG(4,("%s - OK\n", __FUNCTION__)); - - smbw_busy--; - return 0; -} - - -/***************************************************** -a wrapper for stat() -*******************************************************/ -int smbw_stat(const char *fname, struct stat *st) -{ - struct smbw_server *srv; - fstring server, share; - pstring path; - time_t m_time=0, a_time=0, c_time=0; - size_t size=0; - uint32 mode=0; - - DEBUG(4,("%s (%s)\n", __FUNCTION__, fname)); - - if (!fname) { - errno = EINVAL; - return -1; - } - - smbw_init(); - - smbw_busy++; - - /* work out what server they are after */ - smbw_parse_path(fname, server, share, path); - - /* get a connection to the server */ - srv = smbw_server(server, share); - if (!srv) { - /* smbw_server sets errno */ - goto failed; - } - - if (strcmp(share,"IPC$") == 0) { - mode = aDIR | aRONLY; - } else { - if (!smbw_getatr(srv, path, - &mode, &size, &c_time, &a_time, &m_time)) { - errno = smbw_errno(&srv->cli); - goto failed; - } - } - - smbw_setup_stat(st, path, size, mode); - - st->st_atime = time(NULL); - st->st_ctime = m_time; - st->st_mtime = m_time; - st->st_dev = srv->dev; - - smbw_busy--; - return 0; - - failed: - smbw_busy--; - return -1; -} /***************************************************** a wrapper for read() @@ -954,8 +804,9 @@ int smbw_rename(const char *oldname, const char *newname) /***************************************************** a wrapper for utime() *******************************************************/ -int smbw_utime(const char *fname, struct utimbuf *buf) +int smbw_utime(const char *fname, void *buf) { + struct utimbuf *tbuf = (struct utimbuf *)buf; struct smbw_server *srv; fstring server, share; pstring path; @@ -987,7 +838,7 @@ int smbw_utime(const char *fname, struct utimbuf *buf) goto failed; } - if (!cli_setatr(&srv->cli, path, mode, buf->modtime)) { + if (!cli_setatr(&srv->cli, path, mode, tbuf->modtime)) { errno = smbw_errno(&srv->cli); goto failed; } diff --git a/source3/smbwrapper/smbw.h b/source3/smbwrapper/smbw.h index 61bf9de75a..716205c1fc 100644 --- a/source3/smbwrapper/smbw.h +++ b/source3/smbwrapper/smbw.h @@ -55,3 +55,4 @@ struct smbw_dir { struct file_info *list; char *path; }; + diff --git a/source3/smbwrapper/smbw_dir.c b/source3/smbwrapper/smbw_dir.c index db10204b10..22da76eb17 100644 --- a/source3/smbwrapper/smbw_dir.c +++ b/source3/smbwrapper/smbw_dir.c @@ -20,7 +20,6 @@ */ #include "includes.h" -#include "smbw.h" #include "wrapper.h" extern pstring smb_cwd; @@ -576,8 +575,9 @@ DIR *smbw_opendir(const char *fname) /***************************************************** read one entry from a directory *******************************************************/ -struct dirent *smbw_readdir(struct smbw_dir *d) +struct dirent *smbw_readdir(DIR *dirp) { + struct smbw_dir *d = (struct smbw_dir *)dirp; static struct dirent de; if (smbw_getdents(d->fd, &de, sizeof(struct dirent)) > 0) @@ -589,23 +589,26 @@ struct dirent *smbw_readdir(struct smbw_dir *d) /***************************************************** close a DIR* *******************************************************/ -int smbw_closedir(struct smbw_dir *d) +int smbw_closedir(DIR *dirp) { + struct smbw_dir *d = (struct smbw_dir *)dirp; return smbw_close(d->fd); } /***************************************************** seek in a directory *******************************************************/ -void smbw_seekdir(struct smbw_dir *d, off_t offset) +void smbw_seekdir(DIR *dirp, off_t offset) { + struct smbw_dir *d = (struct smbw_dir *)dirp; smbw_dir_lseek(d->fd,offset, SEEK_SET); } /***************************************************** current loc in a directory *******************************************************/ -off_t smbw_telldir(struct smbw_dir *d) +off_t smbw_telldir(DIR *dirp) { + struct smbw_dir *d = (struct smbw_dir *)dirp; return smbw_dir_lseek(d->fd,0,SEEK_CUR); } diff --git a/source3/smbwrapper/smbw_stat.c b/source3/smbwrapper/smbw_stat.c new file mode 100644 index 0000000000..5ca71ee2ef --- /dev/null +++ b/source3/smbwrapper/smbw_stat.c @@ -0,0 +1,179 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper stat 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 "includes.h" +#include "wrapper.h" + +extern int DEBUGLEVEL; + +extern int smbw_busy; + + +/***************************************************** +setup basic info in a stat structure +*******************************************************/ +void smbw_setup_stat(struct stat *st, char *fname, size_t size, int mode) +{ + ZERO_STRUCTP(st); + + if (IS_DOS_DIR(mode)) { + st->st_mode = SMBW_DIR_MODE; + } else { + st->st_mode = SMBW_FILE_MODE; + } + + st->st_size = size; + st->st_blksize = 512; + st->st_blocks = (size+511)/512; + st->st_uid = getuid(); + st->st_gid = getgid(); + st->st_ino = smbw_inode(fname); +} + + +/***************************************************** +try to do a QPATHINFO and if that fails then do a getatr +this is needed because win95 sometimes refuses the qpathinfo +*******************************************************/ +BOOL smbw_getatr(struct smbw_server *srv, char *path, + uint32 *mode, size_t *size, + time_t *c_time, time_t *a_time, time_t *m_time) +{ + DEBUG(5,("sending qpathinfo\n")); + + if (cli_qpathinfo(&srv->cli, path, c_time, a_time, m_time, + size, mode)) return True; + + DEBUG(5,("qpathinfo OK\n")); + + /* if this is NT then don't bother with the getatr */ + if (srv->cli.capabilities & CAP_NT_SMBS) return False; + + if (cli_getatr(&srv->cli, path, mode, size, m_time)) { + a_time = c_time = m_time; + return True; + } + return False; +} + +/***************************************************** +a wrapper for fstat() +*******************************************************/ +int smbw_fstat(int fd, struct stat *st) +{ + struct smbw_file *file; + time_t c_time, a_time, m_time; + uint32 size; + int mode; + + DEBUG(4,("%s\n", __FUNCTION__)); + + smbw_busy++; + + file = smbw_file(fd); + if (!file) { + int ret = smbw_dir_fstat(fd, st); + smbw_busy--; + return ret; + } + + if (!cli_qfileinfo(&file->srv->cli, file->cli_fd, + &mode, &size, &c_time, &a_time, &m_time) && + !cli_getattrE(&file->srv->cli, file->cli_fd, + &mode, &size, &c_time, &a_time, &m_time)) { + errno = EINVAL; + smbw_busy--; + return -1; + } + + smbw_setup_stat(st, file->fname, size, mode); + + st->st_atime = a_time; + st->st_ctime = c_time; + st->st_mtime = m_time; + st->st_dev = file->srv->dev; + + DEBUG(4,("%s - OK\n", __FUNCTION__)); + + smbw_busy--; + return 0; +} + + +/***************************************************** +a wrapper for stat() +*******************************************************/ +int smbw_stat(const char *fname, struct stat *st) +{ + struct smbw_server *srv; + fstring server, share; + pstring path; + time_t m_time=0, a_time=0, c_time=0; + size_t size=0; + uint32 mode=0; + + DEBUG(4,("%s (%s)\n", __FUNCTION__, fname)); + + if (!fname) { + errno = EINVAL; + return -1; + } + + smbw_init(); + + smbw_busy++; + + /* work out what server they are after */ + smbw_parse_path(fname, server, share, path); + + /* get a connection to the server */ + srv = smbw_server(server, share); + if (!srv) { + /* smbw_server sets errno */ + goto failed; + } + + if (strcmp(share,"IPC$") == 0) { + mode = aDIR | aRONLY; + } else { + if (!smbw_getatr(srv, path, + &mode, &size, &c_time, &a_time, &m_time)) { + errno = smbw_errno(&srv->cli); + goto failed; + } + } + + smbw_setup_stat(st, path, size, mode); + + st->st_atime = time(NULL); + st->st_ctime = m_time; + st->st_mtime = m_time; + st->st_dev = srv->dev; + + smbw_busy--; + return 0; + + failed: + smbw_busy--; + return -1; +} + + diff --git a/source3/smbwrapper/wrapped.c b/source3/smbwrapper/wrapped.c index 71bcb76ee9..30676ca3d0 100644 --- a/source3/smbwrapper/wrapped.c +++ b/source3/smbwrapper/wrapped.c @@ -82,7 +82,7 @@ __asm__(".globl __fcntl; __fcntl = fcntl"); int fcntl(int fd, int cmd, long arg) { if (smbw_fd(fd)) { - return smbw_fcntl(fd); + return smbw_fcntl(fd, cmd, arg); } return real_fcntl(fd, cmd, arg); @@ -431,7 +431,7 @@ __asm__(".globl __write; __write = write"); } - int utime(const char *name,struct timeval *tvp) + int utime(const char *name,void *tvp) { if (smbw_path(name)) { return smbw_utime(name, tvp); diff --git a/source3/smbwrapper/wrapper.h b/source3/smbwrapper/wrapper.h index d38aa4227e..5339f652f8 100644 --- a/source3/smbwrapper/wrapper.h +++ b/source3/smbwrapper/wrapper.h @@ -31,7 +31,37 @@ #include "kernel_stat.h" #include "realcalls.h" - -int smbw_path(const char *path); +int smbw_dirp(DIR *dirp); int smbw_fd(int fd); -int smbw_dirp(DIR *); +int smbw_dir_open(const char *fname); +int smbw_dir_close(int fd); +int smbw_stat(const char *fname, struct stat *st); +off_t smbw_dir_lseek(int fd, off_t offset, int whence); +int smbw_path(const char *path); +int smbw_open(const char *fname, int flags, mode_t mode); +int smbw_chdir(const char *name); +int smbw_close(int fd); +int smbw_fchdir(unsigned int fd); +int smbw_fcntl(int fd, int cmd, long arg); +int smbw_getdents(unsigned int fd, struct dirent *dirp, int count); +off_t smbw_lseek(int fd, off_t offset, int whence); +ssize_t smbw_read(int fd, void *buf, size_t count); +ssize_t smbw_write(int fd, void *buf, size_t count); +int smbw_access(const char *name, int mode); +int smbw_chmod(const char *fname, mode_t newmode); +int smbw_chown(const char *fname, uid_t owner, gid_t group); +int smbw_closedir(DIR *d); +int smbw_fstat(int fd, struct stat *st); +char *smbw_getcwd(char *buf, size_t size); +int smbw_stat(const char *fname, struct stat *st); +int smbw_mkdir(const char *fname, mode_t mode); +void smbw_seekdir(DIR *d, off_t offset); +off_t smbw_telldir(DIR *d); +int smbw_unlink(const char *fname); +int smbw_utime(const char *fname,void *buf); +DIR *smbw_opendir(const char *fname); +struct dirent *smbw_readdir(DIR *d); +int smbw_readlink(const char *path, char *buf, size_t bufsize); +int smbw_rename(const char *oldname, const char *newname); +int smbw_rmdir(const char *fname); + |