Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2018-01-15 Martin Pärtel <martin dot partel at gmail dot com>

* Added option --no-user-group-precaching (issue #62).

2017-11-30 Martin Pärtel <martin dot partel at gmail dot com>

* Added options --delete-deny and --rename-deny as suggested by @roojs.
Expand Down
8 changes: 8 additions & 0 deletions src/bindfs.1
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ ioctl. This may be a security concern, especially when mounting as root.
.B \-\-block\-devices\-as\-files, \-o block\-devices\-as\-files
Shows block devices as regular files.

.TP
.B \-\-no\-user\-group\-precaching, \-o no\-user\-group\-precaching
Disables the default behaviour of caching users and their group memberships
at startup. Instead they are read and then cached indefinitely on-demand.
Sending bindfs \fBSIGUSR1\fP will clear this cache in either case.

Currently this cache is only used by \fB\-\-mirror\fP and \fB\-\-mirror\-only\fP.

.TP
.B \-\-multithreaded, \-o multithreaded
Run bindfs in multithreaded mode. While bindfs is designed to be
Expand Down
20 changes: 15 additions & 5 deletions src/bindfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ static void print_usage(const char *progname)
" --resolve-symlinks Resolve symbolic links.\n"
" --resolved-symlink-deletion=... Decide how to delete resolved symlinks.\n"
" --block-devices-as-files Show block devices as regular files.\n"
" --no-user-group-precaching Don't read all users and groups at startup.\n"
" --multithreaded Enable multithreaded mode. See man page\n"
" for security issue with current implementation.\n"
"\n"
Expand Down Expand Up @@ -1846,11 +1847,14 @@ static void setup_signal_handling()

static void signal_handler(int sig)
{
invalidate_user_cache();
invalidate_user_caches();
}

static void atexit_func()
{
// This cleanup is mostly unnecessary, but we do it anyway to
// reduce the "still reachable" allocations that Valgrind shows.

free(settings.mntsrc);
free(settings.mntdest);
free(settings.original_working_dir);
Expand Down Expand Up @@ -1879,6 +1883,8 @@ static void atexit_func()
settings.mirrored_users = NULL;
free(settings.mirrored_members);
settings.mirrored_members = NULL;

clear_user_caches();
}

int main(int argc, char *argv[])
Expand All @@ -1903,6 +1909,7 @@ int main(int argc, char *argv[])
char *chmod_filter;
char *resolved_symlink_deletion;
int no_allow_other;
int no_user_group_precaching;
int multithreaded;
char *uid_offset;
char *gid_offset;
Expand Down Expand Up @@ -1974,13 +1981,11 @@ int main(int argc, char *argv[])
OPT2("--enable-lock-forwarding", "enable-lock-forwarding", OPTKEY_ENABLE_LOCK_FORWARDING),
OPT2("--disable-lock-forwarding", "disable-lock-forwarding", OPTKEY_DISABLE_LOCK_FORWARDING),
OPT2("--enable-ioctl", "enable-ioctl", OPTKEY_ENABLE_IOCTL),
OPT_OFFSET2("--no-user-group-precaching", "no-user-group-precaching", no_user_group_precaching, -1),
OPT_OFFSET2("--multithreaded", "multithreaded", multithreaded, -1),
OPT_OFFSET2("--uid-offset=%s", "uid-offset=%s", uid_offset, 0),
OPT_OFFSET2("--gid-offset=%s", "gid-offset=%s", gid_offset, 0),





FUSE_OPT_END
};

Expand Down Expand Up @@ -2176,6 +2181,11 @@ int main(int argc, char *argv[])
}
}

/* Precache entire user/group database for use by --mirror by default */
if (!od.no_user_group_precaching) {
rebuild_user_caches();
}

/* Parse permission bits */
if (od.perms) {
if (add_chmod_rules_to_permchain(od.perms, settings.permchain) != 0) {
Expand Down
24 changes: 24 additions & 0 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ const char *my_dirname(char *path)
}
}

void insertion_sort_last(void *base, size_t nmemb, size_t size, int (*compar)(const void*, const void*))
{
void *const last = base + (nmemb - 1) * size;
void *const entry = malloc(size);
memcpy(entry, last, size);

// Find the location to insert at.
int n = 0;
void *p = last - size;
while (p >= base && compar(entry, p) < 0) {
p -= size;
n += 1;
}

// We found a *p that's larger or we went below the start of the array, so go back one step.
p += size;
// No need to adjust n, it's now the correct number of elements to shift forward

// Insert at *p.
memmove(p + size, p, n * size);
memcpy(p, entry, size);
free(entry);
}

void grow_array_impl(void **array, int *capacity, int member_size)
{
int new_cap = *capacity;
Expand Down
5 changes: 5 additions & 0 deletions src/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef INC_BINDFS_MISC_H
#define INC_BINDFS_MISC_H

#include <stdlib.h>

/* Counts the number of times ch occurs in s. */
int count_chars(const char *s, char ch);
Expand Down Expand Up @@ -49,6 +50,10 @@ const char *my_basename(const char *path);
Otherwise, returns ".". */
const char *my_dirname(char *path);

/* Sorts an array that is otherwise sorted, but whose last element may be in the wrong place.
The signature is the same as qsort's. */
void insertion_sort_last(void *base, size_t nmemb, size_t size, int (*compar)(const void*, const void*));

/* Reallocs `*array` (may be NULL) to be at least one larger
than `*capacity` (may be 0) and stores the new capacity
in `*capacity`. */
Expand Down
Loading