allow the use of more than one config file by using the new function
krb5_config_parse_file_multi git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@11096 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -47,6 +47,29 @@ static krb5_error_code parse_list(FILE *f, unsigned *lineno,
|
|||||||
krb5_config_binding **parent,
|
krb5_config_binding **parent,
|
||||||
const char **error_message);
|
const char **error_message);
|
||||||
|
|
||||||
|
static krb5_config_section *
|
||||||
|
get_entry(krb5_config_section **parent, const char *name, int type)
|
||||||
|
{
|
||||||
|
krb5_config_section **q;
|
||||||
|
|
||||||
|
for(q = parent; *q != NULL; q = &(*q)->next)
|
||||||
|
if(type == krb5_config_list &&
|
||||||
|
type == (*q)->type &&
|
||||||
|
strcmp(name, (*q)->name) == 0)
|
||||||
|
return *q;
|
||||||
|
*q = calloc(1, sizeof(**q));
|
||||||
|
if(*q == NULL)
|
||||||
|
return NULL;
|
||||||
|
(*q)->name = strdup(name);
|
||||||
|
(*q)->type = type;
|
||||||
|
if((*q)->name == NULL) {
|
||||||
|
free(*q);
|
||||||
|
*q = NULL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return *q;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse a section:
|
* Parse a section:
|
||||||
*
|
*
|
||||||
@@ -75,23 +98,11 @@ parse_section(char *p, krb5_config_section **s, krb5_config_section **parent,
|
|||||||
return KRB5_CONFIG_BADFORMAT;
|
return KRB5_CONFIG_BADFORMAT;
|
||||||
}
|
}
|
||||||
*p1 = '\0';
|
*p1 = '\0';
|
||||||
tmp = malloc(sizeof(*tmp));
|
tmp = get_entry(parent, p + 1, krb5_config_list);
|
||||||
if (tmp == NULL) {
|
if(tmp == NULL) {
|
||||||
*error_message = "out of memory";
|
*error_message = "out of memory";
|
||||||
return KRB5_CONFIG_BADFORMAT;
|
return KRB5_CONFIG_BADFORMAT;
|
||||||
}
|
}
|
||||||
tmp->name = strdup(p+1);
|
|
||||||
if (tmp->name == NULL) {
|
|
||||||
*error_message = "out of memory";
|
|
||||||
return KRB5_CONFIG_BADFORMAT;
|
|
||||||
}
|
|
||||||
tmp->type = krb5_config_list;
|
|
||||||
tmp->u.list = NULL;
|
|
||||||
tmp->next = NULL;
|
|
||||||
if (*s)
|
|
||||||
(*s)->next = tmp;
|
|
||||||
else
|
|
||||||
*parent = tmp;
|
|
||||||
*s = tmp;
|
*s = tmp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -154,44 +165,40 @@ parse_binding(FILE *f, unsigned *lineno, char *p,
|
|||||||
while (*p && *p != '=' && !isspace((unsigned char)*p))
|
while (*p && *p != '=' && !isspace((unsigned char)*p))
|
||||||
++p;
|
++p;
|
||||||
if (*p == '\0') {
|
if (*p == '\0') {
|
||||||
*error_message = "no =";
|
*error_message = "missing =";
|
||||||
return KRB5_CONFIG_BADFORMAT;
|
return KRB5_CONFIG_BADFORMAT;
|
||||||
}
|
}
|
||||||
p2 = p;
|
p2 = p;
|
||||||
while (isspace((unsigned char)*p))
|
while (isspace((unsigned char)*p))
|
||||||
++p;
|
++p;
|
||||||
if (*p != '=') {
|
if (*p != '=') {
|
||||||
*error_message = "no =";
|
*error_message = "missing =";
|
||||||
return KRB5_CONFIG_BADFORMAT;
|
return KRB5_CONFIG_BADFORMAT;
|
||||||
}
|
}
|
||||||
++p;
|
++p;
|
||||||
while(isspace((unsigned char)*p))
|
while(isspace((unsigned char)*p))
|
||||||
++p;
|
++p;
|
||||||
tmp = malloc(sizeof(*tmp));
|
|
||||||
if (tmp == NULL) {
|
|
||||||
*error_message = "out of memory";
|
|
||||||
return KRB5_CONFIG_BADFORMAT;
|
|
||||||
}
|
|
||||||
*p2 = '\0';
|
*p2 = '\0';
|
||||||
tmp->name = strdup(p1);
|
|
||||||
tmp->next = NULL;
|
|
||||||
if (*p == '{') {
|
if (*p == '{') {
|
||||||
tmp->type = krb5_config_list;
|
tmp = get_entry(parent, p1, krb5_config_list);
|
||||||
tmp->u.list = NULL;
|
if (tmp == NULL) {
|
||||||
|
*error_message = "out of memory";
|
||||||
|
return KRB5_CONFIG_BADFORMAT;
|
||||||
|
}
|
||||||
ret = parse_list (f, lineno, &tmp->u.list, error_message);
|
ret = parse_list (f, lineno, &tmp->u.list, error_message);
|
||||||
} else {
|
} else {
|
||||||
|
tmp = get_entry(parent, p1, krb5_config_string);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
*error_message = "out of memory";
|
||||||
|
return KRB5_CONFIG_BADFORMAT;
|
||||||
|
}
|
||||||
p1 = p;
|
p1 = p;
|
||||||
p = p1 + strlen(p1);
|
p = p1 + strlen(p1);
|
||||||
while(p > p1 && isspace((unsigned char)*(p-1)))
|
while(p > p1 && isspace((unsigned char)*(p-1)))
|
||||||
--p;
|
--p;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
tmp->type = krb5_config_string;
|
|
||||||
tmp->u.string = strdup(p1);
|
tmp->u.string = strdup(p1);
|
||||||
}
|
}
|
||||||
if (*b)
|
|
||||||
(*b)->next = tmp;
|
|
||||||
else
|
|
||||||
*parent = tmp;
|
|
||||||
*b = tmp;
|
*b = tmp;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -221,7 +228,6 @@ krb5_config_parse_file_debug (const char *fname,
|
|||||||
*error_message = "cannot open file";
|
*error_message = "cannot open file";
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
*res = NULL;
|
|
||||||
while (fgets(buf, sizeof(buf), f) != NULL) {
|
while (fgets(buf, sizeof(buf), f) != NULL) {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@@ -255,9 +261,9 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
krb5_error_code
|
krb5_error_code
|
||||||
krb5_config_parse_file (krb5_context context,
|
krb5_config_parse_file_multi (krb5_context context,
|
||||||
const char *fname,
|
const char *fname,
|
||||||
krb5_config_section **res)
|
krb5_config_section **res)
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
unsigned lineno;
|
unsigned lineno;
|
||||||
@@ -271,6 +277,15 @@ krb5_config_parse_file (krb5_context context,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
krb5_error_code
|
||||||
|
krb5_config_parse_file (krb5_context context,
|
||||||
|
const char *fname,
|
||||||
|
krb5_config_section **res)
|
||||||
|
{
|
||||||
|
*res = NULL;
|
||||||
|
return krb5_config_parse_file_multi(context, fname, res);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* !HAVE_NETINFO */
|
#endif /* !HAVE_NETINFO */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -316,6 +331,29 @@ krb5_config_get_next (krb5_context context,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const void *
|
||||||
|
vget_next(krb5_context context,
|
||||||
|
const krb5_config_binding *b,
|
||||||
|
const krb5_config_binding **pointer,
|
||||||
|
int type,
|
||||||
|
const char *name,
|
||||||
|
va_list args)
|
||||||
|
{
|
||||||
|
const char *p = va_arg(args, const char *);
|
||||||
|
while(b != NULL) {
|
||||||
|
if(strcmp(b->name, name) == NULL) {
|
||||||
|
if(b->type == type && p == NULL) {
|
||||||
|
*pointer = b;
|
||||||
|
return b->u.generic;
|
||||||
|
} else if(b->type == krb5_config_list && p != NULL) {
|
||||||
|
return vget_next(context, b->u.list, pointer, type, p, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b = b->next;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
const void *
|
const void *
|
||||||
krb5_config_vget_next (krb5_context context,
|
krb5_config_vget_next (krb5_context context,
|
||||||
const krb5_config_section *c,
|
const krb5_config_section *c,
|
||||||
@@ -333,32 +371,20 @@ krb5_config_vget_next (krb5_context context,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (*pointer == NULL) {
|
if (*pointer == NULL) {
|
||||||
b = (c != NULL) ? c : context->cf;
|
/* first time here, walk down the tree looking for the right
|
||||||
|
section */
|
||||||
p = va_arg(args, const char *);
|
p = va_arg(args, const char *);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
return vget_next(context, c, pointer, type, p, args);
|
||||||
b = *pointer;
|
|
||||||
p = b->name;
|
|
||||||
b = b->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (b) {
|
/* we were called again, so just look for more entries with the
|
||||||
if (strcmp (b->name, p) == 0) {
|
same name and type */
|
||||||
if (*pointer == NULL)
|
for (b = (*pointer)->next; b != NULL; b = b->next) {
|
||||||
p = va_arg(args, const char *);
|
if(strcmp(b->name, (*pointer)->name) == 0 && b->type == type) {
|
||||||
else
|
*pointer = b;
|
||||||
p = NULL;
|
return b->u.generic;
|
||||||
if (type == b->type && p == NULL) {
|
|
||||||
*pointer = b;
|
|
||||||
return b->u.generic;
|
|
||||||
} else if(b->type == krb5_config_list && p != NULL) {
|
|
||||||
b = b->u.list;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
b = b->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user