]> granicus.if.org Git - sudo/commitdiff
Also honor SUDO_EDITOR in visudo. Previously is was only used
authorTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 22 Dec 2017 17:22:33 +0000 (10:22 -0700)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 22 Dec 2017 17:22:33 +0000 (10:22 -0700)
by sudoedit.

doc/sudoers.cat
doc/sudoers.man.in
doc/sudoers.mdoc.in
doc/visudo.cat
doc/visudo.man.in
doc/visudo.mdoc.in
plugins/sudoers/editor.c
plugins/sudoers/sudoers.c
plugins/sudoers/sudoers.h
plugins/sudoers/visudo.c

index 19bfd99edf0a9059a4af1f18fd28d6afa26d3ebd..0a1f2cdfc3fbb04a6912b8d9ae239fa1382b0ab5 100644 (file)
@@ -1001,19 +1001,19 @@ S\bSU\bUD\bDO\bOE\bER\bRS\bS O\bOP\bPT\bTI\bIO\bON\bNS\bS
                        higher.  It has no effect unless I/O logging is enabled
                        or the _\bu_\bs_\be_\b__\bp_\bt_\by flag is enabled.
 
-     env_editor        If set, v\bvi\bis\bsu\bud\bdo\bo will use the value of the EDITOR or
-                       VISUAL environment variables before falling back on the
-                       default editor list.  Note that this may create a
-                       security hole as it allows the user to run any
+     env_editor        If set, v\bvi\bis\bsu\bud\bdo\bo will use the value of the SUDO_EDITOR,
+                       VISUAL or EDITOR environment variables before falling
+                       back on the default editor list.  Note that this may
+                       create a security hole as it allows the user to run any
                        arbitrary command as root without logging.  A safer
                        alternative is to place a colon-separated list of
-                       editors in the editor variable.  v\bvi\bis\bsu\bud\bdo\bo will then only
-                       use the EDITOR or VISUAL if they match a value
-                       specified in editor.  If the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt flag is enabled,
-                       the EDITOR and/or VISUAL environment variables must be
-                       present in the _\be_\bn_\bv_\b__\bk_\be_\be_\bp list for the _\be_\bn_\bv_\b__\be_\bd_\bi_\bt_\bo_\br flag to
-                       function when v\bvi\bis\bsu\bud\bdo\bo is invoked via s\bsu\bud\bdo\bo.  This flag is
-                       _\bo_\bf_\bf by default.
+                       editors in the _\be_\bd_\bi_\bt_\bo_\br variable.  v\bvi\bis\bsu\bud\bdo\bo will then only
+                       use SUDO_EDITOR, VISUAL or EDITOR if they match a value
+                       specified in _\be_\bd_\bi_\bt_\bo_\br.  If the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt flag is enabled,
+                       the SUDO_EDITOR, VISUAL and/or EDITOR environment
+                       variables must be present in the _\be_\bn_\bv_\b__\bk_\be_\be_\bp list for the
+                       _\be_\bn_\bv_\b__\be_\bd_\bi_\bt_\bo_\br flag to function when v\bvi\bis\bsu\bud\bdo\bo is invoked via
+                       s\bsu\bud\bdo\bo.  This flag is _\bo_\bf_\bf by default.
 
      env_reset         If set, s\bsu\bud\bdo\bo will run the command in a minimal
                        environment containing the TERM, PATH, HOME, MAIL,
@@ -1613,12 +1613,12 @@ S\bSU\bUD\bDO\bOE\bER\bRS\bS O\bOP\bPT\bTI\bIO\bON\bNS\bS
 
      editor            A colon (`:') separated list of editors allowed to be
                        used with v\bvi\bis\bsu\bud\bdo\bo.  v\bvi\bis\bsu\bud\bdo\bo will choose the editor that
-                       matches the user's EDITOR or VISUAL environment
-                       variable if possible, or the first editor in the list
-                       that exists and is executable.  Note that the EDITOR
-                       and VISUAL environment variables are not preserved by
-                       default when the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt option is enabled.  The
-                       default is _\bv_\bi.
+                       matches the user's SUDO_EDITOR, VISUAL or EDITOR
+                       environment variable if possible, or the first editor
+                       in the list that exists and is executable.  Note that
+                       the SUDO_EDITOR, VISUAL and EDITOR environment
+                       variables are not preserved by default when the
+                       _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt option is enabled.  The default is _\bv_\bi.
 
      iolog_dir         The top-level directory to use when constructing the
                        path name for the input/output log directory.  Only
index 69b4dbe7e07ad2fba66bf4e20c787683df7f3562..f5bf7bb9093cc6ff5bd6d5155ae3ef6e97f73df0 100644 (file)
@@ -2132,29 +2132,32 @@ env_editor
 If set,
 \fBvisudo\fR
 will use the value of the
-\fREDITOR\fR
-or
+\fRSUDO_EDITOR\fR,
 \fRVISUAL\fR
+or
+\fREDITOR\fR
 environment variables before falling back on the default editor list.
 Note that this may create a security hole as it allows the user to
 run any arbitrary command as root without logging.
 A safer alternative is to place a colon-separated list of editors
 in the
-\fReditor\fR
+\fIeditor\fR
 variable.
 \fBvisudo\fR
-will then only use the
-\fREDITOR\fR
-or
+will then only use
+\fRSUDO_EDITOR\fR,
 \fRVISUAL\fR
+or
+\fREDITOR\fR
 if they match a value specified in
-\fReditor\fR.
+\fIeditor\fR.
 If the
 \fIenv_reset\fR
 flag is enabled, the
-\fREDITOR\fR
-and/or
+\fRSUDO_EDITOR\fR,
 \fRVISUAL\fR
+and/or
+\fREDITOR\fR
 environment variables must be present in the
 \fIenv_keep\fR
 list for the
@@ -3310,15 +3313,17 @@ separated list of editors allowed to be used with
 \fBvisudo\fR.
 \fBvisudo\fR
 will choose the editor that matches the user's
-\fREDITOR\fR
-or
+\fRSUDO_EDITOR\fR,
 \fRVISUAL\fR
+or
+\fREDITOR\fR
 environment variable if possible, or the first editor in the
 list that exists and is executable.
 Note that the
-\fREDITOR\fR
-and
+\fRSUDO_EDITOR\fR,
 \fRVISUAL\fR
+and
+\fREDITOR\fR
 environment variables are not preserved by default when the
 \fIenv_reset\fR
 option is enabled.
index ee0e3b376d29cefc9ad4a5f5c0285e91951c4c9a..06b481fcf6858b9953b1fe8c6f1368a2c695662a 100644 (file)
@@ -1998,29 +1998,32 @@ flag is enabled.
 If set,
 .Nm visudo
 will use the value of the
-.Ev EDITOR
-or
+.Ev SUDO_EDITOR ,
 .Ev VISUAL
+or
+.Ev EDITOR
 environment variables before falling back on the default editor list.
 Note that this may create a security hole as it allows the user to
 run any arbitrary command as root without logging.
 A safer alternative is to place a colon-separated list of editors
 in the
-.Li editor
+.Em editor
 variable.
 .Nm visudo
-will then only use the
-.Ev EDITOR
-or
+will then only use
+.Ev SUDO_EDITOR ,
 .Ev VISUAL
+or
+.Ev EDITOR
 if they match a value specified in
-.Li editor .
+.Em editor .
 If the
 .Em env_reset
 flag is enabled, the 
-.Ev EDITOR
-and/or
+.Ev SUDO_EDITOR ,
 .Ev VISUAL
+and/or
+.Ev EDITOR
 environment variables must be present in the
 .Em env_keep
 list for the
@@ -3114,15 +3117,17 @@ separated list of editors allowed to be used with
 .Nm visudo .
 .Nm visudo
 will choose the editor that matches the user's
-.Ev EDITOR
-or
+.Ev SUDO_EDITOR ,
 .Ev VISUAL
+or
+.Ev EDITOR
 environment variable if possible, or the first editor in the
 list that exists and is executable.
 Note that the
-.Ev EDITOR
-and
+.Ev SUDO_EDITOR ,
 .Ev VISUAL
+and
+.Ev EDITOR
 environment variables are not preserved by default when the
 .Em env_reset
 option is enabled.
index aa5c27859a6607407d74df857103844bf8e7102f..38f57912ce08a15cc583fa4ad8508ea9f9efc54c 100644 (file)
@@ -13,27 +13,45 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      _\bs_\bu_\bd_\bo_\be_\br_\bs file is currently being edited you will receive a message to try
      again later.
 
-     There is a hard-coded list of one or more editors that v\bvi\bis\bsu\bud\bdo\bo will use
-     set at compile-time that may be overridden via the _\be_\bd_\bi_\bt_\bo_\br _\bs_\bu_\bd_\bo_\be_\br_\bs Default
-     variable.  This list defaults to vi.  Normally, v\bvi\bis\bsu\bud\bdo\bo does not honor the
-     VISUAL or EDITOR environment variables unless they contain an editor in
-     the aforementioned editors list.  However, if v\bvi\bis\bsu\bud\bdo\bo is configured with
-     the --with-env-editor option or the _\be_\bn_\bv_\b__\be_\bd_\bi_\bt_\bo_\br Default variable is set in
-     _\bs_\bu_\bd_\bo_\be_\br_\bs, v\bvi\bis\bsu\bud\bdo\bo will use any the editor defines by VISUAL or EDITOR.
-     Note that this can be a security hole since it allows the user to execute
-     any program they wish simply by setting VISUAL or EDITOR.
-
-     v\bvi\bis\bsu\bud\bdo\bo parses the _\bs_\bu_\bd_\bo_\be_\br_\bs file after the edit and will not save the
+     v\bvi\bis\bsu\bud\bdo\bo parses the _\bs_\bu_\bd_\bo_\be_\br_\bs file after editing and will not save the
      changes if there is a syntax error.  Upon finding an error, v\bvi\bis\bsu\bud\bdo\bo will
      print a message stating the line number(s) where the error occurred and
      the user will receive the "What now?" prompt.  At this point the user may
      enter `e' to re-edit the _\bs_\bu_\bd_\bo_\be_\br_\bs file, `x' to exit without saving the
      changes, or `Q' to quit and save changes.  The `Q' option should be used
-     with extreme care because if v\bvi\bis\bsu\bud\bdo\bo believes there to be a parse error,
-     so will s\bsu\bud\bdo\bo and no one will be able to run s\bsu\bud\bdo\bo again until the error is
-     fixed.  If `e' is typed to edit the _\bs_\bu_\bd_\bo_\be_\br_\bs file after a parse error has
-     been detected, the cursor will be placed on the line where the error
-     occurred (if the editor supports this feature).
+     with extreme caution because if v\bvi\bis\bsu\bud\bdo\bo believes there to be a parse
+     error, so will s\bsu\bud\bdo\bo and no one will be able to run s\bsu\bud\bdo\bo again until the
+     error is fixed.  If `e' is typed to edit the _\bs_\bu_\bd_\bo_\be_\br_\bs file after a parse
+     error has been detected, the cursor will be placed on the line where the
+     error occurred (if the editor supports this feature).
+
+     There are two _\bs_\bu_\bd_\bo_\be_\br_\bs settings that determine which editor v\bvi\bis\bsu\bud\bdo\bo will
+     run.
+
+     editor    A colon (`:') separated list of editors allowed to be used with
+               v\bvi\bis\bsu\bud\bdo\bo.  v\bvi\bis\bsu\bud\bdo\bo will choose the editor that matches the user's
+               SUDO_EDITOR, VISUAL or EDITOR environment variable if possible,
+               or the first editor in the list that exists and is executable.
+               Note that the SUDO_EDITOR, VISUAL and EDITOR environment
+               variables are not preserved by default when the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt
+               _\bs_\bu_\bd_\bo_\be_\br_\bs option is enabled.  The default editor path is _\bv_\bi which
+               can be set at compile time via the --with-editor configure
+               option.
+
+     env_editor
+               If set, v\bvi\bis\bsu\bud\bdo\bo will use the value of the SUDO_EDITOR, VISUAL or
+               EDITOR environment variables before falling back on the default
+               editor list.  Note that this may create a security hole as it
+               allows the user to run any arbitrary command as root without
+               logging.  A safer alternative is to place a colon-separated
+               list of editors in the _\be_\bd_\bi_\bt_\bo_\br variable.  v\bvi\bis\bsu\bud\bdo\bo will then only
+               use SUDO_EDITOR, VISUAL or EDITOR if they match a value
+               specified in _\be_\bd_\bi_\bt_\bo_\br.  If the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt flag is enabled, the
+               SUDO_EDITOR, VISUAL and/or EDITOR environment variables must be
+               present in the _\be_\bn_\bv_\b__\bk_\be_\be_\bp list for the _\be_\bn_\bv_\b__\be_\bd_\bi_\bt_\bo_\br flag to
+               function when v\bvi\bis\bsu\bud\bdo\bo is invoked via s\bsu\bud\bdo\bo.  The default value is
+               _\bo_\bf_\bf, which can be set at compile time via the --with-env-editor
+               configure option.
 
      The options are as follows:
 
@@ -128,9 +146,11 @@ E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT
      The following environment variables may be consulted depending on the
      value of the _\be_\bd_\bi_\bt_\bo_\br and _\be_\bn_\bv_\b__\be_\bd_\bi_\bt_\bo_\br _\bs_\bu_\bd_\bo_\be_\br_\bs settings:
 
-     VISUAL           Invoked by v\bvi\bis\bsu\bud\bdo\bo as the editor to use
+     SUDO_EDITOR      Invoked by v\bvi\bis\bsu\bud\bdo\bo as the editor to use
 
-     EDITOR           Used by v\bvi\bis\bsu\bud\bdo\bo if VISUAL is not set
+     VISUAL           Used by v\bvi\bis\bsu\bud\bdo\bo if SUDO_EDITOR is not set
+
+     EDITOR           Used by v\bvi\bis\bsu\bud\bdo\bo if neither SUDO_EDITOR nor VISUAL is set
 
 F\bFI\bIL\bLE\bES\bS
      _\b/_\be_\bt_\bc_\b/_\bs_\bu_\bd_\bo_\b._\bc_\bo_\bn_\bf            Sudo front end configuration
@@ -217,4 +237,4 @@ D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
      file distributed with s\bsu\bud\bdo\bo or https://www.sudo.ws/license.html for
      complete details.
 
-Sudo 1.8.22                    December 6, 2017                    Sudo 1.8.22
+Sudo 1.8.22                    December 21, 2017                   Sudo 1.8.22
index f70591c9fd010101de38208c98eca9553dbe099c..79d15f63022df82a7d582abd95ddc5c417c62858 100644 (file)
@@ -21,7 +21,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.TH "VISUDO" "8" "December 6, 2017" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
+.TH "VISUDO" "8" "December 21, 2017" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
 .nh
 .if n .ad l
 .SH "NAME"
@@ -48,48 +48,10 @@ If the
 \fIsudoers\fR
 file is currently being edited you will receive a message to try again later.
 .PP
-There is a hard-coded list of one or more editors that
-\fBvisudo\fR
-will use set at compile-time that may be overridden via the
-\fIeditor\fR
-\fIsudoers\fR
-\fRDefault\fR
-variable.
-This list defaults to
-\fR@editor@\fR.
-Normally,
-\fBvisudo\fR
-does not honor the
-\fRVISUAL\fR
-or
-\fREDITOR\fR
-environment variables unless they contain an editor in the aforementioned
-editors list.
-However, if
-\fBvisudo\fR
-is configured with the
-\fR--with-env-editor\fR
-option or the
-\fIenv_editor\fR
-\fRDefault\fR
-variable is set in
-\fIsudoers\fR,
-\fBvisudo\fR
-will use any the editor defines by
-\fRVISUAL\fR
-or
-\fREDITOR\fR.
-Note that this can be a security hole since it allows the user to
-execute any program they wish simply by setting
-\fRVISUAL\fR
-or
-\fREDITOR\fR.
-.PP
 \fBvisudo\fR
 parses the
 \fIsudoers\fR
-file after the edit and will
-not save the changes if there is a syntax error.
+file after editing and will not save the changes if there is a syntax error.
 Upon finding an error,
 \fBvisudo\fR
 will print a message stating the line number(s)
@@ -107,7 +69,7 @@ to exit without saving the changes, or
 to quit and save changes.
 The
 \(oqQ\(cq
-option should be used with extreme care because if
+option should be used with extreme caution because if
 \fBvisudo\fR
 believes there to be a parse error, so will
 \fBsudo\fR
@@ -122,6 +84,84 @@ is typed to edit the
 file after a parse error has been detected, the cursor will be placed on
 the line where the error occurred (if the editor supports this feature).
 .PP
+There are two
+\fIsudoers\fR
+settings that determine which editor
+\fBvisudo\fR
+will run.
+.TP 10n
+editor
+A colon
+(\(oq:\&\(cq)
+separated list of editors allowed to be used with
+\fBvisudo\fR.
+\fBvisudo\fR
+will choose the editor that matches the user's
+\fRSUDO_EDITOR\fR,
+\fRVISUAL\fR
+or
+\fREDITOR\fR
+environment variable if possible, or the first editor in the
+list that exists and is executable.
+Note that the
+\fRSUDO_EDITOR\fR,
+\fRVISUAL\fR
+and
+\fREDITOR\fR
+environment variables are not preserved by default when the
+\fIenv_reset\fR
+\fIsudoers\fR
+option is enabled.
+The default editor path is
+\fI@editor@\fR
+which can be set at compile time via the
+\fR--with-editor\fR
+configure option.
+.TP 10n
+env_editor
+If set,
+\fBvisudo\fR
+will use the value of the
+\fRSUDO_EDITOR\fR,
+\fRVISUAL\fR
+or
+\fREDITOR\fR
+environment variables before falling back on the default editor list.
+Note that this may create a security hole as it allows the user to
+run any arbitrary command as root without logging.
+A safer alternative is to place a colon-separated list of editors
+in the
+\fIeditor\fR
+variable.
+\fBvisudo\fR
+will then only use
+\fRSUDO_EDITOR\fR,
+\fRVISUAL\fR
+or
+\fREDITOR\fR
+if they match a value specified in
+\fIeditor\fR.
+If the
+\fIenv_reset\fR
+flag is enabled, the
+\fRSUDO_EDITOR\fR,
+\fRVISUAL\fR
+and/or
+\fREDITOR\fR
+environment variables must be present in the
+\fIenv_keep\fR
+list for the
+\fIenv_editor\fR
+flag to function when
+\fBvisudo\fR
+is invoked via
+\fBsudo\fR.
+The default value is
+\fI@env_editor@\fR,
+which can be set at compile time via the
+\fR--with-env-editor\fR
+configure option.
+.PP
 The options are as follows:
 .TP 12n
 \fB\-c\fR, \fB\--check\fR
@@ -314,17 +354,26 @@ and
 \fIsudoers\fR
 settings:
 .TP 17n
-\fRVISUAL\fR
+\fRSUDO_EDITOR\fR
 Invoked by
 \fBvisudo\fR
 as the editor to use
 .TP 17n
-\fREDITOR\fR
+\fRVISUAL\fR
 Used by
 \fBvisudo\fR
 if
-\fRVISUAL\fR
+\fRSUDO_EDITOR\fR
 is not set
+.TP 17n
+\fREDITOR\fR
+Used by
+\fBvisudo\fR
+if neither
+\fRSUDO_EDITOR\fR
+nor
+\fRVISUAL\fR
+is set
 .SH "FILES"
 .TP 26n
 \fI@sysconfdir@/sudo.conf\fR
index 85d78fd8321189ca84be34bcd84cf844ef7bbf3d..e3dbbacd44f584a710bf07d4951dedb3873454da 100644 (file)
@@ -19,7 +19,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.Dd December 6, 2017
+.Dd December 21, 2017
 .Dt VISUDO @mansectsu@
 .Os Sudo @PACKAGE_VERSION@
 .Sh NAME
@@ -45,48 +45,10 @@ If the
 .Em sudoers
 file is currently being edited you will receive a message to try again later.
 .Pp
-There is a hard-coded list of one or more editors that
-.Nm
-will use set at compile-time that may be overridden via the
-.Em editor
-.Em sudoers
-.Li Default
-variable.
-This list defaults to
-.Li "@editor@" .
-Normally,
-.Nm
-does not honor the
-.Ev VISUAL
-or
-.Ev EDITOR
-environment variables unless they contain an editor in the aforementioned
-editors list.
-However, if
-.Nm
-is configured with the
-.Li --with-env-editor
-option or the
-.Em env_editor
-.Li Default
-variable is set in
-.Em sudoers ,
-.Nm
-will use any the editor defines by
-.Ev VISUAL
-or
-.Ev EDITOR .
-Note that this can be a security hole since it allows the user to
-execute any program they wish simply by setting
-.Ev VISUAL
-or
-.Ev EDITOR .
-.Pp
 .Nm
 parses the
 .Em sudoers
-file after the edit and will
-not save the changes if there is a syntax error.
+file after editing and will not save the changes if there is a syntax error.
 Upon finding an error,
 .Nm
 will print a message stating the line number(s)
@@ -104,7 +66,7 @@ to exit without saving the changes, or
 to quit and save changes.
 The
 .Ql Q
-option should be used with extreme care because if
+option should be used with extreme caution because if
 .Nm
 believes there to be a parse error, so will
 .Nm sudo
@@ -119,6 +81,84 @@ is typed to edit the
 file after a parse error has been detected, the cursor will be placed on
 the line where the error occurred (if the editor supports this feature).
 .Pp
+There are two
+.Em sudoers
+settings that determine which editor
+.Nm visudo
+will run.
+.Bl -tag -width 8n
+.It editor
+A colon
+.Pq Ql :\&
+separated list of editors allowed to be used with
+.Nm .
+.Nm
+will choose the editor that matches the user's
+.Ev SUDO_EDITOR ,
+.Ev VISUAL
+or
+.Ev EDITOR
+environment variable if possible, or the first editor in the
+list that exists and is executable.
+Note that the
+.Ev SUDO_EDITOR ,
+.Ev VISUAL
+and
+.Ev EDITOR
+environment variables are not preserved by default when the
+.Em env_reset
+.Em sudoers
+option is enabled.
+The default editor path is
+.Pa @editor@
+which can be set at compile time via the 
+.Li --with-editor
+configure option.
+.It env_editor
+If set,
+.Nm
+will use the value of the
+.Ev SUDO_EDITOR ,
+.Ev VISUAL
+or
+.Ev EDITOR
+environment variables before falling back on the default editor list.
+Note that this may create a security hole as it allows the user to
+run any arbitrary command as root without logging.
+A safer alternative is to place a colon-separated list of editors
+in the
+.Em editor
+variable.
+.Nm
+will then only use
+.Ev SUDO_EDITOR ,
+.Ev VISUAL
+or
+.Ev EDITOR
+if they match a value specified in
+.Em editor .
+If the
+.Em env_reset
+flag is enabled, the 
+.Ev SUDO_EDITOR ,
+.Ev VISUAL
+and/or
+.Ev EDITOR
+environment variables must be present in the
+.Em env_keep
+list for the
+.Em env_editor
+flag to function when
+.Nm
+is invoked via
+.Nm sudo .
+The default value is
+.Em @env_editor@ ,
+which can be set at compile time via the 
+.Li --with-env-editor
+configure option.
+.El
+.Pp
 The options are as follows:
 .Bl -tag -width Fl
 .It Fl c , -check
@@ -301,16 +341,24 @@ and
 .Em sudoers
 settings:
 .Bl -tag -width 15n
-.It Ev VISUAL
+.It Ev SUDO_EDITOR
 Invoked by
 .Nm
 as the editor to use
-.It Ev EDITOR
+.It Ev VISUAL
 Used by
 .Nm
 if
-.Ev VISUAL
+.Ev SUDO_EDITOR
 is not set
+.It Ev EDITOR
+Used by
+.Nm
+if neither
+.Ev SUDO_EDITOR
+nor
+.Ev VISUAL
+is set
 .El
 .Sh FILES
 .Bl -tag -width 24n
index ef34262c8e38bad4a445bafca91b3383355ce990..6708041ee51b4b5767cb697fc04bba0169dddb75 100644 (file)
  * the result against whitelist if non-NULL.  An argument vector
  * suitable for execve() is allocated and stored in argv_out.
  * If nfiles is non-zero, files[] is added to the end of argv_out.
+ *
  * Returns the path to be executed on success, else NULL.
  * The caller is responsible for freeing the returned editor path
  * as well as the argument vector.
  */
-char *
+static char *
 resolve_editor(const char *ed, size_t edlen, int nfiles, char **files,
     int *argc_out, char ***argv_out, char * const *whitelist)
 {
@@ -109,3 +110,65 @@ resolve_editor(const char *ed, size_t edlen, int nfiles, char **files,
     *argv_out = nargv;
     debug_return_str(editor_path);
 }
+
+/*
+ * Determine which editor to use based on the SUDO_EDITOR, VISUAL and
+ * EDITOR environment variables as well as the editor path in sudoers.
+ * If env_error is true, an editor environment variable that cannot be
+ * resolved is an error.
+ *
+ * Returns the path to be executed on success, else NULL.
+ * The caller is responsible for freeing the returned editor path
+ * as well as the argument vector.
+ */
+char *
+find_editor(int nfiles, char **files, int *argc_out, char ***argv_out,
+     char * const *whitelist, const char **env_editor, bool env_error)
+{
+    char *ev[3], *editor_path = NULL;
+    unsigned int i;
+    debug_decl(find_editor, SUDOERS_DEBUG_UTIL)
+
+    /*
+     * If any of SUDO_EDITOR, VISUAL or EDITOR are set, choose the first one.
+     */
+    *env_editor = NULL;
+    ev[0] = "SUDO_EDITOR";
+    ev[1] = "VISUAL";
+    ev[2] = "EDITOR";
+    for (i = 0; i < nitems(ev); i++) {
+       char *editor = getenv(ev[i]);
+
+       if (editor != NULL && *editor != '\0') {
+           *env_editor = editor;
+           editor_path = resolve_editor(editor, strlen(editor),
+               nfiles, files, argc_out, argv_out, whitelist);
+           if (editor_path != NULL)
+               break;
+           if (errno != ENOENT)
+               debug_return_str(NULL);
+       }
+    }
+    if (editor_path == NULL) {
+       const char *def_editor_end = def_editor + strlen(def_editor);
+       const char *cp, *ep;
+
+       if (env_error && *env_editor != NULL) {
+           /* User-specified editor could not be found. */
+           debug_return_str(NULL);
+       }
+
+       /* def_editor could be a path, split it up, avoiding strtok() */
+       for (cp = sudo_strsplit(def_editor, def_editor_end, ":", &ep);
+           cp != NULL; cp = sudo_strsplit(NULL, def_editor_end, ":", &ep)) {
+           editor_path = resolve_editor(cp, (size_t)(ep - cp), nfiles,
+               files, argc_out, argv_out, whitelist);
+           if (editor_path != NULL)
+               break;
+           if (errno != ENOENT)
+               debug_return_str(NULL);
+       }
+    }
+
+    debug_return_str(editor_path);
+}
index 7a7265d67f948729038463b71a9465139a9a891d..3cc1147882236b046c21edb9807bebbd1f85bdc8 100644 (file)
@@ -68,7 +68,6 @@
 /*
  * Prototypes
  */
-static char *find_editor(int nfiles, char **files, int *argc_out, char ***argv_out);
 static bool cb_fqdn(const union sudo_defs_val *);
 static bool cb_runas_default(const union sudo_defs_val *);
 static bool cb_tty_tickets(const union sudo_defs_val *);
@@ -622,13 +621,18 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
     /* Note: must call audit before uid change. */
     if (ISSET(sudo_mode, MODE_EDIT)) {
        int edit_argc;
+       const char *env_editor;
 
        free(safe_cmnd);
        safe_cmnd = find_editor(NewArgc - 1, NewArgv + 1, &edit_argc,
-           &edit_argv);
+           &edit_argv, NULL, &env_editor, false);
        if (safe_cmnd == NULL) {
            if (errno != ENOENT)
                goto done;
+           audit_failure(NewArgc, NewArgv, N_("%s: command not found"),
+               env_editor ? env_editor : def_editor);
+           sudo_warnx(U_("%s: command not found"),
+               env_editor ? env_editor : def_editor);
            goto bad;
        }
        if (audit_success(edit_argc, edit_argv) != 0 && !def_ignore_audit_errors)
@@ -1252,58 +1256,6 @@ sudoers_cleanup(void)
     debug_return;
 }
 
-/*
- * Determine which editor to use.  We don't need to worry about restricting
- * this to a "safe" editor since it runs with the uid of the invoking user,
- * not the runas (privileged) user.
- * Returns a fully-qualified path to the editor on success and fills
- * in argc_out and argv_out accordingly.  Returns NULL on failure.
- */
-static char *
-find_editor(int nfiles, char **files, int *argc_out, char ***argv_out)
-{
-    const char *cp, *ep, *editor = NULL;
-    char *editor_path = NULL, **ev, *ev0[4];
-    debug_decl(find_editor, SUDOERS_DEBUG_PLUGIN)
-
-    /*
-     * If any of SUDO_EDITOR, VISUAL or EDITOR are set, choose the first one.
-     */
-    ev0[0] = "SUDO_EDITOR";
-    ev0[1] = "VISUAL";
-    ev0[2] = "EDITOR";
-    ev0[3] = NULL;
-    for (ev = ev0; editor_path == NULL && *ev != NULL; ev++) {
-       if ((editor = getenv(*ev)) != NULL && *editor != '\0') {
-           editor_path = resolve_editor(editor, strlen(editor),
-               nfiles, files, argc_out, argv_out, NULL);
-           if (editor_path != NULL)
-               break;
-           if (errno != ENOENT)
-               debug_return_str(NULL);
-       }
-    }
-    if (editor_path == NULL) {
-       /* def_editor could be a path, split it up, avoiding strtok() */
-       const char *def_editor_end = def_editor + strlen(def_editor);
-       for (cp = sudo_strsplit(def_editor, def_editor_end, ":", &ep);
-           cp != NULL; cp = sudo_strsplit(NULL, def_editor_end, ":", &ep)) {
-           editor_path = resolve_editor(cp, (size_t)(ep - cp), nfiles,
-               files, argc_out, argv_out, NULL);
-           if (editor_path != NULL)
-               break;
-           if (errno != ENOENT)
-               debug_return_str(NULL);
-       }
-    }
-    if (!editor_path) {
-       audit_failure(NewArgc, NewArgv, N_("%s: command not found"),
-           editor ? editor : def_editor);
-       sudo_warnx(U_("%s: command not found"), editor ? editor : def_editor);
-    }
-    debug_return_str(editor_path);
-}
-
 #ifdef USE_ADMIN_FLAG
 static int
 create_admin_success_flag(void)
index 852d2c2dad869998c0948b7c6f0119db7cc486d7..945d29b95ac1c99d62d233d7ffe11ed991262912 100644 (file)
@@ -403,8 +403,8 @@ bool cb_group_plugin(const union sudo_defs_val *sd_un);
 extern const char *path_plugin_dir;
 
 /* editor.c */
-char *resolve_editor(const char *ed, size_t edlen, int nfiles, char **files,
-    int *argc_out, char ***argv_out, char * const *whitelist);
+char *find_editor(int nfiles, char **files, int *argc_out, char ***argv_out,
+     char * const *whitelist, const char **env_editor, bool env_error);
 
 /* mkdir_parents.c */
 bool sudo_mkdir_parents(char *path, uid_t uid, gid_t gid, mode_t mode, bool quiet);
index 97cc87960ed651656083222a54b53bde1a21bd41..33143ea9765094a706515ce592e1e8c409e932cc 100644 (file)
@@ -289,7 +289,8 @@ done:
 static char *
 get_editor(int *editor_argc, char ***editor_argv)
 {
-    char *editor, *editor_path = NULL, **whitelist = NULL;
+    char *editor_path = NULL, **whitelist = NULL;
+    const char *env_editor;
     static char *files[] = { "+1", "sudoers" };
     unsigned int whitelist_len = 0;
     debug_decl(get_editor, SUDOERS_DEBUG_UTIL)
@@ -318,37 +319,16 @@ get_editor(int *editor_argc, char ***editor_argv)
        whitelist[whitelist_len] = NULL;
     }
 
-    /* First try to use user's VISUAL or EDITOR environment vars. */
-    if ((editor = getenv("VISUAL")) == NULL || *editor == '\0')
-       editor = getenv("EDITOR");
-    if (editor && *editor == '\0')
-       editor = NULL;
-    if (editor != NULL) {
-       editor_path = resolve_editor(editor, strlen(editor), 2, files,
-           editor_argc, editor_argv, whitelist);
-       if (def_env_editor && editor_path == NULL) {
-           /* If we are honoring $EDITOR this is a fatal error. */
-           sudo_fatalx(U_("specified editor (%s) doesn't exist"), editor);
-       }
-    }
+    editor_path = find_editor(2, files, editor_argc, editor_argv, whitelist,
+       &env_editor, true);
     if (editor_path == NULL) {
-       /* def_editor could be a path, split it up, avoiding strtok() */
-       const char *def_editor_end = def_editor + strlen(def_editor);
-       const char *cp, *ep;
-       for (cp = sudo_strsplit(def_editor, def_editor_end, ":", &ep);
-           cp != NULL; cp = sudo_strsplit(NULL, def_editor_end, ":", &ep)) {
-           editor_path = resolve_editor(cp, (size_t)(ep - cp), 2, files,
-               editor_argc, editor_argv, whitelist);
-           if (editor_path != NULL)
-               break;
-           if (errno != ENOENT)
-               goto done;
+       if (def_env_editor && env_editor != NULL) {
+           /* We are honoring $EDITOR so this is a fatal error. */
+           sudo_fatalx(U_("specified editor (%s) doesn't exist"), env_editor);
        }
-    }
-    if (editor_path == NULL)
        sudo_fatalx(U_("no editor found (editor path = %s)"), def_editor);
+    }
 
-done:
     if (whitelist != NULL) {
        while (whitelist_len--)
            free(whitelist[whitelist_len]);