summaryrefslogtreecommitdiff
path: root/nsswitch
diff options
context:
space:
mode:
authorRalph Wuerthner <ralph.wuerthner@de.ibm.com>2018-10-02 13:35:16 +0200
committerJeremy Allison <jra@samba.org>2018-11-01 01:59:10 +0100
commite82b3ac0ae5b50993db3c85d77dd317f957beb7e (patch)
tree1661813a9aed0e85c295b3e464a5f64c108ab2c5 /nsswitch
parent2cfb58d7535e63c5ef9f3970ebaa189741b715cb (diff)
downloadsamba-e82b3ac0ae5b50993db3c85d77dd317f957beb7e.tar.gz
nsswitch: make wb_global_ctx private add add get/put functions to access global context
Signed-off-by: Ralph Wuerthner <ralph.wuerthner@de.ibm.com> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'nsswitch')
-rw-r--r--nsswitch/wb_common.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c
index c2f67d7a556..9ba74c35a6d 100644
--- a/nsswitch/wb_common.c
+++ b/nsswitch/wb_common.c
@@ -35,11 +35,22 @@ struct winbindd_context {
pid_t our_pid; /* calling process pid */
};
-static struct winbindd_context wb_global_ctx = {
- .winbindd_fd = -1,
- .is_privileged = false,
- .our_pid = 0
-};
+static struct winbindd_context *get_wb_global_ctx(void)
+{
+ static struct winbindd_context wb_global_ctx = {
+ .winbindd_fd = -1,
+ .is_privileged = false,
+ .our_pid = 0
+ };
+
+ return &wb_global_ctx;
+}
+
+static void put_wb_global_ctx(void)
+{
+ /* noop for now */
+ return;
+}
/* Free a response structure */
@@ -93,7 +104,11 @@ __attribute__((destructor))
#endif
static void winbind_destructor(void)
{
- winbind_close_sock(&wb_global_ctx);
+ struct winbindd_context *ctx;
+
+ ctx = get_wb_global_ctx();
+ winbind_close_sock(ctx);
+ put_wb_global_ctx();
}
#define CONNECT_TIMEOUT 30
@@ -725,9 +740,11 @@ NSS_STATUS winbindd_request_response(struct winbindd_context *ctx,
struct winbindd_response *response)
{
NSS_STATUS status = NSS_STATUS_UNAVAIL;
+ bool release_global_ctx = false;
if (ctx == NULL) {
- ctx = &wb_global_ctx;
+ ctx = get_wb_global_ctx();
+ release_global_ctx = true;
}
status = winbindd_send_request(ctx, req_type, 0, request);
@@ -737,6 +754,9 @@ NSS_STATUS winbindd_request_response(struct winbindd_context *ctx,
status = winbindd_get_response(ctx, response);
out:
+ if (release_global_ctx) {
+ put_wb_global_ctx();
+ }
return status;
}
@@ -746,9 +766,11 @@ NSS_STATUS winbindd_priv_request_response(struct winbindd_context *ctx,
struct winbindd_response *response)
{
NSS_STATUS status = NSS_STATUS_UNAVAIL;
+ bool release_global_ctx = false;
if (ctx == NULL) {
- ctx = &wb_global_ctx;
+ ctx = get_wb_global_ctx();
+ release_global_ctx = true;
}
status = winbindd_send_request(ctx, req_type, 1, request);
@@ -758,6 +780,9 @@ NSS_STATUS winbindd_priv_request_response(struct winbindd_context *ctx,
status = winbindd_get_response(ctx, response);
out:
+ if (release_global_ctx) {
+ put_wb_global_ctx();
+ }
return status;
}