Bug 1579764

Summary: Running 'sudo -s' gives 'error': mkdir: cannot create directory ‘/home/user/.local’: Permission denied
Product: Red Hat Enterprise Linux 7 Reporter: James Pearson <james-p>
Component: kde-settingsAssignee: Jan Grulich <jgrulich>
Status: CLOSED ERRATA QA Contact: Desktop QE <desktop-qa-list>
Severity: low Docs Contact:
Priority: unspecified    
Version: 7.5CC: amike, bgollahe, cww, huston, jgrulich, jkoten, jwright, steve.traylen, thomas.oulevey, tpelka
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: kde-settings-19-23.9.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-06 12:57:16 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1479323, 1656436    

Description James Pearson 2018-05-18 09:35:12 UTC
Description of problem:

Running 'sudo -s' gives the error/warning :

mkdir: cannot create directory ‘/home/user/.local’: Permission denied

(where /home/user/ is the home directory of the user running sudo

The sudo command works fine - as user becomes root (in this case)


Version-Release number of selected component (if applicable):

kde-settings-19-23.7.el7

How reproducible:

Always

Steps to Reproduce:
1. Run 'sudo -s'


Actual results:

mkdir: cannot create directory ‘/home/user/.local’: Permission denied

Expected results:

No error message

Additional info:

The problem was introduced in bug 1404382 - as /etc/profile.d/kde.csh and kde.sh now does:

# Fix the user-places.xbel error pop at first user login
if ( ! -d ${HOME}/.local/share ) then
    mkdir -p ${HOME}/.local/share
endif

and:

# Fix the user-places.xbel error pop at first user login
if [ ! -d $HOME/.local/share ]; then
    mkdir -p $HOME/.local/share
fi

We have 'Defaults !env_reset' in /etc/sudoers and users' home directories are NFS mounted plus the local root user doesn't have r/w access to users'
~/.local/ directories

The simple fix is to just redirect the mkdir stderr/stdout to /dev/null - and/or also check $SUDO_USER is not set/empty

Comment 2 Steve Traylen 2018-07-13 09:58:31 UTC
You can produce the same error whenever HOME is not set. e.g.

$ env   -u HOME bash -l -c 'echo "home is ${HOME}"'
mkdir: cannot create directory ‘/.local’: Permission denied
home is

Comment 3 Steve Traylen 2018-07-13 11:17:15 UTC
Indeed this is not the way to solve bug 1404382 , kde should create the directories itself.

Comment 11 errata-xmlrpc 2019-08-06 12:57:16 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:2141

Comment 12 Steve Huston 2019-08-27 18:40:34 UTC
This fix seems to have broken startup scripts for csh/tcsh users due to using [ ] instead of ( ) :

erigone:~/foo/etc/profile.d# diff -urN kde.csh /etc/profile.d/kde.csh
--- kde.csh     2019-08-27 14:37:03.222817544 -0400
+++ /etc/profile.d/kde.csh      2019-08-14 04:22:09.000000000 -0400
@@ -22,7 +22,7 @@
 end
 
 # Fix the user-places.xbel error pop at first user login
-if ( ! -d ${HOME}/.local/share ) then
+if [ ! -d ${HOME}/.local/share -a -w ${HOME} ] then
     mkdir -p ${HOME}/.local/share
 endif

erigone:~# su - tcshuser
Last login: Tue Aug 27 14:20:29 EDT 2019 on pts/29
if: Expression Syntax.
[tcshuser@erigone ~]$ foreach S ( /etc/profile.d/*.csh )
foreach? echo $S
foreach? source $S
foreach? end
/etc/profile.d/256term.csh
/etc/profile.d/astro.csh
/etc/profile.d/cobbler.csh
/etc/profile.d/colorgrep.csh
/etc/profile.d/colorls.csh
/etc/profile.d/cvs.csh
/etc/profile.d/gnome-ssh-askpass.csh
/etc/profile.d/kde.csh
if: Expression Syntax.
/etc/profile.d/lang.csh
/etc/profile.d/less.csh
/etc/profile.d/mc.csh
/etc/profile.d/modules.csh
/etc/profile.d/puppet-agent.csh
/etc/profile.d/qt-graphicssystem.csh
/etc/profile.d/qt.csh
/etc/profile.d/vim.csh
/etc/profile.d/which2.csh
[tcshuser@erigone ~]$ source .cshrc
erigone:~>

Comment 13 Steve Huston 2019-08-27 18:51:37 UTC
This seems to be the proper syntax (forgot about using && instead of -a as well):

--- kde.csh.1   2019-08-27 14:44:47.141991394 -0400
+++ kde.csh.2   2019-08-27 14:49:37.950857442 -0400
@@ -22,7 +22,7 @@
 end
 
 # Fix the user-places.xbel error pop at first user login
-if [ ! -d ${HOME}/.local/share -a -w ${HOME} ] then
+if ( ! -d ${HOME}/.local/share && -w ${HOME} ) then
     mkdir -p ${HOME}/.local/share
 endif

Comment 14 James Pearson 2019-08-28 10:31:14 UTC
(In reply to Steve Huston from comment #12)
> This fix seems to have broken startup scripts for csh/tcsh users due to
> using [ ] instead of ( ) :

That's a pretty fundamental error - how did that slip past QA ???