Debian Codegraph @

src/lib/files/config.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 <fcntl.h>
22 #include <errno.h>
23 #include <string.h>
24 #include <stdlib.h>
25
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/util/config.h"cxx . . $ `<file>/src/lib/util/config.h`/
30 #include "lib/files/files.h"cxx . . $ `<file>/src/lib/files/files.h`/
31
32 errno_tcxx . . $ errno_t#
33 authselect_config_readcxx . . $ authselect_config_read(2bdaab245118da41).(char **_profile_id,
34 char ***_features)
35 {
36 return config_readcxx . . $ config_read(2fdb31789c666a26).(PATH_CONFIG_FILEcxx . . $ `src/lib/paths.h:28:9`!, _profile_id, _features);
37 }
38
39 errno_tcxx . . $ errno_t#
40 authselect_config_writecxx . . $ authselect_config_write(2ef3bc9ee8f8b3e9).(const char *profile_id,
41 const char **features)
42 {
43 char *implode;
44 char *output;
45 errno_tcxx . . $ errno_t# ret;
46
47 implode = string_implodecxx . . $ string_implode(427dff5c35d3d96b).(features, '\n');
48 if (implode == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
49 return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
50 }
51
52 output = formatcxx . . $ format(a849077ff1b8d812).("%s\n%s\n", profile_id, implode);
53 freecxx . . $ free(5d22bdacc48458e8).(implode);
54 if (output == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
55 return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
56 }
57
58 ret = textfile_writecxx . . $ textfile_write(54fb1e1f0004e0cf).(PATH_CONFIG_FILEcxx . . $ `src/lib/paths.h:28:9`!, output, AUTHSELECT_FILE_MODEcxx . . $ `src/lib/constants.h:30:9`!);
59 freecxx . . $ free(5d22bdacc48458e8).(output);
60
61 return ret;
62 }
63
64 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
65 authselect_config_locations_writablecxx . . $ authselect_config_locations_writable(c9857a73d68e59ba).()
66 {
67 struct authselect_symlinkcxx . . $ authselect_symlink# files[] = {
68 {PATH_CONFIG_FILEcxx . . $ `src/lib/paths.h:28:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!},
69 SYMLINK_FILEScxx . . $ `src/lib/paths.h:140:9`!
70 };
71 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
72 char *dirpath;
73 errno_tcxx . . $ errno_t# ret;
74 int i;
75
76 INFOcxx . . $ `src/common/common.h:63:9`!("Checking if all required directories are writable.");
77
78 for (i = 0; files[i].namecxx . . $ authselect_symlink#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
79 dirpath = file_get_parent_directorycxx . . $ file_get_parent_directory(a8b8e32347182212).(files[i].namecxx . . $ authselect_symlink#name.);
80 if (dirpath == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
81 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to get path to %s parent directory!", files[i].name);
82 result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
83 continue;
84 }
85
86 ret = file_check_accesscxx . . $ file_check_access(cb7559238bb26814).(dirpath, W_OKcxx . . $ `<external>/14710646456994434043/fcntl.h:129:11`! | X_OKcxx . . $ `<external>/14710646456994434043/fcntl.h:130:11`!);
87 if (ret == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`! && files[i].create_pathcxx . . $ authselect_symlink#create_path.) {
88 INFOcxx . . $ `src/common/common.h:63:9`!("Creating path [%s]", dirpath);
89 ret = file_make_pathcxx . . $ file_make_path(1df18506ef0a631b).(dirpath, AUTHSELECT_DIR_MODEcxx . . $ `src/lib/constants.h:29:9`!);
90 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
91 result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
92 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create path [%s] [%d]: %s",
93 dirpath, ret, strerror(ret));
94 }
95 } else if (ret == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
96 result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
97 ERRORcxx . . $ `src/common/common.h:71:9`!("Directory [%s] does not exist, please create it!", dirpath);
98 } else if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
99 result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
100 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to access directory [%s] in [WX] mode!", dirpath);
101 }
102
103 freecxx . . $ free(5d22bdacc48458e8).(dirpath);
104 }
105
106 return result;
107 }
108
109 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
110 authselect_config_validate_authselectcxx . . $ authselect_config_validate_authselect(555288a511009159).(const char *profile_id,
111 const char **features)
112 {
113 struct authselect_filescxx . . $ authselect_files# *files;
114 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
115 errno_tcxx . . $ errno_t# ret;
116
117 ret = authselect_filescxx . . $ authselect_files(879a8b3bb2b9eac1).(profile_id, features, &files);
118 if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) {
119 ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to load profile [%s] [%d]: %s",
120 profile_id, ret, strerror(ret));
121 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
122 }
123
124 /* Check that generated files exist and have proper content. */
125 result &= authselect_system_validatecxx . . $ authselect_system_validate(a73b0e1def25ad2a).(files);
126
127 /* Check that symlinks exist and point to generated files. */
128 result &= authselect_symlinks_validatecxx . . $ authselect_symlinks_validate(c9857a73d68e59ba).();
129
130 authselect_files_freecxx . . $ authselect_files_free(e1e1e20e9d8c2ec3).(files);
131
132 return result;
133 }
134
135 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
136 authselect_config_validate_usercxx . . $ authselect_config_validate_user(c9857a73d68e59ba).()
137 {
138 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
139
140 result &= authselect_system_validate_missingcxx . . $ authselect_system_validate_missing(c9857a73d68e59ba).();
141 result &= authselect_symlinks_validate_missingcxx . . $ authselect_symlinks_validate_missing(c9857a73d68e59ba).();
142
143 return result;
144 }
145
146 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
147 authselect_config_validate_missingcxx . . $ authselect_config_validate_missing(c9857a73d68e59ba).()
148 {
149 struct authselect_generatedcxx . . $ authselect_generated# generated[] = GENERATED_FILES_PATHScxx . . $ `src/lib/paths.h:99:9`!;
150 struct authselect_symlinkcxx . . $ authselect_symlink# symlinks[] = {SYMLINK_FILEScxx . . $ `src/lib/paths.h:140:9`!};
151 errno_tcxx . . $ errno_t# ret;
152 int i;
153
154 ret = file_existscxx . . $ file_exists(5c4306d8553b3696).(PATH_CONFIG_FILEcxx . . $ `src/lib/paths.h:28:9`!);
155 if (ret != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
156 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
157 }
158
159 for (i = 0; generated[i].pathcxx . . $ authselect_generated#path. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
160 ret = file_existscxx . . $ file_exists(5c4306d8553b3696).(generated[i].pathcxx . . $ authselect_generated#path.);
161 if (ret != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
162 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
163 }
164 }
165
166 for (i = 0; symlinks[i].namecxx . . $ authselect_symlink#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) {
167 ret = file_existscxx . . $ file_exists(5c4306d8553b3696).(symlinks[i].namecxx . . $ authselect_symlink#name.);
168 if (ret != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
169 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
170 }
171 }
172
173 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
174 }