Add function expand_home
This commit is contained in:
parent
b9f1ccd793
commit
da76a8448a
@ -1,6 +1,10 @@
|
||||
ChangeLog for davfs2
|
||||
--------------------
|
||||
|
||||
2012-01-22 Werner Baumann (werner.baumann@onlinehome.de)
|
||||
* mount_davfs.c:
|
||||
Add function expand_home.
|
||||
|
||||
2012-01-21 Werner Baumann (werner.baumann@onlinehome.de)
|
||||
* mount_davfs.c, check_fstab, get_options, parse_persona:
|
||||
Rename check_persona into parse_persona.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user