sss_ini.c revision a5f79cce8abc74beec0c27c477c046bb6cbe7101
/*
SSSD
Authors:
Ondrej Kos <okos@redhat.com>
Copyright (C) 2013 Red Hat
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 <stdio.h>
#include <errno.h>
#include <talloc.h>
#include "config.h"
#include "confdb/confdb_setup.h"
#include "confdb/confdb_private.h"
#ifdef HAVE_LIBINI_CONFIG_V1
#include "ini_configobj.h"
#elif defined(HAVE_LIBINI_CONFIG_V0)
#include "collection.h"
#include "collection_tools.h"
#else
#error "Unsupported libini version"
#endif
#include "ini_config.h"
#ifdef HAVE_LIBINI_CONFIG_V1
struct sss_ini_initdata {
char **error_list;
struct ini_cfgobj *sssd_config;
struct ini_cfgfile *file;
};
#elif defined(HAVE_LIBINI_CONFIG_V0)
struct sss_ini_initdata {
struct collection_item *error_list;
struct collection_item *sssd_config;
struct collection_item *obj;
int file;
};
#define sss_ini_get_sec_list get_section_list
#endif
/* Initialize data structure */
{
}
/* Close file descriptor */
{
#ifdef HAVE_LIBINI_CONFIG_V1
}
#elif defined(HAVE_LIBINI_CONFIG_V0)
}
#endif
}
/* Open configuration file */
const char *config_file)
{
#ifdef HAVE_LIBINI_CONFIG_V1
return ini_config_file_open(config_file,
#elif defined(HAVE_LIBINI_CONFIG_V0)
#endif
}
/* Check configuration file permissions */
{
#ifdef HAVE_LIBINI_CONFIG_V1
0, /* owned by root */
0, /* owned by root */
S_IRUSR, /* r**------ */
#elif defined(HAVE_LIBINI_CONFIG_V0)
return EOK;
#endif
}
/* Get cstat */
{
#ifdef HAVE_LIBINI_CONFIG_V1
return EOK;
#elif defined(HAVE_LIBINI_CONFIG_V0)
#endif
}
/* Get mtime */
char *timestr)
{
#ifdef HAVE_LIBINI_CONFIG_V1
#elif defined(HAVE_LIBINI_CONFIG_V0)
#endif
}
/* Print ini_config errors */
void sss_ini_config_print_errors(char **error_list)
{
#ifdef HAVE_LIBINI_CONFIG_V1
unsigned count = 0;
if (!error_list) {
return;
}
while (error_list[count]) {
count++;
}
#endif
return;
}
/* Load configuration */
const char *config_file)
{
int ret;
#ifdef HAVE_LIBINI_CONFIG_V1
/* Create config object */
"Failed to create config object. Error %d.\n", ret);
return ret;
}
/* Parse file */
"Failed to parse configuration. Error %d.\n", ret);
"Errors detected while parsing: %s\n",
&init_data->error_list);
}
return ret;
}
return ret;
#elif defined(HAVE_LIBINI_CONFIG_V0)
/* Read the configuration into a collection */
&init_data->error_list);
"Parse error reading configuration file [%s]\n",
return ret;
}
return EOK;
#endif
}
/* Get configuration object */
{
}
/* Check configuration object */
{
return ENOENT;
}
return EOK;
}
/* Get integer value */
{
#ifdef HAVE_LIBINI_CONFIG_V1
#elif defined(HAVE_LIBINI_CONFIG_V0)
#endif
}
/* Destroy ini config (v1) */
{
#ifdef HAVE_LIBINI_CONFIG_V1
}
#elif defined(HAVE_LIBINI_CONFIG_V0)
#endif
}
/* Create LDIF */
struct sss_ini_initdata *init_data,
const char **config_ldif)
{
int ret, i, j;
char *ldif;
char *tmp_ldif;
char **sections;
int section_count;
char *dn;
char *tmp_dn;
char *sec_dn;
char **attrs;
int attr_count;
char *ldif_attr;
#ifdef HAVE_LIBINI_CONFIG_V1
#elif defined(HAVE_LIBINI_CONFIG_V0)
#endif
if (!tmp_ctx) {
goto error;
}
/* Read in the collection and convert it to an LDIF */
/* Get the list of sections */
§ion_count, &ret);
goto error;
}
for (i = 0; i < section_count; i++) {
"Processing config section [%s]\n", sections[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++) {
"Processing attribute [%s]\n", attrs[j]);
"Attribute '%s' has empty value, ignoring\n",
attrs[j]);
continue;
}
if (!tmp_dn) {
goto error;
}
}
dn_size ++;
dn_size+1);
if (!tmp_dn) {
goto error;
}
if (!tmp_ldif) {
goto error;
}
}
*config_ldif = (const char *)ldif;
return EOK;
return ret;
}