confdb.c revision c14184c07634801cda7864aa17c6fa8dc9ab43d1
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
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic char *prepend_cn(char *str, int *slen, const char *comp, int clen)
117c1f888a14e73cdd821dc6c23eb0411144a41cnd{
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *ret;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = talloc_realloc(NULL, str, char, *slen + 4 + clen + 1);
bed3c2e56e8f3328e780200466b9d009093db468sf if (!ret)
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return NULL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* move current string to the end */
9597f440430d8c876dd64f5f78066804650a18ecnoodl memmove(&ret[clen +4], ret, *slen+1); /* includes termination */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd memcpy(ret, "cn=", 3);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd memcpy(&ret[3], comp, clen);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret[clen+3] = ',';
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf *slen = *slen + 4 + clen;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh return ret;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick}
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndint parse_section(TALLOC_CTX *mem_ctx, const char *section,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf char **sec_dn, const char **rdn_name)
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin{
117c1f888a14e73cdd821dc6c23eb0411144a41cnd TALLOC_CTX *tmp_ctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *dn = NULL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *p;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char *s;
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener int l, ret;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl /* 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);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (!tmp_ctx) return ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd s = section;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd l = 0;
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd 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 {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd dn = prepend_cn(dn, &l, s, p-s);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (!dn) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = ENOMEM;
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim goto done;
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim }
6beba165aeced2ca77a6f1593ee08c47a32099efcovener if (*p == '\0') {
709e3a21ba73b8433462959cd56c773454b34441trawick if (rdn_name) *rdn_name = s;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd break; /* reached end */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen s = p+1;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (*s == '\0') { /* a section cannot end in '.' */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = EINVAL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd *sec_dn = talloc_steal(mem_ctx, dn);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = EOK;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnddone:
117c1f888a14e73cdd821dc6c23eb0411144a41cnd talloc_free(tmp_ctx);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return ret;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd}
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndint confdb_add_param(struct confdb_ctx *cdb,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd bool replace,
b00fe3c3354db01001b8eddfd9b88441380f837dwrowe const char *section,
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin const char *attribute,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char **values)
a38b5f73e7f0f3b8726fb47d27b145f37036ead0jim{
117c1f888a14e73cdd821dc6c23eb0411144a41cnd TALLOC_CTX *tmp_ctx = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_message *msg;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_result *res;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_dn *dn;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna char *secdn;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna const char *rdn_name;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna int ret, i;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna tmp_ctx = talloc_new(NULL);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (!tmp_ctx) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ENOMEM;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna goto done;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen }
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = parse_section(tmp_ctx, section, &secdn, &rdn_name);
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen if (ret != EOK) {
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen goto done;
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen }
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen 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);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor if (ret != LDB_SUCCESS) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = EIO;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe goto done;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener msg = ldb_msg_new(tmp_ctx);
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener CONFDB_ZERO_CHECK_OR_JUMP(msg, ret, ENOMEM, done);
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener msg->dn = talloc_steal(msg, dn);
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener CONFDB_ZERO_CHECK_OR_JUMP(msg->dn, ret, ENOMEM, done);
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (res->count == 0) { /* add a new message */
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna errno = 0;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna /* cn first */
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ldb_msg_add_string(msg, "cn", rdn_name);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor if (ret != LDB_SUCCESS) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (errno) ret = errno;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor else ret = EIO;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor goto done;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
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;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna goto done;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = ldb_add(cdb->ldb, msg);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (ret != LDB_SUCCESS) {
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = EIO;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna goto done;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
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 }
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe /* now the requested attribute */
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe for (i = 0; values[i]; i++) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = ldb_msg_add_string(msg, attribute, values[i]);
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen if (ret != LDB_SUCCESS) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe if (errno) ret = errno;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe else ret = EIO;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe goto done;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen ret = ldb_modify(cdb->ldb, msg);
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen if (ret != LDB_SUCCESS) {
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen ret = EIO;
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen goto done;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(tmp_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Failed to add [%s] to [%s], error [%d] (%s)\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd attribute, section, ret, strerror(ret)));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveint confdb_get_param(struct confdb_ctx *cdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TALLOC_CTX *mem_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *section,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *attribute,
fb77c505254b6e9c925e23e734463e87574f8f40kess char ***values)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TALLOC_CTX *tmp_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive 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)
fb77c505254b6e9c925e23e734463e87574f8f40kess return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = parse_section(tmp_ctx, section, &secdn, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dn = ldb_dn_new(tmp_ctx, cdb->ldb, secdn);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!dn) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EIO;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = ldb_search(cdb->ldb, tmp_ctx, &res,
bc4b55ec8f31569d606d5680d50189a355bcd7a6rbowen dn, LDB_SCOPE_BASE, attrs, NULL);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != LDB_SUCCESS) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EIO;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (res->count > 1) {
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = EIO;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess vals = talloc_zero(mem_ctx, char *);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EOK;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd 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);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (!vals) {
ef8e89e090461194ecadd31e8796a2c51e0531a2kess ret = ENOMEM;
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* should always be strings so this should be safe */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd 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 }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd vals[i] = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *values = vals;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslivedone:
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive talloc_free(tmp_ctx);
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess if (ret != EOK) {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess DEBUG(1, ("Failed to get [%s] from [%s], error [%d] (%s)\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive attribute, section, ret, strerror(ret)));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveint confdb_set_bool(struct confdb_ctx *cdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *section,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *attribute,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool val)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TALLOC_CTX *tmp_ctx;
130d299c4b2b15be45532a176604c71fdc7bea5bnd struct ldb_dn *dn;
130d299c4b2b15be45532a176604c71fdc7bea5bnd char *secdn;
130d299c4b2b15be45532a176604c71fdc7bea5bnd struct ldb_message *msg;
130d299c4b2b15be45532a176604c71fdc7bea5bnd int ret, lret;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd tmp_ctx = talloc_new(NULL);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (!tmp_ctx)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = parse_section(tmp_ctx, section, &secdn, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd dn = ldb_dn_new(tmp_ctx, cdb->ldb, secdn);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!dn) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EIO;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
627c978514c54179736d152923478be7c8707f9bnd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd msg = ldb_msg_new(tmp_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!msg) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd msg->dn = dn;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd lret = ldb_msg_add_empty(msg, attribute, LDB_FLAG_MOD_REPLACE, NULL);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (lret != LDB_SUCCESS) {
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd DEBUG(SSSDBG_MINOR_FAILURE,
b95ae799514ad86a15610ad75808d7065e9847c9kess ("ldb_msg_add_empty failed: [%s]\n", ldb_strerror(lret)));
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd ret = EIO;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd goto done;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (val) {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd lret = ldb_msg_add_string(msg, attribute, "True");
604c89126c27104f659d7a51b0113e3bd435faf8fielding } else {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd lret = ldb_msg_add_string(msg, attribute, "False");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (lret != LDB_SUCCESS) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_MINOR_FAILURE,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ("ldb_msg_add_string failed: [%s]\n", ldb_strerror(lret)));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EIO;
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd 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;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd goto done;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = EOK;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnddone:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(tmp_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd DEBUG(SSSDBG_CRIT_FAILURE,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ("Failed to set [%s] from [%s], error [%d] (%s)\n",
9583adab6bc4b3758e41963c905d9dad9f067131nd attribute, section, ret, strerror(ret)));
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier return ret;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd}
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268ndint confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd const char *section, const char *attribute,
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier const char *defstr, char **result)
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier{
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd char **values = NULL;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd char *restr;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd int ret;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = confdb_get_param(cdb, ctx, section, attribute, &values);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier if (ret != EOK) {
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier goto failed;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier }
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier if (values[0]) {
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier if (values[1] != NULL) {
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier /* too many values */
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = EINVAL;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier goto failed;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd restr = talloc_steal(ctx, values[0]);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd } else {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd /* Did not return a value, so use the default */
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier if (defstr == NULL) { /* No default given */
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier *result = NULL;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier talloc_free(values);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd return EOK;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd /* Copy the default string */
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd restr = talloc_strdup(ctx, defstr);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (!restr) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto failed;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
627c978514c54179736d152923478be7c8707f9bnd talloc_free(values);
fb77c505254b6e9c925e23e734463e87574f8f40kess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *result = restr;
6f7c18e70781deff3d1129774221de81b43c828end return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndfailed:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(values);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Failed to get [%s] from [%s], error [%d] (%s)\n",
fb77c505254b6e9c925e23e734463e87574f8f40kess attribute, section, ret, strerror(ret)));
fb77c505254b6e9c925e23e734463e87574f8f40kess return ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess}
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
06ba4a61654b3763ad65f52283832ebf058fdf1csliveint confdb_get_int(struct confdb_ctx *cdb,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess const char *section, const char *attribute,
10673857794a4b3d9568ca2d983722a87ed352f1rbowen int defval, int *result)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
ed0dae472b518c553c923a86fb4322d4c50d86a6nd char **values = NULL;
ed0dae472b518c553c923a86fb4322d4c50d86a6nd long val;
10673857794a4b3d9568ca2d983722a87ed352f1rbowen int ret;
10673857794a4b3d9568ca2d983722a87ed352f1rbowen TALLOC_CTX *tmp_ctx;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf tmp_ctx = talloc_new(NULL);
bed3c2e56e8f3328e780200466b9d009093db468sf if (tmp_ctx == NULL) {
bed3c2e56e8f3328e780200466b9d009093db468sf ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto failed;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto failed;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (values[0]) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (values[1] != NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* too many values */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto failed;
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz }
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end errno = 0;
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl val = strtol(values[0], NULL, 0);
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl if (errno) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = errno;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto failed;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
604c89126c27104f659d7a51b0113e3bd435faf8fielding if (val < INT_MIN || val > INT_MAX) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = ERANGE;
604c89126c27104f659d7a51b0113e3bd435faf8fielding goto failed;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding } else {
604c89126c27104f659d7a51b0113e3bd435faf8fielding val = defval;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
909ce17e2bd0faef7b1c294f2307f009793fd493nd talloc_free(tmp_ctx);
909ce17e2bd0faef7b1c294f2307f009793fd493nd
909ce17e2bd0faef7b1c294f2307f009793fd493nd *result = (int)val;
909ce17e2bd0faef7b1c294f2307f009793fd493nd return EOK;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivefailed:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(tmp_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive attribute, section, ret, strerror(ret)));
97a9a944b5887e91042b019776c41d5dd74557aferikabele return ret;
97a9a944b5887e91042b019776c41d5dd74557aferikabele}
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabelelong confdb_get_long(struct confdb_ctx *cdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *section, const char *attribute,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive long defval, long *result)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char **values = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive long val;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TALLOC_CTX *tmp_ctx;
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp_ctx = talloc_new(NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (tmp_ctx == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
97a9a944b5887e91042b019776c41d5dd74557aferikabele goto failed;
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak }
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values);
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener if (ret != EOK) {
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener goto failed;
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim }
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener if (values[0]) {
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener if (values[1] != NULL) {
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener /* too many values */
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener ret = EINVAL;
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener goto failed;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive errno = 0;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive val = strtol(values[0], NULL, 0);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (errno) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = errno;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto failed;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
ed0dae472b518c553c923a86fb4322d4c50d86a6nd
ed0dae472b518c553c923a86fb4322d4c50d86a6nd } else {
ed0dae472b518c553c923a86fb4322d4c50d86a6nd val = defval;
ed0dae472b518c553c923a86fb4322d4c50d86a6nd }
da637bcae7b6e150470e701af29da5604a34a17erbowen
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor talloc_free(tmp_ctx);
da637bcae7b6e150470e701af29da5604a34a17erbowen
da637bcae7b6e150470e701af29da5604a34a17erbowen *result = val;
da637bcae7b6e150470e701af29da5604a34a17erbowen return EOK;
da637bcae7b6e150470e701af29da5604a34a17erbowen
da637bcae7b6e150470e701af29da5604a34a17erbowenfailed:
da637bcae7b6e150470e701af29da5604a34a17erbowen talloc_free(tmp_ctx);
7802d43d20007fa575e43b6ae77d5177ceffdb71sf DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n",
7802d43d20007fa575e43b6ae77d5177ceffdb71sf attribute, section, ret, strerror(ret)));
7802d43d20007fa575e43b6ae77d5177ceffdb71sf return ret;
7802d43d20007fa575e43b6ae77d5177ceffdb71sf}
7802d43d20007fa575e43b6ae77d5177ceffdb71sf
7802d43d20007fa575e43b6ae77d5177ceffdb71sfint confdb_get_bool(struct confdb_ctx *cdb,
7802d43d20007fa575e43b6ae77d5177ceffdb71sf const char *section, const char *attribute,
bed3c2e56e8f3328e780200466b9d009093db468sf bool defval, bool *result)
bed3c2e56e8f3328e780200466b9d009093db468sf{
bed3c2e56e8f3328e780200466b9d009093db468sf char **values = NULL;
bed3c2e56e8f3328e780200466b9d009093db468sf bool 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
bed3c2e56e8f3328e780200466b9d009093db468sf if (strcasecmp(values[0], "FALSE") == 0) {
bed3c2e56e8f3328e780200466b9d009093db468sf val = false;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf } else if (strcasecmp(values[0], "TRUE") == 0) {
bed3c2e56e8f3328e780200466b9d009093db468sf val = true;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf } else {
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(2, ("Value is not a boolean!\n"));
bed3c2e56e8f3328e780200466b9d009093db468sf ret = EINVAL;
bed3c2e56e8f3328e780200466b9d009093db468sf goto failed;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf } else {
bed3c2e56e8f3328e780200466b9d009093db468sf val = defval;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf talloc_free(tmp_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf *result = val;
bed3c2e56e8f3328e780200466b9d009093db468sf return EOK;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sffailed:
bed3c2e56e8f3328e780200466b9d009093db468sf talloc_free(tmp_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n",
bed3c2e56e8f3328e780200466b9d009093db468sf attribute, section, ret, strerror(ret)));
bed3c2e56e8f3328e780200466b9d009093db468sf return ret;
bed3c2e56e8f3328e780200466b9d009093db468sf}
bed3c2e56e8f3328e780200466b9d009093db468sf
fe64b2ba25510d8c9dba5560a2d537763566cf40nd/* WARNING: Unlike other similar functions, this one does NOT take a default,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * and returns ENOENT if the attribute was not found ! */
fe64b2ba25510d8c9dba5560a2d537763566cf40ndint confdb_get_string_as_list(struct confdb_ctx *cdb, TALLOC_CTX *ctx,
bed3c2e56e8f3328e780200466b9d009093db468sf const char *section, const char *attribute,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char ***result)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char **values = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = confdb_get_param(cdb, ctx, section, attribute, &values);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (values && values[0]) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (values[1] != NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* too many values */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EINVAL;
c985aca104389df30d6ec0a637ce0ccaac904362nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen } else {
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Did not return a value */
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = ENOENT;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess goto done;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = split_on_separator(ctx, values[0], ',', true, true, result, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(values);
627c978514c54179736d152923478be7c8707f9bnd if (ret != EOK && ret != ENOENT) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(2, ("Failed to get [%s] from [%s], error [%d] (%s)\n",
fb77c505254b6e9c925e23e734463e87574f8f40kess attribute, section, ret, strerror(ret)));
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndint confdb_init(TALLOC_CTX *mem_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct confdb_ctx **cdb_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *confdb_location)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
5bb5fba250bf526bc51d13b25378d54acb93c1cbnoodl struct confdb_ctx *cdb;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret = EOK;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mode_t old_umask;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive cdb = talloc_zero(mem_ctx, struct confdb_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!cdb)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Because confdb calls use sync ldb calls, we create a separate event
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * context here. This will prevent the ldb sync calls to start nested
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * events.
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * NOTE: this means that we *cannot* do async calls and return in confdb
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * unless we convert all calls and hook back to the main event context.
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive cdb->pev = tevent_context_init(cdb);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!cdb->pev) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(cdb);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return EIO;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess cdb->ldb = ldb_init(cdb, cdb->pev);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (!cdb->ldb) {
fb77c505254b6e9c925e23e734463e87574f8f40kess talloc_free(cdb);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EIO;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_set_debug(cdb->ldb, ldb_debug_messages, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != LDB_SUCCESS) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding DEBUG(0,("Could not set up debug fn.\n"));
604c89126c27104f659d7a51b0113e3bd435faf8fielding talloc_free(cdb);
604c89126c27104f659d7a51b0113e3bd435faf8fielding return EIO;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding old_umask = umask(0177);
604c89126c27104f659d7a51b0113e3bd435faf8fielding
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_connect(cdb->ldb, confdb_location, 0, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd umask(old_umask);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != LDB_SUCCESS) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(0, ("Unable to open config database [%s]\n",
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen confdb_location));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(cdb);
604c89126c27104f659d7a51b0113e3bd435faf8fielding return EIO;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *cdb_ctx = cdb;
22265f1724519886e2a2b5e0ebd61477506b7379noodl
22265f1724519886e2a2b5e0ebd61477506b7379noodl return EOK;
22265f1724519886e2a2b5e0ebd61477506b7379noodl}
22265f1724519886e2a2b5e0ebd61477506b7379noodl
604c89126c27104f659d7a51b0113e3bd435faf8fieldingstatic errno_t get_entry_as_uint32(struct ldb_message *msg,
604c89126c27104f659d7a51b0113e3bd435faf8fielding uint32_t *return_value,
604c89126c27104f659d7a51b0113e3bd435faf8fielding const char *entry,
604c89126c27104f659d7a51b0113e3bd435faf8fielding uint32_t default_value)
604c89126c27104f659d7a51b0113e3bd435faf8fielding{
604c89126c27104f659d7a51b0113e3bd435faf8fielding const char *tmp = NULL;
604c89126c27104f659d7a51b0113e3bd435faf8fielding char *endptr;
604c89126c27104f659d7a51b0113e3bd435faf8fielding uint32_t u32ret = 0;
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding *return_value = 0;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
9597f440430d8c876dd64f5f78066804650a18ecnoodl if (!msg || !entry) {
9597f440430d8c876dd64f5f78066804650a18ecnoodl return EFAULT;
9597f440430d8c876dd64f5f78066804650a18ecnoodl }
9597f440430d8c876dd64f5f78066804650a18ecnoodl
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf tmp = ldb_msg_find_attr_as_string(msg, entry, NULL);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf if (tmp == NULL) {
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf *return_value = default_value;
9597f440430d8c876dd64f5f78066804650a18ecnoodl return EOK;
9597f440430d8c876dd64f5f78066804650a18ecnoodl }
9597f440430d8c876dd64f5f78066804650a18ecnoodl
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf if ((*tmp == '-') || (*tmp == '\0')) {
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf return EINVAL;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf }
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf u32ret = strtouint32 (tmp, &endptr, 10);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf if (errno) {
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf return errno;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf }
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf if (*endptr != '\0') {
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf /* Not all of the string was a valid number */
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf return EINVAL;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf }
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf *return_value = u32ret;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf return EOK;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf}
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsfstatic errno_t get_entry_as_bool(struct ldb_message *msg,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf bool *return_value,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf const char *entry,
9597f440430d8c876dd64f5f78066804650a18ecnoodl bool default_value)
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf{
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf const char *tmp = NULL;
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *return_value = 0;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!msg || !entry) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EFAULT;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp = ldb_msg_find_attr_as_string(msg, entry, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (tmp == NULL || *tmp == '\0') {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *return_value = default_value;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (strcasecmp(tmp, "FALSE") == 0) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *return_value = 0;
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor else if (strcasecmp(tmp, "TRUE") == 0) {
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen *return_value = 1;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive else {
fb77c505254b6e9c925e23e734463e87574f8f40kess return EINVAL;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess return EOK;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive}
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd/* The default UID/GID for domains is 1. This wouldn't work well with
130d299c4b2b15be45532a176604c71fdc7bea5bnd * the local provider */
130d299c4b2b15be45532a176604c71fdc7bea5bndstatic uint32_t confdb_get_min_id(struct sss_domain_info *domain)
130d299c4b2b15be45532a176604c71fdc7bea5bnd{
130d299c4b2b15be45532a176604c71fdc7bea5bnd uint32_t defval = SSSD_MIN_ID;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (domain && strcasecmp(domain->provider, "local") == 0) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd defval = SSSD_LOCAL_MINID;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return defval;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen}
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
fb77c505254b6e9c925e23e734463e87574f8f40kessstatic int confdb_get_domain_internal(struct confdb_ctx *cdb,
fb77c505254b6e9c925e23e734463e87574f8f40kess TALLOC_CTX *mem_ctx,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *name,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd struct sss_domain_info **_domain)
b06660a3ed3d885e15d99c0209a46c4657df33fbrbowen{
d1348237b33bc1755b9f1165eea52317465a7671nd struct sss_domain_info *domain;
d1348237b33bc1755b9f1165eea52317465a7671nd struct ldb_result *res;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TALLOC_CTX *tmp_ctx;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd struct ldb_dn *dn;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *tmp;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd int ret, val;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd uint32_t entry_cache_timeout;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
fb77c505254b6e9c925e23e734463e87574f8f40kess tmp_ctx = talloc_new(mem_ctx);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (!tmp_ctx) return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess dn = ldb_dn_new_fmt(tmp_ctx, cdb->ldb,
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess "cn=%s,%s", name, CONFDB_DOMAIN_BASEDN);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!dn) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = ldb_search(cdb->ldb, tmp_ctx, &res, dn,
130d299c4b2b15be45532a176604c71fdc7bea5bnd LDB_SCOPE_BASE, NULL, NULL);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret != LDB_SUCCESS) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = EIO;
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
df70c4445a86c43993e578fd1212c69ac52587a1rbowen
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (res->count != 1) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd DEBUG(0, ("Unknown domain [%s]\n", name));
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = ENOENT;
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive domain = talloc_zero(mem_ctx, struct sss_domain_info);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!domain) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(res->msgs[0], "cn", NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!tmp) {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess DEBUG(0, ("Invalid configuration entry, fatal error!\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess goto done;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess domain->name = talloc_strdup(domain, tmp);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!domain->name) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive domain->conn_name = domain->name;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(res->msgs[0],
130d299c4b2b15be45532a176604c71fdc7bea5bnd CONFDB_DOMAIN_ID_PROVIDER,
130d299c4b2b15be45532a176604c71fdc7bea5bnd NULL);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (tmp) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd domain->provider = talloc_strdup(domain, tmp);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (!domain->provider) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = ENOMEM;
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess else {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess DEBUG(0, ("Domain [%s] does not specify an ID provider, disabling!\n",
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess domain->name));
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess ret = EINVAL;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
4e10c61d7f924071cad435df940a8f325015b2d3rbowen if (strcasecmp(domain->provider, "files") == 0) {
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen /* The files provider is not valid anymore */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(0, ("The \"files\" provider is invalid\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (strcasecmp(domain->provider, "local") == 0) {
4e10c61d7f924071cad435df940a8f325015b2d3rbowen /* If this is the local provider, we need to ensure that
130d299c4b2b15be45532a176604c71fdc7bea5bnd * no other provider was specified for other types, since
130d299c4b2b15be45532a176604c71fdc7bea5bnd * the local provider cannot load them.
130d299c4b2b15be45532a176604c71fdc7bea5bnd */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp = ldb_msg_find_attr_as_string(res->msgs[0],
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_DOMAIN_AUTH_PROVIDER,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive NULL);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (tmp && strcasecmp(tmp, "local") != 0) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(0, ("Local ID provider does not support [%s] as an AUTH provider.\n", tmp));
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = EINVAL;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
97a9a944b5887e91042b019776c41d5dd74557aferikabele }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp = ldb_msg_find_attr_as_string(res->msgs[0],
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_ACCESS_PROVIDER,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess NULL);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (tmp && strcasecmp(tmp, "permit") != 0) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(0, ("Local ID provider does not support [%s] as an ACCESS provider.\n", tmp));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EINVAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp = ldb_msg_find_attr_as_string(res->msgs[0],
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_CHPASS_PROVIDER,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess NULL);
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen if (tmp && strcasecmp(tmp, "local") != 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(0, ("Local ID provider does not support [%s] as a CHPASS provider.\n", tmp));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EINVAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* The LOCAL provider use always Magic Private Groups */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive domain->mpg = true;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor domain->timeout = ldb_msg_find_attr_as_int(res->msgs[0],
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor CONFDB_DOMAIN_TIMEOUT, 0);
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Determine if this domain can be enumerated */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
6954edc623ca2c179eb5b33e97e4304d06fd649frbowen /* TEMP: test if the old bitfield conf value is used and warn it has been
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * superceeded. */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive val = ldb_msg_find_attr_as_int(res->msgs[0], CONFDB_DOMAIN_ENUMERATE, 0);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (val > 0) { /* ok there was a number in here */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(0, ("Warning: enumeration parameter in %s still uses integers! "
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Enumeration is now a boolean and takes true/false values. "
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener "Interpreting as true\n", domain->name));
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener domain->enumerate = true;
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener } else { /* assume the new format */
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener ret = get_entry_as_bool(res->msgs[0], &domain->enumerate,
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener CONFDB_DOMAIN_ENUMERATE, 0);
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener if(ret != EOK) {
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener DEBUG(0, ("Invalid value for %s\n", CONFDB_DOMAIN_ENUMERATE));
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener goto done;
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor if (!domain->enumerate) {
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener DEBUG(SSSDBG_TRACE_FUNC, ("No enumeration for [%s]!\n", domain->name));
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener }
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Determine if user/group names will be Fully Qualified
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * in NSS interfaces */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_bool(res->msgs[0], &domain->fqnames, CONFDB_DOMAIN_FQ, 0);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if(ret != EOK) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess DEBUG(0, ("Invalid value for %s\n", CONFDB_DOMAIN_FQ));
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess goto done;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_bool(res->msgs[0], &domain->ignore_group_members,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_IGNORE_GROUP_MEMBERS, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if(ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ("Invalid value for %s\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_IGNORE_GROUP_MEMBERS));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_uint32(res->msgs[0], &domain->id_min,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_MINID,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd confdb_get_min_id(domain));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
9bcfc3697a91b5215893a7d0206865b13fc72148nd DEBUG(0, ("Invalid value for minId\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = EINVAL;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = get_entry_as_uint32(res->msgs[0], &domain->id_max,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd CONFDB_DOMAIN_MAXID, 0);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(0, ("Invalid value for maxId\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
d565edaec710102f7e7d06252aaf1de67b7ddd25rbowen goto done;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (domain->id_max && (domain->id_max < domain->id_min)) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(0, ("Invalid domain range\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EINVAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen /* Do we allow to cache credentials */
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen ret = get_entry_as_bool(res->msgs[0], &domain->cache_credentials,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_CACHE_CREDS, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if(ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(0, ("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(0, ("Invalid value for %s\n", CONFDB_DOMAIN_LEGACY_PASS));
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Get the global entry cache timeout setting */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &entry_cache_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_ENTRY_CACHE_TIMEOUT, 5400);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_ENTRY_CACHE_TIMEOUT));
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the user cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->user_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_USER_CACHE_TIMEOUT,
8559a67073808d84d85bb5dd552d4247caafe709sf entry_cache_timeout);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_USER_CACHE_TIMEOUT));
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the group cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->group_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_GROUP_CACHE_TIMEOUT,
8559a67073808d84d85bb5dd552d4247caafe709sf entry_cache_timeout);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_GROUP_CACHE_TIMEOUT));
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the netgroup cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->netgroup_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_NETGROUP_CACHE_TIMEOUT,
8559a67073808d84d85bb5dd552d4247caafe709sf entry_cache_timeout);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_NETGROUP_CACHE_TIMEOUT));
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the service cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->service_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_SERVICE_CACHE_TIMEOUT,
8559a67073808d84d85bb5dd552d4247caafe709sf entry_cache_timeout);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_SERVICE_CACHE_TIMEOUT));
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the autofs cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->autofsmap_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_AUTOFS_CACHE_TIMEOUT,
8559a67073808d84d85bb5dd552d4247caafe709sf entry_cache_timeout);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_AUTOFS_CACHE_TIMEOUT));
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Override the sudo cache timeout, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = get_entry_as_uint32(res->msgs[0], &domain->sudo_timeout,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_SUDO_CACHE_TIMEOUT,
8559a67073808d84d85bb5dd552d4247caafe709sf entry_cache_timeout);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf DEBUG(SSSDBG_FATAL_FAILURE,
8559a67073808d84d85bb5dd552d4247caafe709sf ("Invalid value for [%s]\n",
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_SUDO_CACHE_TIMEOUT));
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Set the PAM warning time, if specified */
8559a67073808d84d85bb5dd552d4247caafe709sf val = ldb_msg_find_attr_as_int(res->msgs[0],
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_DOMAIN_PWD_EXPIRATION_WARNING,
8559a67073808d84d85bb5dd552d4247caafe709sf -1);
8559a67073808d84d85bb5dd552d4247caafe709sf if (val > 0) {
8559a67073808d84d85bb5dd552d4247caafe709sf /* The value is in days, transform it to seconds */
8559a67073808d84d85bb5dd552d4247caafe709sf val *= 24 * 3600;
8559a67073808d84d85bb5dd552d4247caafe709sf } else {
8559a67073808d84d85bb5dd552d4247caafe709sf ret = confdb_get_int(cdb, CONFDB_PAM_CONF_ENTRY,
8559a67073808d84d85bb5dd552d4247caafe709sf CONFDB_PAM_PWD_EXPIRATION_WARNING,
8559a67073808d84d85bb5dd552d4247caafe709sf -1, &val);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Failed to read PAM expiration warning, not fatal.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd val = -1;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess domain->pwd_expiration_warning = val;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_entry_as_uint32(res->msgs[0], &domain->override_gid,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_DOMAIN_OVERRIDE_GID, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(0, ("Invalid value for [%s]\n", CONFDB_DOMAIN_OVERRIDE_GID));
9bcfc3697a91b5215893a7d0206865b13fc72148nd goto done;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive }
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
fb77c505254b6e9c925e23e734463e87574f8f40kess tmp = ldb_msg_find_attr_as_string(res->msgs[0],
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen CONFDB_NSS_OVERRIDE_HOMEDIR, NULL);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (tmp != NULL) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd domain->override_homedir = talloc_strdup(domain, tmp);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (!domain->override_homedir) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
9bcfc3697a91b5215893a7d0206865b13fc72148nd tmp = ldb_msg_find_attr_as_string(res->msgs[0],
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier CONFDB_NSS_FALLBACK_HOMEDIR, NULL);
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier if (tmp != NULL) {
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier domain->fallback_homedir = talloc_strdup(domain, tmp);
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier if (!domain->fallback_homedir) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tmp = ldb_msg_find_attr_as_string(res->msgs[0],
fb77c505254b6e9c925e23e734463e87574f8f40kess CONFDB_DOMAIN_SUBDOMAIN_HOMEDIR,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd CONFDB_DOMAIN_DEFAULT_SUBDOMAIN_HOMEDIR);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (tmp != NULL) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh domain->subdomain_homedir = talloc_strdup(domain, tmp);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (!domain->subdomain_homedir) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = ENOMEM;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh goto done;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess tmp = ldb_msg_find_attr_as_string(res->msgs[0],
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh CONFDB_NSS_OVERRIDE_SHELL, NULL);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (tmp != NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain->override_shell = talloc_strdup(domain, tmp);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!domain->override_shell) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fb77c505254b6e9c925e23e734463e87574f8f40kess
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf tmp = ldb_msg_find_attr_as_string(res->msgs[0],
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CONFDB_NSS_DEFAULT_SHELL, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (tmp != NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain->default_shell = talloc_strdup(domain, tmp);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!domain->default_shell) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = ENOMEM;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
9bcfc3697a91b5215893a7d0206865b13fc72148nd }
9bcfc3697a91b5215893a7d0206865b13fc72148nd
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = get_entry_as_bool(res->msgs[0], &domain->case_sensitive,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh CONFDB_DOMAIN_CASE_SENSITIVE, true);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen if(ret != EOK) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh DEBUG(0, ("Invalid value for %s\n", CONFDB_DOMAIN_CASE_SENSITIVE));
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh goto done;
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawick }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess if (domain->case_sensitive == false &&
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess strcasecmp(domain->provider, "local") == 0) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh DEBUG(SSSDBG_FATAL_FAILURE,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ("Local ID provider does not support the case insensitive flag\n"));
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = EINVAL;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh goto done;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh }
9fb925624300c864fe3969a264e52aa83f3c2dd0slive
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess *_domain = domain;
78f4d313fd5edf76dc5cfb8725e082a08cd29740jwoolley ret = EOK;
78f4d313fd5edf76dc5cfb8725e082a08cd29740jwoolleydone:
f653ca260580e6d64d92ae29963f207b94e87353nd talloc_free(tmp_ctx);
f653ca260580e6d64d92ae29963f207b94e87353nd return ret;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf}
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
9fb925624300c864fe3969a264e52aa83f3c2dd0sliveint confdb_get_domains(struct confdb_ctx *cdb,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh struct sss_domain_info **domains)
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh{
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf TALLOC_CTX *tmp_ctx;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct sss_domain_info *domain, *prevdom = NULL;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh char **domlist;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh int ret, i;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (cdb->doms) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh *domains = cdb->doms;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf return EOK;
9fb925624300c864fe3969a264e52aa83f3c2dd0slive }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh tmp_ctx = talloc_new(NULL);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (!tmp_ctx) return ENOMEM;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = confdb_get_string_as_list(cdb, tmp_ctx,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess CONFDB_MONITOR_CONF_ENTRY,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh CONFDB_MONITOR_ACTIVE_DOMAINS,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh &domlist);
832853bb93c1831daf24e4727c5ca0e1b1786e83lars if (ret == ENOENT) {
832853bb93c1831daf24e4727c5ca0e1b1786e83lars DEBUG(0, ("No domains configured, fatal error!\n"));
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin goto done;
832853bb93c1831daf24e4727c5ca0e1b1786e83lars }
832853bb93c1831daf24e4727c5ca0e1b1786e83lars if (ret != EOK ) {
832853bb93c1831daf24e4727c5ca0e1b1786e83lars DEBUG(0, ("Fatal error retrieving domains list!\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick for (i = 0; domlist[i]; i++) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = confdb_get_domain_internal(cdb, cdb, domlist[i], &domain);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (ret) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick DEBUG(0, ("Error (%d [%s]) retrieving domain [%s], skipping!\n",
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret, strerror(ret), domlist[i]));
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick continue;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (cdb->doms == NULL) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick cdb->doms = domain;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick prevdom = cdb->doms;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick } else {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick prevdom->next = domain;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick prevdom = domain;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (cdb->doms == NULL) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick DEBUG(0, ("No properly configured domains, fatal error!\n"));
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = ENOENT;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick goto done;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick *domains = cdb->doms;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = EOK;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawickdone:
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick talloc_free(tmp_ctx);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick return ret;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick}
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawickint confdb_get_domain(struct confdb_ctx *cdb,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick const char *name,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick struct sss_domain_info **_domain)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sss_domain_info *dom, *doms;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = confdb_get_domains(cdb, &doms);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd for (dom = doms; dom; dom = dom->next) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (strcasecmp(dom->name, name) == 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *_domain = dom;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen return EOK;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOENT;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive