diff options
Diffstat (limited to 'xlators/protocol/server/src/authenticate.c')
| -rw-r--r-- | xlators/protocol/server/src/authenticate.c | 108 |
1 files changed, 60 insertions, 48 deletions
diff --git a/xlators/protocol/server/src/authenticate.c b/xlators/protocol/server/src/authenticate.c index 5a1c2a8c8..d8d138a84 100644 --- a/xlators/protocol/server/src/authenticate.c +++ b/xlators/protocol/server/src/authenticate.c @@ -1,21 +1,14 @@ /* - Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ #ifndef _CONFIG_H #define _CONFIG_H @@ -31,15 +24,15 @@ #include <errno.h> #include "authenticate.h" -static void +static int init (dict_t *this, char *key, data_t *value, void *data) { - void *handle = NULL; - char *auth_file = NULL; - auth_handle_t *auth_handle = NULL; - auth_fn_t authenticate = NULL; - int *error = NULL; - int ret = 0; + void *handle = NULL; + char *auth_file = NULL; + auth_handle_t *auth_handle = NULL; + auth_fn_t authenticate = NULL; + int *error = NULL; + int ret = 0; /* It gets over written */ error = data; @@ -59,7 +52,7 @@ init (dict_t *this, char *key, data_t *value, void *data) if (-1 == ret) { dict_set (this, key, data_from_dynptr (NULL, 0)); *error = -1; - return; + return -1; } handle = dlopen (auth_file, RTLD_LAZY); @@ -69,7 +62,7 @@ init (dict_t *this, char *key, data_t *value, void *data) dict_set (this, key, data_from_dynptr (NULL, 0)); GF_FREE (auth_file); *error = -1; - return; + return -1; } GF_FREE (auth_file); @@ -78,8 +71,9 @@ init (dict_t *this, char *key, data_t *value, void *data) gf_log ("authenticate", GF_LOG_ERROR, "dlsym(gf_auth) on %s\n", dlerror ()); dict_set (this, key, data_from_dynptr (NULL, 0)); + dlclose (handle); *error = -1; - return; + return -1; } auth_handle = GF_CALLOC (1, sizeof (*auth_handle), @@ -87,10 +81,18 @@ init (dict_t *this, char *key, data_t *value, void *data) if (!auth_handle) { dict_set (this, key, data_from_dynptr (NULL, 0)); *error = -1; - return; + dlclose (handle); + return -1; } auth_handle->vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t); + if (!auth_handle->vol_opt) { + dict_set (this, key, data_from_dynptr (NULL, 0)); + *error = -1; + GF_FREE (auth_handle); + dlclose (handle); + return -1; + } auth_handle->vol_opt->given_opt = dlsym (handle, "options"); if (auth_handle->vol_opt->given_opt == NULL) { gf_log ("authenticate", GF_LOG_DEBUG, @@ -102,46 +104,54 @@ init (dict_t *this, char *key, data_t *value, void *data) dict_set (this, key, data_from_dynptr (auth_handle, sizeof (*auth_handle))); + return 0; } -static void +static int fini (dict_t *this, char *key, data_t *value, void *data) { auth_handle_t *handle = data_to_ptr (value); if (handle) { dlclose (handle->handle); } + return 0; +} + +static int +_gf_auth_option_validate (dict_t *d, char *k, data_t *v, void *tmp) +{ + auth_handle_t *handle = NULL; + xlator_t *xl = NULL; + int ret = 0; + + xl = tmp; + + handle = data_to_ptr (v); + if (!handle) + return 0; + + list_add_tail (&(handle->vol_opt->list), &(xl->volume_options)); + + ret = xlator_options_validate_list (xl, xl->options, + handle->vol_opt, NULL); + if (ret) { + gf_log ("authenticate", GF_LOG_ERROR, + "volume option validation failed"); + return -1; + } + return 0; } int32_t gf_auth_init (xlator_t *xl, dict_t *auth_modules) { int ret = 0; - auth_handle_t *handle = NULL; - data_pair_t *pair = NULL; dict_foreach (auth_modules, init, &ret); if (ret) goto out; - pair = auth_modules->members_list; - while (pair) { - handle = data_to_ptr (pair->value); - if (!handle) { - pair = pair->next; - continue; - } - - list_add_tail (&(handle->vol_opt->list), - &(xl->volume_options)); - ret = validate_xlator_volume_options (xl, - handle->vol_opt->given_opt); - if (ret) - gf_log ("authenticate", GF_LOG_ERROR, - "volume option validation failed"); - - pair = pair->next; - } + ret = dict_foreach (auth_modules, _gf_auth_option_validate, xl); out: if (ret) { @@ -155,7 +165,7 @@ out: static dict_t *__input_params; static dict_t *__config_params; -void +int map (dict_t *this, char *key, data_t *value, void *data) { dict_t *res = data; @@ -170,15 +180,16 @@ map (dict_t *this, char *key, data_t *value, void *data) } else { dict_set (res, key, int_to_data (AUTH_DONT_CARE)); } + return 0; } -void +int reduce (dict_t *this, char *key, data_t *value, void *data) { int64_t val = 0; int64_t *res = data; if (!data) - return; + return 0; val = data_to_int64 (value); switch (val) @@ -195,6 +206,7 @@ reduce (dict_t *this, char *key, data_t *value, void *data) case AUTH_DONT_CARE: break; } + return 0; } |
