| 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 <stdio.h> |
| 23 | #include <string.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <unistd.h> |
| 26 | #include <selinux/selinux.h> |
| 27 | #include <selinux/label.h> |
| 28 | #include <sys/stat.h> |
| 29 | |
| 30 | #include "common/common.h"cxx . . $ `<file>/src/common/common.h`/ |
| 31 | #include "lib/constants.h"cxx . . $ `<file>/src/lib/constants.h`/ |
| 32 | #include "lib/util/file.h"cxx . . $ `<file>/src/lib/util/file.h`/ |
| 33 | #include "lib/util/template.h"cxx . . $ `<file>/src/lib/util/template.h`/ |
| 34 | #include "lib/util/selinux.h"cxx . . $ `<file>/src/lib/util/selinux.h`/ |
| 35 | #include "lib/util/string_array.h"cxx . . $ `<file>/src/lib/util/string_array.h`/ |
| 36 | |
| 37 | static errno_tcxx . . $ errno_t# |
| 38 | selinux_get_default_contextcxx . . $ selinux_get_default_context(c4dada3283861623).(const char *path, |
| 39 | char **_context) |
| 40 | { |
| 41 | struct selabel_handlecxx . . $ selabel_handle# *handle; |
| 42 | char *context; |
| 43 | int ret; |
| 44 | |
| 45 | handle = selabel_opencxx . . $ selabel_open(8ce6380dda2db109).(SELABEL_CTX_FILEcxx . . $ `<external>/6506712053259663274/label.h:29:9`!, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, 0); |
| 46 | if (handle == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 47 | ret = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 48 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to create selabel handle [%d]: %s", ret, strerror(ret)); |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | ret = selabel_lookupcxx . . $ selabel_lookup(39010156bb585a1a).(handle, &context, path, 0); |
| 53 | if (ret < 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 54 | context = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 55 | } else if (ret != 0) { |
| 56 | ret = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 57 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to lookup selinux context [%d]: %s", ret, strerror(ret)); |
| 58 | goto done; |
| 59 | } |
| 60 | |
| 61 | INFOcxx . . $ `src/common/common.h:63:9`!("Found default selinux context for [%s]: %s", |
| 62 | path, context == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! ? "NULL" : context); |
| 63 | |
| 64 | *_context = context; |
| 65 | |
| 66 | ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 67 | |
| 68 | done: |
| 69 | selabel_closecxx . . $ selabel_close(532d585ec589ee3e).(handle); |
| 70 | |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | errno_tcxx . . $ errno_t# |
| 75 | selinux_get_contextcxx . . $ selinux_get_context(c4dada3283861623).(const char *path, |
| 76 | char **_context) |
| 77 | { |
| 78 | char *context; |
| 79 | int ret; |
| 80 | |
| 81 | ret = getfileconcxx . . $ getfilecon(c4dada3283861623).(path, &context); |
| 82 | if (ret < 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 83 | return selinux_get_default_contextcxx . . $ selinux_get_default_context(c4dada3283861623).(path, _context); |
| 84 | } else if (ret < 0) { |
| 85 | ret = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 86 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to obtain selinux context for [%s] [%d]: %s", |
| 87 | path, ret, strerror(ret)); |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | INFOcxx . . $ `src/common/common.h:63:9`!("Found selinux context for [%s]: %s", |
| 93 | path, context == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! ? _cxx . . $ `src/common/common.h:33:9`!("not set") : context); |
| 94 | |
| 95 | *_context = context; |
| 96 | |
| 97 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 98 | } |
| 99 | |
| 100 | errno_tcxx . . $ errno_t# |
| 101 | selinux_mkstemp_forcxx . . $ selinux_mkstemp_for(d26d230207164ac8).(const char *filepath, |
| 102 | mode_tcxx . . $ mode_t# mode, |
| 103 | char **_tmpfile) |
| 104 | { |
| 105 | char *original_context = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 106 | char *default_context = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 107 | char *tmpfile; |
| 108 | errno_tcxx . . $ errno_t# ret; |
| 109 | int seret; |
| 110 | |
| 111 | if (is_selinux_enabledcxx . . $ is_selinux_enabled(b126dc7c1de90089).() != 1) { |
| 112 | return file_mktmp_forcxx . . $ file_mktmp_for(d26d230207164ac8).(filepath, mode, _tmpfile); |
| 113 | } |
| 114 | |
| 115 | seret = getfscreateconcxx . . $ getfscreatecon(b90f8021b121110e).(&original_context); |
| 116 | if (seret != 0) { |
| 117 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to get current fscreate selinux context!"); |
| 118 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 119 | } |
| 120 | |
| 121 | ret = selinux_get_contextcxx . . $ selinux_get_context(c4dada3283861623).(filepath, &default_context); |
| 122 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 123 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to get default selinux context for [%s] [%d]: %s!", |
| 124 | filepath, ret, strerror(ret)); |
| 125 | goto done; |
| 126 | } |
| 127 | |
| 128 | /* Set desired fs create context. */ |
| 129 | seret = setfscreateconcxx . . $ setfscreatecon(5c4306d8553b3696).(default_context); |
| 130 | if (seret != 0) { |
| 131 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to set fscreate selinux context!"); |
| 132 | ret = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 133 | goto done; |
| 134 | } |
| 135 | |
| 136 | ret = file_mktmp_forcxx . . $ file_mktmp_for(d26d230207164ac8).(filepath, mode, &tmpfile); |
| 137 | |
| 138 | /* Restore original fs create context. */ |
| 139 | seret = setfscreateconcxx . . $ setfscreatecon(5c4306d8553b3696).(original_context); |
| 140 | if (seret != 0) { |
| 141 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to restore fscreate selinux context!"); |
| 142 | ret = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 143 | goto done; |
| 144 | } |
| 145 | |
| 146 | /* Check result of file_mktmp_for() */ |
| 147 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 148 | freecxx . . $ free(5d22bdacc48458e8).(tmpfile); |
| 149 | goto done; |
| 150 | } |
| 151 | |
| 152 | *_tmpfile = tmpfile; |
| 153 | |
| 154 | ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 155 | |
| 156 | done: |
| 157 | if (original_context != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 158 | freeconcxx . . $ freecon(fda57c8427c60377).(original_context); |
| 159 | } |
| 160 | |
| 161 | if (default_context != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 162 | freeconcxx . . $ freecon(fda57c8427c60377).(default_context); |
| 163 | } |
| 164 | |
| 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | errno_tcxx . . $ errno_t# |
| 169 | selinux_file_copycxx . . $ selinux_file_copy(f8e1a36fd0133965).(const char *source, |
| 170 | const char *destdir, |
| 171 | const char *destname, |
| 172 | mode_tcxx . . $ mode_t# dir_mode) |
| 173 | { |
| 174 | char *original_context = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 175 | char *default_context = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 176 | errno_tcxx . . $ errno_t# ret; |
| 177 | int seret; |
| 178 | |
| 179 | if (is_selinux_enabledcxx . . $ is_selinux_enabled(b126dc7c1de90089).() != 1) { |
| 180 | return file_copycxx . . $ file_copy(f8e1a36fd0133965).(source, destdir, destname, dir_mode); |
| 181 | } |
| 182 | |
| 183 | seret = getfscreateconcxx . . $ getfscreatecon(b90f8021b121110e).(&original_context); |
| 184 | if (seret != 0) { |
| 185 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to get current fscreate selinux context!"); |
| 186 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 187 | } |
| 188 | |
| 189 | ret = selinux_get_contextcxx . . $ selinux_get_context(c4dada3283861623).(source, &default_context); |
| 190 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 191 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to get default selinux context for [%s] [%d]: %s!", |
| 192 | source, ret, strerror(ret)); |
| 193 | goto done; |
| 194 | } |
| 195 | |
| 196 | /* Set desired fs create context. */ |
| 197 | seret = setfscreateconcxx . . $ setfscreatecon(5c4306d8553b3696).(default_context); |
| 198 | if (seret != 0) { |
| 199 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to set fscreate selinux context!"); |
| 200 | ret = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 201 | goto done; |
| 202 | } |
| 203 | |
| 204 | ret = file_copycxx . . $ file_copy(f8e1a36fd0133965).(source, destdir, destname, dir_mode); |
| 205 | |
| 206 | /* Restore original fs create context. */ |
| 207 | seret = setfscreateconcxx . . $ setfscreatecon(5c4306d8553b3696).(original_context); |
| 208 | if (seret != 0) { |
| 209 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to restore fscreate selinux context!"); |
| 210 | ret = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 211 | goto done; |
| 212 | } |
| 213 | |
| 214 | /* Check result of textfile_copy() */ |
| 215 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 216 | goto done; |
| 217 | } |
| 218 | |
| 219 | ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 220 | |
| 221 | done: |
| 222 | if (original_context != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 223 | freeconcxx . . $ freecon(fda57c8427c60377).(original_context); |
| 224 | } |
| 225 | |
| 226 | if (default_context != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 227 | freeconcxx . . $ freecon(fda57c8427c60377).(default_context); |
| 228 | } |
| 229 | |
| 230 | return ret; |
| 231 | } |
| 232 | |
| 233 | errno_tcxx . . $ errno_t# |
| 234 | selinux_mkstemp_copycxx . . $ selinux_mkstemp_copy(97ae8d2497589c87).(const char *source, |
| 235 | const char *destdir, |
| 236 | const char *destname, |
| 237 | mode_tcxx . . $ mode_t# dir_mode, |
| 238 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! keep_secontext, |
| 239 | char **_tmpfile) |
| 240 | { |
| 241 | const char *context_file = keep_secontext ? source : destname; |
| 242 | char *original_context = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 243 | char *default_context = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 244 | errno_tcxx . . $ errno_t# ret; |
| 245 | int seret; |
| 246 | |
| 247 | if (is_selinux_enabledcxx . . $ is_selinux_enabled(b126dc7c1de90089).() != 1) { |
| 248 | return file_mktmp_copycxx . . $ file_mktmp_copy(dbcc8002fb6c5cd0).(source, destdir, destname, dir_mode, _tmpfile); |
| 249 | } |
| 250 | |
| 251 | seret = getfscreateconcxx . . $ getfscreatecon(b90f8021b121110e).(&original_context); |
| 252 | if (seret != 0) { |
| 253 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to get current fscreate selinux context!"); |
| 254 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 255 | } |
| 256 | |
| 257 | ret = selinux_get_contextcxx . . $ selinux_get_context(c4dada3283861623).(context_file, &default_context); |
| 258 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 259 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to get default selinux context for [%s] [%d]: %s!", |
| 260 | source, ret, strerror(ret)); |
| 261 | goto done; |
| 262 | } |
| 263 | |
| 264 | /* Set desired fs create context. */ |
| 265 | seret = setfscreateconcxx . . $ setfscreatecon(5c4306d8553b3696).(default_context); |
| 266 | if (seret != 0) { |
| 267 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to set fscreate selinux context!"); |
| 268 | ret = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 269 | goto done; |
| 270 | } |
| 271 | |
| 272 | ret = file_mktmp_copycxx . . $ file_mktmp_copy(dbcc8002fb6c5cd0).(source, destdir, destname, dir_mode, _tmpfile); |
| 273 | |
| 274 | /* Restore original fs create context. */ |
| 275 | seret = setfscreateconcxx . . $ setfscreatecon(5c4306d8553b3696).(original_context); |
| 276 | if (seret != 0) { |
| 277 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to restore fscreate selinux context!"); |
| 278 | ret = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 279 | goto done; |
| 280 | } |
| 281 | |
| 282 | /* Check result of textfile_copy() */ |
| 283 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 284 | goto done; |
| 285 | } |
| 286 | |
| 287 | ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 288 | |
| 289 | done: |
| 290 | if (original_context != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 291 | freeconcxx . . $ freecon(fda57c8427c60377).(original_context); |
| 292 | } |
| 293 | |
| 294 | if (default_context != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 295 | freeconcxx . . $ freecon(fda57c8427c60377).(default_context); |
| 296 | } |
| 297 | |
| 298 | return ret; |
| 299 | } |
| 300 | |
| 301 | static errno_tcxx . . $ errno_t# |
| 302 | parse_destination_pathcxx . . $ parse_destination_path(c0a3d66f6ffdbd4c).(const char *destination, |
| 303 | char **_dir, |
| 304 | char **_name) |
| 305 | { |
| 306 | const char *cname; |
| 307 | char *name; |
| 308 | char *dir; |
| 309 | |
| 310 | dir = file_get_parent_directorycxx . . $ file_get_parent_directory(a8b8e32347182212).(destination); |
| 311 | if (dir == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 312 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 313 | } |
| 314 | |
| 315 | cname = file_get_basenamecxx . . $ file_get_basename(fb58d2e09a2a1ce6).(destination); |
| 316 | if (cname == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 317 | freecxx . . $ free(5d22bdacc48458e8).(dir); |
| 318 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 319 | } |
| 320 | |
| 321 | name = strdupcxx . . $ strdup(a8b8e32347182212).(cname); |
| 322 | if (name == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 323 | freecxx . . $ free(5d22bdacc48458e8).(dir); |
| 324 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 325 | } |
| 326 | |
| 327 | *_dir = dir; |
| 328 | *_name = name; |
| 329 | |
| 330 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 331 | } |
| 332 | |
| 333 | errno_tcxx . . $ errno_t# |
| 334 | selinux_copy_files_safelycxx . . $ selinux_copy_files_safely(58cfd31e237da923).(struct selinux_safe_copycxx . . $ selinux_safe_copy# *table, |
| 335 | mode_tcxx . . $ mode_t# dir_mode, |
| 336 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! keep_secontext) |
| 337 | { |
| 338 | char **tmpfiles = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 339 | char **names = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 340 | char **dirs = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 341 | errno_tcxx . . $ errno_t# ret; |
| 342 | int i; |
| 343 | |
| 344 | for (i = 0; table[i].sourcecxx . . $ selinux_safe_copy#source. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; i++) { |
| 345 | /* Just counting. */ |
| 346 | } |
| 347 | |
| 348 | tmpfiles = string_array_createcxx . . $ string_array_create(4d3fbc76ec7ad0ba).(i); |
| 349 | if (tmpfiles == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 350 | ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 351 | goto done; |
| 352 | } |
| 353 | |
| 354 | dirs = string_array_createcxx . . $ string_array_create(4d3fbc76ec7ad0ba).(i); |
| 355 | if (dirs == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 356 | ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 357 | goto done; |
| 358 | } |
| 359 | |
| 360 | names = string_array_createcxx . . $ string_array_create(4d3fbc76ec7ad0ba).(i); |
| 361 | if (names == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 362 | ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 363 | goto done; |
| 364 | } |
| 365 | |
| 366 | /* Parse destination. */ |
| 367 | for (i = 0; table[i].sourcecxx . . $ selinux_safe_copy#source. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; i++) { |
| 368 | if (table[i].destinationcxx . . $ selinux_safe_copy#destination. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 369 | /* Skip this entry. */ |
| 370 | continue; |
| 371 | } |
| 372 | |
| 373 | ret = parse_destination_pathcxx . . $ parse_destination_path(c0a3d66f6ffdbd4c).(table[i].destinationcxx . . $ selinux_safe_copy#destination., &dirs[i], &names[i]); |
| 374 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 375 | goto done; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | /* First, write content into temporary files, so we can safely fail |
| 380 | * on error without overwriting destination files. */ |
| 381 | for (i = 0; table[i].sourcecxx . . $ selinux_safe_copy#source. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; i++) { |
| 382 | if (table[i].destinationcxx . . $ selinux_safe_copy#destination. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 383 | /* Skip this entry. */ |
| 384 | continue; |
| 385 | } |
| 386 | |
| 387 | if (file_existscxx . . $ file_exists(5c4306d8553b3696).(table[i].sourcecxx . . $ selinux_safe_copy#source.) == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 388 | if (table[i].write_empty_if_missingcxx . . $ selinux_safe_copy#write_empty_if_missing.) { |
| 389 | INFOcxx . . $ `src/common/common.h:63:9`!("File [%s] does not exist", table[i].source); |
| 390 | INFOcxx . . $ `src/common/common.h:63:9`!("Writing empty temporary file for [%s]", |
| 391 | table[i].destination); |
| 392 | ret = template_write_temporarycxx . . $ template_write_temporary(5071347881743dfd).(table[i].destinationcxx . . $ selinux_safe_copy#destination., "", |
| 393 | AUTHSELECT_FILE_MODEcxx . . $ `src/lib/constants.h:30:9`!, |
| 394 | &tmpfiles[i]); |
| 395 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 396 | goto done; |
| 397 | } |
| 398 | } else if (!table[i].can_unlinkcxx . . $ selinux_safe_copy#can_unlink.) { |
| 399 | ERRORcxx . . $ `src/common/common.h:71:9`!("File [%s] should exist but is missing. It is not safe to " |
| 400 | "delete [%s]. Aborting.", table[i].source, |
| 401 | table[i].destination); |
| 402 | ret = EPERMcxx . . $ `<external>/8987895939074593727/errno-base.h:5:9`!; |
| 403 | goto done; |
| 404 | } else { |
| 405 | /* destination will be removed later */ |
| 406 | INFOcxx . . $ `src/common/common.h:63:9`!("File [%s] does not exist", table[i].source); |
| 407 | tmpfiles[i] = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 408 | } |
| 409 | } else { |
| 410 | INFOcxx . . $ `src/common/common.h:63:9`!("Writing temporary file for [%s]", table[i].destination); |
| 411 | ret = selinux_mkstemp_copycxx . . $ selinux_mkstemp_copy(97ae8d2497589c87).(table[i].sourcecxx . . $ selinux_safe_copy#source., dirs[i], names[i], |
| 412 | dir_mode, keep_secontext, &tmpfiles[i]); |
| 413 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 414 | goto done; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /* Now rename the files. |
| 420 | * |
| 421 | * We now know that the system is writable, so rename call shall not |
| 422 | * fail and it will overwrite any existing file. The only reason it |
| 423 | * can fail is EIO which we can not do anything about and we can not |
| 424 | * even recover from it. |
| 425 | */ |
| 426 | for (i = 0; table[i].sourcecxx . . $ selinux_safe_copy#source. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; i++) { |
| 427 | if (table[i].destinationcxx . . $ selinux_safe_copy#destination. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 428 | /* Skip this entry. */ |
| 429 | continue; |
| 430 | } |
| 431 | |
| 432 | if (tmpfiles[i] == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 433 | INFOcxx . . $ `src/common/common.h:63:9`!("Removing [%s]", table[i].destination); |
| 434 | unlinkcxx . . $ unlink(5c4306d8553b3696).(table[i].destinationcxx . . $ selinux_safe_copy#destination.); |
| 435 | continue; |
| 436 | } |
| 437 | |
| 438 | INFOcxx . . $ `src/common/common.h:63:9`!("Renaming [%s] to [%s]", tmpfiles[i], table[i].destination); |
| 439 | ret = renamecxx . . $ rename(5ae29d726ae57f88).(tmpfiles[i], table[i].destinationcxx . . $ selinux_safe_copy#destination.); |
| 440 | if (ret != 0) { |
| 441 | ret = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 442 | ERRORcxx . . $ `src/common/common.h:71:9`!("Unable to rename [%s] to [%s] [%d]: %s", |
| 443 | tmpfiles[i], table[i].destination, ret, strerror(ret)); |
| 444 | goto done; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 449 | |
| 450 | done: |
| 451 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`! && tmpfiles != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 452 | for (i = 0; table[i].sourcecxx . . $ selinux_safe_copy#source. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; i++) { |
| 453 | if (tmpfiles[i] != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 454 | unlinkcxx . . $ unlink(5c4306d8553b3696).(tmpfiles[i]); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(tmpfiles); |
| 460 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(names); |
| 461 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(dirs); |
| 462 | |
| 463 | return ret; |
| 464 | } |