aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-10-13 23:25:14 +0900
committerOphestra <cat@gensokyo.uk>2026-10-13 23:33:49 +0900
commit612533ee40aaeb97247db551ecbfc5026eb3ca41 (patch)
tree13ae364771f9bcf0def2b7401924d5b7c82af790
parentfadb42ec8daeeb8a576582d274cd4aeb64e535c0 (diff)
all: use Linux kernel coding style
The Gitea web interface is no longer publicly accessible, so it no longer matters that this code style does not render well on Gitea. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--.clang-format121
-rw-r--r--cmd/sharefs/fuse-operations.c414
-rw-r--r--cmd/sharefs/fuse-operations.h44
-rw-r--r--container/seccomp/libseccomp-helper.c218
-rw-r--r--container/seccomp/libseccomp-helper.h23
-rw-r--r--internal/acl/libacl-helper.c200
-rw-r--r--internal/acl/libacl-helper.h35
-rw-r--r--internal/outcome/shim-signal.c81
-rw-r--r--internal/outcome/shim-signal.h8
-rw-r--r--internal/wayland/wayland-client-helper.c185
-rw-r--r--internal/wayland/wayland-client-helper.h64
11 files changed, 787 insertions, 606 deletions
diff --git a/.clang-format b/.clang-format
index ea649c2b..6a0dea43 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,2 +1,119 @@
-ColumnLimit: 0
-IndentWidth: 4
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/dev-tools/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/cmd/sharefs/fuse-operations.c b/cmd/sharefs/fuse-operations.c
index ecff1ad6..36417126 100644
--- a/cmd/sharefs/fuse-operations.c
+++ b/cmd/sharefs/fuse-operations.c
@@ -14,269 +14,301 @@
/* MUST_TRANSLATE_PATHNAME translates a userspace pathname to a relative pathname;
* the resulting address points to a constant string or part of pathname, it is never heap allocated. */
#define MUST_TRANSLATE_PATHNAME(pathname) \
- do { \
- if (pathname == NULL) \
- return -EINVAL; \
- while (*pathname == '/') \
- pathname++; \
- if (*pathname == '\0') \
- pathname = "."; \
- } while (0)
+ do { \
+ if (pathname == NULL) \
+ return -EINVAL; \
+ while (*pathname == '/') \
+ pathname++; \
+ if (*pathname == '\0') \
+ pathname = "."; \
+ } while (0)
/* GET_CONTEXT_PRIV obtains fuse context and private data for the calling thread. */
-#define GET_CONTEXT_PRIV(ctx, priv) \
- do { \
- ctx = fuse_get_context(); \
- priv = ctx->private_data; \
- } while (0)
+#define GET_CONTEXT_PRIV(ctx, priv) \
+ do { \
+ ctx = fuse_get_context(); \
+ priv = ctx->private_data; \
+ } while (0)
/* impl_getattr modifies a struct stat from the kernel to present to userspace;
* impl_getattr returns a negative errno style error code. */
-static int impl_getattr(struct fuse_context *ctx, struct stat *statbuf) {
- /* allowlist of permitted types */
- if (!S_ISDIR(statbuf->st_mode) && !S_ISREG(statbuf->st_mode) && !S_ISLNK(statbuf->st_mode)) {
- return -ENOTRECOVERABLE; /* returning an errno causes all operations on the file to return EIO */
- }
+static int impl_getattr(struct fuse_context *ctx, struct stat *statbuf)
+{
+ /* allowlist of permitted types */
+ if (!S_ISDIR(statbuf->st_mode) && !S_ISREG(statbuf->st_mode) &&
+ !S_ISLNK(statbuf->st_mode)) {
+ return -ENOTRECOVERABLE; /* returning an errno causes all operations on the file to return EIO */
+ }
#define OVERRIDE_PERM(v) (statbuf->st_mode & ~0777) | (v & 0777)
- if (S_ISDIR(statbuf->st_mode))
- statbuf->st_mode = OVERRIDE_PERM(SHAREFS_PERM_DIR);
- else if (S_ISREG(statbuf->st_mode))
- statbuf->st_mode = OVERRIDE_PERM(SHAREFS_PERM_REG);
- else
- statbuf->st_mode = 0; /* should always be symlink in this case */
+ if (S_ISDIR(statbuf->st_mode))
+ statbuf->st_mode = OVERRIDE_PERM(SHAREFS_PERM_DIR);
+ else if (S_ISREG(statbuf->st_mode))
+ statbuf->st_mode = OVERRIDE_PERM(SHAREFS_PERM_REG);
+ else
+ statbuf->st_mode =
+ 0; /* should always be symlink in this case */
- statbuf->st_uid = ctx->uid;
- statbuf->st_gid = SHAREFS_MEDIA_RW_ID;
- statbuf->st_ctim = statbuf->st_mtim;
- statbuf->st_nlink = 1;
- return 0;
+ statbuf->st_uid = ctx->uid;
+ statbuf->st_gid = SHAREFS_MEDIA_RW_ID;
+ statbuf->st_ctim = statbuf->st_mtim;
+ statbuf->st_nlink = 1;
+ return 0;
}
/* fuse_operations implementation */
-int sharefs_getattr(const char *pathname, struct stat *statbuf, struct fuse_file_info *fi) {
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+int sharefs_getattr(const char *pathname, struct stat *statbuf,
+ struct fuse_file_info *fi)
+{
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- (void)fi;
+ (void)fi;
- if (fstatat(priv->dirfd, pathname, statbuf, AT_SYMLINK_NOFOLLOW) == -1)
- return -errno;
- return impl_getattr(ctx, statbuf);
+ if (fstatat(priv->dirfd, pathname, statbuf, AT_SYMLINK_NOFOLLOW) == -1)
+ return -errno;
+ return impl_getattr(ctx, statbuf);
}
-int sharefs_readdir(const char *pathname, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags) {
- int fd;
- DIR *dp;
- struct stat st;
- int ret = 0;
- struct dirent *de;
+int sharefs_readdir(const char *pathname, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi,
+ enum fuse_readdir_flags flags)
+{
+ int fd;
+ DIR *dp;
+ struct stat st;
+ int ret = 0;
+ struct dirent *de;
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- (void)offset;
- (void)fi;
+ (void)offset;
+ (void)fi;
- if ((fd = openat(priv->dirfd, pathname, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1)
- return -errno;
- if ((dp = fdopendir(fd)) == NULL) {
- close(fd);
- return -errno;
- }
+ if ((fd = openat(priv->dirfd, pathname,
+ O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1)
+ return -errno;
+ if ((dp = fdopendir(fd)) == NULL) {
+ close(fd);
+ return -errno;
+ }
- errno = 0; /* for the next readdir call */
- while ((de = readdir(dp)) != NULL) {
- if (flags & FUSE_READDIR_PLUS) {
- if (fstatat(dirfd(dp), de->d_name, &st, AT_SYMLINK_NOFOLLOW) == -1) {
- ret = -errno;
- break;
- }
+ errno = 0; /* for the next readdir call */
+ while ((de = readdir(dp)) != NULL) {
+ if (flags & FUSE_READDIR_PLUS) {
+ if (fstatat(dirfd(dp), de->d_name, &st,
+ AT_SYMLINK_NOFOLLOW) == -1) {
+ ret = -errno;
+ break;
+ }
- if ((ret = impl_getattr(ctx, &st)) < 0)
- break;
+ if ((ret = impl_getattr(ctx, &st)) < 0)
+ break;
- errno = 0;
- ret = filler(buf, de->d_name, &st, 0, FUSE_FILL_DIR_PLUS);
- } else
- ret = filler(buf, de->d_name, NULL, 0, 0);
+ errno = 0;
+ ret = filler(buf, de->d_name, &st, 0,
+ FUSE_FILL_DIR_PLUS);
+ } else
+ ret = filler(buf, de->d_name, NULL, 0, 0);
- if (ret != 0) {
- ret = errno != 0 ? -errno : -EIO; /* filler */
- break;
- }
+ if (ret != 0) {
+ ret = errno != 0 ? -errno : -EIO; /* filler */
+ break;
+ }
- errno = 0; /* for the next readdir call */
- }
- if (ret == 0 && errno != 0)
- ret = -errno; /* readdir */
+ errno = 0; /* for the next readdir call */
+ }
+ if (ret == 0 && errno != 0)
+ ret = -errno; /* readdir */
- closedir(dp);
- return ret;
+ closedir(dp);
+ return ret;
}
-int sharefs_mkdir(const char *pathname, mode_t mode) {
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+int sharefs_mkdir(const char *pathname, mode_t mode)
+{
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- (void)mode;
+ (void)mode;
- if (mkdirat(priv->dirfd, pathname, SHAREFS_PERM_DIR) == -1)
- return -errno;
- return 0;
+ if (mkdirat(priv->dirfd, pathname, SHAREFS_PERM_DIR) == -1)
+ return -errno;
+ return 0;
}
-int sharefs_unlink(const char *pathname) {
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+int sharefs_unlink(const char *pathname)
+{
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- if (unlinkat(priv->dirfd, pathname, 0) == -1)
- return -errno;
- return 0;
+ if (unlinkat(priv->dirfd, pathname, 0) == -1)
+ return -errno;
+ return 0;
}
-int sharefs_rmdir(const char *pathname) {
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+int sharefs_rmdir(const char *pathname)
+{
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- if (unlinkat(priv->dirfd, pathname, AT_REMOVEDIR) == -1)
- return -errno;
- return 0;
+ if (unlinkat(priv->dirfd, pathname, AT_REMOVEDIR) == -1)
+ return -errno;
+ return 0;
}
-int sharefs_rename(const char *oldpath, const char *newpath, unsigned int flags) {
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(oldpath);
- MUST_TRANSLATE_PATHNAME(newpath);
+int sharefs_rename(const char *oldpath, const char *newpath, unsigned int flags)
+{
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(oldpath);
+ MUST_TRANSLATE_PATHNAME(newpath);
- /* TODO(ophestra): replace with wrapper after 05ce67fea99ca09cd4b6625cff7aec9cc222dd5a reaches a release */
- if (syscall(__NR_renameat2, priv->dirfd, oldpath, priv->dirfd, newpath, flags) == -1)
- return -errno;
- return 0;
+ /* TODO(ophestra): replace with wrapper after 05ce67fea99ca09cd4b6625cff7aec9cc222dd5a reaches a release */
+ if (syscall(__NR_renameat2, priv->dirfd, oldpath, priv->dirfd, newpath,
+ flags) == -1)
+ return -errno;
+ return 0;
}
-int sharefs_truncate(const char *pathname, off_t length, struct fuse_file_info *fi) {
- int fd;
- int ret;
+int sharefs_truncate(const char *pathname, off_t length,
+ struct fuse_file_info *fi)
+{
+ int fd;
+ int ret;
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- (void)fi;
+ (void)fi;
- if ((fd = openat(priv->dirfd, pathname, O_WRONLY | O_CLOEXEC)) == -1)
- return -errno;
- if ((ret = ftruncate(fd, length)) == -1)
- ret = -errno;
- close(fd);
- return ret;
+ if ((fd = openat(priv->dirfd, pathname, O_WRONLY | O_CLOEXEC)) == -1)
+ return -errno;
+ if ((ret = ftruncate(fd, length)) == -1)
+ ret = -errno;
+ close(fd);
+ return ret;
}
-int sharefs_utimens(const char *pathname, const struct timespec times[2], struct fuse_file_info *fi) {
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+int sharefs_utimens(const char *pathname, const struct timespec times[2],
+ struct fuse_file_info *fi)
+{
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- (void)fi;
+ (void)fi;
- if (utimensat(priv->dirfd, pathname, times, AT_SYMLINK_NOFOLLOW) == -1)
- return -errno;
- return 0;
+ if (utimensat(priv->dirfd, pathname, times, AT_SYMLINK_NOFOLLOW) == -1)
+ return -errno;
+ return 0;
}
-int sharefs_create(const char *pathname, mode_t mode, struct fuse_file_info *fi) {
- int fd;
+int sharefs_create(const char *pathname, mode_t mode, struct fuse_file_info *fi)
+{
+ int fd;
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- (void)mode;
+ (void)mode;
- if ((fd = openat(priv->dirfd, pathname, fi->flags & ~SHAREFS_FORBIDDEN_FLAGS, SHAREFS_PERM_REG)) == -1)
- return -errno;
- fi->fh = fd;
- return 0;
+ if ((fd = openat(priv->dirfd, pathname,
+ fi->flags & ~SHAREFS_FORBIDDEN_FLAGS,
+ SHAREFS_PERM_REG)) == -1)
+ return -errno;
+ fi->fh = fd;
+ return 0;
}
-int sharefs_open(const char *pathname, struct fuse_file_info *fi) {
- int fd;
+int sharefs_open(const char *pathname, struct fuse_file_info *fi)
+{
+ int fd;
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- if ((fd = openat(priv->dirfd, pathname, fi->flags & ~SHAREFS_FORBIDDEN_FLAGS)) == -1)
- return -errno;
- fi->fh = fd;
- return 0;
+ if ((fd = openat(priv->dirfd, pathname,
+ fi->flags & ~SHAREFS_FORBIDDEN_FLAGS)) == -1)
+ return -errno;
+ fi->fh = fd;
+ return 0;
}
-int sharefs_read(const char *pathname, char *buf, size_t count, off_t offset, struct fuse_file_info *fi) {
- int ret;
+int sharefs_read(const char *pathname, char *buf, size_t count, off_t offset,
+ struct fuse_file_info *fi)
+{
+ int ret;
- (void)pathname;
+ (void)pathname;
- if ((ret = pread(fi->fh, buf, count, offset)) == -1)
- return -errno;
- return ret;
+ if ((ret = pread(fi->fh, buf, count, offset)) == -1)
+ return -errno;
+ return ret;
}
-int sharefs_write(const char *pathname, const char *buf, size_t count, off_t offset, struct fuse_file_info *fi) {
- int ret;
+int sharefs_write(const char *pathname, const char *buf, size_t count,
+ off_t offset, struct fuse_file_info *fi)
+{
+ int ret;
- (void)pathname;
+ (void)pathname;
- if ((ret = pwrite(fi->fh, buf, count, offset)) == -1)
- return -errno;
- return ret;
+ if ((ret = pwrite(fi->fh, buf, count, offset)) == -1)
+ return -errno;
+ return ret;
}
-int sharefs_statfs(const char *pathname, struct statvfs *statbuf) {
- int fd;
- int ret;
+int sharefs_statfs(const char *pathname, struct statvfs *statbuf)
+{
+ int fd;
+ int ret;
- struct fuse_context *ctx;
- struct sharefs_private *priv;
- GET_CONTEXT_PRIV(ctx, priv);
- MUST_TRANSLATE_PATHNAME(pathname);
+ struct fuse_context *ctx;
+ struct sharefs_private *priv;
+ GET_CONTEXT_PRIV(ctx, priv);
+ MUST_TRANSLATE_PATHNAME(pathname);
- if ((fd = openat(priv->dirfd, pathname, O_RDONLY | O_CLOEXEC)) == -1)
- return -errno;
- if ((ret = fstatvfs(fd, statbuf)) == -1)
- ret = -errno;
- close(fd);
- return ret;
+ if ((fd = openat(priv->dirfd, pathname, O_RDONLY | O_CLOEXEC)) == -1)
+ return -errno;
+ if ((ret = fstatvfs(fd, statbuf)) == -1)
+ ret = -errno;
+ close(fd);
+ return ret;
}
-int sharefs_release(const char *pathname, struct fuse_file_info *fi) {
- (void)pathname;
+int sharefs_release(const char *pathname, struct fuse_file_info *fi)
+{
+ (void)pathname;
- return close(fi->fh);
+ return close(fi->fh);
}
-int sharefs_fsync(const char *pathname, int datasync, struct fuse_file_info *fi) {
- (void)pathname;
+int sharefs_fsync(const char *pathname, int datasync, struct fuse_file_info *fi)
+{
+ (void)pathname;
- if (datasync ? fdatasync(fi->fh) : fsync(fi->fh) == -1)
- return -errno;
- return 0;
+ if (datasync ? fdatasync(fi->fh) : fsync(fi->fh) == -1)
+ return -errno;
+ return 0;
}
diff --git a/cmd/sharefs/fuse-operations.h b/cmd/sharefs/fuse-operations.h
index 2150571a..fae181d1 100644
--- a/cmd/sharefs/fuse-operations.h
+++ b/cmd/sharefs/fuse-operations.h
@@ -6,29 +6,43 @@
#error This package requires libfuse >= v3.12
#endif
-#define SHAREFS_MEDIA_RW_ID (1 << 10) - 1 /* owning gid presented to userspace */
-#define SHAREFS_PERM_DIR 0770 /* permission bits for directories presented to userspace */
-#define SHAREFS_PERM_REG 0660 /* permission bits for regular files presented to userspace */
-#define SHAREFS_FORBIDDEN_FLAGS O_DIRECT /* these open flags are cleared unconditionally */
+/* owning gid presented to userspace */
+#define SHAREFS_MEDIA_RW_ID (1 << 10) - 1
+/* permission bits for directories presented to userspace */
+#define SHAREFS_PERM_DIR 0770
+/* permission bits for regular files presented to userspace */
+#define SHAREFS_PERM_REG 0660
+/* these open flags are cleared unconditionally */
+#define SHAREFS_FORBIDDEN_FLAGS O_DIRECT
/* sharefs_private is populated by sharefs_init and contains process-wide context */
struct sharefs_private {
- int dirfd; /* source dirfd opened during sharefs_init */
- uintptr_t setup; /* cgo handle of opaque setup state */
+ int dirfd; /* source dirfd opened during sharefs_init */
+ uintptr_t setup; /* cgo handle of opaque setup state */
};
-int sharefs_getattr(const char *pathname, struct stat *statbuf, struct fuse_file_info *fi);
-int sharefs_readdir(const char *pathname, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags);
+int sharefs_getattr(const char *pathname, struct stat *statbuf,
+ struct fuse_file_info *fi);
+int sharefs_readdir(const char *pathname, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi,
+ enum fuse_readdir_flags flags);
int sharefs_mkdir(const char *pathname, mode_t mode);
int sharefs_unlink(const char *pathname);
int sharefs_rmdir(const char *pathname);
-int sharefs_rename(const char *oldpath, const char *newpath, unsigned int flags);
-int sharefs_truncate(const char *pathname, off_t length, struct fuse_file_info *fi);
-int sharefs_utimens(const char *pathname, const struct timespec times[2], struct fuse_file_info *fi);
-int sharefs_create(const char *pathname, mode_t mode, struct fuse_file_info *fi);
+int sharefs_rename(const char *oldpath, const char *newpath,
+ unsigned int flags);
+int sharefs_truncate(const char *pathname, off_t length,
+ struct fuse_file_info *fi);
+int sharefs_utimens(const char *pathname, const struct timespec times[2],
+ struct fuse_file_info *fi);
+int sharefs_create(const char *pathname, mode_t mode,
+ struct fuse_file_info *fi);
int sharefs_open(const char *pathname, struct fuse_file_info *fi);
-int sharefs_read(const char *pathname, char *buf, size_t count, off_t offset, struct fuse_file_info *fi);
-int sharefs_write(const char *pathname, const char *buf, size_t count, off_t offset, struct fuse_file_info *fi);
+int sharefs_read(const char *pathname, char *buf, size_t count, off_t offset,
+ struct fuse_file_info *fi);
+int sharefs_write(const char *pathname, const char *buf, size_t count,
+ off_t offset, struct fuse_file_info *fi);
int sharefs_statfs(const char *pathname, struct statvfs *statbuf);
int sharefs_release(const char *pathname, struct fuse_file_info *fi);
-int sharefs_fsync(const char *pathname, int datasync, struct fuse_file_info *fi);
+int sharefs_fsync(const char *pathname, int datasync,
+ struct fuse_file_info *fi);
diff --git a/container/seccomp/libseccomp-helper.c b/container/seccomp/libseccomp-helper.c
index de8abc8d..7c640bac 100644
--- a/container/seccomp/libseccomp-helper.c
+++ b/container/seccomp/libseccomp-helper.c
@@ -9,130 +9,142 @@
#define LEN(arr) (sizeof(arr) / sizeof((arr)[0]))
-int32_t hakurei_scmp_make_filter(
- int *ret_p, uintptr_t allocate_p,
- uint32_t arch, uint32_t multiarch,
- struct hakurei_syscall_rule *rules,
- size_t rules_sz, hakurei_export_flag flags) {
- int i;
- int last_allowed_family;
- int disallowed;
- struct hakurei_syscall_rule *rule;
- void *buf;
- size_t len = 0;
+int32_t hakurei_scmp_make_filter(int *ret_p, uintptr_t allocate_p,
+ uint32_t arch, uint32_t multiarch,
+ struct hakurei_syscall_rule *rules,
+ size_t rules_sz, hakurei_export_flag flags)
+{
+ int i;
+ int last_allowed_family;
+ int disallowed;
+ struct hakurei_syscall_rule *rule;
+ void *buf;
+ size_t len = 0;
- int32_t res = 0; /* refer to resPrefix for message */
+ int32_t res = 0; /* refer to resPrefix for message */
- /* Blocklist all but unix, inet, inet6 and netlink */
- struct {
- int family;
- hakurei_export_flag flags_mask;
- } socket_family_allowlist[] = {
- /* NOTE: Keep in numerical order */
- {AF_UNSPEC, 0},
- {AF_LOCAL, 0},
- {AF_INET, 0},
- {AF_INET6, 0},
- {AF_NETLINK, 0},
- {AF_CAN, HAKUREI_EXPORT_CAN},
- {AF_BLUETOOTH, HAKUREI_EXPORT_BLUETOOTH},
- };
+ /* Blocklist all but unix, inet, inet6 and netlink */
+ struct {
+ int family;
+ hakurei_export_flag flags_mask;
+ } socket_family_allowlist[] = {
+ /* NOTE: Keep in numerical order */
+ { AF_UNSPEC, 0 },
+ { AF_LOCAL, 0 },
+ { AF_INET, 0 },
+ { AF_INET6, 0 },
+ { AF_NETLINK, 0 },
+ { AF_CAN, HAKUREI_EXPORT_CAN },
+ { AF_BLUETOOTH, HAKUREI_EXPORT_BLUETOOTH },
+ };
- scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_ALLOW);
- if (ctx == NULL) {
- res = 1;
- goto out;
- } else
- errno = 0;
+ scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_ALLOW);
+ if (ctx == NULL) {
+ res = 1;
+ goto out;
+ } else
+ errno = 0;
- /* We only really need to handle arches on multiarch systems.
+ /* We only really need to handle arches on multiarch systems.
* If only one arch is supported the default is fine */
- if (arch != 0) {
- /* This *adds* the target arch, instead of replacing the
+ if (arch != 0) {
+ /* This *adds* the target arch, instead of replacing the
* native one. This is not ideal, because we'd like to only
* allow the target arch, but we can't really disallow the
* native arch at this point, because then bubblewrap
* couldn't continue running. */
- *ret_p = seccomp_arch_add(ctx, arch);
- if (*ret_p < 0 && *ret_p != -EEXIST) {
- res = 2;
- goto out;
- }
+ *ret_p = seccomp_arch_add(ctx, arch);
+ if (*ret_p < 0 && *ret_p != -EEXIST) {
+ res = 2;
+ goto out;
+ }
- if (flags & HAKUREI_EXPORT_MULTIARCH && multiarch != 0) {
- *ret_p = seccomp_arch_add(ctx, multiarch);
- if (*ret_p < 0 && *ret_p != -EEXIST) {
- res = 3;
- goto out;
- }
- }
- }
+ if (flags & HAKUREI_EXPORT_MULTIARCH && multiarch != 0) {
+ *ret_p = seccomp_arch_add(ctx, multiarch);
+ if (*ret_p < 0 && *ret_p != -EEXIST) {
+ res = 3;
+ goto out;
+ }
+ }
+ }
- for (i = 0; i < rules_sz; i++) {
- rule = &rules[i];
- assert(rule->m_errno == EPERM || rule->m_errno == ENOSYS);
+ for (i = 0; i < rules_sz; i++) {
+ rule = &rules[i];
+ assert(rule->m_errno == EPERM || rule->m_errno == ENOSYS);
- if (rule->arg)
- *ret_p = seccomp_rule_add(ctx, SCMP_ACT_ERRNO(rule->m_errno), rule->syscall, 1, *rule->arg);
- else
- *ret_p = seccomp_rule_add(ctx, SCMP_ACT_ERRNO(rule->m_errno), rule->syscall, 0);
+ if (rule->arg)
+ *ret_p = seccomp_rule_add(ctx,
+ SCMP_ACT_ERRNO(rule->m_errno),
+ rule->syscall, 1, *rule->arg);
+ else
+ *ret_p = seccomp_rule_add(ctx,
+ SCMP_ACT_ERRNO(rule->m_errno),
+ rule->syscall, 0);
- if (*ret_p == -EFAULT) {
- res = 4;
- goto out;
- } else if (*ret_p < 0) {
- res = 5;
- goto out;
- }
- }
+ if (*ret_p == -EFAULT) {
+ res = 4;
+ goto out;
+ } else if (*ret_p < 0) {
+ res = 5;
+ goto out;
+ }
+ }
- /* Socket filtering doesn't work on e.g. i386, so ignore failures here
+ /* Socket filtering doesn't work on e.g. i386, so ignore failures here
* However, we need to user seccomp_rule_add_exact to avoid libseccomp doing
* something else: https://github.com/seccomp/libseccomp/issues/8 */
- last_allowed_family = -1;
- for (i = 0; i < LEN(socket_family_allowlist); i++) {
- if (socket_family_allowlist[i].flags_mask != 0 &&
- (socket_family_allowlist[i].flags_mask & flags) != socket_family_allowlist[i].flags_mask)
- continue;
+ last_allowed_family = -1;
+ for (i = 0; i < LEN(socket_family_allowlist); i++) {
+ if (socket_family_allowlist[i].flags_mask != 0 &&
+ (socket_family_allowlist[i].flags_mask & flags) !=
+ socket_family_allowlist[i].flags_mask)
+ continue;
- for (disallowed = last_allowed_family + 1; disallowed < socket_family_allowlist[i].family; disallowed++) {
- /* Blocklist the in-between valid families */
- seccomp_rule_add_exact(ctx, SCMP_ACT_ERRNO(EAFNOSUPPORT), SCMP_SYS(socket), 1, SCMP_A0(SCMP_CMP_EQ, disallowed));
- }
- last_allowed_family = socket_family_allowlist[i].family;
- }
- /* Blocklist the rest */
- seccomp_rule_add_exact(ctx, SCMP_ACT_ERRNO(EAFNOSUPPORT), SCMP_SYS(socket), 1, SCMP_A0(SCMP_CMP_GE, last_allowed_family + 1));
+ for (disallowed = last_allowed_family + 1;
+ disallowed < socket_family_allowlist[i].family;
+ disallowed++) {
+ /* Blocklist the in-between valid families */
+ seccomp_rule_add_exact(
+ ctx, SCMP_ACT_ERRNO(EAFNOSUPPORT),
+ SCMP_SYS(socket), 1,
+ SCMP_A0(SCMP_CMP_EQ, disallowed));
+ }
+ last_allowed_family = socket_family_allowlist[i].family;
+ }
+ /* Blocklist the rest */
+ seccomp_rule_add_exact(ctx, SCMP_ACT_ERRNO(EAFNOSUPPORT),
+ SCMP_SYS(socket), 1,
+ SCMP_A0(SCMP_CMP_GE, last_allowed_family + 1));
- if (allocate_p == 0) {
- *ret_p = seccomp_load(ctx);
- if (*ret_p != 0) {
- res = 7;
- goto out;
- }
- } else {
- *ret_p = seccomp_export_bpf_mem(ctx, NULL, &len);
- if (*ret_p != 0) {
- res = 6;
- goto out;
- }
+ if (allocate_p == 0) {
+ *ret_p = seccomp_load(ctx);
+ if (*ret_p != 0) {
+ res = 7;
+ goto out;
+ }
+ } else {
+ *ret_p = seccomp_export_bpf_mem(ctx, NULL, &len);
+ if (*ret_p != 0) {
+ res = 6;
+ goto out;
+ }
- buf = hakurei_scmp_allocate(allocate_p, len);
- if (buf == NULL) {
- res = 4;
- goto out;
- }
+ buf = hakurei_scmp_allocate(allocate_p, len);
+ if (buf == NULL) {
+ res = 4;
+ goto out;
+ }
- *ret_p = seccomp_export_bpf_mem(ctx, buf, &len);
- if (*ret_p != 0) {
- res = 6;
- goto out;
- }
- }
+ *ret_p = seccomp_export_bpf_mem(ctx, buf, &len);
+ if (*ret_p != 0) {
+ res = 6;
+ goto out;
+ }
+ }
out:
- if (ctx)
- seccomp_release(ctx);
+ if (ctx)
+ seccomp_release(ctx);
- return res;
+ return res;
}
diff --git a/container/seccomp/libseccomp-helper.h b/container/seccomp/libseccomp-helper.h
index 655110e4..29d5d5de 100644
--- a/container/seccomp/libseccomp-helper.h
+++ b/container/seccomp/libseccomp-helper.h
@@ -2,25 +2,24 @@
#include <stdint.h>
#if (SCMP_VER_MAJOR < 2) || (SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR < 5) || \
- (SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR == 5 && SCMP_VER_MICRO < 1)
+ (SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR == 5 && SCMP_VER_MICRO < 1)
#error This package requires libseccomp >= v2.5.1
#endif
typedef enum {
- HAKUREI_EXPORT_MULTIARCH = 1 << 0,
- HAKUREI_EXPORT_CAN = 1 << 1,
- HAKUREI_EXPORT_BLUETOOTH = 1 << 2,
+ HAKUREI_EXPORT_MULTIARCH = 1 << 0,
+ HAKUREI_EXPORT_CAN = 1 << 1,
+ HAKUREI_EXPORT_BLUETOOTH = 1 << 2,
} hakurei_export_flag;
struct hakurei_syscall_rule {
- int syscall;
- int m_errno;
- struct scmp_arg_cmp *arg;
+ int syscall;
+ int m_errno;
+ struct scmp_arg_cmp *arg;
};
extern void *hakurei_scmp_allocate(uintptr_t f, size_t len);
-int32_t hakurei_scmp_make_filter(
- int *ret_p, uintptr_t allocate_p,
- uint32_t arch, uint32_t multiarch,
- struct hakurei_syscall_rule *rules,
- size_t rules_sz, hakurei_export_flag flags);
+int32_t hakurei_scmp_make_filter(int *ret_p, uintptr_t allocate_p,
+ uint32_t arch, uint32_t multiarch,
+ struct hakurei_syscall_rule *rules,
+ size_t rules_sz, hakurei_export_flag flags);
diff --git a/internal/acl/libacl-helper.c b/internal/acl/libacl-helper.c
index 5fa35c18..c56e6436 100644
--- a/internal/acl/libacl-helper.c
+++ b/internal/acl/libacl-helper.c
@@ -7,129 +7,127 @@
#include <fcntl.h>
#include <sys/acl.h>
-enum hakurei_acl_status hakurei_update_acl(
- int fd,
- uid_t uid,
- acl_perm_t perms) {
- enum hakurei_acl_status ret;
+enum hakurei_acl_status hakurei_update_acl(int fd, uid_t uid, acl_perm_t perms)
+{
+ enum hakurei_acl_status ret;
- bool v;
- int i;
- acl_t acl, acl_d = NULL;
- acl_entry_t entry;
- acl_tag_t tag_type;
- void *qualifier_p;
- acl_permset_t permset;
- acl_perm_t has_perms;
+ bool v;
+ int i;
+ acl_t acl, acl_d = NULL;
+ acl_entry_t entry;
+ acl_tag_t tag_type;
+ void *qualifier_p;
+ acl_permset_t permset;
+ acl_perm_t has_perms;
- ret = HAKUREI_ACL_GET_FILE;
- acl = acl_get_file_at(fd, "", AT_EMPTY_PATH, ACL_TYPE_ACCESS);
- if (acl == NULL)
- goto out;
+ ret = HAKUREI_ACL_GET_FILE;
+ acl = acl_get_file_at(fd, "", AT_EMPTY_PATH, ACL_TYPE_ACCESS);
+ if (acl == NULL)
+ goto out;
- /* prune entries by uid */
- for (i = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); i == 1;
- i = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry)) {
- ret = HAKUREI_ACL_GET_TAG_TYPE;
- if (acl_get_tag_type(entry, &tag_type) != 0)
- goto out;
- if (tag_type != ACL_USER)
- continue;
+ /* prune entries by uid */
+ for (i = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); i == 1;
+ i = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry)) {
+ ret = HAKUREI_ACL_GET_TAG_TYPE;
+ if (acl_get_tag_type(entry, &tag_type) != 0)
+ goto out;
+ if (tag_type != ACL_USER)
+ continue;
- ret = HAKUREI_ACL_GET_QUALIFIER;
- qualifier_p = acl_get_qualifier(entry);
- if (qualifier_p == NULL)
- goto out;
- v = *(uid_t *)qualifier_p == uid;
- acl_free(qualifier_p);
+ ret = HAKUREI_ACL_GET_QUALIFIER;
+ qualifier_p = acl_get_qualifier(entry);
+ if (qualifier_p == NULL)
+ goto out;
+ v = *(uid_t *)qualifier_p == uid;
+ acl_free(qualifier_p);
- if (!v)
- continue;
+ if (!v)
+ continue;
- ret = HAKUREI_ACL_GET_PERMSET;
- if (acl_get_permset(entry, &permset) != 0)
- goto out;
+ ret = HAKUREI_ACL_GET_PERMSET;
+ if (acl_get_permset(entry, &permset) != 0)
+ goto out;
- if (perms == 0)
- goto delete;
+ if (perms == 0)
+ goto delete;
- /* this is quite ugly, but the standard makes it impossible to directly
- * obtain these bits */
- has_perms = 0;
-#define COPY_PERM_BIT(perm) \
- do { \
- ret = HAKUREI_ACL_GET_PERM; \
- i = acl_get_perm(permset, perm); \
- if (i < 0) \
- goto out; \
- if (i > 0) \
- has_perms |= perm; \
- } while (0)
- COPY_PERM_BIT(ACL_READ);
- COPY_PERM_BIT(ACL_WRITE);
- COPY_PERM_BIT(ACL_EXECUTE);
+ /* this is quite ugly, but the standard makes it impossible to
+ * directly obtain these bits */
+ has_perms = 0;
+#define COPY_PERM_BIT(perm) \
+ do { \
+ ret = HAKUREI_ACL_GET_PERM; \
+ i = acl_get_perm(permset, perm); \
+ if (i < 0) \
+ goto out; \
+ if (i > 0) \
+ has_perms |= perm; \
+ } while (0)
+ COPY_PERM_BIT(ACL_READ);
+ COPY_PERM_BIT(ACL_WRITE);
+ COPY_PERM_BIT(ACL_EXECUTE);
- if (perms == has_perms) {
- ret = HAKUREI_ACL_DUP;
- acl_d = acl_dup(acl);
- if (acl_d == NULL)
- goto out;
+ if (perms == has_perms) {
+ ret = HAKUREI_ACL_DUP;
+ acl_d = acl_dup(acl);
+ if (acl_d == NULL)
+ goto out;
- ret = HAKUREI_ACL_CALC_MASK;
- if (acl_calc_mask(&acl_d) != 0)
- goto out;
+ ret = HAKUREI_ACL_CALC_MASK;
+ if (acl_calc_mask(&acl_d) != 0)
+ goto out;
- ret = HAKUREI_ACL_OK;
- if (acl_cmp(acl, acl_d) == 0)
- goto out;
- }
+ ret = HAKUREI_ACL_OK;
+ if (acl_cmp(acl, acl_d) == 0)
+ goto out;
+ }
- delete:
- ret = HAKUREI_ACL_DELETE_ENTRY;
- if (acl_delete_entry(acl, entry) != 0)
- goto out;
- }
+delete:
+ ret = HAKUREI_ACL_DELETE_ENTRY;
+ if (acl_delete_entry(acl, entry) != 0)
+ goto out;
+ }
- if (perms == 0)
- goto set;
+ if (perms == 0)
+ goto set;
- ret = HAKUREI_ACL_CREATE_ENTRY;
- if (acl_create_entry(&acl, &entry) != 0)
- goto out;
+ ret = HAKUREI_ACL_CREATE_ENTRY;
+ if (acl_create_entry(&acl, &entry) != 0)
+ goto out;
- ret = HAKUREI_ACL_GET_PERMSET;
- if (acl_get_permset(entry, &permset) != 0)
- goto out;
+ ret = HAKUREI_ACL_GET_PERMSET;
+ if (acl_get_permset(entry, &permset) != 0)
+ goto out;
- ret = HAKUREI_ACL_ADD_PERM;
- if (acl_add_perm(permset, perms) != 0)
- goto out;
+ ret = HAKUREI_ACL_ADD_PERM;
+ if (acl_add_perm(permset, perms) != 0)
+ goto out;
- ret = HAKUREI_ACL_SET_TAG_TYPE;
- if (acl_set_tag_type(entry, ACL_USER) != 0)
- goto out;
+ ret = HAKUREI_ACL_SET_TAG_TYPE;
+ if (acl_set_tag_type(entry, ACL_USER) != 0)
+ goto out;
- ret = HAKUREI_ACL_SET_QUALIFIER;
- if (acl_set_qualifier(entry, (void *)&uid) != 0)
- goto out;
+ ret = HAKUREI_ACL_SET_QUALIFIER;
+ if (acl_set_qualifier(entry, (void *)&uid) != 0)
+ goto out;
set:
- ret = HAKUREI_ACL_CALC_MASK;
- if (acl_calc_mask(&acl) != 0)
- goto out;
+ ret = HAKUREI_ACL_CALC_MASK;
+ if (acl_calc_mask(&acl) != 0)
+ goto out;
- ret = HAKUREI_ACL_VALID;
- if (acl_valid(acl) != 0)
- goto out;
+ ret = HAKUREI_ACL_VALID;
+ if (acl_valid(acl) != 0)
+ goto out;
- ret = HAKUREI_ACL_SET_FILE;
- if (acl_set_file_at(fd, "", AT_EMPTY_PATH, ACL_TYPE_ACCESS, acl) == 0)
- ret = HAKUREI_ACL_OK;
+ ret = HAKUREI_ACL_SET_FILE;
+ if (acl_set_file_at(fd, "", AT_EMPTY_PATH, ACL_TYPE_ACCESS, acl) == 0)
+ ret = HAKUREI_ACL_OK;
out:
- if (acl != NULL)
- acl_free((void *)acl);
- if (acl_d != NULL)
- acl_free((void *)acl_d);
- return ret;
+ if (acl != NULL)
+ acl_free((void *)acl);
+ if (acl_d != NULL)
+ acl_free((void *)acl_d);
+ return ret;
}
diff --git a/internal/acl/libacl-helper.h b/internal/acl/libacl-helper.h
index 10711dd3..111fac4a 100644
--- a/internal/acl/libacl-helper.h
+++ b/internal/acl/libacl-helper.h
@@ -1,24 +1,21 @@
#include <sys/acl.h>
enum hakurei_acl_status {
- HAKUREI_ACL_OK,
- HAKUREI_ACL_GET_FILE,
- HAKUREI_ACL_GET_TAG_TYPE,
- HAKUREI_ACL_GET_QUALIFIER,
- HAKUREI_ACL_DELETE_ENTRY,
- HAKUREI_ACL_CREATE_ENTRY,
- HAKUREI_ACL_GET_PERMSET,
- HAKUREI_ACL_ADD_PERM,
- HAKUREI_ACL_SET_TAG_TYPE,
- HAKUREI_ACL_SET_QUALIFIER,
- HAKUREI_ACL_CALC_MASK,
- HAKUREI_ACL_VALID,
- HAKUREI_ACL_SET_FILE,
- HAKUREI_ACL_GET_PERM,
- HAKUREI_ACL_DUP,
+ HAKUREI_ACL_OK,
+ HAKUREI_ACL_GET_FILE,
+ HAKUREI_ACL_GET_TAG_TYPE,
+ HAKUREI_ACL_GET_QUALIFIER,
+ HAKUREI_ACL_DELETE_ENTRY,
+ HAKUREI_ACL_CREATE_ENTRY,
+ HAKUREI_ACL_GET_PERMSET,
+ HAKUREI_ACL_ADD_PERM,
+ HAKUREI_ACL_SET_TAG_TYPE,
+ HAKUREI_ACL_SET_QUALIFIER,
+ HAKUREI_ACL_CALC_MASK,
+ HAKUREI_ACL_VALID,
+ HAKUREI_ACL_SET_FILE,
+ HAKUREI_ACL_GET_PERM,
+ HAKUREI_ACL_DUP,
};
-enum hakurei_acl_status hakurei_update_acl(
- int fd,
- uid_t uid,
- acl_perm_t perms);
+enum hakurei_acl_status hakurei_update_acl(int fd, uid_t uid, acl_perm_t perms);
diff --git a/internal/outcome/shim-signal.c b/internal/outcome/shim-signal.c
index f02c0df1..6543d4b8 100644
--- a/internal/outcome/shim-signal.c
+++ b/internal/outcome/shim-signal.c
@@ -9,54 +9,57 @@ static pid_t hakurei_shim_param_ppid = -1;
static int hakurei_shim_fd = -1;
/* see shim.go for handling of the message */
-static inline ssize_t hakurei_shim_write(hakurei_shim_msg msg) {
- int savedErrno = errno;
- unsigned char buf = (unsigned char)msg;
- ssize_t ret = write(hakurei_shim_fd, &buf, 1);
- if (ret == -1 && errno != EAGAIN)
- exit(EXIT_FAILURE);
- errno = savedErrno;
- return ret;
+static inline ssize_t hakurei_shim_write(hakurei_shim_msg msg)
+{
+ int savedErrno = errno;
+ unsigned char buf = (unsigned char)msg;
+ ssize_t ret = write(hakurei_shim_fd, &buf, 1);
+ if (ret == -1 && errno != EAGAIN)
+ exit(EXIT_FAILURE);
+ errno = savedErrno;
+ return ret;
}
-static void hakurei_shim_sigaction(int sig, siginfo_t *si, void *ucontext) {
- if (sig != SIGCONT || si == NULL) {
- hakurei_shim_write(HAKUREI_SHIM_INVALID);
- return;
- }
+static void hakurei_shim_sigaction(int sig, siginfo_t *si, void *ucontext)
+{
+ if (sig != SIGCONT || si == NULL) {
+ hakurei_shim_write(HAKUREI_SHIM_INVALID);
+ return;
+ }
- if (si->si_pid == hakurei_shim_param_ppid) {
- hakurei_shim_write(HAKUREI_SHIM_EXIT_REQUESTED);
- return;
- }
+ if (si->si_pid == hakurei_shim_param_ppid) {
+ hakurei_shim_write(HAKUREI_SHIM_EXIT_REQUESTED);
+ return;
+ }
- hakurei_shim_write(HAKUREI_SHIM_BAD_PID);
+ hakurei_shim_write(HAKUREI_SHIM_BAD_PID);
- if (getppid() != hakurei_shim_param_ppid)
- hakurei_shim_write(HAKUREI_SHIM_ORPHAN);
+ if (getppid() != hakurei_shim_param_ppid)
+ hakurei_shim_write(HAKUREI_SHIM_ORPHAN);
}
-void hakurei_shim_setup_cont_signal(pid_t ppid, int fd) {
- if (hakurei_shim_param_ppid != -1 || hakurei_shim_fd != -1)
- *(volatile int *)NULL = 0; /* unreachable */
+void hakurei_shim_setup_cont_signal(pid_t ppid, int fd)
+{
+ if (hakurei_shim_param_ppid != -1 || hakurei_shim_fd != -1)
+ *(volatile int *)NULL = 0; /* unreachable */
- struct sigaction new_action = {0}, old_action = {0};
- if (sigaction(SIGCONT, NULL, &old_action) != 0)
- return;
- if (old_action.sa_handler != SIG_DFL) {
- errno = ENOTRECOVERABLE;
- return;
- }
+ struct sigaction new_action = { 0 }, old_action = { 0 };
+ if (sigaction(SIGCONT, NULL, &old_action) != 0)
+ return;
+ if (old_action.sa_handler != SIG_DFL) {
+ errno = ENOTRECOVERABLE;
+ return;
+ }
- new_action.sa_sigaction = hakurei_shim_sigaction;
- if (sigemptyset(&new_action.sa_mask) != 0)
- return;
- new_action.sa_flags = SA_ONSTACK | SA_SIGINFO;
+ new_action.sa_sigaction = hakurei_shim_sigaction;
+ if (sigemptyset(&new_action.sa_mask) != 0)
+ return;
+ new_action.sa_flags = SA_ONSTACK | SA_SIGINFO;
- if (sigaction(SIGCONT, &new_action, NULL) != 0)
- return;
+ if (sigaction(SIGCONT, &new_action, NULL) != 0)
+ return;
- errno = 0;
- hakurei_shim_param_ppid = ppid;
- hakurei_shim_fd = fd;
+ errno = 0;
+ hakurei_shim_param_ppid = ppid;
+ hakurei_shim_fd = fd;
}
diff --git a/internal/outcome/shim-signal.h b/internal/outcome/shim-signal.h
index f396a915..db43b561 100644
--- a/internal/outcome/shim-signal.h
+++ b/internal/outcome/shim-signal.h
@@ -2,10 +2,10 @@
/* see shim.go for documentation */
typedef enum {
- HAKUREI_SHIM_EXIT_REQUESTED,
- HAKUREI_SHIM_ORPHAN,
- HAKUREI_SHIM_INVALID,
- HAKUREI_SHIM_BAD_PID,
+ HAKUREI_SHIM_EXIT_REQUESTED,
+ HAKUREI_SHIM_ORPHAN,
+ HAKUREI_SHIM_INVALID,
+ HAKUREI_SHIM_BAD_PID,
} hakurei_shim_msg;
void hakurei_shim_setup_cont_signal(pid_t ppid, int fd);
diff --git a/internal/wayland/wayland-client-helper.c b/internal/wayland/wayland-client-helper.c
index 25af847b..0af69403 100644
--- a/internal/wayland/wayland-client-helper.c
+++ b/internal/wayland/wayland-client-helper.c
@@ -8,110 +8,119 @@
#include "security-context-v1-protocol.h"
#include <wayland-client.h>
-static void registry_handle_global(
- void *data,
- struct wl_registry *registry,
- uint32_t name,
- const char *interface,
- uint32_t version) {
- struct wp_security_context_manager_v1 **out = data;
+static void registry_handle_global(void *data, struct wl_registry *registry,
+ uint32_t name, const char *interface,
+ uint32_t version)
+{
+ struct wp_security_context_manager_v1 **out = data;
- if (strcmp(interface, wp_security_context_manager_v1_interface.name) == 0)
- *out = wl_registry_bind(registry, name, &wp_security_context_manager_v1_interface, 1);
+ if (strcmp(interface, wp_security_context_manager_v1_interface.name) ==
+ 0)
+ *out = wl_registry_bind(
+ registry, name,
+ &wp_security_context_manager_v1_interface, 1);
}
-static void registry_handle_global_remove(
- void *data,
- struct wl_registry *registry,
- uint32_t name) {} /* no-op */
+static void registry_handle_global_remove(void *data,
+ struct wl_registry *registry,
+ uint32_t name)
+{
+} /* no-op */
static const struct wl_registry_listener registry_listener = {
- .global = registry_handle_global,
- .global_remove = registry_handle_global_remove,
+ .global = registry_handle_global,
+ .global_remove = registry_handle_global_remove,
};
-hakurei_wayland_res hakurei_security_context_bind(
- char *socket_path,
- int server_fd,
- const char *app_id,
- const char *instance_id,
- int close_fd) {
- hakurei_wayland_res res = HAKUREI_WAYLAND_SUCCESS; /* see wayland.go for handling */
+hakurei_wayland_res hakurei_security_context_bind(char *socket_path,
+ int server_fd,
+ const char *app_id,
+ const char *instance_id,
+ int close_fd)
+{
+ hakurei_wayland_res res =
+ HAKUREI_WAYLAND_SUCCESS; /* see wayland.go for handling */
- struct wl_display *display = NULL;
- struct wl_registry *registry;
- struct wp_security_context_manager_v1 *security_context_manager = NULL;
- int event_cnt;
- int listen_fd = -1;
- struct sockaddr_un sockaddr = {0};
- struct wp_security_context_v1 *security_context;
+ struct wl_display *display = NULL;
+ struct wl_registry *registry;
+ struct wp_security_context_manager_v1 *security_context_manager = NULL;
+ int event_cnt;
+ int listen_fd = -1;
+ struct sockaddr_un sockaddr = { 0 };
+ struct wp_security_context_v1 *security_context;
- display = wl_display_connect_to_fd(server_fd);
- if (display == NULL) {
- res = HAKUREI_WAYLAND_CONNECT;
- goto out;
- };
+ display = wl_display_connect_to_fd(server_fd);
+ if (display == NULL) {
+ res = HAKUREI_WAYLAND_CONNECT;
+ goto out;
+ };
- registry = wl_display_get_registry(display);
- if (wl_registry_add_listener(registry, &registry_listener, &security_context_manager) < 0) {
- res = HAKUREI_WAYLAND_LISTENER;
- goto out;
- }
- event_cnt = wl_display_roundtrip(display);
- wl_registry_destroy(registry);
- if (event_cnt < 0) {
- res = HAKUREI_WAYLAND_ROUNDTRIP;
- goto out;
- }
+ registry = wl_display_get_registry(display);
+ if (wl_registry_add_listener(registry, &registry_listener,
+ &security_context_manager) < 0) {
+ res = HAKUREI_WAYLAND_LISTENER;
+ goto out;
+ }
+ event_cnt = wl_display_roundtrip(display);
+ wl_registry_destroy(registry);
+ if (event_cnt < 0) {
+ res = HAKUREI_WAYLAND_ROUNDTRIP;
+ goto out;
+ }
- if (security_context_manager == NULL) {
- res = HAKUREI_WAYLAND_NOT_AVAIL;
- goto out;
- }
+ if (security_context_manager == NULL) {
+ res = HAKUREI_WAYLAND_NOT_AVAIL;
+ goto out;
+ }
- listen_fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (listen_fd < 0) {
- res = HAKUREI_WAYLAND_SOCKET;
- goto out;
- }
+ listen_fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (listen_fd < 0) {
+ res = HAKUREI_WAYLAND_SOCKET;
+ goto out;
+ }
- sockaddr.sun_family = AF_UNIX;
- snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s", socket_path);
- if (bind(listen_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) != 0) {
- res = HAKUREI_WAYLAND_BIND;
- goto out;
- }
+ sockaddr.sun_family = AF_UNIX;
+ snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s",
+ socket_path);
+ if (bind(listen_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) !=
+ 0) {
+ res = HAKUREI_WAYLAND_BIND;
+ goto out;
+ }
- if (listen(listen_fd, 0) != 0) {
- res = HAKUREI_WAYLAND_LISTEN;
- goto out;
- }
+ if (listen(listen_fd, 0) != 0) {
+ res = HAKUREI_WAYLAND_LISTEN;
+ goto out;
+ }
- security_context = wp_security_context_manager_v1_create_listener(security_context_manager, listen_fd, close_fd);
- if (security_context == NULL) { /* not reached */
- res = HAKUREI_WAYLAND_NOT_AVAIL;
- goto out;
- }
- wp_security_context_v1_set_sandbox_engine(security_context, "app.hakurei");
- wp_security_context_v1_set_app_id(security_context, app_id);
- wp_security_context_v1_set_instance_id(security_context, instance_id);
- wp_security_context_v1_commit(security_context);
- wp_security_context_v1_destroy(security_context);
- if (wl_display_roundtrip(display) < 0) {
- res = HAKUREI_WAYLAND_ROUNDTRIP;
- goto out;
- }
+ security_context = wp_security_context_manager_v1_create_listener(
+ security_context_manager, listen_fd, close_fd);
+ if (security_context == NULL) { /* not reached */
+ res = HAKUREI_WAYLAND_NOT_AVAIL;
+ goto out;
+ }
+ wp_security_context_v1_set_sandbox_engine(security_context,
+ "app.hakurei");
+ wp_security_context_v1_set_app_id(security_context, app_id);
+ wp_security_context_v1_set_instance_id(security_context, instance_id);
+ wp_security_context_v1_commit(security_context);
+ wp_security_context_v1_destroy(security_context);
+ if (wl_display_roundtrip(display) < 0) {
+ res = HAKUREI_WAYLAND_ROUNDTRIP;
+ goto out;
+ }
out:
- if (listen_fd >= 0)
- close(listen_fd);
- if (security_context_manager != NULL)
- wp_security_context_manager_v1_destroy(security_context_manager);
- if (display != NULL)
- wl_display_disconnect(display);
+ if (listen_fd >= 0)
+ close(listen_fd);
+ if (security_context_manager != NULL)
+ wp_security_context_manager_v1_destroy(
+ security_context_manager);
+ if (display != NULL)
+ wl_display_disconnect(display);
- free((void *)socket_path);
- free((void *)app_id);
- free((void *)instance_id);
- return res;
+ free((void *)socket_path);
+ free((void *)app_id);
+ free((void *)instance_id);
+ return res;
}
diff --git a/internal/wayland/wayland-client-helper.h b/internal/wayland/wayland-client-helper.h
index ce67f6f6..09348be4 100644
--- a/internal/wayland/wayland-client-helper.h
+++ b/internal/wayland/wayland-client-helper.h
@@ -2,41 +2,41 @@
#include <sys/un.h>
typedef enum {
- HAKUREI_WAYLAND_SUCCESS,
- /* wl_display_connect_to_fd failed, errno */
- HAKUREI_WAYLAND_CONNECT,
- /* wl_registry_add_listener failed, errno */
- HAKUREI_WAYLAND_LISTENER,
- /* wl_display_roundtrip failed, errno */
- HAKUREI_WAYLAND_ROUNDTRIP,
- /* compositor does not implement wp_security_context_v1 */
- HAKUREI_WAYLAND_NOT_AVAIL,
- /* socket failed, errno */
- HAKUREI_WAYLAND_SOCKET,
- /* bind failed, errno */
- HAKUREI_WAYLAND_BIND,
- /* listen failed, errno */
- HAKUREI_WAYLAND_LISTEN,
+ HAKUREI_WAYLAND_SUCCESS,
+ /* wl_display_connect_to_fd failed, errno */
+ HAKUREI_WAYLAND_CONNECT,
+ /* wl_registry_add_listener failed, errno */
+ HAKUREI_WAYLAND_LISTENER,
+ /* wl_display_roundtrip failed, errno */
+ HAKUREI_WAYLAND_ROUNDTRIP,
+ /* compositor does not implement wp_security_context_v1 */
+ HAKUREI_WAYLAND_NOT_AVAIL,
+ /* socket failed, errno */
+ HAKUREI_WAYLAND_SOCKET,
+ /* bind failed, errno */
+ HAKUREI_WAYLAND_BIND,
+ /* listen failed, errno */
+ HAKUREI_WAYLAND_LISTEN,
- /* ensure pathname failed, implemented in conn.go */
- HAKUREI_WAYLAND_CREAT,
- /* socket for host server failed, implemented in conn.go */
- HAKUREI_WAYLAND_HOST_SOCKET,
- /* connect for host server failed, implemented in conn.go */
- HAKUREI_WAYLAND_HOST_CONNECT,
- /* cleanup failed, implemented in conn.go */
- HAKUREI_WAYLAND_CLEANUP,
+ /* ensure pathname failed, implemented in conn.go */
+ HAKUREI_WAYLAND_CREAT,
+ /* socket for host server failed, implemented in conn.go */
+ HAKUREI_WAYLAND_HOST_SOCKET,
+ /* connect for host server failed, implemented in conn.go */
+ HAKUREI_WAYLAND_HOST_CONNECT,
+ /* cleanup failed, implemented in conn.go */
+ HAKUREI_WAYLAND_CLEANUP,
} hakurei_wayland_res;
-hakurei_wayland_res hakurei_security_context_bind(
- char *socket_path,
- int server_fd,
- const char *app_id,
- const char *instance_id,
- int close_fd);
+hakurei_wayland_res hakurei_security_context_bind(char *socket_path,
+ int server_fd,
+ const char *app_id,
+ const char *instance_id,
+ int close_fd);
/* returns whether the specified size fits in the sun_path field of sockaddr_un */
-static inline bool hakurei_is_valid_size_sun_path(size_t sz) {
- struct sockaddr_un sockaddr;
- return sz <= sizeof(sockaddr.sun_path);
+static inline bool hakurei_is_valid_size_sun_path(size_t sz)
+{
+ struct sockaddr_un sockaddr;
+ return sz <= sizeof(sockaddr.sun_path);
};