/* * Insert a new relation. If the new_value argument is NULL, then * create a new section instead. * * Note: if the intermediate sections do not exist, this function will * automatically create them. * * ADL - 2/23/99, rewritten TYT 2/25/99 */ errcode_t KRB5_CALLCONV profile_add_relation(profile_t profile, const char **names, const char *new_value) { errcode_t retval; struct profile_node *section; const char **cpp; void *state; if (profile->vt) { if (!profile->vt->add_relation) return PROF_UNSUPPORTED; return profile->vt->add_relation(profile->cbdata, names, new_value); } retval = rw_setup(profile); if (retval) return retval; if (names == 0 || names[0] == 0 || names[1] == 0) return PROF_BAD_NAMESET; k5_mutex_lock(&profile->first_file->data->lock); section = profile->first_file->data->root; for (cpp = names; cpp[1]; cpp++) { state = 0; retval = profile_find_node(section, *cpp, 0, 1, &state, §ion); if (retval == PROF_NO_SECTION) retval = profile_add_node(section, *cpp, 0, §ion); if (retval) { k5_mutex_unlock(&profile->first_file->data->lock); return retval; } } if (new_value == 0) { retval = profile_find_node(section, *cpp, 0, 1, &state, 0); if (retval == 0) { k5_mutex_unlock(&profile->first_file->data->lock); return PROF_EXISTS; } else if (retval != PROF_NO_SECTION) { k5_mutex_unlock(&profile->first_file->data->lock); return retval; } } retval = profile_add_node(section, *cpp, new_value, 0); if (retval) { k5_mutex_unlock(&profile->first_file->data->lock); return retval; } profile->first_file->data->flags |= PROFILE_FILE_DIRTY; k5_mutex_unlock(&profile->first_file->data->lock); return 0; }
static errcode_t parse_std_line(char *line, struct parse_state *state) { char *cp, ch, *tag, *value; char *p; errcode_t retval; struct profile_node *node; int do_subsection = 0; void *iter = 0; if (*line == 0) return 0; cp = skip_over_blanks(line); if (cp[0] == ';' || cp[0] == '#') return 0; strip_line(cp); ch = *cp; if (ch == 0) return 0; if (ch == '[') { if (state->group_level > 0) return PROF_SECTION_NOTOP; cp++; p = strchr(cp, ']'); if (p == NULL) return PROF_SECTION_SYNTAX; *p = '\0'; retval = profile_find_node_subsection(state->root_section, cp, &iter, 0, &state->current_section); if (retval == PROF_NO_SECTION) { retval = profile_add_node(state->root_section, cp, 0, &state->current_section); if (retval) return retval; } else if (retval) return retval; /* * Finish off the rest of the line. */ cp = p+1; if (*cp == '*') { profile_make_node_final(state->current_section); cp++; } /* * A space after ']' should not be fatal */ cp = skip_over_blanks(cp); if (*cp) return PROF_SECTION_SYNTAX; return 0; } if (ch == '}') { if (state->group_level == 0) return PROF_EXTRA_CBRACE; if (*(cp+1) == '*') profile_make_node_final(state->current_section); retval = profile_get_node_parent(state->current_section, &state->current_section); if (retval) return retval; state->group_level--; return 0; } /* * Parse the relations */ tag = cp; cp = strchr(cp, '='); if (!cp) return PROF_RELATION_SYNTAX; if (cp == tag) return PROF_RELATION_SYNTAX; *cp = '\0'; p = tag; /* Look for whitespace on left-hand side. */ while (p < cp && !isspace((int)*p)) p++; if (p < cp) { /* Found some sort of whitespace. */ *p++ = 0; /* If we have more non-whitespace, it's an error. */ while (p < cp) { if (!isspace((int)*p)) return PROF_RELATION_SYNTAX; p++; } } cp = skip_over_blanks(cp+1); value = cp; if (value[0] == '"') { value++; parse_quoted_string(value); } else if (value[0] == 0) { do_subsection++; state->state = STATE_GET_OBRACE; } else if (value[0] == '{' && *(skip_over_blanks(value+1)) == 0) do_subsection++; else { cp = value + strlen(value) - 1; while ((cp > value) && isspace((int) (*cp))) *cp-- = 0; } if (do_subsection) { p = strchr(tag, '*'); if (p) *p = '\0'; retval = profile_add_node(state->current_section, tag, 0, &state->current_section); if (retval) return retval; if (p) profile_make_node_final(state->current_section); state->group_level++; return 0; } p = strchr(tag, '*'); if (p) *p = '\0'; profile_add_node(state->current_section, tag, value, &node); if (p) profile_make_node_final(node); return 0; }
static long parse_line(char *line, struct parse_state *state) { char *cp, ch, *tag, *value; char *p; long retval; struct profile_node *node; int do_subsection = 0; void *iter = 0; state->line_num++; if (state->state == STATE_GET_OBRACE) { cp = skip_over_blanks(line); if (*cp != '{') return PROF_MISSING_OBRACE; state->state = STATE_STD_LINE; return 0; } if (state->state == STATE_INIT_COMMENT) { if (line[0] != '[') return 0; state->state = STATE_STD_LINE; } if (*line == 0) return 0; strip_line(line); cp = skip_over_blanks(line); ch = *cp; if (end_or_comment(ch)) return 0; if (ch == '[') { if (state->group_level > 0) return PROF_SECTION_NOTOP; cp++; cp = skip_over_blanks(cp); p = strchr(cp, ']'); if (p == NULL) return PROF_SECTION_SYNTAX; if (*cp == '"') { cp++; parse_quoted_string(cp); } else { *p-- = '\0'; while (isspace(*p) && (p > cp)) *p-- = '\0'; if (*cp == 0) return PROF_SECTION_SYNTAX; } retval = profile_find_node(state->root_section, cp, 0, 1, &iter, &state->current_section); if (retval == PROF_NO_SECTION) { retval = profile_add_node(state->root_section, cp, 0, &state->current_section); if (retval) return retval; } else if (retval) return retval; /* * Finish off the rest of the line. */ cp = p+1; if (*cp == '*') { state->current_section->final = 1; cp++; } /* * Spaces or comments after ']' should not be fatal */ cp = skip_over_blanks(cp); if (!end_or_comment(*cp)) return PROF_SECTION_SYNTAX; return 0; }