@@ -619,11 +619,41 @@ static bool mag_auth_basic(request_rec *req,
619619 return ret ;
620620}
621621
622+ struct mag_req_cfg * mag_init_cfg (request_rec * req )
623+ {
624+ struct mag_req_cfg * req_cfg = apr_pcalloc (req -> pool ,
625+ sizeof (struct mag_req_cfg ));
626+ req_cfg -> cfg = ap_get_module_config (req -> per_dir_config ,
627+ & auth_gssapi_module );
628+
629+ if (req_cfg -> cfg -> allowed_mechs ) {
630+ req_cfg -> desired_mechs = req_cfg -> cfg -> allowed_mechs ;
631+ } else {
632+ struct mag_server_config * scfg ;
633+ /* Try to fetch the default set if not explicitly configured */
634+ scfg = ap_get_module_config (req -> server -> module_config ,
635+ & auth_gssapi_module );
636+ req_cfg -> desired_mechs = scfg -> default_mechs ;
637+ }
638+
639+ if (req -> proxyreq == PROXYREQ_PROXY ) {
640+ req_cfg -> req_proto = "Proxy-Authorization" ;
641+ req_cfg -> rep_proto = "Proxy-Authenticate" ;
642+ } else {
643+ req_cfg -> req_proto = "Authorization" ;
644+ req_cfg -> rep_proto = "WWW-Authenticate" ;
645+ req_cfg -> use_sessions = req_cfg -> cfg -> use_sessions ;
646+ req_cfg -> send_persist = req_cfg -> cfg -> send_persist ;
647+ }
648+
649+ return req_cfg ;
650+ }
622651
623652static int mag_auth (request_rec * req )
624653{
625654 const char * type ;
626655 int auth_type = -1 ;
656+ struct mag_req_cfg * req_cfg ;
627657 struct mag_config * cfg ;
628658 const char * auth_header ;
629659 char * auth_header_type ;
@@ -656,17 +686,11 @@ static int mag_auth(request_rec *req)
656686 return DECLINED ;
657687 }
658688
659- cfg = ap_get_module_config (req -> per_dir_config , & auth_gssapi_module );
689+ req_cfg = mag_init_cfg (req );
660690
661- if (cfg -> allowed_mechs ) {
662- desired_mechs = cfg -> allowed_mechs ;
663- } else {
664- struct mag_server_config * scfg ;
665- /* Try to fetch the default set if not explicitly configured */
666- scfg = ap_get_module_config (req -> server -> module_config ,
667- & auth_gssapi_module );
668- desired_mechs = scfg -> default_mechs ;
669- }
691+ cfg = req_cfg -> cfg ;
692+
693+ desired_mechs = req_cfg -> desired_mechs ;
670694
671695 /* implicit auth for subrequests if main auth already happened */
672696 if (!ap_is_initial_req (req ) && req -> main != NULL ) {
@@ -718,11 +742,11 @@ static int mag_auth(request_rec *req)
718742 }
719743
720744 /* if available, session always supersedes connection bound data */
721- if (cfg -> use_sessions ) {
745+ if (req_cfg -> use_sessions ) {
722746 mag_check_session (req , cfg , & mc );
723747 }
724748
725- auth_header = apr_table_get (req -> headers_in , "Authorization" );
749+ auth_header = apr_table_get (req -> headers_in , req_cfg -> req_proto );
726750
727751 if (mc ) {
728752 if (mc -> established &&
@@ -925,18 +949,19 @@ static int mag_auth(request_rec *req)
925949 if (auth_type == AUTH_TYPE_BASIC ) {
926950 mag_basic_cache (cfg , mc , ba_user , ba_pwd );
927951 }
928- if (cfg -> use_sessions ) {
952+ if (req_cfg -> use_sessions ) {
929953 mag_attempt_session (req , cfg , mc );
930954 }
931955 }
932956
933- if (cfg -> send_persist )
957+ if (req_cfg -> send_persist )
934958 apr_table_set (req -> headers_out , "Persistent-Auth" ,
935959 cfg -> gss_conn_ctx ? "true" : "false" );
936960
937961 ret = OK ;
938962
939963done :
964+
940965 if ((auth_type != AUTH_TYPE_BASIC ) && (output .length != 0 )) {
941966 int prefixlen = strlen (auth_types [auth_type ]) + 1 ;
942967 replen = apr_base64_encode_len (output .length ) + 1 ;
@@ -945,18 +970,17 @@ static int mag_auth(request_rec *req)
945970 memcpy (reply , auth_types [auth_type ], prefixlen - 1 );
946971 reply [prefixlen - 1 ] = ' ' ;
947972 apr_base64_encode (& reply [prefixlen ], output .value , output .length );
948- apr_table_add (req -> err_headers_out ,
949- "WWW-Authenticate" , reply );
973+ apr_table_add (req -> err_headers_out , req_cfg -> rep_proto , reply );
950974 }
951975 } else if (ret == HTTP_UNAUTHORIZED ) {
952- apr_table_add (req -> err_headers_out , "WWW-Authenticate" , "Negotiate" );
976+ apr_table_add (req -> err_headers_out , req_cfg -> rep_proto , "Negotiate" );
977+
953978 if (is_mech_allowed (desired_mechs , & gss_mech_ntlmssp ,
954979 cfg -> gss_conn_ctx )) {
955- apr_table_add (req -> err_headers_out , "WWW-Authenticate" , "NTLM" );
980+ apr_table_add (req -> err_headers_out , req_cfg -> rep_proto , "NTLM" );
956981 }
957982 if (cfg -> use_basic_auth ) {
958- apr_table_add (req -> err_headers_out ,
959- "WWW-Authenticate" ,
983+ apr_table_add (req -> err_headers_out , req_cfg -> rep_proto ,
960984 apr_psprintf (req -> pool , "Basic realm=\"%s\"" ,
961985 ap_auth_name (req )));
962986 }
0 commit comments