diff options
author | David Shaw <dshaw@jabberwocky.com> | 2002-07-24 21:24:08 +0200 |
---|---|---|
committer | David Shaw <dshaw@jabberwocky.com> | 2002-07-24 21:24:08 +0200 |
commit | d0c643a6c573342704c34527bb0950a56976d563 (patch) | |
tree | 6952e46c863aa2e7a5f0bc386c4761794eb3c456 /g10/exec.c | |
parent | * Makefile.am: Install keyserver helpers in @GNUPG_LIBEXECDIR@ (diff) | |
download | gnupg2-d0c643a6c573342704c34527bb0950a56976d563.tar.xz gnupg2-d0c643a6c573342704c34527bb0950a56976d563.zip |
* options.h, exec.h, exec.c (set_exec_path, exec_write), g10.c (main),
keyserver.c (keyserver_spawn): If the user does not use "exec-path",
completely replace $PATH with GNUPG_LIBEXECDIR before calling the
keyserver helper. If the user does use "exec-path", append
GNUPG_LIBEXECDIR after the specified path.
Diffstat (limited to 'g10/exec.c')
-rw-r--r-- | g10/exec.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/g10/exec.c b/g10/exec.c index 46990f29c..db440f656 100644 --- a/g10/exec.c +++ b/g10/exec.c @@ -51,7 +51,7 @@ int exec_write(struct exec_info **info,const char *program, int exec_read(struct exec_info *info) { return G10ERR_GENERAL; } int exec_finish(struct exec_info *info) { return G10ERR_GENERAL; } -int set_exec_path(const char *path) { return G10ERR_GENERAL; } +int set_exec_path(const char *path,int method) { return G10ERR_GENERAL; } #else /* ! NO_EXEC */ @@ -91,13 +91,31 @@ static int win_system(const char *command) } #endif -int set_exec_path(const char *path) +/* method==0 to replace current $PATH, and 1 to append to current + $PATH. */ +int set_exec_path(const char *path,int method) { - /* Notice that path is never freed. That is intentional due to the - way putenv() works. */ - char *p=m_alloc(5+strlen(path)+1); + char *p,*curpath=NULL; + size_t curlen=0; + + if(method==1 && (curpath=getenv("PATH"))) + curlen=strlen(curpath)+1; + + p=m_alloc(5+curlen+strlen(path)+1); strcpy(p,"PATH="); + + if(curpath) + { + strcat(p,curpath); + strcat(p,":"); + } + strcat(p,path); + + /* 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) return G10ERR_GENERAL; else @@ -313,7 +331,7 @@ int exec_write(struct exec_info **info,const char *program, BUG(); #ifdef FIXED_EXEC_PATH - set_exec_path(FIXED_EXEC_PATH); + set_exec_path(FIXED_EXEC_PATH,0); #endif *info=m_alloc_clear(sizeof(struct exec_info)); |