diff --git a/configure.ac b/configure.ac index c29048ad..5d91217c 100644 --- a/configure.ac +++ b/configure.ac @@ -198,8 +198,13 @@ fi AC_ARG_ENABLE(operatingdir, AS_HELP_STRING([--disable-operatingdir], [Disable the setting of an operating directory])) -if test "x$enable_operatingdir" = xno; then - AC_DEFINE(DISABLE_OPERATINGDIR, 1, [Define this to disable the setting of an operating directory (a chroot of sorts).]) +if test "x$enable_tiny" = xyes; then + if test "x$enable_operatingdir" != xyes; then + enable_operatingdir=no + fi +fi +if test "x$enable_operatingdir" != xno; then + AC_DEFINE(ENABLE_OPERATINGDIR, 1, [Define this to allow setting an operating directory (a chroot of sorts).]) fi AC_ARG_ENABLE(speller, @@ -278,9 +283,6 @@ if test "x$enable_tiny" = xyes; then if test "x$enable_libmagic" != xyes; then enable_libmagic=no fi - if test "x$enable_operatingdir" != xyes; then - AC_DEFINE(DISABLE_OPERATINGDIR, 1, [Define this to disable the setting of an operating directory (a chroot of sorts).]) - fi if test "x$enable_speller" != xyes; then AC_DEFINE(DISABLE_SPELLER, 1, [Define this to disable the spell-checker functions.]) fi diff --git a/src/browser.c b/src/browser.c index a854a244..e1ae9938 100644 --- a/src/browser.c +++ b/src/browser.c @@ -243,7 +243,7 @@ char *do_browser(char *path) sprintf(path, "%s%s", present_path, answer); } -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR if (outside_of_confinement(path, FALSE)) { /* TRANSLATORS: This refers to the confining effect of the * option --operatingdir, not of --restricted. */ @@ -273,7 +273,7 @@ char *do_browser(char *path) continue; } -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR /* Note: The selected file can be outside the operating * directory if it's ".." or if it's a symlink to a * directory outside the operating directory. */ @@ -372,7 +372,7 @@ char *do_browse_from(const char *inpath) } } -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR /* If the resulting path isn't in the operating directory, use * the operating directory instead. */ if (outside_of_confinement(path, FALSE)) diff --git a/src/files.c b/src/files.c index 684f3a74..9ca0cafd 100644 --- a/src/files.c +++ b/src/files.c @@ -422,7 +422,7 @@ bool open_buffer(const char *filename, bool undoable) /* Display newlines in filenames as ^J. */ as_an_at = FALSE; -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR if (outside_of_confinement(filename, FALSE)) { statusline(ALERT, _("Can't read file from outside of %s"), operating_dir); @@ -1069,7 +1069,7 @@ void do_insertfile(void) execute ? &execute_history : #endif NULL, edit_refresh, msg, -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR operating_dir != NULL ? operating_dir : #endif "./"); @@ -1401,7 +1401,7 @@ char *safe_tempfile(FILE **f) return full_tempdir; } -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR /* Change to the specified operating directory, when it's valid. */ void init_operating_dir(void) { @@ -1564,7 +1564,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, realname = real_dir_from_tilde(name); -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR /* If we're writing a temporary file, we're probably going outside * the operating directory, so skip the operating directory test. */ if (!tmp && outside_of_confinement(realname, FALSE)) { @@ -2418,7 +2418,7 @@ char **username_tab_completion(const char *buf, size_t *num_matches, /* Cool, found a match. Add it to the list. This makes a * lot more sense to me (Chris) this way... */ -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR /* ...unless the match exists outside the operating * directory, in which case just go to the next match. */ if (outside_of_confinement(userdata->pw_dir, TRUE)) @@ -2501,7 +2501,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files, size_t char *tmp = charalloc(strlen(dirname) + strlen(nextdir->d_name) + 1); sprintf(tmp, "%s%s", dirname, nextdir->d_name); -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR /* ...unless the match exists outside the operating * directory, in which case just go to the next match. */ skip_match = outside_of_confinement(tmp, TRUE); diff --git a/src/global.c b/src/global.c index eae5b2ba..a9345cb2 100644 --- a/src/global.c +++ b/src/global.c @@ -169,7 +169,7 @@ const char *locking_prefix = "."; const char *locking_suffix = ".swp"; /* Suffix of the vim-style lock file. */ #endif -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR char *operating_dir = NULL; /* The path to our confining "operating" directory, when given. */ #endif @@ -1785,7 +1785,7 @@ void thanks_for_all_the_fish(void) #ifndef NANO_TINY free(backup_dir); #endif -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR free(operating_dir); #endif free(answer); diff --git a/src/nano.c b/src/nano.c index a7d092e6..212a91be 100644 --- a/src/nano.c +++ b/src/nano.c @@ -875,7 +875,7 @@ void usage(void) print_opt("-m", "--mouse", N_("Enable the use of the mouse")); #endif print_opt("-n", "--noread", N_("Do not read the file (only write it)")); -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR print_opt(_("-o "), _("--operatingdir="), N_("Set operating directory")); #endif @@ -960,7 +960,7 @@ void version(void) #ifdef ENABLE_MULTIBUFFER printf(" --enable-multibuffer"); #endif -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR printf(" --enable-operatingdir"); #endif #ifndef DISABLE_SPELLER @@ -1009,7 +1009,7 @@ void version(void) #ifndef ENABLE_NANORC printf(" --disable-nanorc"); #endif -#ifdef DISABLE_OPERATINGDIR +#ifndef ENABLE_OPERATINGDIR printf(" --disable-operatingdir"); #endif #ifdef DISABLE_SPELLER @@ -1940,7 +1940,7 @@ int main(int argc, char **argv) {"mouse", 0, NULL, 'm'}, #endif {"noread", 0, NULL, 'n'}, -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR {"operatingdir", 1, NULL, 'o'}, #endif {"preserve", 0, NULL, 'p'}, @@ -2157,7 +2157,7 @@ int main(int argc, char **argv) case 'n': SET(NOREAD_MODE); break; -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR case 'o': operating_dir = mallocstrcpy(operating_dir, optarg); break; @@ -2252,7 +2252,7 @@ int main(int argc, char **argv) #ifdef ENABLE_NANORC if (!no_rcfiles) { /* Back up the command-line options, then read the rcfile(s). */ -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR char *operating_dir_cpy = operating_dir; #endif #ifndef DISABLE_WRAPJUSTIFY @@ -2274,7 +2274,7 @@ int main(int argc, char **argv) memcpy(flags_cpy, flags, sizeof(flags_cpy)); -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR operating_dir = NULL; #endif #ifndef NANO_TINY @@ -2296,7 +2296,7 @@ int main(int argc, char **argv) #endif /* If the backed-up command-line options have a value, restore them. */ -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR if (operating_dir_cpy != NULL) { free(operating_dir); operating_dir = operating_dir_cpy; @@ -2383,7 +2383,7 @@ int main(int argc, char **argv) init_backup_dir(); #endif -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR /* Set up the operating directory. This entails chdir()ing there, * so that file reads and writes will be based there. */ if (operating_dir != NULL) diff --git a/src/proto.h b/src/proto.h index f5f977ee..640830a9 100644 --- a/src/proto.h +++ b/src/proto.h @@ -137,7 +137,7 @@ extern char *backup_dir; extern const char *locking_prefix; extern const char *locking_suffix; #endif -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR extern char *operating_dir; #endif @@ -291,7 +291,7 @@ char *get_next_filename(const char *name, const char *suffix); void do_insertfile_void(void); char *get_full_path(const char *origpath); char *safe_tempfile(FILE **f); -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR void init_operating_dir(void); bool outside_of_confinement(const char *currpath, bool allow_tabcomp); #endif diff --git a/src/rcfile.c b/src/rcfile.c index ce2c09df..e47ab2b8 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -63,7 +63,7 @@ static const rcoption rcopts[] = { #ifdef ENABLE_WRAPPING {"nowrap", NO_WRAP}, #endif -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR {"operatingdir", 0}, #endif #ifdef ENABLE_HISTORIES @@ -1102,7 +1102,7 @@ void parse_rcfile(FILE *rcstream, bool syntax_only) specified_color_combo[FUNCTION_TAG] = option; else #endif -#ifndef DISABLE_OPERATINGDIR +#ifdef ENABLE_OPERATINGDIR if (strcasecmp(rcopts[i].name, "operatingdir") == 0) operating_dir = option; else