make sure that apps can't close one of the internal smbw file
authorAndrew Tridgell <tridge@samba.org>
Sat, 24 Oct 1998 06:36:22 +0000 (06:36 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 24 Oct 1998 06:36:22 +0000 (06:36 +0000)
descriptors by catching close attempts on those fds and returning
EBADF.
(This used to be commit 9d863fb1681a5b03696552e1d93fe339b4bae455)

source3/include/proto.h
source3/smbwrapper/shared.c
source3/smbwrapper/smbw.c
source3/smbwrapper/wrapped.c

index 9c78e84017360a9ebaa0844d8f096a39fbc1b5c8..bc9b7389db6a92a1cfc45ec2cdbca65838a942cf 100644 (file)
@@ -2407,11 +2407,13 @@ void smbw_setup_shared(void);
 char *smbw_getshared(const char *name);
 void smbw_setshared(const char *name, const char *val);
 int smbw_setenv(const char *name, const char *value);
+int smbw_shared_fd(int fd);
 
 /*The following definitions come from  smbwrapper/smbw.c  */
 
 void smbw_init(void);
 int smbw_fd(int fd);
+int smbw_local_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);
index 7a5cbcee22eef5c0d0118fd8026355fa78b432ac..ef139414bc9824f31a8e3ab693c76007a4fa4fcb 100644 (file)
@@ -212,3 +212,10 @@ int smbw_setenv(const char *name, const char *value)
        return ret;
 }
 
+/*****************************************************************
+return true if the passed fd is the SMBW_HANDLE
+*****************************************************************/  
+int smbw_shared_fd(int fd)
+{
+       return (shared_fd && shared_fd == fd);
+}
index c09d7509f059a91e7ee706854c69b5d27665a9c7..622581b7a677cfd29771ced23b7d6344db617983 100644 (file)
@@ -125,6 +125,25 @@ int smbw_fd(int fd)
        return smbw_file_bmap && bitmap_query(smbw_file_bmap, fd);
 }
 
+/***************************************************** 
+determine if a file descriptor is an internal smbw fd
+*******************************************************/
+int smbw_local_fd(int fd)
+{
+       struct smbw_server *srv;
+       
+       smbw_init();
+
+       if (smbw_busy) return 0;
+       if (smbw_shared_fd(fd)) return 1;
+
+       for (srv=smbw_srvs;srv;srv=srv->next) {
+               if (srv->cli.fd == fd) return 1;
+       }
+
+       return 0;
+}
+
 /***************************************************** 
 a crude inode number generator
 *******************************************************/
@@ -736,7 +755,6 @@ ssize_t smbw_write(int fd, void *buf, size_t count)
 
        file = smbw_file(fd);
        if (!file) {
-               DEBUG(3,("bad fd in read\n"));
                errno = EBADF;
                smbw_busy--;
                return -1;
@@ -768,7 +786,6 @@ ssize_t smbw_pwrite(int fd, void *buf, size_t count, off_t ofs)
 
        file = smbw_file(fd);
        if (!file) {
-               DEBUG(3,("bad fd in read\n"));
                errno = EBADF;
                smbw_busy--;
                return -1;
index d5f47aac46c348be6c45a7f3776d3d0f745f86b1..0a8158dd05094a61dc7f0e8be1a17feba72ff64e 100644 (file)
        if (smbw_fd(fd)) {
                return smbw_close(fd);
        }
+       if (smbw_local_fd(fd)) {
+               errno = EBADF;
+               return -1;
+       }
 
        return real_close(fd);
 }