Add function expand_home

This commit is contained in:
wbaumann
2012-01-22 16:17:47 +00:00
parent b9f1ccd793
commit da76a8448a
2 changed files with 34 additions and 0 deletions

View File

@ -190,6 +190,9 @@ delete_args(dav_args *args);
static void
eval_modes(dav_args *args);
static void
expand_home(char **dir, const dav_args *args);
static void
get_options(dav_args *args, char *option);
@ -1583,6 +1586,33 @@ eval_modes(dav_args *args)
}
/* If *dir starts with '~/' or '~user/' it is turned into an
absolute filename (starting with '/') in the users home directory.
user must be the name of the mounting user.
Otherwise dir is unchanged.
Requires: username, home. */
static void
expand_home(char **dir, const dav_args *args)
{
if (!dir || !*dir || **dir != '~')
return;
char *p = *dir + 1;
if (*p != '/') {
if (strstr(*dir, args->uid_name) != p)
return;
p += strlen(args->uid_name);
}
if (*p != '/')
return;
char *new_dir = NULL;
if (asprintf(&new_dir, "%s%s", args->home, p) < 0)
abort();
free(*dir);
*dir = new_dir;
}
/* Parses the string option and stores the values in the appropriate fields of
args. If an unknown option is found exit(EXIT_FAILURE) is called.
All strings returned in args are newly allocated, and the calling function