summaryrefslogtreecommitdiffstats
path: root/src/pacman/pacman.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/pacman.c')
-rw-r--r--src/pacman/pacman.c140
1 files changed, 90 insertions, 50 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 2847fd50..da6b71e3 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -66,9 +66,9 @@ static int options_cmp(const void *p1, const void *p2)
const char *s1 = p1;
const char *s2 = p2;
- if(s1 == s2) return(0);
- if(!s1) return(-1);
- if(!s2) return(1);
+ if(s1 == s2) return 0;
+ if(!s1) return -1;
+ if(!s2) return 1;
/* First skip all spaces in both strings */
while(isspace((unsigned char)*s1)) {
s1++;
@@ -87,15 +87,15 @@ static int options_cmp(const void *p1, const void *p2)
s2++;
} else if(*s2 == '-') {
/* s1 short, s2 long */
- return(-1);
+ return -1;
} else if(*s1 == '-') {
/* s1 long, s2 short */
- return(1);
+ return 1;
}
/* two short -> strcmp */
}
- return(strcmp(s1, s2));
+ return strcmp(s1, s2);
}
/** Display usage/syntax for the specified operation.
@@ -206,6 +206,7 @@ static void usage(int op, const char * const myname)
addlist(_(" --cachedir <dir> set an alternate package cache location\n"));
addlist(_(" --config <path> set an alternate configuration file\n"));
addlist(_(" --debug display debug messages\n"));
+ addlist(_(" --gpgdir <path> set an alternate home directory for GnuPG\n"));
addlist(_(" --logfile <path> set an alternate log file\n"));
addlist(_(" --noconfirm do not ask for any confirmation\n"));
}
@@ -301,7 +302,7 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
do {
ret = write(fd, buf, count);
} while(ret == -1 && errno == EINTR);
- return(ret);
+ return ret;
}
/** Catches thrown signals. Performs necessary cleanup to ensure database is
@@ -389,6 +390,17 @@ 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);
@@ -397,7 +409,7 @@ static void setlibpaths(void)
}
}
-#define check_optarg() if(!optarg) { return(1); }
+#define check_optarg() if(!optarg) { return 1; }
typedef void (*fn_add) (const char *s);
@@ -411,7 +423,7 @@ static int parsearg_util_addlist(fn_add fn)
fn((char *)alpm_list_getdata(item));
}
FREELIST(list);
- return(0);
+ return 0;
}
/** Helper function for parsing operation from command-line arguments.
@@ -448,9 +460,9 @@ static int parsearg_op(int opt, int dryrun)
if(dryrun) break;
config->help = 1; break;
default:
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
/** Helper functions for parsing command-line arguments.
@@ -471,7 +483,7 @@ static int parsearg_global(int opt)
if(alpm_option_add_cachedir(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
optarg, alpm_strerrorlast());
- return(1);
+ return 1;
}
break;
case OP_CONFIG:
@@ -496,7 +508,7 @@ static int parsearg_global(int opt)
default:
pm_printf(PM_LOG_ERROR, _("'%s' is not a valid debug level\n"),
optarg);
- return(1);
+ return 1;
}
} else {
config->logmask |= PM_LOG_DEBUG;
@@ -504,6 +516,9 @@ static int parsearg_global(int opt)
/* progress bars get wonky with debug on, shut them off */
config->noprogressbar = 1;
break;
+ case OP_GPGDIR:
+ config->gpgdir = strdup(optarg);
+ break;
case OP_LOGFILE:
check_optarg();
config->logfile = strndup(optarg, PATH_MAX);
@@ -515,9 +530,9 @@ static int parsearg_global(int opt)
break;
case 'r': check_optarg(); config->rootdir = strdup(optarg); break;
case 'v': (config->verbose)++; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_database(int opt)
@@ -525,9 +540,9 @@ static int parsearg_database(int opt)
switch(opt) {
case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_query(int opt)
@@ -547,9 +562,9 @@ static int parsearg_query(int opt)
case 's': config->op_q_search = 1; break;
case 't': config->op_q_unrequired = 1; break;
case 'u': config->op_q_upgrade = 1; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/* options common to -S -R -U */
@@ -571,15 +586,15 @@ static int parsearg_trans(int opt)
check_optarg();
config->print_format = strdup(optarg);
break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_remove(int opt)
{
if (parsearg_trans(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case 'c': config->flags |= PM_TRANS_FLAG_CASCADE; break;
case 'n': config->flags |= PM_TRANS_FLAG_NOSAVE; break;
@@ -591,16 +606,16 @@ static int parsearg_remove(int opt)
}
break;
case 'u': config->flags |= PM_TRANS_FLAG_UNNEEDED; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/* options common to -S -U */
static int parsearg_upgrade(int opt)
{
if (parsearg_trans(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
@@ -611,15 +626,15 @@ static int parsearg_upgrade(int opt)
case OP_IGNOREGROUP:
parsearg_util_addlist(alpm_option_add_ignoregrp);
break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_sync(int opt)
{
if (parsearg_upgrade(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case OP_NEEDED: config->flags |= PM_TRANS_FLAG_NEEDED; break;
case 'c': (config->op_s_clean)++; break;
@@ -635,9 +650,9 @@ static int parsearg_sync(int opt)
config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
break;
case 'y': (config->op_s_sync)++; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/** Parse command-line arguments for each operation.
@@ -705,6 +720,7 @@ static int parseargs(int argc, char *argv[])
{"asexplicit", no_argument, 0, OP_ASEXPLICIT},
{"arch", required_argument, 0, OP_ARCH},
{"print-format", required_argument, 0, OP_PRINTFORMAT},
+ {"gpgdir", required_argument, 0, OP_GPGDIR},
{0, 0, 0, 0}
};
@@ -716,22 +732,22 @@ static int parseargs(int argc, char *argv[])
continue;
} else if(opt == '?') {
/* unknown option, getopt printed an error */
- return(1);
+ return 1;
}
parsearg_op(opt, 0);
}
if(config->op == 0) {
pm_printf(PM_LOG_ERROR, _("only one operation may be used at a time\n"));
- return(1);
+ return 1;
}
if(config->help) {
usage(config->op, mbasename(argv[0]));
- return(2);
+ return 2;
}
if(config->version) {
version();
- return(2);
+ return 2;
}
/* parse all other options */
@@ -743,7 +759,7 @@ static int parseargs(int argc, char *argv[])
continue;
} else if(opt == '?') {
/* this should have failed during first pass already */
- return(1);
+ return 1;
} else if(parsearg_op(opt, 1) == 0) {
/* opt is an operation */
continue;
@@ -779,7 +795,7 @@ static int parseargs(int argc, char *argv[])
if(result != 0) {
/* global option parsing failed, abort */
pm_printf(PM_LOG_ERROR, _("invalid option\n"));
- return(result);
+ return result;
}
}
@@ -789,7 +805,7 @@ static int parseargs(int argc, char *argv[])
optind++;
}
- return(0);
+ return 0;
}
/* helper for being used with setrepeatingoption */
@@ -842,7 +858,7 @@ static char *get_filename(const char *url) {
if(filename != NULL) {
filename++;
}
- return(filename);
+ return filename;
}
static char *get_destfile(const char *path, const char *filename) {
@@ -852,7 +868,7 @@ static char *get_destfile(const char *path, const char *filename) {
destfile = calloc(len, sizeof(char));
snprintf(destfile, len, "%s%s", path, filename);
- return(destfile);
+ return destfile;
}
static char *get_tempfile(const char *path, const char *filename) {
@@ -862,7 +878,7 @@ static char *get_tempfile(const char *path, const char *filename) {
tempfile = calloc(len, sizeof(char));
snprintf(tempfile, len, "%s%s.part", path, filename);
- return(tempfile);
+ return tempfile;
}
/** External fetch callback */
@@ -954,7 +970,7 @@ cleanup:
free(tempfile);
free(parsedcmd);
- return(ret);
+ return ret;
}
static int _parse_options(const char *key, char *value,
@@ -1012,7 +1028,7 @@ static int _parse_options(const char *key, char *value,
if(alpm_option_add_cachedir(value) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
value, alpm_strerrorlast());
- return(1);
+ return 1;
}
pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", value);
} else if(strcmp(key, "RootDir") == 0) {
@@ -1021,6 +1037,11 @@ static int _parse_options(const char *key, char *value,
config->rootdir = strdup(value);
pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", value);
}
+ } else if (strcmp(key, "GPGDir") == 0) {
+ if(!config->gpgdir) {
+ config->gpgdir = strdup(value);
+ pm_printf(PM_LOG_DEBUG, "config: gpgdir: %s\n", value);
+ }
} else if (strcmp(key, "LogFile") == 0) {
if(!config->logfile) {
config->logfile = strdup(value);
@@ -1040,7 +1061,7 @@ static int _parse_options(const char *key, char *value,
}
}
- return(0);
+ return 0;
}
static int _add_mirror(pmdb_t *db, char *value)
@@ -1059,7 +1080,7 @@ static int _add_mirror(pmdb_t *db, char *value)
free(temp);
pm_printf(PM_LOG_ERROR, _("The mirror '%s' contains the $arch"
" variable, but no Architecture is defined.\n"), value);
- return(1);
+ return 1;
}
server = temp;
}
@@ -1069,11 +1090,11 @@ static int _add_mirror(pmdb_t *db, char *value)
pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"),
dbname, server, alpm_strerrorlast());
free(server);
- return(1);
+ return 1;
}
free(server);
- return(0);
+ return 0;
}
/* The real parseconfig. Called with a null section argument by the publicly
@@ -1092,7 +1113,7 @@ static int _parseconfig(const char *file, const char *givensection,
fp = fopen(file, "r");
if(fp == NULL) {
pm_printf(PM_LOG_ERROR, _("config file %s could not be read.\n"), file);
- return(1);
+ return 1;
}
/* if we are passed a section, use it as our starting point */
@@ -1224,6 +1245,24 @@ static int _parseconfig(const char *file, const char *givensection,
ret = 1;
goto cleanup;
}
+ } else if(strcmp(key, "VerifySig") == 0) {
+ if (strcmp(value, "Always") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_ALWAYS);
+ } else if (strcmp(value, "Optional") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_OPTIONAL);
+ } else if (strcmp(value, "Never") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_NEVER);
+ } else {
+ pm_printf(PM_LOG_ERROR, _("invalid value for 'VerifySig' : '%s'\n"), value);
+ ret = 1;
+ goto cleanup;
+ }
+ if (ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("could not add pgp verify option to database '%s': %s (%s)\n"),
+ alpm_db_get_name(db), value, alpm_strerrorlast());
+ goto cleanup;
+ }
+ pm_printf(PM_LOG_DEBUG, "config: VerifySig for %s: %s\n",alpm_db_get_name(db), value);
} else {
pm_printf(PM_LOG_WARNING,
_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
@@ -1241,7 +1280,7 @@ cleanup:
/* call setlibpaths here to ensure we have called it at least once */
setlibpaths();
pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file);
- return(ret);
+ return ret;
}
/** Parse a configuration file.
@@ -1251,7 +1290,7 @@ cleanup:
static int parseconfig(const char *file)
{
/* call the real parseconfig function with a null section & db argument */
- return(_parseconfig(file, NULL, NULL));
+ return _parseconfig(file, NULL, NULL);
}
/** print commandline to logfile
@@ -1344,6 +1383,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:
@@ -1478,7 +1518,7 @@ int main(int argc, char *argv[])
cleanup(ret);
/* not reached */
- return(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
/* vim: set ts=2 sw=2 noet: */