| 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 <unistd.h> |
| 23 | #include <sys/stat.h> |
| 24 | |
| 25 | #include "common/common.h"cxx . . $ `<file>/src/common/common.h`/ |
| 26 | #include "lib/constants.h"cxx . . $ `<file>/src/lib/constants.h`/ |
| 27 | #include "lib/util/util.h"cxx . . $ `<file>/src/lib/util/util.h`/ |
| 28 | #include "lib/files/files.h"cxx . . $ `<file>/src/lib/files/files.h`/ |
| 29 | |
| 30 | errno_tcxx . . $ errno_t# |
| 31 | authselect_symlinks_writecxx . . $ authselect_symlinks_write(b126dc7c1de90089).() |
| 32 | { |
| 33 | struct authselect_symlinkcxx . . $ authselect_symlink# symlinks[] = {SYMLINK_FILEScxx . . $ `src/lib/paths.h:140:9`!}; |
| 34 | mode_tcxx . . $ mode_t# oldmask; |
| 35 | errno_tcxx . . $ errno_t# ret; |
| 36 | int i; |
| 37 | |
| 38 | oldmask = umaskcxx . . $ umask(2141b656ce2cc063).(~AUTHSELECT_FILE_MODEcxx . . $ `src/lib/constants.h:30:9`! & ALLPERMScxx . . $ `<external>/531885356569766532/stat.h:196:10`!); |
| 39 | |
| 40 | for (i = 0; symlinks[i].namecxx . . $ authselect_symlink#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) { |
| 41 | INFOcxx . . $ `src/common/common.h:63:9`!("Creating symbolic link [%s] to [%s]", |
| 42 | symlinks[i].name, symlinks[i].dest); |
| 43 | |
| 44 | ret = unlinkcxx . . $ unlink(5c4306d8553b3696).(symlinks[i].namecxx . . $ authselect_symlink#name.); |
| 45 | if (ret != 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 46 | ret = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 47 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to overwrite file [%s] [%d]: %s", |
| 48 | symlinks[i].name, ret, strerror(ret)); |
| 49 | goto done; |
| 50 | } |
| 51 | |
| 52 | ret = symlinkcxx . . $ symlink(5ae29d726ae57f88).(symlinks[i].destcxx . . $ authselect_symlink#dest., symlinks[i].namecxx . . $ authselect_symlink#name.); |
| 53 | if (ret != 0) { |
| 54 | ret = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 55 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create symbolic link [%s] [%d]: %s", |
| 56 | symlinks[i].name, ret, strerror(ret)); |
| 57 | goto done; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 62 | |
| 63 | done: |
| 64 | umaskcxx . . $ umask(2141b656ce2cc063).(oldmask); |
| 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 70 | authselect_symlinks_validatecxx . . $ authselect_symlinks_validate(c9857a73d68e59ba).() |
| 71 | { |
| 72 | struct authselect_symlinkcxx . . $ authselect_symlink# symlinks[] = {SYMLINK_FILEScxx . . $ `src/lib/paths.h:140:9`!}; |
| 73 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 74 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_valid; |
| 75 | errno_tcxx . . $ errno_t# ret; |
| 76 | int i; |
| 77 | |
| 78 | for (i = 0; symlinks[i].namecxx . . $ authselect_symlink#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) { |
| 79 | INFOcxx . . $ `src/common/common.h:63:9`!("Validating link [%s]", symlinks[i].name); |
| 80 | |
| 81 | ret = file_links_tocxx . . $ file_links_to(9f2194e17b4de24f).(symlinks[i].namecxx . . $ authselect_symlink#name., symlinks[i].destcxx . . $ authselect_symlink#dest., &is_valid); |
| 82 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 83 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to validate link [%s] [%d]: %s", |
| 84 | symlinks[i].name, ret, strerror(ret)); |
| 85 | result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 86 | continue; |
| 87 | } |
| 88 | |
| 89 | if (!is_valid) { |
| 90 | ERRORcxx . . $ `src/common/common.h:71:9`!("[%s] was not created by authselect!", symlinks[i].name); |
| 91 | result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return result; |
| 96 | } |
| 97 | |
| 98 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 99 | authselect_symlinks_validate_missingcxx . . $ authselect_symlinks_validate_missing(c9857a73d68e59ba).() |
| 100 | { |
| 101 | struct authselect_symlinkcxx . . $ authselect_symlink# symlinks[] = {SYMLINK_FILEScxx . . $ `src/lib/paths.h:140:9`!}; |
| 102 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 103 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! valid; |
| 104 | errno_tcxx . . $ errno_t# ret; |
| 105 | int i; |
| 106 | |
| 107 | for (i = 0; symlinks[i].namecxx . . $ authselect_symlink#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) { |
| 108 | ret = file_existscxx . . $ file_exists(5c4306d8553b3696).(symlinks[i].namecxx . . $ authselect_symlink#name.); |
| 109 | if (ret == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 110 | continue; |
| 111 | } else if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 112 | ERRORcxx . . $ `src/common/common.h:71:9`!("Error while trying to access file [%s] [%d]: %s", |
| 113 | symlinks[i].name, ret, strerror(ret)); |
| 114 | result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 115 | continue; |
| 116 | } |
| 117 | |
| 118 | ret = file_does_not_link_tocxx . . $ file_does_not_link_to(b4f44182c5fb6adc).(symlinks[i].namecxx . . $ authselect_symlink#name., symlinks[i].destcxx . . $ authselect_symlink#dest., truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!, |
| 119 | &valid); |
| 120 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 121 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to check file [%s] [%d]: %s", |
| 122 | symlinks[i].name, ret, strerror(ret)); |
| 123 | result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 124 | continue; |
| 125 | } |
| 126 | |
| 127 | if (!valid) { |
| 128 | ERRORcxx . . $ `src/common/common.h:71:9`!("Symbolic link [%s] to [%s] still exists!", |
| 129 | symlinks[i].name, symlinks[i].dest); |
| 130 | result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 131 | continue; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return result; |
| 136 | } |
| 137 | |
| 138 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 139 | authselect_symlinks_location_availablecxx . . $ authselect_symlinks_location_available(c9857a73d68e59ba).() |
| 140 | { |
| 141 | struct authselect_symlinkcxx . . $ authselect_symlink# symlinks[] = {SYMLINK_FILEScxx . . $ `src/lib/paths.h:140:9`!}; |
| 142 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 143 | errno_tcxx . . $ errno_t# ret; |
| 144 | int i; |
| 145 | |
| 146 | for (i = 0; symlinks[i].namecxx . . $ authselect_symlink#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) { |
| 147 | ret = file_existscxx . . $ file_exists(5c4306d8553b3696).(symlinks[i].namecxx . . $ authselect_symlink#name.); |
| 148 | if (ret == EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 149 | ERRORcxx . . $ `src/common/common.h:71:9`!("File [%s] exists but it needs to be overwritten!", |
| 150 | symlinks[i].name); |
| 151 | result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 152 | } else if (ret != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 153 | ERRORcxx . . $ `src/common/common.h:71:9`!("Error while trying to access file [%s] [%d]: %s", |
| 154 | symlinks[i].name, ret, strerror(ret)); |
| 155 | result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return result; |
| 160 | } |
| 161 | |
| 162 | errno_tcxx . . $ errno_t# |
| 163 | authselect_symlinks_uninstallcxx . . $ authselect_symlinks_uninstall(d1b40a211a1a4e4c).() |
| 164 | { |
| 165 | struct selinux_safe_copycxx . . $ selinux_safe_copy# table[] = { |
| 166 | {PATH_SYSTEMcxx . . $ `src/lib/paths.h:48:9`!, PATH_SYMLINK_SYSTEMcxx . . $ `src/lib/paths.h:59:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 167 | {PATH_PASSWORDcxx . . $ `src/lib/paths.h:49:9`!, PATH_SYMLINK_PASSWORDcxx . . $ `src/lib/paths.h:60:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 168 | {PATH_FINGERPRINTcxx . . $ `src/lib/paths.h:50:9`!, PATH_SYMLINK_FINGERPRINTcxx . . $ `src/lib/paths.h:61:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 169 | {PATH_SMARTCARDcxx . . $ `src/lib/paths.h:51:9`!, PATH_SYMLINK_SMARTCARDcxx . . $ `src/lib/paths.h:62:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 170 | {PATH_SWITCHABLEcxx . . $ `src/lib/paths.h:52:9`!, PATH_SYMLINK_SWITCHABLEcxx . . $ `src/lib/paths.h:63:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 171 | {PATH_POSTLOGINcxx . . $ `src/lib/paths.h:53:9`!, PATH_SYMLINK_POSTLOGINcxx . . $ `src/lib/paths.h:64:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 172 | {PATH_NSSWITCHcxx . . $ `src/lib/paths.h:54:9`!, PATH_SYMLINK_NSSWITCHcxx . . $ `src/lib/paths.h:65:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 173 | {PATH_DCONF_DBcxx . . $ `src/lib/paths.h:55:9`!, PATH_SYMLINK_DCONF_DBcxx . . $ `src/lib/paths.h:66:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 174 | {PATH_DCONF_LOCKcxx . . $ `src/lib/paths.h:56:9`!, PATH_SYMLINK_DCONF_LOCKcxx . . $ `src/lib/paths.h:67:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!}, |
| 175 | {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!} |
| 176 | }; |
| 177 | errno_tcxx . . $ errno_t# ret; |
| 178 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result; |
| 179 | int i; |
| 180 | |
| 181 | for (i = 0; table[i].sourcecxx . . $ selinux_safe_copy#source. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) { |
| 182 | /* Check if the symlink is still valid. */ |
| 183 | ret = file_does_not_link_tocxx . . $ file_does_not_link_to(b4f44182c5fb6adc).(table[i].destinationcxx . . $ selinux_safe_copy#destination., table[i].sourcecxx . . $ selinux_safe_copy#source., |
| 184 | falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, &result); |
| 185 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | if (result) { |
| 190 | /* This path is already not part of authselect. Let's skip it. */ |
| 191 | INFOcxx . . $ `src/common/common.h:63:9`!("Skipping [%s] because it is not an authselect file", |
| 192 | table[i].destination); |
| 193 | table[i].destinationcxx . . $ selinux_safe_copy#destination. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return selinux_copy_files_safelycxx . . $ selinux_copy_files_safely(58cfd31e237da923).(table, AUTHSELECT_DIR_MODEcxx . . $ `src/lib/constants.h:29:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 198 | } |