Update scanner
[awesomized/libmemcached] / clients / memflush.cc
index 848bc1e7d1677937d620afd91fc9a1171b6bc35a..1ef1bfde52629e9775573c8f6ef57691c46503a0 100644 (file)
  */
 #include "config.h"
 
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
 #include <getopt.h>
+#include <iostream>
+#include <unistd.h>
+
 #include <libmemcached/memcached.h>
 #include "client_options.h"
 #include "utilities.h"
@@ -60,12 +62,24 @@ int main(int argc, char *argv[])
   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;
+    }
+  }
+
   rc = memcached_flush(memc, opt_expire);
   if (rc != MEMCACHED_SUCCESS)
   {
@@ -80,8 +94,6 @@ int main(int argc, char *argv[])
 
   free(opt_servers);
 
-  shutdown_sasl();
-
   return EXIT_SUCCESS;
 }