From b6654c8d5114ed5eb3d4532d50502bd40814969e Mon Sep 17 00:00:00 2001 From: Nick Gregory Date: Mon, 23 Dec 2013 11:51:01 +0000 Subject: add digest support --- src/check_curl.c | 4 ++++ src/cmdline.c | 21 +++++++++++++++++++-- src/cmdline.h | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/check_curl.c b/src/check_curl.c index 7222b01..620c089 100644 --- a/src/check_curl.c +++ b/src/check_curl.c @@ -124,6 +124,10 @@ int main( int argc, char *argv[] ) { if( args_info.authorization_given ) curl_easy_setopt( curl, CURLOPT_USERPWD, args_info.authorization_arg ); + /* -d: digest */ + if( args_info.digest_given ) + curl_easy_setopt( curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST ); + /* user agent */ if( args_info.useragent_given ) curl_easy_setopt( curl, CURLOPT_USERAGENT, args_info.useragent_arg ); diff --git a/src/cmdline.c b/src/cmdline.c index 2c4734f..6b7f0c8 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -55,6 +55,7 @@ const char *gengetopt_args_info_help[] = { " -E, --cert=file Client certificate file and password (SSL)", " --key=key Private key file name (SSL)", " --protocol=protocol The protocol to use (http, ftp) (possible\n values=\"http\", \"ftp\" default=`http')", + " -d, --digest Use digest auth on http authentication", 0 }; @@ -131,6 +132,7 @@ void clear_given (struct gengetopt_args_info *args_info) args_info->cert_given = 0 ; args_info->key_given = 0 ; args_info->protocol_given = 0 ; + args_info->digest_given = 0 ; } static @@ -165,7 +167,6 @@ void clear_args (struct gengetopt_args_info *args_info) args_info->key_orig = NULL; args_info->protocol_arg = gengetopt_strdup ("http"); args_info->protocol_orig = NULL; - } static @@ -197,6 +198,7 @@ void init_args_info(struct gengetopt_args_info *args_info) args_info->cert_help = gengetopt_args_info_help[19] ; args_info->key_help = gengetopt_args_info_help[20] ; args_info->protocol_help = gengetopt_args_info_help[21] ; + args_info->digest_help = gengetopt_args_info_help[22] ; } @@ -438,6 +440,8 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) write_into_file(outfile, "key", args_info->key_orig, 0); if (args_info->protocol_given) write_into_file(outfile, "protocol", args_info->protocol_orig, cmdline_parser_protocol_values); + if (args_info->digest_given) + write_into_file(outfile, "digest", 0, 0 ); i = EXIT_SUCCESS; @@ -1408,6 +1412,7 @@ cmdline_parser_internal ( { "cert", 1, NULL, 'E' }, { "key", 1, NULL, 0 }, { "protocol", 1, NULL, 0 }, + { "digest", 0, NULL, 'd' }, { 0, 0, 0, 0 } }; @@ -1416,7 +1421,7 @@ cmdline_parser_internal ( custom_opterr = opterr; custom_optopt = optopt; - c = custom_getopt_long (argc, argv, "hVvt:c:w:H:I:p:u:f:a:s:SA:E:", long_options, &option_index); + c = custom_getopt_long (argc, argv, "hVvt:c:w:H:I:p:u:f:a:s:SA:E:d", long_options, &option_index); optarg = custom_optarg; optind = custom_optind; @@ -1573,6 +1578,18 @@ cmdline_parser_internal ( additional_error)) goto failure; + break; + case 'd': /* Connect via SSL. Port defaults to 443. */ + + + if (update_arg( 0 , + 0 , &(args_info->digest_given), + &(local_args_info.digest_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "digest", 'd', + additional_error)) + goto failure; + break; case 'A': /* String to be sent in http header as \"User Agent\". */ diff --git a/src/cmdline.h b/src/cmdline.h index d1d63cd..811aec2 100644 --- a/src/cmdline.h +++ b/src/cmdline.h @@ -93,6 +93,7 @@ struct gengetopt_args_info char * protocol_arg; /**< @brief The protocol to use (http, ftp) (default='http'). */ char * protocol_orig; /**< @brief The protocol to use (http, ftp) original value given at command line. */ const char *protocol_help; /**< @brief The protocol to use (http, ftp) help description. */ + const char *digest_help; /**< @brief The protocol to use (http, ftp) help description. */ unsigned int help_given ; /**< @brief Whether help was given. */ unsigned int version_given ; /**< @brief Whether version was given. */ @@ -116,6 +117,7 @@ struct gengetopt_args_info unsigned int cert_given ; /**< @brief Whether cert was given. */ unsigned int key_given ; /**< @brief Whether key was given. */ unsigned int protocol_given ; /**< @brief Whether protocol was given. */ + unsigned int digest_given ; /**< @brief Whether to use digest auth. */ char **inputs ; /**< @brief unamed options (options without names) */ unsigned inputs_num ; /**< @brief unamed options number */ -- cgit v1.2.3-54-g00ecf