diff options
author | Anders Kaseorg <andersk@mit.edu> | 2012-06-29 00:57:48 -0400 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2012-06-29 13:39:11 +0200 |
commit | 028d50d6f99e647a325a0a68303016382c4bbdc9 (patch) | |
tree | 1d9a14635602169d137409becfa108cd6bdb371c /contrib | |
parent | 9976876584e5a1df6e1c9315212c3d274df7a12e (diff) | |
download | monitoring-plugins-028d50d6f99e647a325a0a68303016382c4bbdc9.tar.gz |
Die when asprintf fails
Fixes many instances of
warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/check_http-with-client-certificate.c | 142 |
1 files changed, 71 insertions, 71 deletions
diff --git a/contrib/check_http-with-client-certificate.c b/contrib/check_http-with-client-certificate.c index 60e14812..c47cbd4f 100644 --- a/contrib/check_http-with-client-certificate.c +++ b/contrib/check_http-with-client-certificate.c | |||
@@ -606,7 +606,7 @@ process_arguments( int argc, char **argv ) | |||
606 | *if ( !is_hostname( optarg ) ) | 606 | *if ( !is_hostname( optarg ) ) |
607 | * usage2( "invalid hostname", optarg ); | 607 | * usage2( "invalid hostname", optarg ); |
608 | */ | 608 | */ |
609 | asprintf( &server_hostname, "%s", optarg ); | 609 | xasprintf( &server_hostname, "%s", optarg ); |
610 | use_server_hostname = TRUE; | 610 | use_server_hostname = TRUE; |
611 | break; | 611 | break; |
612 | case 'F': /* File (dummy) */ | 612 | case 'F': /* File (dummy) */ |
@@ -619,7 +619,7 @@ process_arguments( int argc, char **argv ) | |||
619 | *if ( !is_host( optarg ) ) | 619 | *if ( !is_host( optarg ) ) |
620 | * usage2( "invalid ip address or hostname", optarg ) | 620 | * usage2( "invalid ip address or hostname", optarg ) |
621 | */ | 621 | */ |
622 | asprintf( &server_host, "%s", optarg ); | 622 | xasprintf( &server_host, "%s", optarg ); |
623 | break; | 623 | break; |
624 | case 'p': /* Server port */ | 624 | case 'p': /* Server port */ |
625 | if ( !is_intnonneg( optarg ) ) | 625 | if ( !is_intnonneg( optarg ) ) |
@@ -653,7 +653,7 @@ process_arguments( int argc, char **argv ) | |||
653 | break; | 653 | break; |
654 | case 'A': /* client certificate */ | 654 | case 'A': /* client certificate */ |
655 | #ifdef HAVE_SSL | 655 | #ifdef HAVE_SSL |
656 | asprintf( &client_certificate_file, "%s", optarg ); | 656 | xasprintf( &client_certificate_file, "%s", optarg ); |
657 | use_client_certificate = TRUE; | 657 | use_client_certificate = TRUE; |
658 | #else | 658 | #else |
659 | usage( "check_http: invalid option - SSL is not available\n" ); | 659 | usage( "check_http: invalid option - SSL is not available\n" ); |
@@ -661,26 +661,26 @@ process_arguments( int argc, char **argv ) | |||
661 | break; | 661 | break; |
662 | case 'K': /* client certificate passphrase */ | 662 | case 'K': /* client certificate passphrase */ |
663 | #ifdef HAVE_SSL | 663 | #ifdef HAVE_SSL |
664 | asprintf( &client_certificate_passphrase, "%s", optarg ); | 664 | xasprintf( &client_certificate_passphrase, "%s", optarg ); |
665 | use_client_certificate_passphrase = TRUE; | 665 | use_client_certificate_passphrase = TRUE; |
666 | #else | 666 | #else |
667 | usage( "check_http: invalid option - SSL is not available\n" ); | 667 | usage( "check_http: invalid option - SSL is not available\n" ); |
668 | #endif | 668 | #endif |
669 | case 'Z': /* valid CA certificates */ | 669 | case 'Z': /* valid CA certificates */ |
670 | #ifdef HAVE_SSL | 670 | #ifdef HAVE_SSL |
671 | asprintf( &ca_certificate_file, "%s", optarg ); | 671 | xasprintf( &ca_certificate_file, "%s", optarg ); |
672 | use_ca_certificate = TRUE; | 672 | use_ca_certificate = TRUE; |
673 | #else | 673 | #else |
674 | usage( "check_http: invalid option - SSL is not available\n" ); | 674 | usage( "check_http: invalid option - SSL is not available\n" ); |
675 | #endif | 675 | #endif |
676 | break; | 676 | break; |
677 | case 'u': /* URL PATH */ | 677 | case 'u': /* URL PATH */ |
678 | asprintf( &http_url_path, "%s", optarg ); | 678 | xasprintf( &http_url_path, "%s", optarg ); |
679 | break; | 679 | break; |
680 | case 'P': /* POST DATA */ | 680 | case 'P': /* POST DATA */ |
681 | asprintf( &http_post_data, "%s", optarg ); | 681 | xasprintf( &http_post_data, "%s", optarg ); |
682 | use_http_post_data = TRUE; | 682 | use_http_post_data = TRUE; |
683 | asprintf( &http_method, "%s", "POST" ); | 683 | xasprintf( &http_method, "%s", "POST" ); |
684 | break; | 684 | break; |
685 | case 'e': /* expected string in first line of HTTP response */ | 685 | case 'e': /* expected string in first line of HTTP response */ |
686 | strncpy( http_expect , optarg, MAX_INPUT_BUFFER - 1 ); | 686 | strncpy( http_expect , optarg, MAX_INPUT_BUFFER - 1 ); |
@@ -765,13 +765,13 @@ process_arguments( int argc, char **argv ) | |||
765 | * without an option | 765 | * without an option |
766 | */ | 766 | */ |
767 | if ( ( strcmp( server_host, "" ) ) && (c < argc) ) { | 767 | if ( ( strcmp( server_host, "" ) ) && (c < argc) ) { |
768 | asprintf( &server_host, "%s", argv[c++] ); | 768 | xasprintf( &server_host, "%s", argv[c++] ); |
769 | } | 769 | } |
770 | 770 | ||
771 | /* 2. check if another artument is supplied | 771 | /* 2. check if another artument is supplied |
772 | */ | 772 | */ |
773 | if ( ( strcmp( server_hostname, "" ) == 0 ) && (c < argc) ) { | 773 | if ( ( strcmp( server_hostname, "" ) == 0 ) && (c < argc) ) { |
774 | asprintf( &server_hostname, "%s", argv[c++] ); | 774 | xasprintf( &server_hostname, "%s", argv[c++] ); |
775 | } | 775 | } |
776 | 776 | ||
777 | /* 3. if host is still not defined, just copy hostname, | 777 | /* 3. if host is still not defined, just copy hostname, |
@@ -781,7 +781,7 @@ process_arguments( int argc, char **argv ) | |||
781 | if ( strcmp( server_hostname, "" ) == 0 ) { | 781 | if ( strcmp( server_hostname, "" ) == 0 ) { |
782 | usage ("check_http: you must specify a server address or host name\n"); | 782 | usage ("check_http: you must specify a server address or host name\n"); |
783 | } else { | 783 | } else { |
784 | asprintf( &server_host, "%s", server_hostname ); | 784 | xasprintf( &server_host, "%s", server_hostname ); |
785 | } | 785 | } |
786 | } | 786 | } |
787 | 787 | ||
@@ -807,9 +807,9 @@ process_arguments( int argc, char **argv ) | |||
807 | 807 | ||
808 | /* Finally set some default values if necessary */ | 808 | /* Finally set some default values if necessary */ |
809 | if ( strcmp( http_method, "" ) == 0 ) | 809 | if ( strcmp( http_method, "" ) == 0 ) |
810 | asprintf( &http_method, "%s", DEFAULT_HTTP_METHOD ); | 810 | xasprintf( &http_method, "%s", DEFAULT_HTTP_METHOD ); |
811 | if ( strcmp( http_url_path, "" ) == 0 ) { | 811 | if ( strcmp( http_url_path, "" ) == 0 ) { |
812 | asprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); | 812 | xasprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); |
813 | } | 813 | } |
814 | 814 | ||
815 | return TRUE; | 815 | return TRUE; |
@@ -829,25 +829,25 @@ http_request( int sock, struct pageref *page ) | |||
829 | size_t size = 0; | 829 | size_t size = 0; |
830 | char *basic_auth_encoded = NULL; | 830 | char *basic_auth_encoded = NULL; |
831 | 831 | ||
832 | asprintf( &buffer, HTTP_TEMPLATE_REQUEST, buffer, http_method, http_url_path ); | 832 | xasprintf( &buffer, HTTP_TEMPLATE_REQUEST, buffer, http_method, http_url_path ); |
833 | 833 | ||
834 | asprintf( &buffer, HTTP_TEMPLATE_HEADER_USERAGENT, buffer, progname, REVISION, PACKAGE_VERSION ); | 834 | xasprintf( &buffer, HTTP_TEMPLATE_HEADER_USERAGENT, buffer, progname, REVISION, PACKAGE_VERSION ); |
835 | 835 | ||
836 | if ( use_server_hostname ) { | 836 | if ( use_server_hostname ) { |
837 | asprintf( &buffer, HTTP_TEMPLATE_HEADER_HOST, buffer, server_hostname ); | 837 | xasprintf( &buffer, HTTP_TEMPLATE_HEADER_HOST, buffer, server_hostname ); |
838 | } | 838 | } |
839 | 839 | ||
840 | if ( use_basic_auth ) { | 840 | if ( use_basic_auth ) { |
841 | basic_auth_encoded = base64( basic_auth, strlen( basic_auth ) ); | 841 | basic_auth_encoded = base64( basic_auth, strlen( basic_auth ) ); |
842 | asprintf( &buffer, HTTP_TEMPLATE_HEADER_AUTH, buffer, basic_auth_encoded ); | 842 | xasprintf( &buffer, HTTP_TEMPLATE_HEADER_AUTH, buffer, basic_auth_encoded ); |
843 | } | 843 | } |
844 | 844 | ||
845 | /* either send http POST data */ | 845 | /* either send http POST data */ |
846 | if ( use_http_post_data ) { | 846 | if ( use_http_post_data ) { |
847 | /* based on code written by Chris Henesy <lurker@shadowtech.org> */ | 847 | /* based on code written by Chris Henesy <lurker@shadowtech.org> */ |
848 | asprintf( &buffer, "Content-Type: application/x-www-form-urlencoded\r\n" ); | 848 | xasprintf( &buffer, "Content-Type: application/x-www-form-urlencoded\r\n" ); |
849 | asprintf( &buffer, "Content-Length: %i\r\n\r\n", buffer, content_len ); | 849 | xasprintf( &buffer, "Content-Length: %i\r\n\r\n", buffer, content_len ); |
850 | asprintf( &buffer, "%s%s%s", buffer, http_post_data, "\r\n" ); | 850 | xasprintf( &buffer, "%s%s%s", buffer, http_post_data, "\r\n" ); |
851 | sendsize = send( sock, buffer, strlen( buffer ), 0 ); | 851 | sendsize = send( sock, buffer, strlen( buffer ), 0 ); |
852 | if ( sendsize < strlen( buffer ) ) { | 852 | if ( sendsize < strlen( buffer ) ) { |
853 | printf( "ERROR: Incomplete write\n" ); | 853 | printf( "ERROR: Incomplete write\n" ); |
@@ -855,7 +855,7 @@ http_request( int sock, struct pageref *page ) | |||
855 | } | 855 | } |
856 | /* or just a newline */ | 856 | /* or just a newline */ |
857 | } else { | 857 | } else { |
858 | asprintf( &buffer, "%s%s", buffer, "\r\n" ); | 858 | xasprintf( &buffer, "%s%s", buffer, "\r\n" ); |
859 | sendsize = send( sock, buffer, strlen( buffer ) , 0 ); | 859 | sendsize = send( sock, buffer, strlen( buffer ) , 0 ); |
860 | if ( sendsize < strlen( buffer ) ) { | 860 | if ( sendsize < strlen( buffer ) ) { |
861 | printf( "ERROR: Incomplete write\n" ); | 861 | printf( "ERROR: Incomplete write\n" ); |
@@ -870,12 +870,12 @@ http_request( int sock, struct pageref *page ) | |||
870 | recvsize = recv( sock, recvbuff, MAX_INPUT_BUFFER - 1, 0 ); | 870 | recvsize = recv( sock, recvbuff, MAX_INPUT_BUFFER - 1, 0 ); |
871 | if ( recvsize > (size_t) 0 ) { | 871 | if ( recvsize > (size_t) 0 ) { |
872 | recvbuff[recvsize] = '\0'; | 872 | recvbuff[recvsize] = '\0'; |
873 | asprintf( &content, "%s%s", content, recvbuff ); | 873 | xasprintf( &content, "%s%s", content, recvbuff ); |
874 | size += recvsize; | 874 | size += recvsize; |
875 | } | 875 | } |
876 | } while ( recvsize > (size_t) 0 ); | 876 | } while ( recvsize > (size_t) 0 ); |
877 | 877 | ||
878 | asprintf( &page->content, "%s", content ); | 878 | xasprintf( &page->content, "%s", content ); |
879 | page->size = size; | 879 | page->size = size; |
880 | 880 | ||
881 | /* return a CRITICAL status if we couldn't read any data */ | 881 | /* return a CRITICAL status if we couldn't read any data */ |
@@ -895,7 +895,7 @@ parse_http_response( struct pageref *page ) | |||
895 | size_t len = 0; //temporary used | 895 | size_t len = 0; //temporary used |
896 | char *pos = ""; //temporary used | 896 | char *pos = ""; //temporary used |
897 | 897 | ||
898 | asprintf( &content, "%s", page->content ); | 898 | xasprintf( &content, "%s", page->content ); |
899 | 899 | ||
900 | /* find status line and null-terminate it */ | 900 | /* find status line and null-terminate it */ |
901 | // copy content to status | 901 | // copy content to status |
@@ -962,7 +962,7 @@ check_http_response( struct pageref *page ) | |||
962 | 962 | ||
963 | /* check response time befor anything else */ | 963 | /* check response time befor anything else */ |
964 | if ( use_critical_interval && ( elapsed_time > critical_interval ) ) { | 964 | if ( use_critical_interval && ( elapsed_time > critical_interval ) ) { |
965 | asprintf( &msg, RESULT_TEMPLATE_RESPONSE_TIME, | 965 | xasprintf( &msg, RESULT_TEMPLATE_RESPONSE_TIME, |
966 | protocol_text( use_ssl ), | 966 | protocol_text( use_ssl ), |
967 | state_text( STATE_CRITICAL ), | 967 | state_text( STATE_CRITICAL ), |
968 | elapsed_time, | 968 | elapsed_time, |
@@ -970,7 +970,7 @@ check_http_response( struct pageref *page ) | |||
970 | terminate( STATE_CRITICAL, msg ); | 970 | terminate( STATE_CRITICAL, msg ); |
971 | } | 971 | } |
972 | if ( use_warning_interval && ( elapsed_time > warning_interval ) ) { | 972 | if ( use_warning_interval && ( elapsed_time > warning_interval ) ) { |
973 | asprintf( &msg, RESULT_TEMPLATE_RESPONSE_TIME, | 973 | xasprintf( &msg, RESULT_TEMPLATE_RESPONSE_TIME, |
974 | protocol_text( use_ssl ), | 974 | protocol_text( use_ssl ), |
975 | state_text( STATE_WARNING ), | 975 | state_text( STATE_WARNING ), |
976 | elapsed_time, | 976 | elapsed_time, |
@@ -990,9 +990,9 @@ check_http_response( struct pageref *page ) | |||
990 | #else | 990 | #else |
991 | ) | 991 | ) |
992 | #endif | 992 | #endif |
993 | asprintf( &msg, "Expected HTTP response received from host\n" ); | 993 | xasprintf( &msg, "Expected HTTP response received from host\n" ); |
994 | else | 994 | else |
995 | asprintf( &msg, "Expected HTTP response received from host on port %d\n", server_port ); | 995 | xasprintf( &msg, "Expected HTTP response received from host on port %d\n", server_port ); |
996 | terminate( STATE_OK, msg ); | 996 | terminate( STATE_OK, msg ); |
997 | } | 997 | } |
998 | } else { | 998 | } else { |
@@ -1002,9 +1002,9 @@ check_http_response( struct pageref *page ) | |||
1002 | #else | 1002 | #else |
1003 | ) | 1003 | ) |
1004 | #endif | 1004 | #endif |
1005 | asprintf( &msg, "Invalid HTTP response received from host\n" ); | 1005 | xasprintf( &msg, "Invalid HTTP response received from host\n" ); |
1006 | else | 1006 | else |
1007 | asprintf( &msg, "Invalid HTTP response received from host on port %d\n", server_port ); | 1007 | xasprintf( &msg, "Invalid HTTP response received from host on port %d\n", server_port ); |
1008 | terminate( STATE_CRITICAL, msg ); | 1008 | terminate( STATE_CRITICAL, msg ); |
1009 | } | 1009 | } |
1010 | 1010 | ||
@@ -1016,7 +1016,7 @@ check_http_response( struct pageref *page ) | |||
1016 | strstr( page->status, "503" ) || | 1016 | strstr( page->status, "503" ) || |
1017 | strstr( page->status, "504" ) || | 1017 | strstr( page->status, "504" ) || |
1018 | strstr( page->status, "505" )) { | 1018 | strstr( page->status, "505" )) { |
1019 | asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, | 1019 | xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, |
1020 | protocol_text( use_ssl ), | 1020 | protocol_text( use_ssl ), |
1021 | state_text( http_client_error_state ), | 1021 | state_text( http_client_error_state ), |
1022 | page->status, | 1022 | page->status, |
@@ -1044,7 +1044,7 @@ check_http_response( struct pageref *page ) | |||
1044 | strstr( page->status, "415" ) || | 1044 | strstr( page->status, "415" ) || |
1045 | strstr( page->status, "416" ) || | 1045 | strstr( page->status, "416" ) || |
1046 | strstr( page->status, "417" ) ) { | 1046 | strstr( page->status, "417" ) ) { |
1047 | asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, | 1047 | xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, |
1048 | protocol_text( use_ssl ), | 1048 | protocol_text( use_ssl ), |
1049 | state_text( http_client_error_state ), | 1049 | state_text( http_client_error_state ), |
1050 | page->status, | 1050 | page->status, |
@@ -1066,7 +1066,7 @@ check_http_response( struct pageref *page ) | |||
1066 | /* returning STATE_DEPENDENT means follow redirect */ | 1066 | /* returning STATE_DEPENDENT means follow redirect */ |
1067 | return STATE_DEPENDENT; | 1067 | return STATE_DEPENDENT; |
1068 | } else { | 1068 | } else { |
1069 | asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, | 1069 | xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, |
1070 | protocol_text( use_ssl ), | 1070 | protocol_text( use_ssl ), |
1071 | state_text( http_redirect_state ), | 1071 | state_text( http_redirect_state ), |
1072 | page->status, | 1072 | page->status, |
@@ -1087,7 +1087,7 @@ check_http_content( struct pageref *page ) | |||
1087 | /* check for string in content */ | 1087 | /* check for string in content */ |
1088 | if ( check_content_string ) { | 1088 | if ( check_content_string ) { |
1089 | if ( strstr( page->content, content_string ) ) { | 1089 | if ( strstr( page->content, content_string ) ) { |
1090 | asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, | 1090 | xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, |
1091 | protocol_text( use_ssl ), | 1091 | protocol_text( use_ssl ), |
1092 | state_text( STATE_OK ), | 1092 | state_text( STATE_OK ), |
1093 | page->status, | 1093 | page->status, |
@@ -1095,7 +1095,7 @@ check_http_content( struct pageref *page ) | |||
1095 | elapsed_time ); | 1095 | elapsed_time ); |
1096 | terminate( STATE_OK, msg ); | 1096 | terminate( STATE_OK, msg ); |
1097 | } else { | 1097 | } else { |
1098 | asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, | 1098 | xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, |
1099 | protocol_text( use_ssl ), | 1099 | protocol_text( use_ssl ), |
1100 | state_text( STATE_CRITICAL ), | 1100 | state_text( STATE_CRITICAL ), |
1101 | page->status, | 1101 | page->status, |
@@ -1110,7 +1110,7 @@ check_http_content( struct pageref *page ) | |||
1110 | if ( check_content_regex ) { | 1110 | if ( check_content_regex ) { |
1111 | regex_error = regexec( ®ex_preg, page->content, REGEX_REGS, regex_pmatch, 0); | 1111 | regex_error = regexec( ®ex_preg, page->content, REGEX_REGS, regex_pmatch, 0); |
1112 | if ( regex_error == 0 ) { | 1112 | if ( regex_error == 0 ) { |
1113 | asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, | 1113 | xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, |
1114 | protocol_text( use_ssl ), | 1114 | protocol_text( use_ssl ), |
1115 | state_text( STATE_OK ), | 1115 | state_text( STATE_OK ), |
1116 | page->status, | 1116 | page->status, |
@@ -1119,13 +1119,13 @@ check_http_content( struct pageref *page ) | |||
1119 | terminate( STATE_OK, msg ); | 1119 | terminate( STATE_OK, msg ); |
1120 | } else { | 1120 | } else { |
1121 | if ( regex_error == REG_NOMATCH ) { | 1121 | if ( regex_error == REG_NOMATCH ) { |
1122 | asprintf( &msg, "%s, %s: regex pattern not found\n", | 1122 | xasprintf( &msg, "%s, %s: regex pattern not found\n", |
1123 | protocol_text( use_ssl) , | 1123 | protocol_text( use_ssl) , |
1124 | state_text( STATE_CRITICAL ) ); | 1124 | state_text( STATE_CRITICAL ) ); |
1125 | terminate( STATE_CRITICAL, msg ); | 1125 | terminate( STATE_CRITICAL, msg ); |
1126 | } else { | 1126 | } else { |
1127 | regerror( regex_error, ®ex_preg, regex_error_buffer, MAX_INPUT_BUFFER); | 1127 | regerror( regex_error, ®ex_preg, regex_error_buffer, MAX_INPUT_BUFFER); |
1128 | asprintf( &msg, "%s %s: Regex execute Error: %s\n", | 1128 | xasprintf( &msg, "%s %s: Regex execute Error: %s\n", |
1129 | protocol_text( use_ssl) , | 1129 | protocol_text( use_ssl) , |
1130 | state_text( STATE_CRITICAL ), | 1130 | state_text( STATE_CRITICAL ), |
1131 | regex_error_buffer ); | 1131 | regex_error_buffer ); |
@@ -1152,16 +1152,16 @@ prepare_follow_redirect( struct pageref *page ) | |||
1152 | char *orig_url_dirname = NULL; | 1152 | char *orig_url_dirname = NULL; |
1153 | size_t len = 0; | 1153 | size_t len = 0; |
1154 | 1154 | ||
1155 | asprintf( &header, "%s", page->header ); | 1155 | xasprintf( &header, "%s", page->header ); |
1156 | 1156 | ||
1157 | 1157 | ||
1158 | /* restore some default values */ | 1158 | /* restore some default values */ |
1159 | use_http_post_data = FALSE; | 1159 | use_http_post_data = FALSE; |
1160 | asprintf( &http_method, "%s", DEFAULT_HTTP_METHOD ); | 1160 | xasprintf( &http_method, "%s", DEFAULT_HTTP_METHOD ); |
1161 | 1161 | ||
1162 | /* copy url of original request, maybe we need it to compose | 1162 | /* copy url of original request, maybe we need it to compose |
1163 | absolute url from relative Location: header */ | 1163 | absolute url from relative Location: header */ |
1164 | asprintf( &orig_url_path, "%s", http_url_path ); | 1164 | xasprintf( &orig_url_path, "%s", http_url_path ); |
1165 | 1165 | ||
1166 | while ( strcspn( header, "\r\n" ) > (size_t) 0 ) { | 1166 | while ( strcspn( header, "\r\n" ) > (size_t) 0 ) { |
1167 | url_path = realloc( url_path, (size_t) strcspn( header, "\r\n" ) ); | 1167 | url_path = realloc( url_path, (size_t) strcspn( header, "\r\n" ) ); |
@@ -1172,43 +1172,43 @@ prepare_follow_redirect( struct pageref *page ) | |||
1172 | /* Try to find a Location header combination of METHOD HOSTNAME PORT and PATH */ | 1172 | /* Try to find a Location header combination of METHOD HOSTNAME PORT and PATH */ |
1173 | /* 1. scan for Location: http[s]://hostname:port/path */ | 1173 | /* 1. scan for Location: http[s]://hostname:port/path */ |
1174 | if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_PORT_MATCH HTTP_HEADER_URL_PATH_MATCH, &protocol, &hostname, &port, url_path ) == 4 ) { | 1174 | if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_PORT_MATCH HTTP_HEADER_URL_PATH_MATCH, &protocol, &hostname, &port, url_path ) == 4 ) { |
1175 | asprintf( &server_hostname, "%s", hostname ); | 1175 | xasprintf( &server_hostname, "%s", hostname ); |
1176 | asprintf( &server_host, "%s", hostname ); | 1176 | xasprintf( &server_host, "%s", hostname ); |
1177 | use_ssl = chk_protocol(protocol); | 1177 | use_ssl = chk_protocol(protocol); |
1178 | server_port = atoi( port ); | 1178 | server_port = atoi( port ); |
1179 | asprintf( &http_url_path, "%s", url_path ); | 1179 | xasprintf( &http_url_path, "%s", url_path ); |
1180 | return STATE_DEPENDENT; | 1180 | return STATE_DEPENDENT; |
1181 | } | 1181 | } |
1182 | else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_URL_PATH_MATCH, &protocol, &hostname, url_path ) == 3) { | 1182 | else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_URL_PATH_MATCH, &protocol, &hostname, url_path ) == 3) { |
1183 | asprintf( &server_hostname, "%s", hostname ); | 1183 | xasprintf( &server_hostname, "%s", hostname ); |
1184 | asprintf( &server_host, "%s", hostname ); | 1184 | xasprintf( &server_host, "%s", hostname ); |
1185 | use_ssl = chk_protocol(protocol); | 1185 | use_ssl = chk_protocol(protocol); |
1186 | server_port = protocol_std_port(use_ssl); | 1186 | server_port = protocol_std_port(use_ssl); |
1187 | asprintf( &http_url_path, "%s", url_path ); | 1187 | xasprintf( &http_url_path, "%s", url_path ); |
1188 | return STATE_DEPENDENT; | 1188 | return STATE_DEPENDENT; |
1189 | } | 1189 | } |
1190 | else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_PORT_MATCH, &protocol, &hostname, &port ) == 3) { | 1190 | else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_PORT_MATCH, &protocol, &hostname, &port ) == 3) { |
1191 | asprintf( &server_hostname, "%s", hostname ); | 1191 | xasprintf( &server_hostname, "%s", hostname ); |
1192 | asprintf( &server_host, "%s", hostname ); | 1192 | xasprintf( &server_host, "%s", hostname ); |
1193 | use_ssl = chk_protocol(protocol); | 1193 | use_ssl = chk_protocol(protocol); |
1194 | server_port = atoi( port ); | 1194 | server_port = atoi( port ); |
1195 | asprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); | 1195 | xasprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); |
1196 | return STATE_DEPENDENT; | 1196 | return STATE_DEPENDENT; |
1197 | } | 1197 | } |
1198 | else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH, protocol, hostname ) == 2 ) { | 1198 | else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH, protocol, hostname ) == 2 ) { |
1199 | asprintf( &server_hostname, "%s", hostname ); | 1199 | xasprintf( &server_hostname, "%s", hostname ); |
1200 | asprintf( &server_host, "%s", hostname ); | 1200 | xasprintf( &server_host, "%s", hostname ); |
1201 | use_ssl = chk_protocol(protocol); | 1201 | use_ssl = chk_protocol(protocol); |
1202 | server_port = protocol_std_port(use_ssl); | 1202 | server_port = protocol_std_port(use_ssl); |
1203 | asprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); | 1203 | xasprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); |
1204 | } | 1204 | } |
1205 | else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_URL_PATH_MATCH, url_path ) == 1 ) { | 1205 | else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_URL_PATH_MATCH, url_path ) == 1 ) { |
1206 | /* check for relative url and prepend path if necessary */ | 1206 | /* check for relative url and prepend path if necessary */ |
1207 | if ( ( url_path[0] != '/' ) && ( orig_url_dirname = strrchr( orig_url_path, '/' ) ) ) { | 1207 | if ( ( url_path[0] != '/' ) && ( orig_url_dirname = strrchr( orig_url_path, '/' ) ) ) { |
1208 | *orig_url_dirname = '\0'; | 1208 | *orig_url_dirname = '\0'; |
1209 | asprintf( &http_url_path, "%s%s", orig_url_path, url_path ); | 1209 | xasprintf( &http_url_path, "%s%s", orig_url_path, url_path ); |
1210 | } else { | 1210 | } else { |
1211 | asprintf( &http_url_path, "%s", url_path ); | 1211 | xasprintf( &http_url_path, "%s", url_path ); |
1212 | } | 1212 | } |
1213 | return STATE_DEPENDENT; | 1213 | return STATE_DEPENDENT; |
1214 | } | 1214 | } |
@@ -1218,7 +1218,7 @@ prepare_follow_redirect( struct pageref *page ) | |||
1218 | 1218 | ||
1219 | 1219 | ||
1220 | /* default return value is STATE_DEPENDENT to continue looping in main() */ | 1220 | /* default return value is STATE_DEPENDENT to continue looping in main() */ |
1221 | asprintf( &msg, "% %: % - Could not find redirect Location", | 1221 | xasprintf( &msg, "% %: % - Could not find redirect Location", |
1222 | protocol_text( use_ssl ), | 1222 | protocol_text( use_ssl ), |
1223 | state_text( STATE_UNKNOWN ), | 1223 | state_text( STATE_UNKNOWN ), |
1224 | page->status ); | 1224 | page->status ); |
@@ -1239,24 +1239,24 @@ https_request( SSL_CTX *ctx, SSL *ssl, struct pageref *page ) | |||
1239 | size_t size = 0; | 1239 | size_t size = 0; |
1240 | char *basic_auth_encoded = NULL; | 1240 | char *basic_auth_encoded = NULL; |
1241 | 1241 | ||
1242 | asprintf( &buffer, HTTP_TEMPLATE_REQUEST, buffer, http_method, http_url_path ); | 1242 | xasprintf( &buffer, HTTP_TEMPLATE_REQUEST, buffer, http_method, http_url_path ); |
1243 | 1243 | ||
1244 | asprintf( &buffer, HTTP_TEMPLATE_HEADER_USERAGENT, buffer, progname, REVISION, PACKAGE_VERSION ); | 1244 | xasprintf( &buffer, HTTP_TEMPLATE_HEADER_USERAGENT, buffer, progname, REVISION, PACKAGE_VERSION ); |
1245 | 1245 | ||
1246 | if ( use_server_hostname ) { | 1246 | if ( use_server_hostname ) { |
1247 | asprintf( &buffer, HTTP_TEMPLATE_HEADER_HOST, buffer, server_hostname ); | 1247 | xasprintf( &buffer, HTTP_TEMPLATE_HEADER_HOST, buffer, server_hostname ); |
1248 | } | 1248 | } |
1249 | 1249 | ||
1250 | if ( use_basic_auth ) { | 1250 | if ( use_basic_auth ) { |
1251 | basic_auth_encoded = base64( basic_auth, strlen( basic_auth ) ); | 1251 | basic_auth_encoded = base64( basic_auth, strlen( basic_auth ) ); |
1252 | asprintf( &buffer, HTTP_TEMPLATE_HEADER_AUTH, buffer, basic_auth_encoded ); | 1252 | xasprintf( &buffer, HTTP_TEMPLATE_HEADER_AUTH, buffer, basic_auth_encoded ); |
1253 | } | 1253 | } |
1254 | 1254 | ||
1255 | /* either send http POST data */ | 1255 | /* either send http POST data */ |
1256 | if ( use_http_post_data ) { | 1256 | if ( use_http_post_data ) { |
1257 | asprintf( &buffer, "%sContent-Type: application/x-www-form-urlencoded\r\n", buffer ); | 1257 | xasprintf( &buffer, "%sContent-Type: application/x-www-form-urlencoded\r\n", buffer ); |
1258 | asprintf( &buffer, "%sContent-Length: %i\r\n\r\n", buffer, content_len ); | 1258 | xasprintf( &buffer, "%sContent-Length: %i\r\n\r\n", buffer, content_len ); |
1259 | asprintf( &buffer, "%s%s%s", buffer, http_post_data, "\r\n" ); | 1259 | xasprintf( &buffer, "%s%s%s", buffer, http_post_data, "\r\n" ); |
1260 | sendsize = SSL_write( ssl, buffer, strlen( buffer ) ); | 1260 | sendsize = SSL_write( ssl, buffer, strlen( buffer ) ); |
1261 | switch ( SSL_get_error( ssl, sendsize ) ) { | 1261 | switch ( SSL_get_error( ssl, sendsize ) ) { |
1262 | case SSL_ERROR_NONE: | 1262 | case SSL_ERROR_NONE: |
@@ -1270,7 +1270,7 @@ https_request( SSL_CTX *ctx, SSL *ssl, struct pageref *page ) | |||
1270 | /* or just a newline */ | 1270 | /* or just a newline */ |
1271 | } else { | 1271 | } else { |
1272 | 1272 | ||
1273 | asprintf( &buffer, "%s\r\n", buffer ); | 1273 | xasprintf( &buffer, "%s\r\n", buffer ); |
1274 | sendsize = SSL_write( ssl, buffer, strlen( buffer ) ); | 1274 | sendsize = SSL_write( ssl, buffer, strlen( buffer ) ); |
1275 | switch ( SSL_get_error( ssl, sendsize ) ) { | 1275 | switch ( SSL_get_error( ssl, sendsize ) ) { |
1276 | case SSL_ERROR_NONE: | 1276 | case SSL_ERROR_NONE: |
@@ -1293,7 +1293,7 @@ https_request( SSL_CTX *ctx, SSL *ssl, struct pageref *page ) | |||
1293 | case SSL_ERROR_NONE: | 1293 | case SSL_ERROR_NONE: |
1294 | if ( recvsize > (size_t) 0 ) { | 1294 | if ( recvsize > (size_t) 0 ) { |
1295 | recvbuff[recvsize] = '\0'; | 1295 | recvbuff[recvsize] = '\0'; |
1296 | asprintf( &content, "%s%s", content, recvbuff ); | 1296 | xasprintf( &content, "%s%s", content, recvbuff ); |
1297 | size += recvsize; | 1297 | size += recvsize; |
1298 | } | 1298 | } |
1299 | break; | 1299 | break; |
@@ -1317,7 +1317,7 @@ https_request( SSL_CTX *ctx, SSL *ssl, struct pageref *page ) | |||
1317 | } | 1317 | } |
1318 | } while ( recvsize > (size_t) 0 ); | 1318 | } while ( recvsize > (size_t) 0 ); |
1319 | 1319 | ||
1320 | asprintf( &page->content, "%s", content ); | 1320 | xasprintf( &page->content, "%s", content ); |
1321 | page->size = size; | 1321 | page->size = size; |
1322 | 1322 | ||
1323 | /* return a CRITICAL status if we couldn't read any data */ | 1323 | /* return a CRITICAL status if we couldn't read any data */ |
@@ -1446,7 +1446,7 @@ check_server_certificate_hostname( ) | |||
1446 | char *msg = NULL; | 1446 | char *msg = NULL; |
1447 | X509_NAME_get_text_by_NID( X509_get_subject_name( server_certificate ), NID_commonName, server_CN, 256 ); | 1447 | X509_NAME_get_text_by_NID( X509_get_subject_name( server_certificate ), NID_commonName, server_CN, 256 ); |
1448 | if ( strcasecmp( server_CN, server_hostname ) ) { | 1448 | if ( strcasecmp( server_CN, server_hostname ) ) { |
1449 | asprintf( &msg, "SSL ERROR: Server Certificate does not match Hostname %s.\n", server_hostname ); | 1449 | xasprintf( &msg, "SSL ERROR: Server Certificate does not match Hostname %s.\n", server_hostname ); |
1450 | ssl_terminate( STATE_WARNING, msg ); | 1450 | ssl_terminate( STATE_WARNING, msg ); |
1451 | } | 1451 | } |
1452 | 1452 | ||
@@ -1507,20 +1507,20 @@ check_server_certificate_expires( ) | |||
1507 | stamp.tm_hour, stamp.tm_min ); | 1507 | stamp.tm_hour, stamp.tm_min ); |
1508 | 1508 | ||
1509 | if ( ( days_left > 0 ) && ( days_left <= server_certificate_min_days_valid ) ) { | 1509 | if ( ( days_left > 0 ) && ( days_left <= server_certificate_min_days_valid ) ) { |
1510 | asprintf( &msg, "Certificate expires in %d day(s) (%s).\n", days_left, timestamp ); | 1510 | xasprintf( &msg, "Certificate expires in %d day(s) (%s).\n", days_left, timestamp ); |
1511 | ssl_terminate( STATE_WARNING, msg ); | 1511 | ssl_terminate( STATE_WARNING, msg ); |
1512 | } | 1512 | } |
1513 | if ( days_left < 0 ) { | 1513 | if ( days_left < 0 ) { |
1514 | asprintf( &msg, "Certificate expired on %s.\n", timestamp ); | 1514 | xasprintf( &msg, "Certificate expired on %s.\n", timestamp ); |
1515 | ssl_terminate( STATE_CRITICAL, msg ); | 1515 | ssl_terminate( STATE_CRITICAL, msg ); |
1516 | } | 1516 | } |
1517 | 1517 | ||
1518 | if (days_left == 0) { | 1518 | if (days_left == 0) { |
1519 | asprintf( &msg, "Certificate expires today (%s).\n", timestamp ); | 1519 | xasprintf( &msg, "Certificate expires today (%s).\n", timestamp ); |
1520 | ssl_terminate( STATE_WARNING, msg ); | 1520 | ssl_terminate( STATE_WARNING, msg ); |
1521 | } | 1521 | } |
1522 | 1522 | ||
1523 | asprintf( &msg, "Certificate will expire on %s.\n", timestamp ); | 1523 | xasprintf( &msg, "Certificate will expire on %s.\n", timestamp ); |
1524 | ssl_terminate( STATE_OK, msg ); | 1524 | ssl_terminate( STATE_OK, msg ); |
1525 | } | 1525 | } |
1526 | #endif | 1526 | #endif |