@@ -201,14 +201,16 @@ static char *oidc_get_state_cookie_name(request_rec *r, const char *state) {
201201/*
202202 * return the static provider configuration, i.e. from a metadata URL or configuration primitives
203203 */
204- static oidc_provider_t * oidc_provider_static_config (request_rec * r , oidc_cfg * c ) {
204+ static apr_byte_t oidc_provider_static_config (request_rec * r , oidc_cfg * c , oidc_provider_t * * provider ) {
205205
206206 json_t * j_provider = NULL ;
207207 const char * s_json = NULL ;
208208
209209 /* see if we should configure a static provider based on external (cached) metadata */
210- if ((c -> metadata_dir != NULL ) || (c -> provider .metadata_url == NULL ))
211- return & c -> provider ;
210+ if ((c -> metadata_dir != NULL ) || (c -> provider .metadata_url == NULL )) {
211+ * provider = & c -> provider ;
212+ return TRUE;
213+ }
212214
213215 c -> cache -> get (r , OIDC_CACHE_SECTION_PROVIDER , c -> provider .metadata_url ,
214216 & s_json );
@@ -219,7 +221,7 @@ static oidc_provider_t *oidc_provider_static_config(request_rec *r, oidc_cfg *c)
219221 c -> provider .metadata_url , & j_provider , & s_json ) == FALSE) {
220222 oidc_error (r , "could not retrieve metadata from url: %s" ,
221223 c -> provider .metadata_url );
222- return NULL ;
224+ return FALSE ;
223225 }
224226
225227 // TODO: make the expiry configurable
@@ -233,22 +235,20 @@ static oidc_provider_t *oidc_provider_static_config(request_rec *r, oidc_cfg *c)
233235 j_provider = json_loads (s_json , 0 , 0 );
234236 }
235237
236- oidc_debug (r , " # got metadata: %s" , s_json );
238+ * provider = apr_pcalloc (r -> pool , sizeof (oidc_provider_t ));
239+ memcpy (* provider , & c -> provider , sizeof (oidc_provider_t ));
237240
238- oidc_provider_t * provider = apr_pcalloc (r -> pool , sizeof (oidc_provider_t ));
239- memcpy (provider , & c -> provider , sizeof (oidc_provider_t ));
240-
241- if (oidc_metadata_provider_parse (r , j_provider , provider ) == FALSE) {
241+ if (oidc_metadata_provider_parse (r , j_provider , * provider ) == FALSE) {
242242 oidc_error (r , "could not parse metadata from url: %s" ,
243243 c -> provider .metadata_url );
244244 if (j_provider )
245245 json_decref (j_provider );
246- return NULL ;
246+ return FALSE ;
247247 }
248248
249249 json_decref (j_provider );
250250
251- return provider ;
251+ return TRUE ;
252252}
253253
254254/*
@@ -258,7 +258,9 @@ static oidc_provider_t *oidc_get_provider_for_issuer(request_rec *r,
258258 oidc_cfg * c , const char * issuer ) {
259259
260260 /* by default we'll assume that we're dealing with a single statically configured OP */
261- oidc_provider_t * provider = oidc_provider_static_config (r , c );
261+ oidc_provider_t * provider = NULL ;
262+ if (oidc_provider_static_config (r , c , & provider ) == FALSE)
263+ return NULL ;
262264
263265 /* unless a metadata directory was configured, so we'll try and get the provider settings from there */
264266 if (c -> metadata_dir != NULL ) {
@@ -1273,7 +1275,8 @@ static int oidc_authenticate_user(request_rec *r, oidc_cfg *c,
12731275 return oidc_discovery (r , c );
12741276
12751277 /* we're not using multiple OP's configured in a metadata directory, pick the statically configured OP */
1276- provider = oidc_provider_static_config (r , c );
1278+ if (oidc_provider_static_config (r , c , & provider ) == FALSE)
1279+ return HTTP_INTERNAL_SERVER_ERROR ;
12771280 }
12781281
12791282 /* generate a random value to correlate request/response through browser state */
0 commit comments