6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek/*
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek SSSD
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek System Database - initialization
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek Copyright (C) 2008-2011 Simo Sorce <ssorce@redhat.com>
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek Copyright (C) 2008-2011 Stephen Gallagher <ssorce@redhat.com>
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek This program is free software; you can redistribute it and/or modify
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek it under the terms of the GNU General Public License as published by
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek the Free Software Foundation; either version 3 of the License, or
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek (at your option) any later version.
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek This program is distributed in the hope that it will be useful,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek GNU General Public License for more details.
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek You should have received a copy of the GNU General Public License
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek*/
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek#include "util/util.h"
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek#include "util/strtonum.h"
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek#include "util/sss_utf8.h"
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek#include "db/sysdb_private.h"
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek#include "confdb/confdb.h"
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek#include "util/probes.h"
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek#include <time.h>
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek#define LDB_MODULES_PATH "LDB_MODULES_PATH"
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek/* If an entry differs only in these attributes, they are written to
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose * the timestamp cache only. In addition, objectclass/objectcategory is added
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose * so that we can distinguish between users and groups.
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek */
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozekconst char *sysdb_ts_cache_attrs[] = {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek SYSDB_OBJECTCLASS,
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose SYSDB_OBJECTCATEGORY,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek SYSDB_LAST_UPDATE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek SYSDB_CACHE_EXPIRE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek SYSDB_ORIG_MODSTAMP,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek SYSDB_INITGR_EXPIRE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek SYSDB_USN,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek NULL,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek};
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekerrno_t sysdb_ldb_connect(TALLOC_CTX *mem_ctx,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *filename,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek int flags,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek struct ldb_context **_ldb)
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek{
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek int ret;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek struct ldb_context *ldb;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek const char *mod_path;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (_ldb == NULL) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EINVAL;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ldb = ldb_init(mem_ctx, NULL);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!ldb) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ldb_set_debug(ldb, ldb_debug_messages, NULL);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek mod_path = getenv(LDB_MODULES_PATH);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (mod_path != NULL) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek DEBUG(SSSDBG_TRACE_ALL, "Setting ldb module path to [%s].\n", mod_path);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ldb_set_modules_dir(ldb, mod_path);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ldb_connect(ldb, filename, flags, NULL);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek *_ldb = ldb;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EOK;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekstatic errno_t sysdb_ldb_reconnect(TALLOC_CTX *mem_ctx,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *ldb_file,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek int flags,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_context **ldb)
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek{
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek errno_t ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek talloc_zfree(*ldb);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_ldb_connect(mem_ctx, ldb_file, flags, ldb);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_ldb_connect failed.\n");
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek}
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozekstatic errno_t sysdb_chown_db_files(struct sysdb_ctx *sysdb,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek uid_t uid, gid_t gid)
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek{
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek errno_t ret;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = chown(sysdb->ldb_file, uid, gid);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek if (ret != 0) {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = errno;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek "Cannot set sysdb ownership of %s to %"SPRIuid":%"SPRIgid"\n",
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek sysdb->ldb_file, uid, gid);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek return ret;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek }
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek if (sysdb->ldb_ts_file != NULL) {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = chown(sysdb->ldb_ts_file, uid, gid);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek if (ret != 0) {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = errno;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek "Cannot set sysdb ownership of %s to %"SPRIuid":%"SPRIgid"\n",
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek sysdb->ldb_ts_file, uid, gid);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek return ret;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek }
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek }
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek return EOK;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek}
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozekint sysdb_get_db_file(TALLOC_CTX *mem_ctx,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek const char *provider,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek const char *name,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek const char *base_path,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek char **_ldb_file,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek char **_ts_file)
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek{
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek char *ldb_file;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek char *ts_file = NULL;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* special case for the local domain */
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (strcasecmp(provider, "local") == 0) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ldb_file = talloc_asprintf(mem_ctx, "%s/"LOCAL_SYSDB_FILE,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek base_path);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek } else {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ldb_file = talloc_asprintf(mem_ctx, "%s/"CACHE_SYSDB_FILE,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek base_path, name);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ts_file = talloc_asprintf(mem_ctx, "%s/"CACHE_TIMESTAMPS_FILE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek base_path, name);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek if (ts_file == NULL) {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek talloc_free(ldb_file);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek return ENOMEM;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!ldb_file) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek *_ldb_file = ldb_file;
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek *_ts_file = ts_file;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EOK;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekstatic errno_t sysdb_domain_create_int(struct ldb_context *ldb,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *domain_name)
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek{
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek struct ldb_message *msg;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek TALLOC_CTX *tmp_ctx;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek int ret;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek tmp_ctx = talloc_new(NULL);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (tmp_ctx == NULL) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* == create base domain object == */
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek msg = ldb_msg_new(tmp_ctx);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!msg) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek msg->dn = ldb_dn_new_fmt(msg, ldb, SYSDB_DOM_BASE, domain_name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!msg->dn) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ldb_msg_add_string(msg, "cn", domain_name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* do a synchronous add */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ldb_add(ldb, msg);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Failed to initialize DB (%d, [%s]) "
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek "for domain %s!\n",
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret, ldb_errstring(ldb),
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek domain_name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek talloc_zfree(msg);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* == create Users tree == */
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek msg = ldb_msg_new(tmp_ctx);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!msg) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek msg->dn = ldb_dn_new_fmt(msg, ldb,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek SYSDB_TMPL_USER_BASE, domain_name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!msg->dn) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ldb_msg_add_string(msg, "cn", "Users");
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* do a synchronous add */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ldb_add(ldb, msg);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Failed to initialize DB (%d, [%s]) "
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek "for domain %s!\n",
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret, ldb_errstring(ldb),
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek domain_name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek talloc_zfree(msg);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* == create Groups tree == */
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek msg = ldb_msg_new(tmp_ctx);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!msg) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek msg->dn = ldb_dn_new_fmt(msg, ldb,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek SYSDB_TMPL_GROUP_BASE, domain_name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!msg->dn) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ldb_msg_add_string(msg, "cn", "Groups");
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* do a synchronous add */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ldb_add(ldb, msg);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Failed to initialize DB (%d, [%s]) for "
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek "domain %s!\n",
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret, ldb_errstring(ldb),
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek domain_name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek talloc_zfree(msg);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EOK;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozekdone:
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek talloc_zfree(tmp_ctx);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return ret;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekerrno_t sysdb_domain_create(struct sysdb_ctx *sysdb, const char *domain_name)
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek{
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return sysdb_domain_create_int(sysdb->ldb, domain_name);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek}
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek/* Compare versions of sysdb, returns ERRNO accordingly */
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozekstatic errno_t
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozeksysdb_version_check(const char *expected,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek const char *received)
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek{
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek int ret;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek unsigned int exp_major, exp_minor, recv_major, recv_minor;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(received, expected) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return EOK;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = sscanf(expected, "%u.%u", &exp_major, &exp_minor);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != 2) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EINVAL;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = sscanf(received, "%u.%u", &recv_major, &recv_minor);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != 2) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EINVAL;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (recv_major > exp_major) {
e732d23f3ec986a463d757781a334040e03d1f59Jakub Hrozek return ERR_SYSDB_VERSION_TOO_NEW;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek } else if (recv_major < exp_major) {
e732d23f3ec986a463d757781a334040e03d1f59Jakub Hrozek return ERR_SYSDB_VERSION_TOO_OLD;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (recv_minor > exp_minor) {
e732d23f3ec986a463d757781a334040e03d1f59Jakub Hrozek return ERR_SYSDB_VERSION_TOO_NEW;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek } else if (recv_minor < exp_minor) {
e732d23f3ec986a463d757781a334040e03d1f59Jakub Hrozek return ERR_SYSDB_VERSION_TOO_OLD;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return EOK;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekstatic errno_t sysdb_cache_add_base_ldif(struct ldb_context *ldb,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *base_ldif,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *domain_name)
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek{
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek int ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_ldif *ldif;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek while ((ldif = ldb_ldif_read_string(ldb, &base_ldif))) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ldb_add(ldb, ldif->msg);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != LDB_SUCCESS) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek "Failed to initialize DB (%d, [%s]) for domain %s!\n",
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret, ldb_errstring(ldb), domain_name);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return EIO;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ldb_ldif_read_free(ldb, ldif);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return EOK;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek}
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekstatic errno_t sysdb_cache_create_empty(struct ldb_context *ldb,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *base_ldif,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct sss_domain_info *domain)
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek{
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek int ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_cache_add_base_ldif(ldb, base_ldif, domain->name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ret;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_domain_create_int(ldb, domain->name);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return EOK;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek}
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozekstatic errno_t sysdb_ts_cache_upgrade(TALLOC_CTX *mem_ctx,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek struct sysdb_ctx *sysdb,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek struct ldb_context *ldb,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek struct sss_domain_info *domain,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek const char *cur_version,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek const char **_new_version)
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek{
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose errno_t ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose TALLOC_CTX *tmp_ctx;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose const char *version;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct ldb_context *save_ldb;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose tmp_ctx = talloc_new(NULL);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (tmp_ctx == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose return ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose /* The upgrade process depends on having ldb around, yet the upgrade
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose * function shouldn't set the ldb pointer, only the connect function
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose * should after it's successful. To avoid hard refactoring, save the
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose * ldb pointer here and restore in the 'done' handler
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose */
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose save_ldb = sysdb->ldb;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose sysdb->ldb = ldb;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose version = talloc_strdup(tmp_ctx, cur_version);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (version == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_CONF_SETTINGS,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose "Upgrading timstamp cache of DB [%s] from version: %s\n",
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose domain->name, version);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (strcmp(version, SYSDB_TS_VERSION_0_1) == 0) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_ts_upgrade_01(sysdb, &version);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != EOK) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = EOK;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bosedone:
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose sysdb->ldb = save_ldb;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose *_new_version = version;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose talloc_free(tmp_ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose return ret;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek}
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekstatic errno_t sysdb_domain_cache_upgrade(TALLOC_CTX *mem_ctx,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct sysdb_ctx *sysdb,
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek struct sysdb_dom_upgrade_ctx *upgrade_ctx,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_context *ldb,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct sss_domain_info *domain,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *cur_version,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char **_new_version)
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek{
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek errno_t ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek TALLOC_CTX *tmp_ctx;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *version;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_context *save_ldb;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek tmp_ctx = talloc_new(NULL);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (tmp_ctx == NULL) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ENOMEM;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek /* The upgrade process depends on having ldb around, yet the upgrade
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek * function shouldn't set the ldb pointer, only the connect function
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek * should after it's successful. To avoid hard refactoring, save the
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek * ldb pointer here and restore in the 'done' handler
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek save_ldb = sysdb->ldb;
ee71456b887c82ff6aa2581cbb6ddb3607bba51eJakub Hrozek sysdb->ldb = ldb;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek version = talloc_strdup(tmp_ctx, cur_version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (version == NULL) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek "Upgrading DB [%s] from version: %s\n",
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek domain->name, version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_3) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_03(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_4) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_04(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_5) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_05(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_6) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_06(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_7) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_07(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_8) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_08(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_9) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_09(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_10) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_10(sysdb, domain, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_11) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_11(sysdb, domain, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_12) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_12(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_13) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_13(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_14) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_14(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_15) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_15(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (strcmp(version, SYSDB_VERSION_0_16) == 0) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_upgrade_16(sysdb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (strcmp(version, SYSDB_VERSION_0_17) == 0) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = sysdb_upgrade_17(sysdb, upgrade_ctx, &version);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (strcmp(version, SYSDB_VERSION_0_18) == 0) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = sysdb_upgrade_18(sysdb, &version);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret != EOK) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (strcmp(version, SYSDB_VERSION_0_19) == 0) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_upgrade_19(sysdb, &version);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != EOK) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = EOK;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekdone:
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek sysdb->ldb = save_ldb;
ee71456b887c82ff6aa2581cbb6ddb3607bba51eJakub Hrozek *_new_version = version;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek talloc_free(tmp_ctx);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek}
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidênciostatic errno_t remove_ts_cache(struct sysdb_ctx *sysdb)
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio{
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio errno_t ret;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio if (sysdb->ldb_ts_file == NULL) {
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio return EOK;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio }
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio ret = unlink(sysdb->ldb_ts_file);
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio if (ret != EOK && errno != ENOENT) {
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio return errno;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio }
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio return EOK;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio}
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidênciostatic errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio struct sss_domain_info *domain,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio const char *ldb_file,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio int flags,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio const char *exp_version,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio const char *base_ldif,
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio bool *_newly_created,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio struct ldb_context **_ldb,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio const char **_version)
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek{
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek TALLOC_CTX *tmp_ctx = NULL;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_message_element *el;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_result *res;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_dn *verdn;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *version = NULL;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek int ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_context *ldb;
975d0b67a40847265523d195438bf4753d18ff1cLukas Slebodnik bool newly_created = false;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek tmp_ctx = talloc_new(NULL);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!tmp_ctx) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_ldb_connect(tmp_ctx, ldb_file, flags, &ldb);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_ldb_connect failed.\n");
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek verdn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!verdn) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ldb_search(ldb, tmp_ctx, &res,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek verdn, LDB_SCOPE_BASE,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek NULL, NULL);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != LDB_SUCCESS) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (res->count > 1) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (res->count == 1) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek el = ldb_msg_find_element(res->msgs[0], "version");
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!el) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EIO;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (el->num_values != 1) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = EINVAL;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek version = talloc_strndup(tmp_ctx,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek (char *)(el->values[0].data),
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek el->values[0].length);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (!version) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_version_check(exp_version, version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek /* This is not the latest version. Return what version it is
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek * and appropriate error
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek */
ee71456b887c82ff6aa2581cbb6ddb3607bba51eJakub Hrozek *_ldb = talloc_steal(mem_ctx, ldb);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek *_version = talloc_steal(mem_ctx, version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek /* SYSDB_BASE does not exists, means db is empty, populate */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_cache_create_empty(ldb, base_ldif, domain);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio newly_created = true;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio /* We need to reopen the LDB to ensure that
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek * all of the special values take effect
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek * (such as enabling the memberOf plugin and
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek * the various indexes).
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_ldb_reconnect(tmp_ctx, ldb_file, flags, &ldb);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek /* If we connect to a new database, then the version is the
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek * latest one
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek *_version = talloc_strdup(mem_ctx, exp_version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (*_version == NULL) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ENOMEM;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekdone:
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret == EOK) {
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio if (_newly_created != NULL) {
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio *_newly_created = newly_created;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek *_ldb = talloc_steal(mem_ctx, ldb);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek talloc_free(tmp_ctx);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidênciostatic errno_t sysdb_cache_connect(TALLOC_CTX *mem_ctx,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio struct sysdb_ctx *sysdb,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio struct sss_domain_info *domain,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio struct ldb_context **ldb,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio const char **version)
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio{
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio bool newly_created;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio bool ldb_file_exists;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio errno_t ret;
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio ldb_file_exists = !(access(sysdb->ldb_file, F_OK) == -1 && errno == ENOENT);
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
adb9823dc6b6247cd477fa7b050959f264f6582bLukas Slebodnik ret = sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_file,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio 0, SYSDB_VERSION, SYSDB_BASE_LDIF,
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio &newly_created, ldb, version);
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio /* The cache has been newly created. */
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio if (ret == EOK && newly_created && !ldb_file_exists) {
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio ret = remove_ts_cache(sysdb);
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio if (ret != EOK) {
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio DEBUG(SSSDBG_MINOR_FAILURE,
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio "Could not delete the timestamp ldb file (%d) (%s)\n",
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio ret, sss_strerror(ret));
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio }
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio }
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio return ret;
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio}
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidênciostatic errno_t sysdb_ts_cache_connect(TALLOC_CTX *mem_ctx,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio struct sysdb_ctx *sysdb,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio struct sss_domain_info *domain,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio struct ldb_context **ldb,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio const char **version)
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio{
adb9823dc6b6247cd477fa7b050959f264f6582bLukas Slebodnik return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_ts_file,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio LDB_FLG_NOSYNC, SYSDB_TS_VERSION,
9023bf51de6c84337af024388f1860ac1051924cFabiano Fidêncio SYSDB_TS_BASE_LDIF, NULL,
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio ldb, version);
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio}
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekstatic int sysdb_domain_cache_connect(struct sysdb_ctx *sysdb,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct sss_domain_info *domain,
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek struct sysdb_dom_upgrade_ctx *upgrade_ctx)
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek{
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek errno_t ret;
3f6aecfe5061e165c10829142854ec7189029407Lukas Slebodnik const char *version = NULL;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek TALLOC_CTX *tmp_ctx;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct ldb_context *ldb;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek tmp_ctx = talloc_new(NULL);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (tmp_ctx == NULL) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ENOMEM;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio ret = sysdb_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek switch (ret) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek case ERR_SYSDB_VERSION_TOO_OLD:
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek if (upgrade_ctx == NULL) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek "DB version too old [%s], expected [%s] for domain %s!\n",
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek version, SYSDB_VERSION, domain->name);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek ret = sysdb_domain_cache_upgrade(tmp_ctx, sysdb, upgrade_ctx,
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek ldb, domain, version, &version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek /* To be on the safe side, nuke the timestamp cache on upgrades.
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek * This is just a one-time performance hit after an upgrade
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek */
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek ret = remove_ts_cache(sysdb);
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek if (ret != EOK) {
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek "Could not delete the timestamp ldb file (%d) (%s)\n",
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek ret, sss_strerror(ret));
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek return ret;
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek }
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* The version should now match SYSDB_VERSION.
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek * If not, it means we didn't match any of the
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek * known older versions. The DB might be
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek * corrupt or generated by a newer version of
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek * SSSD.
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_version_check(SYSDB_VERSION, version);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret == EOK) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* The cache has been upgraded.
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek * We need to reopen the LDB to ensure that
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek * any changes made above take effect.
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_ldb_reconnect(tmp_ctx, sysdb->ldb_file, 0, &ldb);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek break;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek case ERR_SYSDB_VERSION_TOO_NEW:
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek "DB version too new [%s], expected [%s] for domain %s!\n",
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek version, SYSDB_VERSION, domain->name);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek break;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek default:
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek break;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekdone:
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (ret == EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek sysdb->ldb = talloc_steal(sysdb, ldb);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek talloc_free(tmp_ctx);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozekstatic int sysdb_timestamp_cache_connect(struct sysdb_ctx *sysdb,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek struct sss_domain_info *domain,
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek struct sysdb_dom_upgrade_ctx *upgrade_ctx)
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek{
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek errno_t ret;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek const char *version;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek TALLOC_CTX *tmp_ctx;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek struct ldb_context *ldb;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (sysdb->ldb_ts_file == NULL) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "No timestamp cache for %s\n", domain->name);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek return EOK;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek tmp_ctx = talloc_new(NULL);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (tmp_ctx == NULL) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek return ENOMEM;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio ret = sysdb_ts_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek switch (ret) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek case ERR_SYSDB_VERSION_TOO_OLD:
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek if (upgrade_ctx == NULL) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "DB version too old [%s], expected [%s] for domain %s!\n",
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek version, SYSDB_VERSION, domain->name);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek break;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret = sysdb_ts_cache_upgrade(tmp_ctx, sysdb, ldb, domain, version,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek &version);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (ret != EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "Could not upgrade the timestamp ldb file (%d) (%s)\n",
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret, sss_strerror(ret));
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek break;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek /* The version should now match SYSDB_VERSION.
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek * If not, it means we didn't match any of the
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek * known older versions. The DB might be
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek * corrupt or generated by a newer version of
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek * SSSD.
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek */
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret = sysdb_version_check(SYSDB_TS_VERSION, version);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (ret == EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek /* The cache has been upgraded.
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek * We need to reopen the LDB to ensure that
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek * any changes made above take effect.
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek */
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret = sysdb_ldb_reconnect(tmp_ctx,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek sysdb->ldb_ts_file,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek LDB_FLG_NOSYNC,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek &ldb);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (ret != EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "Could not reopen the timestamp ldb file (%d) (%s)\n",
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret, sss_strerror(ret));
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek break;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek case ERR_SYSDB_VERSION_TOO_NEW:
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "DB version too new [%s], expected [%s] for domain %s!\n",
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek version, SYSDB_TS_VERSION, domain->name);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek break;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek default:
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek break;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (ret != EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "The timestamps cache could not be opened. "
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "Throwing away the database and opening a new one\n");
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek ret = remove_ts_cache(sysdb);
3b67fc6488ac10ca13561d9032f59951f82203e6Jakub Hrozek if (ret != EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "Could not delete the timestamp ldb file (%d) (%s)\n",
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret, sss_strerror(ret));
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek return ret;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek /* Now the connect must succeed because the previous cache doesn't
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek * exist anymore.
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek */
b6d1cd5eaab4c7c73df8ee041944ec05630a9630Fabiano Fidêncio ret = sysdb_ts_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (ret != EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "Could not delete the timestamp ldb file (%d) (%s)\n",
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret, sss_strerror(ret));
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (ret == EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek sysdb->ldb_ts = talloc_steal(sysdb, ldb);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek talloc_free(tmp_ctx);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek return ret;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek}
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozekint sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct sss_domain_info *domain,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek const char *db_path,
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek struct sysdb_dom_upgrade_ctx *upgrade_ctx,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct sysdb_ctx **_ctx)
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek{
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek TALLOC_CTX *tmp_ctx = NULL;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek struct sysdb_ctx *sysdb;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek int ret;
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek tmp_ctx = talloc_new(NULL);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (tmp_ctx == NULL) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek return ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek sysdb = talloc_zero(mem_ctx, struct sysdb_ctx);
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek if (!sysdb) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = ENOMEM;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = sysdb_get_db_file(sysdb, domain->provider, domain->name, db_path,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek &sysdb->ldb_file, &sysdb->ldb_ts_file);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek DEBUG(SSSDBG_FUNC_DATA,
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek "DB File for %s: %s\n", domain->name, sysdb->ldb_file);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek if (sysdb->ldb_ts_file) {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek "Timestamp file for %s: %s\n", domain->name, sysdb->ldb_ts_file);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek ret = sysdb_domain_cache_connect(sysdb, domain, upgrade_ctx);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (ret != EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "Could not open the sysdb cache [%d]: %s\n",
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret, sss_strerror(ret));
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek goto done;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek ret = sysdb_timestamp_cache_connect(sysdb, domain, upgrade_ctx);
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek if (ret != EOK) {
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek "Could not open the timestamp cache [%d]: %s\n",
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek ret, sss_strerror(ret));
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek goto done;
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek }
f21b3cce14055e77af8ccb98dd8e0fa1ec1f7944Jakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozekdone:
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret == EOK) {
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek *_ctx = talloc_steal(mem_ctx, sysdb);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek talloc_free(tmp_ctx);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return ret;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozekint sysdb_init(TALLOC_CTX *mem_ctx,
ebbeac5c6b8b87ab478ee5a04ec48fbbba0c9efcJakub Hrozek struct sss_domain_info *domains)
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek{
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek return sysdb_init_ext(mem_ctx, domains, NULL, false, 0, 0);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozekint sysdb_init_ext(TALLOC_CTX *mem_ctx,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek struct sss_domain_info *domains,
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek struct sysdb_upgrade_ctx *upgrade_ctx,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek bool chown_dbfile,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek uid_t uid,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek gid_t gid)
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek{
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek struct sss_domain_info *dom;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek struct sysdb_ctx *sysdb;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek int ret;
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek TALLOC_CTX *tmp_ctx;
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek struct sysdb_dom_upgrade_ctx *dom_upgrade_ctx;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek if (upgrade_ctx != NULL) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* check if we have an old sssd.ldb to upgrade */
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek ret = sysdb_check_upgrade_02(domains, DB_PATH);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != EOK) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return ret;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek tmp_ctx = talloc_new(mem_ctx);
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek if (tmp_ctx == NULL) {
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek return ENOMEM;
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek }
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek /* open a db for each domain */
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek for (dom = domains; dom; dom = dom->next) {
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek if (upgrade_ctx) {
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek dom_upgrade_ctx = talloc_zero(tmp_ctx,
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek struct sysdb_dom_upgrade_ctx);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = sss_names_init(tmp_ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek upgrade_ctx->cdb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek dom->name,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek &dom_upgrade_ctx->names);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek } else {
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek dom_upgrade_ctx = NULL;
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek ret = sysdb_domain_init_internal(tmp_ctx, dom, DB_PATH,
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek dom_upgrade_ctx, &sysdb);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (ret != EOK) {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek "Cannot connect to database for %s: [%d]: %s\n",
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek dom->name, ret, sss_strerror(ret));
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek if (chown_dbfile) {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = sysdb_chown_db_files(sysdb, uid, gid);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek if (ret != EOK) {
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek "Cannot chown databases for %s: [%d]: %s\n",
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek dom->name, ret, sss_strerror(ret));
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek goto done;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek dom->sysdb = talloc_move(dom, &sysdb);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek }
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek ret = EOK;
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozekdone:
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek talloc_free(tmp_ctx);
6d66c2c465861ff2558f2574eddf8315628ccc6dJakub Hrozek return ret;
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek}
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozekint sysdb_domain_init(TALLOC_CTX *mem_ctx,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek struct sss_domain_info *domain,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek const char *db_path,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek struct sysdb_ctx **_ctx)
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek{
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek return sysdb_domain_init_internal(mem_ctx, domain,
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek db_path, false, _ctx);
6e9d7cbe43fdfc866b18f9ef0779bbfc10ad6f3aJakub Hrozek}