GnuPG looks for configuration files and keyrings in its home directory. For a user, that is typically ~/.gnupg. This patch causes pacman to use /etc/pacman.d/gnupg/ as the default GnuPG home. One may override the default using --gpgdir on the command-line or GPGDir in pacman's configuration file. Signed-off-by: Chris Brannon <cmbrannon@cox.net> --- doc/pacman.8.txt | 7 +++++++ doc/pacman.conf.5.txt | 6 ++++++ src/pacman/Makefile.am | 2 ++ src/pacman/conf.h | 1 + src/pacman/pacman.c | 25 +++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 0 deletions(-) diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt index 6f071ba..a780627 100644 --- a/doc/pacman.8.txt +++ b/doc/pacman.8.txt @@ -136,6 +136,13 @@ Options *\--config* <'file'>:: Specify an alternate configuration file. +*\--gpgdir* <'dir':: + Specify a directory of files used by GnuPG to verify package + signatures. This directory should contain two files: + ``pubring.gpg'' and ``trustdb.gpg''. ``pubring.gpg'' holds the public + keys of all packagers. ``trustdb.gpg'' contains a so-called + trust database, which specifies that the keys are authentic and trusted. + *\--logfile* <'file'>:: Specify an alternate log file. This is an absolute path, regardless of the installation root setting. diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt index 8ef11ec..fa69bfa 100644 --- a/doc/pacman.conf.5.txt +++ b/doc/pacman.conf.5.txt @@ -69,6 +69,12 @@ Options path, the root path is not automatically prepended. +*GPGDir =* path/to/gpg/dir:: + Overrides the default location of the directory containing + configuration files for GnuPG. + A typical default is ``/etc/pacman.d/gnupg''. + This is an absolute path, and the root directory is not prepended. + *LogFile =* '/path/to/file':: Overrides the default location of the pacman log file. A typical default is ``/var/log/pacman.log''. This is an absolute path and the root directory diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am index 220ee9c..4da6ef3 100644 --- a/src/pacman/Makefile.am +++ b/src/pacman/Makefile.am @@ -1,6 +1,7 @@ # paths set at make time conffile = ${sysconfdir}/pacman.conf dbpath = ${localstatedir}/lib/pacman/ +gpgdir = ${sysconfdir}/pacman.d/gnupg/ cachedir = ${localstatedir}/cache/pacman/pkg/ logfile = ${localstatedir}/log/pacman.log @@ -10,6 +11,7 @@ DEFS = -DLOCALEDIR=\"@localedir@\" \ -DCONFFILE=\"$(conffile)\" \ -DROOTDIR=\"$(ROOTDIR)\" \ -DDBPATH=\"$(dbpath)\" \ + -DGPGDIR=\"$(gpgdir)\" \ -DCACHEDIR=\"$(cachedir)\" \ -DLOGFILE=\"$(logfile)\" \ @DEFS@ diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 8ea6662..f491057 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -37,6 +37,7 @@ typedef struct __config_t { char *rootdir; char *dbpath; char *logfile; + char *gpgdir; /* TODO how to handle cachedirs? */ unsigned short op_q_isfile; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 3255cdf..18fd3a8 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -138,6 +138,7 @@ static void usage(int op, const char * const myname) printf(_(" -q, --quiet show less information for query and search\n")); } printf(_(" --config <path> set an alternate configuration file\n")); + printf(_(" --gpgdir <path> set an alternate home directory for GnuPG\n")); printf(_(" --logfile <path> set an alternate log file\n")); printf(_(" --noconfirm do not ask for any confirmation\n")); printf(_(" --noprogressbar do not show a progress bar when downloading files\n")); @@ -306,6 +307,20 @@ static void setlibpaths(void) } } + /* + * Set GnuPG's home directory. This is not relative to + * rootdir, even if rootdir is defined. + * Reasoning: gpgdir contains configuration data. +*/ + if(config->gpgdir) { + ret = alpm_option_set_signaturedir(config->gpgdir); + if(ret != 0) { + pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"), + config->gpgdir, alpm_strerrorlast()); + cleanup(ret); + } + } + /* add a default cachedir if one wasn't specified */ if(alpm_option_get_cachedirs() == NULL) { alpm_option_add_cachedir(CACHEDIR); @@ -366,6 +381,7 @@ static int parseargs(int argc, char *argv[]) {"debug", optional_argument, 0, 1003}, {"noprogressbar", no_argument, 0, 1004}, {"noscriptlet", no_argument, 0, 1005}, + {"gpgdir", required_argument, 0, 1006}, {"cachedir", required_argument, 0, 1007}, {"asdeps", no_argument, 0, 1008}, {"logfile", required_argument, 0, 1009}, @@ -446,6 +462,9 @@ static int parseargs(int argc, char *argv[]) case 1012: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break; + case 1006: + config->gpgdir = strdup(optarg); + break; case 'Q': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break; case 'R': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_REMOVE); break; case 'S': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_SYNC); break; @@ -725,6 +744,11 @@ static int _parseconfig(const char *file, const char *givensection, config->rootdir = strdup(ptr); pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", ptr); } + } else if (strcmp(key, "GPGDir") == 0) { + if(!config->gpgdir) { + config->gpgdir = strdup(ptr); + pm_printf(PM_LOG_DEBUG, "config: gpgdir: %s\n", ptr); + } } else if (strcmp(key, "LogFile") == 0) { if(!config->logfile) { config->logfile = strdup(ptr); @@ -864,6 +888,7 @@ int main(int argc, char *argv[]) /* define paths to reasonable defaults */ alpm_option_set_root(ROOTDIR); alpm_option_set_dbpath(DBPATH); + alpm_option_set_signaturedir(GPGDIR); alpm_option_set_logfile(LOGFILE); /* Priority of options: -- 1.6.0.5