@@ -407,7 +407,6 @@ static bool mag_auth_basic(request_rec *req,
407
407
gss_cred_id_t acquired_cred = GSS_C_NO_CREDENTIAL ;
408
408
gss_buffer_desc input = GSS_C_EMPTY_BUFFER ;
409
409
gss_buffer_desc output = GSS_C_EMPTY_BUFFER ;
410
- gss_OID_set indicated_mechs = GSS_C_NO_OID_SET ;
411
410
gss_OID_set allowed_mechs ;
412
411
gss_OID_set filtered_mechs ;
413
412
gss_OID_set actual_mechs = GSS_C_NO_OID_SET ;
@@ -430,24 +429,19 @@ static bool mag_auth_basic(request_rec *req,
430
429
} else if (cfg -> allowed_mechs ) {
431
430
allowed_mechs = cfg -> allowed_mechs ;
432
431
} else {
432
+ struct mag_server_config * scfg ;
433
433
/* Try to fetch the default set if not explicitly configured,
434
434
* We need to do this because gss_acquire_cred_with_password()
435
435
* is currently limited to acquire creds for a single "default"
436
436
* mechanism if no desired mechanisms are passed in. This causes
437
437
* authentication to fail for secondary mechanisms as no user
438
438
* credentials are generated for those. */
439
- maj = gss_indicate_mechs (& min , & indicated_mechs );
440
- if (maj != GSS_S_COMPLETE ) {
441
- ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , req , "%s" ,
442
- mag_error (req , "gss_indicate_mechs() failed" ,
443
- maj , min ));
444
- /* if indicated _mechs failed, set GSS_C_NO_OID_SET. This
445
- * generally causes only the krb5 mechanism to be tried due
446
- * to implementation constraints, but may change in future. */
447
- allowed_mechs = GSS_C_NO_OID_SET ;
448
- } else {
449
- allowed_mechs = indicated_mechs ;
450
- }
439
+ scfg = ap_get_module_config (req -> server -> module_config ,
440
+ & auth_gssapi_module );
441
+ /* In the worst case scenario default_mechs equals to GSS_C_NO_OID_SET.
442
+ * This generally causes only the krb5 mechanism to be tried due
443
+ * to implementation constraints, but may change in future. */
444
+ allowed_mechs = scfg -> default_mechs ;
451
445
}
452
446
453
447
/* Remove Spnego if present, or we'd repeat failed authentiations
@@ -461,19 +455,14 @@ static bool mag_auth_basic(request_rec *req,
461
455
* multiple times uselessly.
462
456
*/
463
457
filtered_mechs = mag_filter_unwanted_mechs (allowed_mechs );
464
- if ((allowed_mechs != GSS_C_NO_OID_SET ) &&
465
- (filtered_mechs == GSS_C_NO_OID_SET )) {
458
+ if (filtered_mechs == allowed_mechs ) {
459
+ /* in case filtered_mechs was not allocated here don't free it */
460
+ filtered_mechs = GSS_C_NO_OID_SET ;
461
+ } else if (filtered_mechs == GSS_C_NO_OID_SET ) {
466
462
ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , req , "Fatal "
467
463
"failure while filtering mechs, aborting" );
468
464
goto done ;
469
- } else if (filtered_mechs != allowed_mechs ) {
470
- /* if indicated_mechs where sourced then free them here before
471
- * reusing the pointer */
472
- gss_release_oid_set (& min , & indicated_mechs );
473
-
474
- /* mark the list of mechs needs to be freed */
475
- indicated_mechs = filtered_mechs ;
476
-
465
+ } else {
477
466
/* use the filtered list */
478
467
allowed_mechs = filtered_mechs ;
479
468
}
@@ -611,7 +600,7 @@ static bool mag_auth_basic(request_rec *req,
611
600
gss_release_cred (& min , & user_cred );
612
601
gss_delete_sec_context (& min , & user_ctx , GSS_C_NO_BUFFER );
613
602
gss_release_oid_set (& min , & actual_mechs );
614
- gss_release_oid_set (& min , & indicated_mechs );
603
+ gss_release_oid_set (& min , & filtered_mechs );
615
604
#ifdef HAVE_GSS_KRB5_CCACHE_NAME
616
605
if (user_ccache != NULL ) {
617
606
maj = gss_krb5_ccache_name (& min , orig_ccache , NULL );
@@ -653,7 +642,6 @@ static int mag_auth(request_rec *req)
653
642
char * clientname ;
654
643
gss_OID mech_type = GSS_C_NO_OID ;
655
644
gss_OID_set desired_mechs = GSS_C_NO_OID_SET ;
656
- gss_OID_set indicated_mechs = GSS_C_NO_OID_SET ;
657
645
gss_buffer_desc lname = GSS_C_EMPTY_BUFFER ;
658
646
struct mag_conn * mc = NULL ;
659
647
time_t expiration ;
@@ -669,14 +657,11 @@ static int mag_auth(request_rec *req)
669
657
if (cfg -> allowed_mechs ) {
670
658
desired_mechs = cfg -> allowed_mechs ;
671
659
} else {
660
+ struct mag_server_config * scfg ;
672
661
/* Try to fetch the default set if not explicitly configured */
673
- maj = gss_indicate_mechs (& min , & indicated_mechs );
674
- if (maj != GSS_S_COMPLETE ) {
675
- ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , req , "%s" ,
676
- mag_error (req , "gss_indicate_mechs() failed" ,
677
- maj , min ));
678
- }
679
- desired_mechs = indicated_mechs ;
662
+ scfg = ap_get_module_config (req -> server -> module_config ,
663
+ & auth_gssapi_module );
664
+ desired_mechs = scfg -> default_mechs ;
680
665
}
681
666
682
667
/* implicit auth for subrequests if main auth already happened */
@@ -970,7 +955,7 @@ static int mag_auth(request_rec *req)
970
955
ap_auth_name (req )));
971
956
}
972
957
}
973
- gss_release_oid_set ( & min , & indicated_mechs );
958
+
974
959
if (ctx != GSS_C_NO_CONTEXT )
975
960
gss_delete_sec_context (& min , & ctx , GSS_C_NO_BUFFER );
976
961
gss_release_cred (& min , & acquired_cred );
@@ -1246,6 +1231,26 @@ static const char *mag_basic_auth_mechs(cmd_parms *parms, void *mconfig,
1246
1231
}
1247
1232
#endif
1248
1233
1234
+ static void * mag_create_server_config (apr_pool_t * p , server_rec * s )
1235
+ {
1236
+ struct mag_server_config * scfg ;
1237
+ uint32_t maj , min ;
1238
+
1239
+ scfg = apr_pcalloc (p , sizeof (struct mag_server_config ));
1240
+
1241
+ maj = gss_indicate_mechs (& min , & scfg -> default_mechs );
1242
+ if (maj != GSS_S_COMPLETE ) {
1243
+ ap_log_error (APLOG_MARK , APLOG_WARNING , 0 , s ,
1244
+ "gss_indicate_mechs() failed" );
1245
+ } else {
1246
+ /* Register the set in pool */
1247
+ apr_pool_cleanup_register (p , (void * )scfg -> default_mechs ,
1248
+ mag_oid_set_destroy , apr_pool_cleanup_null );
1249
+ }
1250
+
1251
+ return scfg ;
1252
+ }
1253
+
1249
1254
static const command_rec mag_commands [] = {
1250
1255
AP_INIT_FLAG ("GssapiSSLonly" , mag_ssl_only , NULL , OR_AUTHCFG ,
1251
1256
"Work only if connection is SSL Secured" ),
@@ -1291,7 +1296,7 @@ module AP_MODULE_DECLARE_DATA auth_gssapi_module =
1291
1296
STANDARD20_MODULE_STUFF ,
1292
1297
mag_create_dir_config ,
1293
1298
NULL ,
1294
- NULL ,
1299
+ mag_create_server_config ,
1295
1300
NULL ,
1296
1301
mag_commands ,
1297
1302
mag_register_hooks
0 commit comments