4
IPA Provider Common Functions
7
Simo Sorce <ssorce@redhat.com>
9
Copyright (C) 2009 Red Hat
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 3 of the License, or
14
(at your option) any later version.
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
21
You should have received a copy of the GNU General Public License
22
along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include "providers/ipa/ipa_common.h"
29
struct dp_option ipa_basic_opts[] = {
30
{ "ipa_domain", DP_OPT_STRING, NULL_STRING, NULL_STRING },
31
{ "ipa_server", DP_OPT_STRING, NULL_STRING, NULL_STRING },
32
{ "ipa_hostname", DP_OPT_STRING, NULL_STRING, NULL_STRING },
35
struct dp_option ipa_def_ldap_opts[] = {
36
{ "ldap_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
37
{ "ldap_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING },
38
{ "ldap_default_bind_dn", DP_OPT_STRING, NULL_STRING, NULL_STRING },
39
{ "ldap_default_authtok_type", DP_OPT_STRING, NULL_STRING, NULL_STRING},
40
{ "ldap_default_authtok", DP_OPT_BLOB, NULL_BLOB, NULL_BLOB },
41
{ "ldap_search_timeout", DP_OPT_NUMBER, { .number = 60 }, NULL_NUMBER },
42
{ "ldap_network_timeout", DP_OPT_NUMBER, { .number = 6 }, NULL_NUMBER },
43
{ "ldap_opt_timeout", DP_OPT_NUMBER, { .number = 6 }, NULL_NUMBER },
44
{ "ldap_tls_reqcert", DP_OPT_STRING, { "hard" }, NULL_STRING },
45
{ "ldap_user_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING },
46
{ "ldap_user_search_scope", DP_OPT_STRING, { "sub" }, NULL_STRING },
47
{ "ldap_user_search_filter", DP_OPT_STRING, NULL_STRING, NULL_STRING },
48
{ "ldap_group_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING },
49
{ "ldap_group_search_scope", DP_OPT_STRING, { "sub" }, NULL_STRING },
50
{ "ldap_group_search_filter", DP_OPT_STRING, NULL_STRING, NULL_STRING },
51
{ "ldap_schema", DP_OPT_STRING, { "ipa_v1" }, NULL_STRING },
52
{ "ldap_offline_timeout", DP_OPT_NUMBER, { .number = 60 }, NULL_NUMBER },
53
{ "ldap_force_upper_case_realm", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
54
{ "ldap_enumeration_refresh_timeout", DP_OPT_NUMBER, { .number = 300 }, NULL_NUMBER },
55
{ "ldap_purge_cache_timeout", DP_OPT_NUMBER, { .number = 3600 }, NULL_NUMBER },
56
{ "entry_cache_timeout", DP_OPT_NUMBER, { .number = 1800 }, NULL_NUMBER },
57
{ "ldap_tls_cacert", DP_OPT_STRING, NULL_STRING, NULL_STRING },
58
{ "ldap_tls_cacertdir", DP_OPT_STRING, NULL_STRING, NULL_STRING },
59
{ "ldap_id_use_start_tls", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
60
{ "ldap_sasl_mech", DP_OPT_STRING, { "GSSAPI" } , NULL_STRING },
61
{ "ldap_sasl_authid", DP_OPT_STRING, NULL_STRING, NULL_STRING },
62
{ "ldap_krb5_keytab", DP_OPT_STRING, NULL_STRING, NULL_STRING },
63
{ "ldap_krb5_init_creds", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
64
/* use the same parm name as the krb5 module so we set it only once */
65
{ "krb5_realm", DP_OPT_STRING, NULL_STRING, NULL_STRING }
68
struct sdap_attr_map ipa_attr_map[] = {
69
{ "ldap_entry_usn", "entryUSN", SYSDB_USN, NULL },
70
{ "ldap_rootdse_last_usn", "lastUSN", SYSDB_HIGH_USN, NULL }
73
struct sdap_attr_map ipa_user_map[] = {
74
{ "ldap_user_object_class", "posixAccount", SYSDB_USER_CLASS, NULL },
75
{ "ldap_user_name", "uid", SYSDB_NAME, NULL },
76
{ "ldap_user_pwd", "userPassword", SYSDB_PWD, NULL },
77
{ "ldap_user_uid_number", "uidNumber", SYSDB_UIDNUM, NULL },
78
{ "ldap_user_gid_number", "gidNumber", SYSDB_GIDNUM, NULL },
79
{ "ldap_user_gecos", "gecos", SYSDB_GECOS, NULL },
80
{ "ldap_user_home_directory", "homeDirectory", SYSDB_HOMEDIR, NULL },
81
{ "ldap_user_shell", "loginShell", SYSDB_SHELL, NULL },
82
{ "ldap_user_principal", "krbPrincipalName", SYSDB_UPN, NULL },
83
{ "ldap_user_fullname", "cn", SYSDB_FULLNAME, NULL },
84
{ "ldap_user_member_of", "memberOf", SYSDB_MEMBEROF, NULL },
85
{ "ldap_user_uuid", "nsUniqueId", SYSDB_UUID, NULL },
86
{ "ldap_user_modify_timestamp", "modifyTimestamp", SYSDB_ORIG_MODSTAMP, NULL },
87
{ "ldap_user_shadow_last_change", "shadowLastChange", SYSDB_SHADOWPW_LASTCHANGE, NULL },
88
{ "ldap_user_shadow_min", "shadowMin", SYSDB_SHADOWPW_MIN, NULL },
89
{ "ldap_user_shadow_max", "shadowMax", SYSDB_SHADOWPW_MAX, NULL },
90
{ "ldap_user_shadow_warning", "shadowWarning", SYSDB_SHADOWPW_WARNING, NULL },
91
{ "ldap_user_shadow_inactive", "shadowInactive", SYSDB_SHADOWPW_INACTIVE, NULL },
92
{ "ldap_user_shadow_expire", "shadowExpire", SYSDB_SHADOWPW_EXPIRE, NULL },
93
{ "ldap_user_shadow_flag", "shadowFlag", SYSDB_SHADOWPW_FLAG, NULL },
94
{ "ldap_user_krb_last_pwd_change", "krbLastPwdChange", SYSDB_KRBPW_LASTCHANGE, NULL },
95
{ "ldap_user_krb_password_expiration", "krbPasswordExpiration", SYSDB_KRBPW_EXPIRATION, NULL },
96
{ "ldap_pwd_attribute", "pwdAttribute", SYSDB_PWD_ATTRIBUTE, NULL }
99
struct sdap_attr_map ipa_group_map[] = {
100
{ "ldap_group_object_class", "posixGroup", SYSDB_GROUP_CLASS, NULL },
101
{ "ldap_group_name", "cn", SYSDB_NAME, NULL },
102
{ "ldap_group_pwd", "userPassword", SYSDB_PWD, NULL },
103
{ "ldap_group_gid_number", "gidNumber", SYSDB_GIDNUM, NULL },
104
{ "ldap_group_member", "member", SYSDB_MEMBER, NULL },
105
{ "ldap_group_uuid", "nsUniqueId", SYSDB_UUID, NULL },
106
{ "ldap_group_modify_timestamp", "modifyTimestamp", SYSDB_ORIG_MODSTAMP, NULL }
109
struct dp_option ipa_def_krb5_opts[] = {
110
{ "krb5_kdcip", DP_OPT_STRING, NULL_STRING, NULL_STRING },
111
{ "krb5_realm", DP_OPT_STRING, NULL_STRING, NULL_STRING },
112
{ "krb5_ccachedir", DP_OPT_STRING, { "/tmp" }, NULL_STRING },
113
{ "krb5_ccname_template", DP_OPT_STRING, { "FILE:%d/krb5cc_%U_XXXXXX" }, NULL_STRING},
114
{ "krb5_changepw_principal", DP_OPT_STRING, { "kadmin/changepw" }, NULL_STRING },
115
{ "krb5_auth_timeout", DP_OPT_NUMBER, { .number = 15 }, NULL_NUMBER },
116
{ "krb5_keytab", DP_OPT_STRING, { "/etc/krb5.keytab" }, NULL_STRING },
117
{ "krb5_validate", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE }
120
int domain_to_basedn(TALLOC_CTX *memctx, const char *domain, char **basedn)
128
dn = talloc_strdup(memctx, "dc=");
130
while ((p = strchr(s, '.'))) {
132
dn = talloc_asprintf_append_buffer(dn, "%.*s,dc=", l, s);
138
dn = talloc_strdup_append_buffer(dn, s);
147
int ipa_get_options(TALLOC_CTX *memctx,
148
struct confdb_ctx *cdb,
149
const char *conf_path,
150
struct sss_domain_info *dom,
151
struct ipa_options **_opts)
153
struct ipa_options *opts;
158
char hostname[HOST_NAME_MAX + 1];
160
opts = talloc_zero(memctx, struct ipa_options);
161
if (!opts) return ENOMEM;
163
ret = dp_get_options(opts, cdb, conf_path,
171
domain = dp_opt_get_string(opts->basic, IPA_DOMAIN);
173
ret = dp_opt_set_string(opts->basic, IPA_DOMAIN, dom->name);
179
/* FIXME: Make non-fatal once we have discovery */
180
server = dp_opt_get_string(opts->basic, IPA_SERVER);
182
DEBUG(0, ("Can't find ipa server, missing option!\n"));
187
ipa_hostname = dp_opt_get_string(opts->basic, IPA_HOSTNAME);
188
if (ipa_hostname == NULL) {
189
ret = gethostname(hostname, HOST_NAME_MAX);
191
DEBUG(1, ("gethostname failed [%d][%s].\n", errno,
196
hostname[HOST_NAME_MAX] = '\0';
197
DEBUG(9, ("Setting ipa_hostname to [%s].\n", hostname));
198
ret = dp_opt_set_string(opts->basic, IPA_HOSTNAME, hostname);
215
/* the following define is used to keep track of * the options in the ldap
216
* module, so that if they change and ipa is not updated correspondingly
217
* this will trigger a runtime abort error */
218
#define IPA_OPTS_BASIC_TEST 30
220
int ipa_get_id_options(struct ipa_options *ipa_opts,
221
struct confdb_ctx *cdb,
222
const char *conf_path,
223
struct sdap_options **_opts)
233
/* self check test, this should never fail, unless someone forgot
234
* to properly update the code after new ldap options have been added */
235
if (SDAP_OPTS_BASIC != IPA_OPTS_BASIC_TEST) {
236
DEBUG(0, ("Option numbers do not match (%d != %d)\n",
237
SDAP_OPTS_BASIC, IPA_OPTS_BASIC_TEST));
241
tmpctx = talloc_new(ipa_opts);
246
ipa_opts->id = talloc_zero(ipa_opts, struct sdap_options);
252
/* get sdap options */
253
ret = dp_get_options(ipa_opts->id, cdb, conf_path,
256
&ipa_opts->id->basic);
261
if (NULL == dp_opt_get_string(ipa_opts->id->basic, SDAP_SEARCH_BASE)) {
262
ret = domain_to_basedn(tmpctx,
263
dp_opt_get_string(ipa_opts->basic, IPA_DOMAIN),
269
/* FIXME: get values by querying IPA */
270
/* set search base */
271
value = talloc_asprintf(tmpctx, "cn=accounts,%s", basedn);
276
ret = dp_opt_set_string(ipa_opts->id->basic,
277
SDAP_SEARCH_BASE, value);
281
DEBUG(6, ("Option %s set to %s\n",
282
ipa_opts->id->basic[SDAP_SEARCH_BASE].opt_name,
283
dp_opt_get_string(ipa_opts->id->basic, SDAP_SEARCH_BASE)));
286
/* set the ldap_sasl_authid if the ipa_hostname override was specified */
287
if (NULL == dp_opt_get_string(ipa_opts->id->basic, SDAP_SASL_AUTHID)) {
288
hostname = dp_opt_get_string(ipa_opts->basic, IPA_HOSTNAME);
290
value = talloc_asprintf(tmpctx, "host/%s", hostname);
295
ret = dp_opt_set_string(ipa_opts->id->basic,
296
SDAP_SASL_AUTHID, value);
301
DEBUG(6, ("Option %s set to %s\n",
302
ipa_opts->id->basic[SDAP_SASL_AUTHID].opt_name,
303
dp_opt_get_string(ipa_opts->id->basic, SDAP_SASL_AUTHID)));
307
if (NULL == dp_opt_get_string(ipa_opts->id->basic, SDAP_KRB5_REALM)) {
308
realm = dp_opt_get_string(ipa_opts->basic, IPA_DOMAIN);
309
for (i = 0; realm[i]; i++) {
310
realm[i] = toupper(realm[i]);
312
ret = dp_opt_set_string(ipa_opts->id->basic,
313
SDAP_KRB5_REALM, realm);
317
DEBUG(6, ("Option %s set to %s\n",
318
ipa_opts->id->basic[SDAP_KRB5_REALM].opt_name,
319
dp_opt_get_string(ipa_opts->id->basic, SDAP_KRB5_REALM)));
322
/* fix schema to IPAv1 for now */
323
ipa_opts->id->schema_type = SDAP_SCHEMA_IPA_V1;
325
/* set user/group search bases if they are not specified */
326
if (NULL == dp_opt_get_string(ipa_opts->id->basic,
327
SDAP_USER_SEARCH_BASE)) {
328
ret = dp_opt_set_string(ipa_opts->id->basic, SDAP_USER_SEARCH_BASE,
329
dp_opt_get_string(ipa_opts->id->basic,
334
DEBUG(6, ("Option %s set to %s\n",
335
ipa_opts->id->basic[SDAP_USER_SEARCH_BASE].opt_name,
336
dp_opt_get_string(ipa_opts->id->basic,
337
SDAP_USER_SEARCH_BASE)));
340
if (NULL == dp_opt_get_string(ipa_opts->id->basic,
341
SDAP_GROUP_SEARCH_BASE)) {
342
ret = dp_opt_set_string(ipa_opts->id->basic, SDAP_GROUP_SEARCH_BASE,
343
dp_opt_get_string(ipa_opts->id->basic,
348
DEBUG(6, ("Option %s set to %s\n",
349
ipa_opts->id->basic[SDAP_GROUP_SEARCH_BASE].opt_name,
350
dp_opt_get_string(ipa_opts->id->basic,
351
SDAP_GROUP_SEARCH_BASE)));
354
ret = sdap_get_map(ipa_opts->id, cdb, conf_path,
357
&ipa_opts->id->gen_map);
362
ret = sdap_get_map(ipa_opts->id,
366
&ipa_opts->id->user_map);
371
ret = sdap_get_map(ipa_opts->id,
375
&ipa_opts->id->group_map);
381
*_opts = ipa_opts->id;
384
talloc_zfree(tmpctx);
386
talloc_zfree(ipa_opts->id);
391
/* the following define is used to keep track of * the options in the krb5
392
* module, so that if they change and ipa is not updated correspondingly
393
* this will trigger a runtime abort error */
394
#define IPA_KRB5_OPTS_TEST 8
396
int ipa_get_auth_options(struct ipa_options *ipa_opts,
397
struct confdb_ctx *cdb,
398
const char *conf_path,
399
struct dp_option **_opts)
405
/* self check test, this should never fail, unless someone forgot
406
* to properly update the code after new ldap options have been added */
407
if (KRB5_OPTS != IPA_KRB5_OPTS_TEST) {
408
DEBUG(0, ("Option numbers do not match (%d != %d)\n",
409
KRB5_OPTS, IPA_KRB5_OPTS_TEST));
413
ipa_opts->auth = talloc_zero(ipa_opts, struct dp_option);
414
if (ipa_opts->auth == NULL) {
419
/* get krb5 options */
420
ret = dp_get_options(ipa_opts, cdb, conf_path,
422
KRB5_OPTS, &ipa_opts->auth);
428
if (NULL == dp_opt_get_string(ipa_opts->auth, KRB5_REALM)) {
429
value = dp_opt_get_string(ipa_opts->basic, IPA_DOMAIN);
434
for (i = 0; value[i]; i++) {
435
value[i] = toupper(value[i]);
437
ret = dp_opt_set_string(ipa_opts->auth, KRB5_REALM, value);
441
DEBUG(6, ("Option %s set to %s\n",
442
ipa_opts->auth[KRB5_REALM].opt_name,
443
dp_opt_get_string(ipa_opts->auth, KRB5_REALM)));
446
*_opts = ipa_opts->auth;
451
talloc_zfree(ipa_opts->auth);
456
static void ipa_resolve_callback(void *private_data, struct fo_server *server)
458
struct ipa_service *service;
459
struct hostent *srvaddr;
464
service = talloc_get_type(private_data, struct ipa_service);
466
DEBUG(1, ("FATAL: Bad private_data\n"));
470
srvaddr = fo_get_server_hostent(server);
472
DEBUG(1, ("FATAL: No hostent available for server (%s)\n",
473
fo_get_server_name(server)));
477
address = talloc_asprintf(service, srvaddr->h_name);
479
DEBUG(1, ("Failed to copy address ...\n"));
483
new_uri = talloc_asprintf(service, "ldap://%s", address);
485
DEBUG(2, ("Failed to copy URI ...\n"));
486
talloc_free(address);
490
/* free old one and replace with new one */
491
talloc_zfree(service->sdap->uri);
492
service->sdap->uri = new_uri;
493
talloc_zfree(service->krb5_service->address);
494
service->krb5_service->address = address;
496
ret = write_kdcinfo_file(service->krb5_service->realm, address);
498
DEBUG(2, ("write_kdcinfo_file failed, authentication might fail.\n"));
503
int ipa_service_init(TALLOC_CTX *memctx, struct be_ctx *ctx,
504
const char *servers, const char *domain,
505
struct ipa_service **_service)
508
struct ipa_service *service;
514
tmp_ctx = talloc_new(memctx);
519
service = talloc_zero(tmp_ctx, struct ipa_service);
524
service->sdap = talloc_zero(service, struct sdap_service);
525
if (!service->sdap) {
529
service->krb5_service = talloc_zero(service, struct krb5_service);
530
if (!service->krb5_service) {
535
ret = be_fo_add_service(ctx, "IPA");
537
DEBUG(1, ("Failed to create failover service!\n"));
541
service->sdap->name = talloc_strdup(service, "IPA");
542
if (!service->sdap->name) {
547
service->krb5_service->name = talloc_strdup(service, "IPA");
548
if (!service->krb5_service->name) {
553
realm = talloc_strdup(service, domain);
558
for (i = 0; realm[i]; i++) {
559
realm[i] = toupper(realm[i]);
561
service->krb5_service->realm = realm;
563
/* split server parm into a list */
564
ret = split_on_separator(tmp_ctx, servers, ',', true, &list, NULL);
566
DEBUG(1, ("Failed to parse server list!\n"));
570
/* now for each one add a new server to the failover service */
571
for (i = 0; list[i]; i++) {
573
talloc_steal(service, list[i]);
575
ret = be_fo_add_server(ctx, "IPA", list[i], 0, NULL);
576
if (ret && ret != EEXIST) {
577
DEBUG(0, ("Failed to add server\n"));
581
DEBUG(6, ("Added Server %s\n", list[i]));
584
ret = be_fo_service_add_callback(memctx, ctx, "IPA",
585
ipa_resolve_callback, service);
587
DEBUG(1, ("Failed to add failover callback!\n"));
595
*_service = talloc_steal(memctx, service);
597
talloc_zfree(tmp_ctx);