From 613cb60c96e21eaafb82b80a6b6d84b1b1f9729f Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 8 Apr 2026 17:21:44 +0200 Subject: check_curl: Clean up (#2252) * check_curl: remove unused variables * check_curl: run formatter on related files * check_curl_helpers: make code a bit more understandable * check_curl helpers: general api cleanup and code style --- plugins/check_curl.c | 88 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 32 deletions(-) (limited to 'plugins/check_curl.c') diff --git a/plugins/check_curl.c b/plugins/check_curl.c index f63cdea2..b168cbcd 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -247,8 +247,9 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state printf("**** REQUEST CONTENT ****\n%s\n", workingState.http_post_data); } - // curl_state is updated after curl_easy_perform, and with updated curl_state certificate checks can be done - // Check_http tries to check certs as early as possible, and exits with certificate check result by default. Behave similarly. + // curl_state is updated after curl_easy_perform, and with updated curl_state certificate checks + // can be done Check_http tries to check certs as early as possible, and exits with certificate + // check result by default. Behave similarly. #ifdef LIBCURL_FEATURE_SSL if (workingState.use_ssl && config.check_cert) { if (verbose > 1) { @@ -1546,8 +1547,8 @@ void print_help(void) { printf(" %s\n", "-I, --IP-address=ADDRESS"); printf(" %s\n", "IP address or name (use numeric address if possible to bypass DNS lookup)."); - printf(" %s\n", - "This overwrites the network address of the target while leaving everything else (HTTP headers) as they are"); + printf(" %s\n", "This overwrites the network address of the target while leaving everything " + "else (HTTP headers) as they are"); printf(" %s\n", "-p, --port=INTEGER"); printf(" %s", _("Port number (default: ")); printf("%d)\n", HTTP_PORT); @@ -1611,7 +1612,8 @@ void print_help(void) { printf(" %s\n", _("String to expect in the content")); printf(" %s\n", "-u, --url=PATH"); printf(" %s\n", _("URL to GET or POST (default: /)")); - printf(" %s\n", _("This is the part after the address in a URL, so for \"https://example.com/index.html\" it would be '-u /index.html'")); + printf(" %s\n", _("This is the part after the address in a URL, so for " + "\"https://example.com/index.html\" it would be '-u /index.html'")); printf(" %s\n", "-P, --post=STRING"); printf(" %s\n", _("URL decoded http POST data")); printf(" %s\n", @@ -1643,11 +1645,12 @@ void print_help(void) { printf(" %s\n", _("If port is not specified, libcurl defaults to 1080")); printf(" %s\n", _("This value will be set as CURLOPT_PROXY")); printf(" %s\n", "--noproxy=COMMA_SEPARATED_LIST"); - printf(" %s\n", _("Specify hostnames, addresses and subnets where proxy should not be used")); + printf(" %s\n", + _("Specify hostnames, addresses and subnets where proxy should not be used")); printf(" %s\n", _("Example usage: \"example.com,::1,1.1.1.1,localhost,192.168.0.0/16\"")); printf(" %s\n", _("Do not use brackets when specifying IPv6 addresses")); printf(" %s\n", _("Special case when an item is '*' : matches all hosts/addresses " - "and effectively disables proxy.")); + "and effectively disables proxy.")); printf(" %s\n", _("This value will be set as CURLOPT_NOPROXY")); printf(" %s\n", "-a, --authorization=AUTH_PAIR"); printf(" %s\n", _("Username:password on sites with basic authentication")); @@ -1757,38 +1760,59 @@ void print_help(void) { #endif printf("\n %s\n", "CHECK WEBSERVER CONTENT VIA PROXY:"); - printf(" %s\n", _("Proxies are specified or disabled for certain hosts/addresses using environment variables" - " or -x/--proxy and --noproxy arguments:")); - printf(" %s\n", _("Checked environment variables: all_proxy, http_proxy, https_proxy, no_proxy")); - printf(" %s\n", _("Environment variables can also be given in uppercase, but the lowercase ones will " - "take predence if both are defined.")); - printf(" %s\n", _("The environment variables are overwritten by -x/--proxy and --noproxy arguments:")); + printf(" %s\n", _("Proxies are specified or disabled for certain hosts/addresses using " + "environment variables" + " or -x/--proxy and --noproxy arguments:")); + printf(" %s\n", + _("Checked environment variables: all_proxy, http_proxy, https_proxy, no_proxy")); + printf(" %s\n", + _("Environment variables can also be given in uppercase, but the lowercase ones will " + "take predence if both are defined.")); + printf(" %s\n", + _("The environment variables are overwritten by -x/--proxy and --noproxy arguments:")); printf(" %s\n", _("all_proxy/ALL_PROXY environment variables are read first, but protocol " - "specific environment variables override them.")); - printf(" %s\n", _("If SSL is enabled and used, https_proxy/HTTPS_PROXY will be checked and overwrite " - "http_proxy/HTTPS_PROXY.")); - printf(" %s\n", _("Curl accepts proxies using http, https, socks4, socks4a, socks5 and socks5h schemes.")); - printf(" %s\n", _("http_proxy=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org")); - printf(" %s\n", _("http_proxy=http://used.proxy.com HTTP_PROXY=http://ignored.proxy.com ./check_curl -H www.monitoring-plugins.org")); + "specific environment variables override them.")); + printf(" %s\n", + _("If SSL is enabled and used, https_proxy/HTTPS_PROXY will be checked and overwrite " + "http_proxy/HTTPS_PROXY.")); + printf( + " %s\n", + _("Curl accepts proxies using http, https, socks4, socks4a, socks5 and socks5h schemes.")); + printf(" %s\n", + _("http_proxy=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org")); + printf(" %s\n", _("http_proxy=http://used.proxy.com HTTP_PROXY=http://ignored.proxy.com " + "./check_curl -H www.monitoring-plugins.org")); printf(" %s\n", _(" Lowercase http_proxy takes predence over uppercase HTTP_PROXY")); printf(" %s\n", _("./check_curl -H www.monitoring-plugins.org -x http://192.168.100.35:3128")); - printf(" %s\n", _("http_proxy=http://unused.proxy1.com HTTP_PROXY=http://unused.proxy2.com ./check_curl " - "-H www.monitoring-plugins.org --proxy http://used.proxy")); - printf(" %s\n", _(" Proxy specified by --proxy overrides any proxy specified by environment variable.")); + printf(" %s\n", + _("http_proxy=http://unused.proxy1.com HTTP_PROXY=http://unused.proxy2.com ./check_curl " + "-H www.monitoring-plugins.org --proxy http://used.proxy")); + printf( + " %s\n", + _(" Proxy specified by --proxy overrides any proxy specified by environment variable.")); printf(" %s\n", _(" Curl uses port 1080 by default as port is not specified")); - printf(" %s\n", _("HTTPS_PROXY=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org --ssl")); + printf(" %s\n", _("HTTPS_PROXY=http://192.168.100.35:3128 ./check_curl -H " + "www.monitoring-plugins.org --ssl")); printf(" %s\n", _(" HTTPS_PROXY is read as --ssl is toggled")); - printf(" %s\n", _("./check_curl -H www.monitoring-plugins.org --proxy socks5h://192.168.122.21")); - printf(" %s\n", _("./check_curl -H www.monitoring-plugins.org -x http://unused.proxy.com --noproxy '*'")); + printf(" %s\n", + _("./check_curl -H www.monitoring-plugins.org --proxy socks5h://192.168.122.21")); + printf( + " %s\n", + _("./check_curl -H www.monitoring-plugins.org -x http://unused.proxy.com --noproxy '*'")); printf(" %s\n", _(" Disabled proxy for all hosts by using '*' in no_proxy .")); - printf(" %s\n", _("NO_PROXY=www.monitoring-plugins.org ./check_curl -H www.monitoring-plugins.org -x http://unused.proxy.com")); + printf(" %s\n", _("NO_PROXY=www.monitoring-plugins.org ./check_curl -H " + "www.monitoring-plugins.org -x http://unused.proxy.com")); printf(" %s\n", _(" Exact matches with the hostname/address work.")); - printf(" %s\n", _("no_proxy=192.168.178.0/24 ./check_curl -I 192.168.178.10 -x http://proxy.acme.org")); - printf(" %s\n", _("no_proxy=acme.org ./check_curl -H nonpublic.internalwebapp.acme.org -x http://proxy.acme.org")); - printf(" %s\n", _(" Do not use proxy when accessing internal domains/addresses, but use a default proxy when accessing public web.")); - printf(" %s\n", _(" IMPORTANT: Check_curl can not always determine whether itself or the proxy will " - "resolve a hostname before sending a request and getting an answer." - "This can lead to DNS resolvation issues if hostname is only resolvable over proxy.")); + printf(" %s\n", + _("no_proxy=192.168.178.0/24 ./check_curl -I 192.168.178.10 -x http://proxy.acme.org")); + printf(" %s\n", _("no_proxy=acme.org ./check_curl -H nonpublic.internalwebapp.acme.org -x " + "http://proxy.acme.org")); + printf(" %s\n", _(" Do not use proxy when accessing internal domains/addresses, but use a " + "default proxy when accessing public web.")); + printf(" %s\n", + _(" IMPORTANT: Check_curl can not always determine whether itself or the proxy will " + "resolve a hostname before sending a request and getting an answer." + "This can lead to DNS resolvation issues if hostname is only resolvable over proxy.")); printf(" %s\n", _("Legacy proxy requests in check_http style still work:")); printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u http://www.monitoring-plugins.org/ " "-H www.monitoring-plugins.org")); -- cgit v1.2.3-74-g34f1 From 3a6f9292f147de29b21dafa4cf9b7efce3e4cbfd Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 8 Apr 2026 18:06:29 +0200 Subject: Rename USE_OPENSSL to MOPL_USE_OPENSSL (#2253) net-snmp uses the same pre processor name "USE_OPENSSL" as we do. To avoid the conflict, this commit renames it on our side to "MOPL_USE_OPENSSL". "MOPL" (better "MoPl"?) stands for Monitoring Plugins. --- configure.ac | 2 +- lib/utils_base.h | 2 +- plugins/check_curl.c | 26 ++++++++++----------- plugins/check_curl.d/check_curl_helpers.c | 16 ++++++------- plugins/check_smtp.c | 6 ++--- plugins/check_tcp.c | 4 ++-- plugins/sslutils.c | 38 +++++++++++++++---------------- 7 files changed, 47 insertions(+), 47 deletions(-) (limited to 'plugins/check_curl.c') diff --git a/configure.ac b/configure.ac index ae7eb30b..e4351ad7 100644 --- a/configure.ac +++ b/configure.ac @@ -578,7 +578,7 @@ if test "$FOUNDOPENSSL" = "yes" || test "$FOUNDGNUTLS" = "yes"; then AC_SUBST(SSLLIBS) AC_DEFINE(HAVE_SSL,1,[Define if SSL libraries are found]) if test "$FOUNDOPENSSL" = "yes"; then - AC_DEFINE(USE_OPENSSL,1,[Define if using OpenSSL libraries]) + AC_DEFINE(MOPL_USE_OPENSSL,1,[Define if using OpenSSL libraries]) with_openssl="yes" with_gnutls="no" else diff --git a/lib/utils_base.h b/lib/utils_base.h index 27884bf0..1da96f78 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h @@ -9,7 +9,7 @@ #include "./thresholds.h" #include "states.h" -#ifndef USE_OPENSSL +#ifndef MOPL_USE_OPENSSL # include "sha256.h" #endif diff --git a/plugins/check_curl.c b/plugins/check_curl.c index b168cbcd..fe7e61d6 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -62,7 +62,7 @@ const char *email = "devel@monitoring-plugins.org"; #include #include -#if defined(HAVE_SSL) && defined(USE_OPENSSL) +#if defined(HAVE_SSL) && defined(MOPL_USE_OPENSSL) # include #endif @@ -81,9 +81,9 @@ extern char errbuf[MAX_INPUT_BUFFER]; extern bool is_openssl_callback; extern bool add_sslctx_verify_fun; -#if defined(HAVE_SSL) && defined(USE_OPENSSL) +#if defined(HAVE_SSL) && defined(MOPL_USE_OPENSSL) static X509 *cert = NULL; -#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ +#endif /* defined(HAVE_SSL) && defined(MOPL_USE_OPENSSL) */ typedef struct { int errorcode; @@ -114,10 +114,10 @@ static void print_curl_version(void); // check_curl_evaluation_wrapper check_curl_evaluate(check_curl_config config, // mp_check overall[static 1]) {} -#if defined(HAVE_SSL) && defined(USE_OPENSSL) +#if defined(HAVE_SSL) && defined(MOPL_USE_OPENSSL) mp_state_enum np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit); -#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ +#endif /* defined(HAVE_SSL) && defined(MOPL_USE_OPENSSL) */ int main(int argc, char **argv) { #ifdef __OpenBSD__ @@ -167,7 +167,7 @@ int main(int argc, char **argv) { } #ifdef HAVE_SSL -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) { (void)preverify_ok; /* TODO: we get all certificates of the chain, so which ones @@ -190,11 +190,11 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) { } return 1; } -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ #endif /* HAVE_SSL */ #ifdef HAVE_SSL -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) { (void)curl; // ignore unused parameter (void)parm; // ignore unused parameter @@ -211,7 +211,7 @@ CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) { return CURLE_OK; } -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ #endif /* HAVE_SSL */ mp_subcheck check_http(const check_curl_config config, check_curl_working_state workingState, @@ -1867,7 +1867,7 @@ void print_usage(void) { void print_curl_version(void) { printf("%s\n", curl_version()); } #ifdef LIBCURL_FEATURE_SSL -# ifndef USE_OPENSSL +# ifndef MOPL_USE_OPENSSL time_t parse_cert_date(const char *s) { if (!s) { return -1; @@ -1884,11 +1884,11 @@ time_t parse_cert_date(const char *s) { return date; } -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ #endif /* LIBCURL_FEATURE_SSL */ #ifdef LIBCURL_FEATURE_SSL -# ifndef USE_OPENSSL +# ifndef MOPL_USE_OPENSSL /* TODO: this needs cleanup in the sslutils.c, maybe we the #else case to * OpenSSL could be this function */ @@ -2025,5 +2025,5 @@ int net_noopenssl_check_certificate(cert_ptr_union *cert_ptr, int days_till_exp_ } return status; } -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ #endif /* LIBCURL_FEATURE_SSL */ diff --git a/plugins/check_curl.d/check_curl_helpers.c b/plugins/check_curl.d/check_curl_helpers.c index f23dbdb7..80d6f4f6 100644 --- a/plugins/check_curl.d/check_curl_helpers.c +++ b/plugins/check_curl.d/check_curl_helpers.c @@ -439,11 +439,11 @@ check_curl_configure_curl(const check_curl_static_curl_config config, case CURLHELP_SSL_LIBRARY_LIBRESSL: /* set callback to extract certificate with OpenSSL context function (works with * OpenSSL-style libraries only!) */ -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL /* libcurl and monitoring plugins built with OpenSSL, good */ add_sslctx_verify_fun = true; is_openssl_callback = true; -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ /* libcurl is built with OpenSSL, monitoring plugins, so falling * back to manually extracting certificate information */ handle_curl_option_return_code( @@ -1312,16 +1312,16 @@ mp_subcheck check_curl_certificate_checks(CURL *curl, X509 *cert, int warn_days_ #ifdef LIBCURL_FEATURE_SSL if (is_openssl_callback) { -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL /* check certificate with OpenSSL functions, curl has been built against OpenSSL * and we actually have OpenSSL in the monitoring tools */ return mp_net_ssl_check_certificate(cert, warn_days_till_exp, crit_days_till_exp); -# else /* USE_OPENSSL */ +# else /* MOPL_USE_OPENSSL */ xasprintf(&result.output, "HTTP CRITICAL - Cannot retrieve certificates - OpenSSL " "callback used and not linked against OpenSSL\n"); mp_set_subcheck_state(result, STATE_CRITICAL); -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ } else { struct curl_slist *slist; @@ -1329,7 +1329,7 @@ mp_subcheck check_curl_certificate_checks(CURL *curl, X509 *cert, int warn_days_ cert_ptr.to_info = NULL; CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_certinfo); if (!res && cert_ptr.to_info) { -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert * parsing We only check the first certificate and assume it's the one of * the server @@ -1375,13 +1375,13 @@ mp_subcheck check_curl_certificate_checks(CURL *curl, X509 *cert, int warn_days_ BIO_free(cert_BIO); return mp_net_ssl_check_certificate(cert, warn_days_till_exp, crit_days_till_exp); -# else /* USE_OPENSSL */ +# else /* MOPL_USE_OPENSSL */ /* We assume we don't have OpenSSL and np_net_ssl_check_certificate at our * disposal, so we use the libcurl CURLINFO data */ return net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ } else { xasprintf(&sc_cert_result.output, _("Cannot retrieve certificates - cURL returned %d - %s"), res, diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 24883fd8..19e2a58f 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -350,7 +350,7 @@ int main(int argc, char **argv) { } } -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL if (ssl_established) { net_ssl_check_cert_result cert_check_result = np_net_ssl_check_cert2(config.days_till_exp_warn, config.days_till_exp_crit); @@ -389,7 +389,7 @@ int main(int argc, char **argv) { mp_add_subcheck_to_check(&overall, sc_cert_check); } -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ #endif @@ -764,7 +764,7 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) { break; case 'D': { /* Check SSL cert validity */ -#ifdef USE_OPENSSL +#ifdef MOPL_USE_OPENSSL char *temp; if ((temp = strchr(optarg, ',')) != NULL) { *temp = '\0'; diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 49a8c4c1..cd8e04b0 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c @@ -683,7 +683,7 @@ static check_tcp_config_wrapper process_arguments(int argc, char **argv, check_t break; case 'D': /* Check SSL cert validity - days 'til certificate expiration */ #ifdef HAVE_SSL -# ifdef USE_OPENSSL /* XXX */ +# ifdef MOPL_USE_OPENSSL /* XXX */ { char *temp; if ((temp = strchr(optarg, ',')) != NULL) { @@ -708,7 +708,7 @@ static check_tcp_config_wrapper process_arguments(int argc, char **argv, check_t config.check_cert = true; config.use_tls = true; } break; -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ #endif /* fallthrough if we don't have ssl */ case 'S': diff --git a/plugins/sslutils.c b/plugins/sslutils.c index c58a35ab..c4ab6a05 100644 --- a/plugins/sslutils.c +++ b/plugins/sslutils.c @@ -127,7 +127,7 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int } if (cert && privkey) { -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL if (!SSL_CTX_use_certificate_chain_file(ctx, cert)) { # elif USE_GNUTLS if (!SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM)) { @@ -138,7 +138,7 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int return STATE_CRITICAL; } SSL_CTX_use_PrivateKey_file(ctx, privkey, SSL_FILETYPE_PEM); -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL if (!SSL_CTX_check_private_key(ctx)) { printf("%s\n", _("CRITICAL - Private key does not seem to match certificate!\n")); return STATE_CRITICAL; @@ -161,9 +161,9 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int return OK; } else { printf("%s\n", _("CRITICAL - Cannot make SSL connection.")); -# ifdef USE_OPENSSL /* XXX look into ERR_error_string */ +# ifdef MOPL_USE_OPENSSL /* XXX look into ERR_error_string */ ERR_print_errors_fp(stdout); -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ } } else { printf("%s\n", _("CRITICAL - Cannot initiate SSL handshake.")); @@ -192,7 +192,7 @@ int np_net_ssl_read(void *buf, int num) { return SSL_read(s, buf, num); } mp_state_enum np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit) { -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL if (!certificate) { printf("%s\n", _("CRITICAL - No server certificate present to inspect.")); return STATE_CRITICAL; @@ -306,14 +306,14 @@ mp_state_enum np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_ } X509_free(certificate); return status; -# else /* ifndef USE_OPENSSL */ +# else /* ifndef MOPL_USE_OPENSSL */ printf("%s\n", _("WARNING - Plugin does not support checking certificates.")); return STATE_WARNING; -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ } retrieve_expiration_time_result np_net_ssl_get_cert_expiration(X509 *certificate) { -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL retrieve_expiration_time_result result = { .errors = ALL_OK, .remaining_seconds = 0, @@ -404,14 +404,14 @@ retrieve_expiration_time_result np_net_ssl_get_cert_expiration(X509 *certificate X509_free(certificate); return result; -# else /* ifndef USE_OPENSSL */ +# else /* ifndef MOPL_USE_OPENSSL */ printf("%s\n", _("WARNING - Plugin does not support checking certificates.")); return STATE_WARNING; -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ } net_ssl_check_cert_result np_net_ssl_check_cert2(int days_till_exp_warn, int days_till_exp_crit) { -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL X509 *certificate = NULL; certificate = SSL_get_peer_certificate(s); @@ -438,27 +438,27 @@ net_ssl_check_cert_result np_net_ssl_check_cert2(int days_till_exp_warn, int day return result; -# else /* ifndef USE_OPENSSL */ +# else /* ifndef MOPL_USE_OPENSSL */ printf("%s\n", _("WARNING - Plugin does not support checking certificates.")); return STATE_WARNING; -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ } mp_state_enum np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit) { -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL X509 *certificate = NULL; certificate = SSL_get_peer_certificate(s); return (np_net_ssl_check_certificate(certificate, days_till_exp_warn, days_till_exp_crit)); -# else /* ifndef USE_OPENSSL */ +# else /* ifndef MOPL_USE_OPENSSL */ printf("%s\n", _("WARNING - Plugin does not support checking certificates.")); return STATE_WARNING; -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ } mp_subcheck mp_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit) { mp_subcheck sc_cert = mp_subcheck_init(); -# ifdef USE_OPENSSL +# ifdef MOPL_USE_OPENSSL if (!certificate) { xasprintf(&sc_cert.output, _("No server certificate present to inspect")); sc_cert = mp_set_subcheck_state(sc_cert, STATE_CRITICAL); @@ -581,10 +581,10 @@ mp_subcheck mp_net_ssl_check_certificate(X509 *certificate, int days_till_exp_wa } X509_free(certificate); return sc_cert; -# else /* ifndef USE_OPENSSL */ +# else /* ifndef MOPL_USE_OPENSSL */ xasprintf(&sc_cert.output, _("Plugin does not support checking certificates")); sc_cert = mp_set_subcheck_state(sc_cert, STATE_WARNING); return sc_cert; -# endif /* USE_OPENSSL */ +# endif /* MOPL_USE_OPENSSL */ } #endif /* HAVE_SSL */ -- cgit v1.2.3-74-g34f1 From 1db493092ca6a68ff690251cc428037b54019a73 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 8 Apr 2026 18:26:03 +0200 Subject: added CHECK_EOF to work around warnings about EOF and -1 being the same (#2254) Co-authored-by: Andreas Baumann --- plugins/check_cluster.c | 2 +- plugins/check_curl.c | 2 +- plugins/check_dig.c | 2 +- plugins/check_disk.c | 2 +- plugins/check_fping.c | 2 +- plugins/check_game.c | 2 +- plugins/check_hpjd.c | 2 +- plugins/check_ide_smart.c | 2 +- plugins/check_ldap.c | 2 +- plugins/check_load.c | 2 +- plugins/check_mysql.c | 2 +- plugins/check_nagios.c | 2 +- plugins/check_ping.c | 2 +- plugins/check_procs.c | 2 +- plugins/check_radius.c | 2 +- plugins/check_snmp.c | 4 ++-- plugins/check_tcp.c | 2 +- plugins/check_time.c | 2 +- plugins/common.h | 7 +++++++ 19 files changed, 26 insertions(+), 19 deletions(-) (limited to 'plugins/check_curl.c') diff --git a/plugins/check_cluster.c b/plugins/check_cluster.c index 1cbdcd60..92c3827a 100644 --- a/plugins/check_cluster.c +++ b/plugins/check_cluster.c @@ -175,7 +175,7 @@ check_cluster_config_wrapper process_arguments(int argc, char **argv) { while (true) { int option_index = getopt_long(argc, argv, "hHsvVw:c:d:l:", longopts, &option); - if (option_index == -1 || option_index == EOF || option_index == 1) { + if (CHECK_EOF(option_index) || option_index == 1) { break; } diff --git a/plugins/check_curl.c b/plugins/check_curl.c index fe7e61d6..67d89129 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -980,7 +980,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { int option_index = getopt_long( argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:x:b:d:e:p:s:R:r:u:f:C:J:K:DnlLS::m:M:NEB", longopts, &option); - if (option_index == -1 || option_index == EOF || option_index == 1) { + if (CHECK_EOF(option_index) || option_index == 1) { break; } diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 9ea19e6a..9ec8028a 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c @@ -284,7 +284,7 @@ check_dig_config_wrapper process_arguments(int argc, char **argv) { int option_index = getopt_long(argc, argv, "hVvt:l:H:w:c:T:p:a:A:E:X:46", longopts, &option); - if (option_index == -1 || option_index == EOF) { + if (CHECK_EOF(option_index)) { break; } diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 73fe815e..e773e56c 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -448,7 +448,7 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { int option_index = getopt_long( argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option); - if (option_index == -1 || option_index == EOF) { + if (CHECK_EOF(option_index)) { break; } diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 6160c2cb..86ef64a4 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -361,7 +361,7 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { int option_index = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option); - if (option_index == -1 || option_index == EOF || option_index == 1) { + if (CHECK_EOF(option_index) || option_index == 1) { break; } diff --git a/plugins/check_game.c b/plugins/check_game.c index 974a7253..48ec6883 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c @@ -186,7 +186,7 @@ check_game_config_wrapper process_arguments(int argc, char **argv) { while (true) { int option_index = getopt_long(argc, argv, "hVvt:H:P:G:g:p:m:", long_opts, &opt_index); - if (option_index == -1 || option_index == EOF) { + if (CHECK_EOF(option_index)) { break; } diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 9907abc5..883f1df0 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c @@ -299,7 +299,7 @@ check_hpjd_config_wrapper process_arguments(int argc, char **argv) { while (true) { int option_index = getopt_long(argc, argv, "+hVH:C:p:D", longopts, &option); - if (option_index == -1 || option_index == EOF || option_index == 1) { + if (CHECK_EOF(option_index) || option_index == 1) { break; } diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index c1325cf9..43731039 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c @@ -169,7 +169,7 @@ static check_ide_smart_config_wrapper process_arguments(int argc, char **argv) { int longindex = 0; int option_index = getopt_long(argc, argv, "+d:iq10nhVv", longopts, &longindex); - if (option_index == -1 || option_index == EOF || option_index == 1) { + if (CHECK_EOF(option_index) || option_index == 1) { break; } diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 7f8282b4..0e8c5804 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c @@ -362,7 +362,7 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) { int option_index = getopt_long(argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option); - if (option_index == -1 || option_index == EOF) { + if (CHECK_EOF(option_index)) { break; } diff --git a/plugins/check_load.c b/plugins/check_load.c index 644cd604..60fa646f 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -295,7 +295,7 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) { int option = 0; int option_index = getopt_long(argc, argv, "Vhrc:w:n:", longopts, &option); - if (option_index == -1 || option_index == EOF) { + if (CHECK_EOF(option_index)) { break; } diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 15005bf5..b70e0e22 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -504,7 +504,7 @@ check_mysql_config_wrapper process_arguments(int argc, char **argv) { int option_index = getopt_long(argc, argv, "hlvVnSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option); - if (option_index == -1 || option_index == EOF) { + if (CHECK_EOF(option_index)) { break; } diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index a46dc1ed..e2f230c9 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c @@ -227,7 +227,7 @@ check_nagios_config_wrapper process_arguments(int argc, char **argv) { while (true) { int option_index = getopt_long(argc, argv, "+hVvF:C:e:t:", longopts, &option); - if (option_index == -1 || option_index == EOF || option_index == 1) { + if (CHECK_EOF(option_index) || option_index == 1) { break; } diff --git a/plugins/check_ping.c b/plugins/check_ping.c index e1ee0f5c..0c9cb19d 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -221,7 +221,7 @@ check_ping_config_wrapper process_arguments(int argc, char **argv) { while (true) { int option_index = getopt_long(argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option); - if (option_index == -1 || option_index == EOF) { + if (CHECK_EOF(option_index)) { break; } diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 50837cb4..174dcd97 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -432,7 +432,7 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) { int option_index = getopt_long(argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:TX:", longopts, &option); - if (option_index == -1 || option_index == EOF) { + if (CHECK_EOF(option_index)) { break; } diff --git a/plugins/check_radius.c b/plugins/check_radius.c index f20af660..03153926 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c @@ -334,7 +334,7 @@ check_radius_config_wrapper process_arguments(int argc, char **argv) { int option = 0; int option_index = getopt_long(argc, argv, "+hVvH:P:F:u:p:n:N:t:r:e:", longopts, &option); - if (option_index == -1 || option_index == EOF || option_index == 1) { + if (CHECK_EOF(option_index) || option_index == 1) { break; } diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 1746fd79..0f62ce8b 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -447,7 +447,7 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) { argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:M:f:z:", longopts, &option); - if (option_char == -1 || option_char == EOF) { + if (CHECK_EOF(option_char)) { break; } @@ -517,7 +517,7 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) { argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:M:f:z:", longopts, &option); - if (option_char == -1 || option_char == EOF) { + if (CHECK_EOF(option_char)) { break; } diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index cd8e04b0..924322e4 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c @@ -562,7 +562,7 @@ static check_tcp_config_wrapper process_arguments(int argc, char **argv, check_t int option_index = getopt_long(argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:", longopts, &option); - if (option_index == -1 || option_index == EOF || option_index == 1) { + if (CHECK_EOF(option_index) || option_index == 1) { break; } diff --git a/plugins/check_time.c b/plugins/check_time.c index 99708ad3..aec995d4 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c @@ -213,7 +213,7 @@ check_time_config_wrapper process_arguments(int argc, char **argv) { int option = 0; option_char = getopt_long(argc, argv, "hVH:w:c:W:C:p:t:u", longopts, &option); - if (option_char == -1 || option_char == EOF) { + if (CHECK_EOF(option_char)) { break; } diff --git a/plugins/common.h b/plugins/common.h index b3053486..9d1434a3 100644 --- a/plugins/common.h +++ b/plugins/common.h @@ -205,4 +205,11 @@ enum { # define __attribute__(x) /* do nothing */ #endif +/* for checking the result of getopt_long */ +#if EOF == -1 +#define CHECK_EOF(c) ((c) == EOF) +#else +#define CHECK_EOF(c) ((c) == -1 || (c) == EOF) +#endif + #endif /* _COMMON_H_ */ -- cgit v1.2.3-74-g34f1