Skip to content

Commit 1348c92

Browse files
committed
Make per thread winbind context optional
By default proceed to acquire a new context for each operation that needs it. High performance programs that have full control of their thread usage and can afford one socket per thread can set the GSSNTLMSSP_WB_TLS_CTX environment variable. Signed-off-by: Simo Sorce <[email protected]>
1 parent d55c0e5 commit 1348c92

File tree

11 files changed

+156
-43
lines changed

11 files changed

+156
-43
lines changed

conf_macros.m4

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,20 @@ AC_DEFUN([WITH_WBCLIENT],
8585
8686
AM_CONDITIONAL([BUILD_WBCLIENT], [test x"$with_wbclient" = xyes])
8787
])
88+
89+
AC_DEFUN([WITH_WINBIND_TLS_CONTEXT],
90+
[
91+
AC_ARG_WITH([winbind-tls-context],
92+
[AC_HELP_STRING([--with-winbind-tls-context],
93+
[Whether to default to thread local storage for winbind contexts [no]])
94+
],
95+
[with_winbind_tls_context=$withval],
96+
with_winbind_tls_context=no)
97+
98+
if test x"$with_winbind_tls_context" = xyes; then
99+
AC_DEFINE(DEFAULT_WB_TLS_CTX, 1,
100+
[whether to default to thread local storage for winbind contexts S])
101+
fi
102+
AM_CONDITIONAL([DEFAULT_WB_TLS_CTX], [test x"$with_winbind_tls_context" = xyes])
103+
])
104+

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ WITH_TEST_DIR
5353
WITH_MANPAGES
5454
WITH_XML_CATALOG
5555
WITH_WBCLIENT
56+
WITH_WINBIND_TLS_CONTEXT
5657

5758
m4_include([external/pkg.m4])
5859
m4_include([external/docbook.m4])

src/external.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,54 @@
88
#include "gss_ntlmssp_winbind.h"
99
#endif
1010

11-
uint32_t external_netbios_get_names(char **computer, char **domain)
11+
void *external_get_context(void)
1212
{
1313
#if HAVE_WBCLIENT
14-
return winbind_get_names(computer, domain);
14+
return winbind_get_context();
15+
#else
16+
return NULL;
17+
#endif
18+
}
19+
20+
void external_free_context(void *ctx)
21+
{
22+
#if HAVE_WBCLIENT
23+
winbind_free_context(ctx);
24+
#else
25+
return;
26+
#endif
27+
}
28+
29+
uint32_t external_netbios_get_names(void *ctx, char **computer, char **domain)
30+
{
31+
#if HAVE_WBCLIENT
32+
return winbind_get_names(ctx, computer, domain);
1533
#else
1634
return ERR_NOTAVAIL;
1735
#endif
1836
}
1937

20-
uint32_t external_get_creds(struct gssntlm_name *name,
38+
uint32_t external_get_creds(void *ctx,
39+
struct gssntlm_name *name,
2140
struct gssntlm_cred *cred)
2241
{
42+
void *ectx = NULL;
43+
uint32_t ret;
44+
45+
if (ctx == NULL) {
46+
ectx = external_get_context();
47+
} else {
48+
ectx = ctx;
49+
}
2350
#if HAVE_WBCLIENT
24-
return winbind_get_creds(name, cred);
51+
ret = winbind_get_creds(ectx, name, cred);
2552
#else
26-
return ERR_NOTAVAIL;
53+
ret = ERR_NOTAVAIL;
2754
#endif
55+
if (ctx == NULL) {
56+
external_free_context(ectx);
57+
}
58+
return ret;
2859
}
2960

3061
uint32_t external_cli_auth(struct gssntlm_ctx *ctx,
@@ -33,7 +64,8 @@ uint32_t external_cli_auth(struct gssntlm_ctx *ctx,
3364
gss_channel_bindings_t input_chan_bindings)
3465
{
3566
#if HAVE_WBCLIENT
36-
return winbind_cli_auth(cred->cred.external.user.data.user.name,
67+
return winbind_cli_auth(ctx->external_context,
68+
cred->cred.external.user.data.user.name,
3769
cred->cred.external.user.data.user.domain,
3870
input_chan_bindings,
3971
in_flags, &ctx->neg_flags,
@@ -70,7 +102,8 @@ uint32_t external_srv_auth(struct gssntlm_ctx *ctx,
70102
chal_ptr = ctx->server_chal;
71103
}
72104

73-
return winbind_srv_auth(cred->cred.external.user.data.user.name,
105+
return winbind_srv_auth(ctx->external_context,
106+
cred->cred.external.user.data.user.name,
74107
cred->cred.external.user.data.user.domain,
75108
ctx->workstation, chal_ptr,
76109
nt_chal_resp, lm_chal_resp, session_base_key,

src/gss_creds.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ void gssntlm_int_release_cred(struct gssntlm_cred *cred)
401401
}
402402

403403
uint32_t gssntlm_acquire_cred_from(uint32_t *minor_status,
404+
void *external_context,
404405
gss_name_t desired_name,
405406
uint32_t time_req,
406407
gss_OID_set desired_mechs,
@@ -464,7 +465,7 @@ uint32_t gssntlm_acquire_cred_from(uint32_t *minor_status,
464465
}
465466
if (retmin) {
466467
uint32_t ret;
467-
ret = external_get_creds(name, cred);
468+
ret = external_get_creds(external_context, name, cred);
468469
if (ret != ERR_NOTAVAIL) {
469470
retmin = ret;
470471
}
@@ -520,7 +521,7 @@ uint32_t gssntlm_acquire_cred(uint32_t *minor_status,
520521
gss_OID_set *actual_mechs,
521522
uint32_t *time_rec)
522523
{
523-
return gssntlm_acquire_cred_from(minor_status,
524+
return gssntlm_acquire_cred_from(minor_status, NULL,
524525
desired_name,
525526
time_req,
526527
desired_mechs,
@@ -563,7 +564,7 @@ uint32_t gssntlm_acquire_cred_with_password(uint32_t *minor_status,
563564
cred_store.count = 1;
564565
cred_store.elements = &element;
565566

566-
return gssntlm_acquire_cred_from(minor_status,
567+
return gssntlm_acquire_cred_from(minor_status, NULL,
567568
desired_name,
568569
time_req,
569570
desired_mechs,
@@ -586,7 +587,7 @@ uint32_t gssntlm_inquire_cred(uint32_t *minor_status,
586587
uint32_t maj, min;
587588

588589
if (cred_handle == GSS_C_NO_CREDENTIAL) {
589-
maj = gssntlm_acquire_cred_from(&min,
590+
maj = gssntlm_acquire_cred_from(&min, NULL,
590591
NULL, GSS_C_INDEFINITE,
591592
NULL, GSS_C_INITIATE,
592593
GSS_C_NO_CRED_STORE,

src/gss_names.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ uint32_t gssntlm_localname(uint32_t *minor_status,
713713
return GSSERR();
714714
}
715715

716-
uint32_t netbios_get_names(char *computer_name,
716+
uint32_t netbios_get_names(void *ctx, char *computer_name,
717717
char **netbios_host, char **netbios_domain)
718718
{
719719
char *nb_computer_name = NULL;
@@ -741,7 +741,7 @@ uint32_t netbios_get_names(char *computer_name,
741741

742742
if (!nb_computer_name || !nb_domain_name) {
743743
/* fetch only mising ones */
744-
ret = external_netbios_get_names(
744+
ret = external_netbios_get_names(ctx,
745745
nb_computer_name ? NULL : &nb_computer_name,
746746
nb_domain_name ? NULL : &nb_domain_name);
747747
if ((ret != 0) &&

src/gss_ntlmssp.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ struct gssntlm_ctx {
136136

137137
uint32_t int_flags;
138138
time_t expiration_time;
139+
140+
void *external_context;
139141
};
140142

141143
#define set_GSSERRS(min, maj) \
@@ -189,8 +191,11 @@ void gssntlm_release_attrs(struct gssntlm_name_attribute **attrs);
189191
int gssntlm_copy_name(struct gssntlm_name *src, struct gssntlm_name *dst);
190192
int gssntlm_copy_creds(struct gssntlm_cred *in, struct gssntlm_cred *out);
191193

192-
uint32_t external_netbios_get_names(char **computer, char **domain);
193-
uint32_t external_get_creds(struct gssntlm_name *name,
194+
void *external_get_context(void);
195+
void external_free_context(void *ctx);
196+
uint32_t external_netbios_get_names(void *ctx, char **computer, char **domain);
197+
uint32_t external_get_creds(void *ctx,
198+
struct gssntlm_name *name,
194199
struct gssntlm_cred *cred);
195200
uint32_t external_cli_auth(struct gssntlm_ctx *ctx,
196201
struct gssntlm_cred *cred,
@@ -202,7 +207,7 @@ uint32_t external_srv_auth(struct gssntlm_ctx *ctx,
202207
struct ntlm_buffer *lm_chal_resp,
203208
struct ntlm_key *session_base_key);
204209

205-
uint32_t netbios_get_names(char *computer_name,
210+
uint32_t netbios_get_names(void *ctx, char *computer_name,
206211
char **netbios_host, char **netbios_domain);
207212

208213
bool is_ntlm_v1(struct ntlm_buffer *nt_chal_resp);
@@ -232,6 +237,7 @@ uint32_t gssntlm_acquire_cred(uint32_t *minor_status,
232237
uint32_t *time_rec);
233238

234239
uint32_t gssntlm_acquire_cred_from(uint32_t *minor_status,
240+
void *external_context,
235241
gss_name_t desired_name,
236242
uint32_t time_req,
237243
gss_OID_set desired_mechs,

src/gss_ntlmssp_winbind.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
/* Copyright (C) 2014 GSS-NTLMSSP contributors, see COPYING for License */
22

3-
uint32_t winbind_get_names(char **computer, char **domain);
3+
void *winbind_get_context(void);
4+
void winbind_free_context(void *ectx);
45

5-
uint32_t winbind_get_creds(struct gssntlm_name *name,
6+
uint32_t winbind_get_names(void *ectx, char **computer, char **domain);
7+
8+
uint32_t winbind_get_creds(void *ectx,
9+
struct gssntlm_name *name,
610
struct gssntlm_cred *cred);
711

8-
uint32_t winbind_cli_auth(char *user, char *domain,
12+
uint32_t winbind_cli_auth(void *ectx, char *user, char *domain,
913
gss_channel_bindings_t input_chan_bindings,
1014
uint32_t in_flags,
1115
uint32_t *neg_flags,
1216
struct ntlm_buffer *nego_msg,
1317
struct ntlm_buffer *chal_msg,
1418
struct ntlm_buffer *auth_msg,
1519
struct ntlm_key *exported_session_key);
16-
uint32_t winbind_srv_auth(char *user, char *domain,
20+
21+
uint32_t winbind_srv_auth(void *ectx, char *user, char *domain,
1722
char *workstation, uint8_t *challenge,
1823
struct ntlm_buffer *nt_chal_resp,
1924
struct ntlm_buffer *lm_chal_resp,

src/gss_sec_ctx.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ uint32_t gssntlm_init_sec_context(uint32_t *minor_status,
9797
goto done;
9898
}
9999

100+
ctx->external_context = external_get_context();
101+
100102
retmin = gssntlm_copy_name(&cred->cred.user.user,
101103
&ctx->source_name);
102104
if (retmin) {
@@ -169,7 +171,7 @@ uint32_t gssntlm_init_sec_context(uint32_t *minor_status,
169171
goto done;
170172
}
171173

172-
retmin = netbios_get_names(computer_name,
174+
retmin = netbios_get_names(ctx->external_context, computer_name,
173175
&nb_computer_name, &nb_domain_name);
174176
if (retmin) {
175177
set_GSSERR(retmin);
@@ -476,6 +478,8 @@ uint32_t gssntlm_delete_sec_context(uint32_t *minor_status,
476478

477479
ntlm_release_rc4_state(&ctx->crypto_state);
478480

481+
external_free_context(ctx->external_context);
482+
479483
safezero((uint8_t *)ctx, sizeof(struct gssntlm_ctx));
480484
safefree(*context_handle);
481485

@@ -593,6 +597,8 @@ uint32_t gssntlm_accept_sec_context(uint32_t *minor_status,
593597
goto done;
594598
}
595599

600+
ctx->external_context = external_get_context();
601+
596602
/* acquire our own name */
597603
if (!server_name) {
598604
gss_buffer_desc tmpbuf;
@@ -618,7 +624,7 @@ uint32_t gssntlm_accept_sec_context(uint32_t *minor_status,
618624
goto done;
619625
}
620626

621-
retmin = netbios_get_names(computer_name,
627+
retmin = netbios_get_names(ctx->external_context, computer_name,
622628
&nb_computer_name, &nb_domain_name);
623629
if (retmin) {
624630
set_GSSERR(retmin);
@@ -894,7 +900,7 @@ uint32_t gssntlm_accept_sec_context(uint32_t *minor_status,
894900
cred_store = &cs;
895901
}
896902

897-
retmaj = gssntlm_acquire_cred_from(&retmin,
903+
retmaj = gssntlm_acquire_cred_from(&retmin, ctx->external_context,
898904
(gss_name_t)gss_usrname,
899905
GSS_C_INDEFINITE,
900906
GSS_C_NO_OID_SET,

src/gss_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ OM_uint32 gss_acquire_cred_from(OM_uint32 *minor_status,
5353
gss_OID_set *actual_mechs,
5454
OM_uint32 *time_rec)
5555
{
56-
return gssntlm_acquire_cred_from(minor_status,
56+
return gssntlm_acquire_cred_from(minor_status, NULL,
5757
desired_name,
5858
time_req,
5959
desired_mechs,

0 commit comments

Comments
 (0)