[PATCH 3/6] Add wbcContext struct, create and free functions
Matthew Newton
mcn4 at leicester.ac.uk
Sun Feb 22 18:20:08 MST 2015
The basic context structure and functions for libwbclient so that
libwbclient can be made thread-safe.
Signed-off-by: Matthew Newton <matthew-git at newtoncomputing.co.uk>
---
nsswitch/libwbclient/wbclient.c | 43 +++++++++++++++++++++++++++++++++++++++
nsswitch/libwbclient/wbclient.h | 33 ++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
diff --git a/nsswitch/libwbclient/wbclient.c b/nsswitch/libwbclient/wbclient.c
index 93c0318e..c02f976 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
@@ -35,6 +36,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 +263,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((struct winbindd_context *) 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 = (void *) wbctx;
+
+ return ctx;
+}
+
+void wbcCtxFree(struct wbcContext *ctx)
+{
+ wbcFreeMemory(ctx);
+}
+
diff --git a/nsswitch/libwbclient/wbclient.h b/nsswitch/libwbclient/wbclient.h
index dc3e822..42c6273 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
@@ -71,6 +72,7 @@ const char *wbcErrorString(wbcErr error);
* 0.9: Added support for WBC_ID_TYPE_BOTH
* 0.10: Added wbcPingDc2()
* 0.11: Extended wbcAuthenticateUserEx to provide PAC parsing
+ * 0.12: Added wbcCtxCreate and friends
**/
#define WBCLIENT_MAJOR_VERSION 0
#define WBCLIENT_MINOR_VERSION 11
@@ -94,6 +96,15 @@ struct wbcInterfaceDetails {
char *dns_domain;
};
+/**
+ * @brief Library context data
+ *
+ **/
+
+struct wbcContext {
+ void *winbindd_ctx; /* winbindd context */
+};
+
/*
* Data types used by the Winbind Client API
*/
@@ -523,6 +534,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
*/
--
1.7.10.4
--
Matthew Newton, Ph.D. <mcn4 at le.ac.uk>
Systems Specialist, Infrastructure Services,
I.T. Services, University of Leicester, Leicester LE1 7RH, United Kingdom
For IT help contact helpdesk extn. 2253, <ithelp at le.ac.uk>
More information about the samba-technical
mailing list