summaryrefslogtreecommitdiffstats
path: root/src/lib/Client
diff options
context:
space:
mode:
authorDaniel Joseph Barnhart Clark <dclark@pobox.com>2007-07-02 23:59:22 +0000
committerDaniel Joseph Barnhart Clark <dclark@pobox.com>2007-07-02 23:59:22 +0000
commitde8f56862bed763aaced871a825192619fa0edac (patch)
treed0247261f443d465d11c249c0823f86fc99fb71e /src/lib/Client
parent495cc8ba508c4a13c8f8822fbd0aa51c6f4e1356 (diff)
downloadbcfg2-de8f56862bed763aaced871a825192619fa0edac.tar.gz
bcfg2-de8f56862bed763aaced871a825192619fa0edac.tar.bz2
bcfg2-de8f56862bed763aaced871a825192619fa0edac.zip
Power about to die can't find adapter may work or not...
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3409 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Client')
-rw-r--r--src/lib/Client/Tools/POSIX.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py
index 1cc448782..6dcece8e2 100644
--- a/src/lib/Client/Tools/POSIX.py
+++ b/src/lib/Client/Tools/POSIX.py
@@ -22,6 +22,28 @@ def calcPerms(initial, perms):
tempperms |= perm
return tempperms
+def normUid(entry):
+ '''This takes a user name or uid and returns the corrisponding uid or False'''
+ try:
+ try:
+ return int(entry.get('owner'))
+ except:
+ return int(pwd.getpwnam(entry.get('owner'))[2])
+ except (OSError, KeyError):
+ self.logger.error('UID normalization failed for %s' % (entry.get('name')))
+ return False
+
+def normGid(entry):
+ '''This takes a group name or gid and returns the corrisponding gid or False'''
+ try:
+ try:
+ return int(entry.get('group'))
+ except:
+ return int(grp.getgrnam(entry.get('group'))[2])
+ except (OSError, KeyError):
+ self.logger.error('GID normalization failed for %s' % (entry.get('name')))
+ return False
+
class POSIX(Bcfg2.Client.Tools.Tool):
'''POSIX File support code'''
__name__ = 'POSIX'
@@ -95,11 +117,7 @@ class POSIX(Bcfg2.Client.Tools.Tool):
except (OSError, KeyError):
self.logger.error('User/Group resolution failed for path %s' % (entry.get('name')))
owner = 'root'
- try:
- grp.getgrnam('root')
- group = 'root'
- except KeyError:
- group = 'system'
+ group = '0'
finfo = os.stat(entry.get('name'))
perms = oct(finfo[ST_MODE])[-4:]
if entry.get('mtime', '-1') != '-1':
@@ -205,8 +223,7 @@ class POSIX(Bcfg2.Client.Tools.Tool):
def InstallPermissions(self, entry):
'''Install POSIX Permissions'''
try:
- os.chown(entry.get('name'),
- pwd.getpwnam(entry.get('owner'))[2], grp.getgrnam(entry.get('group'))[2])
+ os.chown(entry.get('name'), normUid(entry), normGid(entry))
os.chmod(entry.get('name'), calcPerms(S_IFDIR, entry.get('perms')))
return True
except (OSError, KeyError):
@@ -304,8 +321,7 @@ class POSIX(Bcfg2.Client.Tools.Tool):
newfile.write(filedata)
newfile.close()
try:
- os.chown(newfile.name, pwd.getpwnam(entry.get('owner'))[2],
- grp.getgrnam(entry.get('group'))[2])
+ os.chown(newfile.name, normUid(entry), normGid(entry))
except KeyError:
self.logger.error("Failed to chown %s to %s:%s" % \
(entry.get('name'), entry.get('owner'),