From dc60b72e96d4ff6aa1e818945a8fa8dd5025bcd8 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Fri, 25 Oct 2002 16:08:53 +0000
Subject: [PATCH] forward-ported --disable-wrapping-as-root from nano 1.0.x

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1311 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog    |  4 ++++
 configure.ac |  6 ++++++
 nano.c       | 10 ++++++++++
 rcfile.c     |  6 ++++++
 4 files changed, 26 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index cd6acde5..864e4c34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
 CVS code -
+- General:
+	- Forward-ported Chris' --disable-wrapping-as-root option from
+	  1.0.9.  Per Jordi's suggestions, have it override /etc/nanorc
+	  but not ~/.nanorc. (DLR)
 
 GNU nano 1.1.12 - 10/24/2002
 - General:
diff --git a/configure.ac b/configure.ac
index f23f0825..05a91898 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,12 @@ AC_ARG_ENABLE(wrapping,
     AC_DEFINE(DISABLE_WRAPPING, 1, [Define this to disable any and all text wrapping.])
  fi])
 
+AC_ARG_ENABLE(wrapping-as-root,
+[  --disable-wrapping-as-root  Disable wrapping of text as root by default],
+ [if test x$enableval != xyes; then
+    AC_DEFINE(DISABLE_ROOTWRAP, 1, [Define this to disable wrapping as root by default.])
+ fi])
+
 AC_ARG_ENABLE(color,
 [  --enable-color          Enable color and syntax highlighting],
 [if test x$enableval = xyes; then
diff --git a/nano.c b/nano.c
index 6fbe7e7e..35ccacbf 100644
--- a/nano.c
+++ b/nano.c
@@ -725,6 +725,9 @@ void version(void)
 #ifdef DISABLE_WRAPPING
     printf(" --disable-wrapping");
 #endif
+#ifdef DISABLE_ROOTWRAP
+    printf(" --disable-wrapping-as-root");
+#endif
 #ifdef ENABLE_COLOR
     printf(" --enable-color");
 #endif
@@ -2998,6 +3001,13 @@ int main(int argc, char *argv[])
     }
 	if (!ISSET(NO_RCFILE))
 	    do_rcfile();
+#else
+#if defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING)
+    /* if we don't have rcfile support, we're root, and
+       --disable-wrapping-as-root is used, turn wrapping off */
+    if (geteuid() == 0)
+	SET(NO_WRAP);
+#endif
 #endif /* ENABLE_NANORC */
 
 #ifdef HAVE_GETOPT_LONG
diff --git a/rcfile.c b/rcfile.c
index 6a7fb977..96ffa625 100644
--- a/rcfile.c
+++ b/rcfile.c
@@ -613,6 +613,12 @@ void do_rcfile(void)
 	nanorc = nrealloc(nanorc, strlen(userage->pw_dir) + 9);
 	sprintf(nanorc, "%s/.nanorc", userage->pw_dir);
 
+#if defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING)
+    /* If we've already read $SYSCONFDIR/nanorc (if it's there), we're
+       root, and --disable-wrapping-as-root is used, turn wrapping off */
+	if (euid == 0)
+	    SET(NO_WRAP);
+#endif
 	if ((rcstream = fopen(nanorc, "r")) == NULL) {
 	    /* Don't complain about the file not existing */
 	    if (errno != ENOENT)
-- 
GitLab