Fix krb5_get_profile to create a new profile duplicating the list of
authorKen Raeburn <raeburn@mit.edu>
Sat, 24 Jun 2006 02:39:52 +0000 (02:39 +0000)
committerKen Raeburn <raeburn@mit.edu>
Sat, 24 Jun 2006 02:39:52 +0000 (02:39 +0000)
files from the one in the provided context, instead of constructing
and checking the file list from scratch.  Uses a new function in the
profile library, not put into the public API yet.

* util/profile/prof_init.c (profile_copy): New function.
* util/profile/prof_int.h (profile_copy): Declare it.
* lib/krb5/os/Makefile.in (LOCALINCLUDES): Look in the profile source dir.
* lib/krb5/os/init_os_ctx.c (krb5_get_profile): Replace all the previous code
with a call to profile_copy.

ticket: 3925

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18209 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/Makefile.in
src/lib/krb5/os/init_os_ctx.c
src/util/profile/prof_init.c
src/util/profile/prof_int.h

index db391ab15fde7552a2c8a8a90f5abc818e48775b..403f591e67a2da326e1a4729e7e762a2c30f811d 100644 (file)
@@ -7,6 +7,7 @@ PROG_LIBPATH=-L$(TOPLIBD)
 PROG_RPATH=$(KRB5_LIBDIR)
 DEFS=
 DEFINES=-DLIBDIR=\"$(KRB5_LIBDIR)\"
+LOCALINCLUDES=-I$(SRCTOP)/util/profile
 
 ##DOS##BUILDTOP = ..\..\..
 ##DOS##PREFIXDIR=os
index d26743ac69ce636690eb356c76360049bc653ce0..893355ef93d7ae4f9964dd1f51d0d37ca9254ee9 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "k5-int.h"
 #include "os-proto.h"
+#include "prof_int.h"          /* XXX for profile_copy, not public yet */
 
 #ifdef USE_LOGIN_LIBRARY
 #include "KerberosLoginPrivate.h"
@@ -414,30 +415,7 @@ krb5_os_init_context(krb5_context ctx, krb5_boolean kdc)
 krb5_error_code KRB5_CALLCONV
 krb5_get_profile (krb5_context ctx, profile_t *profile)
 {
-    krb5_error_code    retval = 0;
-    profile_filespec_t *files = 0;
-
-    retval = os_get_default_config_files(&files, ctx->profile_secure);
-
-    if (!retval) {
-        retval = profile_init((const_profile_filespec_t *) files,
-                             profile);
-    }
-
-    if (files)
-        free_filespecs(files);
-
-    if (retval == ENOENT)
-        return KRB5_CONFIG_CANTOPEN;
-
-    if ((retval == PROF_SECTION_NOTOP) ||
-        (retval == PROF_SECTION_SYNTAX) ||
-        (retval == PROF_RELATION_SYNTAX) ||
-        (retval == PROF_EXTRA_CBRACE) ||
-        (retval == PROF_MISSING_OBRACE))
-        return KRB5_CONFIG_BADFORMAT;
-
-    return retval;
+    return profile_copy (ctx->profile, profile);
 }      
 
 
index 888d46d0a61ac72db3f639c91166517cc3378cbb..e5c6f9c8c5b3535360c197d3595a922858d8ed2e 100644 (file)
@@ -66,6 +66,39 @@ profile_init(const_profile_filespec_t *files, profile_t *ret_profile)
         return 0;
 }
 
+#define COUNT_LINKED_LIST(COUNT, PTYPE, START, FIELD)  \
+       {                                               \
+           int cll_counter = 0;                        \
+           PTYPE cll_ptr = (START);                    \
+           while (cll_ptr != NULL) {                   \
+               cll_counter++;                          \
+               cll_ptr = cll_ptr->FIELD;               \
+           }                                           \
+           (COUNT) = cll_counter;                      \
+       }
+
+errcode_t KRB5_CALLCONV
+profile_copy(profile_t old_profile, profile_t *new_profile)
+{
+    size_t size, i;
+    const_profile_filespec_t *files;
+    prf_file_t file;
+    errcode_t err;
+
+    /* The fields we care about are read-only after creation, so
+       no locking is needed.  */
+    COUNT_LINKED_LIST (size, prf_file_t, old_profile->first_file, next);
+    files = malloc ((size+1) * sizeof(*files));
+    if (files == NULL)
+       return errno;
+    for (i = 0, file = old_profile->first_file; i < size; i++, file = file->next)
+       files[i] = file->data->filespec;
+    files[size] = NULL;
+    err = profile_init (files, new_profile);
+    free (files);
+    return err;
+}
+
 errcode_t KRB5_CALLCONV
 profile_init_path(const_profile_filespec_list_t filepath,
                  profile_t *ret_profile)
index 70a8dd920853a7f5cb56551a6059b9f114473644..d6349afd725ea34f01931adbfbb27edaa34cf5c9 100644 (file)
@@ -192,6 +192,8 @@ errcode_t profile_rename_node
 
 /* prof_file.c */
 
+errcode_t KRB5_CALLCONV profile_copy (profile_t, profile_t *);
+
 errcode_t profile_open_file
        (const_profile_filespec_t file, prf_file_t *ret_prof);