From a1df119442a10efbc10ab8738d1e1bb8c2f16c07 Mon Sep 17 00:00:00 2001 From: Matthias Gatto Date: Fri, 13 Dec 2024 18:08:07 +0100 Subject: [PATCH] support ssl_verify in config.json Signed-off-by: Matthias Gatto --- lib.c | 40 ++++++++++++++++++++++++++++++++++++++++ lib.h | 19 ++++++++++--------- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/lib.c b/lib.c index d0d23f5..08c74be 100644 --- a/lib.c +++ b/lib.c @@ -279,6 +279,45 @@ static char *osc_strdup(const char *str) { } while (0) +int osc_set_extra_flag_from_conf(const char *profile, unsigned int *flag) +{ + char buf[1024]; + const char *cfg = cfg_path; + auto_osc_json_c struct json_object *to_free = NULL; + struct json_object *json_tmp, *js = NULL; + + if (!cfg) { + LOAD_CFG_GET_HOME(buf); + cfg = buf; + } + TRY(access(cfg, R_OK), "can't open/read %s\n", cfg); + js = json_object_from_file(cfg); + TRY(!js, "can't load json-file %s (json might have incorect syntaxe)\n", cfg); + to_free = js; + js = json_object_object_get(js, profile); + TRY(!js, "can't find profile %s\n", profile); + + json_tmp = json_object_object_get(js, "ssl_verify"); + if (json_tmp) { + if (!json_object_get_boolean(json_tmp) || + !json_object_get_int(json_tmp)) { + *flag = *flag | OSC_INSECURE_MODE; + } else { + *flag = *flag & (~OSC_INSECURE_MODE); + } + } + json_tmp = json_object_object_get(js, "verbose"); + if (json_tmp) { + if (json_object_get_boolean(json_tmp) || + json_object_get_int(json_tmp)) { + *flag = *flag | OSC_VERBOSE_MODE; + } else { + *flag = *flag & (~OSC_VERBOSE_MODE); + } + } + return 0; +} + int osc_load_ak_sk_from_conf(const char *profile, char **ak, char **sk) { char buf[1024]; @@ -585,6 +624,7 @@ int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag, if (f < 0) return -1; e->flag |= f; + osc_set_extra_flag_from_conf(profile, &flag); } if (!e->region) diff --git a/lib.h b/lib.h index 2ee5202..6894c27 100644 --- a/lib.h +++ b/lib.h @@ -65,15 +65,15 @@ struct osc_str { char *buf; }; -#define OSC_ENV_FREE_AK 1 << 0 -#define OSC_ENV_FREE_REGION 1 << 1 -#define OSC_VERBOSE_MODE 1 << 2 /* curl verbose mode + print request content */ -#define OSC_INSECURE_MODE 1 << 3 /* see --insecure option of curl */ -#define OSC_ENV_FREE_CERT 1 << 4 -#define OSC_ENV_FREE_SSLKEY 1 << 5 -#define OSC_ENV_FREE_SK 1 << 6 -#define OSC_ENV_FREE_PROXY 1 << 7 -#define OSC_ENV_FREE_ENDPOINT 1 << 8 +#define OSC_ENV_FREE_AK (1 << 0) +#define OSC_ENV_FREE_REGION (1 << 1) +#define OSC_VERBOSE_MODE (1 << 2) /* curl verbose mode + print request content */ +#define OSC_INSECURE_MODE (1 << 3) /* see --insecure option of curl */ +#define OSC_ENV_FREE_CERT (1 << 4) +#define OSC_ENV_FREE_SSLKEY (1 << 5) +#define OSC_ENV_FREE_SK (1 << 6) +#define OSC_ENV_FREE_PROXY (1 << 7) +#define OSC_ENV_FREE_ENDPOINT (1 << 8) #define OSC_ENV_FREE_AK_SK (OSC_ENV_FREE_AK | OSC_ENV_FREE_SK) @@ -134,6 +134,7 @@ struct osc_additional_strings { ____args____ +int osc_set_extra_flag_from_conf(const char *profile, unsigned int *flag); int osc_load_ak_sk_from_conf(const char *profile, char **ak, char **sk); int osc_load_region_from_conf(const char *profile, char **region); int osc_load_loging_password_from_conf(const char *profile,