Debian Codegraph @

src/lib/profiles/activate.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 <errno.h>
22 #include <string.h>
23 #include <stdlib.h>
24
25 #include "common/common.h"
26 #include "lib/constants.h"
27 #include "lib/files/files.h"
28 #include "lib/profiles/profiles.h"
29 #include "lib/util/util.h"
30
31 errno_t
32 authselect_profile_dconf_update()
33 {
34 errno_t ret;
35 int sysret;
36
37 ret = file_check_access(AUTHSELECT_DCONF_BIN, X_OK);
38 if (ret != EOK) {
39 return ret;
40 }
41
42 sysret = system(AUTHSELECT_DCONF_BIN " update &> /dev/null");
43 if (sysret != 0) {
44 ERROR("%s update failed: %d", AUTHSELECT_DCONF_BIN, sysret);
45 return EIO;
46 }
47
48 return EOK;
49 }
50
51 errno_t
52 authselect_profile_copy_checksum()
53 {
54 INFO("Copying [%s] to [%s]", PATH_CHECKSUM_ORIG, PATH_CHECKSUM_COPY);
55 return file_copy(PATH_CHECKSUM_ORIG, AUTHSELECT_STATE_DIR, "checksum",
56 AUTHSELECT_DIR_MODE);
57 }
58
59 errno_t
60 authselect_profile_activate(struct authselect_profile *profile,
61 const char **features)
62 {
63 errno_t ret;
64
65 /* Check that all directories are writable. */
66 if (!authselect_config_locations_writable()) {
67 ERROR("Some directories are not accessible by authselect!");
68 return EACCES;
69 }
70
71 ret = authselect_system_write(features, profile->files);
72 if (ret != EOK) {
73 ERROR("Unable to write generated system files [%d]: %s",
74 ret, strerror(ret));
75 return ret;
76 }
77
78 ret = authselect_config_write(profile->id, features);
79 if (ret != EOK) {
80 ERROR("Unable to write configuration [%d]: %s", ret, strerror(ret));
81 return ret;
82 }
83
84 ret = authselect_symlinks_write();
85 if (ret != EOK) {
86 ERROR("Unable to create symbolic links [%d]: %s", ret, strerror(ret));
87 return ret;
88 }
89
90 ret = authselect_profile_dconf_update();
91 if (ret == ENOENT) {
92 INFO("Dconf is not installed on your system");
93 } else if (ret != EOK) {
94 ERROR("Unable to update dconf database [%d]: %s", ret, strerror(ret));
95 return ret;
96 }
97
98 ret = authselect_profile_copy_checksum();
99 if (ret != EOK) {
100 /* This is not a fatal error. */
101 WARN("Unable to copy profiles checksum [%d]: %s", ret, strerror(ret));
102 }
103
104 return EOK;
105 }