aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-05-26 16:45:28 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-05-26 16:45:28 +0200
commit13d72c3fd979a047179b1342dcae026379af0617 (patch)
tree4467f3b31f7dafd596f7044bd6652618dd1f5212
parentf5470419404d643070db99d058405b714695b817 (diff)
downloadbusybox-w32-13d72c3fd979a047179b1342dcae026379af0617.tar.gz
busybox-w32-13d72c3fd979a047179b1342dcae026379af0617.tar.bz2
busybox-w32-13d72c3fd979a047179b1342dcae026379af0617.zip
add/remove-shell: copy /etc/shells mode to new file
function old new delta add_remove_shell_main 259 300 +41 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--loginutils/add-remove-shell.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/loginutils/add-remove-shell.c b/loginutils/add-remove-shell.c
index af7c31779..922b3333d 100644
--- a/loginutils/add-remove-shell.c
+++ b/loginutils/add-remove-shell.c
@@ -43,10 +43,7 @@
43#define REMOVE_SHELL (ENABLE_REMOVE_SHELL && (!ENABLE_ADD_SHELL || applet_name[0] == 'r')) 43#define REMOVE_SHELL (ENABLE_REMOVE_SHELL && (!ENABLE_ADD_SHELL || applet_name[0] == 'r'))
44#define ADD_SHELL (ENABLE_ADD_SHELL && (!ENABLE_REMOVE_SHELL || applet_name[0] == 'a')) 44#define ADD_SHELL (ENABLE_ADD_SHELL && (!ENABLE_REMOVE_SHELL || applet_name[0] == 'a'))
45 45
46/* NB: we use the _address_, not the value, of this string 46#define dont_add ((char*)(uintptr_t)1)
47 * as a "special value of pointer" in the code.
48 */
49static const char dont_add[] ALIGN1 = "\n";
50 47
51int add_remove_shell_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 48int add_remove_shell_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
52int add_remove_shell_main(int argc UNUSED_PARAM, char **argv) 49int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
@@ -54,6 +51,9 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
54 FILE *orig_fp; 51 FILE *orig_fp;
55 char *orig_fn; 52 char *orig_fn;
56 char *new_fn; 53 char *new_fn;
54 struct stat sb;
55
56 sb.st_mode = 0666;
57 57
58 argv++; 58 argv++;
59 59
@@ -61,6 +61,8 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
61 if (!orig_fn) 61 if (!orig_fn)
62 return EXIT_FAILURE; 62 return EXIT_FAILURE;
63 orig_fp = fopen_for_read(orig_fn); 63 orig_fp = fopen_for_read(orig_fn);
64 if (orig_fp)
65 xfstat(fileno(orig_fp), &sb, orig_fn);
64 66
65 new_fn = xasprintf("%s.tmp", orig_fn); 67 new_fn = xasprintf("%s.tmp", orig_fn);
66 /* 68 /*
@@ -71,13 +73,9 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
71 * after which it should revert to O_TRUNC. 73 * after which it should revert to O_TRUNC.
72 * For now, I settle for O_TRUNC instead. 74 * For now, I settle for O_TRUNC instead.
73 */ 75 */
74 xmove_fd(xopen(new_fn, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO); 76 xmove_fd(xopen3(new_fn, O_WRONLY | O_CREAT | O_TRUNC, sb.st_mode), STDOUT_FILENO);
75 77 /* TODO?
76 /* TODO:
77 struct stat sb;
78 xfstat(fileno(orig_fp), &sb);
79 xfchown(STDOUT_FILENO, sb.st_uid, sb.st_gid); 78 xfchown(STDOUT_FILENO, sb.st_uid, sb.st_gid);
80 xfchmod(STDOUT_FILENO, sb.st_mode);
81 */ 79 */
82 80
83 if (orig_fp) { 81 if (orig_fp) {
@@ -95,7 +93,7 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
95 } 93 }
96 /* we are add-shell */ 94 /* we are add-shell */
97 /* mark this name as "do not add" */ 95 /* mark this name as "do not add" */
98 *cpp = (char*)dont_add; 96 *cpp = dont_add;
99 } 97 }
100 cpp++; 98 cpp++;
101 } 99 }