>From 2a5888f0d4db494ce5e249e72b789d2d3d50bd37 Mon Sep 17 00:00:00 2001 From: Matthew Newton Date: Sat, 21 Feb 2015 00:19:32 +0000 Subject: [PATCH 3/7] Add wbcContext struct, create and free functions The basic context structure and functions for libwbclient so that libwbclient can be made thread-safe. Signed-off-by: Matthew Newton --- nsswitch/libwbclient/wbclient.c | 45 ++++++++++++++++++++++++++++++ nsswitch/libwbclient/wbclient.h | 30 ++++++++++++++++++++ nsswitch/libwbclient/wbclient_internal.h | 4 +++ 3 files changed, 79 insertions(+) diff --git a/nsswitch/libwbclient/wbclient.c b/nsswitch/libwbclient/wbclient.c index 93c0318e..c7def15 100644 --- a/nsswitch/libwbclient/wbclient.c +++ b/nsswitch/libwbclient/wbclient.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 @@ -27,6 +28,8 @@ /* From wb_common.c */ +struct winbindd_context; + NSS_STATUS winbindd_request_response(struct winbindd_context *wbctx, int req_type, struct winbindd_request *request, @@ -35,6 +38,9 @@ NSS_STATUS winbindd_priv_request_response(struct winbindd_context *wbctx, int req_type, struct winbindd_request *request, struct winbindd_response *response); +struct winbindd_context *winbindd_ctx_create(void); +void winbindd_ctx_free(struct winbindd_context *ctx); + /* result == NSS_STATUS_UNAVAIL: winbind not around @@ -259,3 +265,42 @@ wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details) *_details = info; return WBC_ERR_SUCCESS; } + +/* Context handling functions */ + +static void wbcContextDestructor(void *ptr) +{ + struct wbcContext *ctx = (struct wbcContext *)ptr; + + winbindd_ctx_free(ctx->winbindd_ctx); +} + +struct wbcContext *wbcCtxCreate(void) +{ + struct wbcContext *ctx; + struct winbindd_context *wbctx; + + ctx = (struct wbcContext *)wbcAllocateMemory( + 1, sizeof(struct wbcContext), wbcContextDestructor); + + if (!ctx) { + return NULL; + } + + wbctx = winbindd_ctx_create(); + + if (!wbctx) { + wbcFreeMemory(ctx); + return NULL; + } + + ctx->winbindd_ctx = wbctx; + + return ctx; +} + +void wbcCtxFree(struct wbcContext *ctx) +{ + wbcFreeMemory(ctx); +} + diff --git a/nsswitch/libwbclient/wbclient.h b/nsswitch/libwbclient/wbclient.h index dc3e822..265cf43 100644 --- a/nsswitch/libwbclient/wbclient.h +++ b/nsswitch/libwbclient/wbclient.h @@ -5,6 +5,7 @@ Copyright (C) Gerald (Jerry) Carter 2007 Copyright (C) Volker Lendecke 2009 + Copyright (C) Matthew Newton 2015 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -94,6 +95,13 @@ struct wbcInterfaceDetails { char *dns_domain; }; +/** + * @brief Library context data + * + **/ + +struct wbcContext; + /* * Data types used by the Winbind Client API */ @@ -523,6 +531,28 @@ struct wbcDomainControllerInfoEx { void wbcFreeMemory(void*); +/********************************************************** + * Context Management + **********************************************************/ + +/** + * @brief Create a new wbcContext context + * + * @return wbcContext + **/ +struct wbcContext *wbcCtxCreate(void); + +/** + * @brief Free a library context + * + * @param ctx wbcContext to free + * + * @return void + **/ +void wbcCtxFree(struct wbcContext *ctx); + + + /* * Utility functions for dealing with SIDs */ diff --git a/nsswitch/libwbclient/wbclient_internal.h b/nsswitch/libwbclient/wbclient_internal.h index 31f4130..e55bf27 100644 --- a/nsswitch/libwbclient/wbclient_internal.h +++ b/nsswitch/libwbclient/wbclient_internal.h @@ -22,6 +22,10 @@ #ifndef _WBCLIENT_INTERNAL_H #define _WBCLIENT_INTERNAL_H +struct wbcContext { + struct winbindd_context *winbindd_ctx; +}; + /* Private functions */ wbcErr wbcRequestResponse(int cmd, -- 1.7.10.4