Example #1
0
    def delete(self, usr):
        """Delete a local Unix account."""

        # Zero out quotas.
        #
        for fs in list(rbconfig.gen_quotas().keys()):
            self.quota_delete(usr.uidNumber, fs)

        # Remove home directory and webtree. Don't bomb out if the
        # directories don't exist (i.e. ignore OSError).
        #
        try:
            self.wrapper(shutil.rmtree, usr.homeDirectory)
        except OSError:
            pass
        try:
            self.wrapper(shutil.rmtree, rbconfig.gen_webtree(usr.uid))
        except OSError:
            pass

        # Remove from announce mailing lists.
        #
        self.list_delete('announce-redbrick', '*****@*****.**' % usr.uid);
        self.list_delete('redbrick-newsletter', '*****@*****.**' % usr.uid);

        for file in rbconfig.gen_extra_user_files(usr.uid):
            try:
                self.wrapper(os.unlink, file)
            except OSError:
                pass
Example #2
0
    def add(self, usr):
        """Add account."""

        # Create home and webtree directory and populate.
        #
        webtree = rbconfig.gen_webtree(usr.uid)
        self.wrapper(os.mkdir, webtree, 0o711)
        self.wrapper(os.chown, webtree, usr.uidNumber, usr.gidNumber)
        self.cmd('%s -Rp %s %s' %
                 (rbconfig.command_cp, rbconfig.dir_skel, usr.homeDirectory))
        self.wrapper(os.chmod, usr.homeDirectory, 0o711)
        self.wrapper(os.symlink, webtree,
                     os.path.join(usr.homeDirectory, 'public_html'))
        # symlink vuln fix
        try:
            self.wrapper(os.chown,
                         os.path.join(usr.homeDirectory, 'public_html'),
                         usr.uidNumber, usr.gidNumber)
        except OSError:
            pass

        # Add a .forward file in their home directory to point to their
        # alternate email address, but only if they're a dcu person and
        # have an alternate email that's not a redbrick address.
        #
        if (usr.usertype in rbconfig.usertypes_dcu and usr.altmail
                and not re.search(r'@.*redbrick\.dcu\.ie', usr.altmail)):
            forward_file = os.path.join(usr.homeDirectory, '.forward')
            forwards = self.my_open(forward_file)
            forwards.write('%s\n' % usr.altmail)
            self.my_close(forwards)
            self.wrapper(os.chmod, forward_file, 0o600)

        # Change user & group ownership recursively on home directory.
        #
        self.cmd('%s -Rh %s:%s %s' %
                 (rbconfig.command_chown, usr.uidNumber, usr.usertype,
                  self.shquote(usr.homeDirectory)))

        # Set quotas for each filesystem.
        #
        for filesystem, (bqs, bqh, iqs, iqh) in list(
                rbconfig.gen_quotas(usr.usertype).items()):
            self.quota_set(usr.uidNumber, filesystem, bqs, bqh, iqs, iqh)

        # Add to redbrick announcement mailing lists.
        #
        self.list_add('announce-redbrick', '*****@*****.**' % usr.uid)
        self.list_add('redbrick-newsletter', '*****@*****.**' % usr.uid)
Example #3
0
    def convert(self, oldusr, newusr):
        """Convert account to a new usertype (Unix group)."""

        if oldusr.usertype == newusr.usertype:
            return

        # Do supplementary group shit in rbuserdb.
        #
        #if rbconfig.convert_primary_groups.has_key(usertype):
        #       group = rbconfig.convert_primary_groups[usertype]
        #else:
        #       group = usertype

        #if rbconfig.convert_extra_groups.has_key(usertype):
        #       groups = '-G ' + rbconfig.convert_extra_groups[usertype]
        #else:
        #       groups = ''

        if newusr.usertype == 'committe' and oldusr.usertype not in ('member', 'staff', 'committe'):
            raise RBFatalError("Non-members cannot be converted to committee group")

        if os.path.exists(newusr.homeDirectory):
            if not os.path.isdir(newusr.homeDirectory):
                try:
                    self.wrapper(os.unlink, newusr.homeDirectory)
                except OSError:
                    raise RBFatalError("New home directory '%s' already exists, could not unlink existing file." % newusr.homeDirectory)
            else:
                raise RBFatalError("New home directory '%s' already exists." % newusr.homeDirectory)

        # Rename home directory.
        #
        try:
            self.wrapper(os.rename, oldusr.homeDirectory, newusr.homeDirectory)
        except:
            raise RBFatalError("Could not rename home directory")

        # Change the home directory and webtree ownership to the new
        # group. -h on Solaris chgrp makes sure to change the symbolic
        # links themselves not the files they point to - very
        # important!!
        #
        self.cmd("%s -Rh %s %s %s" % (rbconfig.command_chgrp, newusr.gidNumber, self.shquote(newusr.homeDirectory), self.shquote(rbconfig.gen_webtree(oldusr.uid))))

        # Add/remove from committee mailing list as appropriate.
        #
        if newusr.usertype == 'committe':
            self.list_add('committee', "*****@*****.**" % oldusr.uid)
        elif oldusr.usertype == 'committe':
            self.list_delete('committee', "*****@*****.**" % oldusr.uid)

        # Add to admin list. Most admins stay in the root group for a while
        # after leaving committee, so removal can be done manually later.
        #
        if newusr.usertype == 'admin':
            self.list_add('rb-admins', "*****@*****.**" % oldusr.uid)
Example #4
0
    def rename(self, oldusr, newusr):
        """Rename an account.

        Requires: oldusr.uid, oldusr.homeDirectory, newusr.uid,
        newusr.homeDirectory.

        """

        # XXX Should check this before we rename user in ldap, have a
        # rbaccount.check_userfree? There should never be a file or
        # directory in /home or /webtree that doesn't belong to an
        # existing user.

        if os.path.exists(newusr.homeDirectory):
            if not os.path.isdir(newusr.homeDirectory):
                try:
                    self.wrapper(os.unlink, newusr.homeDirectory)
                except OSError:
                    raise RBFatalError("New home directory '%s' already exists, could not unlink existing file." % newusr.homeDirectory)
            else:
                raise RBFatalError("New home directory '%s' already exists." % newusr.homeDirectory)

        oldwebtree = rbconfig.gen_webtree(oldusr.uid)
        newwebtree = rbconfig.gen_webtree(newusr.uid)

        try:
            self.wrapper(os.rename, oldusr.homeDirectory, newusr.homeDirectory)
        except OSError as e:
            raise RBFatalError("Could not rename home directory [%s]" % e)

        try:
            self.wrapper(os.rename, oldwebtree, newwebtree)
        except OSError as e:
            raise RBFatalError("Could not rename webtree directory [%s]" % e)

        # Remove and then attempt to rename webtree symlink.
        #
        webtreelink = os.path.join(newusr.homeDirectory, 'public_html')
        try:
            self.wrapper(os.unlink, webtreelink)
        except OSError:
            pass
        if not os.path.exists(webtreelink):
            self.wrapper(os.symlink, newwebtree, webtreelink)

        # Rename any extra files that may belong to a user.
        #
        oldfiles = rbconfig.gen_extra_user_files(oldusr.uid)
        newfiles = rbconfig.gen_extra_user_files(newusr.uid)

        for i in range(len(oldfiles)):
            oldf = oldfiles[i]
            newf = newfiles[i]

            try:
                if os.path.isfile(oldf):
                    self.wrapper(os.rename, oldf, newf)
            except OSError as e :
                raise RBFatalError("Could not rename '%s' to '%s' [%s]" % (oldf, newf, e))

        # XXX
        # Rename their subscription to announce lists in case an email
        # alias isn't put in for them or is later removed.
        #
        self.list_delete('announce-redbrick', "*****@*****.**" % oldusr.uid);
        self.list_delete('redbrick-newsletter', "*****@*****.**" % oldusr.uid);
        self.list_add('announce-redbrick', "*****@*****.**" % newusr.uid);
        self.list_add('redbrick-newsletter', "*****@*****.**" % newusr.uid);