aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/security/context/security_context.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/security/context/security_context.cc')
-rw-r--r--src/core/lib/security/context/security_context.cc129
1 files changed, 65 insertions, 64 deletions
diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc
index 31d800b9b4..b2b90e86e0 100644
--- a/src/core/lib/security/context/security_context.cc
+++ b/src/core/lib/security/context/security_context.cc
@@ -36,17 +36,17 @@ grpc_tracer_flag grpc_trace_auth_context_refcount =
/* --- grpc_call --- */
-grpc_call_error grpc_call_set_credentials(grpc_call *call,
- grpc_call_credentials *creds) {
+grpc_call_error grpc_call_set_credentials(grpc_call* call,
+ grpc_call_credentials* creds) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_client_security_context *ctx = NULL;
+ grpc_client_security_context* ctx = NULL;
GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2,
(call, creds));
if (!grpc_call_is_client(call)) {
gpr_log(GPR_ERROR, "Method is client-side only.");
return GRPC_CALL_ERROR_NOT_ON_SERVER;
}
- ctx = (grpc_client_security_context *)grpc_call_context_get(
+ ctx = (grpc_client_security_context*)grpc_call_context_get(
call, GRPC_CONTEXT_SECURITY);
if (ctx == NULL) {
ctx = grpc_client_security_context_create();
@@ -61,34 +61,34 @@ grpc_call_error grpc_call_set_credentials(grpc_call *call,
return GRPC_CALL_OK;
}
-grpc_auth_context *grpc_call_auth_context(grpc_call *call) {
- void *sec_ctx = grpc_call_context_get(call, GRPC_CONTEXT_SECURITY);
+grpc_auth_context* grpc_call_auth_context(grpc_call* call) {
+ void* sec_ctx = grpc_call_context_get(call, GRPC_CONTEXT_SECURITY);
GRPC_API_TRACE("grpc_call_auth_context(call=%p)", 1, (call));
if (sec_ctx == NULL) return NULL;
return grpc_call_is_client(call)
? GRPC_AUTH_CONTEXT_REF(
- ((grpc_client_security_context *)sec_ctx)->auth_context,
+ ((grpc_client_security_context*)sec_ctx)->auth_context,
"grpc_call_auth_context client")
: GRPC_AUTH_CONTEXT_REF(
- ((grpc_server_security_context *)sec_ctx)->auth_context,
+ ((grpc_server_security_context*)sec_ctx)->auth_context,
"grpc_call_auth_context server");
}
-void grpc_auth_context_release(grpc_auth_context *context) {
+void grpc_auth_context_release(grpc_auth_context* context) {
GRPC_API_TRACE("grpc_auth_context_release(context=%p)", 1, (context));
GRPC_AUTH_CONTEXT_UNREF(context, "grpc_auth_context_unref");
}
/* --- grpc_client_security_context --- */
-grpc_client_security_context *grpc_client_security_context_create(void) {
- return (grpc_client_security_context *)gpr_zalloc(
+grpc_client_security_context* grpc_client_security_context_create(void) {
+ return (grpc_client_security_context*)gpr_zalloc(
sizeof(grpc_client_security_context));
}
-void grpc_client_security_context_destroy(void *ctx) {
+void grpc_client_security_context_destroy(void* ctx) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_client_security_context *c = (grpc_client_security_context *)ctx;
+ grpc_client_security_context* c = (grpc_client_security_context*)ctx;
grpc_call_credentials_unref(&exec_ctx, c->creds);
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context");
if (c->extension.instance != NULL && c->extension.destroy != NULL) {
@@ -100,13 +100,13 @@ void grpc_client_security_context_destroy(void *ctx) {
/* --- grpc_server_security_context --- */
-grpc_server_security_context *grpc_server_security_context_create(void) {
- return (grpc_server_security_context *)gpr_zalloc(
+grpc_server_security_context* grpc_server_security_context_create(void) {
+ return (grpc_server_security_context*)gpr_zalloc(
sizeof(grpc_server_security_context));
}
-void grpc_server_security_context_destroy(void *ctx) {
- grpc_server_security_context *c = (grpc_server_security_context *)ctx;
+void grpc_server_security_context_destroy(void* ctx) {
+ grpc_server_security_context* c = (grpc_server_security_context*)ctx;
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context");
if (c->extension.instance != NULL && c->extension.destroy != NULL) {
c->extension.destroy(c->extension.instance);
@@ -118,9 +118,9 @@ void grpc_server_security_context_destroy(void *ctx) {
static grpc_auth_property_iterator empty_iterator = {NULL, 0, NULL};
-grpc_auth_context *grpc_auth_context_create(grpc_auth_context *chained) {
- grpc_auth_context *ctx =
- (grpc_auth_context *)gpr_zalloc(sizeof(grpc_auth_context));
+grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) {
+ grpc_auth_context* ctx =
+ (grpc_auth_context*)gpr_zalloc(sizeof(grpc_auth_context));
gpr_ref_init(&ctx->refcount, 1);
if (chained != NULL) {
ctx->chained = GRPC_AUTH_CONTEXT_REF(chained, "chained");
@@ -131,9 +131,9 @@ grpc_auth_context *grpc_auth_context_create(grpc_auth_context *chained) {
}
#ifndef NDEBUG
-grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx,
- const char *file, int line,
- const char *reason) {
+grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx,
+ const char* file, int line,
+ const char* reason) {
if (ctx == NULL) return NULL;
if (GRPC_TRACER_ON(grpc_trace_auth_context_refcount)) {
gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count);
@@ -142,7 +142,7 @@ grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx,
val + 1, reason);
}
#else
-grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx) {
+grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx) {
if (ctx == NULL) return NULL;
#endif
gpr_ref(&ctx->refcount);
@@ -150,8 +150,8 @@ grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx) {
}
#ifndef NDEBUG
-void grpc_auth_context_unref(grpc_auth_context *ctx, const char *file, int line,
- const char *reason) {
+void grpc_auth_context_unref(grpc_auth_context* ctx, const char* file, int line,
+ const char* reason) {
if (ctx == NULL) return;
if (GRPC_TRACER_ON(grpc_trace_auth_context_refcount)) {
gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count);
@@ -160,7 +160,7 @@ void grpc_auth_context_unref(grpc_auth_context *ctx, const char *file, int line,
val - 1, reason);
}
#else
-void grpc_auth_context_unref(grpc_auth_context *ctx) {
+void grpc_auth_context_unref(grpc_auth_context* ctx) {
if (ctx == NULL) return;
#endif
if (gpr_unref(&ctx->refcount)) {
@@ -176,18 +176,18 @@ void grpc_auth_context_unref(grpc_auth_context *ctx) {
}
}
-const char *grpc_auth_context_peer_identity_property_name(
- const grpc_auth_context *ctx) {
+const char* grpc_auth_context_peer_identity_property_name(
+ const grpc_auth_context* ctx) {
GRPC_API_TRACE("grpc_auth_context_peer_identity_property_name(ctx=%p)", 1,
(ctx));
return ctx->peer_identity_property_name;
}
-int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context *ctx,
- const char *name) {
+int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context* ctx,
+ const char* name) {
grpc_auth_property_iterator it =
grpc_auth_context_find_properties_by_name(ctx, name);
- const grpc_auth_property *prop = grpc_auth_property_iterator_next(&it);
+ const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it);
GRPC_API_TRACE(
"grpc_auth_context_set_peer_identity_property_name(ctx=%p, name=%s)", 2,
(ctx, name));
@@ -200,13 +200,13 @@ int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context *ctx,
return 1;
}
-int grpc_auth_context_peer_is_authenticated(const grpc_auth_context *ctx) {
+int grpc_auth_context_peer_is_authenticated(const grpc_auth_context* ctx) {
GRPC_API_TRACE("grpc_auth_context_peer_is_authenticated(ctx=%p)", 1, (ctx));
return ctx->peer_identity_property_name == NULL ? 0 : 1;
}
grpc_auth_property_iterator grpc_auth_context_property_iterator(
- const grpc_auth_context *ctx) {
+ const grpc_auth_context* ctx) {
grpc_auth_property_iterator it = empty_iterator;
GRPC_API_TRACE("grpc_auth_context_property_iterator(ctx=%p)", 1, (ctx));
if (ctx == NULL) return it;
@@ -214,8 +214,8 @@ grpc_auth_property_iterator grpc_auth_context_property_iterator(
return it;
}
-const grpc_auth_property *grpc_auth_property_iterator_next(
- grpc_auth_property_iterator *it) {
+const grpc_auth_property* grpc_auth_property_iterator_next(
+ grpc_auth_property_iterator* it) {
GRPC_API_TRACE("grpc_auth_property_iterator_next(it=%p)", 1, (it));
if (it == NULL || it->ctx == NULL) return NULL;
while (it->index == it->ctx->properties.count) {
@@ -227,7 +227,7 @@ const grpc_auth_property *grpc_auth_property_iterator_next(
return &it->ctx->properties.array[it->index++];
} else {
while (it->index < it->ctx->properties.count) {
- const grpc_auth_property *prop = &it->ctx->properties.array[it->index++];
+ const grpc_auth_property* prop = &it->ctx->properties.array[it->index++];
GPR_ASSERT(prop->name != NULL);
if (strcmp(it->name, prop->name) == 0) {
return prop;
@@ -239,7 +239,7 @@ const grpc_auth_property *grpc_auth_property_iterator_next(
}
grpc_auth_property_iterator grpc_auth_context_find_properties_by_name(
- const grpc_auth_context *ctx, const char *name) {
+ const grpc_auth_context* ctx, const char* name) {
grpc_auth_property_iterator it = empty_iterator;
GRPC_API_TRACE("grpc_auth_context_find_properties_by_name(ctx=%p, name=%s)",
2, (ctx, name));
@@ -250,44 +250,45 @@ grpc_auth_property_iterator grpc_auth_context_find_properties_by_name(
}
grpc_auth_property_iterator grpc_auth_context_peer_identity(
- const grpc_auth_context *ctx) {
+ const grpc_auth_context* ctx) {
GRPC_API_TRACE("grpc_auth_context_peer_identity(ctx=%p)", 1, (ctx));
if (ctx == NULL) return empty_iterator;
return grpc_auth_context_find_properties_by_name(
ctx, ctx->peer_identity_property_name);
}
-static void ensure_auth_context_capacity(grpc_auth_context *ctx) {
+static void ensure_auth_context_capacity(grpc_auth_context* ctx) {
if (ctx->properties.count == ctx->properties.capacity) {
ctx->properties.capacity =
GPR_MAX(ctx->properties.capacity + 8, ctx->properties.capacity * 2);
- ctx->properties.array = (grpc_auth_property *)gpr_realloc(
+ ctx->properties.array = (grpc_auth_property*)gpr_realloc(
ctx->properties.array,
ctx->properties.capacity * sizeof(grpc_auth_property));
}
}
-void grpc_auth_context_add_property(grpc_auth_context *ctx, const char *name,
- const char *value, size_t value_length) {
- grpc_auth_property *prop;
+void grpc_auth_context_add_property(grpc_auth_context* ctx, const char* name,
+ const char* value, size_t value_length) {
+ grpc_auth_property* prop;
GRPC_API_TRACE(
"grpc_auth_context_add_property(ctx=%p, name=%s, value=%*.*s, "
"value_length=%lu)",
- 6, (ctx, name, (int)value_length, (int)value_length, value,
- (unsigned long)value_length));
+ 6,
+ (ctx, name, (int)value_length, (int)value_length, value,
+ (unsigned long)value_length));
ensure_auth_context_capacity(ctx);
prop = &ctx->properties.array[ctx->properties.count++];
prop->name = gpr_strdup(name);
- prop->value = (char *)gpr_malloc(value_length + 1);
+ prop->value = (char*)gpr_malloc(value_length + 1);
memcpy(prop->value, value, value_length);
prop->value[value_length] = '\0';
prop->value_length = value_length;
}
-void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx,
- const char *name,
- const char *value) {
- grpc_auth_property *prop;
+void grpc_auth_context_add_cstring_property(grpc_auth_context* ctx,
+ const char* name,
+ const char* value) {
+ grpc_auth_property* prop;
GRPC_API_TRACE(
"grpc_auth_context_add_cstring_property(ctx=%p, name=%s, value=%s)", 3,
(ctx, name, value));
@@ -298,48 +299,48 @@ void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx,
prop->value_length = strlen(value);
}
-void grpc_auth_property_reset(grpc_auth_property *property) {
+void grpc_auth_property_reset(grpc_auth_property* property) {
gpr_free(property->name);
gpr_free(property->value);
memset(property, 0, sizeof(grpc_auth_property));
}
-static void auth_context_pointer_arg_destroy(grpc_exec_ctx *exec_ctx, void *p) {
- GRPC_AUTH_CONTEXT_UNREF((grpc_auth_context *)p, "auth_context_pointer_arg");
+static void auth_context_pointer_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) {
+ GRPC_AUTH_CONTEXT_UNREF((grpc_auth_context*)p, "auth_context_pointer_arg");
}
-static void *auth_context_pointer_arg_copy(void *p) {
- return GRPC_AUTH_CONTEXT_REF((grpc_auth_context *)p,
+static void* auth_context_pointer_arg_copy(void* p) {
+ return GRPC_AUTH_CONTEXT_REF((grpc_auth_context*)p,
"auth_context_pointer_arg");
}
-static int auth_context_pointer_cmp(void *a, void *b) { return GPR_ICMP(a, b); }
+static int auth_context_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
static const grpc_arg_pointer_vtable auth_context_pointer_vtable = {
auth_context_pointer_arg_copy, auth_context_pointer_arg_destroy,
auth_context_pointer_cmp};
-grpc_arg grpc_auth_context_to_arg(grpc_auth_context *p) {
- return grpc_channel_arg_pointer_create((char *)GRPC_AUTH_CONTEXT_ARG, p,
+grpc_arg grpc_auth_context_to_arg(grpc_auth_context* p) {
+ return grpc_channel_arg_pointer_create((char*)GRPC_AUTH_CONTEXT_ARG, p,
&auth_context_pointer_vtable);
}
-grpc_auth_context *grpc_auth_context_from_arg(const grpc_arg *arg) {
+grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) {
if (strcmp(arg->key, GRPC_AUTH_CONTEXT_ARG) != 0) return NULL;
if (arg->type != GRPC_ARG_POINTER) {
gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type,
GRPC_AUTH_CONTEXT_ARG);
return NULL;
}
- return (grpc_auth_context *)arg->value.pointer.p;
+ return (grpc_auth_context*)arg->value.pointer.p;
}
-grpc_auth_context *grpc_find_auth_context_in_args(
- const grpc_channel_args *args) {
+grpc_auth_context* grpc_find_auth_context_in_args(
+ const grpc_channel_args* args) {
size_t i;
if (args == NULL) return NULL;
for (i = 0; i < args->num_args; i++) {
- grpc_auth_context *p = grpc_auth_context_from_arg(&args->args[i]);
+ grpc_auth_context* p = grpc_auth_context_from_arg(&args->args[i]);
if (p != NULL) return p;
}
return NULL;