| 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 <stddef.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <stdbool.h> |
| 24 | |
| 25 | #include "authselect.h"cxx . . $ `<file>/include/authselect.h`/ |
| 26 | |
| 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/files/files.h"cxx . . $ `<file>/src/lib/files/files.h`/ |
| 30 | #include "lib/profiles/profiles.h"cxx . . $ `<file>/src/lib/profiles/profiles.h`/ |
| 31 | |
| 32 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 33 | authselect_check_featurescxx . . $ authselect_check_features(96e48809e1120d04).(const struct authselect_profilecxx . . $ authselect_profile# *profile, |
| 34 | const char **features) |
| 35 | { |
| 36 | const char *similar; |
| 37 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 38 | char **supported; |
| 39 | int i; |
| 40 | |
| 41 | if (features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 42 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 43 | } |
| 44 | |
| 45 | supported = authselect_profile_featurescxx . . $ authselect_profile_features(99e33f263369bfd1).(profile); |
| 46 | if (supported == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 47 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to obtain supported features"); |
| 48 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 49 | } |
| 50 | |
| 51 | for (i = 0; features[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) { |
| 52 | if (string_array_has_valuecxx . . $ string_array_has_value(20870b8b3d19c175).(supported, features[i])) { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 57 | similar = string_array_find_similarcxx . . $ string_array_find_similar(aae266b49c6ddb5a).(features[i], supported, 5); |
| 58 | if (similar != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 59 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unknown profile feature [%s], did you mean [%s]?", |
| 60 | features[i], similar); |
| 61 | } else { |
| 62 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unknown profile feature [%s]", features[i]); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(supported); |
| 67 | |
| 68 | return result; |
| 69 | } |
| 70 | |
| 71 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! void |
| 72 | authselect_set_debug_fncxx . . $ authselect_set_debug_fn(10083e02f417e2d6).(authselect_debug_fncxx . . $ authselect_debug_fn# fn, void *pvt) |
| 73 | { |
| 74 | set_debug_fncxx . . $ set_debug_fn(10083e02f417e2d6).(fn, pvt); |
| 75 | } |
| 76 | |
| 77 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int |
| 78 | authselect_activatecxx . . $ authselect_activate(ee6f66a11326c070).(const char *profile_id, |
| 79 | const char **features, |
| 80 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! force_overwrite) |
| 81 | { |
| 82 | struct authselect_profilecxx . . $ authselect_profile# *profile; |
| 83 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_valid; |
| 84 | errno_tcxx . . $ errno_t# ret; |
| 85 | |
| 86 | INFOcxx . . $ `src/common/common.h:63:9`!("Trying to activate profile [%s]", profile_id); |
| 87 | |
| 88 | ret = authselect_profilecxx . . $ authselect_profile(9cd096d22a496993).(profile_id, &profile); |
| 89 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 90 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to find profile [%s] [%d]: %s", |
| 91 | profile_id, ret, strerror(ret)); |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | if (!authselect_check_featurescxx . . $ authselect_check_features(96e48809e1120d04).(profile, features)) { |
| 96 | ret = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 97 | goto done; |
| 98 | } |
| 99 | |
| 100 | if (force_overwrite) { |
| 101 | INFOcxx . . $ `src/common/common.h:63:9`!("Enforcing activation!"); |
| 102 | ret = authselect_profile_activatecxx . . $ authselect_profile_activate(91f62ebacbff91ef).(profile, features); |
| 103 | goto done; |
| 104 | } |
| 105 | |
| 106 | /* Require force if authselect.conf is missing or invalid but otherwise |
| 107 | * ignore user changes. */ |
| 108 | ret = authselect_validate_configurationcxx . . $ authselect_validate_configuration(4de84dfa0cae09e5).(&is_valid); |
| 109 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 110 | ERRORcxx . . $ `src/common/common.h:71:9`!("%s is missing or unreadable, system was not properly configured " |
| 111 | "by authselect.", PATH_CONFIG_FILEcxx . . $ `src/lib/paths.h:28:9`!); |
| 112 | ERRORcxx . . $ `src/common/common.h:71:9`!("Refusing to activate profile unless overwrite is requested."); |
| 113 | ret = EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`!; |
| 114 | goto done; |
| 115 | } |
| 116 | |
| 117 | if (!is_valid) { |
| 118 | ERRORcxx . . $ `src/common/common.h:71:9`!("Changes to the authselect configuration were detected. " |
| 119 | "These changes will be overwritten. Please call " |
| 120 | "'authselect opt-out' in order to keep them."); |
| 121 | } |
| 122 | |
| 123 | ret = authselect_profile_activatecxx . . $ authselect_profile_activate(91f62ebacbff91ef).(profile, features); |
| 124 | |
| 125 | done: |
| 126 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`! && ret != EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`!) { |
| 127 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to activate profile [%s] [%d]: %s", |
| 128 | profile_id, ret, strerror(ret)); |
| 129 | } |
| 130 | |
| 131 | authselect_profile_freecxx . . $ authselect_profile_free(56572ca77072da15).(profile); |
| 132 | |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int |
| 137 | authselect_uninstallcxx . . $ authselect_uninstall(b126dc7c1de90089).(void) |
| 138 | { |
| 139 | errno_tcxx . . $ errno_t# ret; |
| 140 | |
| 141 | INFOcxx . . $ `src/common/common.h:63:9`!("Trying to uninstall authselect configuration"); |
| 142 | |
| 143 | ret = authselect_symlinks_uninstallcxx . . $ authselect_symlinks_uninstall(d1b40a211a1a4e4c).(); |
| 144 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 145 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to remove symlinks [%d]: %s", ret, strerror(ret)); |
| 146 | return ret; |
| 147 | } |
| 148 | |
| 149 | INFOcxx . . $ `src/common/common.h:63:9`!("Symbolic links were successfully removed"); |
| 150 | |
| 151 | /* Remove files from /etc/authselect */ |
| 152 | ret = authselect_files_uninstallcxx . . $ authselect_files_uninstall(b126dc7c1de90089).(); |
| 153 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 154 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to remove authselect configuration [%d]: %s", |
| 155 | ret, strerror(ret)); |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | INFOcxx . . $ `src/common/common.h:63:9`!("Authselect configuration was successfully removed"); |
| 160 | |
| 161 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 162 | } |
| 163 | |
| 164 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int |
| 165 | authselect_apply_changescxx . . $ authselect_apply_changes(73da94e76e6bd037).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! upgrade) |
| 166 | { |
| 167 | struct authselect_profilecxx . . $ authselect_profile# *profile = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 168 | char **supported = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 169 | char *profile_id; |
| 170 | char **features; |
| 171 | char *checksum_orig = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 172 | char *checksum_copy = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 173 | errno_tcxx . . $ errno_t# ret; |
| 174 | int i; |
| 175 | |
| 176 | ret = authselect_current_configurationcxx . . $ authselect_current_configuration(2bdaab245118da41).(&profile_id, &features); |
| 177 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 178 | return ret; |
| 179 | } |
| 180 | |
| 181 | if (upgrade) { |
| 182 | ret = textfile_readcxx . . $ textfile_read(d26d230207164ac8).(PATH_CHECKSUM_ORIGcxx . . $ `src/lib/paths.h:75:9`!, AUTHSELECT_FILE_SIZE_LIMITcxx . . $ `src/lib/constants.h:31:9`!, |
| 183 | &checksum_orig); |
| 184 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 185 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to read original checksum [%s] [%d]: %s", |
| 186 | PATH_CHECKSUM_ORIGcxx . . $ `src/lib/paths.h:75:9`!, ret, strerror(ret)); |
| 187 | goto done; |
| 188 | } |
| 189 | |
| 190 | ret = textfile_readcxx . . $ textfile_read(d26d230207164ac8).(PATH_CHECKSUM_COPYcxx . . $ `src/lib/paths.h:76:9`!, AUTHSELECT_FILE_SIZE_LIMITcxx . . $ `src/lib/constants.h:31:9`!, |
| 191 | &checksum_copy); |
| 192 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`! && ret != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 193 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to read copy checksum [%s] [%d]: %s", |
| 194 | PATH_CHECKSUM_COPYcxx . . $ `src/lib/paths.h:76:9`!, ret, strerror(ret)); |
| 195 | goto done; |
| 196 | } else if (ret == EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 197 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(checksum_orig, checksum_copy) == 0) { |
| 198 | INFOcxx . . $ `src/common/common.h:63:9`!("Installed profiles did not change. No action is needed."); |
| 199 | ret = EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!; |
| 200 | goto done; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /* Copy checksum file does not exist or profiles did changed. Update. */ |
| 205 | } |
| 206 | |
| 207 | ret = authselect_profilecxx . . $ authselect_profile(9cd096d22a496993).(profile_id, &profile); |
| 208 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 209 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to find profile [%s] [%d]: %s", |
| 210 | profile_id, ret, strerror(ret)); |
| 211 | goto done; |
| 212 | } |
| 213 | |
| 214 | supported = authselect_profile_featurescxx . . $ authselect_profile_features(99e33f263369bfd1).(profile); |
| 215 | if (supported == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 216 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to obtain supported features"); |
| 217 | ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 218 | goto done; |
| 219 | } |
| 220 | |
| 221 | for (i = 0; features[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) { |
| 222 | if (string_array_has_valuecxx . . $ string_array_has_value(20870b8b3d19c175).(supported, features[i])) { |
| 223 | continue; |
| 224 | } |
| 225 | |
| 226 | WARNcxx . . $ `src/common/common.h:67:9`!("Profile feature [%s] is no longer supported, removing it...", |
| 227 | features[i]); |
| 228 | |
| 229 | string_array_del_valuecxx . . $ string_array_del_value(aab58f5807001017).(features, features[i]); |
| 230 | i--; |
| 231 | } |
| 232 | |
| 233 | ret = authselect_activatecxx . . $ authselect_activate(ee6f66a11326c070).(profile_id, (const char **)features, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 234 | |
| 235 | done: |
| 236 | authselect_profile_freecxx . . $ authselect_profile_free(56572ca77072da15).(profile); |
| 237 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(supported); |
| 238 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(features); |
| 239 | freecxx . . $ free(5d22bdacc48458e8).(checksum_orig); |
| 240 | freecxx . . $ free(5d22bdacc48458e8).(checksum_copy); |
| 241 | freecxx . . $ free(5d22bdacc48458e8).(profile_id); |
| 242 | |
| 243 | return ret; |
| 244 | } |
| 245 | |
| 246 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int |
| 247 | authselect_feature_enablecxx . . $ authselect_feature_enable(5c4306d8553b3696).(const char *feature) |
| 248 | { |
| 249 | char *profile_id; |
| 250 | char **features; |
| 251 | errno_tcxx . . $ errno_t# ret; |
| 252 | |
| 253 | ret = authselect_current_configurationcxx . . $ authselect_current_configuration(2bdaab245118da41).(&profile_id, &features); |
| 254 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | features = string_array_add_valuecxx . . $ string_array_add_value(db56f6d53b8c0a98).(features, feature, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!); |
| 259 | if (features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 260 | ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 261 | goto done; |
| 262 | } |
| 263 | |
| 264 | ret = authselect_activatecxx . . $ authselect_activate(ee6f66a11326c070).(profile_id, (const char **)features, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 265 | |
| 266 | done: |
| 267 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(features); |
| 268 | freecxx . . $ free(5d22bdacc48458e8).(profile_id); |
| 269 | |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int |
| 274 | authselect_feature_disablecxx . . $ authselect_feature_disable(5c4306d8553b3696).(const char *feature) |
| 275 | { |
| 276 | char *profile_id; |
| 277 | char **features; |
| 278 | errno_tcxx . . $ errno_t# ret; |
| 279 | |
| 280 | ret = authselect_config_readcxx . . $ authselect_config_read(2bdaab245118da41).(&profile_id, &features); |
| 281 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 282 | return ret; |
| 283 | } |
| 284 | |
| 285 | string_array_del_valuecxx . . $ string_array_del_value(aab58f5807001017).(features, feature); |
| 286 | |
| 287 | ret = authselect_activatecxx . . $ authselect_activate(ee6f66a11326c070).(profile_id, (const char **)features, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 288 | |
| 289 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(features); |
| 290 | freecxx . . $ free(5d22bdacc48458e8).(profile_id); |
| 291 | |
| 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int |
| 296 | authselect_feature_enabledcxx . . $ authselect_feature_enabled(5c4306d8553b3696).(const char *feature) |
| 297 | { |
| 298 | char *profile_id; |
| 299 | char **features; |
| 300 | errno_tcxx . . $ errno_t# ret; |
| 301 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! bret; |
| 302 | |
| 303 | ret = authselect_config_readcxx . . $ authselect_config_read(2bdaab245118da41).(&profile_id, &features); |
| 304 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | bret = string_array_has_valuecxx . . $ string_array_has_value(20870b8b3d19c175).(features, feature); |
| 309 | |
| 310 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(features); |
| 311 | freecxx . . $ free(5d22bdacc48458e8).(profile_id); |
| 312 | |
| 313 | ret = bret ? EOKcxx . . $ `src/common/errno_t.h:34:9`! : ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!; |
| 314 | |
| 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int |
| 319 | authselect_validate_configurationcxx . . $ authselect_validate_configuration(4de84dfa0cae09e5).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *_is_valid) |
| 320 | { |
| 321 | char *profile_id; |
| 322 | char **features; |
| 323 | errno_tcxx . . $ errno_t# ret; |
| 324 | |
| 325 | ret = authselect_config_readcxx . . $ authselect_config_read(2bdaab245118da41).(&profile_id, &features); |
| 326 | if (ret == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 327 | *_is_valid = authselect_config_validate_usercxx . . $ authselect_config_validate_user(c9857a73d68e59ba).(); |
| 328 | |
| 329 | if (*_is_valid && authselect_config_validate_missingcxx . . $ authselect_config_validate_missing(c9857a73d68e59ba).()) { |
| 330 | return ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!; |
| 331 | } |
| 332 | |
| 333 | return EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`!; |
| 334 | } if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 335 | return ret; |
| 336 | } |
| 337 | |
| 338 | *_is_valid = authselect_config_validate_authselectcxx . . $ authselect_config_validate_authselect(555288a511009159).(profile_id, |
| 339 | (const char **)features); |
| 340 | |
| 341 | freecxx . . $ free(5d22bdacc48458e8).(profile_id); |
| 342 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(features); |
| 343 | |
| 344 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 345 | } |
| 346 | |
| 347 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! int |
| 348 | authselect_current_configurationcxx . . $ authselect_current_configuration(2bdaab245118da41).(char **_profile_id, |
| 349 | char ***_features) |
| 350 | { |
| 351 | return authselect_config_readcxx . . $ authselect_config_read(2bdaab245118da41).(_profile_id, _features); |
| 352 | } |
| 353 | |
| 354 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! char ** |
| 355 | authselect_listcxx . . $ authselect_list(6aacb5881005f5e4).() |
| 356 | { |
| 357 | char **profiles; |
| 358 | errno_tcxx . . $ errno_t# ret; |
| 359 | |
| 360 | ret = authselect_profile_listcxx . . $ authselect_profile_list(c293f0ab5a5bee95).(&profiles); |
| 361 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 362 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 363 | } |
| 364 | |
| 365 | return profiles; |
| 366 | } |
| 367 | |
| 368 | _PUBLIC_cxx . . $ `src/lib/constants.h:27:9`! void |
| 369 | authselect_array_freecxx . . $ authselect_array_free(3ed91490e421178f).(char **array) |
| 370 | { |
| 371 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(array); |
| 372 | } |