confdb_setup.c revision e16c6e35fc3afa903e522114115c5ac1987a902a
/*
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 "confdb.h"
#include "confdb_private.h"
#include "confdb_setup.h"
#include "collection.h"
#include "collection_tools.h"
#include "ini_config.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) {
DEBUG(0, ("Failed to initialize DB (%d,[%s]), aborting!\n",
return EIO;
}
}
return EOK;
}
struct collection_item *sssd_config,
char **config_ldif)
{
int ret, i, j;
char *ldif;
char *tmp_ldif;
char *writer;
char **sections;
int section_count;
char *dn;
char *tmp_dn;
char *sec_dn;
char **attrs;
int attr_count;
char *ldif_attr;
struct collection_item *attr;
if (!tmp_ctx) {
goto error;
}
/* Read in the collection and convert it to an LDIF */
/* Get the list of sections */
goto error;
}
for(i = 0; i < section_count; i++) {
goto error;
}
"dn: %s,cn=config\n"
"cn: %s\n",
if(!dn) {
goto error;
}
/* Get all of the attributes and their values as LDIF */
&attr_count, &ret);
goto error;
}
for(j = 0; j < attr_count; j++) {
&attr);
if(!tmp_dn) {
goto error;
}
}
dn_size ++;
dn_size+1);
if(!tmp_dn) {
goto error;
}
if(!tmp_ldif) {
goto error;
}
}
*config_ldif = ldif;
return EOK;
return ret;
}
{
int ret, i;
int fd = -1;
char *config_ldif;
int version;
return EPERM;
}
/* Determine if the conf file has changed since we last updated
* the confdb
*/
if (ret != 0) {
DEBUG(0, ("Unable to stat config file [%s]! (%d [%s])\n",
return errno;
}
DEBUG(0, ("Failed to convert time_t to string ??\n"));
}
/* check if we need to re-init the db */
/* now check if we lastUpdate and last file modification change differ*/
/* not changed, get out, nothing more to do */
return EOK;
}
}
/* Set up a transaction to replace the configuration */
if (ret != LDB_SUCCESS) {
DEBUG(0, ("Failed to start a transaction for updating the configuration\n"));
return sysdb_error_to_errno(ret);
}
/* Purge existing database */
DEBUG(0, ("Could not purge existing configuration\n"));
goto done;
}
/* Read the configuration into a collection */
DEBUG(0, ("Parse error reading configuration file [%s]\n",
config_file));
goto done;
}
/* Make sure that the config file version matches the confdb version */
sssd_config, &item);
DEBUG(0, ("Internal error determining config_file_version\n"));
goto done;
}
/* No known version. Assumed to be version 1 */
DEBUG(0, ("Config file is an old version. "
"Please run configuration upgrade script.\n"));
goto done;
}
DEBUG(0, ("Config file version could not be determined\n"));
goto done;
} else if (version < CONFDB_VERSION_INT) {
DEBUG(0, ("Config file is an old version. "
"Please run configuration upgrade script.\n"));
goto done;
} else if (version > CONFDB_VERSION_INT) {
DEBUG(0, ("Config file version is newer than confdb\n"));
goto done;
}
DEBUG(0, ("Could not create LDIF for confdb\n"));
goto done;
}
i=0;
if (ret != LDB_SUCCESS) {
DEBUG(0, ("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 */
}
done:
return ret;
}