aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bindfs.c88
-rw-r--r--src/misc.c4
-rw-r--r--src/misc.h1
-rw-r--r--src/userinfo.c40
4 files changed, 66 insertions, 67 deletions
diff --git a/src/bindfs.c b/src/bindfs.c
index 5f4b3c8..8c999e2 100644
--- a/src/bindfs.c
+++ b/src/bindfs.c
@@ -80,10 +80,10 @@ static struct Settings {
const char *mntsrc;
const char *mntdest;
int mntsrc_fd;
-
+
char* original_working_dir;
mode_t original_umask;
-
+
UserMap* usermap; /* From the --map option. */
UserMap* usermap_reverse;
@@ -111,7 +111,7 @@ static struct Settings {
CHMOD_IGNORE,
CHMOD_DENY
} chmod_policy;
-
+
int chmod_allow_x;
struct permchain *chmod_permchain; /* the --chmod-filter option */
@@ -132,7 +132,7 @@ static struct Settings {
int ctime_from_mtime;
int hide_hard_links;
-
+
} settings;
@@ -258,7 +258,7 @@ static int getattr_common(const char *procpath, struct stat *stbuf)
/* Possibly map user/group */
stbuf->st_uid = usermap_get_uid_or_default(settings.usermap, stbuf->st_uid, stbuf->st_uid);
stbuf->st_gid = usermap_get_gid_or_default(settings.usermap, stbuf->st_gid, stbuf->st_gid);
-
+
/* Report user-defined owner/group if specified */
if (settings.new_uid != -1)
stbuf->st_uid = settings.new_uid;
@@ -320,7 +320,7 @@ static void chown_new_file(const char *path, struct fuse_context *fc, int (*chow
file_owner = -1;
file_group = -1;
}
-
+
file_owner = usermap_get_uid_or_default(settings.usermap_reverse, fc->uid, file_owner);
file_group = usermap_get_gid_or_default(settings.usermap_reverse, fc->gid, file_group);
@@ -342,7 +342,7 @@ static void *bindfs_init()
{
assert(settings.permchain != NULL);
assert(settings.mntsrc_fd > 0);
-
+
maybe_stdout_stderr_to_file();
if (fchdir(settings.mntsrc_fd) != 0) {
@@ -427,9 +427,9 @@ static int bindfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
struct stat st;
int result = 0;
long pc_ret;
-
+
path = process_path(path);
-
+
pc_ret = pathconf(path, _PC_NAME_MAX);
if (pc_ret < 0) {
DPRINTF("pathconf failed: %s (%d)", strerror(errno), errno);
@@ -447,7 +447,7 @@ static int bindfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
if (de == NULL) {
break;
}
-
+
memset(&st, 0, sizeof(st));
st.st_ino = de->d_ino;
st.st_mode = de->d_type << 12;
@@ -644,7 +644,7 @@ static int bindfs_chown(const char *path, uid_t uid, gid_t gid)
return -EPERM;
}
}
-
+
if (gid != -1) {
switch (settings.chgrp_policy) {
case CHGRP_NORMAL:
@@ -755,7 +755,7 @@ static int bindfs_read(const char *path, char *buf, size_t size, off_t offset,
{
int res;
(void) path;
-
+
res = pread(fi->fh, buf, size, offset);
if (res == -1)
res = -errno;
@@ -792,7 +792,7 @@ static int bindfs_statfs(const char *path, struct statvfs *stbuf)
static int bindfs_release(const char *path, struct fuse_file_info *fi)
{
(void) path;
-
+
close(fi->fh);
return 0;
@@ -825,7 +825,7 @@ static int bindfs_setxattr(const char *path, const char *name, const char *value
size_t size, int flags)
{
DPRINTF("setxattr %s %s=%s", path, name, value);
-
+
if (settings.xattr_policy == XATTR_READ_ONLY)
return -EACCES;
@@ -846,7 +846,7 @@ static int bindfs_getxattr(const char *path, const char *name, char *value,
int res;
DPRINTF("getxattr %s %s", path, name);
-
+
path = process_path(path);
/* fuse checks permissions for us */
#ifdef HAVE_LGETXATTR
@@ -864,7 +864,7 @@ static int bindfs_listxattr(const char *path, char *list, size_t size)
int res;
DPRINTF("listxattr %s", path);
-
+
path = process_path(path);
/* fuse checks permissions for us */
#ifdef HAVE_LLISTXATTR
@@ -1181,7 +1181,7 @@ static int parse_mirrored_users(char* mirror)
assert(j == settings.num_mirrored_members);
}
}
-
+
return 1;
}
@@ -1193,11 +1193,11 @@ static int parse_user_map(UserMap *map, UserMap *reverse_map, char *spec)
uid_t uid_from, uid_to;
gid_t gid_from, gid_to;
UsermapStatus status;
-
+
while (*p != '\0') {
free(tmpstr);
tmpstr = strdup_until(p, ",:");
-
+
if (tmpstr[0] == '@') { /* group */
q = strstr(tmpstr, "/@");
if (!q) {
@@ -1214,7 +1214,7 @@ static int parse_user_map(UserMap *map, UserMap *reverse_map, char *spec)
fprintf(stderr, "Invalid group: %s\n", tmpstr);
goto fail;
}
-
+
status = usermap_add_gid(map, gid_from, gid_to);
if (status != 0) {
fprintf(stderr, "%s\n", usermap_errorstr(status));
@@ -1225,9 +1225,9 @@ static int parse_user_map(UserMap *map, UserMap *reverse_map, char *spec)
fprintf(stderr, "%s\n", usermap_errorstr(status));
goto fail;
}
-
+
} else {
-
+
q = strstr(tmpstr, "/");
if (!q) {
fprintf(stderr, "Invalid syntax: expected user1/user2 but got `%s`\n", tmpstr);
@@ -1243,7 +1243,7 @@ static int parse_user_map(UserMap *map, UserMap *reverse_map, char *spec)
fprintf(stderr, "Invalid username: %s\n", tmpstr);
goto fail;
}
-
+
status = usermap_add_uid(map, uid_from, uid_to);
if (status != 0) {
fprintf(stderr, "%s\n", usermap_errorstr(status));
@@ -1255,7 +1255,7 @@ static int parse_user_map(UserMap *map, UserMap *reverse_map, char *spec)
goto fail;
}
}
-
+
while (*p != '\0' && *p != ',' && *p != ':') {
++p;
}
@@ -1263,10 +1263,10 @@ static int parse_user_map(UserMap *map, UserMap *reverse_map, char *spec)
++p;
}
}
-
+
free(tmpstr);
return 1;
-
+
fail:
free(tmpstr);
return 0;
@@ -1277,16 +1277,16 @@ static void maybe_stdout_stderr_to_file()
/* TODO: make this a command line option. */
#if 0
int fd;
-
+
const char *filename = "bindfs.log";
char *path = malloc(strlen(settings.original_working_dir) + 1 + strlen(filename) + 1);
strcpy(path, settings.original_working_dir);
strcat(path, "/");
strcat(path, filename);
-
+
fd = open(path, O_CREAT | O_WRONLY, 0666);
free(path);
-
+
fchmod(fd, 0777 & ~settings.original_umask);
fflush(stdout);
fflush(stderr);
@@ -1312,7 +1312,7 @@ static void setup_signal_handling()
sa.sa_handler = signal_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
-
+
sigaction(SIGUSR1, &sa, NULL);
}
@@ -1376,43 +1376,43 @@ int main(int argc, char *argv[])
static const struct fuse_opt options[] = {
OPT2("-h", "--help", OPTKEY_HELP),
OPT2("-V", "--version", OPTKEY_VERSION),
-
+
OPT_OFFSET3("-u %s", "--force-user=%s", "force-user=%s", user, -1),
OPT_OFFSET3("-g %s", "--force-group=%s", "force-group=%s", group, -1),
-
+
OPT_OFFSET3("--user=%s", "--owner=%s", "owner=%s", deprecated_user, -1),
OPT_OFFSET2("--group=%s", "group=%s", deprecated_group, -1),
-
+
OPT_OFFSET3("-p %s", "--perms=%s", "perms=%s", perms, -1),
OPT_OFFSET3("-m %s", "--mirror=%s", "mirror=%s", mirror, -1),
OPT_OFFSET3("-M %s", "--mirror-only=%s", "mirror-only=%s", mirror_only, -1),
OPT_OFFSET2("--map=%s", "map=%s", map, -1),
OPT_OFFSET3("-n", "--no-allow-other", "no-allow-other", no_allow_other, -1),
-
+
OPT2("--create-as-user", "create-as-user", OPTKEY_CREATE_AS_USER),
OPT2("--create-as-mounter", "create-as-mounter", OPTKEY_CREATE_AS_MOUNTER),
OPT_OFFSET2("--create-for-user=%s", "create-for-user=%s", create_for_user, -1),
OPT_OFFSET2("--create-for-group=%s", "create-for-group=%s", create_for_group, -1),
OPT_OFFSET2("--create-with-perms=%s", "create-with-perms=%s", create_with_perms, -1),
-
+
OPT2("--chown-normal", "chown-normal", OPTKEY_CHOWN_NORMAL),
OPT2("--chown-ignore", "chown-ignore", OPTKEY_CHOWN_IGNORE),
OPT2("--chown-deny", "chown-deny", OPTKEY_CHOWN_DENY),
-
+
OPT2("--chgrp-normal", "chgrp-normal", OPTKEY_CHGRP_NORMAL),
OPT2("--chgrp-ignore", "chgrp-ignore", OPTKEY_CHGRP_IGNORE),
OPT2("--chgrp-deny", "chgrp-deny", OPTKEY_CHGRP_DENY),
-
+
OPT2("--chmod-normal", "chmod-normal", OPTKEY_CHMOD_NORMAL),
OPT2("--chmod-ignore", "chmod-ignore", OPTKEY_CHMOD_IGNORE),
OPT2("--chmod-deny", "chmod-deny", OPTKEY_CHMOD_DENY),
OPT_OFFSET2("--chmod-filter=%s", "chmod-filter=%s", chmod_filter, -1),
OPT2("--chmod-allow-x", "chmod-allow-x", OPTKEY_CHMOD_ALLOW_X),
-
+
OPT2("--xattr-none", "xattr-none", OPTKEY_XATTR_NONE),
OPT2("--xattr-ro", "xattr-ro", OPTKEY_XATTR_READ_ONLY),
OPT2("--xattr-rw", "xattr-rw", OPTKEY_XATTR_READ_WRITE),
-
+
OPT2("--realistic-permissions", "realistic-permissions", OPTKEY_REALISTIC_PERMISSIONS),
OPT2("--ctime-from-mtime", "ctime-from-mtime", OPTKEY_CTIME_FROM_MTIME),
OPT2("--hide-hard-links", "hide-hard-links", OPTKEY_HIDE_HARD_LINKS),
@@ -1453,7 +1453,7 @@ int main(int argc, char *argv[])
settings.ctime_from_mtime = 0;
settings.hide_hard_links = 0;
atexit(&atexit_func);
-
+
/* Parse options */
if (fuse_opt_parse(&args, &od, options, &process_option) == -1)
return 1;
@@ -1463,7 +1463,7 @@ int main(int argc, char *argv[])
print_usage(my_basename(argv[0]));
return 1;
}
-
+
/* Check for deprecated options */
if (od.deprecated_user) {
fprintf(stderr, "Deprecation warning: please use --force-user instead of --user or --owner.\n");
@@ -1493,7 +1493,7 @@ int main(int argc, char *argv[])
return 1;
}
}
-
+
/* Parse usermap */
if (od.map) {
if (getuid() != 0) {
@@ -1576,11 +1576,11 @@ int main(int argc, char *argv[])
/* We want the kernel to do our access checks for us based on what getattr gives it. */
fuse_opt_add_arg(&args, "-odefault_permissions");
-
+
/* We want to mirror inodes. */
fuse_opt_add_arg(&args, "-ouse_ino");
fuse_opt_add_arg(&args, "-oreaddir_ino");
-
+
/* We need to disable the attribute cache whenever two users
can see different attributes. For now, only mirroring can do that. */
if (is_mirroring_enabled()) {
diff --git a/src/misc.c b/src/misc.c
index bb838c7..799f555 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -116,7 +116,7 @@ void grow_array_impl(void **array, int* capacity, int member_size)
} else {
new_cap *= 2;
}
-
+
*array = realloc(*array, new_cap * member_size);
*capacity = new_cap;
}
@@ -135,7 +135,7 @@ void init_arena(struct arena *a, int initial_capacity)
void grow_arena(struct arena *a, int amount)
{
int new_cap;
-
+
a->size += amount;
if (a->size >= a->capacity) {
new_cap = a->capacity;
diff --git a/src/misc.h b/src/misc.h
index f09883d..8b00f8d 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -17,7 +17,6 @@
along with bindfs. If not, see <http://www.gnu.org/licenses/>.
*/
-
#ifndef INC_BINDFS_MISC_H
#define INC_BINDFS_MISC_H
diff --git a/src/userinfo.c b/src/userinfo.c
index a86c171..89afe6e 100644
--- a/src/userinfo.c
+++ b/src/userinfo.c
@@ -103,9 +103,9 @@ static int rebuild_uid_cache()
struct passwd *pw;
struct uid_cache_entry *ent;
int username_len;
-
+
uid_cache_size = 0;
-
+
while (1) {
errno = 0;
pw = getpwent();
@@ -116,19 +116,19 @@ static int rebuild_uid_cache()
goto error;
}
}
-
+
if (uid_cache_size == uid_cache_capacity) {
grow_array(&uid_cache, &uid_cache_capacity, sizeof(struct uid_cache_entry));
}
-
+
ent = &uid_cache[uid_cache_size++];
ent->uid = pw->pw_uid;
ent->main_gid = pw->pw_gid;
-
+
username_len = strlen(pw->pw_name) + 1;
ent->username_offset = append_to_arena(&cache_arena, pw->pw_name, username_len);
}
-
+
endpwent();
return 1;
error:
@@ -145,11 +145,11 @@ static int rebuild_gid_cache()
struct gid_cache_entry *ent;
int i;
struct uid_cache_entry *uid_ent;
-
+
gid_cache_size = 0;
-
+
qsort(uid_cache, uid_cache_size, sizeof(struct uid_cache_entry), uid_cache_name_sortcmp);
-
+
while (1) {
errno = 0;
gr = getgrent();
@@ -160,16 +160,16 @@ static int rebuild_gid_cache()
goto error;
}
}
-
+
if (gid_cache_size == gid_cache_capacity) {
grow_array(&gid_cache, &gid_cache_capacity, sizeof(struct gid_cache_entry));
}
-
+
ent = &gid_cache[gid_cache_size++];
ent->gid = gr->gr_gid;
ent->uid_count = 0;
ent->uids_offset = cache_arena.size;
-
+
for (i = 0; gr->gr_mem[i] != NULL; ++i) {
uid_ent = (struct uid_cache_entry *)bsearch(
gr->gr_mem[i],
@@ -185,7 +185,7 @@ static int rebuild_gid_cache()
}
}
}
-
+
endgrent();
return 1;
error:
@@ -344,12 +344,12 @@ int user_belongs_to_group(uid_t uid, gid_t gid)
int ret = 0;
int i;
uid_t *uids;
-
+
pthread_rwlock_rdlock(&cache_lock);
-
+
if (cache_rebuild_requested) {
pthread_rwlock_unlock(&cache_lock);
-
+
pthread_rwlock_wrlock(&cache_lock);
if (cache_rebuild_requested) {
DPRINTF("Building user/group cache");
@@ -357,16 +357,16 @@ int user_belongs_to_group(uid_t uid, gid_t gid)
rebuild_cache();
}
pthread_rwlock_unlock(&cache_lock);
-
+
pthread_rwlock_rdlock(&cache_lock);
}
-
+
struct uid_cache_entry *uent = uid_cache_lookup(uid);
if (uent && uent->main_gid == gid) {
ret = 1;
goto done;
}
-
+
struct gid_cache_entry *gent = gid_cache_lookup(gid);
if (gent) {
uids = (uid_t*)ARENA_GET(cache_arena, gent->uids_offset);
@@ -377,7 +377,7 @@ int user_belongs_to_group(uid_t uid, gid_t gid)
}
}
}
-
+
done:
pthread_rwlock_unlock(&cache_lock);
return ret;