mirror of
https://github.com/containers/fuse-overlayfs.git
synced 2025-09-08 06:42:27 -04:00
code: add clang-format
add a clang-format definition file and apply it to the code. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
ff6b14d0a8
commit
ba472b58bc
117
.clang-format
Normal file
117
.clang-format
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: GNU
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveMacros: false
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: All
|
||||||
|
AlwaysBreakAfterReturnType: AllDefinitions
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: true
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: true
|
||||||
|
AfterEnum: true
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: true
|
||||||
|
AfterObjCDeclaration: true
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: true
|
||||||
|
BeforeCatch: true
|
||||||
|
BeforeElse: true
|
||||||
|
IndentBraces: true
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: All
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 0
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
DeriveLineEnding: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: false
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: AfterHash
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PointerAlignment: Right
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: false
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
SpaceAfterLogicalNot: true
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeParens: Always
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
TabWidth: 8
|
||||||
|
UseCRLF: false
|
||||||
|
UseTab: Never
|
||||||
|
...
|
@ -36,3 +36,6 @@ srpm: dist-gzip fuse-overlayfs.spec
|
|||||||
echo $(VERSION)
|
echo $(VERSION)
|
||||||
$(MAKE) -C $(WD) dist-xz
|
$(MAKE) -C $(WD) dist-xz
|
||||||
rpmbuild -bs --define "_sourcedir $(WD)" --define "_specdir $(WD)" --define "_builddir $(WD)" --define "_srcrpmdir $(WD)" --define "_rpmdir $(WD)" --define "_buildrootdir $(WD)/.build" fuse-overlayfs.spec
|
rpmbuild -bs --define "_sourcedir $(WD)" --define "_specdir $(WD)" --define "_builddir $(WD)" --define "_srcrpmdir $(WD)" --define "_rpmdir $(WD)" --define "_buildrootdir $(WD)/.build" fuse-overlayfs.spec
|
||||||
|
|
||||||
|
clang-format:
|
||||||
|
git ls-files | grep -E "\\.[hc]$$" | grep -v "^lib/" | xargs clang-format -style=file -i
|
||||||
|
44
direct.c
44
direct.c
@ -76,7 +76,7 @@ direct_fstat (struct ovl_layer *l, int fd, const char *path, unsigned int mask,
|
|||||||
#ifdef HAVE_STATX
|
#ifdef HAVE_STATX
|
||||||
struct statx stx;
|
struct statx stx;
|
||||||
|
|
||||||
ret = statx (fd, "", AT_STATX_DONT_SYNC|AT_EMPTY_PATH, mask, &stx);
|
ret = statx (fd, "", AT_STATX_DONT_SYNC | AT_EMPTY_PATH, mask, &stx);
|
||||||
if (ret < 0 && (errno == ENOSYS || errno == EINVAL))
|
if (ret < 0 && (errno == ENOSYS || errno == EINVAL))
|
||||||
goto fallback;
|
goto fallback;
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
@ -88,7 +88,7 @@ direct_fstat (struct ovl_layer *l, int fd, const char *path, unsigned int mask,
|
|||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fallback:
|
fallback:
|
||||||
ret = fstat (fd, st);
|
ret = fstat (fd, st);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
@ -103,7 +103,7 @@ direct_statat (struct ovl_layer *l, const char *path, struct stat *st, int flags
|
|||||||
#ifdef HAVE_STATX
|
#ifdef HAVE_STATX
|
||||||
struct statx stx;
|
struct statx stx;
|
||||||
|
|
||||||
ret = statx (l->fd, path, AT_STATX_DONT_SYNC|flags, mask, &stx);
|
ret = statx (l->fd, path, AT_STATX_DONT_SYNC | flags, mask, &stx);
|
||||||
if (ret < 0 && (errno == ENOSYS || errno == EINVAL))
|
if (ret < 0 && (errno == ENOSYS || errno == EINVAL))
|
||||||
goto fallback;
|
goto fallback;
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
@ -114,7 +114,7 @@ direct_statat (struct ovl_layer *l, const char *path, struct stat *st, int flags
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
fallback:
|
fallback:
|
||||||
ret = fstatat (l->fd, path, st, flags);
|
ret = fstatat (l->fd, path, st, flags);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
@ -212,24 +212,22 @@ direct_support_acls (struct ovl_layer *l)
|
|||||||
char value[32];
|
char value[32];
|
||||||
|
|
||||||
return fgetxattr (l->fd, ACL_XATTR, value, sizeof (value)) >= 0
|
return fgetxattr (l->fd, ACL_XATTR, value, sizeof (value)) >= 0
|
||||||
|| errno != ENOTSUP;
|
|| errno != ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct data_source direct_access_ds = {
|
||||||
struct data_source direct_access_ds =
|
.num_of_layers = direct_num_of_layers,
|
||||||
{
|
.load_data_source = direct_load_data_source,
|
||||||
.num_of_layers = direct_num_of_layers,
|
.cleanup = direct_cleanup,
|
||||||
.load_data_source = direct_load_data_source,
|
.file_exists = direct_file_exists,
|
||||||
.cleanup = direct_cleanup,
|
.statat = direct_statat,
|
||||||
.file_exists = direct_file_exists,
|
.fstat = direct_fstat,
|
||||||
.statat = direct_statat,
|
.opendir = direct_opendir,
|
||||||
.fstat = direct_fstat,
|
.readdir = direct_readdir,
|
||||||
.opendir = direct_opendir,
|
.closedir = direct_closedir,
|
||||||
.readdir = direct_readdir,
|
.openat = direct_openat,
|
||||||
.closedir = direct_closedir,
|
.getxattr = direct_getxattr,
|
||||||
.openat = direct_openat,
|
.listxattr = direct_listxattr,
|
||||||
.getxattr = direct_getxattr,
|
.readlinkat = direct_readlinkat,
|
||||||
.listxattr = direct_listxattr,
|
.support_acls = direct_support_acls,
|
||||||
.readlinkat = direct_readlinkat,
|
};
|
||||||
.support_acls = direct_support_acls,
|
|
||||||
};
|
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef FUSE_OVERLAYFS_H
|
#ifndef FUSE_OVERLAYFS_H
|
||||||
# define FUSE_OVERLAYFS_H
|
#define FUSE_OVERLAYFS_H
|
||||||
# define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
# include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
# include <plugin-manager.h>
|
#include <plugin-manager.h>
|
||||||
# include <stdbool.h>
|
#include <stdbool.h>
|
||||||
# include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
# define ACL_XATTR "system.posix_acl_default"
|
#define ACL_XATTR "system.posix_acl_default"
|
||||||
|
|
||||||
typedef struct hash_table Hash_table;
|
typedef struct hash_table Hash_table;
|
||||||
|
|
||||||
@ -143,39 +143,39 @@ struct ovl_layer
|
|||||||
struct data_source
|
struct data_source
|
||||||
{
|
{
|
||||||
int (*num_of_layers) (const char *opaque, const char *path);
|
int (*num_of_layers) (const char *opaque, const char *path);
|
||||||
int (*load_data_source)(struct ovl_layer *l, const char *opaque, const char *path, int n_layer);
|
int (*load_data_source) (struct ovl_layer *l, const char *opaque, const char *path, int n_layer);
|
||||||
int (*cleanup)(struct ovl_layer *l);
|
int (*cleanup) (struct ovl_layer *l);
|
||||||
int (*file_exists)(struct ovl_layer *l, const char *pathname);
|
int (*file_exists) (struct ovl_layer *l, const char *pathname);
|
||||||
int (*statat)(struct ovl_layer *l, const char *path, struct stat *st, int flags, unsigned int mask);
|
int (*statat) (struct ovl_layer *l, const char *path, struct stat *st, int flags, unsigned int mask);
|
||||||
int (*fstat)(struct ovl_layer *l, int fd, const char *path, unsigned int mask, struct stat *st);
|
int (*fstat) (struct ovl_layer *l, int fd, const char *path, unsigned int mask, struct stat *st);
|
||||||
void *(*opendir)(struct ovl_layer *l, const char *path);
|
void *(*opendir) (struct ovl_layer *l, const char *path);
|
||||||
struct dirent *(*readdir)(void *dirp);
|
struct dirent *(*readdir) (void *dirp);
|
||||||
int (*closedir)(void *dirp);
|
int (*closedir) (void *dirp);
|
||||||
int (*openat)(struct ovl_layer *l, const char *path, int flags, mode_t mode);
|
int (*openat) (struct ovl_layer *l, const char *path, int flags, mode_t mode);
|
||||||
int (*listxattr)(struct ovl_layer *l, const char *path, char *buf, size_t size);
|
int (*listxattr) (struct ovl_layer *l, const char *path, char *buf, size_t size);
|
||||||
int (*getxattr)(struct ovl_layer *l, const char *path, const char *name, char *buf, size_t size);
|
int (*getxattr) (struct ovl_layer *l, const char *path, const char *name, char *buf, size_t size);
|
||||||
ssize_t (*readlinkat)(struct ovl_layer *l, const char *path, char *buf, size_t bufsiz);
|
ssize_t (*readlinkat) (struct ovl_layer *l, const char *path, char *buf, size_t bufsiz);
|
||||||
bool (*support_acls)(struct ovl_layer *l);
|
bool (*support_acls) (struct ovl_layer *l);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* passthrough to the file system. */
|
/* passthrough to the file system. */
|
||||||
extern struct data_source direct_access_ds;
|
extern struct data_source direct_access_ds;
|
||||||
|
|
||||||
# ifndef HAVE_STATX
|
#ifndef HAVE_STATX
|
||||||
# define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
|
# define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
|
||||||
# define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
|
# define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
|
||||||
# define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
|
# define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
|
||||||
# define STATX_UID 0x00000008U /* Want/got stx_uid */
|
# define STATX_UID 0x00000008U /* Want/got stx_uid */
|
||||||
# define STATX_GID 0x00000010U /* Want/got stx_gid */
|
# define STATX_GID 0x00000010U /* Want/got stx_gid */
|
||||||
# define STATX_ATIME 0x00000020U /* Want/got stx_atime */
|
# define STATX_ATIME 0x00000020U /* Want/got stx_atime */
|
||||||
# define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
|
# define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
|
||||||
# define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
|
# define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
|
||||||
# define STATX_INO 0x00000100U /* Want/got stx_ino */
|
# define STATX_INO 0x00000100U /* Want/got stx_ino */
|
||||||
# define STATX_SIZE 0x00000200U /* Want/got stx_size */
|
# define STATX_SIZE 0x00000200U /* Want/got stx_size */
|
||||||
# define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
|
# define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
|
||||||
# define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
|
# define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
|
||||||
# define STATX_BTIME 0x00000800U /* Want/got stx_btime */
|
# define STATX_BTIME 0x00000800U /* Want/got stx_btime */
|
||||||
# define STATX_ALL 0x00000fffU /* All currently supported flags */
|
# define STATX_ALL 0x00000fffU /* All currently supported flags */
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,24 +17,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FUSE_OVERLAYFS_ERROR_H
|
#ifndef FUSE_OVERLAYFS_ERROR_H
|
||||||
# define FUSE_OVERLAYFS_ERROR_H
|
#define FUSE_OVERLAYFS_ERROR_H
|
||||||
|
|
||||||
# include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
# ifdef HAVE_ERROR_H
|
#ifdef HAVE_ERROR_H
|
||||||
# include <error.h>
|
# include <error.h>
|
||||||
# else
|
#else
|
||||||
# define error(status, errno, fmt, ...) do { \
|
# define error(status, errno, fmt, ...) \
|
||||||
if (errno == 0) \
|
do \
|
||||||
fprintf (stderr, "fuse-overlayfs: " fmt "\n", ##__VA_ARGS__); \
|
|
||||||
else \
|
|
||||||
{ \
|
{ \
|
||||||
fprintf (stderr, "fuse-overlayfs: " fmt, ##__VA_ARGS__); \
|
if (errno == 0) \
|
||||||
fprintf (stderr, ": %s\n", strerror (errno)); \
|
fprintf (stderr, "fuse-overlayfs: " fmt "\n", ##__VA_ARGS__); \
|
||||||
} \
|
else \
|
||||||
if (status) \
|
{ \
|
||||||
exit (status); \
|
fprintf (stderr, "fuse-overlayfs: " fmt, ##__VA_ARGS__); \
|
||||||
} while(0)
|
fprintf (stderr, ": %s\n", strerror (errno)); \
|
||||||
# endif
|
} \
|
||||||
|
if (status) \
|
||||||
|
exit (status); \
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,9 +52,9 @@ plugin_load_one (struct ovl_plugin_context *context, const char *path)
|
|||||||
plugin_name name;
|
plugin_name name;
|
||||||
struct ovl_plugin *p;
|
struct ovl_plugin *p;
|
||||||
plugin_version version;
|
plugin_version version;
|
||||||
void *handle = dlopen (path, RTLD_NOW|RTLD_LOCAL);
|
void *handle = dlopen (path, RTLD_NOW | RTLD_LOCAL);
|
||||||
if (! handle)
|
if (! handle)
|
||||||
error (EXIT_FAILURE, 0, "cannot load plugin %s: %s", path, dlerror());
|
error (EXIT_FAILURE, 0, "cannot load plugin %s: %s", path, dlerror ());
|
||||||
|
|
||||||
p = calloc (1, sizeof (*p));
|
p = calloc (1, sizeof (*p));
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
|
@ -17,10 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PLUGIN_MANAGER_H
|
#ifndef PLUGIN_MANAGER_H
|
||||||
# define PLUGIN_MANAGER_H
|
#define PLUGIN_MANAGER_H
|
||||||
# include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
# include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
struct ovl_plugin_context
|
struct ovl_plugin_context
|
||||||
{
|
{
|
||||||
@ -37,8 +37,7 @@ struct ovl_plugin_context *load_plugins (const char *plugins);
|
|||||||
/* taken from glibc unistd.h and fixes musl */
|
/* taken from glibc unistd.h and fixes musl */
|
||||||
#ifndef TEMP_FAILURE_RETRY
|
#ifndef TEMP_FAILURE_RETRY
|
||||||
#define TEMP_FAILURE_RETRY(expression) \
|
#define TEMP_FAILURE_RETRY(expression) \
|
||||||
(__extension__ \
|
(__extension__ ({ long int __result; \
|
||||||
({ long int __result; \
|
|
||||||
do __result = (long int) (expression); \
|
do __result = (long int) (expression); \
|
||||||
while (__result == -1L && errno == EINTR); \
|
while (__result == -1L && errno == EINTR); \
|
||||||
__result; }))
|
__result; }))
|
||||||
|
16
plugin.h
16
plugin.h
@ -17,16 +17,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PLUGIN_H
|
#ifndef PLUGIN_H
|
||||||
# define PLUGIN_H
|
#define PLUGIN_H
|
||||||
# include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
# include <utils.h>
|
#include <utils.h>
|
||||||
# include <fuse-overlayfs.h>
|
#include <fuse-overlayfs.h>
|
||||||
|
|
||||||
typedef struct data_source *(*plugin_load_data_source)(const char *opaque, const char *path);
|
typedef struct data_source *(*plugin_load_data_source) (const char *opaque, const char *path);
|
||||||
typedef int (*plugin_release)();
|
typedef int (*plugin_release) ();
|
||||||
typedef const char *(*plugin_name)();
|
typedef const char *(*plugin_name) ();
|
||||||
typedef int (*plugin_version)();
|
typedef int (*plugin_version) ();
|
||||||
|
|
||||||
struct ovl_plugin
|
struct ovl_plugin
|
||||||
{
|
{
|
||||||
|
@ -14,13 +14,13 @@ main ()
|
|||||||
unlink ("suid");
|
unlink ("suid");
|
||||||
unlink ("nosuid");
|
unlink ("nosuid");
|
||||||
|
|
||||||
fd = open ("suid", O_WRONLY|O_CREAT|O_EXCL);
|
fd = open ("suid", O_WRONLY | O_CREAT | O_EXCL);
|
||||||
write (fd, "1", 1);
|
write (fd, "1", 1);
|
||||||
fchown (fd, 0, 0);
|
fchown (fd, 0, 0);
|
||||||
fchmod (fd, S_ISUID | 0755);
|
fchmod (fd, S_ISUID | 0755);
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
fd = open ("nosuid", O_WRONLY|O_CREAT|O_EXCL);
|
fd = open ("nosuid", O_WRONLY | O_CREAT | O_EXCL);
|
||||||
write (fd, "1", 1);
|
write (fd, "1", 1);
|
||||||
fchown (fd, 0, 0);
|
fchown (fd, 0, 0);
|
||||||
fchmod (fd, S_ISUID | 0755);
|
fchmod (fd, S_ISUID | 0755);
|
||||||
|
51
utils.c
51
utils.c
@ -32,48 +32,42 @@
|
|||||||
#include <sys/xattr.h>
|
#include <sys/xattr.h>
|
||||||
|
|
||||||
#ifndef TEMP_FAILURE_RETRY
|
#ifndef TEMP_FAILURE_RETRY
|
||||||
#define TEMP_FAILURE_RETRY(expression) \
|
# define TEMP_FAILURE_RETRY(expression) \
|
||||||
(__extension__ \
|
(__extension__ ({ long int __result; \
|
||||||
({ long int __result; \
|
|
||||||
do __result = (long int) (expression); \
|
do __result = (long int) (expression); \
|
||||||
while (__result == -1L && errno == EINTR); \
|
while (__result == -1L && errno == EINTR); \
|
||||||
__result; }))
|
__result; }))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef RESOLVE_IN_ROOT
|
#ifndef RESOLVE_IN_ROOT
|
||||||
# define RESOLVE_IN_ROOT 0x10
|
# define RESOLVE_IN_ROOT 0x10
|
||||||
#endif
|
#endif
|
||||||
#ifndef __NR_openat2
|
#ifndef __NR_openat2
|
||||||
# define __NR_openat2 437
|
# define __NR_openat2 437
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* uClibc and uClibc-ng don't provide O_TMPFILE */
|
/* uClibc and uClibc-ng don't provide O_TMPFILE */
|
||||||
#ifndef O_TMPFILE
|
#ifndef O_TMPFILE
|
||||||
# define O_TMPFILE (020000000 | O_DIRECTORY)
|
# define O_TMPFILE (020000000 | O_DIRECTORY)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* List of all valid flags for the open/openat flags argument: */
|
/* List of all valid flags for the open/openat flags argument: */
|
||||||
#define VALID_OPEN_FLAGS \
|
#define VALID_OPEN_FLAGS \
|
||||||
(O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC | \
|
(O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC | O_APPEND | O_NDELAY | O_NONBLOCK | O_NDELAY | O_SYNC | O_DSYNC | FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | O_NOATIME | O_CLOEXEC | O_PATH | O_TMPFILE)
|
||||||
O_APPEND | O_NDELAY | O_NONBLOCK | O_NDELAY | O_SYNC | O_DSYNC | \
|
|
||||||
FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \
|
|
||||||
O_NOATIME | O_CLOEXEC | O_PATH | O_TMPFILE)
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
syscall_openat2 (int dirfd, const char *path, uint64_t flags, uint64_t mode, uint64_t resolve)
|
syscall_openat2 (int dirfd, const char *path, uint64_t flags, uint64_t mode, uint64_t resolve)
|
||||||
{
|
{
|
||||||
struct openat2_open_how
|
struct openat2_open_how
|
||||||
{
|
{
|
||||||
uint64_t flags;
|
uint64_t flags;
|
||||||
uint64_t mode;
|
uint64_t mode;
|
||||||
uint64_t resolve;
|
uint64_t resolve;
|
||||||
}
|
} how = {
|
||||||
how =
|
.flags = flags & VALID_OPEN_FLAGS,
|
||||||
{
|
.mode = (flags & O_CREAT) ? (mode & 07777) : 0,
|
||||||
.flags = flags & VALID_OPEN_FLAGS,
|
.resolve = resolve,
|
||||||
.mode = (flags & O_CREAT) ? (mode & 07777) : 0,
|
};
|
||||||
.resolve = resolve,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (int) syscall (__NR_openat2, dirfd, path, &how, sizeof (how), 0);
|
return (int) syscall (__NR_openat2, dirfd, path, &how, sizeof (how), 0);
|
||||||
}
|
}
|
||||||
@ -97,18 +91,19 @@ safe_openat (int dirfd, const char *pathname, int flags, mode_t mode)
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
fallback:
|
fallback:
|
||||||
return openat (dirfd, pathname, flags, mode);
|
return openat (dirfd, pathname, flags, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
file_exists_at (int dirfd, const char *pathname)
|
file_exists_at (int dirfd, const char *pathname)
|
||||||
{
|
{
|
||||||
int ret = faccessat (dirfd, pathname, F_OK, AT_SYMLINK_NOFOLLOW|AT_EACCESS);
|
int ret = faccessat (dirfd, pathname, F_OK, AT_SYMLINK_NOFOLLOW | AT_EACCESS);
|
||||||
if (ret < 0 && errno == EINVAL) {
|
if (ret < 0 && errno == EINVAL)
|
||||||
struct stat buf;
|
{
|
||||||
return fstatat (dirfd, pathname, &buf, AT_SYMLINK_NOFOLLOW);
|
struct stat buf;
|
||||||
}
|
return fstatat (dirfd, pathname, &buf, AT_SYMLINK_NOFOLLOW);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +214,7 @@ open_fd_or_get_path (struct ovl_layer *l, const char *path, char *out, int *fd,
|
|||||||
{
|
{
|
||||||
out[0] = '\0';
|
out[0] = '\0';
|
||||||
|
|
||||||
*fd = l->ds->openat (l, path, O_NONBLOCK|O_NOFOLLOW|flags, 0);
|
*fd = l->ds->openat (l, path, O_NONBLOCK | O_NOFOLLOW | flags, 0);
|
||||||
if (*fd < 0 && (errno == ELOOP || errno == EISDIR || errno == ENXIO))
|
if (*fd < 0 && (errno == ELOOP || errno == EISDIR || errno == ENXIO))
|
||||||
{
|
{
|
||||||
strconcat3 (out, PATH_MAX, l->path, "/", path);
|
strconcat3 (out, PATH_MAX, l->path, "/", path);
|
||||||
|
44
utils.h
44
utils.h
@ -16,25 +16,25 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
# define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
# define _GNU_SOURCE
|
# define _GNU_SOURCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include <config.h>
|
#include <config.h>
|
||||||
# include <dirent.h>
|
#include <dirent.h>
|
||||||
# include <fcntl.h>
|
#include <fcntl.h>
|
||||||
# include <limits.h>
|
#include <limits.h>
|
||||||
# include <stdio.h>
|
#include <stdio.h>
|
||||||
# include <stdlib.h>
|
#include <stdlib.h>
|
||||||
# include <sys/types.h>
|
#include <sys/types.h>
|
||||||
# include <unistd.h>
|
#include <unistd.h>
|
||||||
# include "fuse-overlayfs.h"
|
#include "fuse-overlayfs.h"
|
||||||
|
|
||||||
# define XATTR_OVERRIDE_STAT "user.fuseoverlayfs.override_stat"
|
#define XATTR_OVERRIDE_STAT "user.fuseoverlayfs.override_stat"
|
||||||
# define XATTR_PRIVILEGED_OVERRIDE_STAT "security.fuseoverlayfs.override_stat"
|
#define XATTR_PRIVILEGED_OVERRIDE_STAT "security.fuseoverlayfs.override_stat"
|
||||||
# define XATTR_OVERRIDE_CONTAINERS_STAT "user.containers.override_stat"
|
#define XATTR_OVERRIDE_CONTAINERS_STAT "user.containers.override_stat"
|
||||||
|
|
||||||
void cleanup_freep (void *p);
|
void cleanup_freep (void *p);
|
||||||
void cleanup_filep (FILE **f);
|
void cleanup_filep (FILE **f);
|
||||||
@ -46,17 +46,17 @@ int file_exists_at (int dirfd, const char *pathname);
|
|||||||
int strconcat3 (char *dest, size_t size, const char *s1, const char *s2, const char *s3);
|
int strconcat3 (char *dest, size_t size, const char *s1, const char *s2, const char *s3);
|
||||||
int open_fd_or_get_path (struct ovl_layer *l, const char *path, char *out, int *fd, int flags);
|
int open_fd_or_get_path (struct ovl_layer *l, const char *path, char *out, int *fd, int flags);
|
||||||
|
|
||||||
# define cleanup_file __attribute__((cleanup (cleanup_filep)))
|
#define cleanup_file __attribute__ ((cleanup (cleanup_filep)))
|
||||||
# define cleanup_free __attribute__((cleanup (cleanup_freep)))
|
#define cleanup_free __attribute__ ((cleanup (cleanup_freep)))
|
||||||
# define cleanup_close __attribute__((cleanup (cleanup_closep)))
|
#define cleanup_close __attribute__ ((cleanup (cleanup_closep)))
|
||||||
# define cleanup_dir __attribute__((cleanup (cleanup_dirp)))
|
#define cleanup_dir __attribute__ ((cleanup (cleanup_dirp)))
|
||||||
|
|
||||||
# define LIKELY(x) __builtin_expect((x),1)
|
#define LIKELY(x) __builtin_expect ((x), 1)
|
||||||
# define UNLIKELY(x) __builtin_expect((x),0)
|
#define UNLIKELY(x) __builtin_expect ((x), 0)
|
||||||
|
|
||||||
# ifdef HAVE_STATX
|
#ifdef HAVE_STATX
|
||||||
void statx_to_stat (struct statx *stx, struct stat *st);
|
void statx_to_stat (struct statx *stx, struct stat *st);
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
int safe_openat (int dirfd, const char *pathname, int flags, mode_t mode);
|
int safe_openat (int dirfd, const char *pathname, int flags, mode_t mode);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user