forked from Uninett/mod_auth_mellon
-
Notifications
You must be signed in to change notification settings - Fork 49
/
auth_mellon_config.c
2268 lines (2019 loc) · 78.6 KB
/
auth_mellon_config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* auth_mellon_config.c: an authentication apache module
* Copyright © 2003-2007 UNINETT (http://www.uninett.no/)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "auth_mellon.h"
#ifdef APLOG_USE_MODULE
APLOG_USE_MODULE(auth_mellon);
#endif
/* This is the default endpoint path. Remember to update the description of
* the MellonEndpointPath configuration directive if you change this.
*/
static const char *default_endpoint_path = "/mellon/";
/* This is the default name of the attribute we use as a username. Remember
* to update the description of the MellonUser configuration directive if
* you change this.
*/
static const char *default_user_attribute = "NAME_ID";
/* This is the default prefix to use for attributes received from the
* server. Customizable using the MellonEnvPrefix option
*/
static const char *default_env_prefix = "MELLON_";
/* This is the default name of the cookie which mod_auth_mellon will set.
* If you change this, then you should also update the description of the
* MellonVar configuration directive.
*/
static const char *default_cookie_name = "cookie";
/* The default setting for cookie is to not enforce secure flag
*/
static const int default_secure_cookie = 0;
/* The default setting for cookie is to not enforce HttpOnly flag
*/
static const int default_http_only_cookie = 0;
/* The default setting for setting MELLON_SESSION
*/
static const int default_dump_session = 0;
/* The default setting for setting MELLON_SAML_RESPONSE
*/
static const int default_dump_saml_response = 0;
/* This is the default IdP initiated login location
* the MellonDefaultLoginPath configuration directive if you change this.
*/
static const char *default_login_path = "/";
/* saved POST session time to live
* the MellonPostTTL configuration directive if you change this.
*/
static const apr_time_t post_ttl = 15 * 60;
/* saved POST session maximum size
* the MellonPostSize configuration directive if you change this.
*/
static const apr_size_t post_size = 1024 * 1024;
/* maximum saved POST sessions
* the MellonPostCount configuration directive if you change this.
*/
static const int post_count = 100;
#ifdef ENABLE_DIAGNOSTICS
/* Default filename for mellon diagnostics log file.
* Relative pathname is relative to server root. */
static const char *default_diag_filename = "logs/mellon_diagnostics";
/* Default state for diagnostics is off */
static am_diag_flags_t default_diag_flags = AM_DIAG_FLAG_DISABLE;
#endif
/* whether to merge env. vars or not
* the MellonMergeEnvVars configuration directive if you change this.
*/
static const char *default_merge_env_vars = NULL;
/* for env. vars with multiple values, the index start
* the MellonEnvVarsIndexStart configuration directive if you change this.
*/
static const int default_env_vars_index_start = -1;
/* whether to also populate env. var _N with number of values
* the MellonEnvVarsSetCount configuration directive if you change this.
*/
static const int default_env_vars_count_in_n = -1;
/* The default list of trusted redirect domains. */
static const char * const default_redirect_domains[] = { "[self]", NULL };
/* The default setting to enabled the invalidation session endpoint
*/
static const int default_enabled_invalidation_session = 0;
/* The default setting to send the Expect Header.
*/
static const int default_send_expect_header = 1;
/* This function handles configuration directives which set a
* multivalued string slot in the module configuration (the destination
* strucure is a hash).
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* const char *key The string argument following this configuration
* directive in the configuraion file.
* const char *value Optional value to be stored in the hash.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_hash_string_slot(cmd_parms *cmd,
void *struct_ptr,
const char *key,
const char *value)
{
server_rec *s = cmd->server;
apr_pool_t *pconf = s->process->pconf;
am_dir_cfg_rec *cfg = (am_dir_cfg_rec *)struct_ptr;
int offset;
apr_hash_t **hash;
/*
* If no value is given, we just store the key in the hash.
*/
if (value == NULL || *value == '\0')
value = key;
offset = (int)(long)cmd->info;
hash = (apr_hash_t **)((char *)cfg + offset);
apr_hash_set(*hash, apr_pstrdup(pconf, key), APR_HASH_KEY_STRING, value);
return NULL;
}
/* This function handles configuration directives which set a
* multivalued string slot in the module configuration (the destination
* strucure is a table).
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* const char *key The string argument following this configuration
* directive in the configuraion file.
* const char *value Optional value to be stored in the hash.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_table_string_slot(cmd_parms *cmd,
void *struct_ptr,
const char *key,
const char *value)
{
server_rec *s = cmd->server;
apr_pool_t *pconf = s->process->pconf;
am_dir_cfg_rec *cfg = (am_dir_cfg_rec *)struct_ptr;
int offset;
apr_table_t **table;
/*
* If no value is given, we just store the key in the hash.
*/
if (value == NULL || *value == '\0')
value = key;
offset = (int)(long)cmd->info;
table = (apr_table_t **)((char *)cfg + offset);
apr_table_set(*table, apr_pstrdup(pconf, key), value);
return NULL;
}
/* This function handles configuration directives which set a file slot
* in the module configuration. The file contents are immediately read.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* This value isn't used by this function.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_file_contents_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
const char *path;
apr_status_t rv;
am_dir_cfg_rec *cfg = (am_dir_cfg_rec *)struct_ptr;
int offset;
am_file_data_t **p_file_data, *file_data;
path = ap_server_root_relative(cmd->pool, arg);
if (!path) {
return apr_pstrcat(cmd->pool, cmd->cmd->name,
": Invalid file path ", arg, NULL);
}
offset = (int)(long)cmd->info;
p_file_data = (am_file_data_t **)((char *)cfg + offset);
*p_file_data = am_file_data_new(cmd->pool, path);
file_data = *p_file_data;
rv = am_file_read(file_data);
if (rv != APR_SUCCESS) {
return file_data->strerror;
}
return NULL;
}
/* This function handles configuration directives which set a file
* pathname in the module configuration. The file is checked for
* existence.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* This value isn't used by this function.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_file_pathname_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
const char *path;
apr_status_t rv;
am_dir_cfg_rec *cfg = (am_dir_cfg_rec *)struct_ptr;
int offset;
am_file_data_t **p_file_data, *file_data;
path = ap_server_root_relative(cmd->pool, arg);
if (!path) {
return apr_pstrcat(cmd->pool, cmd->cmd->name,
": Invalid file_data path ", arg, NULL);
}
offset = (int)(long)cmd->info;
p_file_data = (am_file_data_t **)((char *)cfg + offset);
*p_file_data = am_file_data_new(cmd->pool, path);
file_data = *p_file_data;
rv = am_file_stat(file_data);
if (rv != APR_SUCCESS) {
return file_data->strerror;
}
if (file_data->finfo.filetype != APR_REG) {
return apr_psprintf(cmd->pool, "file \"%s\" is not a regular file",
file_data->path);
}
return NULL;
}
/* This function handles configuration directives which use
* a glob pattern, with a second optional argument
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* const char *glob_pat glob(3) pattern
* const char *option Optional argument
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_glob_fn12(cmd_parms *cmd,
void *struct_ptr,
const char *glob_pat,
const char *option)
{
const char *(*take_argv)(cmd_parms *, void *, const char *, const char *);
apr_array_header_t *files;
const char *error;
const char *directory;
int i;
take_argv = cmd->info;
directory = am_filepath_dirname(cmd->pool, glob_pat);
if (glob_pat == NULL || *glob_pat == '\0')
return apr_psprintf(cmd->pool,
"%s takes one or two arguments",
cmd->cmd->name);
if (apr_match_glob(glob_pat, &files, cmd->pool) != 0)
return take_argv(cmd, struct_ptr, glob_pat, option);
for (i = 0; i < files->nelts; i++) {
const char *path;
path = apr_pstrcat(cmd->pool, directory, "/",
((const char **)(files->elts))[i], NULL);
error = take_argv(cmd, struct_ptr, path, option);
if (error != NULL)
return error;
}
return NULL;
}
/* This function handles configuration directives which set an
* idp related slot in the module configuration.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* const char *metadata Path to metadata file for one or multiple IdP
* const char *chain Optional path to validating chain
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_idp_string_slot(cmd_parms *cmd,
void *struct_ptr,
const char *metadata,
const char *chain)
{
server_rec *s = cmd->server;
apr_pool_t *pconf = s->process->pconf;
am_dir_cfg_rec *cfg = (am_dir_cfg_rec *)struct_ptr;
am_file_data_t *idp_file_data = NULL;
am_file_data_t *chain_file_data = NULL;
idp_file_data = am_file_data_new(pconf, metadata);
if (am_file_stat(idp_file_data) != APR_SUCCESS) {
return idp_file_data->strerror;
}
if (chain) {
chain_file_data = am_file_data_new(pconf, chain);
if (am_file_stat(chain_file_data) != APR_SUCCESS) {
return chain_file_data->strerror;
}
} else {
chain_file_data = NULL;
}
am_metadata_t *idp_metadata = apr_array_push(cfg->idp_metadata);
idp_metadata->metadata = idp_file_data;
idp_metadata->chain = chain_file_data;
return NULL;
}
/* This function handles configuration directives which set an
* idp federation blacklist slot in the module configuration.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* int argc Number of blacklisted providerId.
* char *const argv[] List of blacklisted providerId.
*
* Returns:
* NULL on success, or errror string
*/
static const char *am_set_idp_ignore_slot(cmd_parms *cmd,
void *struct_ptr,
int argc,
char *const argv[])
{
server_rec *s = cmd->server;
apr_pool_t *pconf = s->process->pconf;
am_dir_cfg_rec *cfg = (am_dir_cfg_rec *)struct_ptr;
GList *new_idp_ignore;
int i;
if (argc < 1)
return apr_psprintf(cmd->pool, "%s takes at least one arguments",
cmd->cmd->name);
for (i = 0; i < argc; i++) {
new_idp_ignore = apr_palloc(pconf, sizeof(GList));
new_idp_ignore->data = apr_pstrdup(pconf, argv[i]);
/* Prepend it to the list. */
new_idp_ignore->next = cfg->idp_ignore;
if (cfg->idp_ignore != NULL)
cfg->idp_ignore->prev = new_idp_ignore;
cfg->idp_ignore = new_idp_ignore;
}
return NULL;
}
/* This function handles configuration directives which set a file path
* slot in the module configuration.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* This value isn't used by this function.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_module_config_file_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
return ap_set_file_slot(cmd, am_get_mod_cfg(cmd->server), arg);
}
/* This function handles configuration directives which set an int
* slot in the module configuration.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* This value isn't used by this function.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_module_config_int_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
return ap_set_int_slot(cmd, am_get_mod_cfg(cmd->server), arg);
}
/* This function handles the MellonDiagnosticsFile configuration directive.
* It emits as warning in the log file if Mellon is not built with
* diagnostics enabled.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_module_diag_file_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
#ifdef ENABLE_DIAGNOSTICS
return ap_set_file_slot(cmd, am_get_diag_cfg(cmd->server), arg);
#else
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server,
"%s has no effect because Mellon was not compiled with"
" diagnostics enabled, use ./configure --enable-diagnostics"
" at build time to turn this feature on.",
cmd->directive->directive);
return NULL;
#endif
}
/* This function handles configuration directives which sets the
* diagnostics flags in the module configuration.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_module_diag_flags_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
#ifdef ENABLE_DIAGNOSTICS
am_diag_cfg_rec *diag_cfg = am_get_diag_cfg(cmd->server);
if (strcasecmp(arg, "on") == 0) {
diag_cfg->flags = AM_DIAG_FLAG_ENABLE_ALL;
}
else if (strcasecmp(arg, "off") == 0) {
diag_cfg->flags = AM_DIAG_FLAG_DISABLE;
} else {
return apr_psprintf(cmd->pool, "%s: must be one of: 'on', 'off'",
cmd->cmd->name);
}
return NULL;
#else
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server,
"%s has no effect because Mellon was not compiled with"
" diagnostics enabled, use ./configure --enable-diagnostics"
" at build time to turn this feature on.",
cmd->directive->directive);
return NULL;
#endif
}
/* This function handles the MellonCookieSameSite configuration directive.
* This directive can be set to "lax" or "strict"
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string if the argument is wrong.
*/
static const char *am_set_samesite_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
am_dir_cfg_rec *d = (am_dir_cfg_rec *)struct_ptr;
if(!strcasecmp(arg, "lax")) {
d->cookie_samesite = am_samesite_lax;
} else if(!strcasecmp(arg, "strict")) {
d->cookie_samesite = am_samesite_strict;
} else if(!strcasecmp(arg, "none")) {
d->cookie_samesite = am_samesite_none;
} else {
return "The MellonCookieSameSite parameter must be 'lax', 'none' or 'strict'";
}
return NULL;
}
/* This function handles the MellonEnable configuration directive.
* This directive can be set to "off", "info" or "auth".
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string if the argument is wrong.
*/
static const char *am_set_enable_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
am_dir_cfg_rec *d = (am_dir_cfg_rec *)struct_ptr;
if(!strcasecmp(arg, "auth")) {
d->enable_mellon = am_enable_auth;
} else if(!strcasecmp(arg, "info")) {
d->enable_mellon = am_enable_info;
} else if(!strcasecmp(arg, "off")) {
d->enable_mellon = am_enable_off;
} else {
return "parameter must be 'off', 'info' or 'auth'";
}
return NULL;
}
/* This function handles the MellonSecureCookie configuration directive.
* This directive can be set to "on", "off", "secure" or "httponly".
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string if the argument is wrong.
*/
static const char *am_set_secure_slots(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
am_dir_cfg_rec *d = (am_dir_cfg_rec *)struct_ptr;
if(!strcasecmp(arg, "on")) {
d->secure = 1;
d->http_only = 1;
} else if(!strcasecmp(arg, "secure")) {
d->secure = 1;
} else if(!strcasecmp(arg, "httponly")) {
d->http_only = 1;
} else if(strcasecmp(arg, "off")) {
return "parameter must be 'on', 'off', 'secure' or 'httponly'";
}
return NULL;
}
/* This function handles the obsolete configuration directives.
* It is a no-op but logs a warning on startup.
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL
*/
static const char *am_set_obsolete_option(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server,
"Obsolete option %s set which has no effect",
cmd->cmd->name);
return NULL;
}
/* This function handles the MellonEndpointPath configuration directive.
* If the path doesn't end with a '/', then we will append one.
*
* Parameters:
* cmd_parms *cmd The command structure for the MellonEndpointPath
* configuration directive.
* void *struct_ptr Pointer to the current directory configuration.
* NULL if we are not in a directory configuration.
* const char *arg The string argument containing the path of the
* endpoint directory.
*
* Returns:
* This function will always return NULL.
*/
static const char *am_set_endpoint_path(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
am_dir_cfg_rec *d = (am_dir_cfg_rec *)struct_ptr;
/* Make sure that the path ends with '/'. */
if(strlen(arg) == 0 || arg[strlen(arg) - 1] != '/') {
d->endpoint_path = apr_pstrcat(cmd->pool, arg, "/", NULL);
} else {
d->endpoint_path = arg;
}
return NULL;
}
/* This function handles the MellonSetEnv configuration directive.
* This directive allows the user to change the name of attributes.
*
* Parameters:
* cmd_parms *cmd The command structure for the MellonSetEnv
* configuration directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *newName The new name of the attribute.
* const char *oldName The old name of the attribute.
*
* Returns:
* This function will always return NULL.
*/
static const char *am_set_setenv_slot(cmd_parms *cmd,
void *struct_ptr,
const char *newName,
const char *oldName)
{
am_dir_cfg_rec *d = (am_dir_cfg_rec *)struct_ptr;
/* Configure as prefixed attribute name */
am_envattr_conf_t *envattr_conf = (am_envattr_conf_t *)apr_palloc(cmd->pool, sizeof(am_envattr_conf_t));
envattr_conf->name = newName;
envattr_conf->prefixed = 1;
apr_hash_set(d->envattr, oldName, APR_HASH_KEY_STRING, envattr_conf);
return NULL;
}
/* This function handles the MellonSetEnvNoPrefix configuration directive.
* This directive allows the user to change the name of attributes without prefixing them with MELLON_.
*
* Parameters:
* cmd_parms *cmd The command structure for the MellonSetEnv
* configuration directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *newName The new name of the attribute.
* const char *oldName The old name of the attribute.
*
* Returns:
* This function will always return NULL.
*/
static const char *am_set_setenv_no_prefix_slot(cmd_parms *cmd,
void *struct_ptr,
const char *newName,
const char *oldName)
{
am_dir_cfg_rec *d = (am_dir_cfg_rec *)struct_ptr;
/* Configure as not prefixed attribute name */
am_envattr_conf_t *envattr_conf = (am_envattr_conf_t *)apr_palloc(cmd->pool, sizeof(am_envattr_conf_t));
envattr_conf->name = newName;
envattr_conf->prefixed = 0;
apr_hash_set(d->envattr, oldName, APR_HASH_KEY_STRING, envattr_conf);
return NULL;
}
/* This function handles the MellonAuthnContextComparisonType option.
* It could be set to "exact", "minimum", "maximum" or "better"
*
* Parameters:
* cmd_parms *cmd The command structure for this configuration
* directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *arg The string argument following this configuration
* directive in the configuraion file.
*
* Returns:
* NULL on success or an error string if the argument is wrong.
*/
static const char *am_set_authn_context_comparison_type_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
am_dir_cfg_rec *d = (am_dir_cfg_rec *)struct_ptr;
if (!strcasecmp(arg, LASSO_LIB_AUTHN_CONTEXT_COMPARISON_EXACT)) {
d->authn_context_comparison_type =
LASSO_LIB_AUTHN_CONTEXT_COMPARISON_EXACT;
} else if (!strcasecmp(arg, LASSO_LIB_AUTHN_CONTEXT_COMPARISON_MINIMUM)) {
d->authn_context_comparison_type =
LASSO_LIB_AUTHN_CONTEXT_COMPARISON_MINIMUM;
} else if (!strcasecmp(arg, LASSO_LIB_AUTHN_CONTEXT_COMPARISON_MAXIMUM)) {
d->authn_context_comparison_type =
LASSO_LIB_AUTHN_CONTEXT_COMPARISON_MAXIMUM;
} else if (!strcasecmp(arg, LASSO_LIB_AUTHN_CONTEXT_COMPARISON_BETTER)) {
d->authn_context_comparison_type =
LASSO_LIB_AUTHN_CONTEXT_COMPARISON_BETTER;
} else {
return "parameter must be 'exact', 'minimum', 'maximum' or 'better'";
}
return NULL;
}
/* This function decodes MellonCond flags, such as [NOT,REG]
*
* Parameters:
* const char *arg Pointer to the flags string
*
* Returns:
* flags, or -1 on error
*/
static int am_cond_flags(const char *arg)
{
int flags = AM_COND_FLAG_NULL;
static const char * const options[] = {
"OR", /* AM_EXPIRE_FLAG_OR */
"NOT", /* AM_EXPIRE_FLAG_NOT */
"REG", /* AM_EXPIRE_FLAG_REG */
"NC", /* AM_EXPIRE_FLAG_NC */
"MAP", /* AM_EXPIRE_FLAG_MAP */
"REF", /* AM_EXPIRE_FLAG_REF */
"SUB", /* AM_EXPIRE_FLAG_SUB */
/* The other options (IGN, REQ, FSTR, ...) are only internally used */
};
apr_size_t options_count = sizeof(options) / sizeof(*options);
/* Skip initial [ */
if (arg[0] == '[')
arg++;
else
return -1;
do {
apr_size_t i;
for (i = 0; i < options_count; i++) {
apr_size_t optlen = strlen(options[i]);
if (strncmp(arg, options[i], optlen) == 0) {
/* Make sure we have a separator next */
if (arg[optlen] && !strchr("]\t ,", (int)arg[optlen]))
return -1;
flags |= (1 << i);
arg += optlen;
break;
}
/* no match */
if (i == options_count)
return -1;
/* skip spaces, tabs and commas */
arg += strspn(arg, " \t,");
/*
* End of option, but we fire an error if
* there is trailing garbage
*/
if (*arg == ']') {
arg++;
return (*arg == '\0') ? flags : -1;
}
}
} while (*arg);
/* Missing trailing ] */
return -1;
}
/* This function handles the MellonCond configuration directive, which
* allows the user to restrict access based on attributes received from
* the IdP.
*
* Parameters:
* cmd_parms *cmd The command structure for the MellonCond
* configuration directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *attribute Pointer to the attribute name
* const char *value Pointer to the attribute value or regex
* const char *options Pointer to options
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_cond_slot(cmd_parms *cmd,
void *struct_ptr,
const char *attribute,
const char *value,
const char *options)
{
am_dir_cfg_rec *d = struct_ptr;
int flags = AM_COND_FLAG_NULL;
am_cond_t *element;
if (attribute == NULL || *attribute == '\0' ||
value == NULL || *value == '\0')
return apr_pstrcat(cmd->pool, cmd->cmd->name,
" takes at least two arguments", NULL);
if (options != NULL && *options != '\0')
flags = am_cond_flags(options);
if (flags == -1)
return apr_psprintf(cmd->pool, "%s - invalid flags %s",
cmd->cmd->name, options);
element = (am_cond_t *)apr_array_push(d->cond);
element->varname = attribute;
element->flags = flags;
element->str = NULL;
element->regex = NULL;
element->directive = apr_pstrcat(cmd->pool, cmd->directive->directive,
" ", cmd->directive->args, NULL);
if (element->flags & AM_COND_FLAG_REG) {
int regex_flags = AP_REG_EXTENDED|AP_REG_NOSUB;
if (element->flags & AM_COND_FLAG_NC)
regex_flags |= AP_REG_ICASE;
element->regex = ap_pregcomp(cmd->pool, value, regex_flags);
if (element->regex == NULL)
return apr_psprintf(cmd->pool, "%s - invalid regex %s",
cmd->cmd->name, value);
}
/*
* Flag values containing format strings to that we do
* not have to process the others at runtime.
*/
if (strchr(value, '%') != NULL)
element->flags |= AM_COND_FLAG_FSTR;
/*
* We keep the string also for regex, so that we can
* print it for debug purpose and perform substitutions on it.
*/
element->str = value;
return NULL;
}
/* This function handles the MellonRequire configuration directive, which
* allows the user to restrict access based on attributes received from
* the IdP.
*
* Parameters:
* cmd_parms *cmd The command structure for the MellonRequire
* configuration directive.
* void *struct_ptr Pointer to the current directory configuration.
* const char *arg Pointer to the configuration string.
*
* Returns:
* NULL on success or an error string on failure.
*/
static const char *am_set_require_slot(cmd_parms *cmd,
void *struct_ptr,
const char *arg)
{
am_dir_cfg_rec *d = struct_ptr;
char *attribute, *value;
int i;
am_cond_t *element;
am_cond_t *first_element;
attribute = ap_getword_conf(cmd->pool, &arg);
value = ap_getword_conf(cmd->pool, &arg);
if (*attribute == '\0' || *value == '\0') {
return apr_pstrcat(cmd->pool, cmd->cmd->name,
" takes at least two arguments", NULL);
}
/*
* MellonRequire overwrites previous conditions on this attribute
* We just tag the am_cond_t with the ignore flag, as it is
* easier (and probably faster) than to really remove it.
*/
for (i = 0; i < d->cond->nelts; i++) {
am_cond_t *ce = &((am_cond_t *)(d->cond->elts))[i];
if ((strcmp(ce->varname, attribute) == 0) &&
(ce->flags & AM_COND_FLAG_REQ))
ce->flags |= AM_COND_FLAG_IGN;
}
first_element = NULL;
do {
element = (am_cond_t *)apr_array_push(d->cond);
element->varname = attribute;
element->flags = AM_COND_FLAG_OR|AM_COND_FLAG_REQ;
element->str = value;
element->regex = NULL;
/*
* When multiple values are given, we track the first one
* in order to retreive the directive
*/
if (first_element == NULL) {
element->directive = apr_pstrcat(cmd->pool,
cmd->directive->directive, " ",
cmd->directive->args, NULL);
first_element = element;
} else {
element->directive = first_element->directive;
}
} while (*(value = ap_getword_conf(cmd->pool, &arg)) != '\0');