krb5 commit: Clean up style of alt_prof.c

Greg Hudson ghudson at MIT.EDU
Sat Jan 12 00:22:09 EST 2013


https://github.com/krb5/krb5/commit/5c57e1b32b9ba7159207ba8086656ec27bf7d156
commit 5c57e1b32b9ba7159207ba8086656ec27bf7d156
Author: Greg Hudson <ghudson at mit.edu>
Date:   Sat Jan 12 00:21:07 2013 -0500

    Clean up style of alt_prof.c
    
    Get rid of K&R-style function headers, format code and comments
    consistently according to current conventions, rename some variables
    using idiomatic names, and de-indent some nested control blocks.

 src/lib/kadm5/alt_prof.c |  771 +++++++++++++++++++++-------------------------
 1 files changed, 354 insertions(+), 417 deletions(-)

diff --git a/src/lib/kadm5/alt_prof.c b/src/lib/kadm5/alt_prof.c
index 4b6bf80..e527cd4 100644
--- a/src/lib/kadm5/alt_prof.c
+++ b/src/lib/kadm5/alt_prof.c
@@ -37,48 +37,42 @@
 #include <ctype.h>
 #include <kdb_log.h>
 
-static krb5_key_salt_tuple *copy_key_salt_tuple(ksalt, len)
-    krb5_key_salt_tuple *ksalt;
-    krb5_int32 len;
+static krb5_key_salt_tuple *
+copy_key_salt_tuple(krb5_key_salt_tuple *ksalt, krb5_int32 len)
 {
     krb5_key_salt_tuple *knew;
 
-    if((knew = (krb5_key_salt_tuple *)
-        malloc((len ) * sizeof(krb5_key_salt_tuple)))) {
-        memcpy(knew, ksalt, len * sizeof(krb5_key_salt_tuple));
-        return knew;
-    }
-    return 0;
+    knew = calloc(len, sizeof(krb5_key_salt_tuple));
+    if (knew == NULL)
+        return NULL;
+    memcpy(knew, ksalt, len * sizeof(krb5_key_salt_tuple));
+    return knew;
 }
 
 /*
  * krb5_aprof_init()        - Initialize alternate profile context.
  *
  * Parameters:
- *        fname                - default file name of the profile.
- *        envname                - environment variable name which can override fname.
- *        acontextp        - Pointer to opaque context for alternate profile.
+ *        fname             - default file name of the profile.
+ *        envname           - environment variable which can override fname
+ *        acontextp         - Pointer to opaque context for alternate profile
  *
  * Returns:
  *        error codes from profile_init()
  */
 krb5_error_code
-krb5_aprof_init(fname, envname, acontextp)
-    char                *fname;
-    char                *envname;
-    krb5_pointer        *acontextp;
+krb5_aprof_init(char *fname, char *envname, krb5_pointer *acontextp)
 {
-    krb5_error_code kret;
-    profile_t       profile;
-    const char      *kdc_config;
-    char            *profile_path;
-    char            **filenames;
-    int             i;
-    struct          k5buf buf;
-
-    kret = krb5_get_default_config_files (&filenames);
-    if (kret)
-        return kret;
+    krb5_error_code ret;
+    profile_t profile;
+    const char *kdc_config;
+    char *profile_path, **filenames;
+    int i;
+    struct k5buf buf;
+
+    ret = krb5_get_default_config_files(&filenames);
+    if (ret)
+        return ret;
     if (envname == NULL || (kdc_config = getenv(envname)) == NULL)
         kdc_config = fname;
     krb5int_buf_init_dynamic(&buf);
@@ -94,64 +88,63 @@ krb5_aprof_init(fname, envname, acontextp)
     if (profile_path == NULL)
         return ENOMEM;
     profile = (profile_t) NULL;
-    kret = profile_init_path(profile_path, &profile);
+    ret = profile_init_path(profile_path, &profile);
     free(profile_path);
-    if (kret)
-        return kret;
+    if (ret)
+        return ret;
     *acontextp = profile;
     return 0;
 }
 
 /*
- * krb5_aprof_getvals()        - Get values from alternate profile.
+ * krb5_aprof_getvals()     - Get values from alternate profile.
  *
  * Parameters:
- *        acontext        - opaque context for alternate profile.
- *        hierarchy        - hierarchy of value to retrieve.
- *        retdata                - Returned data values.
+ *        acontext          - opaque context for alternate profile.
+ *        hierarchy         - hierarchy of value to retrieve.
+ *        retdata           - Returned data values.
  *
  * Returns:
  *         error codes from profile_get_values()
  */
 krb5_error_code
-krb5_aprof_getvals(acontext, hierarchy, retdata)
-    krb5_pointer        acontext;
-    const char          **hierarchy;
-    char                ***retdata;
+krb5_aprof_getvals(krb5_pointer acontext, const char **hierarchy,
+                   char ***retdata)
 {
-    return(profile_get_values((profile_t) acontext,
-                              hierarchy,
-                              retdata));
+    return profile_get_values(acontext, hierarchy, retdata);
 }
 
 /*
  * krb5_aprof_get_boolean()
  *
  * Parameters:
- *        acontext        - opaque context for alternate profile
- *        hierarchy        - hierarchy of value to retrieve
- *        retdata                - Returned data value
+ *        acontext          - opaque context for alternate profile
+ *        hierarchy         - hierarchy of value to retrieve
+ *        retdata           - Returned data value
  * Returns:
  *        error codes
  */
 
 static krb5_error_code
-string_to_boolean (const char *string, krb5_boolean *out)
+string_to_boolean(const char *string, krb5_boolean *out)
 {
     static const char *const yes[] = { "y", "yes", "true", "t", "1", "on" };
-    static const char *const no[] = { "n", "no", "false", "f", "nil", "0", "off" };
+    static const char *const no[] = { "n", "no", "false", "f", "nil", "0",
+                                      "off" };
     unsigned int i;
 
-    for (i = 0; i < sizeof(yes)/sizeof(yes[0]); i++)
+    for (i = 0; i < sizeof(yes) / sizeof(yes[0]); i++) {
         if (!strcasecmp(string, yes[i])) {
-            *out = 1;
+            *out = TRUE;
             return 0;
         }
-    for (i = 0; i < sizeof(no)/sizeof(no[0]); i++)
+    }
+    for (i = 0; i < sizeof(no) / sizeof(no[0]); i++) {
         if (!strcasecmp(string, no[i])) {
-            *out = 0;
+            *out = FALSE;
             return 0;
         }
+    }
     return PROF_BAD_BOOLEAN;
 }
 
@@ -159,244 +152,227 @@ krb5_error_code
 krb5_aprof_get_boolean(krb5_pointer acontext, const char **hierarchy,
                        int uselast, krb5_boolean *retdata)
 {
-    krb5_error_code kret;
-    char **values;
-    char *valp;
+    krb5_error_code ret;
+    char **values, *valp;
     int idx;
     krb5_boolean val;
 
-    kret = krb5_aprof_getvals (acontext, hierarchy, &values);
-    if (kret)
-        return kret;
+    ret = krb5_aprof_getvals(acontext, hierarchy, &values);
+    if (ret)
+        return ret;
     idx = 0;
     if (uselast) {
-        while (values[idx])
+        while (values[idx] != NULL)
             idx++;
         idx--;
     }
     valp = values[idx];
-    kret = string_to_boolean (valp, &val);
+    ret = string_to_boolean(valp, &val);
     profile_free_list(values);
-    if (kret)
-        return kret;
+    if (ret)
+        return ret;
     *retdata = val;
     return 0;
 }
 
 /*
- * krb5_aprof_get_deltat()        - Get a delta time value from the alternate
- *                                  profile.
+ * krb5_aprof_get_deltat()  - Get a delta time value from the alternate
+ *                            profile.
  *
  * Parameters:
- *        acontext                 - opaque context for alternate profile.
- *        hierarchy                - hierarchy of value to retrieve.
- *        uselast                  - if true, use last value, otherwise use
- *                                   first value found.
- *        deltatp                  - returned delta time value.
+ *        acontext          - opaque context for alternate profile.
+ *        hierarchy         - hierarchy of value to retrieve.
+ *        uselast           - if true, use last value, otherwise use first
+ *                            value found.
+ *        deltatp           - returned delta time value.
  *
  * Returns:
- *         error codes from profile_get_values()
+ *        error codes from profile_get_values()
  *        error codes from krb5_string_to_deltat()
  */
 krb5_error_code
-krb5_aprof_get_deltat(acontext, hierarchy, uselast, deltatp)
-    krb5_pointer        acontext;
-    const char          **hierarchy;
-    krb5_boolean        uselast;
-    krb5_deltat         *deltatp;
+krb5_aprof_get_deltat(krb5_pointer acontext, const char **hierarchy,
+                      krb5_boolean uselast, krb5_deltat *deltatp)
 {
-    krb5_error_code     kret;
-    char                **values;
-    char                *valp;
-    int                 idx;
-
-    if (!(kret = krb5_aprof_getvals(acontext, hierarchy, &values))) {
-        idx = 0;
-        if (uselast) {
-            for (idx=0; values[idx]; idx++);
-            idx--;
-        }
-        valp = values[idx];
-        kret = krb5_string_to_deltat(valp, deltatp);
+    krb5_error_code ret;
+    char **values, *valp;
+    int idx;
 
-        /* Free the string storage */
-        profile_free_list(values);
+    ret = krb5_aprof_getvals(acontext, hierarchy, &values);
+    if (ret)
+        return ret;
+
+    idx = 0;
+    if (uselast) {
+        for (idx = 0; values[idx] != NULL; idx++);
+        idx--;
     }
-    return(kret);
+    valp = values[idx];
+
+    ret = krb5_string_to_deltat(valp, deltatp);
+    profile_free_list(values);
+    return ret;
 }
 
 /*
- * krb5_aprof_get_string()        - Get a string value from the alternate
- *                                  profile.
+ * krb5_aprof_get_string()  - Get a string value from the alternate profile.
  *
  * Parameters:
- *        acontext                 - opaque context for alternate profile.
- *        hierarchy                - hierarchy of value to retrieve.
- *        uselast                  - if true, use last value, otherwise use
- *                                   first value found.
- *        stringp                  - returned string value.
+ *        acontext          - opaque context for alternate profile.
+ *        hierarchy         - hierarchy of value to retrieve.
+ *        uselast           - if true, use last value, otherwise use first
+ *                            value found.
+ *        stringp           - returned string value.
  *
  * Returns:
  *         error codes from profile_get_values()
  */
 krb5_error_code
-krb5_aprof_get_string(acontext, hierarchy, uselast, stringp)
-    krb5_pointer        acontext;
-    const char          **hierarchy;
-    krb5_boolean        uselast;
-    char                **stringp;
+krb5_aprof_get_string(krb5_pointer acontext, const char **hierarchy,
+                      krb5_boolean uselast, char **stringp)
 {
-    krb5_error_code     kret;
-    char                **values;
-    int                 lastidx;
-
-    if (!(kret = krb5_aprof_getvals(acontext, hierarchy, &values))) {
-        for (lastidx=0; values[lastidx]; lastidx++);
-        lastidx--;
-
-        /* Excise the entry we want from the null-terminated list,
-           and free up the rest.  */
-        if (uselast) {
-            *stringp = values[lastidx];
-            values[lastidx] = NULL;
-        } else {
-            *stringp = values[0];
-            values[0] = values[lastidx];
-            values[lastidx] = NULL;
-        }
+    krb5_error_code ret;
+    char **values;
+    int lastidx;
 
-        /* Free the string storage */
-        profile_free_list(values);
+    ret = krb5_aprof_getvals(acontext, hierarchy, &values);
+    if (ret)
+        return ret;
+
+    for (lastidx = 0; values[lastidx] != NULL; lastidx++);
+    lastidx--;
+
+    /* Excise the entry we want from the null-terminated list,
+     * and free up the rest. */
+    if (uselast) {
+        *stringp = values[lastidx];
+        values[lastidx] = NULL;
+    } else {
+        *stringp = values[0];
+        values[0] = values[lastidx];
+        values[lastidx] = NULL;
     }
-    return(kret);
+
+    profile_free_list(values);
+    return 0;
 }
 
 /*
- * krb5_aprof_get_string_all()  - When the attr identified by "hierarchy" is specified multiple times,
- *                                collect all its string values from the alternate  profile.
+ * krb5_aprof_get_string_all() - When the attr identified by "hierarchy" is
+ *                               specified multiple times, concatenate all of
+ *                               its string values from the alternate profile,
+ *                               separated with spaces.
  *
  * Parameters:
- *        acontext                 - opaque context for alternate profile.
- *        hierarchy                - hierarchy of value to retrieve.
- *        stringp                  - Returned string value.
+ *        acontext             - opaque context for alternate profile.
+ *        hierarchy            - hierarchy of value to retrieve.
+ *        stringp              - Returned string value.
  *
  * Returns:
- *         error codes from profile_get_values() or ENOMEM
- *         Caller is responsible for deallocating stringp buffer
+ *        error codes from profile_get_values() or ENOMEM
+ *        Caller is responsible for deallocating stringp buffer
  */
 krb5_error_code
-krb5_aprof_get_string_all(acontext, hierarchy, stringp)
-    krb5_pointer        acontext;
-    const char          **hierarchy;
-    char                **stringp;
+krb5_aprof_get_string_all(krb5_pointer acontext, const char **hierarchy,
+                          char **stringp)
 {
-    krb5_error_code     kret=0;
-    char                **values;
-    int                 lastidx = 0;
-    char                *tmp = NULL ;
-    size_t              buf_size = 0;
-    kret = krb5_aprof_getvals(acontext, hierarchy, &values);
-    if (!kret) {
-        for (lastidx=0; values[lastidx]; lastidx++);
-        lastidx--;
-
-        buf_size = strlen(values[0])+3;
-        for (lastidx=1; values[lastidx]; lastidx++){
-            buf_size += strlen(values[lastidx]) + 3;
-        }
-    }
-    if (buf_size > 0) {
-        *stringp = calloc(1,buf_size);
-        if (*stringp == NULL){
-            profile_free_list(values);
-            return ENOMEM;
-        }
-        tmp=*stringp;
-        strlcpy(tmp, values[0], buf_size);
-        for (lastidx=1; values[lastidx]; lastidx++){
-            tmp = strcat(tmp, " ");
-            tmp = strcat(tmp, values[lastidx]);
-        }
-        /* Free the string storage */
+    krb5_error_code ret;
+    char **values;
+    int idx = 0;
+    size_t buf_size = 0;
+
+    ret = krb5_aprof_getvals(acontext, hierarchy, &values);
+    if (ret)
+        return ret;
+
+    buf_size = strlen(values[0]) + 3;
+    for (idx = 1; values[idx] != NULL; idx++)
+        buf_size += strlen(values[idx]) + 3;
+
+    *stringp = calloc(1, buf_size);
+    if (*stringp == NULL) {
         profile_free_list(values);
+        return ENOMEM;
     }
-    return(kret);
+    strlcpy(*stringp, values[0], buf_size);
+    for (idx = 1; values[idx] != NULL; idx++) {
+        strlcat(*stringp, " ", buf_size);
+        strlcat(*stringp, values[idx], buf_size);
+    }
+
+    profile_free_list(values);
+    return 0;
 }
 
 
 /*
- * krb5_aprof_get_int32()        - Get a 32-bit integer value from the alternate
- *                                  profile.
+ * krb5_aprof_get_int32()   - Get a 32-bit integer value from the alternate
+ *                            profile.
  *
  * Parameters:
- *        acontext                 - opaque context for alternate profile.
- *        hierarchy                - hierarchy of value to retrieve.
- *        uselast                  - if true, use last value, otherwise use
- *                                   first value found.
- *        intp                     - returned 32-bit integer value.
+ *        acontext          - opaque context for alternate profile.
+ *        hierarchy         - hierarchy of value to retrieve.
+ *        uselast           - if true, use last value, otherwise use first
+ *                            value found.
+ *        intp              - returned 32-bit integer value.
  *
  * Returns:
  *        error codes from profile_get_values()
- *        EINVAL                        - value is not an integer
+ *        EINVAL            - value is not an integer
  */
 krb5_error_code
-krb5_aprof_get_int32(acontext, hierarchy, uselast, intp)
-    krb5_pointer        acontext;
-    const char          **hierarchy;
-    krb5_boolean        uselast;
-    krb5_int32          *intp;
+krb5_aprof_get_int32(krb5_pointer acontext, const char **hierarchy,
+                     krb5_boolean uselast, krb5_int32 *intp)
 {
-    krb5_error_code     kret;
-    char                **values;
-    int                 idx;
-
-    if (!(kret = krb5_aprof_getvals(acontext, hierarchy, &values))) {
-        idx = 0;
-        if (uselast) {
-            for (idx=0; values[idx]; idx++);
-            idx--;
-        }
+    krb5_error_code ret;
+    char **values;
+    int idx;
 
-        if (sscanf(values[idx], "%d", intp) != 1)
-            kret = EINVAL;
+    ret = krb5_aprof_getvals(acontext, hierarchy, &values);
+    if (ret)
+        return ret;
 
-        /* Free the string storage */
-        profile_free_list(values);
+    idx = 0;
+    if (uselast) {
+        for (idx = 0; values[idx] != NULL; idx++);
+        idx--;
     }
-    return(kret);
+
+    if (sscanf(values[idx], "%d", intp) != 1)
+        ret = EINVAL;
+
+    profile_free_list(values);
+    return ret;
 }
 
 /*
- * krb5_aprof_finish()    - Finish alternate profile context.
+ * krb5_aprof_finish()      - Finish alternate profile context.
  *
  * Parameter:
- *        acontext        - opaque context for alternate profile.
+ *        acontext          - opaque context for alternate profile.
  *
  * Returns:
  *        0 on success, something else on failure.
  */
 krb5_error_code
-krb5_aprof_finish(acontext)
-    krb5_pointer        acontext;
+krb5_aprof_finish(krb5_pointer acontext)
 {
     profile_release(acontext);
-    return(0);
+    return 0;
 }
 
 /*
- * Returns nonzero if it found something to copy; the caller may still
- * need to check the output field or mask to see if the copy
- * (allocation) was successful.  Returns zero if nothing was found to
- * copy, and thus the caller may want to apply some default heuristic.
- * If the default action is just to use a fixed, compiled-in string,
- * supply it as the default value here and ignore the return value.
+ * Returns nonzero if it found something to copy; the caller may still need to
+ * check the output field or mask to see if the copy (allocation) was
+ * successful.  Returns zero if nothing was found to copy, and thus the caller
+ * may want to apply some default heuristic.  If the default action is just to
+ * use a fixed, compiled-in string, supply it as the default value here and
+ * ignore the return value.
  */
 static int
-get_string_param(char **param_out, char *param_in,
-                 long *mask_out, long mask_in, long mask_bit,
-                 krb5_pointer aprofile,
-                 const char **hierarchy,
-                 const char *config_name,
+get_string_param(char **param_out, char *param_in, long *mask_out,
+                 long mask_in, long mask_bit, krb5_pointer aprofile,
+                 const char **hierarchy, const char *config_name,
                  const char *default_value)
 {
     char *svalue;
@@ -407,7 +383,7 @@ get_string_param(char **param_out, char *param_in,
         if (*param_out)
             *mask_out |= mask_bit;
         return 1;
-    } else if (aprofile &&
+    } else if (aprofile != NULL &&
                !krb5_aprof_get_string(aprofile, hierarchy, TRUE, &svalue)) {
         *param_out = svalue;
         *mask_out |= mask_bit;
@@ -422,43 +398,39 @@ get_string_param(char **param_out, char *param_in,
     }
 }
 /*
- * Similar, for (host-order) port number, if not already set in the
- * output field; default_value==0 means no default.
+ * Similar, for (host-order) port number, if not already set in the output
+ * field; default_value == 0 means no default.
  */
 static void
-get_port_param(int *param_out, int param_in,
-               long *mask_out, long mask_in, long mask_bit,
-               krb5_pointer aprofile,
-               const char **hierarchy,
-               const char *config_name,
-               int default_value)
+get_port_param(int *param_out, int param_in, long *mask_out, long mask_in,
+               long mask_bit, krb5_pointer aprofile, const char **hierarchy,
+               const char *config_name, int default_value)
 {
     krb5_int32 ivalue;
 
-    if (! (*mask_out & mask_bit)) {
-        hierarchy[2] = config_name;
-        if (mask_in & mask_bit) {
-            *mask_out |= mask_bit;
-            *param_out = param_in;
-        } else if (aprofile &&
-                   !krb5_aprof_get_int32(aprofile, hierarchy, TRUE, &ivalue)) {
-            *param_out = ivalue;
-            *mask_out |= mask_bit;
-        } else if (default_value) {
-            *param_out = default_value;
-            *mask_out |= mask_bit;
-        }
+    if (*mask_out & mask_bit)
+        return;
+    hierarchy[2] = config_name;
+    if (mask_in & mask_bit) {
+        *mask_out |= mask_bit;
+        *param_out = param_in;
+    } else if (aprofile != NULL &&
+               !krb5_aprof_get_int32(aprofile, hierarchy, TRUE, &ivalue)) {
+        *param_out = ivalue;
+        *mask_out |= mask_bit;
+    } else if (default_value) {
+        *param_out = default_value;
+        *mask_out |= mask_bit;
     }
 }
+
 /*
  * Similar, for delta_t; default is required.
  */
 static void
-get_deltat_param(krb5_deltat *param_out, krb5_deltat param_in,
-                 long *mask_out, long mask_in, long mask_bit,
-                 krb5_pointer aprofile,
-                 const char **hierarchy,
-                 const char *config_name,
+get_deltat_param(krb5_deltat *param_out, krb5_deltat param_in, long *mask_out,
+                 long mask_in, long mask_bit, krb5_pointer aprofile,
+                 const char **hierarchy, const char *config_name,
                  krb5_deltat default_value)
 {
     krb5_deltat dtvalue;
@@ -510,8 +482,8 @@ parse_admin_server_port(char *server, int *port, long *mask)
 /*
  * Function: kadm5_get_config_params
  *
- * Purpose: Merge configuration parameters provided by the caller with
- * values specified in configuration files and with default values.
+ * Purpose: Merge configuration parameters provided by the caller with values
+ * specified in configuration files and with default values.
  *
  * Arguments:
  *
@@ -525,45 +497,41 @@ parse_admin_server_port(char *server, int *port, long *mask)
  *
  * Effects:
  *
- * The fields and mask of params_out are filled in with values
- * obtained from params_in, the specified profile, and default
- * values.  Only and all fields specified in params_out->mask are
- * set.  The context of params_out must be freed with
- * kadm5_free_config_params.
+ * The fields and mask of params_out are filled in with values obtained from
+ * params_in, the specified profile, and default values.  Only and all fields
+ * specified in params_out->mask are set.  The context of params_out must be
+ * freed with kadm5_free_config_params.
  *
- * params_in and params_out may be the same pointer.  However, all pointers
- * in params_in for which the mask is set will be re-assigned to newly copied
+ * params_in and params_out may be the same pointer.  However, all pointers in
+ * params_in for which the mask is set will be re-assigned to newly copied
  * versions, overwriting the old pointer value.
  */
-krb5_error_code kadm5_get_config_params(context, use_kdc_config,
-                                        params_in, params_out)
-    krb5_context               context;
-    int                        use_kdc_config;
-    kadm5_config_params        *params_in, *params_out;
+krb5_error_code kadm5_get_config_params(krb5_context context,
+                                        int use_kdc_config,
+                                        kadm5_config_params *params_in,
+                                        kadm5_config_params *params_out)
 {
-    char                *filename;
-    char                *envname;
-    char                *lrealm;
-    krb5_pointer        aprofile = 0;
-    const char          *hierarchy[4];
-    char                *svalue;
-    krb5_int32          ivalue;
+    char *filename, *envname, *lrealm, *svalue, *sp, *ep, *tp;
+    krb5_pointer aprofile = 0;
+    const char *hierarchy[4];
+    krb5_int32 ivalue;
     kadm5_config_params params, empty_params;
-
-    krb5_error_code        kret = 0;
+    krb5_boolean bvalue;
+    krb5_error_code ret = 0;
 
     memset(&params, 0, sizeof(params));
     memset(&empty_params, 0, sizeof(empty_params));
 
-    if (params_in == NULL) params_in = &empty_params;
+    if (params_in == NULL)
+        params_in = &empty_params;
 
     if (params_in->mask & KADM5_CONFIG_REALM) {
         lrealm = params.realm = strdup(params_in->realm);
-        if (params.realm)
+        if (params.realm != NULL)
             params.mask |= KADM5_CONFIG_REALM;
     } else {
-        kret = krb5_get_default_realm(context, &lrealm);
-        if (kret)
+        ret = krb5_get_default_realm(context, &lrealm);
+        if (ret)
             goto cleanup;
         params.realm = lrealm;
         params.mask |= KADM5_CONFIG_REALM;
@@ -586,64 +554,67 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
         filename = DEFAULT_PROFILE_PATH;
         envname = "KRB5_CONFIG";
     }
-    if (context->profile_secure == TRUE) envname = 0;
+    if (context->profile_secure == TRUE)
+        envname = NULL;
 
-    kret = krb5_aprof_init(filename, envname, &aprofile);
-    if (kret)
+    ret = krb5_aprof_init(filename, envname, &aprofile);
+    if (ret)
         goto cleanup;
 
-    /* Initialize realm parameters */
+    /* Initialize realm parameters. */
     hierarchy[0] = KRB5_CONF_REALMS;
     hierarchy[1] = lrealm;
-    hierarchy[3] = (char *) NULL;
+    hierarchy[3] = NULL;
 
 #define GET_STRING_PARAM(FIELD, BIT, CONFTAG, DEFAULT)          \
     get_string_param(&params.FIELD, params_in->FIELD,           \
                      &params.mask, params_in->mask, BIT,        \
                      aprofile, hierarchy, CONFTAG, DEFAULT)
 
-    /* Get the value for the admin server */
-    GET_STRING_PARAM(admin_server, KADM5_CONFIG_ADMIN_SERVER, KRB5_CONF_ADMIN_SERVER,
-                     NULL);
+    /* Get the value for the admin server. */
+    GET_STRING_PARAM(admin_server, KADM5_CONFIG_ADMIN_SERVER,
+                     KRB5_CONF_ADMIN_SERVER, NULL);
 
     if (params.mask & KADM5_CONFIG_ADMIN_SERVER) {
         parse_admin_server_port(params.admin_server, &params.kadmind_port,
                                 &params.mask);
     }
 
-    /* Get the value for the database */
+    /* Get the value for the database. */
     GET_STRING_PARAM(dbname, KADM5_CONFIG_DBNAME, KRB5_CONF_DATABASE_NAME,
                      DEFAULT_KDB_FILE);
 
-    /* Get the name of the acl file */
+    /* Get the name of the acl file. */
     GET_STRING_PARAM(acl_file, KADM5_CONFIG_ACL_FILE, KRB5_CONF_ACL_FILE,
                      DEFAULT_KADM5_ACL_FILE);
 
-    /* Get the name of the dict file */
-    GET_STRING_PARAM(dict_file, KADM5_CONFIG_DICT_FILE, KRB5_CONF_DICT_FILE, NULL);
+    /* Get the name of the dict file. */
+    GET_STRING_PARAM(dict_file, KADM5_CONFIG_DICT_FILE, KRB5_CONF_DICT_FILE,
+                     NULL);
 
 #define GET_PORT_PARAM(FIELD, BIT, CONFTAG, DEFAULT)            \
     get_port_param(&params.FIELD, params_in->FIELD,             \
                    &params.mask, params_in->mask, BIT,          \
                    aprofile, hierarchy, CONFTAG, DEFAULT)
-    /* Get the value for the kadmind port */
+
+    /* Get the value for the kadmind port. */
     GET_PORT_PARAM(kadmind_port, KADM5_CONFIG_KADMIND_PORT,
                    KRB5_CONF_KADMIND_PORT, DEFAULT_KADM5_PORT);
 
-    /* Get the value for the kpasswd port */
+    /* Get the value for the kpasswd port. */
     GET_PORT_PARAM(kpasswd_port, KADM5_CONFIG_KPASSWD_PORT,
                    KRB5_CONF_KPASSWD_PORT, DEFAULT_KPASSWD_PORT);
 
-    /* Get the value for the master key name */
+    /* Get the value for the master key name. */
     GET_STRING_PARAM(mkey_name, KADM5_CONFIG_MKEY_NAME,
                      KRB5_CONF_MASTER_KEY_NAME, NULL);
 
-    /* Get the value for the master key type */
+    /* Get the value for the master key type. */
     hierarchy[2] = KRB5_CONF_MASTER_KEY_TYPE;
     if (params_in->mask & KADM5_CONFIG_ENCTYPE) {
         params.mask |= KADM5_CONFIG_ENCTYPE;
         params.enctype = params_in->enctype;
-    } else if (aprofile &&
+    } else if (aprofile != NULL &&
                !krb5_aprof_get_string(aprofile, hierarchy, TRUE, &svalue)) {
         if (!krb5_string_to_enctype(svalue, &params.enctype)) {
             params.mask |= KADM5_CONFIG_ENCTYPE;
@@ -654,13 +625,13 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
         params.enctype = DEFAULT_KDC_ENCTYPE;
     }
 
-    /* Get the value for mkey_from_kbd */
+    /* Get the value for mkey_from_kbd. */
     if (params_in->mask & KADM5_CONFIG_MKEY_FROM_KBD) {
         params.mask |= KADM5_CONFIG_MKEY_FROM_KBD;
         params.mkey_from_kbd = params_in->mkey_from_kbd;
     }
 
-    /* Get the value for the stashfile */
+    /* Get the value for the stashfile. */
     GET_STRING_PARAM(stash_file, KADM5_CONFIG_STASH_FILE,
                      KRB5_CONF_KEY_STASH_FILE, NULL);
 
@@ -674,8 +645,8 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
                      24 * 60 * 60); /* 1 day */
 
     /* Get the value for maximum renewable ticket lifetime. */
-    GET_DELTAT_PARAM(max_rlife, KADM5_CONFIG_MAX_RLIFE, KRB5_CONF_MAX_RENEWABLE_LIFE,
-                     0);
+    GET_DELTAT_PARAM(max_rlife, KADM5_CONFIG_MAX_RLIFE,
+                     KRB5_CONF_MAX_RENEWABLE_LIFE, 0);
 
     /* Get the value for the default principal expiration */
     hierarchy[2] = KRB5_CONF_DEFAULT_PRINCIPAL_EXPIRATION;
@@ -698,36 +669,32 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
     if (params_in->mask & KADM5_CONFIG_FLAGS) {
         params.mask |= KADM5_CONFIG_FLAGS;
         params.flags = params_in->flags;
-    } else if (aprofile &&
+    } else if (aprofile != NULL &&
                !krb5_aprof_get_string(aprofile, hierarchy, TRUE, &svalue)) {
-        char *sp, *ep, *tp;
-
         sp = svalue;
         params.flags = 0;
-        while (sp) {
-            if ((ep = strchr(sp, (int) ',')) ||
-                (ep = strchr(sp, (int) ' ')) ||
-                (ep = strchr(sp, (int) '\t'))) {
-                /* Fill in trailing whitespace of sp */
+        while (sp != NULL) {
+            if ((ep = strchr(sp, ',')) != NULL ||
+                (ep = strchr(sp, ' ')) != NULL ||
+                (ep = strchr(sp, '\t')) != NULL) {
+                /* Fill in trailing whitespace of sp. */
                 tp = ep - 1;
-                while (isspace((int) *tp) && (tp > sp)) {
+                while (isspace((unsigned char)*tp) && tp > sp) {
                     *tp = '\0';
                     tp--;
                 }
                 *ep = '\0';
                 ep++;
-                /* Skip over trailing whitespace of ep */
-                while (isspace((int) *ep) && (*ep)) ep++;
+                /* Skip over trailing whitespace of ep. */
+                while (isspace((unsigned char)*ep) && *ep != '\0')
+                    ep++;
             }
-            /* Convert this flag */
-            if (krb5_string_to_flags(sp,
-                                     "+",
-                                     "-",
-                                     &params.flags))
+            /* Convert this flag. */
+            if (krb5_string_to_flags(sp, "+", "-", &params.flags))
                 break;
             sp = ep;
         }
-        if (!sp)
+        if (sp == NULL)
             params.mask |= KADM5_CONFIG_FLAGS;
         free(svalue);
     } else {
@@ -735,25 +702,24 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
         params.flags = KRB5_KDB_DEF_FLAGS;
     }
 
-    /* Get the value for the supported enctype/salttype matrix */
+    /* Get the value for the supported enctype/salttype matrix. */
     hierarchy[2] = KRB5_CONF_SUPPORTED_ENCTYPES;
     if (params_in->mask & KADM5_CONFIG_ENCTYPES) {
-        /* The following scenario is when the input keysalts are !NULL */
-        if(params_in->keysalts) {
+        if (params_in->keysalts) {
             params.keysalts = copy_key_salt_tuple(params_in->keysalts,
                                                   params_in->num_keysalts);
-            if(params.keysalts) {
+            if (params.keysalts) {
                 params.mask |= KADM5_CONFIG_ENCTYPES;
                 params.num_keysalts = params_in->num_keysalts;
             }
         } else {
             params.mask |= KADM5_CONFIG_ENCTYPES;
-            params.keysalts = 0;
+            params.keysalts = NULL;
             params.num_keysalts = params_in->num_keysalts;
         }
     } else {
         svalue = NULL;
-        if (aprofile)
+        if (aprofile != NULL)
             krb5_aprof_get_string(aprofile, hierarchy, TRUE, &svalue);
         if (svalue == NULL)
             svalue = strdup(KRB5_DEFAULT_SUPPORTED_ENCTYPES);
@@ -761,9 +727,9 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
         params.keysalts = NULL;
         params.num_keysalts = 0;
         krb5_string_to_keysalts(svalue,
-                                ", \t",/* Tuple separators */
-                                ":.-",        /* Key/salt separators */
-                                0,        /* No duplicates */
+                                ", \t", /* Tuple separators */
+                                ":.-",  /* Key/salt separators */
+                                0,      /* No duplicates */
                                 &params.keysalts,
                                 &params.num_keysalts);
         if (params.num_keysalts)
@@ -781,7 +747,6 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
         params.mask |= KADM5_CONFIG_IPROP_ENABLED;
         params.iprop_enabled = params_in->iprop_enabled;
     } else {
-        krb5_boolean bvalue;
         if (aprofile &&
             !krb5_aprof_get_boolean(aprofile, hierarchy, TRUE, &bvalue)) {
             params.iprop_enabled = bvalue;
@@ -792,14 +757,14 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
     if (!GET_STRING_PARAM(iprop_logfile, KADM5_CONFIG_IPROP_LOGFILE,
                           KRB5_CONF_IPROP_LOGFILE, NULL)) {
         if (params.mask & KADM5_CONFIG_DBNAME) {
-            if (asprintf(&params.iprop_logfile, "%s.ulog", params.dbname) >= 0) {
+            if (asprintf(&params.iprop_logfile, "%s.ulog",
+                         params.dbname) >= 0)
                 params.mask |= KADM5_CONFIG_IPROP_LOGFILE;
-            }
         }
     }
 
-    GET_PORT_PARAM(iprop_port, KADM5_CONFIG_IPROP_PORT,
-                   KRB5_CONF_IPROP_PORT, 0);
+    GET_PORT_PARAM(iprop_port, KADM5_CONFIG_IPROP_PORT, KRB5_CONF_IPROP_PORT,
+                   0);
 
     /* 5 min for large KDBs */
     GET_DELTAT_PARAM(iprop_resync_timeout, KADM5_CONFIG_IPROP_RESYNC_TIMEOUT,
@@ -814,8 +779,8 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
         params.mask |= KADM5_CONFIG_ULOG_SIZE;
         params.iprop_ulogsize = params_in->iprop_ulogsize;
     } else {
-        if (aprofile && !krb5_aprof_get_int32(aprofile, hierarchy,
-                                              TRUE, &ivalue)) {
+        if (aprofile != NULL &&
+            !krb5_aprof_get_int32(aprofile, hierarchy, TRUE, &ivalue)) {
             if (ivalue <= 0)
                 params.iprop_ulogsize = DEF_ULOGENTRIES;
             else
@@ -830,41 +795,37 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config,
     *params_out = params;
 
 cleanup:
-    if (aprofile)
-        krb5_aprof_finish(aprofile);
-    if (kret) {
+    krb5_aprof_finish(aprofile);
+    if (ret) {
         kadm5_free_config_params(context, &params);
         params_out->mask = 0;
     }
-    return(kret);
+    return ret;
 }
+
 /*
  * kadm5_free_config_params()        - Free data allocated by above.
  */
 krb5_error_code
-kadm5_free_config_params(context, params)
-    krb5_context        context;
-    kadm5_config_params        *params;
+kadm5_free_config_params(krb5_context context, kadm5_config_params *params)
 {
-    if (params) {
-        free(params->dbname);
-        free(params->mkey_name);
-        free(params->stash_file);
-        free(params->keysalts);
-        free(params->admin_server);
-        free(params->dict_file);
-        free(params->acl_file);
-        free(params->realm);
-        free(params->iprop_logfile);
-    }
-    return(0);
+    if (params == NULL)
+        return 0;
+    free(params->dbname);
+    free(params->mkey_name);
+    free(params->stash_file);
+    free(params->keysalts);
+    free(params->admin_server);
+    free(params->dict_file);
+    free(params->acl_file);
+    free(params->realm);
+    free(params->iprop_logfile);
+    return 0;
 }
 
 krb5_error_code
-kadm5_get_admin_service_name(krb5_context ctx,
-                             char *realm_in,
-                             char *admin_name,
-                             size_t maxlen)
+kadm5_get_admin_service_name(krb5_context ctx, char *realm_in,
+                             char *admin_name, size_t maxlen)
 {
     krb5_error_code ret;
     kadm5_config_params params_in, params_out;
@@ -915,63 +876,46 @@ err_params:
  ***********************************************************************/
 
 /*
- * krb5_read_realm_params()       - Read per-realm parameters from KDC
- *                                  alternate profile.
+ * krb5_read_realm_params() - Read per-realm parameters from KDC alternate
+ *                            profile.
  */
 krb5_error_code
-krb5_read_realm_params(kcontext, realm, rparamp)
-    krb5_context        kcontext;
-    char                *realm;
-    krb5_realm_params   **rparamp;
+krb5_read_realm_params(krb5_context context, char *realm,
+                       krb5_realm_params **rparamp)
 {
-    char                *filename;
-    char                *envname;
-    char                *lrealm;
-    krb5_pointer        aprofile = 0;
-    krb5_realm_params   *rparams;
-    const char          *hierarchy[4];
-    char                *svalue;
-    krb5_int32          ivalue;
-    krb5_boolean        bvalue;
-    krb5_deltat         dtvalue;
-
-    char                *kdcprofile = 0;
-    char                *kdcenv = 0;
-    char                *no_referral = 0;
-    char                *hostbased = 0;
-    krb5_error_code      kret;
-
-    filename = (kdcprofile) ? kdcprofile : DEFAULT_KDC_PROFILE;
-    envname = (kdcenv) ? kdcenv : KDC_PROFILE_ENV;
-
-    if (kcontext->profile_secure == TRUE) envname = 0;
-
-    rparams = (krb5_realm_params *) NULL;
-    if (realm)
+    char *envname, *lrealm, *svalue, *sp, *ep, *tp;
+    char *no_referral = NULL, *hostbased = NULL;
+    krb5_pointer aprofile = NULL;
+    krb5_realm_params *rparams = NULL;
+    const char *hierarchy[4];
+    krb5_int32 ivalue;
+    krb5_boolean bvalue;
+    krb5_deltat dtvalue;
+    krb5_error_code ret;
+
+    if (realm != NULL) {
         lrealm = strdup(realm);
-    else {
-        kret = krb5_get_default_realm(kcontext, &lrealm);
-        if (kret)
+    } else {
+        ret = krb5_get_default_realm(context, &lrealm);
+        if (ret)
             goto cleanup;
     }
 
-    kret = krb5_aprof_init(filename, envname, &aprofile);
-    if (kret)
+    envname = context->profile_secure ? NULL : KDC_PROFILE_ENV;
+    ret = krb5_aprof_init(DEFAULT_KDC_PROFILE, envname, &aprofile);
+    if (ret)
         goto cleanup;
 
-    rparams = (krb5_realm_params *) malloc(sizeof(krb5_realm_params));
-    if (rparams == 0) {
-        kret = ENOMEM;
+    rparams = calloc(1, sizeof(krb5_realm_params));
+    if (rparams == NULL) {
+        ret = ENOMEM;
         goto cleanup;
     }
 
-    /* Initialize realm parameters */
-    memset(rparams, 0, sizeof(krb5_realm_params));
-
     /* Set up the hierarchy so we can query multiple realm variables. */
     hierarchy[0] = KRB5_CONF_REALMS;
     hierarchy[1] = lrealm;
-    hierarchy[3] = (char *) NULL;
+    hierarchy[3] = NULL;
 
     /* Get the value for the KDC port list */
     hierarchy[2] = KRB5_CONF_KDC_PORTS;
@@ -1028,8 +972,7 @@ krb5_read_realm_params(kcontext, realm, rparamp)
     /* Get the value for the default principal expiration */
     hierarchy[2] = KRB5_CONF_DEFAULT_PRINCIPAL_EXPIRATION;
     if (!krb5_aprof_get_string(aprofile, hierarchy, TRUE, &svalue)) {
-        if (!krb5_string_to_timestamp(svalue,
-                                      &rparams->realm_expiration))
+        if (!krb5_string_to_timestamp(svalue, &rparams->realm_expiration))
             rparams->realm_expiration_valid = 1;
         free(svalue);
     }
@@ -1060,37 +1003,33 @@ krb5_read_realm_params(kcontext, realm, rparamp)
     if (!krb5_aprof_get_string_all(aprofile, hierarchy, &hostbased))
         rparams->realm_hostbased = hostbased;
 
-    /* Get the value for the default principal flags */
+    /* Get the value for the default principal flags. */
     hierarchy[2] = KRB5_CONF_DEFAULT_PRINCIPAL_FLAGS;
     if (!krb5_aprof_get_string(aprofile, hierarchy, TRUE, &svalue)) {
-        char *sp, *ep, *tp;
-
         sp = svalue;
         rparams->realm_flags = 0;
         while (sp) {
-            if ((ep = strchr(sp, (int) ',')) ||
-                (ep = strchr(sp, (int) ' ')) ||
-                (ep = strchr(sp, (int) '\t'))) {
-                /* Fill in trailing whitespace of sp */
+            if ((ep = strchr(sp, ',')) != NULL ||
+                (ep = strchr(sp, ' ')) != NULL||
+                (ep = strchr(sp, '\t')) != NULL) {
+                /* Fill in trailing whitespace of sp. */
                 tp = ep - 1;
-                while (isspace((int) *tp) && (tp < sp)) {
+                while (isspace((unsigned char)*tp) && (tp < sp)) {
                     *tp = '\0';
                     tp--;
                 }
                 *ep = '\0';
                 ep++;
-                /* Skip over trailing whitespace of ep */
-                while (isspace((int) *ep) && (*ep)) ep++;
+                /* Skip over trailing whitespace of ep. */
+                while (isspace((unsigned char)*ep) && *ep != '\0')
+                    ep++;
             }
-            /* Convert this flag */
-            if (krb5_string_to_flags(sp,
-                                     "+",
-                                     "-",
-                                     &rparams->realm_flags))
+            /* Convert this flag. */
+            if (krb5_string_to_flags(sp, "+", "-", &rparams->realm_flags))
                 break;
             sp = ep;
         }
-        if (!sp)
+        if (sp == NULL)
             rparams->realm_flags_valid = 1;
         free(svalue);
     }
@@ -1102,34 +1041,32 @@ cleanup:
     if (aprofile)
         krb5_aprof_finish(aprofile);
     free(lrealm);
-    if (kret) {
+    if (ret) {
         if (rparams)
-            krb5_free_realm_params(kcontext, rparams);
+            krb5_free_realm_params(context, rparams);
         rparams = 0;
     }
     *rparamp = rparams;
-    return(kret);
+    return ret;
 }
 
 /*
- * krb5_free_realm_params()        - Free data allocated by above.
+ * krb5_free_realm_params() - Free data allocated by above.
  */
 krb5_error_code
-krb5_free_realm_params(kcontext, rparams)
-    krb5_context        kcontext;
-    krb5_realm_params   *rparams;
+krb5_free_realm_params(krb5_context context, krb5_realm_params *rparams)
 {
-    if (rparams) {
-        free(rparams->realm_profile);
-        free(rparams->realm_mkey_name);
-        free(rparams->realm_stash_file);
-        free(rparams->realm_keysalts);
-        free(rparams->realm_kdc_ports);
-        free(rparams->realm_kdc_tcp_ports);
-        free(rparams->realm_acl_file);
-        free(rparams->realm_no_referral);
-        free(rparams->realm_hostbased);
-        free(rparams);
-    }
-    return(0);
+    if (rparams == NULL)
+        return 0;
+    free(rparams->realm_profile);
+    free(rparams->realm_mkey_name);
+    free(rparams->realm_stash_file);
+    free(rparams->realm_keysalts);
+    free(rparams->realm_kdc_ports);
+    free(rparams->realm_kdc_tcp_ports);
+    free(rparams->realm_acl_file);
+    free(rparams->realm_no_referral);
+    free(rparams->realm_hostbased);
+    free(rparams);
+    return 0;
 }


More information about the cvs-krb5 mailing list