Debian Codegraph @

src/lib/authselect_profile.c

raw symbols SCIP
1 /*
2 Authors:
3 Pavel Březina <[email protected]>
4
5 Copyright (C) 2017 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 <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24
25 #include "authselect.h"cxx . . $ `<file>/include/authselect.h`/
26 #include "common/common.h"cxx . . $ `<file>/src/common/common.h`/
27 #include "lib/constants.h"cxx . . $ `<file>/src/lib/constants.h`/
28 #include "lib/util/util.h"cxx . . $ `<file>/src/lib/util/util.h`/
29 #include "lib/profiles/profiles.h"cxx . . $ `<file>/src/lib/profiles/profiles.h`/
30
31 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int
32 authselect_profilecxx . . $ authselect_profile(9cd096d22a496993).(const char *profile_id,
33 struct authselect_profilecxx . . $ authselect_profile# **_profile)
34 {
35 return authselect_profile_readcxx . . $ authselect_profile_read(73a0aa0767d26394).(profile_id, AUTHSELECT_PROFILE_ANYcxx . . $ AUTHSELECT_PROFILE_ANY.,
36 _profile);
37 }
38
39 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! const char *
40 authselect_profile_idcxx . . $ authselect_profile_id(96f23b929ece55c2).(const struct authselect_profilecxx . . $ authselect_profile# *profile)
41 {
42 if (profile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
43 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
44 }
45
46 return profile->idcxx . . $ authselect_profile#id.;
47 }
48
49 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! const char *
50 authselect_profile_namecxx . . $ authselect_profile_name(96f23b929ece55c2).(const struct authselect_profilecxx . . $ authselect_profile# *profile)
51 {
52 if (profile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
53 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
54 }
55
56 return profile->namecxx . . $ authselect_profile#name.;
57 }
58
59 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! const char *
60 authselect_profile_pathcxx . . $ authselect_profile_path(96f23b929ece55c2).(const struct authselect_profilecxx . . $ authselect_profile# *profile)
61 {
62 if (profile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
63 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
64 }
65
66 return profile->pathcxx . . $ authselect_profile#path.;
67 }
68
69 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! const char *
70 authselect_profile_descriptioncxx . . $ authselect_profile_description(96f23b929ece55c2).(const struct authselect_profilecxx . . $ authselect_profile# *profile)
71 {
72 if (profile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
73 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
74 }
75
76 return profile->descriptioncxx . . $ authselect_profile#description.;
77 }
78
79 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! char *
80 authselect_profile_requirementscxx . . $ authselect_profile_requirements(e64a63f0b99072ff).(const struct authselect_profilecxx . . $ authselect_profile# *profile,
81 const char **features)
82 {
83 if (profile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
84 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
85 }
86
87 return template_generatecxx . . $ template_generate(e6b3452e8157deef).(profile->requirementscxx . . $ authselect_profile#requirements., features);
88 }
89
90 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! char **
91 authselect_profile_nsswitch_mapscxx . . $ authselect_profile_nsswitch_maps(ba3de4acb81939e8).(const struct authselect_profilecxx . . $ authselect_profile# *profile,
92 const char **features)
93 {
94 char *template;
95 char **maps;
96 errno_tcxx . . $ errno_t# ret;
97
98 if (profile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
99 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
100 }
101
102 template = template_generatecxx . . $ template_generate(e6b3452e8157deef).(profile->filescxx . . $ authselect_profile#files.->nsswitchcxx . . $ authselect_files#nsswitch., features);
103 if (template == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
104 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to generate nsswitch.conf");
105 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
106 }
107
108 ret = authselect_nsswitch_find_mapscxx . . $ authselect_nsswitch_find_maps(bd420b23a2195fdd).(template, &maps);
109 freecxx . . $ free(5d22bdacc48458e8).(template);
110 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
111 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to find nsswitch maps [%d]: %s", ret, strerror(ret));
112 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
113 }
114
115 return maps;
116 }
117
118 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! char **
119 authselect_profile_featurescxx . . $ authselect_profile_features(99e33f263369bfd1).(const struct authselect_profilecxx . . $ authselect_profile# *profile)
120 {
121 char **features;
122 char **array;
123 errno_tcxx . . $ errno_t# ret;
124 int i;
125
126 if (profile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
127 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
128 }
129
130 features = string_array_createcxx . . $ string_array_create(4d3fbc76ec7ad0ba).(10);
131 if (features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
132 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create array (out of memory)");
133 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
134 }
135
136 struct authselect_generatedcxx . . $ authselect_generated# files[] = PROFILE_FILEScxx . . $ `src/lib/paths.h:113:9`!(profile->files);
137
138 for (i = 0; files[i].pathcxx . . $ authselect_generated#path. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
139 array = template_list_featurescxx . . $ template_list_features(9945f7050fb66ac).(files[i].contentcxx . . $ authselect_generated#content.);
140 if (array == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
141 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to obtain feature list (out of memory)");
142 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
143 goto done;
144 }
145
146 features = string_array_concatcxx . . $ string_array_concat(1bde152e053d6490).(features, array, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!);
147 string_array_freecxx . . $ string_array_free(3ed91490e421178f).(array);
148
149 if (features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
150 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to obtain feature list (out of memory)");
151 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
152 goto done;
153 }
154 }
155
156 string_array_sortcxx . . $ string_array_sort(3ed91490e421178f).(features);
157
158 ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!;
159
160 done:
161 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
162 string_array_freecxx . . $ string_array_free(3ed91490e421178f).(features);
163 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
164 }
165
166 return features;
167 }
168
169 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! void
170 authselect_profile_freecxx . . $ authselect_profile_free(56572ca77072da15).(struct authselect_profilecxx . . $ authselect_profile# *profile)
171 {
172 if (profile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
173 return;
174 }
175
176 if (profile->idcxx . . $ authselect_profile#id. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
177 freecxx . . $ free(5d22bdacc48458e8).(profile->idcxx . . $ authselect_profile#id.);
178 }
179
180 if (profile->pathcxx . . $ authselect_profile#path. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
181 freecxx . . $ free(5d22bdacc48458e8).(profile->pathcxx . . $ authselect_profile#path.);
182 }
183
184 if (profile->namecxx . . $ authselect_profile#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
185 freecxx . . $ free(5d22bdacc48458e8).(profile->namecxx . . $ authselect_profile#name.);
186 }
187
188 if (profile->descriptioncxx . . $ authselect_profile#description. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
189 freecxx . . $ free(5d22bdacc48458e8).(profile->descriptioncxx . . $ authselect_profile#description.);
190 }
191
192 if (profile->requirementscxx . . $ authselect_profile#requirements. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
193 freecxx . . $ free(5d22bdacc48458e8).(profile->requirementscxx . . $ authselect_profile#requirements.);
194 }
195
196 authselect_files_freecxx . . $ authselect_files_free(e1e1e20e9d8c2ec3).(profile->filescxx . . $ authselect_profile#files.);
197
198 memsetcxx . . $ memset(d1de1e4fb215f1c6).(profile, 0, sizeof(struct authselect_profilecxx . . $ authselect_profile#));
199
200 freecxx . . $ free(5d22bdacc48458e8).(profile);
201
202 return;
203 }
204
205 static char **
206 authselect_profile_files_getcxx . . $ authselect_profile_files_get(9945f7050fb66ac).(const char *profile_path)
207 {
208 const char *files[] = {FILES_ALLcxx . . $ `src/lib/paths.h:161:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!};
209 char **paths;
210 char *path;
211 errno_tcxx . . $ errno_t# ret;
212 int i;
213
214 paths = string_array_createcxx . . $ string_array_create(4d3fbc76ec7ad0ba).(sizeof(files) / sizeof(const char *));
215 if (paths == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
216 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
217 }
218
219 for (i = 0; files[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
220 path = formatcxx . . $ format(a849077ff1b8d812).("%s/%s", profile_path, files[i]);
221 if (path == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
222 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
223 goto done;
224 }
225
226 paths = string_array_add_valuecxx . . $ string_array_add_value(db56f6d53b8c0a98).(paths, path, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!);
227 freecxx . . $ free(5d22bdacc48458e8).(path);
228 if (paths == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
229 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
230 goto done;
231 }
232 }
233
234 ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!;
235
236 done:
237 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
238 string_array_freecxx . . $ string_array_free(3ed91490e421178f).(paths);
239 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
240 }
241
242 return paths;
243 }
244
245 static errno_tcxx . . $ errno_t#
246 authselect_profile_symlinks_addcxx . . $ authselect_profile_symlinks_add(a5865a01926266a1).(const char *profile_path,
247 char ***symlinks,
248 const char **from)
249 {
250 char *target;
251 int i;
252
253 if (from == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
254 return EOKcxx . . $ `src/common/errno_t.h:34:9`!;
255 }
256
257 for (i = 0; from[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
258 target = formatcxx . . $ format(a849077ff1b8d812).("%s/%s", profile_path, from[i]);
259 if (target == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
260 return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
261 }
262
263 *symlinks = string_array_add_valuecxx . . $ string_array_add_value(db56f6d53b8c0a98).(*symlinks, target, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!);
264 freecxx . . $ free(5d22bdacc48458e8).(target);
265 if (*symlinks == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
266 return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
267 }
268 }
269
270 return EOKcxx . . $ `src/common/errno_t.h:34:9`!;
271 }
272
273 static char **
274 authselect_profile_symlinks_getcxx . . $ authselect_profile_symlinks_get(ca292217b9e59c35).(const char *profile_path,
275 uint32_tcxx . . $ uint32_t# flags,
276 const char **symlinks)
277 {
278 const char *sym_meta[] = {FILES_METAcxx . . $ `src/lib/paths.h:155:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!};
279 const char *sym_nsswitch[] = {FILES_NSSWITCHcxx . . $ `src/lib/paths.h:156:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!};
280 const char *sym_pam[] = {FILES_PAMcxx . . $ `src/lib/paths.h:157:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!};
281 const char *sym_dconf[] = {FILES_DCONFcxx . . $ `src/lib/paths.h:159:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!};
282 char **targets;
283 errno_tcxx . . $ errno_t# ret;
284
285 targets = string_array_createcxx . . $ string_array_create(4d3fbc76ec7ad0ba).(10);
286 if (targets == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
287 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
288 goto done;
289 }
290
291 if (flags & AUTHSELECT_SYMLINK_METAcxx . . $ `include/authselect.h:548:9`!) {
292 ret = authselect_profile_symlinks_addcxx . . $ authselect_profile_symlinks_add(a5865a01926266a1).(profile_path, &targets,
293 sym_meta);
294 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
295 goto done;
296 }
297 }
298
299 if (flags & AUTHSELECT_SYMLINK_NSSWITCHcxx . . $ `include/authselect.h:553:9`!) {
300 ret = authselect_profile_symlinks_addcxx . . $ authselect_profile_symlinks_add(a5865a01926266a1).(profile_path, &targets,
301 sym_nsswitch);
302 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
303 goto done;
304 }
305 }
306
307 if (flags & AUTHSELECT_SYMLINK_PAMcxx . . $ `include/authselect.h:558:9`!) {
308 ret = authselect_profile_symlinks_addcxx . . $ authselect_profile_symlinks_add(a5865a01926266a1).(profile_path, &targets,
309 sym_pam);
310 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
311 goto done;
312 }
313 }
314
315 if (flags & AUTHSELECT_SYMLINK_DCONFcxx . . $ `include/authselect.h:563:9`!) {
316 ret = authselect_profile_symlinks_addcxx . . $ authselect_profile_symlinks_add(a5865a01926266a1).(profile_path, &targets,
317 sym_dconf);
318 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
319 goto done;
320 }
321 }
322
323 ret = authselect_profile_symlinks_addcxx . . $ authselect_profile_symlinks_add(a5865a01926266a1).(profile_path, &targets,
324 symlinks);
325 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
326 goto done;
327 }
328
329 done:
330 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
331 string_array_freecxx . . $ string_array_free(3ed91490e421178f).(targets);
332 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
333 }
334
335 return targets;
336 }
337
338 static errno_tcxx . . $ errno_t#
339 authselect_profile_create_emptycxx . . $ authselect_profile_create_empty(c4dada3283861623).(const char *path, char **filepaths)
340 {
341 errno_tcxx . . $ errno_t# ret;
342 int i;
343
344 INFOcxx . . $ `src/common/common.h:63:9`!("Creating empty profile at [%s]", path);
345
346 ret = file_make_pathcxx . . $ file_make_path(1df18506ef0a631b).(path, AUTHSELECT_DIR_MODEcxx . . $ `src/lib/constants.h:29:9`!);
347 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
348 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to make path [%s] [%d]: %s", path, ret, strerror(ret));
349 return ret;
350 }
351
352 for (i = 0; filepaths[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
353 ret = textfile_writecxx . . $ textfile_write(54fb1e1f0004e0cf).(filepaths[i], "", AUTHSELECT_FILE_MODEcxx . . $ `src/lib/constants.h:30:9`!);
354 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
355 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to write to [%s] [%d]: %s",
356 filepaths[i], ret, strerror(ret));
357 return ret;
358 }
359 }
360
361 return EOKcxx . . $ `src/common/errno_t.h:34:9`!;
362 }
363
364 static errno_tcxx . . $ errno_t#
365 authselect_profile_create_from_sourcecxx . . $ authselect_profile_create_from_source(39fbce6abd0515ba).(const char *filename,
366 const char *destination,
367 const char *content,
368 char **symlinks)
369 {
370 const char *symname;
371 errno_tcxx . . $ errno_t# ret;
372 int i;
373
374 for (i = 0; symlinks[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
375 symname = file_get_basenamecxx . . $ file_get_basename(fb58d2e09a2a1ce6).(symlinks[i]);
376 if (symname == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
377 ERRORcxx . . $ `src/common/common.h:71:9`!("There is no filename in [%s]", symlinks[i]);
378 return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
379 }
380
381 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(filename, symname) == 0) {
382 /* Create symlink instead of copying the file - if it exists. */
383 ret = file_existscxx . . $ file_exists(5c4306d8553b3696).(symlinks[i]);
384 if (ret == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
385 INFOcxx . . $ `src/common/common.h:63:9`!("Omitting [%s] since it does not exist in base profile",
386 symname);
387 return EOKcxx . . $ `src/common/errno_t.h:34:9`!;
388 } else if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
389 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to check presence of [%s] [%d]: %s",
390 symlinks[i], ret, strerror(ret));
391 return ret;
392 }
393
394 ret = symlinkcxx . . $ symlink(5ae29d726ae57f88).(symlinks[i], destination);
395 if (ret != 0) {
396 ret = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
397 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create symbolic link [%s] to [%s] [%d]: %s",
398 destination, symlinks[i], ret, strerror(ret));
399 return ret;
400 }
401
402 return EOKcxx . . $ `src/common/errno_t.h:34:9`!;
403 }
404 }
405
406 ret = textfile_writecxx . . $ textfile_write(54fb1e1f0004e0cf).(destination, content, AUTHSELECT_FILE_MODEcxx . . $ `src/lib/constants.h:30:9`!);
407 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
408 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to write to [%s] [%d]: %s",
409 destination, ret, strerror(ret));
410 return ret;
411 }
412
413 return EOKcxx . . $ `src/common/errno_t.h:34:9`!;
414 }
415
416 static errno_tcxx . . $ errno_t#
417 authselect_profile_create_fromcxx . . $ authselect_profile_create_from(d0ce43640251be21).(const char *path,
418 char **filepaths,
419 const char *base_id,
420 enum authselect_profile_typecxx . . $ authselect_profile_type# base_type,
421 uint32_tcxx . . $ uint32_t# symlink_flags,
422 const char **symlinks)
423 {
424 struct authselect_profilecxx . . $ authselect_profile# *base;
425 char **symlink_targets;
426 const char *filename;
427 errno_tcxx . . $ errno_t# ret;
428 int i, j;
429
430 INFOcxx . . $ `src/common/common.h:63:9`!("Creating new profile from \"%s\" at [%s]", base_id, path);
431
432 ret = authselect_profile_readcxx . . $ authselect_profile_read(73a0aa0767d26394).(base_id, base_type, &base);
433 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
434 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to read base profile [%s] [%d]: %s",
435 base_id, ret, strerror(ret));
436 return ret;
437 }
438
439 symlink_targets = authselect_profile_symlinks_getcxx . . $ authselect_profile_symlinks_get(ca292217b9e59c35).(base->pathcxx . . $ authselect_profile#path., symlink_flags,
440 symlinks);
441 if (symlink_targets == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
442 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to resolve symbolic links names");
443 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
444 goto done;
445 }
446
447 ret = file_make_pathcxx . . $ file_make_path(1df18506ef0a631b).(path, AUTHSELECT_DIR_MODEcxx . . $ `src/lib/constants.h:29:9`!);
448 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
449 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to make path [%s] [%d]: %s", path, ret, strerror(ret));
450 goto done;
451 }
452
453 struct authselect_generatedcxx . . $ authselect_generated# profile_files[] = PROFILE_FILEScxx . . $ `src/lib/paths.h:113:9`!(base->files);
454 for (i = 0; filepaths[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
455 filename = file_get_basenamecxx . . $ file_get_basename(fb58d2e09a2a1ce6).(filepaths[i]);
456 if (filename == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
457 ERRORcxx . . $ `src/common/common.h:71:9`!("There is no filename in [%s]", filepaths[i]);
458 ret = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
459 goto done;
460 }
461
462 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(filename, FILE_READMEcxx . . $ `src/lib/paths.h:35:9`!) == 0) {
463 ret = authselect_profile_create_from_sourcecxx . . $ authselect_profile_create_from_source(39fbce6abd0515ba).(filename,
464 filepaths[i], base->descriptioncxx . . $ authselect_profile#description.,
465 symlink_targets);
466 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
467 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create [%s] [%d]: %s",
468 filepaths[i], ret, strerror(ret));
469 goto done;
470 }
471
472 continue;
473 }
474
475 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(filename, FILE_REQUIREMENTcxx . . $ `src/lib/paths.h:36:9`!) == 0) {
476 ret = authselect_profile_create_from_sourcecxx . . $ authselect_profile_create_from_source(39fbce6abd0515ba).(filename,
477 filepaths[i], base->requirementscxx . . $ authselect_profile#requirements.,
478 symlink_targets);
479 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
480 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create [%s] [%d]: %s",
481 filepaths[i], ret, strerror(ret));
482 goto done;
483 }
484
485 continue;
486 }
487
488 for (j = 0; profile_files[j].pathcxx . . $ authselect_generated#path. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; j++) {
489 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(filename, profile_files[j].pathcxx . . $ authselect_generated#path.) == 0) {
490 ret = authselect_profile_create_from_sourcecxx . . $ authselect_profile_create_from_source(39fbce6abd0515ba).(filename,
491 filepaths[i], profile_files[j].contentcxx . . $ authselect_generated#content.,
492 symlink_targets);
493 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
494 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create [%s] [%d]: %s",
495 filepaths[i], ret, strerror(ret));
496 goto done;
497 }
498
499 break;
500 }
501
502 WARNcxx . . $ `src/common/common.h:67:9`!("Unknown file name [%s]", filepaths[i]);
503 }
504 }
505
506 ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!;
507
508 done:
509 authselect_profile_freecxx . . $ authselect_profile_free(56572ca77072da15).(base);
510
511 return ret;
512 }
513
514 _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int
515 authselect_profile_createcxx . . $ authselect_profile_create(4f52199d544410a4).(const char *name,
516 enum authselect_profile_typecxx . . $ authselect_profile_type# type,
517 const char *base_id,
518 enum authselect_profile_typecxx . . $ authselect_profile_type# base_type,
519 uint32_tcxx . . $ uint32_t# symlink_flags,
520 const char **symlinks,
521 char **_path)
522 {
523 char **filepaths = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
524 char *path = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
525 errno_tcxx . . $ errno_t# ret;
526 int i;
527
528 if (string_is_emptycxx . . $ string_is_empty(c5f7da30cbc0f4e9).(name)) {
529 ERRORcxx . . $ `src/common/common.h:71:9`!("Name can not be empty");
530 return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
531 }
532
533 switch (type) {
534 case AUTHSELECT_PROFILE_VENDORcxx . . $ AUTHSELECT_PROFILE_VENDOR.:
535 path = formatcxx . . $ format(a849077ff1b8d812).("%s/%s", DIR_VENDOR_PROFILEScxx . . $ `src/lib/paths.h:71:9`!, name);
536 break;
537 case AUTHSELECT_PROFILE_CUSTOMcxx . . $ AUTHSELECT_PROFILE_CUSTOM.:
538 path = formatcxx . . $ format(a849077ff1b8d812).("%s/%s", DIR_CUSTOM_PROFILEScxx . . $ `src/lib/paths.h:72:9`!, name);
539 break;
540 case AUTHSELECT_PROFILE_DEFAULTcxx . . $ AUTHSELECT_PROFILE_DEFAULT.:
541 ERRORcxx . . $ `src/common/common.h:71:9`!("Default profile can not be created");
542 return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
543 case AUTHSELECT_PROFILE_ANYcxx . . $ AUTHSELECT_PROFILE_ANY.:
544 ERRORcxx . . $ `src/common/common.h:71:9`!("Value AUTHSELECT_PROFILE_ANY is invalid in this context");
545 return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
546 }
547
548 if (path == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
549 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create profile path: out of memory");
550 return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
551 }
552
553 ret = file_existscxx . . $ file_exists(5c4306d8553b3696).(path);
554 if (ret == EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
555 ERRORcxx . . $ `src/common/common.h:71:9`!("Profile \"%s\" already exists at [%s]", name, path);
556 ret = EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`!;
557 goto done;
558 } else if (ret != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
559 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to access [%s] [%d]: %s", path, ret, strerror(ret));
560 goto done;
561 }
562
563 filepaths = authselect_profile_files_getcxx . . $ authselect_profile_files_get(9945f7050fb66ac).(path);
564 if (filepaths == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
565 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create file name: out of memory");
566 ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
567 goto done;
568 }
569
570 if (base_id == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
571 ret = authselect_profile_create_emptycxx . . $ authselect_profile_create_empty(c4dada3283861623).(path, filepaths);
572 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
573 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create empty profile [%d]: %s",
574 ret, strerror(ret));
575 goto done;
576 }
577 } else {
578 ret = authselect_profile_create_fromcxx . . $ authselect_profile_create_from(d0ce43640251be21).(path, filepaths, base_id,
579 base_type, symlink_flags,
580 symlinks);
581 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
582 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create profile [%d]: %s",
583 ret, strerror(ret));
584 goto done;
585 }
586 }
587
588 if (_path != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
589 *_path = path;
590 } else {
591 freecxx . . $ free(5d22bdacc48458e8).(path);
592 }
593
594 ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!;
595
596 done:
597 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
598 for (i = 0; filepaths != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! && filepaths[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
599 unlinkcxx . . $ unlink(5c4306d8553b3696).(filepaths[i]);
600 }
601
602 rmdircxx . . $ rmdir(5c4306d8553b3696).(path);
603 freecxx . . $ free(5d22bdacc48458e8).(path);
604 }
605
606 string_array_freecxx . . $ string_array_free(3ed91490e421178f).(filepaths);
607
608 return ret;
609 }