summaryrefslogtreecommitdiff
path: root/source3/smbd/server.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-07-17 22:21:24 +0000
committerJeremy Allison <jra@samba.org>1998-07-17 22:21:24 +0000
commit471087c9d28a4058efc16f98784cb179ffc1e4c4 (patch)
treeaccca93b43b77c8a46b2b78891d64a822ec3a403 /source3/smbd/server.c
parent18067a7f0c7153d5298ab1e6530ace4f25f926e7 (diff)
downloadsamba-471087c9d28a4058efc16f98784cb179ffc1e4c4.tar.gz
samba-471087c9d28a4058efc16f98784cb179ffc1e4c4.tar.bz2
samba-471087c9d28a4058efc16f98784cb179ffc1e4c4.zip
Code added to fix the renaming of a directory under NT SMB calls.
local.h: Changed MAXDIR to MAX_OPEN_DIRECTORIES - shmem size also tuned by this. dir.c: Use MAX_OPEN_DIRECTORIES. nttrans.c: Allow opening of a directory to succeed. Doesn't actually open a file descriptor but takes a files_struct slot marked as an fd. reply.c: Changed to close any outstanding is_directory files. reply_close changed to understand directory files. server.c: Added open_directory(), close_directory() calls. smb.h: Added is_directory to files_struct. Changed OPEN_FNUM to check that target is !is_directory (this prevents the normal file calls from processing a directory files_struct. Jeremy. (This used to be commit e01ce693f47e75e277f3440d46e32b0bd866b550)
Diffstat (limited to 'source3/smbd/server.c')
-rw-r--r--source3/smbd/server.c125
1 files changed, 102 insertions, 23 deletions
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index a236e2e6ec..cabf2d44b1 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1511,6 +1511,7 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct
fsp->modified = False;
fsp->granted_oplock = False;
fsp->sent_oplock_break = False;
+ fsp->is_directory = False;
fsp->cnum = cnum;
/*
* Note that the file name here is the *untranslated* name
@@ -1609,15 +1610,43 @@ static void check_magic(int fnum,int cnum)
}
}
+/****************************************************************************
+ Common code to close a file or a directory.
+****************************************************************************/
+
+static void close_filestruct(files_struct *fs_p)
+{
+ int cnum = fs_p->cnum;
+
+ fs_p->reserved = False;
+ fs_p->open = False;
+ fs_p->is_directory = False;
+
+ Connections[cnum].num_files_open--;
+ if(fs_p->wbmpx_ptr)
+ {
+ free((char *)fs_p->wbmpx_ptr);
+ fs_p->wbmpx_ptr = NULL;
+ }
+
+#if USE_MMAP
+ if(fs_p->mmap_ptr)
+ {
+ munmap(fs_p->mmap_ptr,fs_p->mmap_size);
+ fs_p->mmap_ptr = NULL;
+ }
+#endif
+}
/****************************************************************************
-close a file - possibly invalidating the read prediction
+ Close a file - possibly invalidating the read prediction.
-If normal_close is 1 then this came from a normal SMBclose (or equivalent)
-operation otherwise it came as the result of some other operation such as
-the closing of the connection. In the latter case printing and
-magic scripts are not run
+ If normal_close is 1 then this came from a normal SMBclose (or equivalent)
+ operation otherwise it came as the result of some other operation such as
+ the closing of the connection. In the latter case printing and
+ magic scripts are not run.
****************************************************************************/
+
void close_file(int fnum, BOOL normal_close)
{
files_struct *fs_p = &Files[fnum];
@@ -1626,28 +1655,12 @@ void close_file(int fnum, BOOL normal_close)
uint32 inode = fs_p->fd_ptr->inode;
int token;
- Files[fnum].reserved = False;
+ close_filestruct(fs_p);
#if USE_READ_PREDICTION
invalidate_read_prediction(fs_p->fd_ptr->fd);
#endif
- fs_p->open = False;
- Connections[cnum].num_files_open--;
- if(fs_p->wbmpx_ptr)
- {
- free((char *)fs_p->wbmpx_ptr);
- fs_p->wbmpx_ptr = NULL;
- }
-
-#if USE_MMAP
- if(fs_p->mmap_ptr)
- {
- munmap(fs_p->mmap_ptr,fs_p->mmap_size);
- fs_p->mmap_ptr = NULL;
- }
-#endif
-
if (lp_share_modes(SNUM(cnum)))
{
lock_share_entry( cnum, dev, inode, &token);
@@ -1684,6 +1697,69 @@ void close_file(int fnum, BOOL normal_close)
memset(fs_p, 0, sizeof(*fs_p));
}
+/****************************************************************************
+ Close a directory opened by an NT SMB call.
+****************************************************************************/
+
+void close_directory(int fnum)
+{
+ files_struct *fs_p = &Files[fnum];
+
+ /*
+ * Do the code common to files and directories.
+ */
+ close_filestruct(fs_p);
+
+ if (fs_p->name) {
+ string_free(&fs_p->name);
+ }
+
+ /* we will catch bugs faster by zeroing this structure */
+ memset(fs_p, 0, sizeof(*fs_p));
+}
+
+/****************************************************************************
+ Open a directory from an NT SMB call.
+****************************************************************************/
+
+void open_directory(int fnum,int cnum,char *fname, int *action)
+{
+ extern struct current_user current_user;
+ files_struct *fsp = &Files[fnum];
+
+ fsp->fd_ptr = NULL;
+ Connections[cnum].num_files_open++;
+ fsp->mode = 0;
+ GetTimeOfDay(&fsp->open_time);
+ fsp->vuid = current_user.vuid;
+ fsp->size = 0;
+ fsp->pos = -1;
+ fsp->open = True;
+ fsp->mmap_ptr = NULL;
+ fsp->mmap_size = 0;
+ fsp->can_lock = True;
+ fsp->can_read = False;
+ fsp->can_write = False;
+ fsp->share_mode = 0;
+ fsp->print_file = False;
+ fsp->modified = False;
+ fsp->granted_oplock = False;
+ fsp->sent_oplock_break = False;
+ fsp->is_directory = True;
+ fsp->cnum = cnum;
+ /*
+ * Note that the file name here is the *untranslated* name
+ * ie. it is still in the DOS codepage sent from the client.
+ * All use of this filename will pass though the sys_xxxx
+ * functions which will do the dos_to_unix translation before
+ * mapping into a UNIX filename. JRA.
+ */
+ string_set(&fsp->name,fname);
+ fsp->wbmpx_ptr = NULL;
+
+ *action = FILE_WAS_OPENED;
+}
+
enum {AFAIL,AREAD,AWRITE,AALL};
/*******************************************************************
@@ -4413,7 +4489,10 @@ static void close_open_files(int cnum)
int i;
for (i=0;i<MAX_OPEN_FILES;i++)
if( Files[i].cnum == cnum && Files[i].open) {
- close_file(i,False);
+ if(Files[i].is_directory)
+ close_directory(i);
+ else
+ close_file(i,False);
}
}