summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiro Jurisic <meeroh@mit.edu>2000-03-24 21:09:05 +0000
committerMiro Jurisic <meeroh@mit.edu>2000-03-24 21:09:05 +0000
commit97971c69b9389be08b7e9ffb742ca35f3706b3af (patch)
tree7e2aa6645f39eb871eb7535012a37496c855c386 /src
parent01ac697ddf4103d59dc940c124c2834ab42e7348 (diff)
downloadkrb5-97971c69b9389be08b7e9ffb742ca35f3706b3af.tar.gz
krb5-97971c69b9389be08b7e9ffb742ca35f3706b3af.tar.xz
krb5-97971c69b9389be08b7e9ffb742ca35f3706b3af.zip
Added profile_get_boolean
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@12136 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/util/profile/ChangeLog8
-rw-r--r--src/util/profile/prof_err.et6
-rw-r--r--src/util/profile/prof_get.c78
-rw-r--r--src/util/profile/profile.exp1
-rw-r--r--src/util/profile/profile.hin5
5 files changed, 97 insertions, 1 deletions
diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog
index aec9f22fa..d30a26b31 100644
--- a/src/util/profile/ChangeLog
+++ b/src/util/profile/ChangeLog
@@ -1,3 +1,11 @@
+2000-03-24 Miro Jurisic <meeroh@mit.edu>
+
+ * prof_get.c: Added prof_get_boolean and changed prof_get_integer
+ to return errors for malformed input
+ * prof.hin: Added prof_get_boolean
+ * profile.exp: Added prof_get_boolean
+ * prof_err.et: Added PROF_BAD_BOOLEAN, PROF_BAD_INTEGER
+
Fri Jan 28 16:27:01 2000 Ezra Peisach <epeisach@mit.edu>
* argv_parse.c: Include string.h (for strlen prototype)
diff --git a/src/util/profile/prof_err.et b/src/util/profile/prof_err.et
index e6e35db0a..dc248f417 100644
--- a/src/util/profile/prof_err.et
+++ b/src/util/profile/prof_err.et
@@ -54,4 +54,10 @@ error_code PROF_FAIL_OPEN, "Couldn't open profile file"
#
error_code PROF_EXISTS, "Section already exists"
+#
+# generated by prof_get.c
+#
+error_code PROF_BAD_BOOLEAN, "Invalid boolean value"
+error_code PROF_BAD_INTEGER, "Invalid integer value"
+
end
diff --git a/src/util/profile/prof_get.c b/src/util/profile/prof_get.c
index 2589b24e4..cf8cef41f 100644
--- a/src/util/profile/prof_get.c
+++ b/src/util/profile/prof_get.c
@@ -252,6 +252,8 @@ profile_get_integer(profile, name, subname, subsubname,
const char *value;
errcode_t retval;
const char *names[4];
+ const char *end_value;
+ long ret_long;
if (profile == 0) {
*ret_int = def_val;
@@ -268,11 +270,85 @@ profile_get_integer(profile, name, subname, subsubname,
return 0;
} else if (retval)
return retval;
+
+ ret_long = strtol (value, &end_value, 10);
+ if ((errno != 0) || (end_value != value + strlen (value)) ||
+ (end_value == value) || (ret_long > INT_MAX) ||
+ (ret_long < INT_MIN)) {
+ return PROF_BAD_INTEGER;
+ }
+
- *ret_int = atoi(value);
+ *ret_int = ret_long;
return 0;
}
+static char *conf_yes[] = {
+ "y", "yes", "true", "t", "1", "on",
+ 0,
+};
+
+static char *conf_no[] = {
+ "n", "no", "false", "nil", "0", "off",
+ 0,
+};
+
+static errcode_t
+profile_parse_boolean(s, ret_boolean)
+ char *s;
+ int* ret_boolean;
+{
+ char **p;
+
+ if (ret_boolean == NULL)
+ return PROF_EINVAL;
+
+ for(p=conf_yes; *p; p++) {
+ if (!strcasecmp(*p,s))
+ *ret_boolean = 1;
+ return 0;
+ }
+
+ for(p=conf_no; *p; p++) {
+ if (!strcasecmp(*p,s))
+ *ret_boolean = 0;
+ return 0;
+ }
+
+ return PROF_BAD_BOOLEAN;
+}
+
+KRB5_DLLIMP errcode_t KRB5_CALLCONV
+profile_get_boolean(profile, name, subname, subsubname,
+ def_val, ret_boolean)
+ profile_t profile;
+ const char *name, *subname, *subsubname;
+ int def_val;
+ int *ret_int;
+{
+ const char *value;
+ errcode_t retval;
+ const char *names[4];
+
+ if (profile == 0) {
+ *ret_int = def_val;
+ return 0;
+ }
+
+ names[0] = name;
+ names[1] = subname;
+ names[2] = subsubname;
+ names[3] = 0;
+ retval = profile_get_value(profile, names, &value);
+ if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) {
+ *ret_int = def_val;
+ return 0;
+ } else if (retval)
+ return retval;
+
+ return prof_parse_boolean (value, ret_int);
+}
+
/*
* This function will return the list of the names of subections in the
* under the specified section name.
diff --git a/src/util/profile/profile.exp b/src/util/profile/profile.exp
index 3eaeb1dfd..ade672adc 100644
--- a/src/util/profile/profile.exp
+++ b/src/util/profile/profile.exp
@@ -11,6 +11,7 @@ profile_release
profile_get_values
profile_free_list
profile_get_string
+profile_get_boolean
profile_get_integer
profile_get_relation_names
profile_get_subsection_names
diff --git a/src/util/profile/profile.hin b/src/util/profile/profile.hin
index f681f36f4..863f60d55 100644
--- a/src/util/profile/profile.hin
+++ b/src/util/profile/profile.hin
@@ -95,6 +95,11 @@ KRB5_DLLIMP long KRB5_CALLCONV profile_get_integer
const char *subsubname, int def_val,
int *ret_default));
+KRB5_DLLIMP long KRB5_CALLCONV profile_get_boolean
+ PROTOTYPE((profile_t profile, const char *name, const char *subname,
+ const char *subsubname, int def_val,
+ int *ret_default));
+
KRB5_DLLIMP long KRB5_CALLCONV profile_get_relation_names
PROTOTYPE((profile_t profile, const char **names, char ***ret_names));