From cd9e3a18c8d1d14f87c6340593e2ce6c4289afbb Mon Sep 17 00:00:00 2001 From: Iain M Conochie Date: Fri, 12 Apr 2024 12:51:22 +0100 Subject: [PATCH] Tidy up config files --- include/ailsacmdb.h | 2 -- lib/config.c | 68 ++++++--------------------------------------- src/cmdb.c | 11 +------- 3 files changed, 9 insertions(+), 72 deletions(-) diff --git a/include/ailsacmdb.h b/include/ailsacmdb.h index b6b19b7..e990f4b 100644 --- a/include/ailsacmdb.h +++ b/include/ailsacmdb.h @@ -1120,8 +1120,6 @@ void chomp(char *input); void display_type_error(short int type); -int -get_config_file_location(char *config); char * cmdb_get_uname(unsigned long int uid); const char * diff --git a/lib/config.c b/lib/config.c index 99a6bbc..5b39e56 100644 --- a/lib/config.c +++ b/lib/config.c @@ -60,32 +60,6 @@ parse_user_cmdb_config(ailsa_cmdb_s *cmdb); static void parse_cmdb_config_values(ailsa_cmdb_s *cmdb, FILE *conf); -int -get_config_file_location(char *config) -{ - int retval = 0; - FILE *cnf; - const char *conf = config; - - if (snprintf(config, CONFIG_LEN, "%s/cmdb/cmdb.conf", SYSCONFDIR) >= CONFIG_LEN) - return AILSA_BUFFER_TOO_SMALL; - if ((cnf = fopen(conf, "r"))) { - fclose(cnf); - } else { - if (snprintf(config, CONFIG_LEN, "%s/dnsa/dnsa.conf", SYSCONFDIR) >= CONFIG_LEN) { - ailsa_syslog(LOG_ERR, "Buffer too small to hold config file location"); - retval = AILSA_BUFFER_TOO_SMALL; - } - if ((cnf = fopen(conf, "r"))) - fclose(cnf); - else { - ailsa_syslog(LOG_ERR, "Cannot open config file %s", conf); - retval = AILSA_FILE_ERROR; - } - } - return retval; -} - void parse_mkvm_config(ailsa_mkvm_s *vm) { @@ -183,7 +157,7 @@ parse_user_mkvm_config(ailsa_mkvm_s *vm) #endif // HAVE_WORDEXP } -/* Grab config values from confile file that uses NAME=value as configuration +/* Grab config values from conffile file that uses NAME=value as configuration options */ #ifndef GET_CONFIG_OPTION # define GET_CONFIG_OPTION(CONFIG, option) { \ @@ -334,14 +308,6 @@ display_mksp_usage(void) printf("\t-p : Specify the path to the storage directory\n"); } -#ifndef OPEN_CMDB_FILE -# define OPEN_CMDB_FILE { \ - if ((conf = fopen(path, "r"))) { \ - parse_cmdb_config_values(cmdb, conf); \ - goto cleanup; \ - } \ - } -#endif static void parse_system_cmdb_config(ailsa_cmdb_s *cmdb) @@ -351,19 +317,13 @@ parse_system_cmdb_config(ailsa_cmdb_s *cmdb) memset(path, 0, FILE_LEN); snprintf(path, FILE_LEN, "%s/cmdb/cmdb.conf", SYSCONFDIR); - OPEN_CMDB_FILE - memset(path, 0, FILE_LEN); - snprintf(path, FILE_LEN, "%s/cmdb/dnsa.conf", SYSCONFDIR); - OPEN_CMDB_FILE - memset(path, 0, FILE_LEN); - snprintf(path, FILE_LEN, "%s/dnsa/cmdb.conf", SYSCONFDIR); - OPEN_CMDB_FILE - memset(path, 0, FILE_LEN); - snprintf(path, FILE_LEN, "%s/dnsa/dnsa.conf", SYSCONFDIR); - OPEN_CMDB_FILE - cleanup: - if (conf) - fclose(conf); + if ((conf = fopen(path, "r"))) { + parse_cmdb_config_values(cmdb, conf); + fclose(conf); + } else { + ailsa_syslog(LOG_DAEMON, "Cannot open %s for config\n", path); + exit (1); + } } static void @@ -383,17 +343,6 @@ parse_user_cmdb_config(ailsa_cmdb_s *cmdb) #ifdef DEBUG ailsa_syslog(LOG_DEBUG, "Cannot open file %s", *uconf); #endif - upath = "~/.dnsa.conf"; - wordexp_t r; - if ((retval = wordexp(upath, &r, 0)) == 0) { - uconf = r.we_wordv; - if (!(conf = fopen(*uconf, "r"))) { -#ifdef DEBUG - ailsa_syslog(LOG_DEBUG, "Cannot open file %s", *uconf); -#endif - } - wordfree(&r); - } } } #endif // HAVE_WORDEXP @@ -436,4 +385,3 @@ parse_user_cmdb_config(ailsa_cmdb_s *cmdb) #undef GET_CONFIG_OPTION #undef GET_CONFIG_INT -#undef OPEN_CMDB_FILE diff --git a/src/cmdb.c b/src/cmdb.c index 5a008a3..e71fdbc 100644 --- a/src/cmdb.c +++ b/src/cmdb.c @@ -314,13 +314,12 @@ cmdb_hardware_type_actions(cmdb_comm_line_s *cm, ailsa_cmdb_s *cc) static int parse_cmdb_command_line(int argc, char **argv, cmdb_comm_line_s *comp) { - const char *optstr = "c:i:k:n:x:y:A:B:C:D:E:H:I:L:M:N:O:P:S:T:U:V:Y:Z:adefghjlmorqstuvwz"; + const char *optstr = "i:k:n:x:y:A:B:C:D:E:H:I:L:M:N:O:P:S:T:U:V:Y:Z:adefghjlmorqstuvwz"; int opt, retval; #ifdef HAVE_GETOPT_H int index; struct option lopts[] = { {"add", no_argument, NULL, 'a'}, - {"config", required_argument, NULL, 'c'}, {"display", no_argument, NULL, 'd'}, {"service", no_argument, NULL, 'e'}, {"force", no_argument, NULL, 'f'}, @@ -369,11 +368,6 @@ parse_cmdb_command_line(int argc, char **argv, cmdb_comm_line_s *comp) }; #endif // HAVE_GETOPT_H retval = 0; - if (!(comp->config)) { - comp->config = ailsa_calloc(CONFIG_LEN, "comp->config in parse_cmdb_command_line"); - if ((retval = get_config_file_location(comp->config)) != 0) - return retval; - } #ifdef HAVE_GETOPT_H while ((opt = getopt_long(argc, argv, optstr, lopts, &index)) != -1) #else @@ -434,9 +428,6 @@ parse_cmdb_command_line(int argc, char **argv, cmdb_comm_line_s *comp) case 'f': comp->force = 1; break; - case 'c': - comp->config = strndup(optarg, CONFIG_LEN); - break; case 'n': comp->name = strndup(optarg, HOST_LEN); break;