import subprocess import os import shutil ''' Hay que mirar de hacer hooks para cada tarea que hacemos ..... mirar llxcfg-usersync-backend-stdin ''' class NetFilesManager: def __init__(self,llxvar): self.llxvar = llxvar self.net_path = "/net" self.nethome_path = os.path.join(self.net_path ,"home") self.netgroup_path = os.path.join(self.net_path ,"groups") def create_home(self,user_info): group = user_info["profile"] uid = user_info["uid"] nethome = os.path.join(self.nethome_path,group,uid) if not os.path.exists(nethome): userid = int(user_info["uidNumber"]) usergid = int(user_info["gidNumber"]) #fix umask for fix correct permission prevmask = os.umask(0) os.mkdir(nethome,0770) #shutils.copytree("/etc/skel/UserFiles",nethome,symlinks=True) p1=subprocess.Popen(["rsync","-rltgD","/etc/skel/UserFiles",nethome]) out = p1.communicate() ''' #chown -R user:guser #chmod 770 for all directories #chmod 660 for all files ''' os.lchown(nethome,userid,usergid) for base ,directories, files in os.walk(nethome): for directori in directories: auxpath = os.path.join(base ,directori) os.lchown(auxpath,userid,usergid) os.chmod(auxpath,0770) for auxfile in files: auxpath = os.path.join(base,auxfile) os.chown(auxpath,userid,usergid) os.chmod(auxpath,0660) # for # restore old umask os.umask(prevmask) return nethome #def createHome def delete_home(self,user_info): nethome = os.path.join(self.nethome_path,user_info["profile"],user_info["uid"]) self.delete_directory(nethome) return nethome #def delete_home def create_group(self,group_cn): group_path = os.path.join(self.netgroup_path,group_cn) if not os.path.exists(group_path): prevumask = os.umask(0) os.mkdir(group_path,0755) os.umask(prevumask) #def create_group def delete_group(self,group_cn): group_path = os.path.join(self.netgroup_path,group_cn) self.delete_directory(group_path) #def delete_group def join_to_group(self,user_info,group_cn): group = user_info["profile"] uid = user_info["uid"] nethome = os.path.join(self.nethome_path,group,uid) auxgroup_path = os.path.join(self.netgroup_path, group_cn) if not os.path.exists(auxgroup_path): self.create_group(group_cn) auxpath = os.path.join(auxgroup_path , uid) if not os.path.exists(auxpath): os.symlink(nethome, auxpath) # def join_to_group def drop_group(self,user_info,group_cn): uid = user_info["uid"] group_path = os.path.join(self.netgroup_path, group_cn) auxpath = os.path.join(group_path , uid) if os.path.exists(auxpath): os.remove(auxpath) # def drop_group def delete_directory(self,directorypath): if os.path.exists(directorypath): try: shutil.rmtree(directorypath) except OSError: print "This path is a link" except : pass else: print "This path not exist " #def delete_directory def exist_home_or_create(self,user_info): group = user_info["profile"] uid = user_info["uid"] nethome = os.path.join(self.nethome_path,group,uid) if not os.path.exists(nethome): self.create_home(user_info) #def exist_home_or_create