Fixed warning on amd64.
[cert-checker.git] / main.c
diff --git a/main.c b/main.c
index 68f50e57704947d593dc3c8fc4574475d09a9a2b..9598d2ecb3b6411ff5c284626e64e8e7b5776d2d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -34,6 +34,7 @@
 
 int warning_after = 30;
 int error_after = 7;
+int verbose = 0;
 
 #define LOG_LEVEL 0
 
@@ -104,7 +105,7 @@ int check( char * hostname, char *service ) {
 
        /* Connect to server */
 
-       int fd = tcp_open( hostname, service );
+       long fd = tcp_open( hostname, service );
        
        if (fd == -1) {
                state= S_UNREACHABLE;
@@ -140,18 +141,23 @@ int check( char * hostname, char *service ) {
                gnutls_x509_crt_import( cert, &cert_list[0], GNUTLS_X509_FMT_DER );
                expiration_time = gnutls_x509_crt_get_expiration_time( cert );
                int expires_in = (expiration_time - today) / 86400;
+               struct tm * t = gmtime( &expiration_time );
                if ((state == S_OK) && (expires_in <= warning_after)) {
                        state = S_WARNING;
-                       sprintf(errmsg, "Certificate will expire in %i days.", expires_in);
+                       sprintf(errmsg, "Warning - Will expire in %i days (%i-%02i-%02i).", expires_in, 
+                               t->tm_year+1900, t->tm_mon+1, t->tm_mday );
                }
                if ((state <= S_WARNING) && (expires_in <= error_after)) {
                        state = S_ERROR;
-                       sprintf(errmsg, "Certificate will expire in %i days.", expires_in);
+                       sprintf(errmsg, "Critical - Will expire in %i days (%i-%02i-%02i).", expires_in,
+                               t->tm_year+1900, t->tm_mon+1, t->tm_mday );
+               }
+               if (state == S_OK) {
+                       sprintf(errmsg, "OK - Will expire in %i days (%i-%02i-%02i).", expires_in,
+                               t->tm_year+1900, t->tm_mon+1, t->tm_mday );
                }
        }
 
-       printf("Got %i certs.", cert_list_size);
-
        /* Clean up */
        err = gnutls_bye( session, GNUTLS_SHUT_WR );
        if (err < 0) gnutls_die(err);
@@ -200,6 +206,8 @@ int main(int argc, char **argv) {
                        case 'h':
                                print_help();
                                exit(0);
+                       case 'v':
+                               verbose++;
                        default: break;
                }
        }
@@ -242,5 +250,12 @@ int main(int argc, char **argv) {
 }
 
 void print_help() {
-       printf("Help yourself.");
+       printf(
+               "Usage: cert-checker [options] -H hostname -p|s port|service\n"
+               "  Where options could be: \n"
+               "       -h      this help\n"
+               "       -w      warning level (in days, default 30)\n"
+               "       -c      critical level (in days, default 7)\n"
+               "       -v      verbosity level\n"      
+       );
 }