folly::Future SaslHandler::SaslInit()

in src/hbase/connection/sasl-handler.cc [154:185]


folly::Future<folly::Unit> SaslHandler::SaslInit(Context *ctx) {
  int rc;
  const char *mechusing, *mechlist = "GSSAPI";
  const char *out;
  unsigned int outlen;

  rc = sasl_client_new(service_name_.c_str(), /* The service we are using*/
                       host_name_.c_str(), NULL,
                       NULL, /* Local and remote IP address strings
                                   (NULL disables mechanisms which require this info)*/
                       NULL, /*connection-specific callbacks*/
                       0 /*security flags*/, &sconn_);
  if (rc != SASL_OK) {
    LOG(FATAL) << "Cannot create client (" << rc << ") ";
    throw std::runtime_error("Cannot create client");
  }
  int curr_rc;
  do {
    curr_rc = sasl_client_start(sconn_,   /* the same context from above */
                                mechlist, /* the list of mechanisms from the server */
                                NULL,     /* filled in if an interaction is needed */
                                &out,     /* filled in on success */
                                &outlen,  /* filled in on success */
                                &mechusing);
  } while (curr_rc == SASL_INTERACT); /* the mechanism may ask us to fill
     in things many times. result is SASL_CONTINUE on success */
  if (curr_rc != SASL_CONTINUE) {
    throw std::runtime_error("Cannot start client (" + std::to_string(curr_rc) + ")");
  }
  folly::Future<folly::Unit> fut = WriteSaslOutput(ctx, out, outlen);
  return fut;
}