-
Notifications
You must be signed in to change notification settings - Fork 44
/
init.c
1810 lines (1500 loc) · 55.2 KB
/
init.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
/*
* Copyright The rpminspect Project Authors
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <libgen.h>
#include <regex.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>
#include <errno.h>
#include <err.h>
#include <toml.h>
#include "internal/callbacks.h"
#include "parser.h"
#include "rpminspect.h"
#include "init.h"
#include "remedy.h"
#include "queue.h"
#include "uthash.h"
/*
* Debug printing on the config file parser is verbose, so it can be
* disabled by commenting this line out and uncommented the
* INIT_DEBUG_PRINT line that expands to void.
*/
/* #define INIT_DEBUG_PRINT DEBUG_PRINT */
#define INIT_DEBUG_PRINT(...) (void)(0)
/* List defaults (not in constants.h to avoid cpp shenanigans) */
/**
* @def BIN_PATHS
* NULL terminated array of strings of paths where executable files
* may reside.
*/
static const char *BIN_PATHS[] = {"/bin", "/sbin", "/usr/bin", "/usr/sbin", NULL};
/**
* @def SHELLS
* NULL terminated array of strings of shells to use for syntax
* checking (only the basename is needed). All shells listed must
* support the '-n' option for syntax checking. The shell should exit
* 0 if the syntax checker passes, non-zero otherwise. The 'rc' shell
* is an exception and has special handling in the 'shellsyntax'
* inspection.
*/
static const char *SHELLS[] = {"sh", "ksh", "zsh", "csh", "tcsh", "rc", "bash", NULL};
/* Supported config filename endings (we assume type by this) */
static const char *CFG_FILENAME_EXTENSIONS[] = {"yaml", "json", "dson", NULL};
/**
* @def UDEV_RULES_DIRS
* NULL terminated array of strings of directories where udev rules files
* may reside.
*/
static const char *UDEV_RULES_DIRS[] = {"/etc/udev/rules.d/", "/usr/lib/udev/rules.d/", NULL};
/* flag indicating the remedy strings have been initialized */
static bool remedy_initialized = false;
static int add_regex(const char *pattern, regex_t **regex_out)
{
int reg_result;
char *errbuf = NULL;
size_t errbuf_size;
if (pattern == NULL || *pattern == '\0') {
return 0;
}
assert(regex_out);
free_regex(*regex_out);
*regex_out = xalloc(sizeof(regex_t));
if ((reg_result = regcomp(*regex_out, pattern, REG_EXTENDED)) != 0) {
/* Get the size needed for the error message */
errbuf_size = regerror(reg_result, *regex_out, NULL, 0);
errbuf = xalloc(errbuf_size);
regerror(reg_result, *regex_out, errbuf, errbuf_size);
warnx("*** %s", errbuf);
/* Clean up and return error */
free(errbuf);
free(*regex_out);
return -1;
}
return 0;
}
/*
* Given an inspection identifier from the config file reader and a
* list value, add it to the per-inspection list of ignores.
*/
static void add_string_list_map_entry(string_list_map_t **table, const char *key, const char *value)
{
string_list_map_t *mapentry = NULL;
assert(key != NULL);
assert(value != NULL);
/* look for the list first, add if not found */
HASH_FIND_STR(*table, key, mapentry);
if (mapentry == NULL) {
/* start a new entry for this inspection */
mapentry = xalloc(sizeof(*mapentry));
mapentry->key = strdup(key);
mapentry->value = list_add(mapentry->value, value);
HASH_ADD_KEYPTR(hh, *table, mapentry->key, strlen(mapentry->key), mapentry);
} else {
/* add to existing ignore list */
mapentry->value = list_add(mapentry->value, value);
}
return;
}
/**
* Given a key and value, initialize a new hash table (clearing the
* old one if necessary) and migrate the data from the list to the
* hash table. Clear the incoming hash table list. The caller is
* responsible for freeing all memory allocated to these structures.
*
* If required is set to true, this function will only append the
* value to an existing key in the table. Use this parameter if
* processing a secondary table and you require the key to exist from
* a previous processing run.
*
* NOTE: The incoming table entries will be removed and freed as the
* data is migrated to the table and keys. Before return, the
* incoming table list will be freed. The actual key and value
* strings in each incoming table entry are not freed since they just
* migrate over to the new structures, but the entries themselves are
* removed and freed from the incoming table.
*
* @param key The key in the hash table (string).
* @param value The value to add to the hash table (string).
* @param required Set to true if key must exist to append value to list.
* @param single Set to true if key must contain only a single value,
* otherwise it's a string list.
* @param table Destination hash table.
*/
static void process_table(const char *key, const char *value, const bool required, const bool single, string_map_t **table)
{
char *tmp = NULL;
string_list_t *tokens = NULL;
string_map_t *entry = NULL;
assert(key != NULL);
assert(value != NULL);
/* look for the key first */
HASH_FIND_STR(*table, key, entry);
if (entry == NULL) {
if (required) {
warnx("*** missing key `%s', unable to append `%s'", key, value);
} else {
/* add the new key/value pair to the table */
entry = xalloc(sizeof(*entry));
entry->key = strdup(key);
entry->value = strdup(value);
HASH_ADD_KEYPTR(hh, *table, entry->key, strlen(entry->key), entry);
}
} else {
/* entry found, handle the value */
if (entry->value != NULL && !single) {
tokens = strsplit(entry->value, " ");
assert(tokens != NULL);
tokens = list_add(tokens, value);
tmp = list_to_string(tokens, " ");
list_free(tokens, free);
} else {
tmp = strdup(value);
}
assert(tmp != NULL);
free(entry->value);
entry->value = tmp;
}
return;
}
/*
* Convert a 10 character mode string for a file to a mode_t
* For example, convert "-rwsr-xr-x" to a mode_t
*/
static mode_t parse_mode(const char *input)
{
mode_t mode = 0;
char i;
assert(input != NULL);
if (strlen(input) != 10) {
warnx(_("*** invalid input string `%s`"), input);
return mode;
}
/* type */
i = input[0];
if (i == 'd') {
mode |= S_IFDIR;
} else if (i == 'c') {
mode |= S_IFCHR;
} else if (i == 'b') {
mode |= S_IFBLK;
} else if (i == '-') {
mode |= S_IFREG;
} else if (i == 'l') {
mode |= S_IFLNK;
} else if (i == 's') {
mode |= S_IFSOCK;
#ifdef S_IFIFO
} else if (i == 'p') {
mode |= S_IFIFO;
#endif
#ifdef S_IFWHT
} else if (i == 'w') {
mode |= S_IFWHT;
#endif
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
/* owner */
i = input[1];
if (i == 'r') {
mode |= S_IRUSR;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
i = input[2];
if (i == 'w') {
mode |= S_IWUSR;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
i = input[3];
if (i == 'x') {
mode |= S_IXUSR;
} else if (i == 'S') {
mode |= S_ISUID;
} else if (i == 's') {
mode |= S_IXUSR | S_ISUID;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
/* group */
i = input[4];
if (i == 'r') {
mode |= S_IRGRP;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
i = input[5];
if (i == 'w') {
mode |= S_IWGRP;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
i = input[6];
if (i == 'x') {
mode |= S_IXGRP;
} else if (i == 'S') {
mode |= S_ISGID;
} else if (i == 's') {
mode |= S_IXGRP | S_ISGID;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
/* other */
i = input[7];
if (i == 'r') {
mode |= S_IROTH;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
i = input[8];
if (i == 'w') {
mode |= S_IWOTH;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
i = input[9];
if (i == 'x') {
mode |= S_IXOTH;
} else if (i == 'T') {
mode |= S_ISVTX;
} else if (i == 't') {
mode |= S_IXOTH | S_ISVTX;
} else if (i != '-') {
warnx(_("*** invalid mode string: %s"), input);
return mode;
}
return mode;
}
/*
* Retrieve a string from configuration, updating the specified field if it
* has already been defined.
*/
static inline void strget(parser_plugin *p, parser_context *ctx, const char *key1, const char *key2, char **dest)
{
char *res;
res = p->getstr(ctx, key1, key2);
if (res == NULL) {
return;
}
free(*dest);
*dest = res;
return;
}
/* lambda for add_ignores() below. */
static bool add_ignores_cb(const char *entry, void *cb_data)
{
add_ignores_cb_data *d = cb_data;
add_string_list_map_entry(d->inspection_ignores, d->inspection, entry);
return false;
}
/* Load and add an inspection's ignores section. */
static inline void add_ignores(struct rpminspect *ri, parser_plugin *p, parser_context *ctx, const char *inspection)
{
add_ignores_cb_data data = { &ri->inspection_ignores, inspection };
if (p->strarray_foreach(ctx, inspection, RI_IGNORE, add_ignores_cb, &data)
&& p->strarray_foreach(ctx, inspection, RI_IGNORES, add_ignores_cb, &data)) {
warnx(_("*** problem adding ignore entries to %s"), inspection);
}
return;
}
/*
* Handle inclusion and exclusion paths for an inspection. Pass the bare name
* of an inspection, not a string. Reuses variables from context.
*/
#define ADD_INCL_EXCL(inspection) \
s = p->getstr(ctx, #inspection, RI_INCLUDE_PATH); \
\
if (s != NULL) { \
if (debug_mode) { \
ri->inspection ## _path_include_pattern = strdup(s); \
} \
\
if (add_regex(s, &ri->inspection ## _path_include) != 0) { \
warnx(_("*** error reading " #inspection " include path")); \
} \
\
free(s); \
} \
\
s = p->getstr(ctx, #inspection, RI_EXCLUDE_PATH); \
\
if (s != NULL) { \
if (debug_mode) { \
ri->inspection ## _path_exclude_pattern = strdup(s); \
} \
\
if (add_regex(s, &ri->inspection ## _path_exclude) != 0) { \
warnx(_("*** error reading " #inspection " include path")); \
} \
\
free(s); \
}
/* lambda for tabledict below. */
static bool tabledict_cb(const char *key, const char *value, void *cb_data)
{
tabledict_cb_data *data = cb_data;
/* javabytecode uses this at top-level, but also supports ignores. */
if (!strcasecmp(key, RI_IGNORE)) {
return false;
}
process_table(key, value, data->required, data->single, data->table);
return false;
}
/* Process a dictionary of strings into the specified table. */
static void tabledict(parser_plugin *p, parser_context *ctx, const char *key1, const char *key2, string_map_t **table, bool required, bool single)
{
tabledict_cb_data data = { required, single, table };
if (p->strdict_foreach(ctx, key1, key2, tabledict_cb, &data)) {
warnx(_("*** ignoring malformed section %s->%s"), key1, key2);
}
return;
}
/* lambda for handling old-style top-level annocheck jobs. A special case of
* tabledict_cb that skips more keys. */
static bool annocheck_cb(const char *key, const char *value, void *cb_data)
{
tabledict_cb_data *data = cb_data;
if (!strcasecmp(key, RI_FAILURE_SEVERITY) || !strcasecmp(key, RI_EXTRA_OPTS) || !strcasecmp(key, RI_IGNORE)) {
return false;
}
process_table(key, value, data->required, data->single, data->table);
return false;
}
/* lambda to handle entries in the rpmdeps config file section. */
static bool rpmdeps_cb(const char *key, const char *value, void *cb_data)
{
deprule_ignore_map_t **deprules_ignore = cb_data;
dep_type_t depkey = TYPE_NULL;
deprule_ignore_map_t *drentry = NULL;
if (!strcmp(key, RI_REQUIRES)) {
depkey = TYPE_REQUIRES;
} else if (!strcmp(key, RI_PROVIDES)) {
depkey = TYPE_PROVIDES;
} else if (!strcmp(key, RI_CONFLICTS)) {
depkey = TYPE_CONFLICTS;
} else if (!strcmp(key, RI_OBSOLETES)) {
depkey = TYPE_OBSOLETES;
} else if (!strcmp(key, RI_ENHANCES)) {
depkey = TYPE_ENHANCES;
} else if (!strcmp(key, RI_RECOMMENDS)) {
depkey = TYPE_RECOMMENDS;
} else if (!strcmp(key, RI_SUGGESTS)) {
depkey = TYPE_SUGGESTS;
} else if (!strcmp(key, RI_SUPPLEMENTS)) {
depkey = TYPE_SUPPLEMENTS;
}
if (depkey != TYPE_NULL) {
HASH_FIND_INT(*deprules_ignore, &depkey, drentry);
}
/* overwrite existing entry, otherwise create new one */
if (drentry == NULL) {
drentry = xalloc(sizeof(*drentry));
drentry->type = depkey;
drentry->pattern = strdup(value);
if (add_regex(value, &drentry->ignore) != 0) {
warnx(_("*** error reading %s ignore pattern"), get_deprule_desc(depkey));
}
HASH_ADD_INT(*deprules_ignore, type, drentry);
} else {
free(drentry->pattern);
drentry->pattern = NULL;
drentry->type = depkey;
drentry->pattern = strdup(value);
regfree(drentry->ignore);
drentry->ignore = NULL;
if (add_regex(value, &drentry->ignore) != 0) {
warnx(_("*** error reading %s ignore pattern"), get_deprule_desc(depkey));
}
}
return false;
}
/* lambda for handle_inspections() below. */
static bool handle_inspections_cb(const char *key, const char *value, void *cb_data)
{
uint64_t *tests = cb_data;
bool onoff = true;
if (!strcasecmp(value, RI_ON)) {
onoff = false;
} else if (strcasecmp(value, RI_OFF)) {
warnx(_("*** flag must be 'on' or 'off'; ignoring '%s'"), value);
}
if (!process_inspection_flag(key, onoff, tests)) {
err(RI_PROGRAM_ERROR, _("*** unknown inspections: `%s`"), key);
return true;
}
return false;
}
/* Turn inspections on and off from the "inspections" config section. */
static inline void handle_inspections(struct rpminspect *ri, parser_plugin *p, parser_context *ctx)
{
if (p->strdict_foreach(ctx, RI_INSPECTIONS, NULL, handle_inspections_cb, &ri->tests)) {
warnx(_("*** malformed/unknown inspections section"));
}
return;
}
/* lambda for adding entries from the badfuncs_allowed configuration. */
static bool badfuncs_allowed_cb(const char *key, const char *value, void *cb_data)
{
string_list_map_t **bad_functions_allowed = cb_data;
add_string_list_map_entry(bad_functions_allowed, key, value);
return false;
}
/* Process a desktop skip array and merge it in to desktop_skips_t */
static void process_desktop_skips(desktop_skips_t **desktop_skips, string_list_t *slist, int flag)
{
string_entry_t *sentry = NULL;
desktop_skips_t *ds = NULL;
assert(desktop_skips != NULL);
if (slist == NULL || TAILQ_EMPTY(slist)) {
return;
}
TAILQ_FOREACH(sentry, slist, items) {
HASH_FIND_STR(*desktop_skips, sentry->data, ds);
if (ds == NULL) {
ds = xalloc(sizeof(*ds));
ds->path = strdup(sentry->data);
assert(ds->path != NULL);
ds->flags |= flag;
HASH_ADD_KEYPTR(hh, *desktop_skips, ds->path, strlen(ds->path), ds);
} else {
ds->flags |= flag;
}
}
return;
}
/*
* Callback function for toml_walk() to read in the data from the
* remedy override file.
*/
static inline void _remedy_walker(struct toml_node *node, void *data)
{
char *r = NULL;
char *n = NULL;
string_entry_t *entry = NULL;
struct rpminspect *ri = (struct rpminspect *) data;
static bool in_remedy = false;
/* sure, beginning of document, got it */
if (toml_type(node) == TOML_ROOT) {
return;
}
/* the name in this context is like 'key' in key=value */
n = toml_name(node);
/* note if we are in the [remedy] section */
if (toml_type(node) == TOML_TABLE && n != NULL && !strcmp(n, "remedy")) {
in_remedy = true;
free(n);
return;
}
/* gather all strings in the remedy section that match a known remedy */
if (in_remedy && toml_type(node) == TOML_STRING) {
r = toml_value_as_string(node);
if (r) {
ri->remedy_overrides = list_add(ri->remedy_overrides, r);
if (!set_remedy(n, r)) {
warnx("*** '%s' is not a valid remedy identifier", n);
TAILQ_REMOVE(ri->remedy_overrides, entry, items);
free(entry->data);
free(entry);
}
}
free(r);
}
free(n);
return;
}
/*
* Parse remedy TOML file and load override remedy strings.
*/
static void read_remedy(const char *remedyfile, struct rpminspect *ri)
{
struct toml_node *root = NULL;
char *buf = NULL;
off_t len;
assert(ri != NULL);
/* no remedyfile defined in the config file, fine */
if (remedyfile == NULL) {
return;
}
/* init libtoml and read in the file */
if (toml_init(&root)) {
warn("toml_init");
return;
}
buf = read_file_bytes(remedyfile, &len);
if (toml_parse(root, buf, strlen(buf))) {
warn("toml_parse");
free(buf);
toml_free(root);
return;
}
free(buf);
/* walk the results */
toml_walk(root, _remedy_walker, ri);
/* clean up */
toml_free(root);
return;
}
/*
* Read either the main configuration file or a configuration file
* overlay (profile) and populate the struct rpminspect members.
*/
static void read_cfgfile(struct rpminspect *ri, const char *filename, const bool local)
{
parser_plugin *p = NULL;
parser_context *ctx = NULL;
char *s = NULL;
tabledict_cb_data annocheck_cb_data = { false, false, &ri->annocheck };
string_list_t *slist = NULL;
assert(ri != NULL);
assert(filename != NULL);
INIT_DEBUG_PRINT("filename=|%s|\n", filename);
if (parse_agnostic(filename, &p, &ctx)) {
warnx(_("*** ignoring malformed %s configuration file: %s"), COMMAND_NAME, filename);
return;
}
/* Processing order doesn't matter, so match data/generic.yaml. */
/* Read in common settings */
strget(p, ctx, RI_COMMON, RI_WORKDIR, &ri->workdir);
strget(p, ctx, RI_COMMON, RI_PROFILEDIR, &ri->profiledir);
strget(p, ctx, RI_COMMON, RI_REMEDYFILE, &ri->remedyfile);
if (ri->remedyfile != NULL) {
/* remedy override strings, try to read in */
read_remedy(ri->remedyfile, ri);
}
/* Read in some other basic settings */
strget(p, ctx, RI_KOJI, RI_HUB, &ri->kojihub);
strget(p, ctx, RI_KOJI, RI_DOWNLOAD_URSINE, &ri->kojiursine);
strget(p, ctx, RI_KOJI, RI_DOWNLOAD_MBS, &ri->kojimbs);
strget(p, ctx, RI_COMMANDS, RI_MSGUNFMT, &ri->commands.msgunfmt);
strget(p, ctx, RI_COMMANDS, RI_DESKTOP_FILE_VALIDATE, &ri->commands.desktop_file_validate);
strget(p, ctx, RI_COMMANDS, RI_ABIDIFF, &ri->commands.abidiff);
strget(p, ctx, RI_COMMANDS, RI_KMIDIFF, &ri->commands.kmidiff);
strget(p, ctx, RI_COMMANDS, RI_UDEVADM, &ri->commands.udevadm);
strget(p, ctx, RI_VENDOR, RI_VENDOR_DATA_DIR, &ri->vendor_data_dir);
array(p, ctx, RI_VENDOR, RI_LICENSEDB, &ri->licensedb);
s = p->getstr(ctx, RI_ENVIRONMENT, RI_PRODUCT_RELEASE);
if (s != NULL) {
ri->have_environment = true;
free(ri->product_release);
ri->product_release = s;
s = NULL;
}
s = p->getstr(ctx, RI_VENDOR, RI_FAVOR_RELEASE);
if (s != NULL) {
if (!strcasecmp(s, RI_OLDEST)) {
ri->favor_release = FAVOR_OLDEST;
} else if (!strcasecmp(s, RI_NEWEST)) {
ri->favor_release = FAVOR_NEWEST;
} else {
ri->favor_release = FAVOR_NONE;
}
free(s);
}
handle_inspections(ri, p, ctx);
tabledict(p, ctx, RI_PRODUCTS, NULL, &ri->products, false, false);
array(p, ctx, RI_MACROFILES, NULL, &ri->macrofiles);
array(p, ctx, RI_IGNORE, NULL, &ri->ignores);
array(p, ctx, RI_SECURITY_PATH_PREFIX, NULL, &ri->security_path_prefix);
array(p, ctx, RI_BADWORDS, NULL, &ri->badwords);
strget(p, ctx, RI_METADATA, RI_VENDOR, &ri->vendor);
array(p, ctx, RI_METADATA, RI_BUILDHOST_SUBDOMAIN, &ri->buildhost_subdomain);
#ifdef _HAVE_MODULARITYLABEL
s = p->getstr(ctx, RI_MODULARITY, RI_STATIC_CONTEXT);
if (s != NULL) {
if (!strcasecmp(s, RI_REQUIRED)) {
ri->modularity_static_context = STATIC_CONTEXT_REQUIRED;
} else if (!strcasecmp(s, RI_FORBIDDEN)) {
ri->modularity_static_context = STATIC_CONTEXT_FORBIDDEN;
} else if (!strcasecmp(s, RI_RECOMMEND)) {
ri->modularity_static_context = STATIC_CONTEXT_RECOMMEND;
} else {
ri->modularity_static_context = STATIC_CONTEXT_NULL;
warnx(_("*** unknown modularity static context settiongs '%s'"), s);
}
free(s);
}
tabledict(p, ctx, RI_MODULARITY, RI_RELEASE_REGEXP, &ri->modularity_release, false, false);
#endif
ADD_INCL_EXCL(elf);
add_ignores(ri, p, ctx, RI_ELF);
array(p, ctx, RI_EMPTYRPM, RI_EXPECTED_EMPTY, &ri->expected_empty_rpms);
ADD_INCL_EXCL(manpage);
add_ignores(ri, p, ctx, RI_MANPAGE);
ADD_INCL_EXCL(xml);
add_ignores(ri, p, ctx, RI_XML);
strget(p, ctx, RI_DESKTOP, RI_DESKTOP_ENTRY_FILES_DIR, &ri->desktop_entry_files_dir);
/* handle the desktop skips as two arrays and then merge them in to desktop_skips */
array(p, ctx, RI_DESKTOP, RI_DESKTOP_SKIP_EXEC_CHECK, &slist);
process_desktop_skips(&ri->desktop_skips, slist, SKIP_EXEC);
list_free(slist, free);
slist = NULL;
array(p, ctx, RI_DESKTOP, RI_DESKTOP_SKIP_ICON_CHECK, &slist);
process_desktop_skips(&ri->desktop_skips, slist, SKIP_ICON);
list_free(slist, free);
slist = NULL;
add_ignores(ri, p, ctx, RI_DESKTOP);
array(p, ctx, RI_CHANGEDFILES, RI_HEADER_FILE_EXTENSIONS, &ri->header_file_extensions);
add_ignores(ri, p, ctx, RI_CHANGEDFILES);
array(p, ctx, RI_ADDEDFILES, RI_FORBIDDEN_PATH_PREFIXES, &ri->forbidden_path_prefixes);
array(p, ctx, RI_ADDEDFILES, RI_FORBIDDEN_PATH_SUFFIXES, &ri->forbidden_path_suffixes);
array(p, ctx, RI_ADDEDFILES, RI_FORBIDDEN_DIRECTORIES, &ri->forbidden_directories);
add_ignores(ri, p, ctx, RI_ADDEDFILES);
add_ignores(ri, p, ctx, RI_MOVEDFILES);
add_ignores(ri, p, ctx, RI_REMOVEDFILES);
array(p, ctx, RI_OWNERSHIP, RI_BIN_PATHS, &ri->bin_paths);
strget(p, ctx, RI_OWNERSHIP, RI_BIN_OWNER, &ri->bin_owner);
strget(p, ctx, RI_OWNERSHIP, RI_BIN_GROUP, &ri->bin_group);
array(p, ctx, RI_OWNERSHIP, RI_FORBIDDEN_OWNERS, &ri->forbidden_owners);
array(p, ctx, RI_OWNERSHIP, RI_FORBIDDEN_GROUPS, &ri->forbidden_groups);
add_ignores(ri, p, ctx, RI_OWNERSHIP);
array(p, ctx, RI_SHELLSYNTAX, RI_SHELLS, &ri->shells);
add_ignores(ri, p, ctx, RI_SHELLSYNTAX);
s = p->getstr(ctx, RI_FILESIZE, RI_SIZE_THRESHOLD);
if (s != NULL) {
if (!strcasecmp(s, RI_INFO) || !strcasecmp(s, RI_INFO_ONLY0) || !strcasecmp(s, RI_INFO_ONLY1)) {
ri->size_threshold = -1;
} else {
errno = 0;
ri->size_threshold = strtol(s, 0, 10);
if ((ri->size_threshold == LONG_MIN || ri->size_threshold == LONG_MAX) && errno == ERANGE) {
warn("*** strtol");
ri->size_threshold = 0;
}
}
free(s);
}
add_ignores(ri, p, ctx, RI_FILESIZE);
array(p, ctx, RI_LTO, RI_LTO_SYMBOL_NAME_PREFIXES, &ri->lto_symbol_name_prefixes);
add_ignores(ri, p, ctx, RI_LTO);
s = p->getstr(ctx, RI_SPECNAME, RI_MATCH);
if (s != NULL) {
if (!strcasecmp(s, RI_SUFFIX)) {
ri->specmatch = MATCH_SUFFIX;
} else if (!strcasecmp(s, RI_PREFIX)) {
ri->specmatch = MATCH_PREFIX;
} else if (!strcasecmp(s, RI_FULL)) {
ri->specmatch = MATCH_FULL;
} else {
warnx(_("*** unknown specname match setting '%s', defaulting to 'full'"), s);
ri->specmatch = MATCH_FULL;
}
free(s);
}
s = p->getstr(ctx, RI_SPECNAME, RI_PRIMARY);
if (s != NULL) {
if (!strcasecmp(s, RI_FILENAME)) {
ri->specprimary = PRIMARY_FILENAME;
} else if (!strcasecmp(s, RI_NAME)) {
ri->specprimary = PRIMARY_NAME;
} else {
warnx(_("*** unknown specname primary setting '%s', defaulting to 'name'"), s);
ri->specprimary = PRIMARY_NAME;
}
free(s);
}
add_ignores(ri, p, ctx, RI_SPECNAME);
s = p->getstr(ctx, RI_ANNOCHECK, RI_FAILURE_SEVERITY);
if (s != NULL) {
ri->annocheck_failure_severity = getseverity(s, RESULT_NULL);
if (ri->annocheck_failure_severity == RESULT_NULL) {
warnx(_("*** invalid annocheck failure_reporting_level: %s, defaulting to %s"), s, strseverity(RESULT_VERIFY));
ri->annocheck_failure_severity = RESULT_VERIFY;
}
free(s);
}
strget(p, ctx, RI_ANNOCHECK, RI_PROFILE, &ri->annocheck_profile);
tabledict(p, ctx, RI_ANNOCHECK, RI_JOBS, &ri->annocheck, false, false);
tabledict(p, ctx, RI_ANNOCHECK, RI_EXTRA_OPTS, &ri->annocheck, true, false);
add_ignores(ri, p, ctx, RI_ANNOCHECK);
/* Backward compatibility for annocheck jobs at top-level. */
if (ri->annocheck == NULL) {
p->strdict_foreach(ctx, RI_ANNOCHECK, NULL, annocheck_cb, &annocheck_cb_data);
}
tabledict(p, ctx, RI_JAVABYTECODE, NULL, &ri->jvm, false, true);
add_ignores(ri, p, ctx, RI_JAVABYTECODE);
tabledict(p, ctx, RI_PATHMIGRATION, RI_MIGRATED_PATHS, &ri->pathmigration, false, false);
array(p, ctx, RI_PATHMIGRATION, RI_EXCLUDED_PATHS, &ri->pathmigration_excluded_paths);
add_ignores(ri, p, ctx, RI_PATHMIGRATION);
add_ignores(ri, p, ctx, RI_POLITICS);
array(p, ctx, RI_FILES, RI_FORBIDDEN_PATHS, &ri->forbidden_paths);
add_ignores(ri, p, ctx, RI_FILES);
strget(p, ctx, RI_ABIDIFF, RI_SUPPRESSION_FILE, &ri->abidiff_suppression_file);
strget(p, ctx, RI_ABIDIFF, RI_DEBUGINFO_PATH, &ri->abidiff_debuginfo_path);
strget(p, ctx, RI_ABIDIFF, RI_EXTRA_ARGS, &ri->abidiff_extra_args);
s = p->getstr(ctx, RI_ABIDIFF, RI_SECURITY_LEVEL_THRESHOLD);
if (s != NULL) {
errno = 0;
ri->abi_security_threshold = strtol(s, 0, 10);
if ((ri->abi_security_threshold == LONG_MIN ||
ri->abi_security_threshold == LONG_MAX) && errno == ERANGE) {
warn("*** strtol");
ri->abi_security_threshold = DEFAULT_ABI_SECURITY_THRESHOLD;
}
free(s);
}
add_ignores(ri, p, ctx, RI_ABIDIFF);
strget(p, ctx, RI_KMIDIFF, RI_SUPPRESSION_FILE, &ri->kmidiff_suppression_file);
strget(p, ctx, RI_KMIDIFF, RI_DEBUGINFO_PATH, &ri->kmidiff_debuginfo_path);
strget(p, ctx, RI_KMIDIFF, RI_EXTRA_ARGS, &ri->kmidiff_extra_args);
array(p, ctx, RI_KMIDIFF, RI_KERNEL_FILENAMES, &ri->kernel_filenames);
strget(p, ctx, RI_KMIDIFF, RI_KABI_DIR, &ri->kabi_dir);
strget(p, ctx, RI_KMIDIFF, RI_KABI_FILENAME, &ri->kabi_filename);
add_ignores(ri, p, ctx, RI_KMIDIFF);
array(p, ctx, RI_PATCHES, RI_AUTOMACROS, &ri->automacros);
array(p, ctx, RI_PATCHES, RI_IGNORE_LIST, &ri->patch_ignore_list);
array(p, ctx, RI_BADFUNCS, RI_FORBIDDEN, &ri->bad_functions);
/* ri->bad_functions_allowed is a string_list_map_t, not string_map_t. */
if (p->strdict_foreach(ctx, RI_BADFUNCS, RI_ALLOWED, badfuncs_allowed_cb, &ri->bad_functions_allowed)) {
warnx(_("*** malformed badfuncs->allowed section"));
}
/* Backward compatibility for badfuncs prior to "forbidden". */
if (ri->bad_functions == NULL && ri->bad_functions_allowed == NULL) {
array(p, ctx, RI_BADFUNCS, NULL, &ri->bad_functions);
}
add_ignores(ri, p, ctx, RI_BADFUNCS);
array(p, ctx, RI_RUNPATH, RI_ALLOWED_PATHS, &ri->runpath_allowed_paths);
array(p, ctx, RI_RUNPATH, RI_ALLOWED_ORIGIN_PATHS, &ri->runpath_allowed_origin_paths);
array(p, ctx, RI_RUNPATH, RI_ORIGIN_PREFIX_TRIM, &ri->runpath_origin_prefix_trim);
add_ignores(ri, p, ctx, RI_RUNPATH);
add_ignores(ri, p, ctx, RI_TYPES);
if (p->havesection(ctx, RI_UNICODE) && local) {
warnx(_("*** ignoring 'unicode' section in %s; only allowed in system-wide configuration"), filename);
} else {
s = p->getstr(ctx, RI_UNICODE, RI_EXCLUDE);
if (s != NULL && add_regex(s, &ri->unicode_exclude) != 0) {
warnx(_("*** error reading unicode exclude regular expression: %s"), s);
}
free(s);
array(p, ctx, RI_UNICODE, RI_EXCLUDED_MIME_TYPES, &ri->unicode_excluded_mime_types);
array(p, ctx, RI_UNICODE, RI_FORBIDDEN_CODEPOINTS, &ri->unicode_forbidden_codepoints);
add_ignores(ri, p, ctx, RI_UNICODE);
}
if (p->strdict_foreach(ctx, RI_RPMDEPS, RI_IGNORE, rpmdeps_cb, &ri->deprules_ignore)) {
warnx(_("*** malformed rpmdeps->ignore section; skipping"));
}
add_ignores(ri, p, ctx, RI_VIRUS);
add_ignores(ri, p, ctx, RI_CAPABILITIES);
add_ignores(ri, p, ctx, RI_CONFIG);
add_ignores(ri, p, ctx, RI_DOC);
add_ignores(ri, p, ctx, RI_KMOD);
add_ignores(ri, p, ctx, RI_PERMISSIONS);
add_ignores(ri, p, ctx, RI_SYMLINKS);
add_ignores(ri, p, ctx, RI_UPSTREAM);
add_ignores(ri, p, ctx, RI_DEBUGINFO);
strget(p, ctx, RI_DEBUGINFO, RI_DEBUGINFO_SECTIONS, &ri->debuginfo_sections);
array(p, ctx, RI_UDEVRULES, RI_UDEV_RULES_DIRS, &ri->udev_rules_dirs);
add_ignores(ri, p, ctx, RI_UDEVRULES);
p->fini(ctx);
return;
}
/*
* Given a directory and a filename with an extension, try to look for
* it under all support filename extensions. If found, return the
* full path to the config file to the caller. The caller is
* responsible for freeing this string. NULL is return if no config
* file is found.
*/
static char *find_cfgfile(const char *dir, const char *name)
{
int i = 0;
char *tmp = NULL;
char *filename = NULL;
assert(dir != NULL);
assert(name != NULL);
for (i = 0; CFG_FILENAME_EXTENSIONS[i] != NULL; i++) {
xasprintf(&tmp, "%s/%s.%s", dir, name, CFG_FILENAME_EXTENSIONS[i]);
filename = realpath(tmp, NULL);
if (filename && !access(filename, F_OK|R_OK)) {
free(tmp);
return filename;
}
free(tmp);
free(filename);
}
return NULL;
}
/*
* Initialize the fileinfo list for the given product release. If the
* file cannot be found, return false.
*/