X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fascent.c;h=2ad641dfede55d98b9a3cf92ebd288dd20881ed4;hb=654783aed1fab02766a9cc036e859799e01f6f9e;hp=94691d6b08a545e4b72ffad26e09b775a5624db7;hpb=d22aee658210cbfa44caa39f302aa9331d4eab82;p=collectd.git diff --git a/src/ascent.c b/src/ascent.c index 94691d6b..2ad641df 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -91,10 +91,12 @@ struct player_info_s typedef struct player_info_s player_info_t; #define PLAYER_INFO_STATIC_INIT { -1, -1, -1, -1, -1 } -static char *url = NULL; -static char *user = NULL; -static char *pass = NULL; -static char *cacert = NULL; +static char *url = NULL; +static char *user = NULL; +static char *pass = NULL; +static char *verify_peer = NULL; +static char *verify_host = NULL; +static char *cacert = NULL; static CURL *curl = NULL; @@ -108,6 +110,8 @@ static const char *config_keys[] = "URL", "User", "Password", + "VerifyPeer", + "VerifyHost", "CACert" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -123,17 +127,19 @@ static int ascent_submit_gauge (const char *plugin_instance, /* {{{ */ vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "ascent"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "ascent", sizeof (vl.plugin)); if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); return (0); } /* }}} int ascent_submit_gauge */ @@ -498,6 +504,10 @@ static int ascent_config (const char *key, const char *value) /* {{{ */ return (config_set (&user, value)); else if (strcasecmp (key, "Password") == 0) return (config_set (&pass, value)); + else if (strcasecmp (key, "VerifyPeer") == 0) + return (config_set (&verify_peer, value)); + else if (strcasecmp (key, "VerifyHost") == 0) + return (config_set (&verify_host, value)); else if (strcasecmp (key, "CACert") == 0) return (config_set (&cacert, value)); else @@ -534,7 +544,7 @@ static int ascent_init (void) /* {{{ */ { int status; - status = snprintf (credentials, sizeof (credentials), "%s:%s", + status = ssnprintf (credentials, sizeof (credentials), "%s:%s", user, (pass == NULL) ? "" : pass); if (status >= sizeof (credentials)) { @@ -542,13 +552,22 @@ static int ascent_init (void) /* {{{ */ "credentials have been truncated."); return (-1); } - credentials[sizeof (credentials) - 1] = '\0'; curl_easy_setopt (curl, CURLOPT_USERPWD, credentials); } curl_easy_setopt (curl, CURLOPT_URL, url); + if ((verify_peer == NULL) || (strcmp (verify_peer, "true") == 0)) + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1); + else + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0); + + if ((verify_host == NULL) || (strcmp (verify_host, "true") == 0)) + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2); + else + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0); + if (cacert != NULL) curl_easy_setopt (curl, CURLOPT_CAINFO, cacert);