diff options
author | M. Sean Finney <seanius@users.sourceforge.net> | 2005-10-19 12:59:55 +0000 |
---|---|---|
committer | M. Sean Finney <seanius@users.sourceforge.net> | 2005-10-19 12:59:55 +0000 |
commit | 65282c7685ca01c57d94d3df93c2f95d5b945e57 (patch) | |
tree | eb1d0c95752126bd526d939332d14bf40cf7d1f7 /plugins/netutils.c | |
parent | 8611341fb989382545c0c934c700e027d9bbab15 (diff) | |
download | monitoring-plugins-65282c7685ca01c57d94d3df93c2f95d5b945e57.tar.gz |
- initial attempt at consolidating ssl-related code into netutils.{c,h}
- added some #ifdefs to common.h and netutils.h to prevent multiple
inclusions (as netlibs now includes common.h)
- all ssl plugins (tcp/http/smtp) compile cleanly against gnutls, though
certificate checking still needs to be done.
- modified configure script so you can also explicitly say "without-gnutls"
too (otherwise if you disable openssl you have no way of disabling
gnutls too)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1255 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r-- | plugins/netutils.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c index 9539a7f0..e3fbb3aa 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c @@ -234,6 +234,54 @@ np_net_connect (const char *host_name, int port, int *sd, int proto) } } +#ifdef HAVE_SSL +static SSL_CTX *c=NULL; +static SSL *s=NULL; + +int np_net_ssl_init (int sd){ + SSL_METHOD *m=NULL; + /* Initialize SSL context */ + SSLeay_add_ssl_algorithms (); + m = SSLv23_client_method (); + SSL_load_error_strings (); + OpenSSL_add_all_algorithms(); + if ((c = SSL_CTX_new (m)) == NULL) { + printf (_("CRITICAL - Cannot create SSL context.\n")); + return STATE_CRITICAL; + } + if ((s = SSL_new (c)) != NULL){ + SSL_set_fd (s, sd); + if (SSL_connect(s) == 1){ + return OK; + } else { + printf (_("CRITICAL - Cannot make SSL connection ")); +#ifdef USE_OPENSSL /* XXX look into ERR_error_string */ + ERR_print_errors_fp (stdout); +#endif /* USE_OPENSSL */ + } + } else { + printf (_("CRITICAL - Cannot initiate SSL handshake.\n")); + } + return STATE_CRITICAL; +} + +void np_net_ssl_cleanup (){ + if(s){ + SSL_shutdown (s); + SSL_free (s); + if(c) SSL_CTX_free (c); + } +} + +int np_net_ssl_write(const void *buf, int num){ + return SSL_write(s, buf, num); +} + +int np_net_ssl_read(void *buf, int num){ + return SSL_read(s, buf, num); +} + +#endif /* HAVE_SSL */ int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size) |