| 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 <string.h> |
| 22 | #include <stdlib.h> |
| 23 | |
| 24 | #include "authselect.h" |
| 25 | #include "lib/constants.h" |
| 26 | #include "lib/files/files.h" |
| 27 | #include "lib/profiles/profiles.h" |
| 28 | |
| 29 | _PUBLIC_ int |
| 30 | authselect_files(const char *profile_id, |
| 31 | const char **features, |
| 32 | struct authselect_files **_files) |
| 33 | { |
| 34 | struct authselect_profile *profile; |
| 35 | struct authselect_files *files; |
| 36 | errno_t ret; |
| 37 | |
| 38 | ret = authselect_profile(profile_id, &profile); |
| 39 | if (ret != EOK) { |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | ret = authselect_system_generate(features, profile->files, &files); |
| 44 | authselect_profile_free(profile); |
| 45 | if (ret != EOK) { |
| 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | *_files = files; |
| 50 | |
| 51 | return EOK; |
| 52 | } |
| 53 | |
| 54 | _PUBLIC_ const char * |
| 55 | authselect_files_nsswitch(const struct authselect_files *files) |
| 56 | { |
| 57 | if (files == NULL) { |
| 58 | return NULL; |
| 59 | } |
| 60 | |
| 61 | return files->nsswitch; |
| 62 | } |
| 63 | |
| 64 | _PUBLIC_ const char * |
| 65 | authselect_files_systemauth(const struct authselect_files *files) |
| 66 | { |
| 67 | if (files == NULL) { |
| 68 | return NULL; |
| 69 | } |
| 70 | |
| 71 | return files->systemauth; |
| 72 | } |
| 73 | |
| 74 | _PUBLIC_ const char * |
| 75 | authselect_files_passwordauth(const struct authselect_files *files) |
| 76 | { |
| 77 | if (files == NULL) { |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | return files->passwordauth; |
| 82 | } |
| 83 | |
| 84 | _PUBLIC_ const char * |
| 85 | authselect_files_smartcardauth(const struct authselect_files *files) |
| 86 | { |
| 87 | if (files == NULL) { |
| 88 | return NULL; |
| 89 | } |
| 90 | |
| 91 | return files->smartcardauth; |
| 92 | } |
| 93 | |
| 94 | _PUBLIC_ const char * |
| 95 | authselect_files_fingerprintauth(const struct authselect_files *files) |
| 96 | { |
| 97 | if (files == NULL) { |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | return files->fingerprintauth; |
| 102 | } |
| 103 | |
| 104 | _PUBLIC_ const char * |
| 105 | authselect_files_switchableauth(const struct authselect_files *files) |
| 106 | { |
| 107 | if (files == NULL) { |
| 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | return files->switchableauth; |
| 112 | } |
| 113 | |
| 114 | _PUBLIC_ const char * |
| 115 | authselect_files_postlogin(const struct authselect_files *files) |
| 116 | { |
| 117 | if (files == NULL) { |
| 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | return files->postlogin; |
| 122 | } |
| 123 | |
| 124 | _PUBLIC_ const char * |
| 125 | authselect_files_dconf_db(const struct authselect_files *files) |
| 126 | { |
| 127 | if (files == NULL) { |
| 128 | return NULL; |
| 129 | } |
| 130 | |
| 131 | return files->dconfdb; |
| 132 | } |
| 133 | |
| 134 | _PUBLIC_ const char * |
| 135 | authselect_files_dconf_lock(const struct authselect_files *files) |
| 136 | { |
| 137 | if (files == NULL) { |
| 138 | return NULL; |
| 139 | } |
| 140 | |
| 141 | return files->dconflock; |
| 142 | } |
| 143 | |
| 144 | _PUBLIC_ void |
| 145 | authselect_files_free(struct authselect_files *files) |
| 146 | { |
| 147 | if (files == NULL) { |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | if (files->systemauth != NULL) { |
| 152 | free(files->systemauth); |
| 153 | } |
| 154 | |
| 155 | if (files->passwordauth != NULL) { |
| 156 | free(files->passwordauth); |
| 157 | } |
| 158 | |
| 159 | if (files->smartcardauth != NULL) { |
| 160 | free(files->smartcardauth); |
| 161 | } |
| 162 | |
| 163 | if (files->switchableauth != NULL) { |
| 164 | free(files->switchableauth); |
| 165 | } |
| 166 | |
| 167 | if (files->fingerprintauth != NULL) { |
| 168 | free(files->fingerprintauth); |
| 169 | } |
| 170 | |
| 171 | if (files->postlogin != NULL) { |
| 172 | free(files->postlogin); |
| 173 | } |
| 174 | |
| 175 | if (files->nsswitch != NULL) { |
| 176 | free(files->nsswitch); |
| 177 | } |
| 178 | |
| 179 | if (files->dconfdb != NULL) { |
| 180 | free(files->dconfdb); |
| 181 | } |
| 182 | |
| 183 | if (files->dconflock != NULL) { |
| 184 | free(files->dconflock); |
| 185 | } |
| 186 | |
| 187 | memset(files, 0, sizeof(struct authselect_files)); |
| 188 | |
| 189 | free(files); |
| 190 | } |