added basic chmod(), chown() and utime() support (not fully
authorAndrew Tridgell <tridge@samba.org>
Sat, 3 Oct 1998 10:24:49 +0000 (10:24 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 3 Oct 1998 10:24:49 +0000 (10:24 +0000)
implemented).

this is enough to be able to edit files using emacs on the smbwrapper
filesystem

source/Makefile.in
source/smbwrapper/chmod.c [new file with mode: 0644]
source/smbwrapper/chown.c [new file with mode: 0644]
source/smbwrapper/smbw.c
source/smbwrapper/smbw.h
source/smbwrapper/utime.c [new file with mode: 0644]
source/smbwrapper/wrapper.h

index 51cc52eb8ae7a100f8a02e3bcf46222ab3dc1a0e..d7113c5e5d9a7e5cf117c70887bcb82aa77e08cf 100644 (file)
@@ -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/source/smbwrapper/chmod.c b/source/smbwrapper/chmod.c
new file mode 100644 (file)
index 0000000..50d2404
--- /dev/null
@@ -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/source/smbwrapper/chown.c b/source/smbwrapper/chown.c
new file mode 100644 (file)
index 0000000..31621d1
--- /dev/null
@@ -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);
+}
+
index dc253d7c32a9a31b777912fdd6f2086be17b6c08..3ee48007d58d84f1ea16ebff1d7e4536303209cd 100644 (file)
@@ -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;
+}
index fe291408767ee20d8dd4a83c2ad25e8ec50028fb..60a339181bad8aebac1a176f14789f9f6857f114 100644 (file)
@@ -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/source/smbwrapper/utime.c b/source/smbwrapper/utime.c
new file mode 100644 (file)
index 0000000..9a269aa
--- /dev/null
@@ -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);
+}
index d2f52dbd6c66e47ab49790d168c446eb41aedb10..c891cd948f8ef27c90c569c432be61f575a8981c 100644 (file)
@@ -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"