From d0c643a6c573342704c34527bb0950a56976d563 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Wed, 24 Jul 2002 19:24:08 +0000 Subject: * 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. --- g10/exec.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'g10/exec.c') 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)); -- cgit v1.2.3