Better return values on error.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1257 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -130,44 +130,44 @@ value : STRING
|
||||
|
||||
static int yylex(void)
|
||||
{
|
||||
int c;
|
||||
static char save;
|
||||
static char yytext[1024];
|
||||
char *p = yytext;
|
||||
int type = 0;
|
||||
while(1){
|
||||
if(save){
|
||||
c = save;
|
||||
save = 0;
|
||||
}else
|
||||
c = getc(F);
|
||||
if(c == EOF)
|
||||
break;
|
||||
if(isspace(c))
|
||||
if(type)
|
||||
break; /* end of token */
|
||||
else
|
||||
continue; /* eat ws */
|
||||
if(strchr("[]={}", c)){
|
||||
if(type)
|
||||
save = c;
|
||||
else{
|
||||
return c;
|
||||
}
|
||||
break;
|
||||
int c;
|
||||
static char save;
|
||||
static char yytext[1024];
|
||||
char *p = yytext;
|
||||
int type = 0;
|
||||
while(1){
|
||||
if(save){
|
||||
c = save;
|
||||
save = 0;
|
||||
}else
|
||||
c = getc(F);
|
||||
if(c == EOF)
|
||||
break;
|
||||
if(isspace(c))
|
||||
if(type)
|
||||
break; /* end of token */
|
||||
else
|
||||
continue; /* eat ws */
|
||||
if(strchr("[]={}", c)){
|
||||
if(type)
|
||||
save = c;
|
||||
else{
|
||||
return c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*p++ = c;
|
||||
type = STRING;
|
||||
continue;
|
||||
}
|
||||
*p++ = c;
|
||||
type = STRING;
|
||||
continue;
|
||||
}
|
||||
*p = 0;
|
||||
yylval.s = strdup(yytext);
|
||||
return type;
|
||||
*p = 0;
|
||||
yylval.s = strdup(yytext);
|
||||
return type;
|
||||
}
|
||||
|
||||
void yyerror(char *s)
|
||||
{
|
||||
printf("yyerror: %s\n", s);
|
||||
printf("yyerror: %s\n", s);
|
||||
}
|
||||
|
||||
|
||||
@@ -176,10 +176,10 @@ void yyerror(char *s)
|
||||
static void
|
||||
free_config_file(k5_cfile *cf)
|
||||
{
|
||||
if(!cf)
|
||||
return;
|
||||
FREE(cf->filename);
|
||||
free(cf);
|
||||
if(!cf)
|
||||
return;
|
||||
FREE(cf->filename);
|
||||
free(cf);
|
||||
}
|
||||
|
||||
static void free_config_relation(krb5_config_relation *rel);
|
||||
@@ -187,95 +187,95 @@ static void free_config_relation(krb5_config_relation *rel);
|
||||
static void
|
||||
free_config_value(krb5_config_value val)
|
||||
{
|
||||
if(val.type == krb5_config_value_string)
|
||||
FREE(val.data.string);
|
||||
else if(val.type == krb5_config_value_list)
|
||||
free_config_relation(val.data.relations);
|
||||
else
|
||||
fprintf(stderr, "free_config_value: krb5_config_value "
|
||||
"with bad type passed (%d)\n", val.type);
|
||||
if(val.type == krb5_config_value_string)
|
||||
FREE(val.data.string);
|
||||
else if(val.type == krb5_config_value_list)
|
||||
free_config_relation(val.data.relations);
|
||||
else
|
||||
fprintf(stderr, "free_config_value: krb5_config_value "
|
||||
"with bad type passed (%d)\n", val.type);
|
||||
}
|
||||
|
||||
static void
|
||||
free_config_relation(krb5_config_relation *rel)
|
||||
{
|
||||
if(!rel)
|
||||
return;
|
||||
free_config_value(rel->value);
|
||||
free_config_relation(rel->next);
|
||||
FREE(rel);
|
||||
if(!rel)
|
||||
return;
|
||||
free_config_value(rel->value);
|
||||
free_config_relation(rel->next);
|
||||
FREE(rel);
|
||||
}
|
||||
|
||||
static void
|
||||
free_config_section(krb5_config_section *sec)
|
||||
{
|
||||
if(!sec)
|
||||
return;
|
||||
FREE(sec->name);
|
||||
free_config_relation(sec->relations);
|
||||
free_config_section(sec->next);
|
||||
FREE(sec);
|
||||
if(!sec)
|
||||
return;
|
||||
FREE(sec->name);
|
||||
free_config_relation(sec->relations);
|
||||
free_config_section(sec->next);
|
||||
FREE(sec);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
krb5_free_config_file(k5_cfile *cf)
|
||||
{
|
||||
free_config_file(cf);
|
||||
free_config_file(cf);
|
||||
}
|
||||
|
||||
krb5_error_code
|
||||
krb5_get_config_tag(k5_cfile *cf, const char *tag, char **value)
|
||||
{
|
||||
char *str;
|
||||
char *p;
|
||||
krb5_config_section *s;
|
||||
krb5_config_relation *r;
|
||||
char *str;
|
||||
char *p;
|
||||
krb5_config_section *s;
|
||||
krb5_config_relation *r;
|
||||
|
||||
str = strdup(tag);
|
||||
p = strtok(str, " \t");
|
||||
if(!p)
|
||||
return ENOENT;
|
||||
for(s = cf->sections; s; s = s->next){
|
||||
if(!strcmp(s->name, p)){
|
||||
p = strtok(NULL, " \t");
|
||||
for(r = s->relations; r;){
|
||||
if(!strcmp(r->tag, p)){
|
||||
if(r->value.type == krb5_config_value_string){
|
||||
*value = strdup(r->value.data.string);
|
||||
free(str);
|
||||
return 0;
|
||||
}else{
|
||||
str = strdup(tag);
|
||||
p = strtok(str, " \t");
|
||||
if(!p)
|
||||
return KRB5_REALM_UNKNOWN;
|
||||
for(s = cf->sections; s; s = s->next){
|
||||
if(!strcmp(s->name, p)){
|
||||
p = strtok(NULL, " \t");
|
||||
r = r->value.data.relations;
|
||||
continue;
|
||||
}
|
||||
for(r = s->relations; r;){
|
||||
if(!strcmp(r->tag, p)){
|
||||
if(r->value.type == krb5_config_value_string){
|
||||
*value = strdup(r->value.data.string);
|
||||
free(str);
|
||||
return 0;
|
||||
}else{
|
||||
p = strtok(NULL, " \t");
|
||||
r = r->value.data.relations;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
r = r->next;
|
||||
}
|
||||
}
|
||||
r = r->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ENOENT;
|
||||
return KRB5_REALM_UNKNOWN;
|
||||
}
|
||||
|
||||
krb5_error_code
|
||||
krb5_parse_config_file(k5_cfile **cfile, const char *filename)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
if(!filename)
|
||||
filename = krb5_config_file;
|
||||
F = fopen(filename, "r");
|
||||
if(F == NULL)
|
||||
return errno;
|
||||
cf = ALLOC(1, k5_cfile);
|
||||
if(!cf)
|
||||
krb5_error_code ret;
|
||||
if(!filename)
|
||||
filename = krb5_config_file;
|
||||
F = fopen(filename, "r");
|
||||
if(F == NULL)
|
||||
return errno;
|
||||
cf = ALLOC(1, k5_cfile);
|
||||
if(!cf)
|
||||
return ENOMEM;
|
||||
ret = yyparse();
|
||||
ret = yyparse();
|
||||
|
||||
fclose(F);
|
||||
if(ret)
|
||||
fclose(F);
|
||||
if(ret)
|
||||
krb5_free_config_file(cf);
|
||||
else
|
||||
else
|
||||
*cfile = cf;
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user