sss_ini.c revision 199984c7972272f8162a356cda139c22f6f08556
/*
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"
#else
#include "collection.h"
#include "collection_tools.h"
#endif
#include "ini_config.h"
#ifdef HAVE_LIBINI_CONFIG_V1
struct sss_ini_initdata {
char **error_list;
struct ref_array *ra_success_list;
struct ref_array *ra_error_list;
struct ini_cfgobj *sssd_config;
struct ini_cfgfile *file;
};
#else
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
}
#else
}
#endif
}
/* Open configuration file */
const char *config_file)
{
#ifdef HAVE_LIBINI_CONFIG_V1
return ini_config_file_open(config_file,
#else
#endif
}
/* Check configuration file permissions */
{
#ifdef HAVE_LIBINI_CONFIG_V1
0, /* owned by root */
0, /* owned by root */
S_IRUSR, /* r**------ */
#else
return EOK;
#endif
}
/* Get cstat */
{
#ifdef HAVE_LIBINI_CONFIG_V1
return EOK;
#else
#endif
}
/* Get mtime */
char *timestr)
{
#ifdef HAVE_LIBINI_CONFIG_V1
#else
#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,
const char *config_dir)
{
int ret;
#ifdef HAVE_LIBINI_CONFIG_V1
#ifdef HAVE_LIBINI_CONFIG_V1_3
uint32_t i = 0;
struct access_check snip_check;
#endif /* HAVE_LIBINI_CONFIG_V1_3 */
/* 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;
}
#ifdef HAVE_LIBINI_CONFIG_V1_3
"Failed to augment configuration [%d]: %s",
}
"Config merge success: %s\n", msg);
i++;
}
i = 0;
"Config merge error: %s\n", msg);
i++;
}
/* switch config objects if there are no errors */
if (modified_sssd_config != NULL) {
} else {
"Using only main configuration file due to errors in merging\n");
}
#endif
return ret;
#else
/* Read the configuration into a collection */
&init_data->error_list);
"Parse error reading configuration file [%s]\n",
return ret;
}
return EOK;
#endif
}
struct ref_array *
{
#ifdef HAVE_LIBINI_CONFIG_V1_3
return init_data->ra_success_list;
#else
return NULL;
#endif /* HAVE_LIBINI_CONFIG_V1_3 */
}
struct ref_array *
{
#ifdef HAVE_LIBINI_CONFIG_V1_3
return init_data->ra_error_list;
#else
return NULL;
#endif /* HAVE_LIBINI_CONFIG_V1_3 */
}
/* Get configuration object */
{
}
/* Check configuration object */
{
return ENOENT;
}
return EOK;
}
/* Get integer value */
{
#ifdef HAVE_LIBINI_CONFIG_V1
#else
#endif
}
/* Destroy ini config (v1) */
{
#ifdef HAVE_LIBINI_CONFIG_V1
}
#else
#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
#else
#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;
}
#ifdef HAVE_LIBINI_CONFIG_V1_3
const char *rules_path,
struct ini_errobj *errobj)
{
int ret;
goto done;
}
goto done;
}
done:
return ret;
}
#endif /* HAVE_LIBINI_CONFIG_V1_3 */
const char *rules_path)
{
#ifdef HAVE_LIBINI_CONFIG_V1_3
int ret;
goto done;
}
errobj);
"Failed to get errors from validators.\n");
goto done;
}
/* Do not error out when validators find some issue */
while (!ini_errobj_no_more_msgs(errobj)) {
}
done:
return ret;
#else
"libini_config does not support configuration file validataion\n");
return EOK;
#endif /* HAVE_LIBINI_CONFIG_V1_3 */
}
struct sss_ini_initdata *data,
const char *rules_path,
char ***_errors,
{
#ifdef HAVE_LIBINI_CONFIG_V1_3
int ret;
return EINVAL;
}
return ENOMEM;
}
goto done;
}
errobj);
goto done;
}
if (num_errors == 0) {
goto done;
}
goto done;
}
for (int i = 0; i < num_errors; i++) {
goto done;
}
}
done:
return ret;
#else
"libini_config does not support configuration file validataion\n");
return EINVAL;
}
_num_errors = 0;
return EOK;
#endif /* HAVE_LIBINI_CONFIG_V1_3 */
}