Two versions of resolver code were almost identical, so unify them and reduce duplica...
authorKen Raeburn <raeburn@mit.edu>
Sat, 2 Aug 2008 05:17:53 +0000 (05:17 +0000)
committerKen Raeburn <raeburn@mit.edu>
Sat, 2 Aug 2008 05:17:53 +0000 (05:17 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20594 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/keytab/kt_file.c

index 8137cf9917c65c9a1afd1b7d0553dd8b5ffbbd9a..cc254dd4b4e4598abe1a304afbce5b5c0f9f95c4 100644 (file)
@@ -198,8 +198,9 @@ static krb5_error_code krb5_ktfileint_find_slot
  * initialized with file keytab routines.
  */
 
-static krb5_error_code KRB5_CALLCONV 
-krb5_ktfile_resolve(krb5_context context, const char *name, krb5_keytab *id)
+static krb5_error_code
+ktfile_common_resolve(krb5_context context, const char *name,
+                     krb5_keytab *id, const struct _krb5_kt_ops *ops)
 {
     krb5_ktfile_data *data;
     krb5_error_code err;
@@ -207,7 +208,7 @@ krb5_ktfile_resolve(krb5_context context, const char *name, krb5_keytab *id)
     if ((*id = (krb5_keytab) malloc(sizeof(**id))) == NULL)
        return(ENOMEM);
     
-    (*id)->ops = &krb5_ktf_ops;
+    (*id)->ops = ops;
     if ((data = (krb5_ktfile_data *)malloc(sizeof(krb5_ktfile_data))) == NULL) {
        krb5_xfree(*id);
        return(ENOMEM);
@@ -237,6 +238,12 @@ krb5_ktfile_resolve(krb5_context context, const char *name, krb5_keytab *id)
     return(0);
 }
 
+static krb5_error_code KRB5_CALLCONV 
+krb5_ktfile_resolve(krb5_context context, const char *name, krb5_keytab *id)
+{
+    return ktfile_common_resolve(context, name, id, &krb5_ktf_writable_ops);
+}
+
 
 /*
  * "Close" a file-based keytab and invalidate the id.  This means
@@ -835,40 +842,7 @@ krb5_ktf_keytab_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octe
 static krb5_error_code KRB5_CALLCONV
 krb5_ktfile_wresolve(krb5_context context, const char *name, krb5_keytab *id)
 {
-    krb5_ktfile_data *data;
-    krb5_error_code err;
-
-    if ((*id = (krb5_keytab) malloc(sizeof(**id))) == NULL)
-       return(ENOMEM);
-    
-    (*id)->ops = &krb5_ktf_writable_ops;
-    if ((data = (krb5_ktfile_data *)malloc(sizeof(krb5_ktfile_data))) == NULL) {
-       krb5_xfree(*id);
-       return(ENOMEM);
-    }
-
-    err = k5_mutex_init(&data->lock);
-    if (err) {
-       krb5_xfree(data);
-       krb5_xfree(*id);
-       return err;
-    }
-
-    if ((data->name = (char *)calloc(strlen(name) + 1, sizeof(char))) == NULL) {
-       k5_mutex_destroy(&data->lock);
-       krb5_xfree(data);
-       krb5_xfree(*id);
-       return(ENOMEM);
-    }
-
-    (void) strcpy(data->name, name);
-    data->openf = 0;
-    data->version = 0;
-    data->iter_count = 0;
-
-    (*id)->data = (krb5_pointer)data;
-    (*id)->magic = KV5M_KEYTAB;
-    return(0);
+    return ktfile_common_resolve(context, name, id, &krb5_ktf_writable_ops);
 }