1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-15 22:05:02 -05:00

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>
This commit is contained in:
Andrew Gregory 2014-04-26 11:53:47 -04:00 committed by Allan McRae
parent 2aa85c3bfd
commit 95121cc4f1
5 changed files with 50 additions and 53 deletions

3
README
View File

@ -565,6 +565,9 @@ API CHANGES BETWEEN 4.1 AND 4.2
API CHANGES BETWEEN 4.2 AND 5.0 API CHANGES BETWEEN 4.2 AND 5.0
=============================== ===============================
[REMOVED]
- alpm_siglevel_t - removed members ALPM_SIG_PACKAGE_SET, ALPM_SIG_PACKAGE_TRUST_SET
[ADDED] [ADDED]
- pkgbase accessor - pkgbase accessor
- alpm_pkg_get_base() - alpm_pkg_get_base()

View File

@ -202,9 +202,6 @@ typedef enum _alpm_siglevel_t {
ALPM_SIG_DATABASE_MARGINAL_OK = (1 << 12), ALPM_SIG_DATABASE_MARGINAL_OK = (1 << 12),
ALPM_SIG_DATABASE_UNKNOWN_OK = (1 << 13), ALPM_SIG_DATABASE_UNKNOWN_OK = (1 << 13),
ALPM_SIG_PACKAGE_SET = (1 << 27),
ALPM_SIG_PACKAGE_TRUST_SET = (1 << 28),
ALPM_SIG_USE_DEFAULT = (1 << 31) ALPM_SIG_USE_DEFAULT = (1 << 31)
} alpm_siglevel_t; } alpm_siglevel_t;

View File

@ -709,7 +709,7 @@ alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename,
_alpm_log(handle, ALPM_LOG_DEBUG, "registering sync database '%s'\n", treename); _alpm_log(handle, ALPM_LOG_DEBUG, "registering sync database '%s'\n", treename);
#ifndef HAVE_LIBGPGME #ifndef HAVE_LIBGPGME
if((level &= ~ALPM_SIG_PACKAGE_SET) != 0 && level != ALPM_SIG_USE_DEFAULT) { if(level != ALPM_SIG_USE_DEFAULT) {
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL); RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL);
} }
#endif #endif

View File

@ -318,12 +318,15 @@ int config_set_arch(const char *arch)
* @return 0 on success, 1 on any parsing error * @return 0 on success, 1 on any parsing error
*/ */
static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage, 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; alpm_list_t *i;
int ret = 0; 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 */ /* Collapse the option names into a single bitmasked value */
for(i = values; i; i = alpm_list_next(i)) { for(i = values; i; i = alpm_list_next(i)) {
const char *original = i->data, *value; 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 */ /* now parse out and store actual flag if it is valid */
if(strcmp(value, "Never") == 0) { if(strcmp(value, "Never") == 0) {
if(package) { if(package) {
level &= ~ALPM_SIG_PACKAGE; SLUNSET(ALPM_SIG_PACKAGE);
level |= ALPM_SIG_PACKAGE_SET;
} }
if(database) { if(database) {
level &= ~ALPM_SIG_DATABASE; SLUNSET(ALPM_SIG_DATABASE);
} }
} else if(strcmp(value, "Optional") == 0) { } else if(strcmp(value, "Optional") == 0) {
if(package) { if(package) {
level |= ALPM_SIG_PACKAGE; SLSET(ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL);
level |= ALPM_SIG_PACKAGE_OPTIONAL;
level |= ALPM_SIG_PACKAGE_SET;
} }
if(database) { if(database) {
level |= ALPM_SIG_DATABASE; SLSET(ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL);
level |= ALPM_SIG_DATABASE_OPTIONAL;
} }
} else if(strcmp(value, "Required") == 0) { } else if(strcmp(value, "Required") == 0) {
if(package) { if(package) {
level |= ALPM_SIG_PACKAGE; SLSET(ALPM_SIG_PACKAGE);
level &= ~ALPM_SIG_PACKAGE_OPTIONAL; SLUNSET(ALPM_SIG_PACKAGE_OPTIONAL);
level |= ALPM_SIG_PACKAGE_SET;
} }
if(database) { if(database) {
level |= ALPM_SIG_DATABASE; SLSET(ALPM_SIG_DATABASE);
level &= ~ALPM_SIG_DATABASE_OPTIONAL; SLUNSET(ALPM_SIG_DATABASE_OPTIONAL);
} }
} else if(strcmp(value, "TrustedOnly") == 0) { } else if(strcmp(value, "TrustedOnly") == 0) {
if(package) { if(package) {
level &= ~ALPM_SIG_PACKAGE_MARGINAL_OK; SLUNSET(ALPM_SIG_PACKAGE_MARGINAL_OK | ALPM_SIG_PACKAGE_UNKNOWN_OK);
level &= ~ALPM_SIG_PACKAGE_UNKNOWN_OK;
level |= ALPM_SIG_PACKAGE_TRUST_SET;
} }
if(database) { if(database) {
level &= ~ALPM_SIG_DATABASE_MARGINAL_OK; SLUNSET(ALPM_SIG_DATABASE_MARGINAL_OK | ALPM_SIG_DATABASE_UNKNOWN_OK);
level &= ~ALPM_SIG_DATABASE_UNKNOWN_OK;
} }
} else if(strcmp(value, "TrustAll") == 0) { } else if(strcmp(value, "TrustAll") == 0) {
if(package) { if(package) {
level |= ALPM_SIG_PACKAGE_MARGINAL_OK; SLSET(ALPM_SIG_PACKAGE_MARGINAL_OK | ALPM_SIG_PACKAGE_UNKNOWN_OK);
level |= ALPM_SIG_PACKAGE_UNKNOWN_OK;
level |= ALPM_SIG_PACKAGE_TRUST_SET;
} }
if(database) { if(database) {
level |= ALPM_SIG_DATABASE_MARGINAL_OK; SLSET(ALPM_SIG_DATABASE_MARGINAL_OK | ALPM_SIG_DATABASE_UNKNOWN_OK);
level |= ALPM_SIG_DATABASE_UNKNOWN_OK;
} }
} else { } else {
pm_printf(ALPM_LOG_ERROR, 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; level &= ~ALPM_SIG_USE_DEFAULT;
} }
#undef SLSET
#undef SLUNSET
/* ensure we have sig checking ability and are actually turning it on */ /* ensure we have sig checking ability and are actually turning it on */
if(!(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) && if(!(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) &&
level & (ALPM_SIG_PACKAGE | ALPM_SIG_DATABASE)) { 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) { if(!ret) {
*storage = level; *storage = level;
*storage_mask = mask;
} }
return ret; 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. * Merge the package entires of two signature verification levels.
* @param base initial siglevel * @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; return mask ? (over & mask) | (base & ~mask) : 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;
} }
static int process_cleanmethods(alpm_list_t *values, 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) { } else if(strcmp(key, "SigLevel") == 0) {
alpm_list_t *values = NULL; alpm_list_t *values = NULL;
setrepeatingoption(value, "SigLevel", &values); 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); FREELIST(values);
return 1; return 1;
} }
@ -592,7 +579,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "LocalFileSigLevel") == 0) { } else if(strcmp(key, "LocalFileSigLevel") == 0) {
alpm_list_t *values = NULL; alpm_list_t *values = NULL;
setrepeatingoption(value, "LocalFileSigLevel", &values); 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); FREELIST(values);
return 1; return 1;
} }
@ -600,7 +588,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "RemoteFileSigLevel") == 0) { } else if(strcmp(key, "RemoteFileSigLevel") == 0) {
alpm_list_t *values = NULL; alpm_list_t *values = NULL;
setrepeatingoption(value, "RemoteFileSigLevel", &values); 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); FREELIST(values);
return 1; return 1;
} }
@ -728,8 +717,11 @@ static int setup_libalpm(void)
alpm_option_set_default_siglevel(handle, config->siglevel); alpm_option_set_default_siglevel(handle, config->siglevel);
merge_siglevel(&config->siglevel, &config->localfilesiglevel); config->localfilesiglevel = merge_siglevel(config->siglevel,
merge_siglevel(&config->siglevel, &config->remotefilesiglevel); 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_local_file_siglevel(handle, config->localfilesiglevel);
alpm_option_set_remote_file_siglevel(handle, config->remotefilesiglevel); 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; alpm_list_t *values = NULL;
setrepeatingoption(value, "SigLevel", &values); setrepeatingoption(value, "SigLevel", &values);
if(values) { if(values) {
if(repo->siglevel == ALPM_SIG_USE_DEFAULT) { ret = process_siglevel(values, &repo->siglevel,
repo->siglevel = config->siglevel; &repo->siglevel_mask, file, line);
}
ret = process_siglevel(values, &repo->siglevel, file, line);
FREELIST(values); 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 */ /* 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); db = alpm_register_syncdb(config->handle, section->name, repo->siglevel);
if(db == NULL) { if(db == NULL) {
pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"), pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),

View File

@ -38,6 +38,7 @@ typedef struct __config_repo_t {
alpm_list_t *servers; alpm_list_t *servers;
alpm_db_usage_t usage; alpm_db_usage_t usage;
alpm_siglevel_t siglevel; alpm_siglevel_t siglevel;
alpm_siglevel_t siglevel_mask;
} config_repo_t; } config_repo_t;
typedef struct __config_t { typedef struct __config_t {
@ -94,6 +95,10 @@ typedef struct __config_t {
alpm_siglevel_t localfilesiglevel; alpm_siglevel_t localfilesiglevel;
alpm_siglevel_t remotefilesiglevel; alpm_siglevel_t remotefilesiglevel;
alpm_siglevel_t siglevel_mask;
alpm_siglevel_t localfilesiglevel_mask;
alpm_siglevel_t remotefilesiglevel_mask;
/* conf file options */ /* conf file options */
/* I Love Candy! */ /* I Love Candy! */
unsigned short chomp; unsigned short chomp;