| 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 | #ifndef _FILES_H_ |
| 22 | #define _FILES_H_ |
| 23 | |
| 24 | #include <stdbool.h> |
| 25 | |
| 26 | #include "common/errno_t.h" |
| 27 | |
| 28 | struct authselect_files { |
| 29 | char *systemauth; |
| 30 | char *passwordauth; |
| 31 | char *smartcardauth; |
| 32 | char *switchableauth; |
| 33 | char *fingerprintauth; |
| 34 | char *postlogin; |
| 35 | char *nsswitch; |
| 36 | char *dconfdb; |
| 37 | char *dconflock; |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * Read information from configuration file. |
| 42 | * |
| 43 | * @param _profile_id Profile ID. |
| 44 | * @param _features NULL-terminated string array of enabled features. |
| 45 | * |
| 46 | * @return EOK on success, ENOENT if the configuration file is missing, |
| 47 | * other errno code on error. |
| 48 | */ |
| 49 | errno_t |
| 50 | authselect_config_read(char **_profile_id, |
| 51 | char ***_features); |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Write information into configuration file. |
| 56 | * |
| 57 | * @param profile_id Profile ID. |
| 58 | * @param features NULL-terminated string array of enabled features. |
| 59 | * |
| 60 | * @return EOK on success, other errno code on error. |
| 61 | */ |
| 62 | errno_t |
| 63 | authselect_config_write(const char *profile_id, |
| 64 | const char **features); |
| 65 | |
| 66 | /** |
| 67 | * Test if all locations that we work with are writable. |
| 68 | * |
| 69 | * @return True if all locations are writable, false otherwise. |
| 70 | */ |
| 71 | bool |
| 72 | authselect_config_locations_writable(void); |
| 73 | |
| 74 | /** |
| 75 | * Validate existing authselect configuration. |
| 76 | * |
| 77 | * Check that all files are created, readable and with correct content |
| 78 | * and that all symbolic links exist. |
| 79 | * |
| 80 | * @return True if the configuration is valid, false otherwise. |
| 81 | */ |
| 82 | bool |
| 83 | authselect_config_validate_authselect(const char *profile_id, |
| 84 | const char **features); |
| 85 | |
| 86 | /** |
| 87 | * Validate existing non-authselect configuration. |
| 88 | * |
| 89 | * Check that there are no left overs from previous authselect configuration. |
| 90 | * All generated files must be removed and all symbolic links must either not |
| 91 | * exists, point to different location or must be other file or directory. |
| 92 | * |
| 93 | * @return True if the are no left overs, false otherwise. |
| 94 | */ |
| 95 | bool |
| 96 | authselect_config_validate_user(void); |
| 97 | |
| 98 | /** |
| 99 | * Validate missing configuration. |
| 100 | * |
| 101 | * Check that there is no configuration at all (there are no authselect and |
| 102 | * no system files present). |
| 103 | * |
| 104 | * @return True if there is no configuration, false otherwise. |
| 105 | */ |
| 106 | bool |
| 107 | authselect_config_validate_missing(void); |
| 108 | |
| 109 | /** |
| 110 | * Generate contents of nsswitch.conf. |
| 111 | * |
| 112 | * @param template The file template. |
| 113 | * @param features List of enabled features. |
| 114 | * @param _content Generated content. |
| 115 | * |
| 116 | * @return EOK on success, other errno code on failure. |
| 117 | */ |
| 118 | errno_t |
| 119 | authselect_nsswitch_generate(const char *template, |
| 120 | const char **features, |
| 121 | char **_content); |
| 122 | |
| 123 | /** |
| 124 | * Find nsswitch maps in generated content. |
| 125 | * |
| 126 | * @param content Generated content. |
| 127 | * @param _maps Maps found in @content. |
| 128 | * |
| 129 | * @return EOK on success, other errno code on error. |
| 130 | */ |
| 131 | errno_t |
| 132 | authselect_nsswitch_find_maps(char *content, |
| 133 | char ***_maps); |
| 134 | |
| 135 | /** |
| 136 | * Read system files templates and return them in files structure. |
| 137 | * |
| 138 | * @param dirname Name of the directory that contains the files. |
| 139 | * @param dirfd File descriptor of the opened directory. |
| 140 | * @param _templates Output templates. |
| 141 | * |
| 142 | * @return EOK on success, other errno code on error. |
| 143 | */ |
| 144 | errno_t |
| 145 | authselect_system_read_templates(const char *dirname, |
| 146 | int dirfd, |
| 147 | struct authselect_files **_templates); |
| 148 | |
| 149 | /** |
| 150 | * Generate content of system files based on provided templates. |
| 151 | * |
| 152 | * @param features Optional features that should be enabled. |
| 153 | * @param templates System file templates. |
| 154 | * @param _files Generated system files content. |
| 155 | * |
| 156 | * @return EOK on success, other errno code on failure. |
| 157 | */ |
| 158 | errno_t |
| 159 | authselect_system_generate(const char **features, |
| 160 | struct authselect_files *templates, |
| 161 | struct authselect_files **_files); |
| 162 | |
| 163 | /** |
| 164 | * Write system files. |
| 165 | * |
| 166 | * @param features Optional features that should be enabled. |
| 167 | * @param templates System file templates. |
| 168 | * @param _files Generated system files content. |
| 169 | * |
| 170 | * @return EOK on success, other errno code on failure. |
| 171 | */ |
| 172 | errno_t |
| 173 | authselect_system_write(const char **features, |
| 174 | struct authselect_files *templates); |
| 175 | |
| 176 | /** |
| 177 | * Validate content of system files that we generate. |
| 178 | * |
| 179 | * @return True if the files are readable and have expected content, return |
| 180 | * false otherwise. |
| 181 | */ |
| 182 | bool |
| 183 | authselect_system_validate(struct authselect_files *files); |
| 184 | |
| 185 | /** |
| 186 | * Validate generated files for non-existing configuration. |
| 187 | * |
| 188 | * It checks that there are not left overs from previous authselect |
| 189 | * configuration, i.e. that all generated files do not exist. |
| 190 | * |
| 191 | * @return True if all generated files do not exist, false otherwise. |
| 192 | */ |
| 193 | bool |
| 194 | authselect_system_validate_missing(void); |
| 195 | |
| 196 | /** |
| 197 | * Write symbolic links to system configuration files. |
| 198 | * |
| 199 | * @return EOK on success, other errno code on failure. |
| 200 | */ |
| 201 | errno_t |
| 202 | authselect_symlinks_write(void); |
| 203 | |
| 204 | /** |
| 205 | * Validate symbolic links that we create. |
| 206 | * |
| 207 | * @return True if all symbolic links points to their expected destination, |
| 208 | * false otherwise. |
| 209 | */ |
| 210 | bool |
| 211 | authselect_symlinks_validate(void); |
| 212 | |
| 213 | /** |
| 214 | * Validate symbolic links for non-existing configuration. |
| 215 | * |
| 216 | * It checks that all symbolic links are either regular files or they point |
| 217 | * to different destination that we create for authselect or they do not |
| 218 | * exist at all. |
| 219 | * |
| 220 | * @return True if there are not left over symbolic links, false otherwise. |
| 221 | */ |
| 222 | bool |
| 223 | authselect_symlinks_validate_missing(void); |
| 224 | |
| 225 | /** |
| 226 | * Check if all locations where our symbolic links will be stored |
| 227 | * are available. Returns false if any file already exist on these |
| 228 | * locations. |
| 229 | * |
| 230 | * @return True if all locations are empty, false otherwise. |
| 231 | */ |
| 232 | bool |
| 233 | authselect_symlinks_location_available(void); |
| 234 | |
| 235 | /** |
| 236 | * Remove symbolic links generated by authselect by copying authselect files |
| 237 | * to their system destination. |
| 238 | * |
| 239 | * @return EOK on success, other errno code on failure. |
| 240 | */ |
| 241 | errno_t |
| 242 | authselect_symlinks_uninstall(); |
| 243 | |
| 244 | /** |
| 245 | * Remove files from authselect directory. |
| 246 | */ |
| 247 | errno_t |
| 248 | authselect_files_uninstall(void); |
| 249 | |
| 250 | |
| 251 | /** |
| 252 | * List all profile directories in a sorted NULL-terminated string array. |
| 253 | * |
| 254 | * This will find all profiles within default, vendor and custom profile |
| 255 | * directories. |
| 256 | * |
| 257 | * @param _profiles NULL-terminated sorted string array. |
| 258 | * |
| 259 | * @return EOK on success, other errno code on failure. |
| 260 | */ |
| 261 | errno_t |
| 262 | authselect_profile_list(char ***_profiles); |
| 263 | |
| 264 | #endif /* _FILES_H_ */ |