From f230c32371667353f57206e1d52ed87c8ebe2472 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Wed, 16 Dec 2015 18:00:57 -0800 Subject: [PATCH] promote chop_* functions into fko_util --- client/config_init.c | 1 + common/fko_util.c | 33 +++++++++++++++++++++++++++++++++ common/fko_util.h | 4 ++++ server/config_init.c | 6 ++---- server/utils.c | 30 ------------------------------ server/utils.h | 3 --- 6 files changed, 40 insertions(+), 37 deletions(-) diff --git a/client/config_init.c b/client/config_init.c index 6a8f19b8..14041e32 100644 --- a/client/config_init.c +++ b/client/config_init.c @@ -2348,6 +2348,7 @@ config_init(fko_cli_options_t *options, int argc, char **argv) case GPG_HOME_DIR: options->use_gpg = 1; strlcpy(options->gpg_home_dir, optarg, sizeof(options->gpg_home_dir)); + chop_char(options->gpg_home_dir, PATH_SEP); add_var_to_bitmask(FWKNOP_CLI_ARG_USE_GPG, &var_bitmask); add_var_to_bitmask(FWKNOP_CLI_ARG_GPG_HOMEDIR, &var_bitmask); break; diff --git a/common/fko_util.c b/common/fko_util.c index 3e095c75..32adca78 100644 --- a/common/fko_util.c +++ b/common/fko_util.c @@ -622,6 +622,39 @@ is_base64(const unsigned char * const buf, const unsigned short int len) return rv; } +void +chop_char(char *str, const char chop) +{ + if(str != NULL + && str[0] != 0x0 + && strlen(str) > 1 /* don't truncate a single-char string */ + && str[strlen(str)-1] == chop) + str[strlen(str)-1] = 0x0; + return; +} + +void +chop_newline(char *str) +{ + chop_char(str, 0x0a); + return; +} + +void chop_spaces(char *str) +{ + int i; + if (str != NULL && str[0] != 0x0) + { + for (i=strlen(str)-1; i > 0; i--) + { + if(str[i] != 0x20) + break; + str[i] = 0x0; + } + } + return; +} + /** * @brief Dump a FKO context to a buffer * diff --git a/common/fko_util.h b/common/fko_util.h index f7fd153d..4988770b 100644 --- a/common/fko_util.h +++ b/common/fko_util.h @@ -54,6 +54,10 @@ int zero_buf(char *buf, int len); const char * enc_type_inttostr(const int type); const char * msg_type_inttostr(const int type); +void chop_newline(char *str); +void chop_char(char *str, const char chop); +void chop_spaces(char *str); + #if !HAVE_STRLCAT size_t strlcat(char *dst, const char *src, size_t siz); #endif diff --git a/server/config_init.c b/server/config_init.c index 215b327c..4fde5aa7 100644 --- a/server/config_init.c +++ b/server/config_init.c @@ -1210,8 +1210,7 @@ config_init(fko_srv_options_t *opts, int argc, char **argv) } break; case ACCESS_FOLDER: - if(strlen(optarg) > 1) - chop_char(optarg, PATH_SEP); + chop_char(optarg, PATH_SEP); if (is_valid_dir(optarg)) set_config_entry(opts, CONF_ACCESS_FOLDER, optarg); else @@ -1286,8 +1285,7 @@ config_init(fko_srv_options_t *opts, int argc, char **argv) } break; case GPG_HOME_DIR: - if(strlen(optarg) > 1) - chop_char(optarg, PATH_SEP); + chop_char(optarg, PATH_SEP); if (is_valid_dir(optarg)) set_config_entry(opts, CONF_GPG_HOME_DIR, optarg); else diff --git a/server/utils.c b/server/utils.c index 66f71696..95835ad9 100644 --- a/server/utils.c +++ b/server/utils.c @@ -213,36 +213,6 @@ verify_file_perms_ownership(const char *file) return 1; } -void -chop_char(char *str, const char chop) -{ - if(str != NULL && str[0] != 0x0 && str[strlen(str)-1] == chop) - str[strlen(str)-1] = 0x0; - return; -} - -void -chop_newline(char *str) -{ - chop_char(str, 0x0a); - return; -} - -void chop_spaces(char *str) -{ - int i; - if (str != NULL && str[0] != 0x0) - { - for (i=strlen(str)-1; i > 0; i--) - { - if(str[i] != 0x20) - break; - str[i] = 0x0; - } - } - return; -} - void truncate_partial_line(char *str) { diff --git a/server/utils.h b/server/utils.h index 436873dd..c3dc2063 100644 --- a/server/utils.h +++ b/server/utils.h @@ -66,9 +66,6 @@ int is_valid_dir(const char *path); int is_valid_exe(const char *path); int is_valid_file(const char *path); int verify_file_perms_ownership(const char *file); -void chop_newline(char *str); -void chop_char(char *str, const char chop); -void chop_spaces(char *str); void truncate_partial_line(char *str); int is_digits(const char * const str); int strtoargv(const char * const args_str, char **argv_new, int *argc_new,