Skip to content

Commit 6050919

Browse files
committed
Add option to map GSS Name to local Name
Always preserves the received name in GSS_NAME. In the kereberos case this will result in the environment variable called GSS_NAME the user's principal, while REMOTE_USER will contain the user name as mapped by the kerberos library.
1 parent 8498340 commit 6050919

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/mod_auth_gssapi.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module AP_MODULE_DECLARE_DATA mag_module;
3838

3939
struct mag_config {
4040
bool ssl_only;
41+
bool map_to_local;
4142
gss_key_value_set_desc cred_store;
4243
};
4344

@@ -100,6 +101,9 @@ static int mag_auth(request_rec *req)
100101
uint32_t maj, min;
101102
char *reply;
102103
size_t replen;
104+
char *clientname;
105+
gss_OID mech_type = GSS_C_NO_OID;
106+
gss_buffer_desc lname = GSS_C_EMPTY_BUFFER;
103107

104108
type = ap_auth_type(req);
105109
if ((type == NULL) || (strcasecmp(type, "GSSAPI") != 0)) {
@@ -132,7 +136,7 @@ static int mag_auth(request_rec *req)
132136
* should work with Krb, will fail with NTLMSSP */
133137
maj = gss_accept_sec_context(&min, &ctx, GSS_C_NO_CREDENTIAL,
134138
&input, GSS_C_NO_CHANNEL_BINDINGS,
135-
&client, NULL, &output, &flags, NULL,
139+
&client, &mech_type, &output, &flags, NULL,
136140
&delegated_cred);
137141
if (GSS_ERROR(maj)) {
138142
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
@@ -170,7 +174,22 @@ static int mag_auth(request_rec *req)
170174
#endif
171175

172176
req->ap_auth_type = apr_pstrdup(req->pool, "Negotiate");
173-
req->user = apr_pstrndup(req->pool, name.value, name.length);
177+
178+
/* Always set the GSS name in an env var */
179+
clientname = apr_pstrndup(req->pool, name.value, name.length);
180+
apr_table_set(req->subprocess_env, "GSS_NAME", clientname);
181+
182+
if (cfg->map_to_local) {
183+
maj = gss_localname(&min, client, mech_type, &lname);
184+
if (maj != GSS_S_COMPLETE) {
185+
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
186+
mag_error(req, "gss_localname() failed", maj, min));
187+
goto done;
188+
}
189+
req->user = apr_pstrndup(req->pool, lname.value, lname.length);
190+
} else {
191+
req->user = clientname;
192+
}
174193
ret = OK;
175194

176195
done:
@@ -182,6 +201,7 @@ static int mag_auth(request_rec *req)
182201
gss_release_name(&min, &client);
183202
gss_release_buffer(&min, &name);
184203
gss_delete_sec_context(&min, &ctx, GSS_C_NO_BUFFER);
204+
gss_release_buffer(&min, &lname);
185205
return ret;
186206
}
187207

@@ -203,6 +223,13 @@ static const char *mag_ssl_only(cmd_parms *parms, void *mconfig, int on)
203223
return NULL;
204224
}
205225

226+
static const char *mag_map_to_local(cmd_parms *parms, void *mconfig, int on)
227+
{
228+
struct mag_config *cfg = (struct mag_config *)mconfig;
229+
cfg->map_to_local = on ? true : false;
230+
return NULL;
231+
}
232+
206233
static const char *mag_cred_store(cmd_parms *parms, void *mconfig,
207234
const char *w)
208235
{
@@ -252,6 +279,8 @@ static const char *mag_cred_store(cmd_parms *parms, void *mconfig,
252279
static const command_rec mag_commands[] = {
253280
AP_INIT_FLAG("GSSSSLOnly", mag_ssl_only, NULL, OR_AUTHCFG,
254281
"Work only if connection is SSL Secured"),
282+
AP_INIT_FLAG("GSSLocalName", mag_map_to_local, NULL, OR_AUTHCFG,
283+
"Work only if connection is SSL Secured"),
255284
AP_INIT_ITERATE("GSSCredStore", mag_cred_store, NULL, OR_AUTHCFG,
256285
"Credential Store"),
257286
{ NULL }

0 commit comments

Comments
 (0)