diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bindfs.1 | 29 | ||||
-rw-r--r-- | src/bindfs.c | 27 |
2 files changed, 53 insertions, 3 deletions
diff --git a/src/bindfs.1 b/src/bindfs.1 index c71f988..1663cd1 100644 --- a/src/bindfs.1 +++ b/src/bindfs.1 @@ -64,21 +64,44 @@ Currently, the options \fB--force-user\fP, \fB--force-group\fP, \fB--mirror\fP, the corresponding behavior of this option. Requires mounting as root. + .TP .B \-\-map-passwd=\fI<passwdfile>\fP, \-o map-passwd=\fI<passwdfile>\fP .PD 0 .TP .B \-\-map-group=\fI<groupfile>\fP, \-o map-group=\fI<groupfile>\fP Like \fB--map=...\fP, but reads the UID/GID mapping from passwd and group -files (like \fI/etc/passwd\fP and \fI/etc/group\fP). Helpful to restore -system backups where UIDs/GIDs differ. +files (like \fI/etc/passwd\fP and \fI/etc/group\fP). Maps UID/GID provided in +the \fI<passwdfile>\fP or \fI<groupfile>\fP to its corresponding user/group +name. Helpful to restore system backups where UIDs/GIDs differ. Example usage: \& bindfs --map-passwd=/mnt/orig/etc/passwd \\ .br \& \--map-group=/mnt/orig/etc/group \\ -.br +.br +\& /mnt/orig /mnt/mapped + +Requires mounting as root. + +.TP +.B \-\-map-passwd-rev=\fI<passwdfile>\fP, \-o map-passwd-rev=\fI<passwdfile>\fP +.PD 0 +.TP +.B \-\-map-group-rev=\fI<groupfile>\fP, \-o map-group-rev=\fI<groupfile>\fP +Reversed variant of \fB--map-passwd\fP and \fB--map-group\fP. Like +\fB--map=...\fP, but reads the UID/GID mapping from passwd and group files +(like \fI/etc/passwd\fP and \fI/etc/group\fP). Maps user/group name provided in +the \fI<passwdfile>\fP or \fI<groupfile>\fP to its corresponding UID/GID. +Helpful to create compatible chroot environments where UIDs/GIDs differ. + +Example usage: + +\& bindfs --map-passwd-rev=/mnt/mapped/etc/passwd \\ +.br +\& \--map-group-rev=/mnt/mapped/etc/group \\ +.br \& /mnt/orig /mnt/mapped Requires mounting as root. diff --git a/src/bindfs.c b/src/bindfs.c index 332999b..fd71624 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -1695,6 +1695,8 @@ static void print_usage(const char *progname) " --map=user1/user2:... Let user2 see files of user1 as his own.\n" " --map-passwd=<passwdfile> Load uid mapping from <passwdfile>.\n" " --map-group=<groupfile> Load gid mapping from <groupfile>.\n" + " --map-passwd-rev=<passwdfile> Load reversed uid mapping from <passwdfile>.\n" + " --map-group-rev=<groupfile> Load reversed gid mapping from <groupfile>.\n" " --uid-offset=... Set file uid = uid + offset.\n" " --gid-offset=... Set file gid = gid + offset.\n" "\n" @@ -2322,6 +2324,8 @@ int main(int argc, char *argv[]) char *map; char *map_passwd; char *map_group; + char *map_passwd_rev; + char *map_group_rev; char *read_rate; char *write_rate; char *create_for_user; @@ -2366,6 +2370,8 @@ int main(int argc, char *argv[]) OPT_OFFSET2("--map=%s", "map=%s", map, -1), OPT_OFFSET2("--map-passwd=%s", "map-passwd=%s", map_passwd, -1), OPT_OFFSET2("--map-group=%s", "map-group=%s", map_group, -1), + OPT_OFFSET2("--map-passwd-rev=%s", "map-passwd=%s", map_passwd_rev, -1), + OPT_OFFSET2("--map-group-rev=%s", "map-group=%s", map_group_rev, -1), OPT_OFFSET3("-n", "--no-allow-other", "no-allow-other", no_allow_other, -1), OPT_OFFSET2("--read-rate=%s", "read-rate=%s", read_rate, -1), @@ -2544,6 +2550,17 @@ int main(int argc, char *argv[]) } } + if (od.map_passwd_rev) { + if (getuid() != 0) { + fprintf(stderr, "Error: You need to be root to use --map-passwd-rev !\n"); + return 1; + } + if (!parse_map_file(settings.usermap_reverse, settings.usermap, od.map_passwd_rev, 0)) { + /* parse_map_file printed an error */ + return 1; + } + } + /* Parse group */ if (od.map_group) { if (getuid() != 0) { @@ -2556,6 +2573,16 @@ int main(int argc, char *argv[]) } } + if (od.map_group_rev) { + if (getuid() != 0) { + fprintf(stderr, "Error: You need to be root to use --map-group-rev !\n"); + return 1; + } + if (!parse_map_file(settings.usermap_reverse, settings.usermap, od.map_group_rev, 1)) { + /* parse_map_file printed an error */ + return 1; + } + } /* Parse usermap (may overwrite values from --map-passwd and --map-group) */ if (od.map) { if (getuid() != 0) { |