Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat(security): init sasl #599

Merged
merged 16 commits into from
Aug 26, 2020
11 changes: 7 additions & 4 deletions src/runtime/security/kinit_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ error_s check_configuration()
class kinit_context : public utils::singleton<kinit_context>
{
public:
kinit_context() : _opt(nullptr) {}
virtual ~kinit_context();
~kinit_context();

// implementation of 'kinit -k -t <keytab_file> <principal>'
error_s kinit();
const std::string username() const { return _user_name; }
const std::string &username() const { return _user_name; }

private:
kinit_context() : _opt(nullptr) {}
levy5307 marked this conversation as resolved.
Show resolved Hide resolved

// init kerberos context
void init_krb5_ctx();

Expand Down Expand Up @@ -111,6 +112,8 @@ class kinit_context : public utils::singleton<kinit_context>

uint64_t _cred_expire_timestamp;
std::shared_ptr<boost::asio::deadline_timer> _timer;

friend class utils::singleton<kinit_context>;
};

kinit_context::~kinit_context() { krb5_get_init_creds_opt_free(_krb5_context, _opt); }
Expand Down Expand Up @@ -314,6 +317,6 @@ error_s kinit_context::wrap_krb5_err(krb5_error_code krb5_err, const std::string

error_s run_kinit() { return kinit_context::instance().kinit(); }

const std::string get_username() { return kinit_context::instance().username(); }
const std::string &get_username() { return kinit_context::instance().username(); }
} // namespace security
} // namespace dsn
2 changes: 1 addition & 1 deletion src/runtime/security/kinit_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
namespace dsn {
namespace security {
extern error_s run_kinit();
extern const std::string get_username();
extern const std::string &get_username();
} // namespace security
} // namespace dsn
3 changes: 1 addition & 2 deletions src/runtime/security/sasl_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ void sasl_set_mutex_local()
error_s init_sasl(bool is_server)
{
sasl_set_mutex_local();
int err = 0;
err = sasl_client_init(&client_callbacks[0]);
int err = sasl_client_init(&client_callbacks[0]);
levy5307 marked this conversation as resolved.
Show resolved Hide resolved
error_s ret = error_s::make(ERR_OK);
if (err != SASL_OK) {
ret = error_s::make(ERR_SASL_INTERNAL);
Expand Down