[PATCH 6/6] Move wbc global variables into global context instead
Volker Lendecke
Volker.Lendecke at SerNet.DE
Tue Feb 24 04:22:29 MST 2015
On Mon, Feb 23, 2015 at 01:21:05AM +0000, Matthew Newton wrote:
> There are some global variables in use in the libwbclient
> library. Now that we have a context, move these into it so that
> they are thread-safe when the wbcCtx* functions are used.
>
> Signed-off-by: Matthew Newton <matthew-git at newtoncomputing.co.uk>
> ---
> nsswitch/libwbclient/wbc_pwd.c | 127 ++++++++++++++++++------------
> nsswitch/libwbclient/wbclient.c | 9 +++
> nsswitch/libwbclient/wbclient.h | 4 +
> nsswitch/libwbclient/wbclient_internal.h | 2 +
> 4 files changed, 90 insertions(+), 52 deletions(-)
>
> diff --git a/nsswitch/libwbclient/wbc_pwd.c b/nsswitch/libwbclient/wbc_pwd.c
> index 0b05133..3bf437c 100644
> --- a/nsswitch/libwbclient/wbc_pwd.c
> +++ b/nsswitch/libwbclient/wbc_pwd.c
> @@ -4,6 +4,7 @@
> Winbind client API
>
> Copyright (C) Gerald (Jerry) Carter 2007
> + Copyright (C) Matthew Newton 2015
>
>
> This library is free software; you can redistribute it and/or
> @@ -359,28 +360,24 @@ wbcErr wbcGetgrgid(gid_t gid, struct group **grp)
> return wbcCtxGetgrgid(NULL, gid, grp);
> }
>
> -/** @brief Number of cached passwd structs
> - *
> - */
> -static uint32_t pw_cache_size;
> -
> -/** @brief Position of the pwent context
> - *
> - */
> -static uint32_t pw_cache_idx;
> -
> /** @brief Winbindd response containing the passwd structs
> *
> */
> static struct winbindd_response pw_response;
>
> /* Reset the passwd iterator */
> -wbcErr wbcCtxSetpwent(struct wbcContext *ctx)
> +wbcErr wbcCtxSetpwent(struct wbcContext *_ctx)
> {
> wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
> + struct wbcContext *ctx;
>
> - if (pw_cache_size > 0) {
> - pw_cache_idx = pw_cache_size = 0;
> + ctx = _ctx;
> + if (!ctx) {
> + ctx = &wbcGlobalCtx;
> + }
> +
> + if (ctx->pw_cache_size > 0) {
> + ctx->pw_cache_idx = ctx->pw_cache_size = 0;
> winbindd_free_response(&pw_response);
> }
>
> @@ -400,12 +397,18 @@ wbcErr wbcSetpwent(void)
> }
>
> /* Close the passwd iterator */
> -wbcErr wbcCtxEndpwent(struct wbcContext *ctx)
> +wbcErr wbcCtxEndpwent(struct wbcContext *_ctx)
> {
> wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
> + struct wbcContext *ctx;
> +
> + ctx = _ctx;
> + if (!ctx) {
> + ctx = &wbcGlobalCtx;
> + }
Can you explain the reason behind the _ctx and ctx?
Thanks,
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
More information about the samba-technical
mailing list