Changeset af0cc3aa37cdfc89dbbf6a332d86b7cdf0b97349

Show
Ignore:
Timestamp:
05/24/07 17:05:28 (6 years ago)
Author:
iacopo <iacopo@…>
Children:
6ecf068da5fba67c2aa66cbf2e358d2c24ac58f1
Parents:
a0262d65402e841ba795780fac249f10bda80490
git-committer:
iacopo <iacopo@…> (05/24/07 17:05:28)
Message:

Home selection.
Check user duplicate unix/ldap.
Backup policy selection.

git-svn-id:  https://labs.truelite.it/svn/octofuss/trunk@346 5a101938-5c21-0410-9b5a-a83d6f3706a9

Location:
lib/octofuss
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lib/octofuss/cluster/__init__.py

    r0b74f36 raf0cc3a  
    187187 
    188188                self.selected_cluster = None 
     189 
     190                #Check when cannot import some modules 
     191                self.restartRequired = False 
     192 
    189193                 
    190194                self.model = ClusterTreeModel(self.network) 
     
    383387 
    384388        def install_software(self,obj,path): 
    385                 #try: 
    386                 from octofuss.packages import PackagesAdmin 
    387                 if len(path) is 1: 
    388                         s = PackagesAdmin(self.network[path[0]]) 
    389                 elif len(path) is 2: 
    390                         s = PackagesAdmin(Host(path[1])) 
    391                 self.change_app_content(s) 
    392                 #except Exception, e: 
    393                 #        self.__error_dialog(str(e)) 
     389                try: 
     390                        if self.restartRequired: 
     391                                raise Exception("You need to check some problems!") 
     392                        from octofuss.packages import PackagesAdmin 
     393                        if len(path) is 1: 
     394                                s = PackagesAdmin(self.network[path[0]]) 
     395                        elif len(path) is 2: 
     396                                s = PackagesAdmin(Host(path[1])) 
     397                        self.change_app_content(s) 
     398                except Exception, e: 
     399                        self.restartRequired = True 
     400                        self.__error_dialog(str(e)) 
    394401 
    395402        def add_host(self, obj,path, res): 
  • lib/octofuss/users/__init__.py

    ra0262d6 raf0cc3a  
    190190 
    191191        def getName(self): 
    192                 return self.objectClass['posixAccount'].getAttribute('cn') 
     192                return self.objectClass['posixAccount'].getAttribute('uid') 
    193193 
    194194        def getPassword(self): 
     
    423423        list = ldap.search(filter="(uid=*)", findattr=[]) 
    424424 
     425        #Keep track of local system users, and avoid duplicate "username" 
     426        global locallist 
     427 
    425428        objectList = {}  
    426429        # Parsing the list and create users object 
     
    484487                if objectList.has_key(ldapuser.getName().getValue()): 
    485488                        raise UserError("Incongruous ldap tree\nDuplicate user name in ldap server: "+ldapuser.getName().getValue()) 
     489                if locallist.has_key(ldapuser.getName().getValue()): 
     490                        print "Ldap user "+ldapuser.getName().getValue()+" already present in system users." 
     491                        continue  
    486492                objectList[ldapuser.getName().getValue()]=ldapuser 
    487493  
     
    566572# Second = create LDAP groups 
    567573ldapgrouplist = __ldap_group() 
    568 #Third = create LDAP users 
     574#Third = create UNIX users 
     575locallist =  __local() 
     576#Fourth = create LDAP users 
    569577ldaplist = __ldap_user() 
    570 #Fourth = create UNIX users 
    571 locallist =  __local() 
     578 
    572579 
    573580 
     
    871878                 
    872879                 
    873                    
     880        def createHomeDirectoryNoControl(self, dir, uid, gid): 
     881                """ Create home directory with owner and group """ 
     882                # Check if home already exists 
     883                #It does less checks. It create the dir only if it doesn't exist. 
     884                 
     885                if dir: 
     886                        if not os.path.isdir(dir): 
     887                                #os.mkdir(dir) 
     888                                os.system("/bin/cp -a /etc/skel "+dir) 
     889                                os.chown(dir, int(uid), int(gid)) 
     890                                os.system("chown -R "+uid+"."+gid+" "+dir) 
     891                                os.chmod(dir,0700) 
     892                                 
     893                        else: 
     894                                raise UserError("Home directory "+dir+" already exists!") 
     895                else: 
     896                        raise UserError("Directory  must be not null!") 
     897                  
    874898 
    875899        def createHomeDirectory(self, name, uid, gid, path="/home"): 
     
    11731197                                user = self.getUser(username) 
    11741198                                flags = user.getAttribute('sambaSamAccount','sambaAcctFlags') 
     1199                                  
     1200                                 
    11751201                                if flags != None: 
    11761202                                        if "D" in flags.getValue(): 
     
    14491475                # Create user directory 
    14501476                # __createHomeDirectory(self, name, uid, gid, path="/home/"): 
    1451                 self.createHomeDirectory(l.getName().getValue(), l.getUidNumber().getValue(), l.getGid().getValue()) 
     1477                homePrefix = "/home/" 
     1478                lenHome = len(homePrefix) 
     1479                dir = l.getHome().getValue() 
     1480                if dir.startswith(homePrefix) and dir[lenHome:].strip() != "": 
     1481                        self.createHomeDirectoryNoControl(l.getName().getValue(), l.getUidNumber().getValue(), l.getGid().getValue()) 
     1482                else: 
     1483                        raise UserError("User created, but could not create home directory.") 
     1484 
    14521485 
    14531486 
     
    17451778                        raise UserError("User already exists!") 
    17461779 
    1747                 if os.path.isdir("/home/"+l.getName().getValue()): 
     1780                homePrefix = "/home/" 
     1781                lenHome = len(homePrefix) 
     1782                dir = l.getHome().getValue() 
     1783                if dir.startswith(homePrefix) and dir[lenHome:].strip() != "": 
     1784                        pass 
     1785                else: 
     1786                        raise UserError("Invalid home directory!") 
     1787                if os.path.isdir(dir): 
    17481788                        raise UserError("Directory already exist") 
    17491789 
     
    18001840                #Home directory work 
    18011841                #Trying to create home  
    1802                 self.createHomeDirectory(l.getName().getValue(),l.getUidNumber().getValue(),l.getGid().getValue()) 
     1842                self.createHomeDirectoryNoControl(dir, l.getUidNumber().getValue(), l.getGid().getValue()) 
     1843 
    18031844                 
    18041845                 
     
    19011942 
    19021943                                        else: 
    1903                                                 raise Exception("Could not compress and delete home directory!\nTry without compress it.") 
     1944                                                raise Exception("Could not compress and delete home directory!") 
    19041945                                elif compress == -9: 
    19051946                                        #Rename 
  • lib/octofuss/users/ui/__init__.py

    r55cb0ff raf0cc3a  
    2828#backend = Backend() 
    2929backend = backendSingleton 
    30  
    3130 
    3231 
     
    14921491                mainFrame = gtk.Frame(_("New User")) 
    14931492                vboxMain = gtk.VBox() 
    1494                 mainTable = gtk.Table(7,2,False) 
     1493                mainTable = gtk.Table(8,2,False) 
    14951494 
    14961495                fieldLabel = gtk.Label(_("<b><big>Base preferences</big></b>")) 
     
    15521551 
    15531552 
     1553                #Home directory selection 
     1554                labelHome = gtk.Label(_("Home directory")) 
     1555                al5 = gtk.Alignment(xalign=0.5) 
     1556                al5.add(labelHome) 
     1557 
     1558                entryHome= gtk.Entry() 
     1559 
     1560                mainTable.attach(al5,0,1,5,6,xoptions=gtk.FILL,yoptions=gtk.SHRINK,ypadding=10,xpadding=30) 
     1561                mainTable.attach(entryHome,1,2,5,6,yoptions=gtk.SHRINK,ypadding=10,xpadding=10) 
     1562 
     1563 
    15541564                # Maing group selection comboBox 
    15551565                groupComboLabel = gtk.Label(_("Main group")) 
    1556                 al5 = gtk.Alignment(xalign=0.5) 
    1557                 al5.add(groupComboLabel) 
     1566                al6 = gtk.Alignment(xalign=0.5) 
     1567                al6.add(groupComboLabel) 
    15581568 
    15591569                groupComboBox = gtk.ComboBox() 
     
    15651575                groupComboBox.set_active(0) 
    15661576 
    1567                 mainTable.attach(al5,0,1,5,6,xoptions=gtk.FILL,yoptions=gtk.SHRINK,ypadding=10,xpadding=30) 
    1568                 mainTable.attach(groupComboBox,1,2,5,6,yoptions=gtk.SHRINK,ypadding=10,xpadding=10) 
     1577                mainTable.attach(al6,0,1,6,7,xoptions=gtk.FILL,yoptions=gtk.SHRINK,ypadding=10,xpadding=30) 
     1578                mainTable.attach(groupComboBox,1,2,6,7,yoptions=gtk.SHRINK,ypadding=10,xpadding=10) 
    15691579 
    15701580                groupLabel = gtk.Label(_("<b><big>User privileges</big></b>")) 
     
    15721582                groupLabel.set_use_markup(True) 
    15731583 
    1574                 mainTable.attach(groupLabel,0,1,6,7,xoptions=gtk.FILL,yoptions=gtk.SHRINK,ypadding=10,xpadding=10) 
     1584                mainTable.attach(groupLabel,0,1,7,8,xoptions=gtk.FILL,yoptions=gtk.SHRINK,ypadding=10,xpadding=10) 
    15751585 
    15761586 
     
    16441654                v.pack_start(mainFrame) 
    16451655                save = gtk.Button(stock="gtk-add") 
    1646                 save.connect("clicked", self.__save_clicked,entryRealname,entryUsername,entryPassword,entryPasswordConferma,groupsToShow,self.__groupList, groupComboBox) 
     1656                save.connect("clicked", self.__save_clicked,entryRealname,entryUsername,entryPassword,entryPasswordConferma,entryHome,groupsToShow,self.__groupList, groupComboBox) 
    16471657 
    16481658                cancel = gtk.Button(stock="gtk-cancel") 
     
    16571667                 
    16581668 
    1659         def __save_clicked(self,button, entryRealname,entryUsername,entryPassword,entryPasswordConferma,groupsToShow, groupList,groupComboBox): 
     1669        def __save_clicked(self,button, entryRealname,entryUsername,entryPassword,entryPasswordConferma,entryHome,groupsToShow, groupList,groupComboBox): 
    16601670                """ Check fields and add the user to Ldap Server """  
    16611671                global backend 
     
    17111721                        n.setAttribute("objectClass",attrObjectClass) 
    17121722                        n.setAttribute("gidNumber", str(gid)) 
    1713                         n.setAttribute("homeDirectory","/home/"+entryUsername.get_text()) 
     1723                        #n.setAttribute("homeDirectory","/home/"+entryUsername.get_text()) 
     1724                        homePrefix = "/home/" 
     1725                        lenHome = len(homePrefix) 
     1726                        directoryHome = entryHome.get_text().replace(" ","")                                 
     1727 
     1728                        if not entryHome.get_text(): 
     1729                                n.setAttribute("homeDirectory","/home/"+entryUsername.get_text()) 
     1730                        elif directoryHome.startswith(homePrefix): 
     1731                                import string 
     1732                                for i in directoryHome[lenHome:]: 
     1733                                        if i in string.ascii_letters or i in string.digits: 
     1734                                                pass 
     1735                                        else: 
     1736                                                self.showDialog(_("Invalid characters in home directory field!"),gtk.MESSAGE_ERROR) 
     1737                                                return 
     1738 
     1739                                             
     1740                                if directoryHome[lenHome:].strip() != "": 
     1741                                        n.setAttribute("homeDirectory",directoryHome)  
     1742                                else: 
     1743                                        self.showDialog(_("Home directory /home/ is not a valid path."),gtk.MESSAGE_ERROR) 
     1744                                        return 
     1745                                
     1746                        else: 
     1747                                #Display security error 
     1748                                self.showDialog(_("Home directory selection is permitted only under /home/"),gtk.MESSAGE_ERROR) 
     1749                                return 
     1750                                 
     1751                             
    17141752                        n.setAttribute("loginShell","/bin/sh") 
    17151753