diff --git a/g10/ChangeLog b/g10/ChangeLog index 99acde15f..02de71b4e 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,11 @@ +2002-07-24 David Shaw + + * 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. + 2002-07-23 David Shaw * import.c (parse_import_options), export.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)); diff --git a/g10/exec.h b/g10/exec.h index 442952804..427f25810 100644 --- a/g10/exec.h +++ b/g10/exec.h @@ -18,6 +18,6 @@ int exec_write(struct exec_info **info,const char *program, const char *args_in,const char *name,int writeonly,int binary); int exec_read(struct exec_info *info); int exec_finish(struct exec_info *info); -int set_exec_path(const char *path); +int set_exec_path(const char *path,int method); #endif /* !_EXEC_H_ */ diff --git a/g10/g10.c b/g10/g10.c index 1c542c8f5..7a1b624f3 100644 --- a/g10/g10.c +++ b/g10/g10.c @@ -1361,8 +1361,10 @@ main( int argc, char **argv ) case oTempDir: opt.temp_dir=pargs.r.ret_str; break; case oExecPath: #ifndef FIXED_EXEC_PATH - if(set_exec_path(pargs.r.ret_str)) + if(set_exec_path(pargs.r.ret_str,0)) log_error(_("unable to set exec-path to %s\n"),pargs.r.ret_str); + else + opt.exec_path_set=1; #endif break; case oNotation: diff --git a/g10/keyserver.c b/g10/keyserver.c index cff51290b..c64ad4bc8 100644 --- a/g10/keyserver.c +++ b/g10/keyserver.c @@ -339,6 +339,11 @@ keyserver_spawn(int action,STRLIST list, opt.keyserver_options.use_temp_files=1; #endif +#ifndef FIXED_EXEC_PATH + /* Push the libdir into path */ + set_exec_path(GNUPG_LIBEXECDIR,opt.exec_path_set); +#endif + /* Build the filename for the helper to execute */ command=m_alloc(strlen("gpgkeys_")+strlen(opt.keyserver_scheme)+1); diff --git a/g10/options.h b/g10/options.h index 2bc866ea2..db82bc4ad 100644 --- a/g10/options.h +++ b/g10/options.h @@ -133,6 +133,7 @@ struct { STRLIST other; } keyserver_options; int exec_disable; + int exec_path_set; unsigned int import_options; unsigned int export_options; char *def_preference_list;