2003-06-05 09:14:21 +02:00
|
|
|
/* exec.c - generic call-a-program code
|
2006-04-19 13:26:11 +02:00
|
|
|
* Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
2003-06-05 09:14:21 +02:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 21:49:40 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-05 09:14:21 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG 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
|
2016-11-05 12:02:19 +01:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2003-06-05 09:14:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
|
|
#include "gpg.h"
|
2003-06-05 09:14:21 +02:00
|
|
|
#include "options.h"
|
2017-03-07 12:21:23 +01:00
|
|
|
#include "../common/i18n.h"
|
2003-06-05 09:14:21 +02:00
|
|
|
#include "exec.h"
|
|
|
|
|
|
|
|
#ifdef NO_EXEC
|
2019-07-25 04:21:58 +02:00
|
|
|
int set_exec_path(const char *path) { return GPG_ERR_GENERAL; }
|
|
|
|
#else
|
2006-04-19 13:26:11 +02:00
|
|
|
/* Replaces current $PATH */
|
2011-02-04 12:57:53 +01:00
|
|
|
int
|
2009-07-13 19:36:02 +02:00
|
|
|
set_exec_path(const char *path)
|
2003-06-05 09:14:21 +02:00
|
|
|
{
|
2006-04-19 13:26:11 +02:00
|
|
|
char *p;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
p=xmalloc(5+strlen(path)+1);
|
2003-06-05 09:14:21 +02:00
|
|
|
strcpy(p,"PATH=");
|
|
|
|
strcat(p,path);
|
|
|
|
|
|
|
|
if(DBG_EXTPROG)
|
2006-04-19 13:26:11 +02:00
|
|
|
log_debug("set_exec_path: %s\n",p);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
|
|
/* Notice that path is never freed. That is intentional due to the
|
|
|
|
way putenv() works. This leaks a few bytes if we call
|
|
|
|
set_exec_path multiple times. */
|
|
|
|
|
|
|
|
if(putenv(p)!=0)
|
2015-01-22 12:06:11 +01:00
|
|
|
return GPG_ERR_GENERAL;
|
2003-06-05 09:14:21 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* ! NO_EXEC */
|