summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-10-24 06:36:22 +0000
committerAndrew Tridgell <tridge@samba.org>1998-10-24 06:36:22 +0000
commit4140f2bfc141ee9a91723d274344769f8b11a5f9 (patch)
tree10570387473b06026ce76564bdb8b3f7a23c4b69
parentf9881e8e74041bc022716f01767a174e7a36b38e (diff)
downloadsamba-4140f2bfc141ee9a91723d274344769f8b11a5f9.tar.gz
samba-4140f2bfc141ee9a91723d274344769f8b11a5f9.tar.bz2
samba-4140f2bfc141ee9a91723d274344769f8b11a5f9.zip
make sure that apps can't close one of the internal smbw file
descriptors by catching close attempts on those fds and returning EBADF. (This used to be commit 9d863fb1681a5b03696552e1d93fe339b4bae455)
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/smbwrapper/shared.c7
-rw-r--r--source3/smbwrapper/smbw.c21
-rw-r--r--source3/smbwrapper/wrapped.c4
4 files changed, 32 insertions, 2 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 9c78e84017..bc9b7389db 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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);
diff --git a/source3/smbwrapper/shared.c b/source3/smbwrapper/shared.c
index 7a5cbcee22..ef139414bc 100644
--- a/source3/smbwrapper/shared.c
+++ b/source3/smbwrapper/shared.c
@@ -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);
+}
diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c
index c09d7509f0..622581b7a6 100644
--- a/source3/smbwrapper/smbw.c
+++ b/source3/smbwrapper/smbw.c
@@ -126,6 +126,25 @@ int smbw_fd(int 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
*******************************************************/
ino_t smbw_inode(const char *name)
@@ -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;
diff --git a/source3/smbwrapper/wrapped.c b/source3/smbwrapper/wrapped.c
index d5f47aac46..0a8158dd05 100644
--- a/source3/smbwrapper/wrapped.c
+++ b/source3/smbwrapper/wrapped.c
@@ -145,6 +145,10 @@
if (smbw_fd(fd)) {
return smbw_close(fd);
}
+ if (smbw_local_fd(fd)) {
+ errno = EBADF;
+ return -1;
+ }
return real_close(fd);
}