22 #ifdef HAVE_SASL_SASL_H
27 #include <boost/algorithm/string.hpp>
33 DEFINE_bool(force_lowercase_usernames,
false,
"If true, all principals and usernames are"
34 " mapped to lowercase shortnames before being passed to any components (Sentry, "
35 "admission control) for authorization");
37 using boost::algorithm::is_any_of;
38 using boost::algorithm::join;
39 using boost::algorithm::split;
40 using boost::algorithm::to_lower;
45 const int offset,
const uint32_t len, uint32_t* outLen) {
50 result = sasl_decode(
conn,
51 (
const char*)incoming, len, (
const char**)&output, &outputlen);
52 if (result != SASL_OK) {
53 throw SaslException(sasl_errdetail(
conn));
60 const int offset,
const uint32_t len, uint32_t* outLen) {
65 result = sasl_encode(
conn, (
const char*)outgoing+offset,
66 len, (
const char**)&output, &outputlen);
67 if (result != SASL_OK) {
68 throw SaslException(sasl_errdetail(
conn));
77 sasl_getprop(
conn, SASL_USERNAME, reinterpret_cast<const void **>(&username));
78 if (result != SASL_OK) {
80 ss <<
"Error getting SASL_USERNAME property: " << sasl_errstring(result, NULL, NULL);
81 throw SaslException(ss.str().c_str());
92 if (FLAGS_force_lowercase_usernames) {
93 vector<string> components;
94 split(components, ret, is_any_of(
"@"));
95 if (components.size() > 0 ) {
96 to_lower(components[0]);
97 ret = join(components,
"@");
104 const string&
protocol,
const string& serverName,
const map<string,string>& props,
105 sasl_callback_t* callbacks) {
107 if (!props.empty()) {
108 throw SaslServerImplException(
"Properties not yet supported");
110 int result = sasl_client_new(protocol.c_str(), serverName.c_str(),
111 NULL, NULL, callbacks, 0, &
conn);
112 if (result != SASL_OK) {
114 throw SaslServerImplException(sasl_errdetail(
conn));
116 throw SaslServerImplException(sasl_errstring(result, NULL, NULL));
120 if (!authenticationId.empty()) {
136 const uint8_t* challenge,
const uint32_t len, uint32_t *resLen) {
137 sasl_interact_t* client_interact=NULL;
144 result=sasl_client_start(
conn,
149 (
const char**)&mechUsing);
154 result=sasl_client_step(
conn,
155 (
const char*)challenge,
161 result = SASL_CONTINUE;
165 if (result == SASL_OK) {
167 }
else if (result != SASL_CONTINUE) {
168 throw SaslClientImplException(sasl_errdetail(
conn));
171 return (uint8_t*)out;
191 const string& userRealm,
192 unsigned flags, sasl_callback_t* callbacks) {
194 int result = sasl_server_new(service.c_str(),
195 serverFQDN.size() == 0 ? NULL : serverFQDN.c_str(),
196 userRealm.size() == 0 ? NULL :userRealm.c_str(),
197 NULL, NULL, callbacks, flags, &
conn);
198 if (result != SASL_OK) {
200 throw SaslServerImplException(sasl_errdetail(
conn));
202 throw SaslServerImplException(sasl_errstring(result, NULL, NULL));
211 const uint32_t len, uint32_t* resLen) {
217 result = sasl_server_start(
conn,
218 (
const char *)response, NULL, 0, (
const char **)&out, &outlen);
220 result = sasl_server_step(
conn,
221 (
const char*)response, len, (
const char**)&out, &outlen);
224 if (result == SASL_OK) {
226 }
else if (result != SASL_CONTINUE) {
227 throw SaslServerImplException(sasl_errdetail(
conn));
std::string getNegotiatedProperty(const std::string &propName)
const StringSearch UrlParser::protocol_search & protocol
virtual std::string getMechanismName()
std::string getUsername()
DEFINE_bool(compact_catalog_topic, false,"If true, updates sent via the statestore are ""compacted before transmission. This saves network bandwidth at the cost of a small"" quantity of CPU time. Enable this option in cluster with large catalogs (make ""sure it is also enabled on receiving Impala demons as well).")
uint8_t * unwrap(const uint8_t *incoming, const int offset, const uint32_t len, uint32_t *outLen)
uint8_t * evaluateChallengeOrResponse(const uint8_t *challenge, const uint32_t len, uint32_t *outLen)
uint8_t * wrap(const uint8_t *outgoing, int offset, const uint32_t len, uint32_t *outLen)
virtual uint8_t * evaluateChallengeOrResponse(const uint8_t *challenge, const uint32_t len, uint32_t *resLen)
TSaslServer(const std::string &service, const std::string &serverFQDN, const std::string &userRealm, unsigned flags, sasl_callback_t *callbacks)
uint8_t offset[7 *64-sizeof(uint64_t)]
virtual bool hasInitialResponse()
TSaslClient(const std::string &mechanisms, const std::string &authorizationId, const std::string &protocol, const std::string &serverName, const std::map< std::string, std::string > &props, sasl_callback_t *callbacks)