summaryrefslogtreecommitdiff
path: root/src/pacman/pacman.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/pacman.c')
-rw-r--r--src/pacman/pacman.c155
1 files changed, 99 insertions, 56 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 0ad03540..c5c83d77 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.
@@ -207,6 +207,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"));
}
@@ -302,7 +303,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
@@ -321,7 +322,7 @@ static void handler(int signum)
xwrite(out, msg1, strlen(msg1));
xwrite(err, msg2, strlen(msg2));
exit(signum);
- } else if((signum == SIGINT)) {
+ } else if(signum == SIGINT) {
const char *msg = "\nInterrupt signal received\n";
xwrite(err, msg, strlen(msg));
if(alpm_trans_interrupt() == 0) {
@@ -390,6 +391,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);
@@ -398,9 +410,9 @@ 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);
+typedef int (*fn_add) (const char *s);
static int parsearg_util_addlist(fn_add fn)
{
@@ -412,7 +424,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.
@@ -449,9 +461,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.
@@ -472,7 +484,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:
@@ -497,7 +509,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;
@@ -505,6 +517,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);
@@ -516,9 +531,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)
@@ -526,9 +541,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)
@@ -548,9 +563,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 */
@@ -572,15 +587,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;
@@ -592,16 +607,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;
@@ -612,15 +627,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;
@@ -636,9 +651,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.
@@ -706,6 +721,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}
};
@@ -717,22 +733,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 */
@@ -744,7 +760,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;
@@ -780,7 +796,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;
}
}
@@ -790,21 +806,23 @@ static int parseargs(int argc, char *argv[])
optind++;
}
- return(0);
+ return 0;
}
/* helper for being used with setrepeatingoption */
-static void option_add_holdpkg(const char *name) {
+static int option_add_holdpkg(const char *name) {
config->holdpkg = alpm_list_add(config->holdpkg, strdup(name));
+ return 0;
}
/* helper for being used with setrepeatingoption */
-static void option_add_syncfirst(const char *name) {
+static int option_add_syncfirst(const char *name) {
config->syncfirst = alpm_list_add(config->syncfirst, strdup(name));
+ return 0;
}
/* helper for being used with setrepeatingoption */
-static void option_add_cleanmethod(const char *value) {
+static int option_add_cleanmethod(const char *value) {
if (strcmp(value, "KeepInstalled") == 0) {
config->cleanmethod |= PM_CLEAN_KEEPINST;
} else if (strcmp(value, "KeepCurrent") == 0) {
@@ -813,6 +831,7 @@ static void option_add_cleanmethod(const char *value) {
pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"),
value);
}
+ return 0;
}
/** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm
@@ -823,7 +842,7 @@ static void option_add_cleanmethod(const char *value) {
* @param optionfunc a function pointer to an alpm_option_add_* function
*/
static void setrepeatingoption(char *ptr, const char *option,
- void (*optionfunc)(const char*))
+ int (*optionfunc)(const char*))
{
char *q;
@@ -843,7 +862,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) {
@@ -853,7 +872,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) {
@@ -863,7 +882,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 */
@@ -955,7 +974,7 @@ cleanup:
free(tempfile);
free(parsedcmd);
- return(ret);
+ return ret;
}
static int _parse_options(const char *key, char *value,
@@ -1013,7 +1032,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) {
@@ -1022,6 +1041,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);
@@ -1041,7 +1065,7 @@ static int _parse_options(const char *key, char *value,
}
}
- return(0);
+ return 0;
}
static int _add_mirror(pmdb_t *db, char *value)
@@ -1060,7 +1084,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;
}
@@ -1070,11 +1094,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
@@ -1093,7 +1117,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 */
@@ -1225,6 +1249,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"),
@@ -1242,7 +1284,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.
@@ -1252,7 +1294,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
@@ -1345,6 +1387,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:
@@ -1479,7 +1522,7 @@ int main(int argc, char *argv[])
cleanup(ret);
/* not reached */
- return(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
/* vim: set ts=2 sw=2 noet: */