Commit bbced206 authored by wuchengcheng's avatar wuchengcheng

change auth response failure and destroy auth response msg and code style

parent afbee1f0
This diff is collapsed.
......@@ -230,12 +230,6 @@ public:
static const char* status_str(Status);
// Although the implementation of this function looks somewhat weird,
// we did not find a better way to provide auth failure check for user codes.
bool IsAuthFailure() const {
return (_err == "Auth failure");
}
private:
bool PopCounter(uint8_t command, uint64_t* new_value, uint64_t* cas_value);
bool PopStore(uint8_t command, uint64_t* cas_value);
......
......@@ -35,22 +35,21 @@ constexpr char kPadding[1] = {'\0'};
// To get the couchbase authentication protocol, see
// https://developer.couchbase.com/documentation/server/3.x/developer/dev-guide-3.0/sasl.html
int CouchbaseAuthenticator::GenerateCredential(std::string* auth_str) const {
const brpc::policy::MemcacheRequestHeader header = {
brpc::policy::MC_MAGIC_REQUEST, brpc::policy::MC_BINARY_SASL_AUTH,
butil::HostToNet16(sizeof(kPlainAuthCommand) - 1), 0, 0, 0,
butil::HostToNet32(sizeof(kPlainAuthCommand) + 1 +
bucket_name_.length() * 2 + bucket_password_.length()),
0, 0};
butil::IOBuf in;
in.append(&header, sizeof(header));
in.append(kPlainAuthCommand, sizeof(kPlainAuthCommand) - 1);
in.append(bucket_name_.c_str(), bucket_name_.length());
in.append(kPadding, sizeof(kPadding));
in.append(bucket_name_.c_str(), bucket_name_.length());
in.append(kPadding, sizeof(kPadding));
in.append(bucket_password_.c_str(), bucket_password_.length());
auth_str->assign(in.to_string().c_str(), in.size());
return 0;
const brpc::policy::MemcacheRequestHeader header = {
brpc::policy::MC_MAGIC_REQUEST, brpc::policy::MC_BINARY_SASL_AUTH,
butil::HostToNet16(sizeof(kPlainAuthCommand) - 1), 0, 0, 0,
butil::HostToNet32(sizeof(kPlainAuthCommand) + 1 +
bucket_name_.length() * 2 + bucket_password_.length()),
0, 0};
auth_str->clear();
auth_str->append(reinterpret_cast<const char*>(&header), sizeof(header));
auth_str->append(kPlainAuthCommand, sizeof(kPlainAuthCommand) - 1);
auth_str->append(bucket_name_);
auth_str->append(kPadding, sizeof(kPadding));
auth_str->append(bucket_name_);
auth_str->append(kPadding, sizeof(kPadding));
auth_str->append(bucket_password_);
return 0;
}
} // namespace policy
......
......@@ -130,8 +130,11 @@ ParseResult ParseMemcacheMessage(butil::IOBuf* source,
if (header->status != 0) {
LOG(ERROR) << "Failed to authenticate the couchbase bucket."
<< "All the following commands will result in auth failure.";
return MakeParseError(PARSE_ERROR_NO_RESOURCE,
"Fail to authenticate with the couchbase bucket");
}
msg = static_cast<MostCommonMessage*>(socket->release_parsing_context());
DestroyingPtr<MostCommonMessage> auth_msg(
static_cast<MostCommonMessage*>(socket->release_parsing_context()));
socket->GivebackPipelinedInfo(pi);
} else {
if (++msg->pi.count >= pi.count) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment