From b62b785d0fbc27e83954fcf951fe722f0b791a98 Mon Sep 17 00:00:00 2001 From: Palak Date: Tue, 16 Apr 2024 14:00:00 +0530 Subject: [PATCH] Added -m flag --- src/admin.c | 52 +++++++++------------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/src/admin.c b/src/admin.c index 084e6a0..642a7a9 100644 --- a/src/admin.c +++ b/src/admin.c @@ -166,8 +166,7 @@ usage(void) printf(" pgagroal-admin [ -f FILE ] [ COMMAND ] \n"); printf("\n"); printf("Options:\n"); - printf(" -c, --config CONFIG_FILE Set the path to the pgagroal.conf file\n"); - printf(" Default: %s\n", PGAGROAL_DEFAULT_CONF_FILE); + printf(" -m, --master-key-file MASTER_KEY_FILE Set the path to the master.key file\n"); printf(" -f, --file FILE Set the path to a user file\n"); printf(" Defaults to %s\n", PGAGROAL_DEFAULT_USERS_FILE); printf(" -U, --user USER Set the user name\n"); @@ -201,16 +200,13 @@ main(int argc, char** argv) int option_index = 0; size_t command_count = sizeof(command_table) / sizeof(struct pgagroal_command); struct pgagroal_parsed_command parsed = {.cmd = NULL, .args = {0}}; - char* configuration_path = NULL; - struct main_configuration* config = NULL; - int ret; - size_t size; + char* master_key_path = NULL; while (1) { static struct option long_options[] = { - {"config", required_argument, 0, 'c'}, + {"master-key-file", required_argument, 0, 'm'}, {"user", required_argument, 0, 'U'}, {"password", required_argument, 0, 'P'}, {"file", required_argument, 0, 'f'}, @@ -220,7 +216,7 @@ main(int argc, char** argv) {"help", no_argument, 0, '?'} }; - c = getopt_long(argc, argv, "gV?c:f:U:P:l:", + c = getopt_long(argc, argv, "gV?f:m:U:P:l:", long_options, &option_index); if (c == -1) @@ -230,8 +226,8 @@ main(int argc, char** argv) switch (c) { - case 'c': - configuration_path = optarg; + case 'm': + master_key_path = optarg; break; case 'U': username = optarg; @@ -271,36 +267,6 @@ main(int argc, char** argv) exit(1); } - size = sizeof(struct main_configuration); - if (pgagroal_create_shared_memory(size, HUGEPAGE_OFF, &shmem)) - { - errx(1, "Error creating shared memory"); - } - pgagroal_init_configuration(shmem); - - if (configuration_path != NULL) - { - ret = pgagroal_read_configuration(shmem, configuration_path, false); - if (ret == PGAGROAL_CONFIGURATION_STATUS_FILE_NOT_FOUND) - { - errx(1, "Configuration not found: <%s>", configuration_path); - } - else if (ret == PGAGROAL_CONFIGURATION_STATUS_FILE_TOO_BIG) - { - errx(1, "Too many sections in the configuration file <%s>", configuration_path); - } - config = (struct main_configuration*)shmem; - } - else - { - ret = pgagroal_read_configuration(shmem, PGAGROAL_DEFAULT_CONF_FILE, false); - if(ret == PGAGROAL_CONFIGURATION_STATUS_FILE_NOT_FOUND){ - errx(1, "Configuration file not found"); - } - config = (struct main_configuration*)shmem; - - } - if (!parse_command(argc, argv, optind, &parsed, command_table, command_count)) { usage(); @@ -321,21 +287,21 @@ main(int argc, char** argv) if (parsed.cmd->action == ACTION_MASTER_KEY) { - if (master_key(password, generate_pwd, pwd_length, config->master_key_file_location)) + if (master_key(password, generate_pwd, pwd_length, master_key_path)) { errx(1, "Cannot generate master key"); } } else if (parsed.cmd->action == ACTION_ADD_USER) { - if (add_user(file_path, username, password, generate_pwd, pwd_length, config->master_key_file_location)) + if (add_user(file_path, username, password, generate_pwd, pwd_length, master_key_path)) { errx(1, "Error for "); } } else if (parsed.cmd->action == ACTION_UPDATE_USER) { - if (update_user(file_path, username, password, generate_pwd, pwd_length, config->master_key_file_location)) + if (update_user(file_path, username, password, generate_pwd, pwd_length, master_key_path)) { errx(1, "Error for "); }