#! /bin/sh /usr/share/dpatch/dpatch-run ## 08_expand_home_fix.dpatch by ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Make expand_home expanding "~" correctly @DPATCH@ diff -urNad libpam-mount-0.44~/src/rdconf1.c libpam-mount-0.44/src/rdconf1.c --- libpam-mount-0.44~/src/rdconf1.c 2008-11-17 13:45:48.000000000 +0100 +++ libpam-mount-0.44/src/rdconf1.c 2008-11-17 13:46:14.000000000 +0100 @@ -66,7 +66,7 @@ }; /* Functions */ -static char *expand_home(const char *, char *, size_t); +static bool expand_home(const char *, char **); static char *expand_user(const char *, char *, size_t); static inline int strcmp_1u(const xmlChar *, const char *); static int rc_volume_cond_ext(const struct passwd *, xmlNode *); @@ -89,11 +89,11 @@ struct vol *vpt; HXlist_for_each_entry(vpt, &config->volume_list, list) { - if (expand_home(u, vpt->mountpoint, sizeof(vpt->mountpoint)) == NULL || + if (!expand_home(u, &vpt->mountpoint) || expand_user(u, vpt->mountpoint, sizeof(vpt->mountpoint)) == NULL || - expand_home(u, vpt->volume, sizeof(vpt->volume)) == NULL || + !expand_home(u, &vpt->volume) || expand_user(u, vpt->volume, sizeof(vpt->volume)) == NULL || - expand_home(u, vpt->fs_key_path, sizeof(vpt->fs_key_path)) == NULL || + !expand_home(u, &vpt->fs_key_path) || expand_user(u, vpt->fs_key_path, sizeof(vpt->fs_key_path)) == NULL) return false; @@ -267,38 +267,37 @@ } //----------------------------------------------------------------------------- -/** + /** * expand_home - - * @user: username to use for home directory lookup - * @path: pathname to expand - * @size: size of @path + * @user: username to use for home directory lookup + * @path_pptr: pointer to pathname to expand * - * Expands tildes in @path to the user home directory and updates @path. - * Returns @dest. + * Expands tildes in @path_pptr to the user home directory. + * Returns true if successful, else false. */ -static char *expand_home(const char *user, char *path, size_t size) +static bool expand_home(const char *user, char **path_pptr) { - struct passwd *pe; - char *buf; - - if (path[0] != '~' || path[1] != '/') - return path; - - if ((pe = getpwnam(user)) == NULL) { - l0g("Could not lookup account information for %s\n", user); - return NULL; - } - - if ((buf = xmalloc(size)) == NULL) { - l0g("%s\n", strerror(errno)); - return NULL; - } - if (snprintf(buf, size, "%s%s", pe->pw_dir, path + 1) >= size) - l0g("Warning: Not enough buffer space in expand_home()\n"); + char *buf, *path = *path_pptr; + struct passwd *pe; + size_t size; - strncpy(path, buf, size); - free(buf); - return path; + if (path == NULL) + return true; + if (*path != '~') + return true; + if ((pe = getpwnam(user)) == NULL) { + misc_log("Could not lookup account info for %s\n", user); + return false; + } + size = strlen(pe->pw_dir) + strlen(path) + 1; + if ((buf = xmalloc(size)) == NULL) { + l0g("%s\n", strerror(errno)); + return NULL; + } + snprintf(buf, size, "%s%s", pe->pw_dir, path + 1); + free(path); + *path_pptr = buf; + return true; } /**