Update scanner
[awesomized/libmemcached] / clients / memcp.cc
index 3869242b171c8cff803dda17624d4c3b0606bee2..228362513905beabef0108285301d6c48f3d741f 100644 (file)
 
 #include "config.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-#include <unistd.h>
+#include <cerrno>
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
+#include <cstdlib>
+#include <cstring>
+#include <fcntl.h>
 #include <getopt.h>
-#include <sys/types.h>
+#include <iostream>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <strings.h>
-#include <string.h>
 #include <sys/types.h>
-#include <stdlib.h>
-#include <limits.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 
 #include <libmemcached/memcached.h>
@@ -114,12 +116,25 @@ int main(int argc, char *argv[])
   memcached_server_list_free(servers);
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
                          (uint64_t)opt_binary);
-  if (!initialize_sasl(memc, opt_username, opt_passwd))
+
+  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;
+    }
+  }
+
   while (optind < argc)
   {
     struct stat sbuf;
@@ -206,7 +221,6 @@ int main(int argc, char *argv[])
     free(opt_servers);
   if (opt_hash)
     free(opt_hash);
-  shutdown_sasl();
 
   return return_code;
 }