diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/Makefile.in | 3 | ||||
-rw-r--r-- | source3/smbwrapper/chmod.c | 32 | ||||
-rw-r--r-- | source3/smbwrapper/chown.c | 32 | ||||
-rw-r--r-- | source3/smbwrapper/smbw.c | 161 | ||||
-rw-r--r-- | source3/smbwrapper/smbw.h | 1 | ||||
-rw-r--r-- | source3/smbwrapper/utime.c | 31 | ||||
-rw-r--r-- | source3/smbwrapper/wrapper.h | 1 |
7 files changed, 257 insertions, 4 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index 51cc52eb8a..d7113c5e5d 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -198,7 +198,8 @@ SMBWRAPPER_OBJ = smbwrapper/open.o smbwrapper/stat.o \ smbwrapper/lstat.o smbwrapper/close.o smbwrapper/getdents.o \ smbwrapper/fcntl.o smbwrapper/access.o smbwrapper/chdir.o \ smbwrapper/write.o smbwrapper/readlink.o smbwrapper/unlink.o \ - smbwrapper/rename.o \ + smbwrapper/rename.o smbwrapper/utime.o smbwrapper/chown.o \ + smbwrapper/chmod.o \ $(LIBSMB_OBJ) $(PARAM_OBJ) \ $(UBIQX_OBJ) $(LIB_OBJ) diff --git a/source3/smbwrapper/chmod.c b/source3/smbwrapper/chmod.c new file mode 100644 index 0000000000..50d2404a68 --- /dev/null +++ b/source3/smbwrapper/chmod.c @@ -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 chmod(const char *name,mode_t mode) +{ + if (smbw_path(name)) { + return smbw_chmod(name, mode); + } + + return real_chmod(name, mode); +} + diff --git a/source3/smbwrapper/chown.c b/source3/smbwrapper/chown.c new file mode 100644 index 0000000000..31621d151d --- /dev/null +++ b/source3/smbwrapper/chown.c @@ -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 chown(const char *name,uid_t owner, gid_t group) +{ + if (smbw_path(name)) { + return smbw_chown(name, owner, group); + } + + return real_chown(name, owner, group); +} + diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c index dc253d7c32..3ee48007d5 100644 --- a/source3/smbwrapper/smbw.c +++ b/source3/smbwrapper/smbw.c @@ -225,6 +225,8 @@ char *smbw_parse_path(const char *fname, char *server, char *share, char *path) char *p, *p2; int len; + *server = *share = *path = 0; + if (fname[0] == '/') { pstrcpy(s, fname); } else { @@ -299,7 +301,11 @@ BOOL smbw_path(const char *path) fstring server, share; pstring s; char *cwd; - int l; + int l=strlen(SMBW_PREFIX)-1; + + if (path[0] == '/' && strncmp(path,SMBW_PREFIX,l)) { + return False; + } if (smbw_busy) return False; @@ -309,8 +315,6 @@ BOOL smbw_path(const char *path) cwd = smbw_parse_path(path, server, share, s); - l = strlen(SMBW_PREFIX)-1; - if (strncmp(cwd,SMBW_PREFIX,l) == 0 && (cwd[l] == '/' || cwd[l] == 0)) { return True; @@ -430,6 +434,15 @@ struct smbw_server *smbw_server(char *server, char *share) goto failed; } + /* some programs play with file descriptors fairly intimately. We + try to get out of the way by duping to a high fd number */ + if (fcntl(SMBW_CLI_FD, F_GETFD) && errno == EBADF) { + if (dup2(srv->cli.fd, SMBW_CLI_FD) == SMBW_CLI_FD) { + close(srv->cli.fd); + srv->cli.fd = SMBW_CLI_FD; + } + } + DLIST_ADD(smbw_srvs, srv); return srv; @@ -1250,3 +1263,145 @@ int smbw_rename(const char *oldname, const char *newname) smbw_busy--; return -1; } + + +/***************************************************** +a wrapper for utime() +*******************************************************/ +int smbw_utime(const char *fname, struct utimbuf *buf) +{ + struct smbw_server *srv; + fstring server, share; + pstring path; + uint32 mode; + + 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 (!cli_getatr(&srv->cli, path, &mode, NULL, NULL)) { + errno = smbw_errno(&srv->cli); + goto failed; + } + + if (!cli_setatr(&srv->cli, path, mode, buf->modtime)) { + errno = smbw_errno(&srv->cli); + goto failed; + } + + smbw_busy--; + return 0; + + failed: + smbw_busy--; + return -1; +} + +/***************************************************** +a wrapper for chown() +*******************************************************/ +int smbw_chown(const char *fname, uid_t owner, gid_t group) +{ + struct smbw_server *srv; + fstring server, share; + pstring path; + uint32 mode; + + 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 (!cli_getatr(&srv->cli, path, &mode, NULL, NULL)) { + errno = smbw_errno(&srv->cli); + goto failed; + } + + /* assume success */ + + smbw_busy--; + return 0; + + failed: + smbw_busy--; + return -1; +} + +/***************************************************** +a wrapper for chmod() +*******************************************************/ +int smbw_chmod(const char *fname, mode_t newmode) +{ + struct smbw_server *srv; + fstring server, share; + pstring path; + uint32 mode; + + 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 (!cli_getatr(&srv->cli, path, &mode, NULL, NULL)) { + errno = smbw_errno(&srv->cli); + goto failed; + } + + /* assume success for the moment - need to add attribute mapping */ + + smbw_busy--; + return 0; + + failed: + smbw_busy--; + return -1; +} diff --git a/source3/smbwrapper/smbw.h b/source3/smbwrapper/smbw.h index fe29140876..60a339181b 100644 --- a/source3/smbwrapper/smbw.h +++ b/source3/smbwrapper/smbw.h @@ -22,6 +22,7 @@ #define SMBW_PREFIX "/smb/" #define SMBW_FD_OFFSET 1024 +#define SMBW_CLI_FD 1023 #define SMBW_MAX_OPEN 2048 #define SMBW_FILE_MODE (S_IFREG | 0644) diff --git a/source3/smbwrapper/utime.c b/source3/smbwrapper/utime.c new file mode 100644 index 0000000000..9a269aa942 --- /dev/null +++ b/source3/smbwrapper/utime.c @@ -0,0 +1,31 @@ +/* + 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 utime(const char *name,struct timeval *tvp) +{ + if (smbw_path(name)) { + return smbw_utime(name, tvp); + } + + return real_utime(name, tvp); +} diff --git a/source3/smbwrapper/wrapper.h b/source3/smbwrapper/wrapper.h index d2f52dbd6c..c891cd948f 100644 --- a/source3/smbwrapper/wrapper.h +++ b/source3/smbwrapper/wrapper.h @@ -6,5 +6,6 @@ #include <errno.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/time.h> #include "kernel_stat.h" #include "realcalls.h" |