summaryrefslogtreecommitdiffstats
path: root/src/util/profile/prof_set.c
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2009-12-07 22:36:41 +0000
committerTom Yu <tlyu@mit.edu>2009-12-07 22:36:41 +0000
commitac911f663389980be59a0f9ee98f062e6c627658 (patch)
treec423ac7174c1a82a107013894a6944a506e68774 /src/util/profile/prof_set.c
parent741938feb12538b659a36d7e0329efe6a5550669 (diff)
downloadkrb5-ac911f663389980be59a0f9ee98f062e6c627658.tar.gz
krb5-ac911f663389980be59a0f9ee98f062e6c627658.tar.xz
krb5-ac911f663389980be59a0f9ee98f062e6c627658.zip
Mark and reindent util, with some exceptions
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23455 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/profile/prof_set.c')
-rw-r--r--src/util/profile/prof_set.c431
1 files changed, 216 insertions, 215 deletions
diff --git a/src/util/profile/prof_set.c b/src/util/profile/prof_set.c
index a08bfd7574..893048ffb9 100644
--- a/src/util/profile/prof_set.c
+++ b/src/util/profile/prof_set.c
@@ -1,6 +1,7 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prof_set.c --- routines that expose the public interfaces for
- * inserting, updating and deleting items from the profile.
+ * inserting, updating and deleting items from the profile.
*
* WARNING: These routines only look at the first file opened in the
* profile. It's not clear how to handle multiple files, actually.
@@ -22,55 +23,55 @@
static errcode_t rw_setup(profile_t profile)
{
- prf_file_t file;
- errcode_t retval = 0;
-
- if (!profile)
- return PROF_NO_PROFILE;
-
- if (profile->magic != PROF_MAGIC_PROFILE)
- return PROF_MAGIC_PROFILE;
-
- file = profile->first_file;
-
- retval = profile_lock_global();
- if (retval)
- return retval;
-
- /* Don't update the file if we've already made modifications */
- if (file->data->flags & PROFILE_FILE_DIRTY) {
- profile_unlock_global();
- return 0;
- }
-
- if ((file->data->flags & PROFILE_FILE_SHARED) != 0) {
- prf_data_t new_data;
- new_data = profile_make_prf_data(file->data->filespec);
- if (new_data == NULL) {
- retval = ENOMEM;
- } else {
- retval = k5_mutex_init(&new_data->lock);
- if (retval == 0) {
- new_data->root = NULL;
- new_data->flags = file->data->flags & ~PROFILE_FILE_SHARED;
- new_data->timestamp = 0;
- new_data->upd_serial = file->data->upd_serial;
- }
- }
-
- if (retval != 0) {
- profile_unlock_global();
- free(new_data);
- return retval;
- }
- profile_dereference_data_locked(file->data);
- file->data = new_data;
- }
-
- profile_unlock_global();
- retval = profile_update_file(file);
-
- return retval;
+ prf_file_t file;
+ errcode_t retval = 0;
+
+ if (!profile)
+ return PROF_NO_PROFILE;
+
+ if (profile->magic != PROF_MAGIC_PROFILE)
+ return PROF_MAGIC_PROFILE;
+
+ file = profile->first_file;
+
+ retval = profile_lock_global();
+ if (retval)
+ return retval;
+
+ /* Don't update the file if we've already made modifications */
+ if (file->data->flags & PROFILE_FILE_DIRTY) {
+ profile_unlock_global();
+ return 0;
+ }
+
+ if ((file->data->flags & PROFILE_FILE_SHARED) != 0) {
+ prf_data_t new_data;
+ new_data = profile_make_prf_data(file->data->filespec);
+ if (new_data == NULL) {
+ retval = ENOMEM;
+ } else {
+ retval = k5_mutex_init(&new_data->lock);
+ if (retval == 0) {
+ new_data->root = NULL;
+ new_data->flags = file->data->flags & ~PROFILE_FILE_SHARED;
+ new_data->timestamp = 0;
+ new_data->upd_serial = file->data->upd_serial;
+ }
+ }
+
+ if (retval != 0) {
+ profile_unlock_global();
+ free(new_data);
+ return retval;
+ }
+ profile_dereference_data_locked(file->data);
+ file->data = new_data;
+ }
+
+ profile_unlock_global();
+ retval = profile_update_file(file);
+
+ return retval;
}
@@ -81,50 +82,50 @@ static errcode_t rw_setup(profile_t profile)
*/
errcode_t KRB5_CALLCONV
profile_update_relation(profile_t profile, const char **names,
- const char *old_value, const char *new_value)
+ const char *old_value, const char *new_value)
{
- 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;
-
- if (!old_value || !*old_value)
- return PROF_EINVAL;
-
- 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, 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;
+ 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;
+
+ if (!old_value || !*old_value)
+ return PROF_EINVAL;
+
+ 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, 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;
}
/*
@@ -135,40 +136,40 @@ profile_update_relation(profile_t profile, const char **names,
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;
-
- 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;
+ 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;
+
+ 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;
}
/*
@@ -179,46 +180,46 @@ profile_clear_relation(profile_t profile, const char **names)
*/
errcode_t KRB5_CALLCONV
profile_rename_section(profile_t profile, const char **names,
- const char *new_name)
+ 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;
+ 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;
}
/*
@@ -232,54 +233,54 @@ profile_rename_section(profile_t profile, const char **names,
*/
errcode_t KRB5_CALLCONV
profile_add_relation(profile_t profile, const char **names,
- const char *new_value)
+ const char *new_value)
{
- errcode_t retval;
- struct profile_node *section;
- const char **cpp;
- void *state;
-
- 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 == PROF_NO_SECTION)
- retval = profile_add_node(section, *cpp, 0, &section);
- 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;
+ errcode_t retval;
+ struct profile_node *section;
+ const char **cpp;
+ void *state;
+
+ 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 == PROF_NO_SECTION)
+ retval = profile_add_node(section, *cpp, 0, &section);
+ 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;
}