- Add better explanations for and in the "Terminal breakage"
comments, and handle missing key #ifdefs inside the functions
that use those keys. (DLR)
+ - Add restricted mode, accessible via the -Z/--restricted
+ command line option or by invoking nano with any name
+ beginning with 'r' (e.g. "rnano"). In restricted mode, nano
+ will not read or write to any file not specified on the
+ command line, read any nanorc files, allow suspending, or
+ allow a file to be appended to, prepended to, or saved under a
+ different name if it already has one. (IO ERROR) DLR: Also
+ disable backup files and spell checking (since the latter can
+ leave a pre-spell-checked version of the file in a temporary
+ directory), use tail() to get the program name so that the
+ check for its beginning with 'r' will work when a path is
+ specified, disable toggles that are only useful with options
+ that are disabled in restricted mode, call nano_disabled_msg()
+ when trying to read or spell check a file instead of leaving
+ the shortcuts out of the main list, and instead of acting as
+ though TEMP_OPT is enabled when exiting with a modified file
+ (which caused problems if the filename was blank), only allow
+ a filename to be modified at the writeout prompt if it's blank
+ beforehand. Changes to do_writeout(), toggle_init(),
+ shortcut_init(), die_save_file(), and nanogetstr().
+ - Call nano_disabled_msg() directly from the shortcut list
+ instead of inside the disabled functions. (David Benbennick)
- files.c:
add_open_file()
- Rearrange the NANO_SMALL #ifdef so that the code to set the
MODIFIED flag in open_files->flags is included only once.
(DLR)
+ do_writeout()
+ - Refactor so that no recursion is needed if we try to exit with
+ a modified file that has no name when TEMP_OPT is set. (DLR)
- nano.c:
do_delete()
- Tweak for efficiency. (David Benbennick)
+ do_exit()
+ - Refactor so that no recursion is needed if we try to exit with
+ a modified file that has no name when TEMP_OPT is set. (DLR)
print_numlock_warning()
- Removed, as it's no longer needed and was never called
anywhere after the input overhaul. (DLR)
- Use napms() instead of nanosleep(), as it does the same thing
(aside from taking an argument in milliseconds instead of
microseconds) and curses includes it. (DLR)
+- nano.1:
+ - Document restricted mode. (IO ERROR) DLR: Add minor
+ modifications to account for the above changes.
- nano.texi:
- Fix inaccuracies: Meta-L now toggles line wrapping, and Meta-<
and Meta-> aren't toggles. (DLR)
+ - Document restricted mode. (IO ERROR) DLR: Add minor
+ modifications to account for the above changes.
- faq.html:
- Removed question about the NumLock glitch, as it's no longer
needed. (DLR)
toggle_init_one(TOGGLE_NOHELP_KEY, toggle_nohelp_msg, NO_HELP);
#ifdef ENABLE_MULTIBUFFER
- toggle_init_one(TOGGLE_MULTIBUFFER_KEY, toggle_multibuffer_msg, MULTIBUFFER);
+ if (!ISSET(RESTRICTED))
+ toggle_init_one(TOGGLE_MULTIBUFFER_KEY, toggle_multibuffer_msg, MULTIBUFFER);
#endif
toggle_init_one(TOGGLE_CONST_KEY, toggle_const_msg, CONSTUPDATE);
toggle_init_one(TOGGLE_AUTOINDENT_KEY, toggle_autoindent_msg, AUTOINDENT);
toggle_init_one(TOGGLE_WRAP_KEY, toggle_wrap_msg, NO_WRAP);
#endif
toggle_init_one(TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg, CUT_TO_END);
- toggle_init_one(TOGGLE_SUSPEND_KEY, toggle_suspend_msg, SUSPEND);
+ if (!ISSET(RESTRICTED))
+ toggle_init_one(TOGGLE_SUSPEND_KEY, toggle_suspend_msg, SUSPEND);
#ifndef DISABLE_MOUSE
toggle_init_one(TOGGLE_MOUSE_KEY, toggle_mouse_msg, USE_MOUSE);
#endif
- toggle_init_one(TOGGLE_NOCONVERT_KEY, toggle_noconvert_msg, NO_CONVERT);
- toggle_init_one(TOGGLE_DOS_KEY, toggle_dos_msg, DOS_FILE);
- toggle_init_one(TOGGLE_MAC_KEY, toggle_mac_msg, MAC_FILE);
- toggle_init_one(TOGGLE_BACKUP_KEY, toggle_backup_msg, BACKUP_FILE);
+ if (!ISSET(RESTRICTED)) {
+ toggle_init_one(TOGGLE_NOCONVERT_KEY, toggle_noconvert_msg, NO_CONVERT);
+ toggle_init_one(TOGGLE_DOS_KEY, toggle_dos_msg, DOS_FILE);
+ toggle_init_one(TOGGLE_MAC_KEY, toggle_mac_msg, MAC_FILE);
+ toggle_init_one(TOGGLE_BACKUP_KEY, toggle_backup_msg, BACKUP_FILE);
+ }
toggle_init_one(TOGGLE_SMOOTH_KEY, toggle_smooth_msg, SMOOTHSCROLL);
#ifdef ENABLE_COLOR
toggle_init_one(TOGGLE_SYNTAX_KEY, toggle_syntax_msg, COLOR_SYNTAX);
/* Translators: try to keep this string under 10 characters long */
sc_init_one(&main_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
#ifdef ENABLE_MULTIBUFFER
if (open_files != NULL && (open_files->prev != NULL || open_files->next != NULL))
/* Translators: try to keep this string under 10 characters long */
sc_init_one(&main_list, NANO_JUSTIFY_KEY, _("Justify"),
IFHELP(nano_justify_msg, NANO_NO_KEY),
- NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW, do_justify);
+ NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW,
+#ifndef NANO_SMALL
+ do_justify
+#else
+ nano_disabled_msg
+#endif
+ );
/* this is so we can view multiple files */
/* Translators: try to keep this string under 10 characters long */
#else
NOVIEW
#endif
- , do_insertfile_void);
+ , !ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg);
/* Translators: try to keep this string under 10 characters long */
sc_init_one(&main_list, NANO_WHEREIS_KEY, _("Where Is"),
/* Translators: try to keep this string under 10 characters long */
sc_init_one(&main_list, NANO_SPELL_KEY, _("To Spell"),
IFHELP(nano_spell_msg, NANO_NO_KEY), NANO_SPELL_FKEY,
- NANO_NO_KEY, NOVIEW, do_spell);
+ NANO_NO_KEY, NOVIEW,
+#ifndef DISABLE_SPELLER
+ !ISSET(RESTRICTED) ? do_spell :
+#endif
+ nano_disabled_msg);
sc_init_one(&main_list, NANO_GOTO_KEY, _("Go To Line"),
IFHELP(nano_goto_msg, NANO_ALT_GOTO_KEY), NANO_GOTO_FKEY,
sc_init_one(&main_list, NANO_MARK_KEY, _("Mark Text"),
IFHELP(nano_mark_msg, NANO_ALT_MARK_KEY),
- NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_mark);
+ NANO_NO_KEY, NANO_NO_KEY, NOVIEW,
+#ifndef NANO_SMALL
+ do_mark
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&main_list, NANO_DELETE_KEY, _("Delete"),
IFHELP(nano_delete_msg, NANO_NO_KEY), NANO_NO_KEY,
sc_init_one(&whereis_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
/* Translators: try to keep this string under 10 characters long */
sc_init_one(&whereis_list, NANO_CANCEL_KEY, _("Cancel"),
sc_init_one(&replace_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&replace_list, NANO_CANCEL_KEY, _("Cancel"),
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
sc_init_one(&replace_list_2, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&replace_list_2, NANO_CANCEL_KEY, _("Cancel"),
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
sc_init_one(&goto_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&goto_list, NANO_CANCEL_KEY, _("Cancel"),
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
sc_init_one(&writefile_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
#ifndef DISABLE_BROWSER
/* Translators: try to keep this string under 16 characters long */
- sc_init_one(&writefile_list, NANO_TOFILES_KEY, _("To Files"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&writefile_list, NANO_TOFILES_KEY, _("To Files"),
IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
#endif
#ifndef NANO_SMALL
/* Translators: try to keep this string under 16 characters long */
- sc_init_one(&writefile_list, NANO_NO_KEY, _("DOS Format"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&writefile_list, NANO_NO_KEY, _("DOS Format"),
IFHELP(nano_dos_msg, TOGGLE_DOS_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
/* Translators: try to keep this string under 16 characters long */
- sc_init_one(&writefile_list, NANO_NO_KEY, _("Mac Format"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&writefile_list, NANO_NO_KEY, _("Mac Format"),
IFHELP(nano_mac_msg, TOGGLE_MAC_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
#endif
/* Translators: try to keep this string under 16 characters long */
- sc_init_one(&writefile_list, NANO_NO_KEY, _("Append"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&writefile_list, NANO_NO_KEY, _("Append"),
IFHELP(nano_append_msg, NANO_APPEND_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
/* Translators: try to keep this string under 16 characters long */
- sc_init_one(&writefile_list, NANO_NO_KEY, _("Prepend"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&writefile_list, NANO_NO_KEY, _("Prepend"),
IFHELP(nano_prepend_msg, NANO_PREPEND_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
#ifndef NANO_SMALL
/* Translators: try to keep this string under 16 characters long */
- sc_init_one(&writefile_list, NANO_NO_KEY, _("Backup File"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&writefile_list, NANO_NO_KEY, _("Backup File"),
IFHELP(nano_backup_msg, TOGGLE_BACKUP_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
#endif
sc_init_one(&insertfile_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&insertfile_list, NANO_CANCEL_KEY, _("Cancel"),
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
NANO_NO_KEY, VIEW, 0);
#ifndef DISABLE_BROWSER
- sc_init_one(&insertfile_list, NANO_TOFILES_KEY, _("To Files"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&insertfile_list, NANO_TOFILES_KEY, _("To Files"),
IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
#endif
#ifndef NANO_SMALL
/* Translators: try to keep this string under 22 characters long */
- sc_init_one(&insertfile_list, NANO_EXTCMD_KEY, _("Execute Command"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&insertfile_list, NANO_EXTCMD_KEY, _("Execute Command"),
IFHELP(nano_execute_msg, NANO_NO_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
#ifdef ENABLE_MULTIBUFFER
/* Translators: try to keep this string under 22 characters long */
- sc_init_one(&insertfile_list, NANO_NO_KEY, _("New Buffer"),
+ if (!ISSET(RESTRICTED))
+ sc_init_one(&insertfile_list, NANO_NO_KEY, _("New Buffer"),
IFHELP(nano_multibuffer_msg, TOGGLE_MULTIBUFFER_KEY), NANO_NO_KEY,
NANO_NO_KEY, NOVIEW, 0);
#endif
sc_init_one(&spell_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&spell_list, NANO_CANCEL_KEY, _("Cancel"),
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
sc_init_one(&extcmd_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&extcmd_list, NANO_CANCEL_KEY, _("Cancel"),
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
sc_init_one(&browser_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&browser_list, NANO_CANCEL_KEY, _("Cancel"),
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
sc_init_one(&gotodir_list, NANO_HELP_KEY, _("Get Help"),
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
- NANO_NO_KEY, VIEW, do_help);
+ NANO_NO_KEY, VIEW,
+#ifndef DISABLE_HELP
+ do_help
+#else
+ nano_disabled_msg
+#endif
+ );
sc_init_one(&gotodir_list, NANO_CANCEL_KEY, _("Cancel"),
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
char *ret;
int i = -1;
+ /* No emergency files in restricted mode! */
+ if (ISSET(RESTRICTED))
+ return;
+
/* If we can't save, we have REAL bad problems, but we might as well
TRY. */
if (die_filename[0] == '\0')
#ifdef ENABLE_COLOR
print1opt(_("-Y [str]"), _("--syntax [str]"), _("Syntax definition to use"));
#endif
+ print1opt(_("-Z"), _("--restricted"), _("Restricted mode"));
print1opt("-c", "--const", _("Constantly show cursor position"));
#ifndef NANO_SMALL
print1opt("-d", "--rebinddelete", _("Fix Backspace/Delete confusion problem"));
return ISSET(NO_HELP) ? 2 : 0;
}
-#if defined(DISABLE_JUSTIFY) || defined(DISABLE_SPELLER) || defined(DISABLE_HELP) || defined(NANO_SMALL)
-void nano_disabled_msg(void)
+int nano_disabled_msg(void)
{
statusbar(_("Sorry, support for this function has been disabled"));
+ return 1;
}
-#endif
#ifndef NANO_SMALL
static int pid; /* This is the PID of the newly forked process
return 0;
}
-#endif /* !NANO_SMALL */
int do_mark(void)
{
-#ifdef NANO_SMALL
- nano_disabled_msg();
-#else
TOGGLE(MARK_ISSET);
if (ISSET(MARK_ISSET)) {
statusbar(_("Mark Set"));
statusbar(_("Mark UNset"));
edit_refresh();
}
-#endif
return 1;
}
+#endif /* !NANO_SMALL */
#ifndef DISABLE_WRAPPING
void wrap_reset(void)
return NULL;
}
-#endif
int do_spell(void)
{
-#ifdef DISABLE_SPELLER
- nano_disabled_msg();
- return 1;
-#else
int i;
char *temp, *spell_msg;
statusbar(_("Finished checking spelling"));
return 1;
-#endif
}
+#endif /* !DISABLE_SPELLER */
#if !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)
/* The "indentation" of a line is the white-space between the quote part
{
return do_para_search(2, NULL, NULL, NULL, TRUE);
}
-#endif
/* Justify a paragraph. */
int do_justify(void)
{
-#ifdef DISABLE_JUSTIFY
- nano_disabled_msg();
- return 1;
-#else
size_t quote_len;
/* Length of the initial quotation of the paragraph we
* justify. */
display_main_list();
return 0;
-#endif /* !DISABLE_JUSTIFY */
}
+#endif /* !DISABLE_JUSTIFY */
int do_exit(void)
{
{"mac", 0, 0, 'M'},
{"noconvert", 0, 0, 'N'},
{"smooth", 0, 0, 'S'},
+ {"restricted", 0, 0, 'Z'},
{"autoindent", 0, 0, 'i'},
{"cut", 0, 0, 'k'},
#endif
#endif
#ifdef HAVE_GETOPT_LONG
- while ((optchr = getopt_long(argc, argv, "h?BDE:FHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz",
+ while ((optchr = getopt_long(argc, argv, "h?BDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz",
long_options, NULL)) != -1) {
#else
while ((optchr =
- getopt(argc, argv, "h?BDE:FHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz")) != -1) {
+ getopt(argc, argv, "h?BDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz")) != -1) {
#endif
switch (optchr) {
syntaxstr = mallocstrcpy(syntaxstr, optarg);
break;
#endif
+ case 'Z':
+ SET(RESTRICTED);
+ break;
case 'c':
SET(CONSTUPDATE);
break;
}
}
+ /* If filename starts with 'r', we use restricted mode. */
+ if (*(tail(argv[0])) == 'r')
+ SET(RESTRICTED);
+
+ /* If we're using restricted mode, disable suspending, backup files,
+ * and reading rcfiles. */
+ if (ISSET(RESTRICTED)) {
+ UNSET(SUSPEND);
+ UNSET(BACKUP_FILE);
+ SET(NO_RCFILE);
+ }
+
/* We've read through the command line options. Now back up the flags
and values that are set, and read the rcfile(s). If the values
haven't changed afterward, restore the backed-up values. */