|
|
|
@ -27,7 +27,7 @@ _ = lambda x: x
|
|
|
|
|
setLocalTranslate('cl_client3', sys.modules[__name__])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Printable(object):
|
|
|
|
|
class Printable():
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
|
if isinstance(parent, Printable):
|
|
|
|
|
self.parent = parent.parent
|
|
|
|
@ -46,8 +46,7 @@ class _shareData(Printable):
|
|
|
|
|
|
|
|
|
|
def getDataInFile(self, fileName='', lenData=0):
|
|
|
|
|
"""Get data list from file"""
|
|
|
|
|
return filter(lambda x: len(x) == lenData,
|
|
|
|
|
map(lambda x: x.rstrip().split(":"), open(fileName)))
|
|
|
|
|
return [z for z in [x.rstrip().split(":") for x in open(fileName)] if len(z) == lenData]
|
|
|
|
|
|
|
|
|
|
def getFileAccess(self, perm="READ"):
|
|
|
|
|
if perm == "READ":
|
|
|
|
@ -79,7 +78,7 @@ class _shareData(Printable):
|
|
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
|
if self.getFileAccess(perm="WRITE"):
|
|
|
|
|
buff = "\n".join(map(lambda x: ":".join(x), self.data)) + "\n"
|
|
|
|
|
buff = "\n".join((":".join(x) for x in self.data)) + "\n"
|
|
|
|
|
FD = open(self.fileName, "w+")
|
|
|
|
|
FD.write(buff)
|
|
|
|
|
FD.close()
|
|
|
|
@ -91,7 +90,8 @@ class _shareData(Printable):
|
|
|
|
|
if self.getData() is False:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
self.data = filter(lambda x: x[0] != name, self.data)
|
|
|
|
|
# self.data = filter(lambda x: x[0] != name, self.data)
|
|
|
|
|
self.data = [x for x in self.data if x[0] != name]
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def replace(self, name, listData):
|
|
|
|
@ -119,7 +119,8 @@ class _shareData(Printable):
|
|
|
|
|
if self.getData() is False:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
listData = filter(lambda x: x[0] == name, self.data)
|
|
|
|
|
# listData = filter(lambda x: x[0] == name, self.data)
|
|
|
|
|
listData = [x for x in self.data if x[0] == name]
|
|
|
|
|
if listData:
|
|
|
|
|
return listData[0]
|
|
|
|
|
else:
|
|
|
|
@ -174,7 +175,8 @@ class group(_shareData):
|
|
|
|
|
if self.getData() is False:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
delEmpty = lambda y: filter(lambda x: x.strip(), y)
|
|
|
|
|
# delEmpty = lambda y: filter(lambda x: x.strip(), y)
|
|
|
|
|
delEmpty = lambda y: [x for x in y if x.strip()]
|
|
|
|
|
flagFound = False
|
|
|
|
|
for index, listDataOld in enumerate(self.data):
|
|
|
|
|
if name == listDataOld[0]:
|
|
|
|
@ -219,8 +221,7 @@ class group(_shareData):
|
|
|
|
|
if self.getData() is False:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
dataGroup = map(lambda x: x[3].split(","),
|
|
|
|
|
filter(lambda x: x[0] == name, self.data))
|
|
|
|
|
dataGroup = [x[3].split(",") for x in self.data if x[0] == name]
|
|
|
|
|
if dataGroup:
|
|
|
|
|
return dataGroup[0]
|
|
|
|
|
else:
|
|
|
|
@ -234,8 +235,9 @@ class group(_shareData):
|
|
|
|
|
for dataList in self.data:
|
|
|
|
|
groupName, x, gid, userList = dataList
|
|
|
|
|
if groupName in groups:
|
|
|
|
|
usersList = ",".join(filter(lambda x: x != userName,
|
|
|
|
|
userList.split(",")))
|
|
|
|
|
# usersList = ",".join(filter(lambda x: x != userName,
|
|
|
|
|
# userList.split(",")))
|
|
|
|
|
usersList = ",".join([x for x in userList.split(",") if x != userName])
|
|
|
|
|
dataList[3] = usersList
|
|
|
|
|
data.append(dataList)
|
|
|
|
|
self.data = data
|
|
|
|
@ -293,7 +295,7 @@ class _shareCache(_shareData):
|
|
|
|
|
modeFile = 0o600
|
|
|
|
|
if getModeFile(self.fileName, mode="mode") != modeFile:
|
|
|
|
|
os.chmod(self.fileName, modeFile)
|
|
|
|
|
buff = "\n".join(map(lambda x: ":".join(x), self.data)) + "\n"
|
|
|
|
|
buff = "\n".join((":".join(x) for x in self.data)) + "\n"
|
|
|
|
|
FD = open(self.fileName, "w+")
|
|
|
|
|
FD.write(buff)
|
|
|
|
|
FD.close()
|
|
|
|
@ -421,10 +423,8 @@ class userCache(Printable):
|
|
|
|
|
if not cacheCreatePasswdObj.save():
|
|
|
|
|
return False
|
|
|
|
|
# delete groups
|
|
|
|
|
usersGids = map(lambda x: x[3], cacheCreatePasswdObj.data)
|
|
|
|
|
deleteGroups = map(lambda x: x[0],
|
|
|
|
|
filter(lambda x: not x[2] in usersGids and not x[3],
|
|
|
|
|
cacheCreateGroupObj.data))
|
|
|
|
|
usersGids = [x[3] for x in cacheCreatePasswdObj.data]
|
|
|
|
|
deleteGroups = [x[0] for x in cacheCreateGroupObj.data if not x[2] in usersGids and not x[3]]
|
|
|
|
|
for delGroupName in deleteGroups:
|
|
|
|
|
if not cacheCreateGroupObj.delete(delGroupName):
|
|
|
|
|
return False
|
|
|
|
@ -454,10 +454,8 @@ class userCache(Printable):
|
|
|
|
|
if not cachePasswdObj.save():
|
|
|
|
|
return False
|
|
|
|
|
# delete groups
|
|
|
|
|
usersGids = map(lambda x: x[3], cachePasswdObj.data)
|
|
|
|
|
deleteGroups = map(lambda x: x[0],
|
|
|
|
|
filter(lambda x: not x[2] in usersGids and not x[3],
|
|
|
|
|
cacheGroupObj.data))
|
|
|
|
|
usersGids = [x[3] for x in cachePasswdObj.data]
|
|
|
|
|
deleteGroups = [x[0] for x in cacheGroupObj.data if not x[2] in usersGids and not x[3]]
|
|
|
|
|
for delGroupName in deleteGroups:
|
|
|
|
|
if not cacheGroupObj.delete(delGroupName):
|
|
|
|
|
return False
|
|
|
|
@ -497,11 +495,11 @@ class userCache(Printable):
|
|
|
|
|
return False
|
|
|
|
|
cacheCreateGroupObj = cacheCreateGroup(self)
|
|
|
|
|
secondUsersGroups = groupObj.getSecondUserGroups(userName)
|
|
|
|
|
usersGids = map(lambda x: x[3], passwdObj.data)
|
|
|
|
|
usersGids = [x[3] for x in passwdObj.data]
|
|
|
|
|
listGroupDataWork = []
|
|
|
|
|
for index, groupData in enumerate(listGroupData):
|
|
|
|
|
groupName, x, gid, listUsers = groupData
|
|
|
|
|
listUsers = filter(lambda x: x.strip(), listUsers.split(','))
|
|
|
|
|
listUsers = [x.strip() for x in listUsers.split(',')]
|
|
|
|
|
listUsers = ",".join(filter(lambda x: x != userName, listUsers))
|
|
|
|
|
cacheCreateGroupData = cacheCreateGroupObj.get(groupName)
|
|
|
|
|
if cacheCreateGroupData is False:
|
|
|
|
@ -546,7 +544,7 @@ class userCache(Printable):
|
|
|
|
|
cacheCreateListPasswdData = cacheCreatePasswdObj.getData()
|
|
|
|
|
if cacheCreateListPasswdData is False:
|
|
|
|
|
return False
|
|
|
|
|
delUsersPasswd = map(lambda x: x[0], cacheCreateListPasswdData)
|
|
|
|
|
delUsersPasswd = [x[0] for x in cacheCreateListPasswdData]
|
|
|
|
|
for delUser in delUsersPasswd:
|
|
|
|
|
if not self.delUserFromSystem(delUser):
|
|
|
|
|
return False
|
|
|
|
@ -573,8 +571,8 @@ class userCache(Printable):
|
|
|
|
|
if cacheListCreatePasswdData is False:
|
|
|
|
|
return False
|
|
|
|
|
# remove deleted users
|
|
|
|
|
cacheUsers = map(lambda x: x[0], cacheListPasswdData)
|
|
|
|
|
createUsers = map(lambda x: x[0], cacheListCreatePasswdData)
|
|
|
|
|
cacheUsers = [x[0] for x in cacheListPasswdData]
|
|
|
|
|
createUsers = [x[0] for x in cacheListCreatePasswdData]
|
|
|
|
|
deletedUsers = list(set(createUsers) - set(cacheUsers))
|
|
|
|
|
for delUser in deletedUsers:
|
|
|
|
|
if not self.delUserFromSystem(delUser):
|
|
|
|
@ -645,9 +643,11 @@ class userCache(Printable):
|
|
|
|
|
retGroup = groupObj.get(groupName)
|
|
|
|
|
if retGroup is False:
|
|
|
|
|
return False
|
|
|
|
|
listUsers = filter(lambda x: x.strip(), listUsers.split(','))
|
|
|
|
|
# listUsers = filter(lambda x: x.strip(), listUsers.split(','))
|
|
|
|
|
listUsers = [x for x in listUsers.split(',') if x.strip()]
|
|
|
|
|
if setAddUsers & set(listUsers) or gid in addUsersGid:
|
|
|
|
|
listUsers = filter(lambda x: not x in notAddUsers, listUsers)
|
|
|
|
|
# listUsers = filter(lambda x: not x in notAddUsers, listUsers)
|
|
|
|
|
listUsers = [x for x in listUsers if not x in notAddUsers]
|
|
|
|
|
if not retGroup:
|
|
|
|
|
if not cacheCreateGroupObj.add(groupName, gid, listUsers):
|
|
|
|
|
return False
|
|
|
|
@ -687,8 +687,7 @@ class userCache(Printable):
|
|
|
|
|
if not ldapData:
|
|
|
|
|
deletedCacheUsers.append(userName)
|
|
|
|
|
continue
|
|
|
|
|
cacheGroupData = map(lambda x: x[0], filter(lambda x: x[2] == gid,
|
|
|
|
|
cacheListGroupData))
|
|
|
|
|
cacheGroupData = [x[0] for x in cacheListGroupData if x[2] == gid]
|
|
|
|
|
if not cacheGroupData:
|
|
|
|
|
deletedCacheUsers.append(userName)
|
|
|
|
|
continue
|
|
|
|
@ -702,9 +701,7 @@ class userCache(Printable):
|
|
|
|
|
x, x, shadowLastChange, shadowMin, shadowMax, shadowWarning, \
|
|
|
|
|
x, x, x = cacheShadowData
|
|
|
|
|
groups = cacheGroupObj.getSecondUserGroups(userName)
|
|
|
|
|
gidsGroups = map(lambda x: x[2],
|
|
|
|
|
filter(lambda x: x[0] in groups,
|
|
|
|
|
cacheGroupObj.data))
|
|
|
|
|
gidsGroups = [x[2] for x in cacheGroupObj.data if x[0] in groups]
|
|
|
|
|
userShadowDict = {'uid': uid,
|
|
|
|
|
'gid': gid,
|
|
|
|
|
'fullName': gecos,
|
|
|
|
@ -720,8 +717,7 @@ class userCache(Printable):
|
|
|
|
|
for attr, value in userShadowDict.items():
|
|
|
|
|
if attr == "groups":
|
|
|
|
|
for index, val in enumerate(value):
|
|
|
|
|
if set(map(lambda x: x[index],
|
|
|
|
|
ldapData[attr])) != set(val):
|
|
|
|
|
if set([x[index] for x in ldapData[attr]]) != set(val):
|
|
|
|
|
flagDeleteUser = True
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|