* 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.
This commit is contained in:
David Shaw 2002-07-24 19:24:08 +00:00
parent 0ecc2099ac
commit d0c643a6c5
6 changed files with 42 additions and 8 deletions

View File

@ -1,3 +1,11 @@
2002-07-24 David Shaw <dshaw@jabberwocky.com>
* 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 <dshaw@jabberwocky.com>
* import.c (parse_import_options), export.c

View File

@ -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));

View File

@ -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_ */

View File

@ -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:

View File

@ -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);

View File

@ -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;