diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-09-08 20:55:59 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-09-08 20:55:59 +0200 |
commit | b278ac0e607aa971c46706be63c580a2fd88dd56 (patch) | |
tree | 3d726c79024f77ea9eaa62cf0f68a92f48847386 /miscutils | |
parent | d134aa93414c7d07a938b8076021c62d9987f683 (diff) | |
download | busybox-w32-b278ac0e607aa971c46706be63c580a2fd88dd56.tar.gz busybox-w32-b278ac0e607aa971c46706be63c580a2fd88dd56.tar.bz2 busybox-w32-b278ac0e607aa971c46706be63c580a2fd88dd56.zip |
setfattr: new applet
function old new delta
setfattr_main - 189 +189
packed_usage 31516 31588 +72
setxattr - 53 +53
lsetxattr - 53 +53
removexattr - 37 +37
lremovexattr - 37 +37
applet_names 2649 2658 +9
find_applet_by_name 124 128 +4
applet_main 1532 1536 +4
------------------------------------------------------------------------------
(add/remove: 7/0 grow/shrink: 4/0 up/down: 458/0) Total: 458 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/setfattr.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/miscutils/setfattr.c b/miscutils/setfattr.c new file mode 100644 index 000000000..f0ef227cb --- /dev/null +++ b/miscutils/setfattr.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * setfattr - set extended attributes of filesystem objects. | ||
3 | * | ||
4 | * Copyright (C) 2017 by Denys Vlasenko <vda.linux@googlemail.com> | ||
5 | * | ||
6 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
7 | */ | ||
8 | //config:config SETFATTR | ||
9 | //config: bool "setfattr" | ||
10 | //config: default y | ||
11 | //config: help | ||
12 | //config: Set/delete extended attributes on files | ||
13 | |||
14 | //applet:IF_SETFATTR(APPLET_NOEXEC(setfattr, setfattr, BB_DIR_USR_BIN, BB_SUID_DROP, setfattr)) | ||
15 | |||
16 | //kbuild:lib-$(CONFIG_SETFATTR) += setfattr.o | ||
17 | |||
18 | #include <sys/xattr.h> | ||
19 | #include "libbb.h" | ||
20 | |||
21 | //usage:#define setfattr_trivial_usage | ||
22 | //usage: "[-h] -n|-x ATTR [-v VALUE] FILE..." | ||
23 | //usage:#define setfattr_full_usage "\n\n" | ||
24 | //usage: "Set extended attributes" | ||
25 | //usage: "\n" | ||
26 | //usage: "\n -h Do not follow symlinks" | ||
27 | //usage: "\n -x ATTR Remove attribute ATTR" | ||
28 | //usage: "\n -n ATTR Set attribute ATTR to VALUE" | ||
29 | //usage: "\n -v VALUE (default: empty)" | ||
30 | int setfattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
31 | int setfattr_main(int argc UNUSED_PARAM, char **argv) | ||
32 | { | ||
33 | const char *name; | ||
34 | const char *value = ""; | ||
35 | int status; | ||
36 | int opt; | ||
37 | enum { | ||
38 | OPT_h = (1 << 0), | ||
39 | OPT_x = (1 << 1), | ||
40 | }; | ||
41 | |||
42 | opt = getopt32(argv, "^" | ||
43 | "hx:n:v:" | ||
44 | /* Min one arg, either -x or -n is a must, -x does not allow -v */ | ||
45 | "\0" "-1:x:n:n--x:x--nv:v--x" | ||
46 | , &name, &name, &value | ||
47 | ); | ||
48 | argv += optind; | ||
49 | |||
50 | status = EXIT_SUCCESS; | ||
51 | do { | ||
52 | int r; | ||
53 | if (opt & OPT_x) | ||
54 | r = ((opt & OPT_h) ? lremovexattr : removexattr)(*argv, name); | ||
55 | else { | ||
56 | r = ((opt & OPT_h) ? lsetxattr : setxattr)( | ||
57 | *argv, name, | ||
58 | value, strlen(value), /*flags:*/ 0 | ||
59 | ); | ||
60 | } | ||
61 | if (r) { | ||
62 | bb_simple_perror_msg(*argv); | ||
63 | status = EXIT_FAILURE; | ||
64 | } | ||
65 | } while (*++argv); | ||
66 | |||
67 | return status; | ||
68 | } | ||