1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/*
SSSD
files_init.c - Initialization of the files provider
Copyright (C) 2016 Red Hat
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "providers/data_provider/dp.h"
#include "providers/files/files_private.h"
#include "util/util.h"
#define DEFAULT_PASSWD_FILE "/etc/passwd"
#define DEFAULT_GROUP_FILE "/etc/group"
static errno_t files_init_file_sources(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx,
const char ***_passwd_files,
const char ***_group_files)
{
TALLOC_CTX *tmp_ctx = NULL;
char *conf_passwd_files;
char *conf_group_files;
char **passwd_list = NULL;
char **group_list = NULL;
int num_passwd_files = 0;
int num_group_files = 0;
const char **passwd_files = NULL;
const char **group_files = NULL;
char *dfl_passwd_files = NULL;
char *env_group_files = NULL;
int i;
errno_t ret;
tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
ret = ENOMEM;
goto done;
}
ret = sss_getenv(tmp_ctx, "SSS_FILES_PASSWD", DEFAULT_PASSWD_FILE,
&dfl_passwd_files);
if (ret == EOK) {
sss_log(SSS_LOG_ALERT,
"Defaulting to %s for the passwd file, "
"this should only be used for testing!\n",
dfl_passwd_files);
} else if (ret != ENOENT) {
sss_log(SSS_LOG_ALERT, "sss_getenv() failed");
goto done;
}
DEBUG(SSSDBG_TRACE_FUNC,
"Using passwd file: [%s].\n",
dfl_passwd_files);
ret = sss_getenv(tmp_ctx, "SSS_FILES_GROUP", DEFAULT_GROUP_FILE,
&env_group_files);
if (ret == EOK) {
sss_log(SSS_LOG_ALERT,
"Defaulting to %s for the group file, "
"this should only be used for testing!\n",
env_group_files);
} else if (ret != ENOENT) {
sss_log(SSS_LOG_ALERT, "sss_getenv() failed");
goto done;
}
DEBUG(SSSDBG_TRACE_FUNC,
"Using group file: [%s].\n",
env_group_files);
ret = confdb_get_string(be_ctx->cdb, tmp_ctx, be_ctx->conf_path,
CONFDB_FILES_PASSWD, dfl_passwd_files,
&conf_passwd_files);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Failed to retrieve confdb passwd files!\n");
goto done;
}
ret = confdb_get_string(be_ctx->cdb, tmp_ctx, be_ctx->conf_path,
CONFDB_FILES_GROUP, env_group_files,
&conf_group_files);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Failed to retrieve confdb group files!\n");
goto done;
}
ret = split_on_separator(tmp_ctx, conf_passwd_files, ',', true, true,
&passwd_list, &num_passwd_files);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Failed to parse passwd list!\n");
goto done;
}
passwd_files = talloc_zero_array(tmp_ctx, const char *,
num_passwd_files + 1);
if (passwd_files == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
ret = ENOMEM;
goto done;
}
for (i = 0; i < num_passwd_files; i++) {
DEBUG(SSSDBG_TRACE_FUNC,
"Using passwd file: [%s].\n", passwd_list[i]);
passwd_files[i] = talloc_strdup(passwd_files, passwd_list[i]);
if (passwd_files[i] == NULL) {
ret = ENOMEM;
goto done;
}
}
/* Retrieve list of group files */
ret = split_on_separator(tmp_ctx, conf_group_files, ',', true, true,
&group_list, &num_group_files);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Failed to parse group files!\n");
goto done;
}
group_files = talloc_zero_array(tmp_ctx, const char *,
num_group_files + 1);
if (group_files == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
ret = ENOMEM;
goto done;
}
for (i = 0; i < num_group_files; i++) {
DEBUG(SSSDBG_TRACE_FUNC,
"Using group file: [%s].\n", group_list[i]);
group_files[i] = talloc_strdup(group_files, group_list[i]);
if (group_files[i] == NULL) {
ret = ENOMEM;
goto done;
}
}
*_passwd_files = talloc_steal(mem_ctx, passwd_files);
*_group_files = talloc_steal(mem_ctx, group_files);
ret = EOK;
done:
talloc_free(tmp_ctx);
return ret;
}
int sssm_files_init(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx,
struct data_provider *provider,
const char *module_name,
void **_module_data)
{
struct files_id_ctx *ctx;
errno_t ret;
ctx = talloc_zero(mem_ctx, struct files_id_ctx);
if (ctx == NULL) {
return ENOMEM;
}
ctx->be = be_ctx;
ctx->domain = be_ctx->domain;
ret = files_init_file_sources(ctx, be_ctx,
&ctx->passwd_files,
&ctx->group_files);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Cannot initialize the passwd/group source files\n");
goto done;
}
ctx->fctx = sf_init(ctx, be_ctx->ev,
ctx->passwd_files,
ctx->group_files,
ctx);
if (ctx->fctx == NULL) {
ret = ENOMEM;
goto done;
}
ret = confdb_certmap_to_sysdb(be_ctx->cdb, be_ctx->domain, true);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Failed to initialize certificate mapping rules. "
"Authentication with certificates/Smartcards might not work "
"as expected.\n");
/* not fatal, ignored */
} else {
ret = files_init_certmap(ctx, ctx);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "files_init_certmap failed. "
"Authentication with certificates/Smartcards might not work "
"as expected.\n");
/* not fatal, ignored */
}
}
*_module_data = ctx;
ret = EOK;
done:
if (ret != EOK) {
talloc_free(ctx);
}
return ret;
}
int sssm_files_id_init(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx,
void *module_data,
struct dp_method *dp_methods)
{
struct files_id_ctx *ctx;
ctx = talloc_get_type(module_data, struct files_id_ctx);
if (ctx == NULL) {
return EINVAL;
}
dp_set_method(dp_methods, DPM_ACCOUNT_HANDLER,
files_account_info_handler_send,
files_account_info_handler_recv,
ctx, struct files_id_ctx,
struct dp_id_data, struct dp_reply_std);
dp_set_method(dp_methods, DPM_ACCT_DOMAIN_HANDLER,
default_account_domain_send,
default_account_domain_recv,
NULL, void,
struct dp_get_acct_domain_data, struct dp_reply_std);
return EOK;
}
int sssm_files_auth_init(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx,
void *module_data,
struct dp_method *dp_methods)
{
dp_set_method(dp_methods, DPM_AUTH_HANDLER,
files_auth_handler_send, files_auth_handler_recv, NULL, void,
struct pam_data, struct pam_data *);
return EOK;
}
|