Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 1, or (at your option) any later
+Software Foundation; either version 2, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
/* Flags hacking. */
#include "config.h"
extern int set_job_control ();
#endif
+#if defined (RESTRICTED_SHELL)
+extern char *shell_name;
+#endif
+
+/* -c, -s invocation options -- not really flags, but they show up in $- */
+extern int want_pending_command, read_from_stdin;
+
/* **************************************************************** */
/* */
/* The Standard Sh Flags. */
disallows: changing directories, command or path names containing `/',
unsetting or resetting the values of $PATH and $SHELL, and any type of
output redirection. */
-int restricted = 0;
+int restricted = 0; /* currently restricted */
+int restricted_shell = 0; /* shell was started in restricted mode. */
#endif /* RESTRICTED_SHELL */
/* Non-zero means that this shell is running in `privileged' mode. This
- mode is entered on startup if the real and effective uids or gids
- differ. */
+ is required if the shell is to run setuid. If the `-p' option is
+ not supplied at startup, and the real and effective uids or gids
+ differ, disable_priv_mode is called to relinquish setuid status. */
int privileged_mode = 0;
#if defined (BRACE_EXPANSION)
}
/* Change the state of a flag, and return it's original value, or return
- FLAG_ERROR if there is no flag called NAME. ON_OR_OFF should be one
- of FLAG_ON or FLAG_OFF. */
+ FLAG_ERROR if there is no flag FLAG. ON_OR_OFF must be either
+ FLAG_ON or FLAG_OFF. */
int
change_flag (flag, on_or_off)
int flag;
{
int *value, old_value;
- value = find_flag (flag);
-
#if defined (RESTRICTED_SHELL)
/* Don't allow "set +r" in a shell which is `restricted'. */
if (restricted && flag == 'r' && on_or_off == FLAG_OFF)
return (FLAG_ERROR);
#endif /* RESTRICTED_SHELL */
- if (value == (int *)FLAG_UNKNOWN)
+ value = find_flag (flag);
+
+ if ((value == (int *)FLAG_UNKNOWN) || (on_or_off != FLAG_ON && on_or_off != FLAG_OFF))
return (FLAG_ERROR);
old_value = *value;
- if (on_or_off == FLAG_ON)
- *value = 1;
- else if (on_or_off == FLAG_OFF)
- *value = 0;
- else
- return (FLAG_ERROR);
+ *value = (on_or_off == FLAG_ON) ? 1 : 0;
/* Special cases for a few flags. */
switch (flag)
{
#if defined (JOB_CONTROL)
case 'm':
- set_job_control (on_or_off == '-');
+ set_job_control (on_or_off == FLAG_ON);
break;
#endif /* JOB_CONTROL */
+#if defined (RESTRICTED_SHELL)
+ case 'r':
+ if (on_or_off == FLAG_ON)
+ maybe_make_restricted (shell_name);
+ break;
+#endif
+
+#if defined (BANG_HISTORY)
+ case 'H':
+ if (on_or_off == FLAG_ON)
+ bash_initialize_history ();
+ break;
+#endif
+
case 'p':
- if (on_or_off == '+')
+ if (on_or_off == FLAG_OFF)
disable_priv_mode ();
break;
char *temp;
int i, string_index;
- temp = xmalloc (1 + NUM_SHELL_FLAGS);
+ temp = xmalloc (1 + NUM_SHELL_FLAGS + read_from_stdin + want_pending_command);
for (i = string_index = 0; shell_flags[i].name; i++)
if (*(shell_flags[i].value))
temp[string_index++] = shell_flags[i].name;
+ if (want_pending_command)
+ temp[string_index++] = 'c';
+ if (read_from_stdin)
+ temp[string_index++] = 's';
+
temp[string_index] = '\0';
return (temp);
}
+
+void
+reset_shell_flags ()
+{
+ mark_modified_vars = exit_immediately_on_error = disallow_filename_globbing = 0;
+ place_keywords_in_env = read_but_dont_execute = just_one_command = 0;
+ noclobber = unbound_vars_is_error = echo_input_at_read = 0;
+ echo_command_at_execute = jobs_m_flag = forced_interactive = 0;
+ no_symbolic_links = no_invisible_vars = privileged_mode = 0;
+
+ hashing_enabled = interactive_comments = 1;
+
+#if defined (JOB_CONTROL)
+ asynchronous_notification = 0;
+#endif
+
+#if defined (BANG_HISTORY)
+ history_expansion = 1;
+#endif
+
+#if defined (BRACE_EXPANSION)
+ brace_expansion = 1;
+#endif
+
+#if defined (RESTRICTED_SHELL)
+ restricted = 0;
+#endif
+}