From db31df8186eafabd9a997a89e33779cf10ce5a9b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Sep 2007 22:14:39 +0000 Subject: r25171: More pstring removal. Jeremy. (This used to be commit 4748d2639796e8caa67fae44d1cf660d49d82663) --- source3/lib/smbrun.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'source3/lib/smbrun.c') diff --git a/source3/lib/smbrun.c b/source3/lib/smbrun.c index b656822321..26330ab992 100644 --- a/source3/lib/smbrun.c +++ b/source3/lib/smbrun.c @@ -1,18 +1,18 @@ -/* +/* Unix SMB/CIFS implementation. run a command as a specified user 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 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 . */ @@ -27,11 +27,19 @@ This is a utility function of smbrun(). ****************************************************************************/ static int setup_out_fd(void) -{ +{ int fd; - pstring path; - - slprintf(path, sizeof(path)-1, "%s/smb.XXXXXX", tmpdir()); + TALLOC_CTX *ctx = talloc_stackframe(); + char *path = NULL; + + path = talloc_asprintf(ctx, + "%s/smb.XXXXXX", + tmpdir()); + if (!path) { + TALLOC_FREE(ctx); + errno = ENOMEM; + return -1; + } /* now create the file */ fd = smb_mkstemp(path); @@ -39,6 +47,7 @@ static int setup_out_fd(void) if (fd == -1) { DEBUG(0,("setup_out_fd: Failed to create file %s. (%s)\n", path, strerror(errno) )); + TALLOC_FREE(ctx); return -1; } @@ -46,6 +55,7 @@ static int setup_out_fd(void) /* Ensure file only kept around by open fd. */ unlink(path); + TALLOC_FREE(ctx); return fd; } @@ -59,7 +69,7 @@ static int smbrun_internal(const char *cmd, int *outfd, BOOL sanitize) pid_t pid; uid_t uid = current_user.ut.uid; gid_t gid = current_user.ut.gid; - + /* * Lose any elevated privileges. */ -- cgit