Commit fdef27fb authored by npzacs's avatar npzacs
Browse files

Moved _load_config() to keydbcfg.c

parent 83b6b7b1
......@@ -244,7 +244,7 @@ static int _parse_cert_file(config_file *cf, FILE *fp)
return result;
}
int keydbcfg_load_pk_file(config_file *cf)
static int _load_pk_file(config_file *cf)
{
static const char pk_file_name[] = PK_FILE_NAME;
FILE *fp;
......@@ -265,7 +265,7 @@ int keydbcfg_load_pk_file(config_file *cf)
return result;
}
int keydbcfg_load_cert_file(config_file *cf)
static int _load_cert_file(config_file *cf)
{
static const char cert_file_name[] = CERT_FILE_NAME;
FILE *fp;
......@@ -402,7 +402,7 @@ int keycache_find(const char *type, const uint8_t *disc_id, uint8_t *key, unsign
return result;
}
char *keydbcfg_find_config_file(void)
static char *_find_config_file(void)
{
static const char cfg_file_name[] = CFG_FILE_NAME;
......@@ -422,3 +422,37 @@ char *keydbcfg_find_config_file(void)
return cfg_file;
}
config_file *keydbcfg_config_load(const char *configfile_path)
{
int config_ok = 0;
config_file *cf = keydbcfg_new_config_file();
/* try to load KEYDB.cfg */
if (configfile_path) {
config_ok = keydbcfg_parse_config(cf, configfile_path);
} else {
/* If no configfile path given, check for config files in user's home or
* under /etc.
*/
char *cfgfile = _find_config_file();
config_ok = keydbcfg_parse_config(cf, cfgfile);
X_FREE(cfgfile);
}
/* Try to load simple (aacskeys) config files */
config_ok = _load_pk_file(cf) || config_ok;
config_ok = _load_cert_file(cf) || config_ok;
if (!config_ok) {
DEBUG(DBG_AACS | DBG_CRIT, "No valid AACS configuration files found\n");
keydbcfg_config_file_close(cf);
return NULL;
}
return cf;
}
......@@ -118,9 +118,7 @@ AACS_PRIVATE int keydbcfg_config_file_close(config_file *cfgfile);
/* */
AACS_PRIVATE char *keydbcfg_find_config_file(void);
AACS_PRIVATE int keydbcfg_load_cert_file(config_file *cf);
AACS_PRIVATE int keydbcfg_load_pk_file(config_file *cf);
AACS_PRIVATE config_file *keydbcfg_config_load(const char *configfile_path);
AACS_PRIVATE int keycache_save(const char *type, const uint8_t *disc_id,
const uint8_t *key, unsigned int len);
......
......@@ -596,39 +596,6 @@ static int _decrypt_unit(AACS *aacs, uint8_t *out_buf, const uint8_t *in_buf, ui
return 0;
}
static int _load_config(AACS *aacs, const char *configfile_path)
{
int config_ok = 0;
aacs->cf = keydbcfg_new_config_file();
/* try to load KEYDB.cfg */
if (configfile_path) {
config_ok = keydbcfg_parse_config(aacs->cf, configfile_path);
} else {
/* If no configfile path given, check for config files in user's home or
* under /etc.
*/
char *cfgfile = keydbcfg_find_config_file();
config_ok = keydbcfg_parse_config(aacs->cf, cfgfile);
X_FREE(cfgfile);
}
/* Try to load simple (aacskeys) config files */
config_ok = keydbcfg_load_pk_file(aacs->cf) || config_ok;
config_ok = keydbcfg_load_cert_file(aacs->cf) || config_ok;
if (!config_ok) {
DEBUG(DBG_AACS | DBG_CRIT, "No valid AACS configuration files found\n");
return AACS_ERROR_NO_CONFIG;
}
return AACS_SUCCESS;
}
void aacs_get_version(int *major, int *minor, int *micro)
{
*major = AACS_VERSION_MAJOR;
......@@ -663,9 +630,10 @@ AACS *aacs_open2(const char *path, const char *configfile_path, int *error_code)
AACS *aacs = calloc(1, sizeof(AACS));
*error_code = _load_config(aacs, configfile_path);
if (*error_code != AACS_SUCCESS) {
aacs->cf = keydbcfg_config_load(configfile_path);
if (!aacs->cf) {
aacs_close(aacs);
*error_code = AACS_ERROR_NO_CONFIG;
return NULL;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment