diff options
author | Simo Sorce <simo@redhat.com> | 2014-08-12 18:04:42 -0400 |
---|---|---|
committer | Robbie Harwood <rharwood@redhat.com> | 2015-12-01 17:45:34 -0500 |
commit | e155f81d84f7dd0b0b643a1228c2f9c503fc87e5 (patch) | |
tree | 427093e88256783f03c2a80e518b06600c3890e8 /proxy | |
parent | fdcad4fa9696c5f501b16d1b3f622ccc28b6147f (diff) | |
download | gss-proxy-e155f81d84f7dd0b0b643a1228c2f9c503fc87e5.tar.gz gss-proxy-e155f81d84f7dd0b0b643a1228c2f9c503fc87e5.tar.xz gss-proxy-e155f81d84f7dd0b0b643a1228c2f9c503fc87e5.zip |
Add helper to find options in rpc messages
Use it in gp_export.c where the code is duplicate already.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Robbie Harwoood <rharwood@redhat.com>
Diffstat (limited to 'proxy')
-rw-r--r-- | proxy/src/gp_common.h | 25 | ||||
-rw-r--r-- | proxy/src/gp_export.c | 49 |
2 files changed, 44 insertions, 30 deletions
diff --git a/proxy/src/gp_common.h b/proxy/src/gp_common.h index 96afbb3..25a89b7 100644 --- a/proxy/src/gp_common.h +++ b/proxy/src/gp_common.h @@ -89,4 +89,29 @@ union gp_rpc_res { gssx_res_wrap_size_limit wrap_size_limit; }; +#define gpopt_string_match(buf, val, len) \ + (len == (buf)->octet_string_len && \ + strncmp((val), (buf)->octet_string_val, \ + (buf)->octet_string_len) == 0) + +#define gp_option_name_match(opt, val, len) \ + gpopt_string_match(&((opt)->option), val, len) + +#define gp_option_value_match(opt, val, len) \ + gpopt_string_match(&((opt)->value), val, len) + +#define gp_options_find(res, opts, name, len) \ +do { \ + struct gssx_option *_v; \ + int _o; \ + res = NULL; \ + for (_o = 0; _o < opts.options_len; _o++) { \ + _v = &opts.options_val[_o]; \ + if (gp_option_name_match(_v, name, len)) { \ + res = _v; \ + break; \ + } \ + } \ +} while(0) + #endif /* _GP_COMMON_H_ */ diff --git a/proxy/src/gp_export.c b/proxy/src/gp_export.c index 284bca6..0ef3128 100644 --- a/proxy/src/gp_export.c +++ b/proxy/src/gp_export.c @@ -372,21 +372,16 @@ enum exp_ctx_types { int gp_get_exported_context_type(struct gssx_call_ctx *ctx) { - struct gssx_option *val; - int i; - - for (i = 0; i < ctx->options.options_len; i++) { - val = &ctx->options.options_val[i]; - if (val->option.octet_string_len == sizeof(EXP_CTX_TYPE_OPTION) && - strncmp(EXP_CTX_TYPE_OPTION, - val->option.octet_string_val, - val->option.octet_string_len) == 0) { - if (strncmp(LINUX_LUCID_V1, - val->value.octet_string_val, - val->value.octet_string_len) == 0) { - return EXP_CTX_LINUX_LUCID_V1; - } - return -1; + struct gssx_option *val = NULL; + + gp_options_find(val, ctx->options, + EXP_CTX_TYPE_OPTION, sizeof(EXP_CTX_TYPE_OPTION)); + if (val) { + if (gp_option_value_match(val, LINUX_LUCID_V1, + sizeof(LINUX_LUCID_V1))) { + return EXP_CTX_LINUX_LUCID_V1; + } else { + return EXP_CTX_PARTIAL; } } @@ -661,22 +656,16 @@ enum exp_creds_types { int gp_get_export_creds_type(struct gssx_call_ctx *ctx) { - struct gssx_option *val; - int i; - - for (i = 0; i < ctx->options.options_len; i++) { - val = &ctx->options.options_val[i]; - if (val->option.octet_string_len == sizeof(EXP_CREDS_TYPE_OPTION) && - strncmp(EXP_CREDS_TYPE_OPTION, - val->option.octet_string_val, - val->option.octet_string_len) == 0) { - if (strncmp(LINUX_CREDS_V1, - val->value.octet_string_val, - val->value.octet_string_len) == 0) { - return EXP_CREDS_LINUX_V1; - } - return -1; + struct gssx_option *val = NULL; + + gp_options_find(val, ctx->options, + EXP_CTX_TYPE_OPTION, sizeof(EXP_CTX_TYPE_OPTION)); + if (val) { + if (gp_option_value_match(val, LINUX_CREDS_V1, + sizeof(LINUX_CREDS_V1))) { + return EXP_CREDS_LINUX_V1; } + return -1; } return EXP_CREDS_NO_CREDS; |