Coverage Report

Created: 2026-12-01 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mod_auth_openidc/src/cfg/dir.c
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
20
/***************************************************************************
21
 * Copyright (C) 2017-2026 ZmartZone Holding BV
22
 * All rights reserved.
23
 *
24
 * DISCLAIMER OF WARRANTIES:
25
 *
26
 * THE SOFTWARE PROVIDED HEREUNDER IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
27
 * ANY WARRANTIES OR REPRESENTATIONS EXPRESS, IMPLIED OR STATUTORY; INCLUDING,
28
 * WITHOUT LIMITATION, WARRANTIES OF QUALITY, PERFORMANCE, NONINFRINGEMENT,
29
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  NOR ARE THERE ANY
30
 * WARRANTIES CREATED BY A COURSE OR DEALING, COURSE OF PERFORMANCE OR TRADE
31
 * USAGE.  FURTHERMORE, THERE ARE NO WARRANTIES THAT THE SOFTWARE WILL MEET
32
 * YOUR NEEDS OR BE FREE FROM ERRORS, OR THAT THE OPERATION OF THE SOFTWARE
33
 * WILL BE UNINTERRUPTED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
34
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF
36
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
 *
40
 * @Author: Hans Zandbelt - hans.zandbelt@openidc.com
41
 */
42
43
#include "cfg/dir.h"
44
#include "cfg/cfg_int.h"
45
#include "cfg/parse.h"
46
#include "util/util.h"
47
#include "util/util_cfg.h"
48
49
/*
50
 * "unset" sentinel for the INT_OFF members below: the standard OIDC_CONFIG_POS_INT_UNSET (-1)
51
 * cannot be used since -1 is a valid configured value for those directives
52
 */
53
19.9k
#define OIDC_DIR_INT_OFF_UNSET -2
54
55
/*
56
 * directory related configuration
57
 */
58
/*
59
 * Generate declaration, initialization, and merge logic for simple directory members;
60
 * INT_OFF members are integers for which -1 is a valid configured value, e.g. to switch a
61
 * feature off in a location nested in one that enables it, so they use OIDC_DIR_INT_OFF_UNSET
62
 */
63
#define OIDC_DIR_CFG_SIMPLE_MEMBERS(PTR, INT, INT_OFF)                                                                 \
64
5.49k
  PTR(char *, discover_url)                                                                                      \
65
5.49k
  PTR(char *, cookie_path)                                                                                       \
66
5.49k
  PTR(char *, cookie)                                                                                            \
67
5.49k
  PTR(char *, authn_header)                                                                                      \
68
5.49k
  PTR(char *, unauthz_arg)                                                                                       \
69
5.49k
  PTR(apr_array_header_t *, pass_cookies)                                                                        \
70
5.49k
  PTR(apr_array_header_t *, strip_cookies)                                                                       \
71
5.49k
  PTR(oidc_apr_expr_t *, path_auth_request_expr)                                                                 \
72
5.49k
  PTR(oidc_apr_expr_t *, path_scope_expr)                                                                        \
73
5.49k
  PTR(oidc_apr_expr_t *, unauth_expression)                                                                      \
74
5.49k
  PTR(oidc_apr_expr_t *, userinfo_claims_expr)                                                                   \
75
5.49k
  PTR(char *, state_cookie_prefix)                                                                               \
76
5.49k
  PTR(apr_array_header_t *, pass_userinfo_as)                                                                    \
77
5.49k
  INT(unauth_action)                                                                                             \
78
5.49k
  INT(unautz_action)                                                                                             \
79
5.49k
  INT(pass_info_in)                                                                                              \
80
5.49k
  INT(pass_info_encoding)                                                                                        \
81
5.49k
  INT(oauth_accept_token_in)                                                                                     \
82
5.49k
  INT(preserve_post)                                                                                             \
83
5.49k
  INT(pass_access_token)                                                                                         \
84
5.49k
  INT(pass_refresh_token)                                                                                        \
85
5.49k
  INT(action_on_error_refresh)                                                                                   \
86
5.49k
  INT(pass_idtoken_as)                                                                                           \
87
5.49k
  INT_OFF(oauth_token_introspect_interval)                                                                       \
88
5.49k
  INT_OFF(refresh_access_token_before_expiry)                                                                    \
89
5.49k
  INT_OFF(refresh_access_token_interval)
90
91
#define OIDC_DIR_M_DECL_PTR(type, name) type name;
92
#define OIDC_DIR_M_DECL_INT(name) int name;
93
#define OIDC_DIR_M_DECL_INT_OFF(name) int name;
94
71.3k
#define OIDC_DIR_M_CREATE_PTR(type, name) c->name = NULL;
95
54.9k
#define OIDC_DIR_M_CREATE_INT(name) c->name = OIDC_CONFIG_POS_INT_UNSET;
96
16.4k
#define OIDC_DIR_M_CREATE_INT_OFF(name) c->name = OIDC_DIR_INT_OFF_UNSET;
97
0
#define OIDC_DIR_M_MERGE_PTR(type, name) c->name = _oidc_cfg_merge_ptr(add->name, base->name);
98
0
#define OIDC_DIR_M_MERGE_INT(name) c->name = _oidc_cfg_merge_pos_int(add->name, base->name);
99
0
#define OIDC_DIR_M_MERGE_INT_OFF(name) c->name = _oidc_cfg_dir_merge_int_off(add->name, base->name);
100
101
struct oidc_dir_cfg_t {
102
  OIDC_DIR_CFG_SIMPLE_MEMBERS(OIDC_DIR_M_DECL_PTR, OIDC_DIR_M_DECL_INT, OIDC_DIR_M_DECL_INT_OFF)
103
  /* special: created as an (empty) hash, merged on entry count */
104
  apr_hash_t *oauth_accept_token_options;
105
};
106
107
0
#define OIDC_PASS_ID_TOKEN_AS_CLAIMS_STR "claims"
108
0
#define OIDC_PASS_IDTOKEN_AS_PAYLOAD_STR "payload"
109
0
#define OIDC_PASS_IDTOKEN_AS_SERIALIZED_STR "serialized"
110
0
#define OIDC_PASS_IDTOKEN_OFF_STR "off"
111
112
/*
113
 * define how to pass the id_token/claims in HTTP headers
114
 */
115
0
const char *oidc_cmd_dir_pass_idtoken_as_set(cmd_parms *cmd, void *m, const char *arg) {
116
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
117
118
  /* only read when the parse below succeeds and has written it; seeded so the optimizer does not
119
   * have to prove that across the call (-Wmaybe-uninitialized) */
120
0
  oidc_pass_idtoken_as_t type = OIDC_PASS_IDTOKEN_AS_CLAIMS;
121
0
  const char *rv = NULL;
122
123
0
  static const oidc_cfg_option_t options[] = {
124
0
      {OIDC_PASS_IDTOKEN_AS_CLAIMS, OIDC_PASS_ID_TOKEN_AS_CLAIMS_STR},
125
0
      {OIDC_PASS_IDTOKEN_AS_PAYLOAD, OIDC_PASS_IDTOKEN_AS_PAYLOAD_STR},
126
0
      {OIDC_PASS_IDTOKEN_AS_SERIALIZED, OIDC_PASS_IDTOKEN_AS_SERIALIZED_STR},
127
0
      {OIDC_PASS_IDTOKEN_OFF, OIDC_PASS_IDTOKEN_OFF_STR}};
128
129
0
  if (arg) {
130
0
    rv = oidc_cfg_parse_option(cmd->pool, options, OIDC_CFG_OPTIONS_SIZE(options), arg, (int *)&type);
131
0
    if (rv != NULL)
132
0
      return OIDC_CONFIG_DIR_RV(cmd, rv);
133
    // NB: assign the first to override the "unset" default
134
0
    if (dir_cfg->pass_idtoken_as == OIDC_CONFIG_POS_INT_UNSET)
135
0
      dir_cfg->pass_idtoken_as = type;
136
0
    else
137
0
      dir_cfg->pass_idtoken_as |= type;
138
0
  }
139
140
0
  return NULL;
141
0
}
142
143
84
#define OIDC_PASS_USERINFO_AS_CLAIMS_STR "claims"
144
42
#define OIDC_PASS_USERINFO_AS_JSON_OBJECT_STR "json"
145
42
#define OIDC_PASS_USERINFO_AS_JWT_STR "jwt"
146
42
#define OIDC_PASS_USERINFO_AS_SIGNED_JWT_STR "signed_jwt"
147
148
/*
149
 * parse a "pass id token as" value from the provided strings
150
 */
151
static const char *oidc_cfg_dir_parse_pass_userinfo_as(apr_pool_t *pool, const char *v,
152
42
                   oidc_pass_user_info_as_t **result) {
153
42
  const char *rv = NULL;
154
  /* only read when the parse below succeeds and has written it; seeded so the optimizer does not
155
   * have to prove that across the call (-Wmaybe-uninitialized) */
156
42
  oidc_pass_userinfo_enum_t type = OIDC_PASS_USERINFO_AS_CLAIMS;
157
42
  static const oidc_cfg_option_t options[] = {
158
42
      {OIDC_PASS_USERINFO_AS_CLAIMS, OIDC_PASS_USERINFO_AS_CLAIMS_STR},
159
42
      {OIDC_PASS_USERINFO_AS_JSON_OBJECT, OIDC_PASS_USERINFO_AS_JSON_OBJECT_STR},
160
42
      {OIDC_PASS_USERINFO_AS_JWT, OIDC_PASS_USERINFO_AS_JWT_STR},
161
42
      {OIDC_PASS_USERINFO_AS_SIGNED_JWT, OIDC_PASS_USERINFO_AS_SIGNED_JWT_STR}};
162
163
  /* split "<type>:<name>" without writing into `v`: oidc_cfg_dir_post_config passes the default
164
   * as a string literal, so truncating it in place would write to read-only memory. Copying out
165
   * just the type also avoids duplicating the whole string when there is no separator at all. */
166
42
  const char *sep = _oidc_strstr(v, ":");
167
42
  const char *value = (sep != NULL) ? apr_pstrndup(pool, v, (apr_size_t)(sep - v)) : v;
168
42
  const char *name = (sep != NULL) ? sep + 1 : NULL;
169
170
42
  rv = oidc_cfg_parse_option(pool, options, OIDC_CFG_OPTIONS_SIZE(options), value, (int *)&type);
171
42
  if (rv != NULL)
172
0
    return rv;
173
174
42
  *result = apr_pcalloc(pool, sizeof(oidc_pass_user_info_as_t));
175
42
  (*result)->type = type;
176
42
  if (name)
177
0
    (*result)->name = apr_pstrdup(pool, name);
178
179
42
  return NULL;
180
42
}
181
182
/*
183
 * define how to pass the userinfo/claims in HTTP headers
184
 */
185
0
const char *oidc_cmd_dir_pass_userinfo_as_set(cmd_parms *cmd, void *m, const char *arg) {
186
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
187
0
  const char *rv = NULL;
188
0
  oidc_pass_user_info_as_t *p = NULL;
189
0
  rv = oidc_cfg_dir_parse_pass_userinfo_as(cmd->pool, arg, &p);
190
0
  if (rv != NULL)
191
0
    return OIDC_CONFIG_DIR_RV(cmd, rv);
192
0
  if (dir_cfg->pass_userinfo_as == NULL)
193
0
    dir_cfg->pass_userinfo_as = apr_array_make(cmd->pool, 3, sizeof(const oidc_pass_user_info_as_t *));
194
0
  APR_ARRAY_PUSH(dir_cfg->pass_userinfo_as, const oidc_pass_user_info_as_t *) = p;
195
0
  return NULL;
196
0
}
197
198
#define OIDC_OAUTH_ACCEPT_TOKEN_IN_HEADER_STR "header"
199
#define OIDC_OAUTH_ACCEPT_TOKEN_IN_POST_STR "post"
200
#define OIDC_OAUTH_ACCEPT_TOKEN_IN_QUERY_STR "query"
201
#define OIDC_OAUTH_ACCEPT_TOKEN_IN_COOKIE_STR "cookie"
202
#define OIDC_OAUTH_ACCEPT_TOKEN_IN_BASIC_STR "basic"
203
204
static const oidc_cfg_option_t oidc_oauth_accept_token_in_options[] = {
205
    {OIDC_OAUTH_ACCEPT_TOKEN_IN_HEADER, OIDC_OAUTH_ACCEPT_TOKEN_IN_HEADER_STR},
206
    {OIDC_OAUTH_ACCEPT_TOKEN_IN_POST, OIDC_OAUTH_ACCEPT_TOKEN_IN_POST_STR},
207
    {OIDC_OAUTH_ACCEPT_TOKEN_IN_QUERY, OIDC_OAUTH_ACCEPT_TOKEN_IN_QUERY_STR},
208
    {OIDC_OAUTH_ACCEPT_TOKEN_IN_COOKIE, OIDC_OAUTH_ACCEPT_TOKEN_IN_COOKIE_STR},
209
    {OIDC_OAUTH_ACCEPT_TOKEN_IN_BASIC, OIDC_OAUTH_ACCEPT_TOKEN_IN_BASIC_STR}};
210
211
/*
212
 * convert an "accept OAuth 2.0 token in" byte value to a string representation
213
 */
214
2.43k
const char *oidc_cfg_dir_accept_oauth_token_in2str(apr_pool_t *pool, oidc_oauth_accept_token_in_t v) {
215
2.43k
  static oidc_cfg_option_t enabled[OIDC_CFG_OPTIONS_SIZE(oidc_oauth_accept_token_in_options)];
216
2.43k
  int i = 0;
217
14.6k
  for (int j = 0; j < OIDC_CFG_OPTIONS_SIZE(oidc_oauth_accept_token_in_options); j++) {
218
12.1k
    if (v & oidc_oauth_accept_token_in_options[j].val) {
219
6.65k
      enabled[i] = oidc_oauth_accept_token_in_options[j];
220
6.65k
      i++;
221
6.65k
    }
222
12.1k
  }
223
2.43k
  return oidc_cfg_parse_options_flatten(pool, enabled, i);
224
2.43k
}
225
226
7.37k
#define OIDC_OAUTH_ACCEPT_TOKEN_IN_COOKIE_NAME_DEFAULT "PA.global"
227
7.37k
#define OIDC_OAUTH_ACCEPT_TOKEN_IN_COOKIE_SEPARATOR ":"
228
229
/*
230
 * define which method of pass an OAuth Bearer token is accepted
231
 */
232
7.37k
const char *oidc_cmd_dir_accept_oauth_token_in_set(cmd_parms *cmd, void *m, const char *arg) {
233
7.37k
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
234
7.37k
  int v = 0;
235
7.37k
  const char *rv = NULL;
236
7.37k
  const char *s = NULL;
237
7.37k
  char *p = NULL;
238
239
7.37k
  s = apr_pstrdup(cmd->pool, arg);
240
7.37k
  p = _oidc_strstr(s, OIDC_OAUTH_ACCEPT_TOKEN_IN_COOKIE_SEPARATOR);
241
242
7.37k
  if (p != NULL) {
243
0
    *p = '\0';
244
0
    p++;
245
7.37k
  } else {
246
7.37k
    p = OIDC_OAUTH_ACCEPT_TOKEN_IN_COOKIE_NAME_DEFAULT;
247
7.37k
  }
248
249
7.37k
  rv = oidc_cfg_parse_option(cmd->pool, oidc_oauth_accept_token_in_options,
250
7.37k
           OIDC_CFG_OPTIONS_SIZE(oidc_oauth_accept_token_in_options), s, &v);
251
7.37k
  if (rv != NULL)
252
0
    return OIDC_CONFIG_DIR_RV(cmd, rv);
253
254
7.37k
  if (dir_cfg->oauth_accept_token_in == OIDC_CONFIG_POS_INT_UNSET)
255
3.88k
    dir_cfg->oauth_accept_token_in = v;
256
3.48k
  else
257
3.48k
    dir_cfg->oauth_accept_token_in |= v;
258
259
7.37k
  if (v == OIDC_OAUTH_ACCEPT_TOKEN_IN_COOKIE)
260
1.07k
    apr_hash_set(dir_cfg->oauth_accept_token_options, OIDC_OAUTH_ACCEPT_TOKEN_IN_OPTION_COOKIE_NAME,
261
1.07k
           APR_HASH_KEY_STRING, p);
262
263
7.37k
  return NULL;
264
7.37k
}
265
266
/*
267
 * specify cookies names to pass/strip
268
 */
269
0
const char *oidc_cmd_dir_strip_cookies_set(cmd_parms *cmd, void *m, const char *arg) {
270
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
271
0
  return oidc_cfg_string_list_add(cmd->pool, &dir_cfg->strip_cookies, arg);
272
0
}
273
274
0
const char *oidc_cmd_dir_pass_cookies_set(cmd_parms *cmd, void *m, const char *arg) {
275
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
276
0
  return oidc_cfg_string_list_add(cmd->pool, &dir_cfg->pass_cookies, arg);
277
0
}
278
279
/*
280
 * Body generators for the per-directory (oidc_dir_cfg_t) accessors declared in
281
 * cfg/dir.h: for member `foo` they emit oidc_cmd_dir_foo_set() and
282
 * oidc_cfg_dir_foo_get(); those names are token-pasted here and so appear in
283
 * no source line.
284
 */
285
#define OIDC_CFG_DIR_MEMBER_FUNC_GET(member, type, def_val, unset_val)                                                 \
286
676k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
676k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
676k
    if (dir_cfg->member == unset_val)                                                                      \
289
676k
      return (type)def_val;                                                                          \
290
13.3k
    return (type)dir_cfg->member;                                                                          \
291
676k
  }
oidc_cfg_dir_preserve_post_get
Line
Count
Source
286
5.34k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
5.34k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
5.34k
    if (dir_cfg->member == unset_val)                                                                      \
289
5.34k
      return (type)def_val;                                                                          \
290
5.34k
    return (type)dir_cfg->member;                                                                          \
291
5.34k
  }
oidc_cfg_dir_refresh_access_token_before_expiry_get
Line
Count
Source
286
392
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
392
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
392
    if (dir_cfg->member == unset_val)                                                                      \
289
392
      return (type)def_val;                                                                          \
290
392
    return (type)dir_cfg->member;                                                                          \
291
392
  }
oidc_cfg_dir_refresh_access_token_interval_get
Line
Count
Source
286
392
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
392
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
392
    if (dir_cfg->member == unset_val)                                                                      \
289
392
      return (type)def_val;                                                                          \
290
392
    return (type)dir_cfg->member;                                                                          \
291
392
  }
Unexecuted instantiation: oidc_cfg_dir_action_on_error_refresh_get
oidc_cfg_dir_state_cookie_prefix_get
Line
Count
Source
286
581k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
581k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
581k
    if (dir_cfg->member == unset_val)                                                                      \
289
581k
      return (type)def_val;                                                                          \
290
581k
    return (type)dir_cfg->member;                                                                          \
291
581k
  }
Unexecuted instantiation: oidc_cfg_dir_discover_url_get
oidc_cfg_dir_cookie_get
Line
Count
Source
286
19.0k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
19.0k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
19.0k
    if (dir_cfg->member == unset_val)                                                                      \
289
19.0k
      return (type)def_val;                                                                          \
290
19.0k
    return (type)dir_cfg->member;                                                                          \
291
19.0k
  }
oidc_cfg_dir_cookie_path_get
Line
Count
Source
286
45.6k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
45.6k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
45.6k
    if (dir_cfg->member == unset_val)                                                                      \
289
45.6k
      return (type)def_val;                                                                          \
290
45.6k
    return (type)dir_cfg->member;                                                                          \
291
45.6k
  }
oidc_cfg_dir_authn_header_get
Line
Count
Source
286
2.35k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
2.35k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
2.35k
    if (dir_cfg->member == unset_val)                                                                      \
289
2.35k
      return (type)def_val;                                                                          \
290
2.35k
    return (type)dir_cfg->member;                                                                          \
291
2.35k
  }
oidc_cfg_dir_pass_info_in_get
Line
Count
Source
286
2.04k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
2.04k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
2.04k
    if (dir_cfg->member == unset_val)                                                                      \
289
2.04k
      return (type)def_val;                                                                          \
290
2.04k
    return (type)dir_cfg->member;                                                                          \
291
2.04k
  }
oidc_cfg_dir_pass_info_encoding_get
Line
Count
Source
286
1.65k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
1.65k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
1.65k
    if (dir_cfg->member == unset_val)                                                                      \
289
1.65k
      return (type)def_val;                                                                          \
290
1.65k
    return (type)dir_cfg->member;                                                                          \
291
1.65k
  }
oidc_cfg_dir_pass_access_token_get
Line
Count
Source
286
2.33k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
2.33k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
2.33k
    if (dir_cfg->member == unset_val)                                                                      \
289
2.33k
      return (type)def_val;                                                                          \
290
2.33k
    return (type)dir_cfg->member;                                                                          \
291
2.33k
  }
oidc_cfg_dir_pass_refresh_token_get
Line
Count
Source
286
584
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
584
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
584
    if (dir_cfg->member == unset_val)                                                                      \
289
584
      return (type)def_val;                                                                          \
290
584
    return (type)dir_cfg->member;                                                                          \
291
584
  }
oidc_cfg_dir_oauth_accept_token_in_get
Line
Count
Source
286
11.3k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
11.3k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
11.3k
    if (dir_cfg->member == unset_val)                                                                      \
289
11.3k
      return (type)def_val;                                                                          \
290
11.3k
    return (type)dir_cfg->member;                                                                          \
291
11.3k
  }
oidc_cfg_dir_pass_cookies_get
Line
Count
Source
286
258
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
258
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
258
    if (dir_cfg->member == unset_val)                                                                      \
289
258
      return (type)def_val;                                                                          \
290
258
    return (type)dir_cfg->member;                                                                          \
291
258
  }
oidc_cfg_dir_strip_cookies_get
Line
Count
Source
286
655
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
655
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
655
    if (dir_cfg->member == unset_val)                                                                      \
289
655
      return (type)def_val;                                                                          \
290
655
    return (type)dir_cfg->member;                                                                          \
291
655
  }
oidc_cfg_dir_unautz_action_get
Line
Count
Source
286
1.08k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
1.08k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
1.08k
    if (dir_cfg->member == unset_val)                                                                      \
289
1.08k
      return (type)def_val;                                                                          \
290
1.08k
    return (type)dir_cfg->member;                                                                          \
291
1.08k
  }
oidc_cfg_dir_pass_idtoken_as_get
Line
Count
Source
286
1.57k
  type oidc_cfg_dir_##member##_get(request_rec *r) {                                                             \
287
1.57k
    oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);               \
288
1.57k
    if (dir_cfg->member == unset_val)                                                                      \
289
1.57k
      return (type)def_val;                                                                          \
290
1.57k
    return (type)dir_cfg->member;                                                                          \
291
1.57k
  }
292
293
#define OIDC_CFG_DIR_MEMBER_FUNC_INT_GET(member, type, def_val)                                                        \
294
  OIDC_CFG_DIR_MEMBER_FUNC_GET(member, type, def_val, OIDC_CONFIG_POS_INT_UNSET)
295
296
#define OIDC_CFG_DIR_MEMBER_FUNC_INT_OFF_GET(member, type, def_val)                                                    \
297
  OIDC_CFG_DIR_MEMBER_FUNC_GET(member, type, def_val, OIDC_DIR_INT_OFF_UNSET)
298
299
#define OIDC_CFG_DIR_MEMBER_FUNCS_INT(member, type, parse, def_val)                                                    \
300
2
  const char *oidc_cmd_dir_##member##_set(cmd_parms *cmd, void *m, const char *arg) {                            \
301
2
    oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;                                                         \
302
2
    int v = -1;                                                                                            \
303
2
    const char *rv = parse;                                                                                \
304
2
    if (rv == NULL)                                                                                        \
305
2
      dir_cfg->member = v;                                                                           \
306
2
    return OIDC_CONFIG_DIR_RV(cmd, rv);                                                                    \
307
2
  }                                                                                                              \
308
  OIDC_CFG_DIR_MEMBER_FUNC_INT_GET(member, type, def_val)
309
310
/* default for preserving POST parameters across authentication requests */
311
#define OIDC_DEFAULT_PRESERVE_POST 0
312
2
OIDC_CFG_DIR_MEMBER_FUNCS_INT(preserve_post, int, oidc_cfg_parse_boolean(cmd->pool, arg, &v),
313
            OIDC_DEFAULT_PRESERVE_POST)
314
315
0
#define OIDC_APPINFO_ENCODING_NONE_STR "none"
316
0
#define OIDC_APPINFO_ENCODING_LATIN1_STR "latin1"
317
0
#define OIDC_APPINFO_ENCODING_BASE64URL_STR "base64url"
318
319
0
#define OIDC_APPINFO_PASS_NONE_STR "none"
320
0
#define OIDC_APPINFO_PASS_HEADERS_STR "headers"
321
0
#define OIDC_APPINFO_PASS_ENVVARS_STR "environment"
322
0
#define OIDC_APPINFO_PASS_BOTH_STR "both"
323
324
0
#define OIDC_APPINFO_PASS_BOTH (OIDC_APPINFO_PASS_HEADERS | OIDC_APPINFO_PASS_ENVVARS)
325
326
/*
327
 * define how to pass claims information to the application: in headers and/or environment variables
328
 * and optionally specify the encoding applied to the values
329
 */
330
0
const char *oidc_cmd_dir_pass_claims_as_set(cmd_parms *cmd, void *m, const char *arg1, const char *arg2) {
331
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
332
0
  const char *rv = NULL;
333
334
0
  static const oidc_cfg_option_t pass_options[] = {{OIDC_APPINFO_PASS_NONE, OIDC_APPINFO_PASS_NONE_STR},
335
0
               {OIDC_APPINFO_PASS_HEADERS, OIDC_APPINFO_PASS_HEADERS_STR},
336
0
               {OIDC_APPINFO_PASS_ENVVARS, OIDC_APPINFO_PASS_ENVVARS_STR},
337
0
               {OIDC_APPINFO_PASS_BOTH, OIDC_APPINFO_PASS_BOTH_STR}};
338
339
0
  rv = oidc_cfg_parse_option(cmd->pool, pass_options, OIDC_CFG_OPTIONS_SIZE(pass_options), arg1,
340
0
           &dir_cfg->pass_info_in);
341
342
0
  static const oidc_cfg_option_t encoding_options[] = {
343
0
      {OIDC_APPINFO_ENCODING_NONE, OIDC_APPINFO_ENCODING_NONE_STR},
344
0
      {OIDC_APPINFO_ENCODING_BASE64URL, OIDC_APPINFO_ENCODING_BASE64URL_STR},
345
0
      {OIDC_APPINFO_ENCODING_LATIN1, OIDC_APPINFO_ENCODING_LATIN1_STR}};
346
347
0
  if ((rv == NULL) && (arg2 != NULL))
348
0
    rv = oidc_cfg_parse_option(cmd->pool, encoding_options, OIDC_CFG_OPTIONS_SIZE(encoding_options), arg2,
349
0
             &dir_cfg->pass_info_encoding);
350
351
0
  return OIDC_CONFIG_DIR_RV(cmd, rv);
352
0
}
353
354
#define OIDC_UNAUTH_AUTHENTICATE_STR "auth"
355
#define OIDC_UNAUTH_PASS_STR "pass"
356
#define OIDC_UNAUTH_RETURN401_STR "401"
357
#define OIDC_UNAUTH_RETURN410_STR "410"
358
#define OIDC_UNAUTH_RETURN407_STR "407"
359
360
static const oidc_cfg_option_t unauth_action_options[] = {{OIDC_UNAUTH_AUTHENTICATE, OIDC_UNAUTH_AUTHENTICATE_STR},
361
                {OIDC_UNAUTH_PASS, OIDC_UNAUTH_PASS_STR},
362
                {OIDC_UNAUTH_RETURN401, OIDC_UNAUTH_RETURN401_STR},
363
                {OIDC_UNAUTH_RETURN410, OIDC_UNAUTH_RETURN410_STR},
364
                {OIDC_UNAUTH_RETURN407, OIDC_UNAUTH_RETURN407_STR}};
365
366
0
static const char *oidc_cfg_dir_unauth_action2str(oidc_unauth_action_t action) {
367
0
  for (int i = 0; i < OIDC_CFG_OPTIONS_SIZE(unauth_action_options); i++) {
368
    /* oidc_cfg_option_t holds the value as an int; the cast keeps the comparison signed */
369
0
    if ((int)action == unauth_action_options[i].val)
370
0
      return unauth_action_options[i].str;
371
0
  }
372
0
  return NULL;
373
0
}
374
375
/*
376
 * define how to act on unauthenticated requests
377
 */
378
182
const char *oidc_cmd_dir_unauth_action_set(cmd_parms *cmd, void *m, const char *arg1, const char *arg2) {
379
182
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
380
182
  const char *rv =
381
182
      oidc_cfg_parse_option(cmd->pool, unauth_action_options, OIDC_CFG_OPTIONS_SIZE(unauth_action_options), arg1,
382
182
          &dir_cfg->unauth_action);
383
182
  if (rv == NULL)
384
182
    rv = oidc_util_apr_expr_parse(cmd, arg2, &dir_cfg->unauth_expression, OIDC_APR_EXPR_RESULT_BOOLEAN);
385
182
  return OIDC_CONFIG_DIR_RV(cmd, rv);
386
182
}
387
388
649
#define OIDC_UNAUTZ_RETURN403_STR "403"
389
649
#define OIDC_UNAUTZ_RETURN401_STR "401"
390
649
#define OIDC_UNAUTZ_AUTHENTICATE_STR "auth"
391
649
#define OIDC_UNAUTZ_RETURN302_STR "302"
392
393
/*
394
 * define how to act on unauthorized requests
395
 */
396
649
const char *oidc_cmd_dir_unautz_action_set(cmd_parms *cmd, void *m, const char *arg1, const char *arg2) {
397
649
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
398
649
  static const oidc_cfg_option_t options[] = {{OIDC_UNAUTZ_RETURN403, OIDC_UNAUTZ_RETURN403_STR},
399
649
                {OIDC_UNAUTZ_RETURN401, OIDC_UNAUTZ_RETURN401_STR},
400
649
                {OIDC_UNAUTZ_AUTHENTICATE, OIDC_UNAUTZ_AUTHENTICATE_STR},
401
649
                {OIDC_UNAUTZ_RETURN302, OIDC_UNAUTZ_RETURN302_STR}};
402
649
  const char *rv =
403
649
      oidc_cfg_parse_option(cmd->pool, options, OIDC_CFG_OPTIONS_SIZE(options), arg1, &dir_cfg->unautz_action);
404
649
  if ((rv == NULL) && (arg2 != NULL)) {
405
210
    dir_cfg->unauthz_arg = apr_pstrdup(cmd->pool, arg2);
406
439
  } else if (dir_cfg->unautz_action == OIDC_UNAUTZ_RETURN302) {
407
0
    rv =
408
0
        apr_psprintf(cmd->temp_pool, "the (2nd) URL argument to %s must be set", cmd->directive->directive);
409
0
    return rv;
410
0
  }
411
649
  return OIDC_CONFIG_DIR_RV(cmd, rv);
412
649
}
413
414
#ifdef USE_LIBJQ
415
416
const char *oidc_cmd_dir_userinfo_claims_expr_set(cmd_parms *cmd, void *m, const char *arg) {
417
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
418
  const char *rv =
419
      oidc_util_apr_expr_parse(cmd, arg, &dir_cfg->userinfo_claims_expr, OIDC_APR_EXPR_RESULT_STRING);
420
  return OIDC_CONFIG_DIR_RV(cmd, rv);
421
}
422
423
#endif
424
425
0
const char *oidc_cmd_dir_path_auth_request_params_set(cmd_parms *cmd, void *m, const char *arg) {
426
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
427
0
  const char *rv = NULL;
428
0
  rv = oidc_util_apr_expr_parse(cmd, arg, &dir_cfg->path_auth_request_expr, OIDC_APR_EXPR_RESULT_STRING);
429
0
  return OIDC_CONFIG_DIR_RV(cmd, rv);
430
0
}
431
432
0
const char *oidc_cmd_dir_path_scope_set(cmd_parms *cmd, void *m, const char *arg) {
433
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
434
0
  const char *rv = NULL;
435
0
  rv = oidc_util_apr_expr_parse(cmd, arg, &dir_cfg->path_scope_expr, OIDC_APR_EXPR_RESULT_STRING);
436
0
  return OIDC_CONFIG_DIR_RV(cmd, rv);
437
0
}
438
439
/* value that switches a refresh trigger off, e.g. in a location nested in one that enables it */
440
0
#define OIDC_REFRESH_TRIGGER_OFF -1
441
442
/*
443
 * parse a refresh trigger in seconds, or OIDC_REFRESH_TRIGGER_OFF, into member, plus the optional
444
 * action to take on refresh errors
445
 */
446
static const char *oidc_cmd_dir_refresh_trigger_set(cmd_parms *cmd, oidc_dir_cfg_t *dir_cfg, int *member, int min_value,
447
0
                int max_value, const char *arg1, const char *arg2) {
448
0
  int v = OIDC_REFRESH_TRIGGER_OFF;
449
0
  const char *rv = oidc_cfg_parse_int(cmd->pool, arg1, &v);
450
0
  if (rv != NULL)
451
0
    goto end;
452
453
0
  if (v != OIDC_REFRESH_TRIGGER_OFF) {
454
0
    rv = oidc_cfg_parse_is_valid_int(cmd->pool, v, min_value, max_value);
455
0
    if (rv != NULL) {
456
0
      rv = apr_psprintf(cmd->pool, "%s (or %d to switch it off)", rv, OIDC_REFRESH_TRIGGER_OFF);
457
0
      goto end;
458
0
    }
459
0
  }
460
461
0
  *member = v;
462
463
0
  if (arg2 != NULL)
464
0
    rv = oidc_cfg_parse_action_on_error_refresh_as(
465
0
        cmd->pool, arg2, (oidc_on_error_action_t *)&dir_cfg->action_on_error_refresh);
466
467
0
end:
468
469
0
  return OIDC_CONFIG_DIR_RV(cmd, rv);
470
0
}
471
472
0
#define OIDC_REFRESH_ACCESS_TOKEN_BEFORE_EXPIRY_MIN 0
473
0
#define OIDC_REFRESH_ACCESS_TOKEN_BEFORE_EXPIRY_MAX (3600 * 24 * 365)
474
475
/*
476
 * set the time in seconds that the access token needs to be valid for
477
 */
478
const char *oidc_cmd_dir_refresh_access_token_before_expiry_set(cmd_parms *cmd, void *m, const char *arg1,
479
0
                const char *arg2) {
480
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
481
0
  return oidc_cmd_dir_refresh_trigger_set(cmd, dir_cfg, &dir_cfg->refresh_access_token_before_expiry,
482
0
            OIDC_REFRESH_ACCESS_TOKEN_BEFORE_EXPIRY_MIN,
483
0
            OIDC_REFRESH_ACCESS_TOKEN_BEFORE_EXPIRY_MAX, arg1, arg2);
484
0
}
485
486
0
#define OIDC_REFRESH_ACCESS_TOKEN_INTERVAL_MIN 1
487
0
#define OIDC_REFRESH_ACCESS_TOKEN_INTERVAL_MAX (3600 * 24 * 365)
488
489
/*
490
 * set the maximum time in seconds after which the access token is refreshed regardless of its expiry
491
 */
492
const char *oidc_cmd_dir_refresh_access_token_interval_set(cmd_parms *cmd, void *m, const char *arg1,
493
0
                 const char *arg2) {
494
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
495
0
  return oidc_cmd_dir_refresh_trigger_set(cmd, dir_cfg, &dir_cfg->refresh_access_token_interval,
496
0
            OIDC_REFRESH_ACCESS_TOKEN_INTERVAL_MIN,
497
0
            OIDC_REFRESH_ACCESS_TOKEN_INTERVAL_MAX, arg1, arg2);
498
0
}
499
500
#define OIDC_CFG_DIR_MEMBER_FUNC_PTR(member, type, parse, def_val)                                                     \
501
0
  const char *oidc_cmd_dir_##member##_set(cmd_parms *cmd, void *m, const char *arg) {                            \
502
0
    oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;                                                         \
503
0
    const char *rv = parse;                                                                                \
504
0
    return OIDC_CONFIG_DIR_RV(cmd, rv);                                                                    \
505
0
  }                                                                                                              \
506
                                                                                                                       \
507
  OIDC_CFG_DIR_MEMBER_FUNC_GET(member, type, def_val, NULL)
508
509
#define OIDC_CFG_DIR_MEMBER_FUNC_STR(member, type, def_val)                                                            \
510
0
  const char *oidc_cmd_dir_##member##_set(cmd_parms *cmd, void *m, const char *arg) {                            \
511
0
    oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;                                                         \
512
0
    dir_cfg->member = apr_pstrdup(cmd->pool, arg);                                                         \
513
0
    return NULL;                                                                                           \
514
0
  }                                                                                                              \
515
                                                                                                                       \
516
  OIDC_CFG_DIR_MEMBER_FUNC_GET(member, type, def_val, NULL)
517
518
/* define the default number of seconds that the access token needs to be valid for; -1 = no refresh */
519
#define OIDC_DEFAULT_REFRESH_ACCESS_TOKEN_BEFORE_EXPIRY OIDC_REFRESH_TRIGGER_OFF
520
OIDC_CFG_DIR_MEMBER_FUNC_INT_OFF_GET(refresh_access_token_before_expiry, int,
521
             OIDC_DEFAULT_REFRESH_ACCESS_TOKEN_BEFORE_EXPIRY)
522
523
/* define the default maximum age in seconds of the access token; -1 = no interval-based refresh */
524
#define OIDC_DEFAULT_REFRESH_ACCESS_TOKEN_INTERVAL OIDC_REFRESH_TRIGGER_OFF
525
OIDC_CFG_DIR_MEMBER_FUNC_INT_OFF_GET(refresh_access_token_interval, int, OIDC_DEFAULT_REFRESH_ACCESS_TOKEN_INTERVAL)
526
527
/* default action to be taken on access token refresh error */
528
#define OIDC_DEFAULT_ON_ERROR_REFRESH OIDC_ON_ERROR_502;
529
OIDC_CFG_DIR_MEMBER_FUNC_INT_GET(action_on_error_refresh, oidc_on_error_action_t, OIDC_DEFAULT_ON_ERROR_REFRESH)
530
531
/* default prefix of the state cookie that binds the state in the authorization request/response to the browser */
532
#define OIDC_DEFAULT_STATE_COOKIE_PREFIX "mod_auth_openidc_state_"
533
0
OIDC_CFG_DIR_MEMBER_FUNC_STR(state_cookie_prefix, const char *, OIDC_DEFAULT_STATE_COOKIE_PREFIX)
534
535
0
OIDC_CFG_DIR_MEMBER_FUNC_PTR(discover_url, const char *,
536
           oidc_cfg_parse_relative_or_absolute_url(cmd->pool, arg, &dir_cfg->discover_url), NULL)
537
538
/* default name of the session cookie */
539
#define OIDC_DEFAULT_COOKIE "mod_auth_openidc_session"
540
0
OIDC_CFG_DIR_MEMBER_FUNC_STR(cookie, const char *, OIDC_DEFAULT_COOKIE)
541
542
/* default cookie path */
543
#define OIDC_DEFAULT_COOKIE_PATH "/"
544
0
OIDC_CFG_DIR_MEMBER_FUNC_STR(cookie_path, const char *, OIDC_DEFAULT_COOKIE_PATH)
545
546
/* default for the HTTP header name in which the remote user name is passed */
547
#define OIDC_DEFAULT_AUTHN_HEADER NULL
548
0
OIDC_CFG_DIR_MEMBER_FUNC_STR(authn_header, const char *, OIDC_DEFAULT_AUTHN_HEADER)
549
550
/* default for passing app info in headers */
551
#define OIDC_DEFAULT_PASS_APPINFO_IN OIDC_APPINFO_PASS_BOTH
552
OIDC_CFG_DIR_MEMBER_FUNC_INT_GET(pass_info_in, oidc_appinfo_pass_in_t, OIDC_DEFAULT_PASS_APPINFO_IN)
553
554
/* default for passing app info in a specific encoding */
555
#define OIDC_DEFAULT_APPINFO_ENCODING OIDC_APPINFO_ENCODING_LATIN1
556
OIDC_CFG_DIR_MEMBER_FUNC_INT_GET(pass_info_encoding, oidc_appinfo_encoding_t, OIDC_DEFAULT_APPINFO_ENCODING)
557
558
/* default for passing the access token in a header/environment variable */
559
#define OIDC_DEFAULT_PASS_ACCESS_TOKEN 1
560
0
OIDC_CFG_DIR_MEMBER_FUNCS_INT(pass_access_token, apr_byte_t, oidc_cfg_parse_boolean(cmd->pool, arg, &v),
561
            OIDC_DEFAULT_PASS_ACCESS_TOKEN)
562
563
/* default for passing the refresh token in a header/environment variable */
564
#define OIDC_DEFAULT_PASS_REFRESH_TOKEN 0
565
0
OIDC_CFG_DIR_MEMBER_FUNCS_INT(pass_refresh_token, apr_byte_t, oidc_cfg_parse_boolean(cmd->pool, arg, &v),
566
            OIDC_DEFAULT_PASS_REFRESH_TOKEN)
567
568
#define OIDC_OAUTH_ACCEPT_TOKEN_IN_DEFAULT OIDC_OAUTH_ACCEPT_TOKEN_IN_HEADER
569
OIDC_CFG_DIR_MEMBER_FUNC_INT_GET(oauth_accept_token_in, oidc_oauth_accept_token_in_t,
570
         OIDC_OAUTH_ACCEPT_TOKEN_IN_DEFAULT)
571
572
8.15k
const char *oidc_cfg_dir_accept_token_in_option_get(request_rec *r, const char *key) {
573
8.15k
  oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
574
8.15k
  return apr_hash_get(dir_cfg->oauth_accept_token_options, key, APR_HASH_KEY_STRING);
575
8.15k
}
576
577
0
#define OIDC_OAUTH_ACCESS_TOKEN_INTROSPECTION_INTERVAL_MIN -1
578
0
#define OIDC_OAUTH_ACCESS_TOKEN_INTROSPECTION_INTERVAL_MAX (3600 * 24 * 365)
579
580
/* default value for the token introspection interval (0 = disabled, no expiry of claims) */
581
3.47k
#define OIDC_DEFAULT_TOKEN_INTROSPECTION_INTERVAL 0
582
583
0
const char *oidc_cmd_dir_token_introspection_interval_set(cmd_parms *cmd, void *m, const char *arg) {
584
0
  oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
585
0
  const char *rv = oidc_cfg_parse_int_min_max(cmd->pool, arg, &dir_cfg->oauth_token_introspect_interval,
586
0
                OIDC_OAUTH_ACCESS_TOKEN_INTROSPECTION_INTERVAL_MIN,
587
0
                OIDC_OAUTH_ACCESS_TOKEN_INTROSPECTION_INTERVAL_MAX);
588
0
  return OIDC_CONFIG_DIR_RV(cmd, rv);
589
0
}
590
591
3.47k
int oidc_cfg_dir_token_introspection_interval_get(request_rec *r) {
592
3.47k
  const oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
593
3.47k
  if (dir_cfg->oauth_token_introspect_interval <= OIDC_DIR_INT_OFF_UNSET)
594
3.47k
    return OIDC_DEFAULT_TOKEN_INTROSPECTION_INTERVAL;
595
0
  return dir_cfg->oauth_token_introspect_interval;
596
3.47k
}
597
598
OIDC_CFG_DIR_MEMBER_FUNC_GET(pass_cookies, const apr_array_header_t *, NULL, NULL)
599
OIDC_CFG_DIR_MEMBER_FUNC_GET(strip_cookies, const apr_array_header_t *, NULL, NULL)
600
601
/* default action to take on an incoming unauthenticated request */
602
133
#define OIDC_DEFAULT_UNAUTH_ACTION OIDC_UNAUTH_AUTHENTICATE
603
604
161
oidc_unauth_action_t oidc_cfg_dir_unauth_action_get(request_rec *r) {
605
161
  oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
606
161
  const char *s = NULL;
607
161
  oidc_unauth_action_t action = OIDC_CONFIG_POS_INT_UNSET;
608
609
161
  if (dir_cfg->unauth_action == OIDC_CONFIG_POS_INT_UNSET) {
610
133
    action = OIDC_DEFAULT_UNAUTH_ACTION;
611
133
    goto end;
612
133
  }
613
614
28
  if (dir_cfg->unauth_expression == NULL) {
615
28
    action = dir_cfg->unauth_action;
616
28
    goto end;
617
28
  }
618
619
0
  s = oidc_util_apr_expr_exec(r, dir_cfg->unauth_expression, OIDC_APR_EXPR_RESULT_BOOLEAN);
620
621
0
  action = (s != NULL) ? dir_cfg->unauth_action : OIDC_DEFAULT_UNAUTH_ACTION;
622
623
0
  oidc_debug(r, "expression evaluation resulted in: %s (%s) for: %s", oidc_cfg_dir_unauth_action2str(action),
624
0
       s != NULL ? "true" : "false (default)", dir_cfg->unauth_expression->str);
625
626
161
end:
627
628
161
  return action;
629
0
}
630
631
190
apr_byte_t oidc_cfg_dir_unauth_expr_is_set(request_rec *r) {
632
190
  const oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
633
190
  return (dir_cfg->unauth_expression != NULL) ? TRUE : FALSE;
634
190
}
635
636
/* default action to take on an incoming authorized request */
637
#define OIDC_DEFAULT_UNAUTZ_ACTION OIDC_UNAUTZ_RETURN403
638
OIDC_CFG_DIR_MEMBER_FUNC_INT_GET(unautz_action, oidc_unautz_action_t, OIDC_DEFAULT_UNAUTZ_ACTION)
639
640
890
const char *oidc_cfg_dir_unauthz_arg_get(request_rec *r) {
641
890
  const oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
642
890
  return dir_cfg->unauthz_arg;
643
890
}
644
645
107
const char *oidc_cfg_dir_path_auth_request_params_get(request_rec *r) {
646
107
  const oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
647
107
  return oidc_util_apr_expr_exec(r, dir_cfg->path_auth_request_expr, OIDC_APR_EXPR_RESULT_STRING);
648
107
}
649
650
/* default pass user info as */
651
42
#define OIDC_DEFAULT_PASS_USERINFO_AS OIDC_PASS_USERINFO_AS_CLAIMS_STR
652
653
static apr_array_header_t *pass_userinfo_as_default = NULL;
654
655
/*
656
 * forget the default when the pool that holds it is destroyed, so that the next post-config phase in
657
 * this process creates it again rather than leaving a pointer to freed memory behind: the unit tests
658
 * create and destroy a configuration pool for every test, and where they do not fork (CK_FORK=no,
659
 * Windows) they all run in one process
660
 */
661
0
static apr_status_t oidc_cfg_dir_pass_userinfo_as_default_cleanup(void *data) {
662
0
  apr_array_header_t **dflt = data;
663
0
  *dflt = NULL;
664
0
  return APR_SUCCESS;
665
0
}
666
667
/*
668
 * initialize the default pass-userinfo-as array once, from the (single-threaded) post-config phase;
669
 * lazy initialization from the request path is not safe under threaded MPMs because the static and
670
 * the process pool it allocates from are shared across worker threads without locking.
671
 */
672
42
int oidc_cfg_dir_post_config(server_rec *s) {
673
42
  oidc_pass_user_info_as_t *p = NULL;
674
42
  if (pass_userinfo_as_default != NULL)
675
0
    return OK;
676
  /* the configuration pool, not the process pool: this cleanup lives in the module, and httpd unloads
677
   * the module's DSO when it destroys pconf, which happens before the process pool's own cleanups run
678
   * at exit; one registered on the process pool would then jump into unmapped code, crashing every
679
   * shutdown of the parent process. pconf is also cleared on a restart, after which the next
680
   * post-config phase creates the default again. */
681
42
  pass_userinfo_as_default = apr_array_make(s->process->pconf, 3, sizeof(const oidc_pass_user_info_as_t *));
682
42
  apr_pool_cleanup_register(s->process->pconf, &pass_userinfo_as_default,
683
42
          oidc_cfg_dir_pass_userinfo_as_default_cleanup, apr_pool_cleanup_null);
684
42
  if (oidc_cfg_dir_parse_pass_userinfo_as(s->process->pconf, OIDC_DEFAULT_PASS_USERINFO_AS, &p) != NULL)
685
0
    return HTTP_INTERNAL_SERVER_ERROR;
686
42
  APR_ARRAY_PUSH(pass_userinfo_as_default, const oidc_pass_user_info_as_t *) = p;
687
42
  return OK;
688
42
}
689
690
1.68k
const apr_array_header_t *oidc_cfg_dir_pass_userinfo_as_get(request_rec *r) {
691
1.68k
  const oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
692
1.68k
  return dir_cfg->pass_userinfo_as ? dir_cfg->pass_userinfo_as : pass_userinfo_as_default;
693
1.68k
}
694
695
/* default pass id_token as */
696
#define OIDC_DEFAULT_PASS_IDTOKEN_AS OIDC_PASS_IDTOKEN_AS_CLAIMS
697
OIDC_CFG_DIR_MEMBER_FUNC_INT_GET(pass_idtoken_as, oidc_pass_idtoken_as_t, OIDC_DEFAULT_PASS_IDTOKEN_AS)
698
699
#ifdef USE_LIBJQ
700
const char *oidc_cfg_dir_userinfo_claims_expr_get(request_rec *r) {
701
  const oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
702
  return oidc_util_apr_expr_exec(r, dir_cfg->userinfo_claims_expr, OIDC_APR_EXPR_RESULT_STRING);
703
}
704
#endif
705
706
107
const char *oidc_cfg_dir_path_scope_get(request_rec *r) {
707
107
  const oidc_dir_cfg_t *dir_cfg = ap_get_module_config(r->per_dir_config, &auth_openidc_module);
708
107
  return oidc_util_apr_expr_exec(r, dir_cfg->path_scope_expr, OIDC_APR_EXPR_RESULT_STRING);
709
107
}
710
711
/*
712
 * create a new directory config record with defaults
713
 */
714
5.49k
void *oidc_cfg_dir_config_create(apr_pool_t *pool, char *path) {
715
5.49k
  oidc_dir_cfg_t *c = apr_pcalloc(pool, sizeof(oidc_dir_cfg_t));
716
71.3k
  OIDC_DIR_CFG_SIMPLE_MEMBERS(OIDC_DIR_M_CREATE_PTR, OIDC_DIR_M_CREATE_INT, OIDC_DIR_M_CREATE_INT_OFF)
717
5.49k
  c->oauth_accept_token_options = apr_hash_make(pool);
718
5.49k
  return c;
719
5.49k
}
720
721
/*
722
 * pick the "add" hash if it has any entries, otherwise fall back to "base"
723
 */
724
0
static apr_hash_t *_oidc_cfg_dir_merge_hash(apr_hash_t *add, apr_hash_t *base) {
725
0
  return apr_hash_count(add) > 0 ? add : base;
726
0
}
727
728
/*
729
 * pick the "add" INT_OFF value if it was explicitly configured, including to -1
730
 * (i.e. not the OIDC_DIR_INT_OFF_UNSET default), otherwise fall back to "base"
731
 */
732
0
static int _oidc_cfg_dir_merge_int_off(int add, int base) {
733
0
  return add > OIDC_DIR_INT_OFF_UNSET ? add : base;
734
0
}
735
736
/*
737
 * merge a new directory config with a base one
738
 */
739
0
void *oidc_cfg_dir_config_merge(apr_pool_t *pool, void *BASE, void *ADD) {
740
0
  oidc_dir_cfg_t *c = apr_pcalloc(pool, sizeof(oidc_dir_cfg_t));
741
0
  const oidc_dir_cfg_t *base = BASE;
742
0
  const oidc_dir_cfg_t *add = ADD;
743
0
  OIDC_DIR_CFG_SIMPLE_MEMBERS(OIDC_DIR_M_MERGE_PTR, OIDC_DIR_M_MERGE_INT, OIDC_DIR_M_MERGE_INT_OFF)
744
0
  c->oauth_accept_token_options =
745
0
      _oidc_cfg_dir_merge_hash(add->oauth_accept_token_options, base->oauth_accept_token_options);
746
0
  return c;
747
0
}