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)
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))
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;
}