Skip to content

Commit 574d469

Browse files
committed
Set context data on the pool with a destructor
This way the context is available for the duration of the connection. It is also properly freed if the connection is interrupted before the context is fully established.
1 parent 2d095d2 commit 574d469

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/mod_auth_gssapi.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static int mag_post_config(apr_pool_t *cfg, apr_pool_t *log,
100100

101101

102102
struct mag_conn {
103+
apr_pool_t *parent;
103104
gss_ctx_id_t ctx;
104105
bool established;
105106
char *user_name;
@@ -113,10 +114,23 @@ static int mag_pre_connection(conn_rec *c, void *csd)
113114
mc = apr_pcalloc(c->pool, sizeof(struct mag_conn));
114115
if (!mc) return DECLINED;
115116

117+
mc->parent = c->pool;
116118
ap_set_module_config(c->conn_config, &auth_gssapi_module, (void*)mc);
117119
return OK;
118120
}
119121

122+
static apr_status_t mag_conn_destroy(void *ptr)
123+
{
124+
struct mag_conn *mc = (struct mag_conn *)ptr;
125+
uint32_t min;
126+
127+
if (mc->ctx) {
128+
(void)gss_delete_sec_context(&min, &mc->ctx, GSS_C_NO_BUFFER);
129+
mc->established = false;
130+
}
131+
return APR_SUCCESS;
132+
}
133+
120134
static bool mag_conn_is_https(conn_rec *c)
121135
{
122136
if (mag_is_https) {
@@ -212,6 +226,10 @@ static int mag_auth(request_rec *req)
212226
goto done;
213227
}
214228

229+
/* register the context in the connection pool, so it can be freed
230+
* when the connection is terminated */
231+
apr_pool_userdata_set(mc, "mag_conn_ptr", mag_conn_destroy, mc->parent);
232+
215233
if (maj == GSS_S_CONTINUE_NEEDED) {
216234
if (!cfg->gss_conn_ctx) {
217235
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
@@ -224,11 +242,6 @@ static int mag_auth(request_rec *req)
224242
goto done;
225243
}
226244

227-
/* once the connection has been accepted we do not need the context
228-
* anymore, discard it. FIXME: we also need a destructor for those
229-
* mechanisms (like NTLMSSP) that do not complete in one step */
230-
gss_delete_sec_context(&min, pctx, GSS_C_NO_BUFFER);
231-
232245
#ifdef HAVE_GSS_STORE_CRED_INTO
233246
if (cfg->cred_store && delegated_cred != GSS_C_NO_CREDENTIAL) {
234247
gss_key_value_set_desc store = {0, NULL};
@@ -265,8 +278,8 @@ static int mag_auth(request_rec *req)
265278
}
266279

267280
if (mc) {
268-
mc->user_name = apr_pstrdup(req->connection->pool, req->user);
269-
mc->gss_name = apr_pstrdup(req->connection->pool, clientname);
281+
mc->user_name = apr_pstrdup(mc->parent, req->user);
282+
mc->gss_name = apr_pstrdup(mc->parent, clientname);
270283
mc->established = true;
271284
}
272285

0 commit comments

Comments
 (0)