svn rev #25075: trunk/src/ lib/krb5/krb/ util/profile/

ghudson@MIT.EDU ghudson at MIT.EDU
Sat Aug 6 21:17:16 EDT 2011


http://src.mit.edu/fisheye/changelog/krb5/?cs=25075
Commit By: ghudson
Log Message:
Use portable path functions when loading plugins.


Changed Files:
U   trunk/src/lib/krb5/krb/plugin.c
U   trunk/src/util/profile/prof_init.c
Modified: trunk/src/lib/krb5/krb/plugin.c
===================================================================
--- trunk/src/lib/krb5/krb/plugin.c	2011-08-07 01:12:28 UTC (rev 25074)
+++ trunk/src/lib/krb5/krb/plugin.c	2011-08-07 01:17:16 UTC (rev 25075)
@@ -132,35 +132,6 @@
     return 0;
 }
 
-/*
- * Convert a possibly relative pathname for a shared object to an absolute
- * path.  Non-absolute pathnames will be treated as relative to the system
- * plugins directory.
- */
-static krb5_error_code
-expand_relative_modpath(krb5_context context, const char *modpath,
-                        char **full_modpath_out)
-{
-    char *path;
-
-    *full_modpath_out = NULL;
-
-    /* XXX Unix-specific path handling for now. */
-    if (*modpath == '/') {
-        /* We already have an absolute path. */
-        path = strdup(modpath);
-        if (path == NULL)
-            return ENOMEM;
-    } else {
-        /* Append the relative path to the system plugins directory. */
-        if (asprintf(&path, "%s/%s", context->plugin_base_dir, modpath) < 0)
-            return ENOMEM;
-    }
-
-    *full_modpath_out = path;
-    return 0;
-}
-
 /* Return true if value is found in list. */
 static krb5_boolean
 find_in_list(char **list, const char *value)
@@ -250,7 +221,8 @@
     ret = parse_modstr(context, modstr, &modname, &modpath);
     if (ret != 0)
         goto cleanup;
-    ret = expand_relative_modpath(context, modpath, &fullpath);
+    /* Treat non-absolute modpaths as relative to the plugin base directory. */
+    ret = k5_path_join(context->plugin_base_dir, modpath, &fullpath);
     if (ret != 0)
         goto cleanup;
     if (!module_enabled(modname, enable, disable))

Modified: trunk/src/util/profile/prof_init.c
===================================================================
--- trunk/src/util/profile/prof_init.c	2011-08-07 01:12:28 UTC (rev 25074)
+++ trunk/src/util/profile/prof_init.c	2011-08-07 01:17:16 UTC (rev 25075)
@@ -66,27 +66,38 @@
 static errcode_t
 parse_modspec(const char *modspec, char **ret_path, char **ret_residual)
 {
-    const char *p, *prefix;
-    char *path, *residual;
+    const char *p;
+    char *path, *fullpath, *residual;
+    errcode_t ret;
 
     *ret_path = *ret_residual = NULL;
 
-    p = strchr(modspec, ':');
+    /* Find the separator, skipping a Windows drive letter if present. */
+    p = (*modspec != '\0' && modspec[1] == ':') ? modspec + 2 : modspec;
+    p = strchr(p, ':');
     if (p == NULL)
         return PROF_MODULE_SYNTAX;
 
-    /* XXX Unix path handling for now. */
-    prefix = (*modspec == '/') ? "" : LIBDIR "/";
-    if (asprintf(&path, "%s%.*s", prefix, (int)(p - modspec), modspec) < 0)
+    /* Copy the path. */
+    path = malloc(p - modspec + 1);
+    if (path == NULL)
         return ENOMEM;
+    memcpy(path, modspec, p - modspec);
+    path[p - modspec] = '\0';
 
+    /* Compose the path with LIBDIR if it's not absolute. */
+    ret = k5_path_join(LIBDIR, path, &fullpath);
+    free(path);
+    if (ret)
+        return ret;
+
     residual = strdup(p + 1);
     if (residual == NULL) {
-        free(path);
+        free(fullpath);
         return ENOMEM;
     }
 
-    *ret_path = path;
+    *ret_path = fullpath;
     *ret_residual = residual;
     return 0;
 }




More information about the cvs-krb5 mailing list