Debian Codegraph @

src/lib/profiles/list.c

raw symbols SCIP
1 /*
2 Authors:
3 Pavel Březina <[email protected]>
4
5 Copyright (C) 2018 Red Hat
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <errno.h>
22 #include <string.h>
23 #include <dirent.h>
24 #include <stdlib.h>
25 #include <sys/stat.h>
26
27 #include "common/common.h"cxx . . $ `<file>/src/common/common.h`/
28 #include "lib/constants.h"cxx . . $ `<file>/src/lib/constants.h`/
29 #include "lib/profiles/profiles.h"cxx . . $ `<file>/src/lib/profiles/profiles.h`/
30 #include "lib/util/util.h"cxx . . $ `<file>/src/lib/util/util.h`/
31
32 static errno_tcxx . . $ errno_t#
33 authselect_profile_dir_readcxx . . $ authselect_profile_dir_read(8ed4944af204dfb0).(const char *path,
34 char ***array,
35 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_custom)
36 {
37 char *id;
38 char **subdirs;
39 errno_tcxx . . $ errno_t# ret;
40 int i;
41
42 INFOcxx . . $ `src/common/common.h:63:9`!("Reading profile directory [%s]", path);
43
44 ret = dir_listcxx . . $ dir_list(3003b1af897cb540).(path, DIR_LIST_DIRScxx . . $ `src/lib/util/dir.h:30:9`!, &subdirs, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
45 if (ret == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
46 /* This is just a warning so it should not be treated as error. */
47 WARNcxx . . $ `src/common/common.h:67:9`!("Directory [%s] is missing!", path);
48 return EOKcxx . . $ `src/common/errno_t.h:34:9`!;
49 } else if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
50 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to list directory [%s] [%d]: %s",
51 path, ret, strerror(ret));
52 return ret;
53 }
54
55 for (i = 0; subdirs[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
56 if (is_custom) {
57 /* Custom profile needs to be prefixed with custom/ */
58 id = authselect_profile_custom_idcxx . . $ authselect_profile_custom_id(a8b8e32347182212).(subdirs[i]);
59 if (id == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
60 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
61 goto done;
62 }
63
64 freecxx . . $ free(5d22bdacc48458e8).(subdirs[i]);
65 subdirs[i] = id;
66
67 }
68
69 INFOcxx . . $ `src/common/common.h:63:9`!("Found profile [%s]", subdirs[i]);
70 }
71
72 *array = string_array_concatcxx . . $ string_array_concat(1bde152e053d6490).(*array, subdirs, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!);
73 if (*array == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
74 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
75 goto done;
76 }
77
78 ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!;
79
80 done:
81 string_array_freecxx . . $ string_array_free(3ed91490e421178f).(subdirs);
82
83 return ret;
84 }
85
86 static int
87 authselect_profile_list_sortcxx . . $ authselect_profile_list_sort(9148c8c3ff42c9d8).(const void *a, const void *b)
88 {
89 const char *str_a = *(const char **)a;
90 const char *str_b = *(const char **)b;
91
92 if (str_a == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
93 return 1;
94 }
95
96 if (str_b == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
97 return -1;
98 }
99
100 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_custom_a = authselect_profile_is_customcxx . . $ authselect_profile_is_custom(c5f7da30cbc0f4e9).(str_a);
101 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_custom_b = authselect_profile_is_customcxx . . $ authselect_profile_is_custom(c5f7da30cbc0f4e9).(str_b);
102
103 /* Custom profiles go last, otherwise we sort alphabetically. */
104 if (is_custom_a && !is_custom_b) {
105 return 1;
106 }
107
108 if (!is_custom_a && is_custom_b) {
109 return -1;
110 }
111
112 return strcmpcxx . . $ strcmp(5ae29d726ae57f88).(str_a, str_b);
113 }
114
115
116 errno_tcxx . . $ errno_t#
117 authselect_profile_listcxx . . $ authselect_profile_list(c293f0ab5a5bee95).(char ***_profiles)
118 {
119 char **profiles;
120 errno_tcxx . . $ errno_t# ret;
121
122 profiles = string_array_createcxx . . $ string_array_create(4d3fbc76ec7ad0ba).(1);
123 if (profiles == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
124 return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
125 }
126
127 ret = authselect_profile_dir_readcxx . . $ authselect_profile_dir_read(8ed4944af204dfb0).(DIR_DEFAULT_PROFILEScxx . . $ `src/lib/paths.h:70:9`!, &profiles, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
128 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
129 goto done;
130 }
131
132 ret = authselect_profile_dir_readcxx . . $ authselect_profile_dir_read(8ed4944af204dfb0).(DIR_VENDOR_PROFILEScxx . . $ `src/lib/paths.h:71:9`!, &profiles, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
133 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
134 goto done;
135 }
136
137 ret = authselect_profile_dir_readcxx . . $ authselect_profile_dir_read(8ed4944af204dfb0).(DIR_CUSTOM_PROFILEScxx . . $ `src/lib/paths.h:72:9`!, &profiles, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!);
138 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
139 goto done;
140 }
141
142 qsortcxx . . $ qsort(ebb60b13a65e77d7).(profiles, string_array_countcxx . . $ string_array_count(44350d944485fca).(profiles), sizeof(char *),
143 authselect_profile_list_sortcxx . . $ authselect_profile_list_sort(9148c8c3ff42c9d8).);
144
145 *_profiles = profiles;
146
147 ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!;
148
149 done:
150 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
151 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to list profiles [%d]: %s", ret, strerror(ret));
152 string_array_freecxx . . $ string_array_free(3ed91490e421178f).(profiles);
153 }
154
155 return ret;
156 }