diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-08-17 13:11:34 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-08-17 13:11:34 +0000 |
commit | a6d194886a4a5f7507fa37289ff96c1be56f14a6 (patch) | |
tree | 1b24d31f4b2b8d050f73089607382907f78e1232 /source/smbd/close.c | |
parent | 534a90ca44641417c21f6ed6d4b94b1de60f808d (diff) | |
download | samba-a6d194886a4a5f7507fa37289ff96c1be56f14a6.tar.gz samba-a6d194886a4a5f7507fa37289ff96c1be56f14a6.tar.xz samba-a6d194886a4a5f7507fa37289ff96c1be56f14a6.zip |
this completes the splitup of server.c.
the splitup was done with an axe, not a scalpel, so there are some
rough edges. I mostly wanted to get the general form right with fine
tuning of what goes where to come later. Still, this is better than
what we had before where server.c was a general repository for
anything that didn't fit elsewhere.
Diffstat (limited to 'source/smbd/close.c')
-rw-r--r-- | source/smbd/close.c | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/source/smbd/close.c b/source/smbd/close.c new file mode 100644 index 00000000000..9bc0a89338f --- /dev/null +++ b/source/smbd/close.c @@ -0,0 +1,170 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + file closing + Copyright (C) Andrew Tridgell 1992-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 "includes.h" + +extern int DEBUGLEVEL; + +extern int32 global_oplocks_open; + + +/**************************************************************************** +run a file if it is a magic script +****************************************************************************/ +static void check_magic(files_struct *fsp,connection_struct *conn) +{ + if (!*lp_magicscript(SNUM(conn))) + return; + + DEBUG(5,("checking magic for %s\n",fsp->fsp_name)); + + { + char *p; + if (!(p = strrchr(fsp->fsp_name,'/'))) + p = fsp->fsp_name; + else + p++; + + if (!strequal(lp_magicscript(SNUM(conn)),p)) + return; + } + + { + int ret; + pstring magic_output; + pstring fname; + pstrcpy(fname,fsp->fsp_name); + + if (*lp_magicoutput(SNUM(conn))) + pstrcpy(magic_output,lp_magicoutput(SNUM(conn))); + else + slprintf(magic_output,sizeof(fname)-1, "%s.out",fname); + + chmod(fname,0755); + ret = smbrun(fname,magic_output,False); + DEBUG(3,("Invoking magic command %s gave %d\n",fname,ret)); + unlink(fname); + } +} + +/**************************************************************************** + Common code to close a file or a directory. +****************************************************************************/ +static void close_filestruct(files_struct *fsp) +{ + connection_struct *conn = fsp->conn; + + fsp->open = False; + fsp->is_directory = False; + + conn->num_files_open--; + if(fsp->wbmpx_ptr) { + free((char *)fsp->wbmpx_ptr); + fsp->wbmpx_ptr = NULL; + } + +#if WITH_MMAP + if(fsp->mmap_ptr) { + munmap(fsp->mmap_ptr,fsp->mmap_size); + fsp->mmap_ptr = NULL; + } +#endif +} + +/**************************************************************************** + 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. +****************************************************************************/ +void close_file(files_struct *fsp, BOOL normal_close) +{ + uint32 dev = fsp->fd_ptr->dev; + uint32 inode = fsp->fd_ptr->inode; + int token; + connection_struct *conn = fsp->conn; + + close_filestruct(fsp); + +#if USE_READ_PREDICTION + invalidate_read_prediction(fsp->fd_ptr->fd); +#endif + + if (lp_share_modes(SNUM(conn))) { + lock_share_entry(conn, dev, inode, &token); + del_share_mode(token, fsp); + } + + fd_attempt_close(fsp->fd_ptr); + + if (lp_share_modes(SNUM(conn))) + unlock_share_entry(conn, dev, inode, token); + + /* NT uses smbclose to start a print - weird */ + if (normal_close && fsp->print_file) + print_file(conn, fsp); + + /* check for magic scripts */ + if (normal_close) { + check_magic(fsp,conn); + } + + if(fsp->granted_oplock == True) + global_oplocks_open--; + + fsp->sent_oplock_break = False; + + DEBUG(2,("%s closed file %s (numopen=%d)\n", + conn->user,fsp->fsp_name, + conn->num_files_open)); + + if (fsp->fsp_name) { + string_free(&fsp->fsp_name); + } + + file_free(fsp); +} + +/**************************************************************************** + Close a directory opened by an NT SMB call. +****************************************************************************/ + +void close_directory(files_struct *fsp) +{ + /* TODO - walk the list of pending + change notify requests and free + any pertaining to this fsp. */ + + remove_pending_change_notify_requests_by_fid(fsp); + + /* + * Do the code common to files and directories. + */ + close_filestruct(fsp); + + if (fsp->fsp_name) + string_free(&fsp->fsp_name); + + file_free(fsp); +} + |