FYI:

----- Forwarded message from Craig Skinner <[email protected]> -----

Date: Sat, 31 Jan 2015 11:02:39 +0000 (GMT)
From: Craig Skinner <[email protected]>
To: [email protected]
Subject: sudo not honouring $PATH, $MAIL & umask

>Synopsis:      sudo not honouring $PATH, $MAIL & umask
>Category:      user
>Environment:
        System      : OpenBSD 5.6
        Details     : OpenBSD 5.6 (GENERIC) #274: Fri Aug  8 00:05:13 MDT 2014
                         
[email protected]:/usr/src/sys/arch/i386/compile/GENERIC

        Architecture: OpenBSD.i386
        Machine     : i386
>Description:
        sudo -H -i -u username
does not honour username's login(.conf) settings of $PATH, $MAIL & umask

login(1):

     login enters information into the environment (see environ(7)) specifying
     the user's home directory (HOME), command interpreter (SHELL), search
     path (PATH), terminal type (TERM), and user name (both LOGNAME and USER).

ENVIRONMENT
     login sets the following environment variables:

     HOME
     MAIL

sudo(8):

  Command Environment
     ......................  On BSD systems, if the use_loginclass option is
     enabled, the environment is initialized based on the path and setenv
     settings in /etc/login.conf.  The new environment contains the TERM,
     PATH, HOME, MAIL, SHELL, LOGNAME, USER, USERNAME and SUDO_* variables in
     addition to variables from the invoking process permitted by the
     env_check and env_keep options.  This is effectively a whitelist for
     environment variables.




>How-To-Repeat:
        Environment setup:


$ userinfo craig | egrep '^shell|^class'
class   staff
shell   /bin/ksh

$ userinfo david | egrep '^shell|^class'
class
shell   /bin/ksh


$ stat /etc/profile /etc/ksh.kshrc
stat: /etc/profile: No such file or directory
stat: /etc/ksh.kshrc: No such file or directory

$ stat ~craig/.profile ~craig/.kshrc
stat: /home/craig/.profile: No such file or directory
stat: /home/craig/.kshrc: No such file or directory

$ sudo stat ~david/.profile ~david/.kshrc
stat: /home/david/.profile: No such file or directory
stat: /home/david/.kshrc: No such file or directory


$ getcap -s path -f /etc/login.conf staff
/usr/bin /bin /usr/sbin /sbin /usr/local/bin /usr/local/sbin ~/bin
$ getcap -s umask -f /etc/login.conf staff
077

$ getcap -s path -f /etc/login.conf default
/usr/bin /bin /usr/local/bin ~/bin
$ getcap -s umask -f /etc/login.conf default
022


$ egrep 'env_|Defaults' /etc/sudoers | grep -v ^#
Defaults env_keep +="FTPMODE PKG_CACHE PKG_PATH SM_PATH SSH_AUTH_SOCK EDITOR 
VISUAL"
Defaults:%wsrc env_keep +="DESTDIR DISTDIR FETCH_CMD FLAVOR GROUP MAKE MAKECONF"
Defaults:%wsrc env_keep +="MULTI_PACKAGES NOMAN OKAY_FILES OWNER PKG_DBDIR"
Defaults:%wsrc env_keep +="PKG_DESTDIR PKG_TMPDIR PORTSDIR RELEASEDIR 
SHARED_ONLY"
Defaults:%wsrc env_keep +="SUBPACKAGE WRKOBJDIR SUDO_PORT_V1"
Defaults env_keep +="ftp_proxy http_proxy"
Defaults always_set_home, ignore_dot, use_loginclass



$ printenv LOGNAME; printenv PATH; printenv MAIL; umask
craig
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/home/craig/bin
/var/mail/craig
077


Here, $PATH, $MAIL & umask are unchanged:

$ /usr/bin/sudo -H -i -u david
$ printenv LOGNAME; printenv PATH; printenv MAIL; umask
david
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/home/craig/bin
/var/mail/craig
077


Compare the difference when logging in as that user:

$ exit
$ login david
Password:
$ printenv LOGNAME; printenv PATH; printenv MAIL; umask
david
/usr/bin:/bin:/usr/local/bin:/home/david/bin
022



SSH login gains correct $MAIL, along with $PATH & umask:

$ ssh localhost david
Password:
$ printenv LOGNAME; printenv PATH; printenv MAIL; umask
david
/usr/bin:/bin:/usr/local/bin:/home/david/bin
/var/mail/david
022



Note that login looses $MAIL again:

$ login david
Password:
$ printenv LOGNAME; printenv PATH; printenv MAIL; umask
david
/usr/bin:/bin:/usr/local/bin:/home/david/bin
022





>Fix:
        The sudo users mailing list said the 3 issues I identified
are known bugs, which have been fixed in newer sudo versions:
http://thread.gmane.org/gmane.comp.tools.sudo.user/4367

$ sudo -V
Sudo version 1.7.2p8

http://www.sudo.ws/sudo/stable.html
"The current stable release of sudo is 1.8.11p2"


Sudo bug 387 refers to MAIL being fixed in 1.7.4:
http://www.sudo.ws/bugs/show_bug.cgi?id=387

Sudo bug 527 (FreeBSD "sudo -i" doesn't use variables from /etc/login.conf)
seems to be similar: http://www.sudo.ws/bugs/show_bug.cgi?id=527
which is logged as Fixed in sudo 1.8.4

Maybe that fix also covers the login.conf path & umask issues:

http://www.sudo.ws/sudo/stable.html#1.8.4
On systems that use login.conf, sudo -i now sets environment variables
based on login.conf.


http://www.sudo.ws/sudo/stable.html#1.8.5
The initial evironment created when env_reset is in effect now includes
the contents of /etc/environment on AIX systems and the "setenv" and
"path" entries from /etc/login.conf on BSD systems.


http://www.sudo.ws/sudo/stable.html#1.8.6
Sudo is now built with the -fstack-protector flag if the the compiler supports 
it. 
Sudo is now built as a Position Independent Executable (PIE)
if supported by the compiler and linker.


http://www.sudo.ws/sudo/stable.html#1.8.6p6
On systems where the controlling tty can be determined via /proc or sysctl(),
sudo will no longer fall back to using ttyname() if the process has no
controlling tty. This prevents sudo from using a non-controlling tty for
logging and time stamp purposes. This is a potential security issue. 


http://www.sudo.ws/sudo/stable.html#1.8.7
The sudo.conf file now supports line continuation by
using a backslash as the last character on the line.
There is now a standalone sudo.conf manual page. 
Sudo now produces better error messages when
there is an error in the sudo.conf file.


http://www.sudo.ws/sudo/stable.html#1.8.9
On systems with BSD login classes, if the user specified a group (not a user)
to run the command as, it was possible to specify a different login class
even when the command was not run as the super user. 


http://www.sudo.ws/sudo/stable.html#1.8.9p5
Fixed parsing of the "umask" defaults setting in sudoers. Bug #632.


http://www.sudo.ws/sudo/stable.html#1.8.11p1
Fixed a crash with "sudo -i" when the current working directory does not exist. 
Bug #670.



http://marc.info/?l=openbsd-tech&m=139781410603949&w=2
http://marc.info/?l=openbsd-tech&m=140128033831591&w=2



dmesg:
OpenBSD 5.6 (GENERIC) #274: Fri Aug  8 00:05:13 MDT 2014
    [email protected]:/usr/src/sys/arch/i386/compile/GENERIC
cpu0: Intel Pentium II ("GenuineIntel" 686-class, 512KB L2 cache) 349 MHz
cpu0: 
FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR,PGE,MCA,CMOV,PSE36,MMX,FXSR,PERF
real mem  = 536363008 (511MB)
avail mem = 515149824 (491MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: AT/286+ BIOS, date 07/19/99, BIOS32 rev. 0 @ 0xfd861, SMBIOS 
rev. 2.1 @ 0xf7d95 (32 entries)
bios0: vendor IBM version "PDKT27AUS" date 07/19/99
bios0: IBM 6275500
acpi0 at bios0: rev 0
acpi0: sleep states S0 S1 S4 S5
acpi0: tables DSDT FACP
acpi0: wakeup devices PCI0(S5) PS2K(S1) PS2M(S1) COM1(S5) COM2(S5) USB0(S1)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpiprt0 at acpi0: bus 0 (PCI0)
acpicpu0 at acpi0
bios0: ROM list: 0xc0000/0x8000
cpu0 at mainbus0: (uniprocessor)
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
pci0 at mainbus0 bus 0: configuration mode 1 (bios)
pchb0 at pci0 dev 0 function 0 "Intel 82443BX AGP" rev 0x03
intelagp0 at pchb0
agp0 at intelagp0: aperture at 0xec000000, size 0x4000000
ppb0 at pci0 dev 1 function 0 "Intel 82443BX AGP" rev 0x03
pci1 at ppb0 bus 1
vga1 at pci1 dev 1 function 0 "S3 Trio3D AGP" rev 0x01
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
piixpcib0 at pci0 dev 2 function 0 "Intel 82371AB PIIX4 ISA" rev 0x02
pciide0 at pci0 dev 2 function 1 "Intel 82371AB IDE" rev 0x01: DMA, channel 0 
wired to compatibility, channel 1 wired to compatibility
wd0 at pciide0 channel 0 drive 0: <ST3250820A>
wd0: 16-sector PIO, LBA48, 238475MB, 488397168 sectors
wd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 2
wd1 at pciide0 channel 1 drive 0: <Maxtor 5A320J0>
wd1: 16-sector PIO, LBA48, 308921MB, 632672208 sectors
atapiscsi0 at pciide0 channel 1 drive 1
scsibus1 at atapiscsi0: 2 targets
cd0 at scsibus1 targ 0 lun 0: <TEAC, DV-516D, 1.06> ATAPI 5/cdrom removable
wd1(pciide0:1:0): using PIO mode 4, Ultra-DMA mode 2
cd0(pciide0:1:1): using PIO mode 4, Ultra-DMA mode 2
uhci0 at pci0 dev 2 function 2 "Intel 82371AB USB" rev 0x01: irq 10
piixpm0 at pci0 dev 2 function 3 "Intel 82371AB Power" rev 0x02: SMI
iic0 at piixpm0
spdmem0 at iic0 addr 0x50: 256MB SDRAM non-parity PC133CL2
spdmem1 at iic0 addr 0x51: 256MB SDRAM non-parity PC133CL2
spdmem2 at iic0 addr 0x55: 1GB DDR2 SDRAM PC2-6500CL5
xl0 at pci0 dev 16 function 0 "3Com 3c905B 100Base-TX" rev 0x30: irq 11, 
address 00:10:5a:f2:85:2c
exphy0 at xl0 phy 24: 3Com internal media interface
xl1 at pci0 dev 18 function 0 "3Com 3c905B 100Base-TX" rev 0x30: irq 9, address 
00:10:5a:f1:9d:a7
exphy1 at xl1 phy 24: 3Com internal media interface
isa0 at piixpcib0
isadma0 at isa0
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
com0: console
com1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo
pckbc0 at isa0 port 0x60/5
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard, using wsdisplay0
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
lpt0 at isa0 port 0x378/4 irq 7
npx0 at isa0 port 0xf0/16: reported by CPUID; using exception 16
fdc0 at isa0 port 0x3f0/6 irq 6 drq 2
fd0 at fdc0 drive 0: 1.44MB 80 cyl, 2 head, 18 sec
usb0 at uhci0: USB revision 1.0
uhub0 at usb0 "Intel UHCI root hub" rev 1.00/1.00 addr 1
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
root on wd0a (0e3aa2ac975978d6.a) swap on wd0b dump on wd0b
acpi0: PM1 stuck (en 0x500 st 0x400), clearing

usbdevs:
Controller /dev/usb0:
addr 1: full speed, self powered, config 1, UHCI root hub(0x0000), 
Intel(0x8086), rev 1.00
 port 1 powered
 port 2 powered

----- End forwarded message -----

Reply via email to