check for existence before chmod/chown/chcon (#206)

code review feedback
This commit is contained in:
Hans Krijger
2016-06-06 11:48:21 -07:00
parent 95cf642f79
commit 89cb898ac3
3 changed files with 20 additions and 5 deletions
+4 -1
View File
@@ -194,7 +194,7 @@ class DefaultOSUtil(object):
"""
path, thumbprint, value = pubkey
if path is None:
raise OSUtilError("Publich key path is None")
raise OSUtilError("Public key path is None")
crytputil = CryptUtil(conf.get_openssl_cmd())
@@ -261,6 +261,9 @@ class DefaultOSUtil(object):
Returns exit result.
"""
if self.is_selinux_system():
if not os.path.exists(path):
logger.error("Path does not exist: {0}".format(path))
return 1
return shellutil.run('chcon ' + con + ' ' + path)
def conf_sshd(self, disable_password):
+9 -3
View File
@@ -91,11 +91,17 @@ def mkdir(dirpath, mode=None, owner=None):
chowner(dirpath, owner)
def chowner(path, owner):
owner_info = pwd.getpwnam(owner)
os.chown(path, owner_info[2], owner_info[3])
if not os.path.exists(path):
logger.error("Path does not exist: {0}".format(path))
else:
owner_info = pwd.getpwnam(owner)
os.chown(path, owner_info[2], owner_info[3])
def chmod(path, mode):
os.chmod(path, mode)
if not os.path.exists(path):
logger.error("Path does not exist: {0}".format(path))
else:
os.chmod(path, mode)
def rm_files(*args):
for path in args:
+7 -1
View File
@@ -228,6 +228,9 @@ class AbstractDistro(object):
Returns exit result.
"""
if self.isSelinuxSystem():
if not os.path.exists(path):
Error("Path does not exist: {0}".format(path))
return 1
return Run('chcon ' + cn + ' ' + path)
def setHostname(self,name):
@@ -2336,7 +2339,10 @@ def ChangeOwner(filepath, user):
except:
pass
if p != None:
os.chown(filepath, p[2], p[3])
if not os.path.exists(filepath):
Error("Path does not exist: {0}".format(filepath))
else:
os.chown(filepath, p[2], p[3])
def CreateDir(dirpath, user, mode):
"""