mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-31 11:41:32 +01:00
common: New functions gnupg_daemon_rootdir and gnupg_chdir.
* common/sysutils.c (gnupg_chdir): New. * common/homedir.c (gnupg_daemon_rootdir): New. * agent/gpg-agent.c (main): Use these functions instead chdir("/"). * dirmngr/dirmngr.c (main): Ditto. * scd/scdaemon.c (main): Ditto. -- Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
f2d2648a4d
commit
226f143ca0
@ -1708,9 +1708,10 @@ main (int argc, char **argv )
|
||||
opt.running_detached = 1;
|
||||
}
|
||||
|
||||
if (chdir("/"))
|
||||
if (gnupg_chdir (gnupg_daemon_rootdir ()))
|
||||
{
|
||||
log_error ("chdir to / failed: %s\n", strerror (errno));
|
||||
log_error ("chdir to '%s' failed: %s\n",
|
||||
gnupg_daemon_rootdir (), strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
|
@ -433,6 +433,34 @@ gnupg_default_homedir_p (void)
|
||||
}
|
||||
|
||||
|
||||
/* Return the directory name used by daemons for their current working
|
||||
* directory. */
|
||||
const char *
|
||||
gnupg_daemon_rootdir (void)
|
||||
{
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
static char *name;
|
||||
|
||||
if (!name)
|
||||
{
|
||||
char path[MAX_PATH];
|
||||
size_t n;
|
||||
|
||||
n = GetSystemDirectoryA (path, sizeof path);
|
||||
if (!n || n >= sizeof path)
|
||||
name = xstrdup ("/"); /* Error - use the curret top dir instead. */
|
||||
else
|
||||
name = xstrdup (path);
|
||||
}
|
||||
|
||||
return name;
|
||||
|
||||
#else /*!HAVE_W32_SYSTEM*/
|
||||
return "/";
|
||||
#endif /*!HAVE_W32_SYSTEM*/
|
||||
}
|
||||
|
||||
|
||||
/* Helper for gnupg-socketdir. This is a global function, so that
|
||||
* gpgconf can use it for its --create-socketdir command. If
|
||||
* SKIP_CHECKS is set permission checks etc. are not done. The
|
||||
|
@ -796,6 +796,15 @@ gnupg_mkdir (const char *name, const char *modestr)
|
||||
}
|
||||
|
||||
|
||||
/* A simple wrapper around chdir. NAME is expected to be utf8
|
||||
* encoded. */
|
||||
int
|
||||
gnupg_chdir (const char *name)
|
||||
{
|
||||
return chdir (name);
|
||||
}
|
||||
|
||||
|
||||
/* A wrapper around chmod which takes a string for the mode argument.
|
||||
This makes it easier to handle the mode argument which is not
|
||||
defined on all systems. The format of the modestring is the same
|
||||
|
@ -65,7 +65,8 @@ void gnupg_allow_set_foregound_window (pid_t pid);
|
||||
int gnupg_remove (const char *fname);
|
||||
gpg_error_t gnupg_rename_file (const char *oldname, const char *newname,
|
||||
int *block_signals);
|
||||
int gnupg_mkdir (const char *name, const char *modestr);
|
||||
int gnupg_mkdir (const char *name, const char *modestr);
|
||||
int gnupg_chdir (const char *name);
|
||||
int gnupg_chmod (const char *name, const char *modestr);
|
||||
char *gnupg_mkdtemp (char *template);
|
||||
int gnupg_setenv (const char *name, const char *value, int overwrite);
|
||||
|
@ -235,6 +235,7 @@ const char *default_homedir (void);
|
||||
void gnupg_set_homedir (const char *newdir);
|
||||
const char *gnupg_homedir (void);
|
||||
int gnupg_default_homedir_p (void);
|
||||
const char *gnupg_daemon_rootdir (void);
|
||||
const char *gnupg_socketdir (void);
|
||||
const char *gnupg_sysconfdir (void);
|
||||
const char *gnupg_bindir (void);
|
||||
|
@ -1351,11 +1351,13 @@ main (int argc, char **argv)
|
||||
log_set_prefix (NULL, oldflags | GPGRT_LOG_RUN_DETACHED);
|
||||
opt.running_detached = 1;
|
||||
|
||||
if (chdir("/"))
|
||||
if (gnupg_chdir (gnupg_daemon_rootdir ()))
|
||||
{
|
||||
log_error ("chdir to / failed: %s\n", strerror (errno));
|
||||
log_error ("chdir to '%s' failed: %s\n",
|
||||
gnupg_daemon_rootdir (), strerror (errno));
|
||||
dirmngr_exit (1);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -908,9 +908,10 @@ main (int argc, char **argv )
|
||||
sigaction (SIGPIPE, &sa, NULL);
|
||||
}
|
||||
|
||||
if (chdir("/"))
|
||||
if (gnupg_chdir (gnupg_daemon_rootdir ()))
|
||||
{
|
||||
log_error ("chdir to / failed: %s\n", strerror (errno));
|
||||
log_error ("chdir to '%s' failed: %s\n",
|
||||
gnupg_daemon_rootdir (), strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user