confdb.c revision ff22e829fd73fc53027d1e6ca005a9ac334086dd
97a9a944b5887e91042b019776c41d5dd74557aferikabele/*
97a9a944b5887e91042b019776c41d5dd74557aferikabele SSSD
97a9a944b5887e91042b019776c41d5dd74557aferikabele
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive NSS Configuratoin DB
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
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
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
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/>.
4b5981e276e93df97c34e4da05ca5cf8bbd937dand*/
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd#include "config.h"
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd#include <ctype.h>
4aa805f8500255bc52a4c03259fe46df10a1d07cyoshiki#include "util/util.h"
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen#include "confdb/confdb.h"
dfb59c684345700bf9186b8d44936f8b1ba082ffgryzor#include "confdb/confdb_private.h"
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi#include "util/strtonum.h"
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi#include "db/sysdb.h"
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#define CONFDB_ZERO_CHECK_OR_JUMP(var, ret, err, label) do { \
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!var) { \
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = err; \
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto label; \
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } \
fe64b2ba25510d8c9dba5560a2d537763566cf40nd} while(0)
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
fe64b2ba25510d8c9dba5560a2d537763566cf40nd/* Warning messages */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define SAME_DOMAINS_ERROR_MSG "Domain '%s' is the same as or differs only "\
117c1f888a14e73cdd821dc6c23eb0411144a41cnd "in case from domain '%s'.\n"
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
117c1f888a14e73cdd821dc6c23eb0411144a41cndstatic char *prepend_cn(char *str, int *slen, const char *comp, int clen)
bed3c2e56e8f3328e780200466b9d009093db468sf{
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *ret;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = talloc_realloc(NULL, str, char, *slen + 4 + clen + 1);
9597f440430d8c876dd64f5f78066804650a18ecnoodl if (!ret)
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return NULL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* move current string to the end */
8559a67073808d84d85bb5dd552d4247caafe709sf memmove(&ret[clen +4], ret, *slen+1); /* includes termination */
8559a67073808d84d85bb5dd552d4247caafe709sf memcpy(ret, "cn=", 3);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd memcpy(&ret[3], comp, clen);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret[clen+3] = ',';
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
117c1f888a14e73cdd821dc6c23eb0411144a41cnd *slen = *slen + 4 + clen;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf return ret;
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin}
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndint parse_section(TALLOC_CTX *mem_ctx, const char *section,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char **sec_dn, const char **rdn_name)
117c1f888a14e73cdd821dc6c23eb0411144a41cnd{
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener TALLOC_CTX *tmp_ctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *dn = NULL;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl char *p;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char *s;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd int l, ret;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* section must be a non null string and must not start with '/' */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (!section || !*section || *section == '/') return EINVAL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd tmp_ctx = talloc_new(mem_ctx);
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd if (!tmp_ctx) return ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd s = section;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd l = 0;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd while ((p = strchrnul(s, '/'))) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (l == 0) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd dn = talloc_asprintf(tmp_ctx, "cn=%s", s);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd l = 3 + (p-s);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd dn[l] = '\0';
117c1f888a14e73cdd821dc6c23eb0411144a41cnd } else {
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim dn = prepend_cn(dn, &l, s, p-s);
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim }
6beba165aeced2ca77a6f1593ee08c47a32099efcovener if (!dn) {
709e3a21ba73b8433462959cd56c773454b34441trawick ret = ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen if (*p == '\0') {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (rdn_name) *rdn_name = s;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd break; /* reached end */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd s = p+1;
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin if (*s == '\0') { /* a section cannot end in '.' */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = EINVAL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd *sec_dn = talloc_steal(mem_ctx, dn);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = EOK;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnddone:
117c1f888a14e73cdd821dc6c23eb0411144a41cnd talloc_free(tmp_ctx);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return ret;
b00fe3c3354db01001b8eddfd9b88441380f837dwrowe}
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
117c1f888a14e73cdd821dc6c23eb0411144a41cndint confdb_add_param(struct confdb_ctx *cdb,
a38b5f73e7f0f3b8726fb47d27b145f37036ead0jim bool replace,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char *section,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *attribute,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char **values)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna TALLOC_CTX *tmp_ctx = NULL;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna struct ldb_message *msg;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna struct ldb_result *res;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna struct ldb_dn *dn;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna char *secdn;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna const char *rdn_name;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna int ret, i;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen tmp_ctx = talloc_new(NULL);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen if (!tmp_ctx) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ENOMEM;
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen goto done;
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen }
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen ret = parse_section(tmp_ctx, section, &secdn, &rdn_name);
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen if (ret != EOK) {
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor goto done;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe }
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe dn = ldb_dn_new(tmp_ctx, cdb->ldb, secdn);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor CONFDB_ZERO_CHECK_OR_JUMP(dn, ret, EIO, done);
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = ldb_search(cdb->ldb, tmp_ctx, &res,
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe dn, LDB_SCOPE_BASE, NULL, NULL);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (ret != LDB_SUCCESS) {
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener ret = EIO;
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener goto done;
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener }
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener msg = ldb_msg_new(tmp_ctx);
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener CONFDB_ZERO_CHECK_OR_JUMP(msg, ret, ENOMEM, done);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna msg->dn = talloc_steal(msg, dn);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna CONFDB_ZERO_CHECK_OR_JUMP(msg->dn, ret, ENOMEM, done);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (res->count == 0) { /* add a new message */
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor errno = 0;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor /* cn first */
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = ldb_msg_add_string(msg, "cn", rdn_name);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (ret != LDB_SUCCESS) {
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor if (errno) ret = errno;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna else ret = EIO;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna goto done;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna /* now the requested attribute */
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna for (i = 0; values[i]; i++) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ldb_msg_add_string(msg, attribute, values[i]);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (ret != LDB_SUCCESS) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (errno) ret = errno;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna else ret = EIO;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor goto done;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ldb_add(cdb->ldb, msg);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (ret != LDB_SUCCESS) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = EIO;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe goto done;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe }
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe } else {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe int optype;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe errno = 0;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe /* mark this as a replacement */
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe if (replace) optype = LDB_FLAG_MOD_REPLACE;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe else optype = LDB_FLAG_MOD_ADD;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = ldb_msg_add_empty(msg, attribute, optype, NULL);
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe if (ret != LDB_SUCCESS) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe if (errno) ret = errno;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe else ret = EIO;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe goto done;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe }
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe /* now the requested attribute */
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe for (i = 0; values[i]; i++) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = ldb_msg_add_string(msg, attribute, values[i]);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor if (ret != LDB_SUCCESS) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (errno) ret = errno;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna else ret = EIO;
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen goto done;
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen }
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen }
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ldb_modify(cdb->ldb, msg);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != LDB_SUCCESS) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EIO;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(tmp_ctx);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_CRIT_FAILURE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "Failed to add [%s] to [%s], error [%d] (%s)\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive attribute, section, ret, strerror(ret));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kessint confdb_get_param(struct confdb_ctx *cdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TALLOC_CTX *mem_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *section,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *attribute,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char ***values)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TALLOC_CTX *tmp_ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ldb_result *res;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct ldb_dn *dn;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char *secdn;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *attrs[] = { attribute, NULL };
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char **vals;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ldb_message_element *el;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret, i;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp_ctx = talloc_new(mem_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!tmp_ctx)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOMEM;
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = parse_section(tmp_ctx, section, &secdn, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dn = ldb_dn_new(tmp_ctx, cdb->ldb, secdn);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (!dn) {
bc4b55ec8f31569d606d5680d50189a355bcd7a6rbowen ret = EIO;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ldb_search(cdb->ldb, tmp_ctx, &res,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dn, LDB_SCOPE_BASE, attrs, NULL);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != LDB_SUCCESS) {
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = EIO;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess if (res->count > 1) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EIO;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd vals = talloc_zero(mem_ctx, char *);
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = EOK;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
ef8e89e090461194ecadd31e8796a2c51e0531a2kess if (res->count > 0) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd el = ldb_msg_find_element(res->msgs[0], attribute);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (el && el->num_values > 0) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd vals = talloc_realloc(mem_ctx, vals, char *, el->num_values +1);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (!vals) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* should always be strings so this should be safe */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd for (i = 0; i < el->num_values; i++) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_val v = el->values[i];
fe64b2ba25510d8c9dba5560a2d537763566cf40nd vals[i] = talloc_strndup(vals, (char *)v.data, v.length);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!vals[i]) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess vals[i] = NULL;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive }
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess *values = vals;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnddone:
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_free(tmp_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_CRIT_FAILURE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "Failed to get [%s] from [%s], error [%d] (%s)\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive attribute, section, ret, strerror(ret));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
130d299c4b2b15be45532a176604c71fdc7bea5bndint confdb_set_bool(struct confdb_ctx *cdb,
130d299c4b2b15be45532a176604c71fdc7bea5bnd const char *section,
130d299c4b2b15be45532a176604c71fdc7bea5bnd const char *attribute,
130d299c4b2b15be45532a176604c71fdc7bea5bnd bool val)
130d299c4b2b15be45532a176604c71fdc7bea5bnd{
130d299c4b2b15be45532a176604c71fdc7bea5bnd TALLOC_CTX *tmp_ctx;
130d299c4b2b15be45532a176604c71fdc7bea5bnd struct ldb_dn *dn;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *secdn;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_message *msg;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret, lret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp_ctx = talloc_new(NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!tmp_ctx)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = parse_section(tmp_ctx, section, &secdn, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
627c978514c54179736d152923478be7c8707f9bnd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd dn = ldb_dn_new(tmp_ctx, cdb->ldb, secdn);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!dn) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EIO;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd msg = ldb_msg_new(tmp_ctx);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (!msg) {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = ENOMEM;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd goto done;
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd }
b95ae799514ad86a15610ad75808d7065e9847c9kess
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd msg->dn = dn;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd lret = ldb_msg_add_empty(msg, attribute, LDB_FLAG_MOD_REPLACE, NULL);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (lret != LDB_SUCCESS) {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd DEBUG(SSSDBG_MINOR_FAILURE,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd "ldb_msg_add_empty failed: [%s]\n", ldb_strerror(lret));
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = EIO;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (val) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd lret = ldb_msg_add_string(msg, attribute, "True");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd lret = ldb_msg_add_string(msg, attribute, "False");
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (lret != LDB_SUCCESS) {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd DEBUG(SSSDBG_MINOR_FAILURE,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd "ldb_msg_add_string failed: [%s]\n", ldb_strerror(lret));
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = EIO;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd goto done;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd lret = ldb_modify(cdb->ldb, msg);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (lret != LDB_SUCCESS) {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd DEBUG(SSSDBG_MINOR_FAILURE,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd "ldb_modify failed: [%s]\n", ldb_strerror(lret));
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = EIO;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = EOK;
9583adab6bc4b3758e41963c905d9dad9f067131nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nddone:
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier talloc_free(tmp_ctx);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (ret != EOK) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd DEBUG(SSSDBG_CRIT_FAILURE,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd "Failed to set [%s] from [%s], error [%d] (%s)\n",
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd attribute, section, ret, strerror(ret));
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier }
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier return ret;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd}
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268ndint confdb_set_string(struct confdb_ctx *cdb,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd const char *section,
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier const char *attribute,
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier char *val)
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier{
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier TALLOC_CTX *tmp_ctx;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier struct ldb_dn *dn;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier char *secdn;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier struct ldb_message *msg;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier int ret, lret;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier tmp_ctx = talloc_new(NULL);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (!tmp_ctx) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd return ENOMEM;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = parse_section(tmp_ctx, section, &secdn, NULL);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier if (ret != EOK) {
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier goto done;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd dn = ldb_dn_new(tmp_ctx, cdb->ldb, secdn);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (!dn) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = EIO;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd goto done;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd msg = ldb_msg_new(tmp_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!msg) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
627c978514c54179736d152923478be7c8707f9bnd }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd msg->dn = dn;
6f7c18e70781deff3d1129774221de81b43c828end
fe64b2ba25510d8c9dba5560a2d537763566cf40nd lret = ldb_msg_add_empty(msg, attribute, LDB_FLAG_MOD_REPLACE, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (lret != LDB_SUCCESS) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_MINOR_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "ldb_msg_add_empty failed: [%s]\n", ldb_strerror(lret));
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = EIO;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive lret = ldb_msg_add_string(msg, attribute, val);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (lret != LDB_SUCCESS) {
10673857794a4b3d9568ca2d983722a87ed352f1rbowen DEBUG(SSSDBG_MINOR_FAILURE,
fb77c505254b6e9c925e23e734463e87574f8f40kess "ldb_msg_add_string failed: [%s]\n", ldb_strerror(lret));
ed0dae472b518c553c923a86fb4322d4c50d86a6nd ret = EIO;
ed0dae472b518c553c923a86fb4322d4c50d86a6nd goto done;
10673857794a4b3d9568ca2d983722a87ed352f1rbowen }
10673857794a4b3d9568ca2d983722a87ed352f1rbowen
bed3c2e56e8f3328e780200466b9d009093db468sf lret = ldb_modify(cdb->ldb, msg);
bed3c2e56e8f3328e780200466b9d009093db468sf if (lret != LDB_SUCCESS) {
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_MINOR_FAILURE,
bed3c2e56e8f3328e780200466b9d009093db468sf "ldb_modify failed: [%s]\n", ldb_strerror(lret));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EIO;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EOK;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedone:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(tmp_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_CRIT_FAILURE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "Failed to set [%s] from [%s], error [%d] (%s)\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive attribute, section, ret, strerror(ret));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz return ret;
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz}
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end
9335f6d807d76d60e54af4ededdebebddb3e3d13noodlint confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx,
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl const char *section, const char *attribute,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *defstr, char **result)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char **values = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char *restr;
604c89126c27104f659d7a51b0113e3bd435faf8fielding int ret;
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = confdb_get_param(cdb, ctx, section, attribute, &values);
604c89126c27104f659d7a51b0113e3bd435faf8fielding if (ret != EOK) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding goto failed;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding if (values[0]) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding if (values[1] != NULL) {
909ce17e2bd0faef7b1c294f2307f009793fd493nd /* too many values */
909ce17e2bd0faef7b1c294f2307f009793fd493nd ret = EINVAL;
909ce17e2bd0faef7b1c294f2307f009793fd493nd goto failed;
909ce17e2bd0faef7b1c294f2307f009793fd493nd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive restr = talloc_steal(ctx, values[0]);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Did not return a value, so use the default */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (defstr == NULL) { /* No default given */
97a9a944b5887e91042b019776c41d5dd74557aferikabele *result = NULL;
97a9a944b5887e91042b019776c41d5dd74557aferikabele talloc_free(values);
97a9a944b5887e91042b019776c41d5dd74557aferikabele return EOK;
97a9a944b5887e91042b019776c41d5dd74557aferikabele }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Copy the default string */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive restr = talloc_strdup(ctx, defstr);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!restr) {
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto failed;
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(values);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele *result = restr;
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak return EOK;
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covenerfailed:
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener talloc_free(values);
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener DEBUG(SSSDBG_CRIT_FAILURE,
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim "Failed to get [%s] from [%s], error [%d] (%s)\n",
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener attribute, section, ret, strerror(ret));
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener return ret;
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener}
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covenerint confdb_get_int(struct confdb_ctx *cdb,
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener const char *section, const char *attribute,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int defval, int *result)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char **values = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive long val;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd TALLOC_CTX *tmp_ctx;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp_ctx = talloc_new(NULL);
ed0dae472b518c553c923a86fb4322d4c50d86a6nd if (tmp_ctx == NULL) {
ed0dae472b518c553c923a86fb4322d4c50d86a6nd ret = ENOMEM;
ed0dae472b518c553c923a86fb4322d4c50d86a6nd goto failed;
ed0dae472b518c553c923a86fb4322d4c50d86a6nd }
da637bcae7b6e150470e701af29da5604a34a17erbowen
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values);
da637bcae7b6e150470e701af29da5604a34a17erbowen if (ret != EOK) {
da637bcae7b6e150470e701af29da5604a34a17erbowen goto failed;
da637bcae7b6e150470e701af29da5604a34a17erbowen }
da637bcae7b6e150470e701af29da5604a34a17erbowen
da637bcae7b6e150470e701af29da5604a34a17erbowen if (values[0]) {
da637bcae7b6e150470e701af29da5604a34a17erbowen if (values[1] != NULL) {
7802d43d20007fa575e43b6ae77d5177ceffdb71sf /* too many values */
7802d43d20007fa575e43b6ae77d5177ceffdb71sf ret = EINVAL;
7802d43d20007fa575e43b6ae77d5177ceffdb71sf goto failed;
7802d43d20007fa575e43b6ae77d5177ceffdb71sf }
7802d43d20007fa575e43b6ae77d5177ceffdb71sf
7802d43d20007fa575e43b6ae77d5177ceffdb71sf errno = 0;
7802d43d20007fa575e43b6ae77d5177ceffdb71sf val = strtol(values[0], NULL, 0);
bed3c2e56e8f3328e780200466b9d009093db468sf if (errno) {
bed3c2e56e8f3328e780200466b9d009093db468sf ret = errno;
bed3c2e56e8f3328e780200466b9d009093db468sf goto failed;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf if (val < INT_MIN || val > INT_MAX) {
bed3c2e56e8f3328e780200466b9d009093db468sf ret = ERANGE;
bed3c2e56e8f3328e780200466b9d009093db468sf goto failed;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf } else {
bed3c2e56e8f3328e780200466b9d009093db468sf val = defval;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf talloc_free(tmp_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf *result = (int)val;
bed3c2e56e8f3328e780200466b9d009093db468sf return EOK;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sffailed:
bed3c2e56e8f3328e780200466b9d009093db468sf talloc_free(tmp_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_CRIT_FAILURE,
bed3c2e56e8f3328e780200466b9d009093db468sf "Failed to read [%s] from [%s], error [%d] (%s)\n",
bed3c2e56e8f3328e780200466b9d009093db468sf attribute, section, ret, strerror(ret));
bed3c2e56e8f3328e780200466b9d009093db468sf return ret;
bed3c2e56e8f3328e780200466b9d009093db468sf}
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sflong confdb_get_long(struct confdb_ctx *cdb,
bed3c2e56e8f3328e780200466b9d009093db468sf const char *section, const char *attribute,
bed3c2e56e8f3328e780200466b9d009093db468sf long defval, long *result)
bed3c2e56e8f3328e780200466b9d009093db468sf{
bed3c2e56e8f3328e780200466b9d009093db468sf char **values = NULL;
bed3c2e56e8f3328e780200466b9d009093db468sf long val;
bed3c2e56e8f3328e780200466b9d009093db468sf int ret;
bed3c2e56e8f3328e780200466b9d009093db468sf TALLOC_CTX *tmp_ctx;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf tmp_ctx = talloc_new(NULL);
bed3c2e56e8f3328e780200466b9d009093db468sf if (tmp_ctx == NULL) {
bed3c2e56e8f3328e780200466b9d009093db468sf ret = ENOMEM;
bed3c2e56e8f3328e780200466b9d009093db468sf goto failed;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values);
bed3c2e56e8f3328e780200466b9d009093db468sf if (ret != EOK) {
bed3c2e56e8f3328e780200466b9d009093db468sf goto failed;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf if (values[0]) {
bed3c2e56e8f3328e780200466b9d009093db468sf if (values[1] != NULL) {
bed3c2e56e8f3328e780200466b9d009093db468sf /* too many values */
bed3c2e56e8f3328e780200466b9d009093db468sf ret = EINVAL;
bed3c2e56e8f3328e780200466b9d009093db468sf goto failed;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
fe64b2ba25510d8c9dba5560a2d537763566cf40nd errno = 0;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd val = strtol(values[0], NULL, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (errno) {
bed3c2e56e8f3328e780200466b9d009093db468sf ret = errno;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto failed;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd val = defval;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fb77c505254b6e9c925e23e734463e87574f8f40kess talloc_free(tmp_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fb77c505254b6e9c925e23e734463e87574f8f40kess *result = val;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndfailed:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(tmp_ctx);
c985aca104389df30d6ec0a637ce0ccaac904362nd DEBUG(SSSDBG_CRIT_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Failed to read [%s] from [%s], error [%d] (%s)\n",
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen attribute, section, ret, strerror(ret));
fb77c505254b6e9c925e23e734463e87574f8f40kess return ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess}
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkessint confdb_get_bool(struct confdb_ctx *cdb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *section, const char *attribute,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd bool defval, bool *result)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char **values = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd bool val;
627c978514c54179736d152923478be7c8707f9bnd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TALLOC_CTX *tmp_ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess tmp_ctx = talloc_new(NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (tmp_ctx == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto failed;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
5bb5fba250bf526bc51d13b25378d54acb93c1cbnoodl goto failed;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (values[0]) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (values[1] != NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* too many values */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto failed;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (strcasecmp(values[0], "FALSE") == 0) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd val = false;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd } else if (strcasecmp(values[0], "TRUE") == 0) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd val = true;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, "Value is not a boolean!\n");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto failed;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd val = defval;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(tmp_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
604c89126c27104f659d7a51b0113e3bd435faf8fielding *result = val;
604c89126c27104f659d7a51b0113e3bd435faf8fielding return EOK;
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fieldingfailed:
604c89126c27104f659d7a51b0113e3bd435faf8fielding talloc_free(tmp_ctx);
604c89126c27104f659d7a51b0113e3bd435faf8fielding DEBUG(SSSDBG_CRIT_FAILURE,
604c89126c27104f659d7a51b0113e3bd435faf8fielding "Failed to read [%s] from [%s], error [%d] (%s)\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd attribute, section, ret, strerror(ret));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen/* WARNING: Unlike other similar functions, this one does NOT take a default,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * and returns ENOENT if the attribute was not found ! */
604c89126c27104f659d7a51b0113e3bd435faf8fieldingint confdb_get_string_as_list(struct confdb_ctx *cdb, TALLOC_CTX *ctx,
604c89126c27104f659d7a51b0113e3bd435faf8fielding const char *section, const char *attribute,
604c89126c27104f659d7a51b0113e3bd435faf8fielding char ***result)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
22265f1724519886e2a2b5e0ebd61477506b7379noodl char **values = NULL;
22265f1724519886e2a2b5e0ebd61477506b7379noodl int ret;
22265f1724519886e2a2b5e0ebd61477506b7379noodl
22265f1724519886e2a2b5e0ebd61477506b7379noodl ret = confdb_get_param(cdb, ctx, section, attribute, &values);
604c89126c27104f659d7a51b0113e3bd435faf8fielding if (ret != EOK) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding goto done;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding if (values && values[0]) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding if (values[1] != NULL) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding /* too many values */
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = EINVAL;
604c89126c27104f659d7a51b0113e3bd435faf8fielding goto done;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
9597f440430d8c876dd64f5f78066804650a18ecnoodl /* Did not return a value */
9597f440430d8c876dd64f5f78066804650a18ecnoodl ret = ENOENT;
9597f440430d8c876dd64f5f78066804650a18ecnoodl goto done;
9597f440430d8c876dd64f5f78066804650a18ecnoodl }
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf ret = split_on_separator(ctx, values[0], ',', true, true, result, NULL);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
9597f440430d8c876dd64f5f78066804650a18ecnoodldone:
9597f440430d8c876dd64f5f78066804650a18ecnoodl talloc_free(values);
9597f440430d8c876dd64f5f78066804650a18ecnoodl if (ret != EOK && ret != ENOENT) {
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf DEBUG(SSSDBG_OP_FAILURE,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf "Failed to get [%s] from [%s], error [%d] (%s)\n",
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf attribute, section, ret, strerror(ret));
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf }
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf return ret;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf}
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsfint confdb_init(TALLOC_CTX *mem_ctx,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf struct confdb_ctx **cdb_ctx,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf const char *confdb_location)
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf{
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf struct confdb_ctx *cdb;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf int ret = EOK;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf mode_t old_umask;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf cdb = talloc_zero(mem_ctx, struct confdb_ctx);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf if (!cdb)
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf return ENOMEM;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf /* Because confdb calls use sync ldb calls, we create a separate event
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf * context here. This will prevent the ldb sync calls to start nested
9597f440430d8c876dd64f5f78066804650a18ecnoodl * events.
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf * NOTE: this means that we *cannot* do async calls and return in confdb
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf * unless we convert all calls and hook back to the main event context.
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd cdb->pev = tevent_context_init(cdb);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!cdb->pev) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(cdb);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EIO;
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd cdb->ldb = ldb_init(cdb, cdb->pev);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!cdb->ldb) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(cdb);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EIO;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ldb_set_debug(cdb->ldb, ldb_debug_messages, NULL);
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen if (ret != LDB_SUCCESS) {
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor DEBUG(SSSDBG_FATAL_FAILURE,"Could not set up debug fn.\n");
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen talloc_free(cdb);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return EIO;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess old_umask = umask(0177);
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = ldb_connect(cdb->ldb, confdb_location, 0, NULL);
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive umask(old_umask);
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive if (ret != LDB_SUCCESS) {
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive DEBUG(SSSDBG_FATAL_FAILURE, "Unable to open config database [%s]\n",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd confdb_location);
130d299c4b2b15be45532a176604c71fdc7bea5bnd talloc_free(cdb);
130d299c4b2b15be45532a176604c71fdc7bea5bnd return EIO;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd *cdb_ctx = cdb;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd return EOK;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cndstatic errno_t get_entry_as_uint32(struct ldb_message *msg,
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen uint32_t *return_value,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *entry,
fb77c505254b6e9c925e23e734463e87574f8f40kess uint32_t default_value)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *tmp = NULL;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd char *endptr;
b06660a3ed3d885e15d99c0209a46c4657df33fbrbowen uint32_t u32ret = 0;
d1348237b33bc1755b9f1165eea52317465a7671nd
d1348237b33bc1755b9f1165eea52317465a7671nd *return_value = 0;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (!msg || !entry) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return EFAULT;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tmp = ldb_msg_find_attr_as_string(msg, entry, NULL);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (tmp == NULL) {
fb77c505254b6e9c925e23e734463e87574f8f40kess *return_value = default_value;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return EOK;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if ((*tmp == '-') || (*tmp == '\0')) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
130d299c4b2b15be45532a176604c71fdc7bea5bnd u32ret = strtouint32 (tmp, &endptr, 10);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (errno) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd return errno;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (*endptr != '\0') {
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* Not all of the string was a valid number */
df70c4445a86c43993e578fd1212c69ac52587a1rbowen return EINVAL;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd *return_value = u32ret;
130d299c4b2b15be45532a176604c71fdc7bea5bnd return EOK;
130d299c4b2b15be45532a176604c71fdc7bea5bnd}
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic errno_t get_entry_as_bool(struct ldb_message *msg,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool *return_value,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *entry,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool default_value)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *tmp = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *return_value = 0;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!msg || !entry) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess return EFAULT;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(msg, entry, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (tmp == NULL || *tmp == '\0') {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *return_value = default_value;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return EOK;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (strcasecmp(tmp, "FALSE") == 0) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd *return_value = 0;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd else if (strcasecmp(tmp, "TRUE") == 0) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd *return_value = 1;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd else {
130d299c4b2b15be45532a176604c71fdc7bea5bnd return EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess return EOK;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess}
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess/* The default UID/GID for domains is 1. This wouldn't work well with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * the local provider */
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowenstatic uint32_t confdb_get_min_id(struct sss_domain_info *domain)
4e10c61d7f924071cad435df940a8f325015b2d3rbowen{
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen uint32_t defval = SSSD_MIN_ID;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (domain && strcasecmp(domain->provider, "local") == 0) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive defval = SSSD_LOCAL_MINID;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd return defval;
4e10c61d7f924071cad435df940a8f325015b2d3rbowen}
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bndstatic int confdb_get_domain_internal(struct confdb_ctx *cdb,
130d299c4b2b15be45532a176604c71fdc7bea5bnd TALLOC_CTX *mem_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *name,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sss_domain_info **_domain)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
fb77c505254b6e9c925e23e734463e87574f8f40kess struct sss_domain_info *domain;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct ldb_result *res;
fb77c505254b6e9c925e23e734463e87574f8f40kess TALLOC_CTX *tmp_ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ldb_dn *dn;
97a9a944b5887e91042b019776c41d5dd74557aferikabele const char *tmp;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret, val;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd uint32_t entry_cache_timeout;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess tmp_ctx = talloc_new(mem_ctx);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (!tmp_ctx) return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fe64b2ba25510d8c9dba5560a2d537763566cf40nd dn = ldb_dn_new_fmt(tmp_ctx, cdb->ldb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "cn=%s,%s", name, CONFDB_DOMAIN_BASEDN);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!dn) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen ret = ldb_search(cdb->ldb, tmp_ctx, &res, dn,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd LDB_SCOPE_BASE, NULL, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != LDB_SUCCESS) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EIO;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (res->count != 1) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_FATAL_FAILURE, "Unknown domain [%s]\n", name);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = ENOENT;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor goto done;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd domain = talloc_zero(mem_ctx, struct sss_domain_info);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (!domain) {
6954edc623ca2c179eb5b33e97e4304d06fd649frbowen ret = ENOMEM;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(res->msgs[0], "cn", NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!tmp) {
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener DEBUG(SSSDBG_FATAL_FAILURE,
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener "Invalid configuration entry, fatal error!\n");
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener ret = EINVAL;
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener goto done;
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener }
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener domain->name = talloc_strdup(domain, tmp);
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener if (!domain->name) {
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener ret = ENOMEM;
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener goto done;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor domain->conn_name = domain->name;
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener tmp = ldb_msg_find_attr_as_string(res->msgs[0],
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener CONFDB_DOMAIN_ID_PROVIDER,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (tmp) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain->provider = talloc_strdup(domain, tmp);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!domain->provider) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = ENOMEM;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess goto done;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Domain [%s] does not specify an ID provider, disabling!\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain->name);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EINVAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (strcasecmp(domain->provider, "files") == 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* The files provider is not valid anymore */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE, "The \"files\" provider is invalid\n");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EINVAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
9bcfc3697a91b5215893a7d0206865b13fc72148nd }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess if (strcasecmp(domain->provider, "local") == 0) {
fb77c505254b6e9c925e23e734463e87574f8f40kess /* If this is the local provider, we need to ensure that
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * no other provider was specified for other types, since
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * the local provider cannot load them.
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tmp = ldb_msg_find_attr_as_string(res->msgs[0],
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd CONFDB_DOMAIN_AUTH_PROVIDER,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive NULL);
d565edaec710102f7e7d06252aaf1de67b7ddd25rbowen if (tmp && strcasecmp(tmp, "local") != 0) {
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor DEBUG(SSSDBG_FATAL_FAILURE,
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess "Local ID provider does not support [%s] as an AUTH provider.\n", tmp);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp = ldb_msg_find_attr_as_string(res->msgs[0],
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_ACCESS_PROVIDER,
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen NULL);
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen if (tmp && strcasecmp(tmp, "permit") != 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Local ID provider does not support [%s] as an ACCESS provider.\n", tmp);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EINVAL;
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf tmp = ldb_msg_find_attr_as_string(res->msgs[0],
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_CHPASS_PROVIDER,
8559a67073808d84d85bb5dd552d4247caafe709sf NULL);
8559a67073808d84d85bb5dd552d4247caafe709sf if (tmp && strcasecmp(tmp, "local") != 0) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf "Local ID provider does not support [%s] as a CHPASS provider.\n", tmp);
8559a67073808d84d85bb5dd552d4247caafe709sf ret = EINVAL;
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* The LOCAL provider use always Magic Private Groups */
8559a67073808d84d85bb5dd552d4247caafe709sf domain->mpg = true;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf domain->timeout = ldb_msg_find_attr_as_int(res->msgs[0],
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_TIMEOUT, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Determine if this domain can be enumerated */
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* TEMP: test if the old bitfield conf value is used and warn it has been
8559a67073808d84d85bb5dd552d4247caafe709sf * superceeded. */
8559a67073808d84d85bb5dd552d4247caafe709sf val = ldb_msg_find_attr_as_int(res->msgs[0], CONFDB_DOMAIN_ENUMERATE, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf if (val > 0) { /* ok there was a number in here */
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf "Warning: enumeration parameter in %s still uses integers! "
8559a67073808d84d85bb5dd552d4247caafe709sf "Enumeration is now a boolean and takes true/false values. "
8559a67073808d84d85bb5dd552d4247caafe709sf "Interpreting as true\n", domain->name);
8559a67073808d84d85bb5dd552d4247caafe709sf domain->enumerate = true;
8559a67073808d84d85bb5dd552d4247caafe709sf } else { /* assume the new format */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_bool(res->msgs[0], &domain->enumerate,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_ENUMERATE, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf if(ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf "Invalid value for %s\n", CONFDB_DOMAIN_ENUMERATE);
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf if (!domain->enumerate) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_TRACE_FUNC, "No enumeration for [%s]!\n", domain->name);
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Determine if user/group names will be Fully Qualified
8559a67073808d84d85bb5dd552d4247caafe709sf * in NSS interfaces */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_bool(res->msgs[0], &domain->fqnames, CONFDB_DOMAIN_FQ, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf if(ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE, "Invalid value for %s\n", CONFDB_DOMAIN_FQ);
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_bool(res->msgs[0], &domain->ignore_group_members,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_IGNORE_GROUP_MEMBERS, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf if(ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf "Invalid value for %s\n",
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_IGNORE_GROUP_MEMBERS);
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->id_min,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_MINID,
8559a67073808d84d85bb5dd552d4247caafe709sf confdb_get_min_id(domain));
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE, "Invalid value for minId\n");
8559a67073808d84d85bb5dd552d4247caafe709sf ret = EINVAL;
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->id_max,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_MAXID, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE, "Invalid value for maxId\n");
8559a67073808d84d85bb5dd552d4247caafe709sf ret = EINVAL;
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf if (domain->id_max && (domain->id_max < domain->id_min)) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE, "Invalid domain range\n");
8559a67073808d84d85bb5dd552d4247caafe709sf ret = EINVAL;
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Do we allow to cache credentials */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_bool(res->msgs[0], &domain->cache_credentials,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_CACHE_CREDS, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf if(ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf "Invalid value for %s\n", CONFDB_DOMAIN_CACHE_CREDS);
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_bool(res->msgs[0], &domain->legacy_passwords,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_LEGACY_PASS, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf if(ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf "Invalid value for %s\n", CONFDB_DOMAIN_LEGACY_PASS);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Get the global entry cache timeout setting */
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = get_entry_as_uint32(res->msgs[0], &entry_cache_timeout,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_ENTRY_CACHE_TIMEOUT, 5400);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Invalid value for [%s]\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_ENTRY_CACHE_TIMEOUT);
9bcfc3697a91b5215893a7d0206865b13fc72148nd goto done;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive }
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Override the user cache timeout, if specified */
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen ret = get_entry_as_uint32(res->msgs[0], &domain->user_timeout,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd CONFDB_DOMAIN_USER_CACHE_TIMEOUT,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd entry_cache_timeout);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_FATAL_FAILURE,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "Invalid value for [%s]\n",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd CONFDB_DOMAIN_USER_CACHE_TIMEOUT);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
9bcfc3697a91b5215893a7d0206865b13fc72148nd
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier /* Override the group cache timeout, if specified */
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier ret = get_entry_as_uint32(res->msgs[0], &domain->group_timeout,
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier CONFDB_DOMAIN_GROUP_CACHE_TIMEOUT,
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier entry_cache_timeout);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_FATAL_FAILURE,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "Invalid value for [%s]\n",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd CONFDB_DOMAIN_GROUP_CACHE_TIMEOUT);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
fb77c505254b6e9c925e23e734463e87574f8f40kess
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Override the netgroup cache timeout, if specified */
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = get_entry_as_uint32(res->msgs[0], &domain->netgroup_timeout,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh CONFDB_DOMAIN_NETGROUP_CACHE_TIMEOUT,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh entry_cache_timeout);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (ret != EOK) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh DEBUG(SSSDBG_FATAL_FAILURE,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh "Invalid value for [%s]\n",
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess CONFDB_DOMAIN_NETGROUP_CACHE_TIMEOUT);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess goto done;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh /* Override the service cache timeout, if specified */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_uint32(res->msgs[0], &domain->service_timeout,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_SERVICE_CACHE_TIMEOUT,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd entry_cache_timeout);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Invalid value for [%s]\n",
fb77c505254b6e9c925e23e734463e87574f8f40kess CONFDB_DOMAIN_SERVICE_CACHE_TIMEOUT);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Override the autofs cache timeout, if specified */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_uint32(res->msgs[0], &domain->autofsmap_timeout,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf CONFDB_DOMAIN_AUTOFS_CACHE_TIMEOUT,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf entry_cache_timeout);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
9bcfc3697a91b5215893a7d0206865b13fc72148nd DEBUG(SSSDBG_FATAL_FAILURE,
9bcfc3697a91b5215893a7d0206865b13fc72148nd "Invalid value for [%s]\n",
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh CONFDB_DOMAIN_AUTOFS_CACHE_TIMEOUT);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh goto done;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh /* Override the sudo cache timeout, if specified */
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawick ret = get_entry_as_uint32(res->msgs[0], &domain->sudo_timeout,
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess CONFDB_DOMAIN_SUDO_CACHE_TIMEOUT,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess entry_cache_timeout);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (ret != EOK) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh DEBUG(SSSDBG_FATAL_FAILURE,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh "Invalid value for [%s]\n",
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh CONFDB_DOMAIN_SUDO_CACHE_TIMEOUT);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh goto done;
9fb925624300c864fe3969a264e52aa83f3c2dd0slive }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
78f4d313fd5edf76dc5cfb8725e082a08cd29740jwoolley /* Set refresh_expired_interval, if specified */
78f4d313fd5edf76dc5cfb8725e082a08cd29740jwoolley ret = get_entry_as_uint32(res->msgs[0], &domain->refresh_expired_interval,
f653ca260580e6d64d92ae29963f207b94e87353nd CONFDB_DOMAIN_REFRESH_EXPIRED_INTERVAL,
f653ca260580e6d64d92ae29963f207b94e87353nd 0);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf if (ret != EOK) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess DEBUG(SSSDBG_FATAL_FAILURE,
9fb925624300c864fe3969a264e52aa83f3c2dd0slive "Invalid value for [%s]\n",
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh CONFDB_DOMAIN_REFRESH_EXPIRED_INTERVAL);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh goto done;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf }
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh /* Set the PAM warning time, if specified. If not specified, pass on
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh * the "not set" value of "-1" which means "use provider default". The
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf * value 0 means "always display the warning if server sends one" */
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh domain->pwd_expiration_warning = -1;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf val = ldb_msg_find_attr_as_int(res->msgs[0],
9fb925624300c864fe3969a264e52aa83f3c2dd0slive CONFDB_DOMAIN_PWD_EXPIRATION_WARNING,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh -1);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (val == -1) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = confdb_get_int(cdb, CONFDB_PAM_CONF_ENTRY,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess CONFDB_PAM_PWD_EXPIRATION_WARNING,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess -1, &val);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (ret != EOK) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh DEBUG(SSSDBG_CRIT_FAILURE,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh "Failed to read PAM expiration warning, not fatal.\n");
832853bb93c1831daf24e4727c5ca0e1b1786e83lars val = -1;
832853bb93c1831daf24e4727c5ca0e1b1786e83lars }
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin }
832853bb93c1831daf24e4727c5ca0e1b1786e83lars
832853bb93c1831daf24e4727c5ca0e1b1786e83lars DEBUG(SSSDBG_TRACE_LIBS, "pwd_expiration_warning is %d\n", val);
832853bb93c1831daf24e4727c5ca0e1b1786e83lars if (val >= 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_CONF_SETTINGS,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick "Setting domain password expiration warning to %d days\n", val);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick /* The value is in days, transform it to seconds */
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick domain->pwd_expiration_warning = val * 24 * 3600;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = get_entry_as_uint32(res->msgs[0], &domain->override_gid,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick CONFDB_DOMAIN_OVERRIDE_GID, 0);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (ret != EOK) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick DEBUG(SSSDBG_FATAL_FAILURE,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick "Invalid value for [%s]\n", CONFDB_DOMAIN_OVERRIDE_GID);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick goto done;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick tmp = ldb_msg_find_attr_as_string(res->msgs[0],
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick CONFDB_NSS_OVERRIDE_HOMEDIR, NULL);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (tmp != NULL) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick domain->override_homedir = talloc_strdup(domain, tmp);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (!domain->override_homedir) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = ENOMEM;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick goto done;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick tmp = ldb_msg_find_attr_as_string(res->msgs[0],
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick CONFDB_NSS_FALLBACK_HOMEDIR, NULL);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (tmp != NULL) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick domain->fallback_homedir = talloc_strdup(domain, tmp);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (!domain->fallback_homedir) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = ENOMEM;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick goto done;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick tmp = ldb_msg_find_attr_as_string(res->msgs[0],
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick CONFDB_DOMAIN_SUBDOMAIN_HOMEDIR,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick CONFDB_DOMAIN_DEFAULT_SUBDOMAIN_HOMEDIR);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (tmp != NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain->subdomain_homedir = talloc_strdup(domain, tmp);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!domain->subdomain_homedir) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp = ldb_msg_find_attr_as_string(res->msgs[0],
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_NSS_HOMEDIR_SUBSTRING, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (tmp != NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain->homedir_substr = talloc_strdup(domain, tmp);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen if (domain->homedir_substr == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(res->msgs[0],
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_NSS_OVERRIDE_SHELL, NULL);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (tmp != NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive domain->override_shell = talloc_strdup(domain, tmp);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!domain->override_shell) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(res->msgs[0],
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_NSS_DEFAULT_SHELL, NULL);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen if (tmp != NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive domain->default_shell = talloc_strdup(domain, tmp);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!domain->default_shell) {
59cd19c3d75e35ae820e23f6b0161910784fce4eslive ret = ENOMEM;
59cd19c3d75e35ae820e23f6b0161910784fce4eslive goto done;
59cd19c3d75e35ae820e23f6b0161910784fce4eslive }
59cd19c3d75e35ae820e23f6b0161910784fce4eslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tmp = ldb_msg_find_attr_as_string(res->msgs[0],
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd CONFDB_DOMAIN_CASE_SENSITIVE, "true");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (tmp != NULL) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (strcasecmp(tmp, "true") == 0) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd domain->case_sensitive = true;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd domain->case_preserve = true;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else if (strcasecmp(tmp, "false") == 0) {
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd domain->case_sensitive = false;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen domain->case_preserve = false;
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd } else if (strcasecmp(tmp, "preserving") == 0) {
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen domain->case_sensitive = false;
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd domain->case_preserve = true;
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd } else {
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd DEBUG(SSSDBG_FATAL_FAILURE,
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd "Invalid value for %s\n", CONFDB_DOMAIN_CASE_SENSITIVE);
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd goto done;
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd }
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd } else {
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd /* default */
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd domain->case_sensitive = true;
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd domain->case_preserve = true;
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (domain->case_sensitive == false &&
06ba4a61654b3763ad65f52283832ebf058fdf1cslive strcasecmp(domain->provider, "local") == 0) {
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen DEBUG(SSSDBG_FATAL_FAILURE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "Local ID provider does not support the case insensitive flag\n");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(res->msgs[0],
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_SUBDOMAIN_ENUMERATE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_DEFAULT_SUBDOMAIN_ENUMERATE);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (tmp != NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = split_on_separator(domain, tmp, ',', true, true,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess &domain->sd_enumerate, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != 0) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_FATAL_FAILURE,
fb77c505254b6e9c925e23e734463e87574f8f40kess "Cannot parse %s\n", CONFDB_SUBDOMAIN_ENUMERATE);
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive }
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive ret = get_entry_as_uint32(res->msgs[0], &domain->subdomain_refresh_interval,
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawick CONFDB_DOMAIN_SUBDOMAIN_REFRESH, 14400);
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive if (ret != EOK || domain->subdomain_refresh_interval == 0) {
59cd19c3d75e35ae820e23f6b0161910784fce4eslive DEBUG(SSSDBG_FATAL_FAILURE,
59cd19c3d75e35ae820e23f6b0161910784fce4eslive "Invalid value for [%s]\n", CONFDB_DOMAIN_SUBDOMAIN_REFRESH);
59cd19c3d75e35ae820e23f6b0161910784fce4eslive goto done;
59cd19c3d75e35ae820e23f6b0161910784fce4eslive }
59cd19c3d75e35ae820e23f6b0161910784fce4eslive
59cd19c3d75e35ae820e23f6b0161910784fce4eslive *_domain = domain;
59cd19c3d75e35ae820e23f6b0161910784fce4eslive ret = EOK;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzordone:
b5d3d68a9f683722eac7a3ca507c3e571908dfc0rbowen talloc_free(tmp_ctx);
b5d3d68a9f683722eac7a3ca507c3e571908dfc0rbowen return ret;
b5d3d68a9f683722eac7a3ca507c3e571908dfc0rbowen}
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
59cd19c3d75e35ae820e23f6b0161910784fce4esliveint confdb_get_domains(struct confdb_ctx *cdb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sss_domain_info **domains)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TALLOC_CTX *tmp_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sss_domain_info *domain = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char **domlist;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret, i;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (cdb->doms) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *domains = cdb->doms;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
c1fcddc76fd5db5ac4ccd7c6ae839d53d128f354minfrin
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp_ctx = talloc_new(NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!tmp_ctx) return ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = confdb_get_string_as_list(cdb, tmp_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_MONITOR_CONF_ENTRY,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_MONITOR_ACTIVE_DOMAINS,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor &domlist);
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess if (ret == ENOENT) {
fb109b84906e3ee61680aa289953c2f9e859354erbowen DEBUG(SSSDBG_FATAL_FAILURE, "No domains configured, fatal error!\n");
fb109b84906e3ee61680aa289953c2f9e859354erbowen goto done;
fb109b84906e3ee61680aa289953c2f9e859354erbowen }
fb109b84906e3ee61680aa289953c2f9e859354erbowen if (ret != EOK ) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess DEBUG(SSSDBG_FATAL_FAILURE, "Fatal error retrieving domains list!\n");
fb109b84906e3ee61680aa289953c2f9e859354erbowen goto done;
db2474c3448fc75c325aa43ba0144fced1a38c53rjung }
db2474c3448fc75c325aa43ba0144fced1a38c53rjung
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for (i = 0; domlist[i]; i++) {
fb109b84906e3ee61680aa289953c2f9e859354erbowen /* check if domain name is really unique */
fb109b84906e3ee61680aa289953c2f9e859354erbowen DLIST_FOR_EACH(domain, cdb->doms) {
fb109b84906e3ee61680aa289953c2f9e859354erbowen if (strcasecmp(domain->name, domlist[i]) == 0) {
fb109b84906e3ee61680aa289953c2f9e859354erbowen DEBUG(SSSDBG_FATAL_FAILURE,
db2474c3448fc75c325aa43ba0144fced1a38c53rjung SAME_DOMAINS_ERROR_MSG, domlist[i], domain->name);
db2474c3448fc75c325aa43ba0144fced1a38c53rjung sss_log(SSS_LOG_CRIT,
db2474c3448fc75c325aa43ba0144fced1a38c53rjung SAME_DOMAINS_ERROR_MSG, domlist[i], domain->name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
5155e92c6100b47513159eee1b2b9914ab204a5acovener
5155e92c6100b47513159eee1b2b9914ab204a5acovener domain = NULL;
5155e92c6100b47513159eee1b2b9914ab204a5acovener ret = confdb_get_domain_internal(cdb, cdb, domlist[i], &domain);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret) {
fb109b84906e3ee61680aa289953c2f9e859354erbowen DEBUG(SSSDBG_FATAL_FAILURE,
fb109b84906e3ee61680aa289953c2f9e859354erbowen "Error (%d [%s]) retrieving domain [%s], skipping!\n",
fb109b84906e3ee61680aa289953c2f9e859354erbowen ret, strerror(ret), domlist[i]);
fb109b84906e3ee61680aa289953c2f9e859354erbowen continue;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawick DLIST_ADD_END(cdb->doms, domain, struct sss_domain_info *);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
c023f60e35022146373e40249f0c8c8d623b6fcfnd
c023f60e35022146373e40249f0c8c8d623b6fcfnd if (cdb->doms == NULL) {
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen DEBUG(SSSDBG_FATAL_FAILURE,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor "No properly configured domains, fatal error!\n");
c023f60e35022146373e40249f0c8c8d623b6fcfnd ret = ENOENT;
c023f60e35022146373e40249f0c8c8d623b6fcfnd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *domains = cdb->doms;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EOK;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin talloc_free(tmp_ctx);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin return ret;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf}
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfint confdb_get_domain(struct confdb_ctx *cdb,
2851546ce44280e54301016a7e92b00a87745509sf const char *name,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct sss_domain_info **_domain)
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf{
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct sss_domain_info *dom, *doms;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf int ret;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = confdb_get_domains(cdb, &doms);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf if (ret != EOK) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf return ret;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf }
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf for (dom = doms; dom; dom = get_next_domain(dom, false)) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf if (strcasecmp(dom->name, name) == 0) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf *_domain = dom;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf return EOK;
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf }
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf }
2bb4320391b88748dc6e851deca941b058231664rbowen
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf return ENOENT;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf}
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfint confdb_list_all_domain_names(TALLOC_CTX *mem_ctx,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct confdb_ctx *cdb,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf char ***_names)
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf{
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf TALLOC_CTX *tmp_ctx = NULL;
2bb4320391b88748dc6e851deca941b058231664rbowen struct ldb_dn *dn = NULL;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct ldb_result *res = NULL;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf static const char *attrs[] = {CONFDB_DOMAIN_ATTR, NULL};
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf const char *name = NULL;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf char **names = NULL;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf int i;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf int ret;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf tmp_ctx = talloc_new(NULL);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf if (tmp_ctx == NULL) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf return ENOMEM;
2bb4320391b88748dc6e851deca941b058231664rbowen }
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf dn = ldb_dn_new(tmp_ctx, cdb->ldb, CONFDB_DOMAIN_BASEDN);
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen if (dn == NULL) {
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen ret = ENOMEM;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf goto done;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf }
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen ret = ldb_search(cdb->ldb, tmp_ctx, &res, dn, LDB_SCOPE_ONELEVEL,
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen attrs, NULL);
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen if (ret != LDB_SUCCESS) {
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen ret = EIO;
221a06bb836af6024708190895834af79c90d1c8rbowen goto done;
221a06bb836af6024708190895834af79c90d1c8rbowen }
221a06bb836af6024708190895834af79c90d1c8rbowen
221a06bb836af6024708190895834af79c90d1c8rbowen names = talloc_zero_array(tmp_ctx, char*, res->count + 1);
2bb4320391b88748dc6e851deca941b058231664rbowen if (names == NULL) {
2bb4320391b88748dc6e851deca941b058231664rbowen ret = ENOMEM;
2bb4320391b88748dc6e851deca941b058231664rbowen goto done;
2bb4320391b88748dc6e851deca941b058231664rbowen }
2bb4320391b88748dc6e851deca941b058231664rbowen
2bb4320391b88748dc6e851deca941b058231664rbowen for (i = 0; i < res->count; i++) {
2bb4320391b88748dc6e851deca941b058231664rbowen name = ldb_msg_find_attr_as_string(res->msgs[i], CONFDB_DOMAIN_ATTR,
2bb4320391b88748dc6e851deca941b058231664rbowen NULL);
2bb4320391b88748dc6e851deca941b058231664rbowen if (name == NULL) {
2bb4320391b88748dc6e851deca941b058231664rbowen DEBUG(SSSDBG_MINOR_FAILURE,
2bb4320391b88748dc6e851deca941b058231664rbowen "The object [%s] doesn't have a name\n",
2bb4320391b88748dc6e851deca941b058231664rbowen ldb_dn_get_linearized(res->msgs[i]->dn));
2bb4320391b88748dc6e851deca941b058231664rbowen ret = EINVAL;
2bb4320391b88748dc6e851deca941b058231664rbowen goto done;
2bb4320391b88748dc6e851deca941b058231664rbowen }
2bb4320391b88748dc6e851deca941b058231664rbowen
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf names[i] = talloc_strdup(names, name);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf if (names[i] == NULL) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = ENOMEM;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf goto done;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf }
2bb4320391b88748dc6e851deca941b058231664rbowen }
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
2bb4320391b88748dc6e851deca941b058231664rbowen *_names = talloc_steal(mem_ctx, names);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
2bb4320391b88748dc6e851deca941b058231664rbowen ret = EOK;
0b5f11662dee7135ff8dd04311a4ee6df7fe2b1crbowen
2bb4320391b88748dc6e851deca941b058231664rbowendone:
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf talloc_free(tmp_ctx);
2bb4320391b88748dc6e851deca941b058231664rbowen return ret;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf}
2bb4320391b88748dc6e851deca941b058231664rbowen