diff options
author | Jeremy Allison <jra@samba.org> | 2007-09-12 23:50:21 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:30:41 -0500 |
commit | 7632f8fb4003657591778d2b55f546d1737859d1 (patch) | |
tree | 8c9abf282bfc5fc9c2fba67a8beaeecc98072a4b /source/smbd/close.c | |
parent | 7f0db75fb0f24873577dcb758a2ecee74fdc4297 (diff) | |
download | samba-7632f8fb4003657591778d2b55f546d1737859d1.tar.gz samba-7632f8fb4003657591778d2b55f546d1737859d1.tar.xz samba-7632f8fb4003657591778d2b55f546d1737859d1.zip |
r25118: More pstring elimination.
Jeremy.
Diffstat (limited to 'source/smbd/close.c')
-rw-r--r-- | source/smbd/close.c | 103 |
1 files changed, 58 insertions, 45 deletions
diff --git a/source/smbd/close.c b/source/smbd/close.c index 40db9f9b7f7..aee1c92f7b2 100644 --- a/source/smbd/close.c +++ b/source/smbd/close.c @@ -1,20 +1,20 @@ -/* +/* Unix SMB/CIFS implementation. file closing Copyright (C) Andrew Tridgell 1992-1998 Copyright (C) Jeremy Allison 1992-2007. Copyright (C) Volker Lendecke 2005 - + 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 3 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, see <http://www.gnu.org/licenses/>. */ @@ -29,60 +29,73 @@ extern struct current_user current_user; static void check_magic(files_struct *fsp,connection_struct *conn) { - if (!*lp_magicscript(SNUM(conn))) + int ret; + const char *magic_output = NULL; + SMB_STRUCT_STAT st; + int tmp_fd, outfd; + TALLOC_CTX *ctx = NULL; + const char *p; + + if (!*lp_magicscript(SNUM(conn))) { return; + } DEBUG(5,("checking magic for %s\n",fsp->fsp_name)); - { - char *p; - if (!(p = strrchr_m(fsp->fsp_name,'/'))) - p = fsp->fsp_name; - else - p++; + if (!(p = strrchr_m(fsp->fsp_name,'/'))) { + p = fsp->fsp_name; + } else { + p++; + } - if (!strequal(lp_magicscript(SNUM(conn)),p)) - return; + if (!strequal(lp_magicscript(SNUM(conn)),p)) { + return; } - { - int ret; - pstring magic_output; - pstring fname; - SMB_STRUCT_STAT st; - int tmp_fd, outfd; - - 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,&tmp_fd); - DEBUG(3,("Invoking magic command %s gave %d\n",fname,ret)); - unlink(fname); - if (ret != 0 || tmp_fd == -1) { - if (tmp_fd != -1) - close(tmp_fd); - return; - } - outfd = open(magic_output, O_CREAT|O_EXCL|O_RDWR, 0600); - if (outfd == -1) { - close(tmp_fd); - return; - } + ctx = talloc_stackframe(); + + if (*lp_magicoutput(SNUM(conn))) { + magic_output = lp_magicoutput(SNUM(conn)); + } else { + magic_output = talloc_asprintf(ctx, + "%s.out", + fsp->fsp_name); + } + if (!magic_output) { + TALLOC_FREE(ctx); + return; + } - if (sys_fstat(tmp_fd,&st) == -1) { + chmod(fsp->fsp_name,0755); + ret = smbrun(fsp->fsp_name,&tmp_fd); + DEBUG(3,("Invoking magic command %s gave %d\n", + fsp->fsp_name,ret)); + + unlink(fsp->fsp_name); + if (ret != 0 || tmp_fd == -1) { + if (tmp_fd != -1) { close(tmp_fd); - close(outfd); - return; } + TALLOC_FREE(ctx); + return; + } + outfd = open(magic_output, O_CREAT|O_EXCL|O_RDWR, 0600); + if (outfd == -1) { + close(tmp_fd); + TALLOC_FREE(ctx); + return; + } - transfer_file(tmp_fd,outfd,(SMB_OFF_T)st.st_size); + if (sys_fstat(tmp_fd,&st) == -1) { close(tmp_fd); close(outfd); + return; } + + transfer_file(tmp_fd,outfd,(SMB_OFF_T)st.st_size); + close(tmp_fd); + close(outfd); + TALLOC_FREE(ctx); } /**************************************************************************** @@ -90,7 +103,7 @@ static void check_magic(files_struct *fsp,connection_struct *conn) ****************************************************************************/ static NTSTATUS close_filestruct(files_struct *fsp) -{ +{ NTSTATUS status = NT_STATUS_OK; connection_struct *conn = fsp->conn; |