Exemplo n.º 1
0
Arquivo: prof_set.c Projeto: WeiY/krb5
/*
 * Delete or update a particular child node
 *
 * ADL - 2/23/99, rewritten TYT 2/25/99
 */
errcode_t KRB5_CALLCONV
profile_update_relation(profile_t profile, const char **names,
                        const char *old_value, const char *new_value)
{
    errcode_t       retval;
    struct profile_node *section, *node;
    void            *state;
    const char      **cpp;

    if (profile->vt) {
        if (!profile->vt->update_relation)
            return PROF_UNSUPPORTED;
        return profile->vt->update_relation(profile->cbdata, names, old_value,
                                            new_value);
    }

    retval = rw_setup(profile);
    if (retval)
        return retval;

    if (names == 0 || names[0] == 0 || names[1] == 0)
        return PROF_BAD_NAMESET;

    if (!old_value || !*old_value)
        return PROF_EINVAL;

    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, &section);
        if (retval) {
            k5_mutex_unlock(&profile->first_file->data->lock);
            return retval;
        }
    }

    state = 0;
    retval = profile_find_node(section, *cpp, old_value, 0, &state, &node);
    if (retval == 0) {
        if (new_value)
            retval = profile_set_relation_value(node, new_value);
        else
            retval = profile_remove_node(node);
    }
    if (retval == 0)
        profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
    k5_mutex_unlock(&profile->first_file->data->lock);

    return retval;
}
Exemplo n.º 2
0
Arquivo: prof_set.c Projeto: WeiY/krb5
/*
 * Clear a particular all of the relations with a specific name.
 *
 * TYT - 2/25/99
 */
errcode_t KRB5_CALLCONV
profile_clear_relation(profile_t profile, const char **names)
{
    errcode_t       retval;
    struct profile_node *section, *node;
    void            *state;
    const char      **cpp;

    if (profile->vt) {
        if (!profile->vt->update_relation)
            return PROF_UNSUPPORTED;
        return profile->vt->update_relation(profile->cbdata, names, NULL,
                                            NULL);
    }

    retval = rw_setup(profile);
    if (retval)
        return retval;

    if (names == 0 || names[0] == 0 || names[1] == 0)
        return PROF_BAD_NAMESET;

    section = profile->first_file->data->root;
    for (cpp = names; cpp[1]; cpp++) {
        state = 0;
        retval = profile_find_node(section, *cpp, 0, 1,
                                   &state, &section);
        if (retval)
            return retval;
    }

    state = 0;
    do {
        retval = profile_find_node(section, *cpp, 0, 0, &state, &node);
        if (retval)
            return retval;
        retval = profile_remove_node(node);
        if (retval)
            return retval;
    } while (state);

    profile->first_file->data->flags |= PROFILE_FILE_DIRTY;

    return 0;
}
Exemplo n.º 3
0
/* 
 * Rename a particular section; if the new_section name is NULL,
 * delete it.
 * 
 * ADL - 2/23/99, rewritten TYT 2/25/99
 */
errcode_t KRB5_CALLCONV
profile_rename_section(profile_t profile, const char **names,
		       const char *new_name)
{	
	errcode_t	retval;
	struct profile_node *section, *node;
	void		*state;
	const char	**cpp;
	
	retval = rw_setup(profile);
	if (retval)
		return retval;
	
	if (names == 0 || names[0] == 0 || names[1] == 0)
		return PROF_BAD_NAMESET;

	retval = k5_mutex_lock(&profile->first_file->data->lock);
	if (retval)
	    return retval;
	section = profile->first_file->data->root;
	for (cpp = names; cpp[1]; cpp++) {
		state = 0;
		retval = profile_find_node(section, *cpp, 0, 1,
					   &state, &section);
		if (retval) {
		    k5_mutex_unlock(&profile->first_file->data->lock);
		    return retval;
		}
	}

	state = 0;
	retval = profile_find_node(section, *cpp, 0, 1, &state, &node);
	if (retval == 0) {
	    if (new_name)
		retval = profile_rename_node(node, new_name);
	    else
		retval = profile_remove_node(node);
	}
	if (retval == 0)
	    profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
	k5_mutex_unlock(&profile->first_file->data->lock);
	return retval;
}