confdb.c revision c14184c07634801cda7864aa17c6fa8dc9ab43d1
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive NSS Configuratoin DB
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is free software; you can redistribute it and/or modify
fe64b2ba25510d8c9dba5560a2d537763566cf40nd it under the terms of the GNU General Public License as published by
fe64b2ba25510d8c9dba5560a2d537763566cf40nd the Free Software Foundation; either version 3 of the License, or
fe64b2ba25510d8c9dba5560a2d537763566cf40nd (at your option) any later version.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is distributed in the hope that it will be useful,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd but WITHOUT ANY WARRANTY; without even the implied warranty of
fe64b2ba25510d8c9dba5560a2d537763566cf40nd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz GNU General Public License for more details.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd You should have received a copy of the GNU General Public License
fe64b2ba25510d8c9dba5560a2d537763566cf40nd along with this program. If not, see <http://www.gnu.org/licenses/>.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#define CONFDB_ZERO_CHECK_OR_JUMP(var, ret, err, label) do { \
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic char *prepend_cn(char *str, int *slen, const char *comp, int clen)
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = talloc_realloc(NULL, str, char, *slen + 4 + clen + 1);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* move current string to the end */
9597f440430d8c876dd64f5f78066804650a18ecnoodl memmove(&ret[clen +4], ret, *slen+1); /* includes termination */
117c1f888a14e73cdd821dc6c23eb0411144a41cndint parse_section(TALLOC_CTX *mem_ctx, const char *section,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char *s;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl /* section must be a non null string and must not start with '/' */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (!section || !*section || *section == '/') return EINVAL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (l == 0) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd l = 3 + (p-s);
6beba165aeced2ca77a6f1593ee08c47a32099efcovener if (*p == '\0') {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd break; /* reached end */
b00fe3c3354db01001b8eddfd9b88441380f837dwrowe const char *section,
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin const char *attribute,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char **values)
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna const char *rdn_name;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = parse_section(tmp_ctx, section, &secdn, &rdn_name);
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener CONFDB_ZERO_CHECK_OR_JUMP(msg->dn, ret, ENOMEM, done);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna /* cn first */
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna /* now the requested attribute */
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna for (i = 0; values[i]; i++) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ldb_msg_add_string(msg, attribute, values[i]);
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe /* mark this as a replacement */
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = ldb_msg_add_empty(msg, attribute, optype, NULL);
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe /* now the requested attribute */
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe for (i = 0; values[i]; i++) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Failed to add [%s] to [%s], error [%d] (%s)\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *section,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *attribute,
130d299c4b2b15be45532a176604c71fdc7bea5bnd vals = talloc_realloc(mem_ctx, vals, char *, el->num_values +1);
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* should always be strings so this should be safe */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd vals[i] = talloc_strndup(vals, (char *)v.data, v.length);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!vals[i]) {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess DEBUG(1, ("Failed to get [%s] from [%s], error [%d] (%s)\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *section,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *attribute,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd lret = ldb_msg_add_empty(msg, attribute, LDB_FLAG_MOD_REPLACE, NULL);
b95ae799514ad86a15610ad75808d7065e9847c9kess ("ldb_msg_add_empty failed: [%s]\n", ldb_strerror(lret)));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ("ldb_msg_add_string failed: [%s]\n", ldb_strerror(lret)));
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ("Failed to set [%s] from [%s], error [%d] (%s)\n",
4335f1cbf345c91bb996eec540c11ba8ce5d4268ndint confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx,
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = confdb_get_param(cdb, ctx, section, attribute, &values);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier /* too many values */
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd /* Did not return a value, so use the default */
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd /* Copy the default string */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Failed to get [%s] from [%s], error [%d] (%s)\n",
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* too many values */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n",
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values);
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener /* too many values */
7802d43d20007fa575e43b6ae77d5177ceffdb71sf DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n",
bed3c2e56e8f3328e780200466b9d009093db468sf ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values);
bed3c2e56e8f3328e780200466b9d009093db468sf /* too many values */
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd/* WARNING: Unlike other similar functions, this one does NOT take a default,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * and returns ENOENT if the attribute was not found ! */
fe64b2ba25510d8c9dba5560a2d537763566cf40ndint confdb_get_string_as_list(struct confdb_ctx *cdb, TALLOC_CTX *ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = confdb_get_param(cdb, ctx, section, attribute, &values);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* too many values */
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Did not return a value */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = split_on_separator(ctx, values[0], ',', true, true, result, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(2, ("Failed to get [%s] from [%s], error [%d] (%s)\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Because confdb calls use sync ldb calls, we create a separate event
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * context here. This will prevent the ldb sync calls to start nested
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * NOTE: this means that we *cannot* do async calls and return in confdb
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * unless we convert all calls and hook back to the main event context.
604c89126c27104f659d7a51b0113e3bd435faf8fieldingstatic errno_t get_entry_as_uint32(struct ldb_message *msg,
604c89126c27104f659d7a51b0113e3bd435faf8fielding const char *entry,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf /* Not all of the string was a valid number */
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf const char *entry,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd/* The default UID/GID for domains is 1. This wouldn't work well with
130d299c4b2b15be45532a176604c71fdc7bea5bnd * the local provider */
130d299c4b2b15be45532a176604c71fdc7bea5bndstatic uint32_t confdb_get_min_id(struct sss_domain_info *domain)
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (domain && strcasecmp(domain->provider, "local") == 0) {
fb77c505254b6e9c925e23e734463e87574f8f40kessstatic int confdb_get_domain_internal(struct confdb_ctx *cdb,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *name,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *tmp;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive domain = talloc_zero(mem_ctx, struct sss_domain_info);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(res->msgs[0], "cn", NULL);
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess DEBUG(0, ("Invalid configuration entry, fatal error!\n"));
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess DEBUG(0, ("Domain [%s] does not specify an ID provider, disabling!\n",
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen /* The files provider is not valid anymore */
4e10c61d7f924071cad435df940a8f325015b2d3rbowen /* If this is the local provider, we need to ensure that
130d299c4b2b15be45532a176604c71fdc7bea5bnd * no other provider was specified for other types, since
130d299c4b2b15be45532a176604c71fdc7bea5bnd * the local provider cannot load them.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(0, ("Local ID provider does not support [%s] as an AUTH provider.\n", tmp));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(0, ("Local ID provider does not support [%s] as an ACCESS provider.\n", tmp));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(0, ("Local ID provider does not support [%s] as a CHPASS provider.\n", tmp));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* The LOCAL provider use always Magic Private Groups */
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor domain->timeout = ldb_msg_find_attr_as_int(res->msgs[0],
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Determine if this domain can be enumerated */
6954edc623ca2c179eb5b33e97e4304d06fd649frbowen /* TEMP: test if the old bitfield conf value is used and warn it has been
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * superceeded. */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive val = ldb_msg_find_attr_as_int(res->msgs[0], CONFDB_DOMAIN_ENUMERATE, 0);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(0, ("Warning: enumeration parameter in %s still uses integers! "
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Enumeration is now a boolean and takes true/false values. "
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener } else { /* assume the new format */
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener ret = get_entry_as_bool(res->msgs[0], &domain->enumerate,
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener DEBUG(0, ("Invalid value for %s\n", CONFDB_DOMAIN_ENUMERATE));
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener DEBUG(SSSDBG_TRACE_FUNC, ("No enumeration for [%s]!\n", domain->name));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Determine if user/group names will be Fully Qualified
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * in NSS interfaces */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_bool(res->msgs[0], &domain->fqnames, CONFDB_DOMAIN_FQ, 0);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess DEBUG(0, ("Invalid value for %s\n", CONFDB_DOMAIN_FQ));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_bool(res->msgs[0], &domain->ignore_group_members,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ("Invalid value for %s\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (domain->id_max && (domain->id_max < domain->id_min)) {
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen /* Do we allow to cache credentials */
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen ret = get_entry_as_bool(res->msgs[0], &domain->cache_credentials,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(0, ("Invalid value for %s\n", CONFDB_DOMAIN_CACHE_CREDS));
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_bool(res->msgs[0], &domain->legacy_passwords,
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(0, ("Invalid value for %s\n", CONFDB_DOMAIN_LEGACY_PASS));
8559a67073808d84d85bb5dd552d4247caafe709sf /* Get the global entry cache timeout setting */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &entry_cache_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the user cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->user_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the group cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->group_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the netgroup cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->netgroup_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the service cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->service_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the autofs cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->autofsmap_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the sudo cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->sudo_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf /* Set the PAM warning time, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf if (val > 0) {
8559a67073808d84d85bb5dd552d4247caafe709sf /* The value is in days, transform it to seconds */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Failed to read PAM expiration warning, not fatal.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_uint32(res->msgs[0], &domain->override_gid,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(0, ("Invalid value for [%s]\n", CONFDB_DOMAIN_OVERRIDE_GID));
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier domain->fallback_homedir = talloc_strdup(domain, tmp);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh domain->subdomain_homedir = talloc_strdup(domain, tmp);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = get_entry_as_bool(res->msgs[0], &domain->case_sensitive,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh DEBUG(0, ("Invalid value for %s\n", CONFDB_DOMAIN_CASE_SENSITIVE));
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ("Local ID provider does not support the case insensitive flag\n"));
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick for (i = 0; domlist[i]; i++) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = confdb_get_domain_internal(cdb, cdb, domlist[i], &domain);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick DEBUG(0, ("Error (%d [%s]) retrieving domain [%s], skipping!\n",
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick DEBUG(0, ("No properly configured domains, fatal error!\n"));
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick const char *name,