summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2014-04-26 17:53:47 +0200
committerAllan McRae <allan@archlinux.org>2015-01-21 05:27:46 +0100
commit95121cc4f1b63fccaa27dfb567e5a2dfa628671e (patch)
tree4c7a232f1eaef3391ac340573dab653091ea5a55 /src
parent2aa85c3bfdb17a11213495558c493bc68408efe7 (diff)
downloadpacman-95121cc4f1b63fccaa27dfb567e5a2dfa628671e.tar.gz
pacman-95121cc4f1b63fccaa27dfb567e5a2dfa628671e.tar.xz
conf.c: use masks for siglevel inheritance
This will allow pacman to parse its config file in a single pass and removes the need for the *_SET siglevels in alpm that were only required for pacman's siglevel inheritance. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/conf.c90
-rw-r--r--src/pacman/conf.h5
2 files changed, 46 insertions, 49 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 085e7569..a2126e3f 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -318,12 +318,15 @@ int config_set_arch(const char *arch)
* @return 0 on success, 1 on any parsing error
*/
static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
- const char *file, int linenum)
+ alpm_siglevel_t *storage_mask, const char *file, int linenum)
{
- alpm_siglevel_t level = *storage;
+ alpm_siglevel_t level = *storage, mask = *storage_mask;
alpm_list_t *i;
int ret = 0;
+#define SLSET(sl) do { level |= (sl); mask |= (sl); } while(0)
+#define SLUNSET(sl) do { level &= ~(sl); mask |= (sl); } while(0)
+
/* Collapse the option names into a single bitmasked value */
for(i = values; i; i = alpm_list_next(i)) {
const char *original = i->data, *value;
@@ -346,51 +349,40 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
/* now parse out and store actual flag if it is valid */
if(strcmp(value, "Never") == 0) {
if(package) {
- level &= ~ALPM_SIG_PACKAGE;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLUNSET(ALPM_SIG_PACKAGE);
}
if(database) {
- level &= ~ALPM_SIG_DATABASE;
+ SLUNSET(ALPM_SIG_DATABASE);
}
} else if(strcmp(value, "Optional") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE;
- level |= ALPM_SIG_PACKAGE_OPTIONAL;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLSET(ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL);
}
if(database) {
- level |= ALPM_SIG_DATABASE;
- level |= ALPM_SIG_DATABASE_OPTIONAL;
+ SLSET(ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL);
}
} else if(strcmp(value, "Required") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE;
- level &= ~ALPM_SIG_PACKAGE_OPTIONAL;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLSET(ALPM_SIG_PACKAGE);
+ SLUNSET(ALPM_SIG_PACKAGE_OPTIONAL);
}
if(database) {
- level |= ALPM_SIG_DATABASE;
- level &= ~ALPM_SIG_DATABASE_OPTIONAL;
+ SLSET(ALPM_SIG_DATABASE);
+ SLUNSET(ALPM_SIG_DATABASE_OPTIONAL);
}
} else if(strcmp(value, "TrustedOnly") == 0) {
if(package) {
- level &= ~ALPM_SIG_PACKAGE_MARGINAL_OK;
- level &= ~ALPM_SIG_PACKAGE_UNKNOWN_OK;
- level |= ALPM_SIG_PACKAGE_TRUST_SET;
+ SLUNSET(ALPM_SIG_PACKAGE_MARGINAL_OK | ALPM_SIG_PACKAGE_UNKNOWN_OK);
}
if(database) {
- level &= ~ALPM_SIG_DATABASE_MARGINAL_OK;
- level &= ~ALPM_SIG_DATABASE_UNKNOWN_OK;
+ SLUNSET(ALPM_SIG_DATABASE_MARGINAL_OK | ALPM_SIG_DATABASE_UNKNOWN_OK);
}
} else if(strcmp(value, "TrustAll") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE_MARGINAL_OK;
- level |= ALPM_SIG_PACKAGE_UNKNOWN_OK;
- level |= ALPM_SIG_PACKAGE_TRUST_SET;
+ SLSET(ALPM_SIG_PACKAGE_MARGINAL_OK | ALPM_SIG_PACKAGE_UNKNOWN_OK);
}
if(database) {
- level |= ALPM_SIG_DATABASE_MARGINAL_OK;
- level |= ALPM_SIG_DATABASE_UNKNOWN_OK;
+ SLSET(ALPM_SIG_DATABASE_MARGINAL_OK | ALPM_SIG_DATABASE_UNKNOWN_OK);
}
} else {
pm_printf(ALPM_LOG_ERROR,
@@ -401,6 +393,9 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
level &= ~ALPM_SIG_USE_DEFAULT;
}
+#undef SLSET
+#undef SLUNSET
+
/* ensure we have sig checking ability and are actually turning it on */
if(!(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) &&
level & (ALPM_SIG_PACKAGE | ALPM_SIG_DATABASE)) {
@@ -412,6 +407,7 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
if(!ret) {
*storage = level;
+ *storage_mask = mask;
}
return ret;
}
@@ -419,23 +415,13 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
/**
* Merge the package entires of two signature verification levels.
* @param base initial siglevel
- * @param over overridden siglevel, derived value is stored here
+ * @param over overridden siglevel
+ * @return merged siglevel
*/
-static void merge_siglevel(alpm_siglevel_t *base, alpm_siglevel_t *over)
+static alpm_siglevel_t merge_siglevel(alpm_siglevel_t base,
+ alpm_siglevel_t over, alpm_siglevel_t mask)
{
- alpm_siglevel_t level = *over;
- if(!(level & ALPM_SIG_USE_DEFAULT)) {
- if(!(level & ALPM_SIG_PACKAGE_SET)) {
- level |= *base & ALPM_SIG_PACKAGE;
- level |= *base & ALPM_SIG_PACKAGE_OPTIONAL;
- }
- if(!(level & ALPM_SIG_PACKAGE_TRUST_SET)) {
- level |= *base & ALPM_SIG_PACKAGE_MARGINAL_OK;
- level |= *base & ALPM_SIG_PACKAGE_UNKNOWN_OK;
- }
- }
-
- *over = level;
+ return mask ? (over & mask) | (base & ~mask) : over;
}
static int process_cleanmethods(alpm_list_t *values,
@@ -584,7 +570,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "SigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "SigLevel", &values);
- if(process_siglevel(values, &config->siglevel, file, linenum)) {
+ if(process_siglevel(values, &config->siglevel,
+ &config->siglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -592,7 +579,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "LocalFileSigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "LocalFileSigLevel", &values);
- if(process_siglevel(values, &config->localfilesiglevel, file, linenum)) {
+ if(process_siglevel(values, &config->localfilesiglevel,
+ &config->localfilesiglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -600,7 +588,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "RemoteFileSigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "RemoteFileSigLevel", &values);
- if(process_siglevel(values, &config->remotefilesiglevel, file, linenum)) {
+ if(process_siglevel(values, &config->remotefilesiglevel,
+ &config->remotefilesiglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -728,8 +717,11 @@ static int setup_libalpm(void)
alpm_option_set_default_siglevel(handle, config->siglevel);
- merge_siglevel(&config->siglevel, &config->localfilesiglevel);
- merge_siglevel(&config->siglevel, &config->remotefilesiglevel);
+ config->localfilesiglevel = merge_siglevel(config->siglevel,
+ config->localfilesiglevel, config->localfilesiglevel_mask);
+ config->remotefilesiglevel = merge_siglevel(config->siglevel,
+ config->remotefilesiglevel, config->remotefilesiglevel_mask);
+
alpm_option_set_local_file_siglevel(handle, config->localfilesiglevel);
alpm_option_set_remote_file_siglevel(handle, config->remotefilesiglevel);
@@ -839,10 +831,8 @@ static int _parse_repo(const char *key, char *value, const char *file,
alpm_list_t *values = NULL;
setrepeatingoption(value, "SigLevel", &values);
if(values) {
- if(repo->siglevel == ALPM_SIG_USE_DEFAULT) {
- repo->siglevel = config->siglevel;
- }
- ret = process_siglevel(values, &repo->siglevel, file, line);
+ ret = process_siglevel(values, &repo->siglevel,
+ &repo->siglevel_mask, file, line);
FREELIST(values);
}
}
@@ -888,6 +878,8 @@ static int finish_section(struct section_t *section)
}
/* if we are not looking at options sections only, register a db */
+ repo->siglevel = merge_siglevel(config->siglevel,
+ repo->siglevel, repo->siglevel_mask);
db = alpm_register_syncdb(config->handle, section->name, repo->siglevel);
if(db == NULL) {
pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index e1d13379..3eae363f 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -38,6 +38,7 @@ typedef struct __config_repo_t {
alpm_list_t *servers;
alpm_db_usage_t usage;
alpm_siglevel_t siglevel;
+ alpm_siglevel_t siglevel_mask;
} config_repo_t;
typedef struct __config_t {
@@ -94,6 +95,10 @@ typedef struct __config_t {
alpm_siglevel_t localfilesiglevel;
alpm_siglevel_t remotefilesiglevel;
+ alpm_siglevel_t siglevel_mask;
+ alpm_siglevel_t localfilesiglevel_mask;
+ alpm_siglevel_t remotefilesiglevel_mask;
+
/* conf file options */
/* I Love Candy! */
unsigned short chomp;