From: Glenn L McGrath Date: Tue, 2 Sep 2003 02:36:18 +0000 (-0000) Subject: move all "-/bin/sh" "/bin/sh" and "sh" to libbb/messages.c file as one X-Git-Tag: android-x86-2.2~7000 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=dc4e75ef7ca135c836d22e380847672cf5b3773b;p=android-x86%2Fexternal-busybox.git move all "-/bin/sh" "/bin/sh" and "sh" to libbb/messages.c file as one constant. Vodz last_patch_107 --- diff --git a/coreutils/chroot.c b/coreutils/chroot.c index 5562e58c8..eeed01302 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c @@ -43,7 +43,7 @@ int chroot_main(int argc, char **argv) if (argc == 2) { argv -= 2; if (!(*argv = getenv("SHELL"))) { - *argv = (char *) "/bin/sh"; + *argv = (char *) DEFAULT_SHELL; } argv[1] = (char *) "-i"; } diff --git a/include/libbb.h b/include/libbb.h index a6d9a510b..64903732d 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -332,6 +332,21 @@ extern const char * const bb_path_group_file; extern const char * const bb_path_securetty_file; extern const char * const bb_path_motd_file; +/* + * You can change LIBBB_DEFAULT_LOGIN_SHELL, but don`t use, + * use bb_default_login_shell and next defines, + * if you LIBBB_DEFAULT_LOGIN_SHELL change, + * don`t lose change increment constant! + */ +#define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh" + +extern const char * const bb_default_login_shell; +/* "/bin/sh" */ +#define DEFAULT_SHELL (bb_default_login_shell+1) +/* "sh" */ +#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) + + extern const char bb_path_mtab_file[]; extern int bb_default_error_retval; diff --git a/init/init.c b/init/init.c index e52517e91..2f44e13bf 100644 --- a/init/init.c +++ b/init/init.c @@ -104,8 +104,6 @@ struct serial_struct { #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) -#define SHELL "/bin/sh" /* Default shell */ -#define LOGIN_SHELL "-" SHELL /* Default login shell */ #define INITTAB "/etc/inittab" /* inittab file location */ #ifndef INIT_SCRIPT #define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */ @@ -180,7 +178,7 @@ static const int RB_AUTOBOOT = 0x01234567; static const char * const environment[] = { "HOME=/", "PATH=" _PATH_STDPATH, - "SHELL=" SHELL, + "SHELL=/bin/sh", "USER=root", NULL }; @@ -526,7 +524,7 @@ static pid_t run(const struct init_action *a) /* See if any special /bin/sh requiring characters are present */ if (strpbrk(a->command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) { - cmd[0] = SHELL; + cmd[0] = (char *)DEFAULT_SHELL; cmd[1] = "-c"; cmd[2] = strcat(strcpy(buf, "exec "), a->command); cmd[3] = NULL; @@ -840,7 +838,7 @@ static void child_handler(int sig) #endif /* ! DEBUG_INIT */ -static void new_init_action(int action, char *command, const char *cons) +static void new_init_action(int action, const char *command, const char *cons) { struct init_action *new_action, *a; @@ -960,10 +958,10 @@ static void parse_inittab(void) /* Prepare to restart init when a HUP is received */ new_init_action(RESTART, "/sbin/init", ""); /* Askfirst shell on tty1-4 */ - new_init_action(ASKFIRST, LOGIN_SHELL, ""); - new_init_action(ASKFIRST, LOGIN_SHELL, VC_2); - new_init_action(ASKFIRST, LOGIN_SHELL, VC_3); - new_init_action(ASKFIRST, LOGIN_SHELL, VC_4); + new_init_action(ASKFIRST, bb_default_login_shell, ""); + new_init_action(ASKFIRST, bb_default_login_shell, VC_2); + new_init_action(ASKFIRST, bb_default_login_shell, VC_3); + new_init_action(ASKFIRST, bb_default_login_shell, VC_4); /* sysinit */ new_init_action(SYSINIT, INIT_SCRIPT, ""); @@ -1116,7 +1114,7 @@ extern int init_main(int argc, char **argv) if (argc > 1 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) { /* Start a shell on console */ - new_init_action(RESPAWN, LOGIN_SHELL, ""); + new_init_action(RESPAWN, bb_default_login_shell, ""); } else { /* Not in single user mode -- see what inittab says */ diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 0d7103ef0..0ccd85dbe 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in @@ -59,7 +59,7 @@ LIBBB_MOBJ0:=full_version.o \ can_not_create_raw_socket.o perm_denied_are_you_root.o \ shadow_file.o passwd_file.o group_file.o gshadow_file.o nologin_file.o \ securetty_file.o motd_file.o \ - msg_standard_input.o msg_standard_output.o + msg_standard_input.o msg_standard_output.o shell_file.o LIBBB_MSRC1:=$(LIBBB_DIR)xfuncs.c LIBBB_MOBJ1:=xmalloc.o xrealloc.o xcalloc.o xstrdup.o xstrndup.o \ diff --git a/libbb/messages.c b/libbb/messages.c index 11493db12..adfd1ffcc 100644 --- a/libbb/messages.c +++ b/libbb/messages.c @@ -90,3 +90,7 @@ const char * const bb_path_securetty_file = SECURETTY_FILE; const char * const bb_path_motd_file = MOTD_FILE; #endif +#ifdef L_shell_file +const char * const bb_default_login_shell = LIBBB_DEFAULT_LOGIN_SHELL; +#endif + diff --git a/loginutils/adduser.c b/loginutils/adduser.c index 41dc9f019..c4ab557d0 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c @@ -53,7 +53,6 @@ typedef struct { static const char default_passwd[] = "x"; static const char default_gecos[] = "Linux User,,,"; static const char default_home_prefix[] = "/home"; -static const char default_shell[] = "/bin/sh"; #ifdef CONFIG_FEATURE_SHADOWPASSWDS /* shadow in use? */ @@ -257,7 +256,7 @@ int adduser_main(int argc, char **argv) const char *login; const char *gecos = default_gecos; const char *home = NULL; - const char *shell = default_shell; + const char *shell = DEFAULT_SHELL; const char *usegroup = NULL; int flags; int setpass = 1; diff --git a/loginutils/login.c b/loginutils/login.c index c2bada258..3fca899c0 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -65,7 +65,7 @@ extern int login_main(int argc, char **argv) char full_tty[200]; char fromhost[512]; char username[USERNAME_SIZE]; - char *tmp; + const char *tmp; int amroot; int flag; int failed; @@ -267,15 +267,17 @@ auth_ok: chmod ( full_tty, 0600 ); change_identity ( pw ); - setup_environment ( pw-> pw_shell, 1, !opt_preserve, pw ); + tmp = pw-> pw_shell; + if(!tmp || !*tmp) + tmp = DEFAULT_SHELL; + setup_environment ( tmp, 1, !opt_preserve, pw ); motd ( ); signal ( SIGALRM, SIG_DFL ); /* default alarm signal */ if ( pw-> pw_uid == 0 ) syslog ( LOG_INFO, "root login %s\n", fromhost ); - - run_shell ( pw-> pw_shell, 1, 0, 0 + run_shell ( tmp, 1, 0, 0 #ifdef CONFIG_SELINUX , sid #endif diff --git a/loginutils/su.c b/loginutils/su.c index 04c213e4e..2d7a7ac05 100644 --- a/loginutils/su.c +++ b/loginutils/su.c @@ -21,7 +21,6 @@ /* The shell to run if none is given in the user's passwd entry. */ -#define DEFAULT_SHELL "/bin/sh" #define DEFAULT_USER "root" //#define SYSLOG_SUCCESS diff --git a/miscutils/crond.c b/miscutils/crond.c index f0920136f..637e09dd8 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -54,9 +54,6 @@ #define MAXLINES 256 /* max lines in non-root crontabs */ #endif -static const char def_sh[] = "/bin/sh"; - - typedef struct CronFile { struct CronFile *cf_Next; struct CronLine *cf_LineBase; @@ -313,7 +310,7 @@ ChangeUser(const char *user) } setenv("USER", pas->pw_name, 1); setenv("HOME", pas->pw_dir, 1); - setenv("SHELL", def_sh, 1); + setenv("SHELL", DEFAULT_SHELL, 1); /* * Change running state to the user in question @@ -997,7 +994,7 @@ RunJob(const char *user, CronLine *line) user, mailFile); } - ForkJob(user, line, mailFd, def_sh, "-c", line->cl_Shell, mailFile); + ForkJob(user, line, mailFd, DEFAULT_SHELL, "-c", line->cl_Shell, mailFile); } /* @@ -1081,12 +1078,12 @@ RunJob(const char *user, CronLine *line) #ifdef FEATURE_DEBUG_OPT if (DebugOpt) - crondlog("\005Child Running %s\n", def_sh); + crondlog("\005Child Running %s\n", DEFAULT_SHELL); #endif - execl(def_sh, def_sh, "-c", line->cl_Shell, NULL); + execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", line->cl_Shell, NULL); crondlog("\024unable to exec, user %s cmd %s -c %s\n", user, - def_sh, line->cl_Shell); + DEFAULT_SHELL, line->cl_Shell); exit(0); } else if (pid < 0) { /* diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 6b9446464..6c4da95fe 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -320,7 +320,7 @@ EditFile(const char *user, const char *file) ptr = PATH_VI; snprintf(visual, sizeof(visual), "%s %s", ptr, file); - execl("/bin/sh", "/bin/sh", "-c", visual, NULL); + execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", visual, NULL); perror("exec"); exit(0); } @@ -360,7 +360,7 @@ ChangeUser(const char *user, short dochdir) } setenv("USER", pas->pw_name, 1); setenv("HOME", pas->pw_dir, 1); - setenv("SHELL", "/bin/sh", 1); + setenv("SHELL", DEFAULT_SHELL, 1); /* * Change running state to the user in question diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 78f2bb0f1..1a23bac37 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -1009,7 +1009,7 @@ static int doit(char *str) case -1: /* failure */ return 0; case 0: /* child */ - execle("/bin/sh", "/bin/sh", "-c", str, NULL, environ); + execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, NULL, environ); exit(127); } waitpid(child, &status, 0); diff --git a/networking/telnetd.c b/networking/telnetd.c index 27b08aced..205661ba2 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c @@ -1,4 +1,4 @@ -/* $Id: telnetd.c,v 1.6 2003/04/25 12:32:37 andersen Exp $ +/* $Id: telnetd.c,v 1.7 2003/09/02 02:36:16 bug1 Exp $ * * Simple telnet server * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) @@ -52,7 +52,7 @@ static const char *loginpath = #ifdef CONFIG_LOGIN "/bin/login"; #else -"/bin/sh"; +DEFAULT_SHELL; #endif static const char *issuefile = "/etc/issue.net"; diff --git a/shell/ash.c b/shell/ash.c index 521d65ab6..59aa336cd 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -3729,7 +3729,7 @@ repeat: for (ap = argv; *ap; ap++) ; ap = new = ckmalloc((ap - argv + 2) * sizeof(char *)); - *ap++ = cmd = "/bin/sh"; + *ap++ = cmd = (char *)DEFAULT_SHELL; while ((*ap++ = *argv++)) ; argv = new; diff --git a/shell/msh.c b/shell/msh.c index a142c451a..31dd04f3e 100644 --- a/shell/msh.c +++ b/shell/msh.c @@ -668,7 +668,6 @@ static char *null = ""; static int heedint =1; static struct env e ={line, iostack, iostack-1, (xint *)NULL, FDBASE, (struct env *)NULL}; static void (*qflag)(int) = SIG_IGN; -static char shellname[] = "/bin/sh"; static int startl; static int peeksym; static int nlseen; @@ -717,7 +716,7 @@ extern int msh_main(int argc, char **argv) shell = lookup("SHELL"); if (shell->value == null) - setval(shell, shellname); + setval(shell, DEFAULT_SHELL); export(shell); homedir = lookup("HOME"); @@ -2871,7 +2870,7 @@ char *c, **v, **envp; *v = e.linep; tp = *--v; *v = e.linep; - execve(shellname, v, envp); + execve(DEFAULT_SHELL, v, envp); *v = tp; return("no Shell"); @@ -3902,7 +3901,7 @@ int quoted; dup2(pf[1], 1); closepipe(pf); - argument_list[0] = shellname; + argument_list[0] = (char *)DEFAULT_SHELL; argument_list[1] = "-c"; argument_list[2] = child_cmd; argument_list[3] = 0;