FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 07-18-2011, 04:06 AM
Kerrick Staley
 
Default Changed SigLevel parsing in conf.c

Changed the SigLevel parsing in conf.c to handle the new options.

Signed-off-by: Kerrick Staley <mail@kerrickstaley.com>
---
src/pacman/conf.c | 93 ++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 78 insertions(+), 15 deletions(-)

diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index fac6da3..f0a6930 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -222,20 +222,83 @@ int config_set_arch(const char *arch)
return 0;
}

-static alpm_siglevel_t option_verifysig(const char *value)
+/**
+ * Parse a signature verification level. Destroys the passed string.
+ * @param value the string listing the siglevel options
+ * @return -1 if value was empty, -2 if value contained unknown
+ * options, -3 if some of the options were contradictory, the siglevel
+ * value otherwise.
+ */
+static alpm_siglevel_t option_siglevel(char *value)
{
- alpm_siglevel_t level;
- if(strcmp(value, "Always") == 0) {
- level = ALPM_SIG_PACKAGE | ALPM_SIG_DATABASE;
- } else if(strcmp(value, "Optional") == 0) {
- level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL |
- ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
- } else if(strcmp(value, "Never") == 0) {
- level = 0;
- } else {
+ alpm_siglevel_t level = 0;
+
+ char *strtok_state;
+ char *tok = strtok_r(value, " ", &strtok_state);
+
+ if (!tok) {
return -1;
}
- pm_printf(ALPM_LOG_DEBUG, "config: VerifySig = %s (%d)
", value, level);
+
+ do {
+ if(strcmp(tok, "Never") == 0) {
+ level = level ? -3 : 0;
+ break;
+ } else if(strcmp(tok, "Optional") == 0) {
+ level = level ? -3 : ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL |
+ ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
+ break;
+ } else if(strcmp(tok, "Required") == 0) {
+ level = level ? -3 : ALPM_SIG_PACKAGE | ALPM_SIG_DATABASE;
+ break;
+ } else if(strcmp(tok, "PackageHash") == 0) {
+ if (level & ALPM_SIG_DATABASE_OPTIONAL) {
+ level = -3;
+ break;
+ }
+ level |= ALPM_SIG_DATABASE | ALPM_SIG_PACKAGE_HASH_OK;
+ } else if(strcmp(tok, "PackageRequired") == 0) {
+ if (level & ALPM_SIG_PACKAGE_OPTIONAL) {
+ level = -3;
+ break;
+ }
+ level |= ALPM_SIG_PACKAGE;
+ } else if(strcmp(tok, "DatabaseRequired") == 0) {
+ if (level & ALPM_SIG_DATABASE_OPTIONAL) {
+ level = -3;
+ break;
+ }
+ level |= ALPM_SIG_DATABASE;
+ } else if(strcmp(tok, "PackageOptional") == 0) {
+ if (level & ALPM_SIG_PACKAGE) {
+ level = -3;
+ break;
+ }
+ level |= ALPM_SIG_PACKAGE_OPTIONAL;
+ } else if(strcmp(tok, "DatabaseOptional") == 0) {
+ if (level & ALPM_SIG_PACKAGE) {
+ level = -3;
+ break;
+ }
+ level |= ALPM_SIG_DATABASE_OPTIONAL;
+ } else if(strcmp(tok, "PackageAllowMarginal") == 0) {
+ level |= ALPM_SIG_PACKAGE_MARGINAL_OK;
+ } else if(strcmp(tok, "DatabaseAllowMarginal") == 0) {
+ level |= ALPM_SIG_DATABASE_MARGINAL_OK;
+ } else if(strcmp(tok, "PackageAllowUnknown") == 0) {
+ level |= ALPM_SIG_PACKAGE_UNKNOWN_OK;
+ } else if(strcmp(tok, "DatabaseAllowUnknown") == 0) {
+ level |= ALPM_SIG_DATABASE_UNKNOWN_OK;
+ } else {
+ level = -2;
+ break;
+ }
+ } while ((tok = strtok_r(NULL, " ", &strtok_state)));
+
+ if (level > 0) {
+ pm_printf(ALPM_LOG_DEBUG, "config: SigLevel = %s (%d)
", value, level);
+ }
+
return level;
}

@@ -359,9 +422,9 @@ static int _parse_options(const char *key, char *value,
return 1;
}
FREELIST(methods);
- } else if(strcmp(key, "VerifySig") == 0) {
- alpm_siglevel_t level = option_verifysig(value);
- if(level != -1) {
+ } else if(strcmp(key, "SigLevel") == 0) {
+ alpm_siglevel_t level = option_siglevel(value);
+ if(level > 0) {
config->siglevel = level;
} else {
pm_printf(ALPM_LOG_ERROR,
@@ -727,7 +790,7 @@ static int _parseconfig(const char *file, struct section_t *section,
}
section->servers = alpm_list_add(section->servers, strdup(value));
} else if(strcmp(key, "VerifySig") == 0) {
- alpm_siglevel_t level = option_verifysig(value);
+ alpm_siglevel_t level = option_siglevel(value);
if(level != -1) {
section->siglevel = level;
} else {
--
1.7.6
 

Thread Tools




All times are GMT. The time now is 12:48 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org