Index: net/http/http_auth_gssapi_posix.cc |
diff --git a/net/http/http_auth_gssapi_posix.cc b/net/http/http_auth_gssapi_posix.cc |
index a4b8c0cd839cc49bcf656d2ee5fb17b43193cbb6..09d5aff0c4055a104f876d15515ee8266476a2e8 100644 |
--- a/net/http/http_auth_gssapi_posix.cc |
+++ b/net/http/http_auth_gssapi_posix.cc |
@@ -27,33 +27,19 @@ |
namespace { |
static gss_OID_desc GSS_C_NT_USER_NAME_VAL = { |
- 10, |
- const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01") |
-}; |
+ 10, const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01")}; |
static gss_OID_desc GSS_C_NT_MACHINE_UID_NAME_VAL = { |
- 10, |
- const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02") |
-}; |
+ 10, const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02")}; |
static gss_OID_desc GSS_C_NT_STRING_UID_NAME_VAL = { |
- 10, |
- const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03") |
-}; |
+ 10, const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03")}; |
static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_X_VAL = { |
- 6, |
- const_cast<char*>("\x2b\x06\x01\x05\x06\x02") |
-}; |
+ 6, const_cast<char*>("\x2b\x06\x01\x05\x06\x02")}; |
static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_VAL = { |
- 10, |
- const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04") |
-}; |
+ 10, const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")}; |
static gss_OID_desc GSS_C_NT_ANONYMOUS_VAL = { |
- 6, |
- const_cast<char*>("\x2b\x06\01\x05\x06\x03") |
-}; |
+ 6, const_cast<char*>("\x2b\x06\01\x05\x06\x03")}; |
static gss_OID_desc GSS_C_NT_EXPORT_NAME_VAL = { |
- 6, |
- const_cast<char*>("\x2b\x06\x01\x05\x06\x04") |
-}; |
+ 6, const_cast<char*>("\x2b\x06\x01\x05\x06\x04")}; |
} // namespace |
@@ -81,18 +67,14 @@ namespace net { |
// iso.org.dod.internet.security.mechanism.snego (1.3.6.1.5.5.2) |
gss_OID_desc CHROME_GSS_SPNEGO_MECH_OID_DESC_VAL = { |
- 6, |
- const_cast<char*>("\x2b\x06\x01\x05\x05\x02") |
-}; |
+ 6, const_cast<char*>("\x2b\x06\x01\x05\x05\x02")}; |
-gss_OID CHROME_GSS_SPNEGO_MECH_OID_DESC = |
- &CHROME_GSS_SPNEGO_MECH_OID_DESC_VAL; |
+gss_OID CHROME_GSS_SPNEGO_MECH_OID_DESC = &CHROME_GSS_SPNEGO_MECH_OID_DESC_VAL; |
// Debugging helpers. |
namespace { |
-std::string DisplayStatus(OM_uint32 major_status, |
- OM_uint32 minor_status) { |
+std::string DisplayStatus(OM_uint32 major_status, OM_uint32 minor_status) { |
if (major_status == GSS_S_COMPLETE) |
return "OK"; |
return base::StringPrintf("0x%08X 0x%08X", major_status, minor_status); |
@@ -112,20 +94,18 @@ std::string DisplayCode(GSSAPILibrary* gssapi_lib, |
// a finite number of iterations as well. As an added sanity check, no |
// individual message may exceed |kMaxMsgLength|, and the final result |
// will not exceed |kMaxMsgLength|*2-1. |
- for (int i = 0; i < kMaxDisplayIterations && rv.size() < kMaxMsgLength; |
- ++i) { |
+ for (int i = 0; i < kMaxDisplayIterations && rv.size() < kMaxMsgLength; ++i) { |
OM_uint32 min_stat; |
gss_buffer_desc_struct msg = GSS_C_EMPTY_BUFFER; |
- OM_uint32 maj_stat = |
- gssapi_lib->display_status(&min_stat, status, status_code_type, |
- GSS_C_NULL_OID, &msg_ctx, &msg); |
+ OM_uint32 maj_stat = gssapi_lib->display_status( |
+ &min_stat, status, status_code_type, GSS_C_NULL_OID, &msg_ctx, &msg); |
if (maj_stat == GSS_S_COMPLETE) { |
- int msg_len = (msg.length > kMaxMsgLength) ? |
- static_cast<int>(kMaxMsgLength) : |
- static_cast<int>(msg.length); |
+ int msg_len = (msg.length > kMaxMsgLength) |
+ ? static_cast<int>(kMaxMsgLength) |
+ : static_cast<int>(msg.length); |
if (msg_len > 0 && msg.value != NULL) { |
- rv += base::StringPrintf(" %.*s", msg_len, |
- static_cast<char*>(msg.value)); |
+ rv += |
+ base::StringPrintf(" %.*s", msg_len, static_cast<char*>(msg.value)); |
} |
} |
gssapi_lib->release_buffer(&min_stat, &msg); |
@@ -142,25 +122,22 @@ std::string DisplayExtendedStatus(GSSAPILibrary* gssapi_lib, |
return "OK"; |
std::string major = DisplayCode(gssapi_lib, major_status, GSS_C_GSS_CODE); |
std::string minor = DisplayCode(gssapi_lib, minor_status, GSS_C_MECH_CODE); |
- return base::StringPrintf("Major: %s | Minor: %s", major.c_str(), |
- minor.c_str()); |
+ return base::StringPrintf( |
+ "Major: %s | Minor: %s", major.c_str(), minor.c_str()); |
} |
// ScopedName releases a gss_name_t when it goes out of scope. |
class ScopedName { |
public: |
- ScopedName(gss_name_t name, |
- GSSAPILibrary* gssapi_lib) |
- : name_(name), |
- gssapi_lib_(gssapi_lib) { |
+ ScopedName(gss_name_t name, GSSAPILibrary* gssapi_lib) |
+ : name_(name), gssapi_lib_(gssapi_lib) { |
DCHECK(gssapi_lib_); |
} |
~ScopedName() { |
if (name_ != GSS_C_NO_NAME) { |
OM_uint32 minor_status = 0; |
- OM_uint32 major_status = |
- gssapi_lib_->release_name(&minor_status, &name_); |
+ OM_uint32 major_status = gssapi_lib_->release_name(&minor_status, &name_); |
if (major_status != GSS_S_COMPLETE) { |
LOG(WARNING) << "Problem releasing name. " |
<< DisplayStatus(major_status, minor_status); |
@@ -179,10 +156,8 @@ class ScopedName { |
// ScopedBuffer releases a gss_buffer_t when it goes out of scope. |
class ScopedBuffer { |
public: |
- ScopedBuffer(gss_buffer_t buffer, |
- GSSAPILibrary* gssapi_lib) |
- : buffer_(buffer), |
- gssapi_lib_(gssapi_lib) { |
+ ScopedBuffer(gss_buffer_t buffer, GSSAPILibrary* gssapi_lib) |
+ : buffer_(buffer), gssapi_lib_(gssapi_lib) { |
DCHECK(gssapi_lib_); |
} |
@@ -217,9 +192,8 @@ std::string AppendIfPredefinedValue(gss_OID oid, |
std::string output; |
if (oid->length != predefined_oid->length) |
return output; |
- if (0 != memcmp(oid->elements, |
- predefined_oid->elements, |
- predefined_oid->length)) |
+ if (0 != |
+ memcmp(oid->elements, predefined_oid->elements, predefined_oid->length)) |
return output; |
output += " ("; |
@@ -243,7 +217,7 @@ std::string DescribeOid(GSSAPILibrary* gssapi_lib, const gss_OID oid) { |
// contain only printable characters and are NULL terminated. |
const char* str = reinterpret_cast<const char*>(oid); |
size_t str_length = 0; |
- for ( ; str_length < kMaxCharsToPrint; ++str_length) { |
+ for (; str_length < kMaxCharsToPrint; ++str_length) { |
if (!str[str_length] || !isprint(str[str_length])) |
break; |
} |
@@ -261,7 +235,7 @@ std::string DescribeOid(GSSAPILibrary* gssapi_lib, const gss_OID oid) { |
reinterpret_cast<const unsigned char*>(oid->elements); |
// Don't print more than |kMaxCharsToPrint| characters. |
size_t i = 0; |
- for ( ; (i < byte_length) && (i < kMaxCharsToPrint); ++i) { |
+ for (; (i < byte_length) && (i < kMaxCharsToPrint); ++i) { |
output += base::StringPrintf("\\x%02X", elements[i]); |
} |
if (i >= kMaxCharsToPrint) |
@@ -269,27 +243,20 @@ std::string DescribeOid(GSSAPILibrary* gssapi_lib, const gss_OID oid) { |
output += "\""; |
// Check if the OID is one of the predefined values. |
- output += AppendIfPredefinedValue(oid, |
- GSS_C_NT_USER_NAME, |
- "GSS_C_NT_USER_NAME"); |
- output += AppendIfPredefinedValue(oid, |
- GSS_C_NT_MACHINE_UID_NAME, |
- "GSS_C_NT_MACHINE_UID_NAME"); |
- output += AppendIfPredefinedValue(oid, |
- GSS_C_NT_STRING_UID_NAME, |
- "GSS_C_NT_STRING_UID_NAME"); |
- output += AppendIfPredefinedValue(oid, |
- GSS_C_NT_HOSTBASED_SERVICE_X, |
- "GSS_C_NT_HOSTBASED_SERVICE_X"); |
- output += AppendIfPredefinedValue(oid, |
- GSS_C_NT_HOSTBASED_SERVICE, |
- "GSS_C_NT_HOSTBASED_SERVICE"); |
- output += AppendIfPredefinedValue(oid, |
- GSS_C_NT_ANONYMOUS, |
- "GSS_C_NT_ANONYMOUS"); |
- output += AppendIfPredefinedValue(oid, |
- GSS_C_NT_EXPORT_NAME, |
- "GSS_C_NT_EXPORT_NAME"); |
+ output += |
+ AppendIfPredefinedValue(oid, GSS_C_NT_USER_NAME, "GSS_C_NT_USER_NAME"); |
+ output += AppendIfPredefinedValue( |
+ oid, GSS_C_NT_MACHINE_UID_NAME, "GSS_C_NT_MACHINE_UID_NAME"); |
+ output += AppendIfPredefinedValue( |
+ oid, GSS_C_NT_STRING_UID_NAME, "GSS_C_NT_STRING_UID_NAME"); |
+ output += AppendIfPredefinedValue( |
+ oid, GSS_C_NT_HOSTBASED_SERVICE_X, "GSS_C_NT_HOSTBASED_SERVICE_X"); |
+ output += AppendIfPredefinedValue( |
+ oid, GSS_C_NT_HOSTBASED_SERVICE, "GSS_C_NT_HOSTBASED_SERVICE"); |
+ output += |
+ AppendIfPredefinedValue(oid, GSS_C_NT_ANONYMOUS, "GSS_C_NT_ANONYMOUS"); |
+ output += AppendIfPredefinedValue( |
+ oid, GSS_C_NT_EXPORT_NAME, "GSS_C_NT_EXPORT_NAME"); |
return output; |
} |
@@ -300,18 +267,14 @@ std::string DescribeName(GSSAPILibrary* gssapi_lib, const gss_name_t name) { |
gss_buffer_desc_struct output_name_buffer = GSS_C_EMPTY_BUFFER; |
gss_OID_desc output_name_type_desc = GSS_C_EMPTY_BUFFER; |
gss_OID output_name_type = &output_name_type_desc; |
- major_status = gssapi_lib->display_name(&minor_status, |
- name, |
- &output_name_buffer, |
- &output_name_type); |
+ major_status = gssapi_lib->display_name( |
+ &minor_status, name, &output_name_buffer, &output_name_type); |
ScopedBuffer scoped_output_name(&output_name_buffer, gssapi_lib); |
if (major_status != GSS_S_COMPLETE) { |
- std::string error = |
- base::StringPrintf("Unable to describe name 0x%p, %s", |
- name, |
- DisplayExtendedStatus(gssapi_lib, |
- major_status, |
- minor_status).c_str()); |
+ std::string error = base::StringPrintf( |
+ "Unable to describe name 0x%p, %s", |
+ name, |
+ DisplayExtendedStatus(gssapi_lib, major_status, minor_status).c_str()); |
return error; |
} |
int len = output_name_buffer.length; |
@@ -348,33 +311,31 @@ std::string DescribeContext(GSSAPILibrary* gssapi_lib, |
ScopedName(src_name, gssapi_lib); |
ScopedName(targ_name, gssapi_lib); |
if (major_status != GSS_S_COMPLETE) { |
- std::string error = |
- base::StringPrintf("Unable to describe context 0x%p, %s", |
- context_handle, |
- DisplayExtendedStatus(gssapi_lib, |
- major_status, |
- minor_status).c_str()); |
+ std::string error = base::StringPrintf( |
+ "Unable to describe context 0x%p, %s", |
+ context_handle, |
+ DisplayExtendedStatus(gssapi_lib, major_status, minor_status).c_str()); |
return error; |
} |
std::string source(DescribeName(gssapi_lib, src_name)); |
std::string target(DescribeName(gssapi_lib, targ_name)); |
- std::string description = base::StringPrintf("Context 0x%p: " |
- "Source \"%s\", " |
- "Target \"%s\", " |
- "lifetime %d, " |
- "mechanism %s, " |
- "flags 0x%08X, " |
- "local %d, " |
- "open %d", |
- context_handle, |
- source.c_str(), |
- target.c_str(), |
- lifetime_rec, |
- DescribeOid(gssapi_lib, |
- mech_type).c_str(), |
- ctx_flags, |
- locally_initiated, |
- open); |
+ std::string description = base::StringPrintf( |
+ "Context 0x%p: " |
+ "Source \"%s\", " |
+ "Target \"%s\", " |
+ "lifetime %d, " |
+ "mechanism %s, " |
+ "flags 0x%08X, " |
+ "local %d, " |
+ "open %d", |
+ context_handle, |
+ source.c_str(), |
+ target.c_str(), |
+ lifetime_rec, |
+ DescribeOid(gssapi_lib, mech_type).c_str(), |
+ ctx_flags, |
+ locally_initiated, |
+ open); |
return description; |
} |
@@ -432,7 +393,7 @@ base::NativeLibrary GSSAPISharedLibrary::LoadSharedLibrary() { |
#if defined(OS_MACOSX) |
"libgssapi_krb5.dylib" // MIT Kerberos |
#elif defined(OS_OPENBSD) |
- "libgssapi.so" // Heimdal - OpenBSD |
+ "libgssapi.so" // Heimdal - OpenBSD |
#else |
"libgssapi_krb5.so.2", // MIT Kerberos - FC, Suse10, Debian |
"libgssapi.so.4", // Heimdal - Suse10, MDK |
@@ -464,13 +425,14 @@ base::NativeLibrary GSSAPISharedLibrary::LoadSharedLibrary() { |
} |
#if defined(DLOPEN_KERBEROS) |
-#define BIND(lib, x) \ |
- DCHECK(lib); \ |
- gss_##x##_type x = reinterpret_cast<gss_##x##_type>( \ |
- base::GetFunctionPointerFromNativeLibrary(lib, "gss_" #x)); \ |
- if (x == NULL) { \ |
- LOG(WARNING) << "Unable to bind function \"" << "gss_" #x << "\""; \ |
- return false; \ |
+#define BIND(lib, x) \ |
+ DCHECK(lib); \ |
+ gss_##x##_type x = reinterpret_cast<gss_##x##_type>( \ |
+ base::GetFunctionPointerFromNativeLibrary(lib, "gss_" #x)); \ |
+ if (x == NULL) { \ |
+ LOG(WARNING) << "Unable to bind function \"" \ |
+ << "gss_" #x << "\""; \ |
+ return false; \ |
} |
#else |
#define BIND(lib, x) gss_##x##_type x = gss_##x |
@@ -502,52 +464,49 @@ bool GSSAPISharedLibrary::BindMethods(base::NativeLibrary lib) { |
#undef BIND |
-OM_uint32 GSSAPISharedLibrary::import_name( |
- OM_uint32* minor_status, |
- const gss_buffer_t input_name_buffer, |
- const gss_OID input_name_type, |
- gss_name_t* output_name) { |
+OM_uint32 GSSAPISharedLibrary::import_name(OM_uint32* minor_status, |
+ const gss_buffer_t input_name_buffer, |
+ const gss_OID input_name_type, |
+ gss_name_t* output_name) { |
DCHECK(initialized_); |
- return import_name_(minor_status, input_name_buffer, input_name_type, |
- output_name); |
+ return import_name_( |
+ minor_status, input_name_buffer, input_name_type, output_name); |
} |
-OM_uint32 GSSAPISharedLibrary::release_name( |
- OM_uint32* minor_status, |
- gss_name_t* input_name) { |
+OM_uint32 GSSAPISharedLibrary::release_name(OM_uint32* minor_status, |
+ gss_name_t* input_name) { |
DCHECK(initialized_); |
return release_name_(minor_status, input_name); |
} |
-OM_uint32 GSSAPISharedLibrary::release_buffer( |
- OM_uint32* minor_status, |
- gss_buffer_t buffer) { |
+OM_uint32 GSSAPISharedLibrary::release_buffer(OM_uint32* minor_status, |
+ gss_buffer_t buffer) { |
DCHECK(initialized_); |
return release_buffer_(minor_status, buffer); |
} |
-OM_uint32 GSSAPISharedLibrary::display_name( |
- OM_uint32* minor_status, |
- const gss_name_t input_name, |
- gss_buffer_t output_name_buffer, |
- gss_OID* output_name_type) { |
+OM_uint32 GSSAPISharedLibrary::display_name(OM_uint32* minor_status, |
+ const gss_name_t input_name, |
+ gss_buffer_t output_name_buffer, |
+ gss_OID* output_name_type) { |
DCHECK(initialized_); |
- return display_name_(minor_status, |
- input_name, |
- output_name_buffer, |
- output_name_type); |
+ return display_name_( |
+ minor_status, input_name, output_name_buffer, output_name_type); |
} |
-OM_uint32 GSSAPISharedLibrary::display_status( |
- OM_uint32* minor_status, |
- OM_uint32 status_value, |
- int status_type, |
- const gss_OID mech_type, |
- OM_uint32* message_context, |
- gss_buffer_t status_string) { |
+OM_uint32 GSSAPISharedLibrary::display_status(OM_uint32* minor_status, |
+ OM_uint32 status_value, |
+ int status_type, |
+ const gss_OID mech_type, |
+ OM_uint32* message_context, |
+ gss_buffer_t status_string) { |
DCHECK(initialized_); |
- return display_status_(minor_status, status_value, status_type, mech_type, |
- message_context, status_string); |
+ return display_status_(minor_status, |
+ status_value, |
+ status_type, |
+ mech_type, |
+ message_context, |
+ status_string); |
} |
OM_uint32 GSSAPISharedLibrary::init_sec_context( |
@@ -596,18 +555,15 @@ OM_uint32 GSSAPISharedLibrary::wrap_size_limit( |
max_input_size); |
} |
-OM_uint32 GSSAPISharedLibrary::delete_sec_context( |
- OM_uint32* minor_status, |
- gss_ctx_id_t* context_handle, |
- gss_buffer_t output_token) { |
+OM_uint32 GSSAPISharedLibrary::delete_sec_context(OM_uint32* minor_status, |
+ gss_ctx_id_t* context_handle, |
+ gss_buffer_t output_token) { |
// This is called from the owner class' destructor, even if |
// Init() is not called, so we can't assume |initialized_| |
// is set. |
if (!initialized_) |
return 0; |
- return delete_sec_context_(minor_status, |
- context_handle, |
- output_token); |
+ return delete_sec_context_(minor_status, context_handle, output_token); |
} |
OM_uint32 GSSAPISharedLibrary::inquire_context( |
@@ -633,8 +589,7 @@ OM_uint32 GSSAPISharedLibrary::inquire_context( |
} |
ScopedSecurityContext::ScopedSecurityContext(GSSAPILibrary* gssapi_lib) |
- : security_context_(GSS_C_NO_CONTEXT), |
- gssapi_lib_(gssapi_lib) { |
+ : security_context_(GSS_C_NO_CONTEXT), gssapi_lib_(gssapi_lib) { |
DCHECK(gssapi_lib_); |
} |
@@ -722,9 +677,9 @@ int HttpAuthGSSAPI::GenerateAuthToken(const AuthCredentials* credentials, |
gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER; |
input_token.length = decoded_server_auth_token_.length(); |
- input_token.value = (input_token.length > 0) ? |
- const_cast<char*>(decoded_server_auth_token_.data()) : |
- NULL; |
+ input_token.value = (input_token.length > 0) |
+ ? const_cast<char*>(decoded_server_auth_token_.data()) |
+ : NULL; |
gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; |
ScopedBuffer scoped_output_token(&output_token, library_); |
int rv = GetNextSecurityToken(spn, &input_token, &output_token); |
@@ -740,7 +695,6 @@ int HttpAuthGSSAPI::GenerateAuthToken(const AuthCredentials* credentials, |
return OK; |
} |
- |
namespace { |
// GSSAPI status codes consist of a calling error (essentially, a programmer |
@@ -831,7 +785,6 @@ int MapInitSecContextStatusToError(OM_uint32 major_status) { |
// At this point, every documented status has been checked. |
return ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS; |
} |
- |
} |
int HttpAuthGSSAPI::GetNextSecurityToken(const std::string& spn, |
@@ -846,10 +799,7 @@ int HttpAuthGSSAPI::GetNextSecurityToken(const std::string& spn, |
OM_uint32 minor_status = 0; |
gss_name_t principal_name = GSS_C_NO_NAME; |
OM_uint32 major_status = library_->import_name( |
- &minor_status, |
- &spn_buffer, |
- GSS_C_NT_HOSTBASED_SERVICE, |
- &principal_name); |
+ &minor_status, &spn_buffer, GSS_C_NT_HOSTBASED_SERVICE, &principal_name); |
int rv = MapImportNameStatusToError(major_status); |
if (rv != OK) { |
LOG(ERROR) << "Problem importing name from " |
@@ -863,26 +813,24 @@ int HttpAuthGSSAPI::GetNextSecurityToken(const std::string& spn, |
OM_uint32 req_flags = 0; |
if (can_delegate_) |
req_flags |= GSS_C_DELEG_FLAG; |
- major_status = library_->init_sec_context( |
- &minor_status, |
- GSS_C_NO_CREDENTIAL, |
- scoped_sec_context_.receive(), |
- principal_name, |
- gss_oid_, |
- req_flags, |
- GSS_C_INDEFINITE, |
- GSS_C_NO_CHANNEL_BINDINGS, |
- in_token, |
- NULL, // actual_mech_type |
- out_token, |
- NULL, // ret flags |
- NULL); |
+ major_status = library_->init_sec_context(&minor_status, |
+ GSS_C_NO_CREDENTIAL, |
+ scoped_sec_context_.receive(), |
+ principal_name, |
+ gss_oid_, |
+ req_flags, |
+ GSS_C_INDEFINITE, |
+ GSS_C_NO_CHANNEL_BINDINGS, |
+ in_token, |
+ NULL, // actual_mech_type |
+ out_token, |
+ NULL, // ret flags |
+ NULL); |
rv = MapInitSecContextStatusToError(major_status); |
if (rv != OK) { |
LOG(ERROR) << "Problem initializing context. \n" |
<< DisplayExtendedStatus(library_, major_status, minor_status) |
- << '\n' |
- << DescribeContext(library_, scoped_sec_context_.get()); |
+ << '\n' << DescribeContext(library_, scoped_sec_context_.get()); |
} |
return rv; |
} |