confdb_setup.c revision 8b2a31634764168183506925a4b9f461afdba6f3
/*
SSSD
Configuration Database
Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 2009
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <unistd.h>
#include "confdb.h"
#include "confdb_private.h"
#include "confdb_setup.h"
#include "tools/tools_util.h"
{
char **values;
int ret;
"config",
"version",
&values);
return ret;
}
/* empty database, will need to init */
return ENOENT;
}
/* more than 1 value ?? */
return EIO;
}
/* Existing version does not match executable version */
values[0], CONFDB_VERSION);
/* This is recoverable, since we purge the confdb file
* when we re-initialize it.
*/
return ENOENT;
}
return EOK;
}
{
int ret, i;
struct ldb_result *res;
/* Get the list of all DNs */
if (ret != LDB_SUCCESS) {
goto done;
}
/* Delete this DN */
if (ret != LDB_SUCCESS) {
goto done;
}
}
done:
return ret;
}
{
int ret;
const char *base_ldif = CONFDB_BASE_LDIF;
if (ret != LDB_SUCCESS) {
"Failed to initialize DB (%d,[%s]), aborting!\n",
return EIO;
}
}
return EOK;
}
struct confdb_ctx *cdb)
{
int ret;
int version;
char timestr[21];
bool in_transaction = false;
const char *config_ldif;
struct sss_ini_initdata *init_data;
return ENOMEM;
}
if (!init_data) {
goto done;
}
/* Open config file */
ret);
/* Anything other than ENOENT is unrecoverable */
goto done;
} else {
/* Copy the default configuration file to the standard location
* and then retry
*/
0600,
getuid(),
getgid(),
false);
"Could not copy default configuration: %s",
sss_strerror(ret));
/* sss specific error denoting missing configuration file */
goto done;
}
/* Try again */
"sss_ini_config_file_open(default) failed: %s [%d]\n",
/* sss specific error denoting missing configuration file */
}
goto done;
}
}
}
"Permission check on config file failed.\n");
goto done;
}
"Status check on config file failed.\n");
goto done;
}
errno = 0;
"Failed to convert time_t to string ??\n");
}
/* FIXME: Determine if the conf file or any snippet has changed
* since we last updated the confdb or if some snippet was
* added or removed.
*/
goto done;
}
/* FIXME: Do not hardcode the path */
"/var/lib/sss/cfg_rules.ini");
/* This is not fatal, continue */
}
/* Make sure that the config file version matches the confdb version */
"Internal error determining config_file_version\n");
goto done;
}
/* No known version. Use default. */
"Value of config_file_version option not found. "
"Assumed to be version %d.\n", CONFDB_DEFAULT_CFG_FILE_VER);
} else {
-1, &ret);
"Config file version could not be determined\n");
goto done;
} else if (version < CONFDB_VERSION_INT) {
"Config file is an old version. "
"Please run configuration upgrade script.\n");
goto done;
} else if (version > CONFDB_VERSION_INT) {
"Config file version is newer than confdb\n");
goto done;
}
}
/* Set up a transaction to replace the configuration */
if (ret != LDB_SUCCESS) {
"Failed to start a transaction for "
"updating the configuration\n");
goto done;
}
in_transaction = true;
/* Purge existing database */
"Could not purge existing configuration\n");
goto done;
}
goto done;
}
if (ret != LDB_SUCCESS) {
"Failed to initialize DB (%d,[%s]), aborting!\n",
goto done;
}
}
/* now store the lastUpdate time so that we do not re-init if nothing
* changed on restart */
"Failed to set last update time on db!\n");
goto done;
}
goto done;
}
in_transaction = false;
done:
if (in_transaction) {
}
}
return ret;
}
const char *cdb_file,
const char *config_file,
const char *config_dir,
struct confdb_ctx **_cdb)
{
struct confdb_ctx *cdb;
return ENOMEM;
}
goto done;
}
/* Initialize the CDB from the configuration file */
/* First-time setup */
/* Purge any existing confdb in case an old
* misconfiguration gets in the way
*/
"Purging existing confdb failed: %d [%s].\n",
goto done;
}
}
/* Load special entries */
"Unable to load special entries into confdb\n");
goto done;
}
goto done;
}
goto done;
}
done:
return ret;
}