Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/sparsebundlefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@
static gid_t gid = []() {
// But prefer 'nogroup' for the group, since the group
// has no actual effect on who can access the mount.
if (group *nogroup = getgrnam("nogroup"))

Check notice on line 125 in src/sparsebundlefs.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/sparsebundlefs.cpp#L125

Consider using getgrnam_r(...) instead of getgrnam(...) for improved thread safety. (runtime/threadsafe_fn)
return nogroup->gr_gid;
if (group *nobody = getgrnam("nobody"))

Check notice on line 127 in src/sparsebundlefs.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/sparsebundlefs.cpp#L127

Consider using getgrnam_r(...) instead of getgrnam(...) for improved thread safety. (runtime/threadsafe_fn)
return nobody->gr_gid;
// Fall back to the mounting user
return getgid();
Expand Down Expand Up @@ -523,12 +523,12 @@

case FUSE_OPT_KEY_NONOPT:
if (!sparsebundle->path) {
sparsebundle->path = realpath(arg, 0);

Check notice on line 526 in src/sparsebundlefs.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/sparsebundlefs.cpp#L526

Use of strtrns (CWE-120, CWE-785) (flawfinder7-realpath)
if (!sparsebundle->path)
sparsebundle_fatal_error("bad sparse-bundle `%s'", arg);
return SPARSEBUNDLE_OPT_HANDLED;
} else if (!sparsebundle->mountpoint) {
sparsebundle->mountpoint = realpath(arg, 0);

Check notice on line 531 in src/sparsebundlefs.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/sparsebundlefs.cpp#L531

Use of strtrns (CWE-120, CWE-785) (flawfinder7-realpath)
if (!sparsebundle->mountpoint)
sparsebundle_fatal_error("bad mount point `%s'", arg);
fuse_opt_add_arg(outargs, sparsebundle->mountpoint);
Expand All @@ -550,89 +550,89 @@
return value;
}

int main(int argc, char **argv)
{
openlog("sparsebundlefs", LOG_PERROR, LOG_USER);
setlogmask(~(LOG_MASK(LOG_DEBUG)));

struct sparsebundle_t sparsebundle = {};

struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
fuse_opt_parse(&args, &sparsebundle, sparsebundle_options, sparsebundle_opt_proc);

fuse_opt_add_arg(&args, "-oro"); // Force read-only mount
fuse_opt_add_arg(&args, "-s"); // Force single-threaded operation

if (!sparsebundle.path || !sparsebundle.mountpoint)
return sparsebundle_show_usage(argv[0]);

syslog(LOG_DEBUG, "mounting `%s' at mount-point `%s'",
sparsebundle.path, sparsebundle.mountpoint);

char *last_dot = strrchr(sparsebundle.path, '.');
if (!last_dot || strcmp(last_dot, ".sparsebundle") != 0)
if (!last_dot || (strcmp(last_dot, ".sparsebundle") != 0 && strcmp(last_dot, ".backupbundle") != 0))
sparsebundle_fatal_error("%s is not a sparse bundle (wrong extension)",
sparsebundle.path);

char *plist_path;
if (asprintf(&plist_path, "%s/Info.plist", sparsebundle.path) == -1)
sparsebundle_fatal_error("could not resolve Info.plist path");

ifstream plist_file(plist_path);
if (!plist_file.is_open())
sparsebundle_fatal_error("failed to open %s", plist_path);

stringstream plist_data;
plist_data << plist_file.rdbuf();

string key, line;
while (getline(plist_data, line)) {
static const char whitespace_chars[] = " \n\r\t";
line.erase(0, line.find_first_not_of(whitespace_chars));
line.erase(line.find_last_not_of(whitespace_chars) + 1);

if (line.compare(0, 5, "<key>") == 0) {
key = line.substr(5, line.length() - 11);
} else if (!key.empty()) {
line.erase(0, line.find_first_of('>') + 1);
line.erase(line.find_first_of('<'));

if (key == "band-size")
sparsebundle.band_size = read_size(line);
else if (key == "size")
sparsebundle.size = read_size(line);

key.clear();
}
}

syslog(LOG_DEBUG, "bundle has band size %ju and total size %ju",
uintmax_t(sparsebundle.band_size), uintmax_t(sparsebundle.size));

if (!sparsebundle.band_size || !sparsebundle.size)
sparsebundle_fatal_error("invalid (zero) band size or total size");

syslog(LOG_DEBUG, "mounting as uid=%d, with allow_other=%d and allow_root=%d",
getuid(), sparsebundle.options.allow_other, sparsebundle.options.allow_root);

struct fuse_operations sparsebundle_filesystem_operations = {};
sparsebundle_filesystem_operations.getattr = sparsebundle_getattr;
sparsebundle_filesystem_operations.open = sparsebundle_open;
sparsebundle_filesystem_operations.read = sparsebundle_read;
sparsebundle_filesystem_operations.readdir = sparsebundle_readdir;
sparsebundle_filesystem_operations.release = sparsebundle_release;
#if FUSE_SUPPORTS_ZERO_COPY
syslog(LOG_DEBUG, "fuse supports zero-copy");
if (sparsebundle.options.noreadbuf)
syslog(LOG_DEBUG, "disabling zero-copy");
else
sparsebundle_filesystem_operations.read_buf = sparsebundle_read_buf;
#endif

syslog(LOG_DEBUG, "max open file descriptors is %ju",
uintmax_t(sparsebundle_max_files()));

int ret = fuse_main(args.argc, args.argv, &sparsebundle_filesystem_operations, &sparsebundle);
syslog(LOG_DEBUG, "exiting with return code %d", ret);
return ret;

Check notice on line 637 in src/sparsebundlefs.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/sparsebundlefs.cpp#L553-L637

Complex Method
}