X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Fmemstat.cc;h=ae6a356584c35007b5c07c5c3febfac4318c3beb;hb=03d1a2a58d61fc30135f49032ab95c6785aa4ec6;hp=1eab6f9f30623b52d503c6ecbafdc2f005104780;hpb=999006a8904a0f08293f1df7bda81bff914b091a;p=m6w6%2Flibmemcached diff --git a/clients/memstat.cc b/clients/memstat.cc index 1eab6f9f..ae6a3565 100644 --- a/clients/memstat.cc +++ b/clients/memstat.cc @@ -1,4 +1,5 @@ /* LibMemcached + * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ * Copyright (C) 2006-2009 Brian Aker * All rights reserved. * @@ -11,7 +12,7 @@ * Brian Aker * Toru Maesaka */ -#include +#include #include #include @@ -25,7 +26,7 @@ #include #include -#include +#include #include "client_options.h" #include "utilities.h" @@ -46,6 +47,8 @@ static bool opt_analyze= false; static char *opt_servers= NULL; static char *stat_args= NULL; static char *analyze_mode= NULL; +static char *opt_username; +static char *opt_passwd; static struct option long_options[]= { @@ -59,6 +62,8 @@ static struct option long_options[]= {(OPTIONSTRING)"server-version", no_argument, NULL, OPT_SERVER_VERSION}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, {(OPTIONSTRING)"analyze", optional_argument, NULL, OPT_ANALYZE}, + {(OPTIONSTRING)"username", required_argument, NULL, OPT_USERNAME}, + {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD}, {0, 0, 0, 0}, }; @@ -123,6 +128,24 @@ int main(int argc, char *argv[]) memcached_return_t rc= memcached_server_push(memc, servers); memcached_server_list_free(servers); + if (opt_username and LIBMEMCACHED_WITH_SASL_SUPPORT == 0) + { + memcached_free(memc); + std::cerr << "--username was supplied, but binary was not built with SASL support." << std::endl; + return EXIT_FAILURE; + } + + if (opt_username) + { + memcached_return_t ret; + if (memcached_failed(ret= memcached_set_sasl_auth_data(memc, opt_username, opt_passwd))) + { + std::cerr << memcached_last_error_message(memc) << std::endl; + memcached_free(memc); + return EXIT_FAILURE; + } + } + if (rc != MEMCACHED_SUCCESS and rc != MEMCACHED_SOME_ERRORS) { printf("Failure to communicate with servers (%s)\n", @@ -393,6 +416,15 @@ static void options_parse(int argc, char *argv[]) close_stdio(); break; + case OPT_USERNAME: + opt_username= optarg; + opt_binary= true; + break; + + case OPT_PASSWD: + opt_passwd= optarg; + break; + case '?': /* getopt_long already printed an error message. */ exit(1);