Exemple #1
0
def deploy_sysdb(comm, opts):
    """Put inital data to SysDB.

    @param comm
      a communicator. The following proxies should be available:
        - Tartarus.deployPrx.UserManager of type Tartarus::SysDB::UserManager
        - Tartarus.deployPrx.GroupManager of type Tartarus::SysDB::GroupManager
        - Tartarys.deployPrx.SysDBService of type Tartarus::core::Service
    @param opts
      a dictionary { option name : option value }. The following options are used
          *Name* *Type* *Madatory* *Comment*
          name   String M          n/a
    """
    prx = comm.propertyToProxy('Tartarus.deployPrx.SysDBService')
    _checked_configure(prx, opts.get('sysdb_force'))

    prx = comm.propertyToProxy('Tartarus.deployPrx.UserManager')
    um = SysDB.UserManagerPrx.checkedCast(prx)
    prx = comm.propertyToProxy('Tartarus.deployPrx.GroupManager')
    gm = SysDB.GroupManagerPrx.checkedCast(prx)

    admins_gid = gm.create(SysDB.GroupRecord(-1, "netadmins",
                                             "Network administrators"))
    users_gid = gm.create(SysDB.GroupRecord(-1, "netusers", "Network users"))

    uid = um.create(SysDB.UserRecord(-1, admins_gid, opts['name'],
                                     "System administrator"))
    gm.addUsers(users_gid, [uid])
Exemple #2
0
 def _group_exists(self, con, gid):
     cur = self._dbh.execute(con,
             "SELECT name FROM groups WHERE gid == %s",
             gid - self._go)
     if len(cur.fetchall()) != 1:
         raise I.GroupNotFound("Group not found",
                 "searching for group in database", gid)
Exemple #3
0
 def delete(self, con, gid, current):
     n = gid - self._go
     cur = self._dbh.execute(con,
             "DELETE FROM groups WHERE gid == %s", n)
     if cur.rowcount != 1:
         raise I.GroupNotFound("Group not found",
                 "deleting group", gid)
     con.commit()
Exemple #4
0
 def getById(self, con, uid, current):
     cur = self._dbh.execute(con, _user_query + " WHERE uid == %s",
                             uid - self._uo)
     res = cur.fetchall()
     if len(res) == 1:
         return self._db2users(res)[0]
     #XXX: RETURN USER WITH gid=-1
     raise I.UserNotFound("User not found", "retrieving user by id", uid)
Exemple #5
0
 def getByName(self, con, name, current):
     cur = self._dbh.execute(con,
             "SELECT gid, name, description FROM groups "
             "WHERE name == %s", name)
     res = cur.fetchall()
     if len(res) != 1:
         raise I.GroupNotFound("Group not found",
                 "Could not get group information for  %s" % name, -1)
     return self._db2groups(res)[0]
Exemple #6
0
 def getById(self, con, gid, current):
     cur = self._dbh.execute(con,
             "SELECT gid, name, description FROM groups "
             "WHERE gid == %s", gid - self._go)
     res = cur.fetchall()
     if len(res) != 1:
         raise I.GroupNotFound("Group not found",
                 "retrieving group by id" ,gid)
     return self._db2groups(res)[0]
Exemple #7
0
 def getByName(self, con, name, current):
     cur = self._dbh.execute(con, _user_query + " WHERE users.name == %s",
                             name)
     res = cur.fetchall()
     if len(res) == 1:
         return self._db2users(res)[0]
     #XXX: RETURN USER WITH gid=-1
     raise I.UserNotFound("User not found",
                          "retrieving data for user %s" % name, -1)
Exemple #8
0
def sysdb_deploy(wiz):
    wiz.dialog.info('Configuring SysDB...')

    wiz.sysdb_service.configure({'force': 'force'})
    prx = wiz.comm.propertyToProxy('Tartarus.deployPrx.UserManager')
    um = SysDB.UserManagerPrx.checkedCast(prx)
    prx = wiz.comm.propertyToProxy('Tartarus.deployPrx.GroupManager')
    gm = SysDB.GroupManagerPrx.checkedCast(prx)

    admins_gid = gm.create(SysDB.GroupRecord(-1, "netadmins",
                                             "Network administrators"))
    users_gid = gm.create(SysDB.GroupRecord(-1, "netusers", "Network users"))

    for name, full_name, _, is_adm in wiz.opts['users']:
        if is_adm:
            uid = um.create(SysDB.UserRecord(-1, admins_gid, name, full_name))
            gm.addUsers(users_gid, [uid])
        else:
            um.create(SysDB.UserRecord(-1, users_gid, name, full_name))
Exemple #9
0
 def getGroupsForUserId(self, con, uid, current):
     cur = self._dbh.execute(con,
             "SELECT groups.gid "
             "FROM groups, group_entries "
             "WHERE groups.gid == group_entries.gid "
             "AND group_entries.uid == %s",
             uid - self._uo)
     res = cur.fetchall()
     if len(res) == 0:
         #user definitly has primary group...
         raise I.UserNotFound("User not found",
                 "retrieving groups for user id", uid)
     return [ x[0] + self._go for x in res ]
Exemple #10
0
 def delUserFromGroups(self, con, uid, groups, current):
     ids = tuple((i - self._go for i in groups))
     ps = '(' + ', '.join(('%s' for x in ids)) +')'
     cur = self._dbh.execute(con,
             "DELETE FROM real_group_entries "
             "WHERE uid == %s AND gid IN " + ps,
             uid - self._uo, *ids)
     if cur.rowcount != len(groups):
         if current.ctx.get("PartialStrategy") != "Partial":
             #XXX: search for wrong uid and raise I.GroupNotFound
             raise I.GroupNotFound("Group not found",
                     "Some groups were not found", -1)
     con.commit()
Exemple #11
0
 def getUsers(self, con, userids, current):
     ids = tuple((i - self._uo for i in userids))
     ps = '(' + ', '.join(('%s' for x in ids)) + ')'
     cur = self._dbh.execute(con, _user_query + " WHERE uid IN " + ps, *ids)
     res = self._db2users(cur.fetchall())
     if (len(res) != len(userids)
             and current.ctx.get("PartialStrategy") != "Partial"):
         retrieved = set((u.uid for u in res))
         for i in userids:
             if i not in retrieved:
                 raise I.UserNotFound("User not found",
                                      "retrieving multiple users", i)
     return res
Exemple #12
0
 def getGroupsForUserName(self, con, name, current):
     cur = self._dbh.execute(con,
             "SELECT groups.gid "
             "FROM groups, group_entries, users "
             "WHERE groups.gid == group_entries.gid "
             "AND group_entries.uid == users.uid "
             "AND users.name == %s",
             name)
     res = cur.fetchall()
     if len(res) == 0:
         #user definitly has primary group...
         raise I.UserNotFound("User not found",
                 "Could not find user %s" % name, -1)
     return [ x[0] + self._go for x in res ]
Exemple #13
0
 def getGroups(self, con, groupids, current):
     ids = tuple((i - self._go for i in groupids))
     ps = '(' + ', '.join(('%s' for x in ids)) +')'
     cur = self._dbh.execute(con,
             "SELECT gid, name, description FROM groups "
             + "WHERE gid IN " + ps, *ids)
     res = self._db2groups(cur.fetchall())
     if (len(res) != len(groupids)
             and current.ctx.get("PartialStrategy") != "Partial"):
         retrieved = set( (g.gid for g in res) )
         for i in groupids:
             if i not in retrieved:
                 raise I.GroupNotFound("Group not found",
                         "retrieving multiple groups", i)
     return res
Exemple #14
0
 def modify(self, con, group, current):
     if not self._good_name.match(group.name):
         raise C.ValueError("Invalid group name: %s" % group.name)
     try:
         cur = self._dbh.execute(con,
                                 "UPDATE groups SET "
                                 "name=%s, description=%s "
                                 "WHERE gid == %s",
                                 group.name, group.description,
                                 group.gid - self._go)
     except self._dbh.IntegrityError:
         raise C.AlreadyExistsError("Group already exists",
                                    group.name)
     if cur.rowcount != 1:
         raise I.GroupNotFound("Group not found",
                 "modifying group", group.gid)
     con.commit()
Exemple #15
0
 def modify(self, con, user, current):
     if not self._good_name.match(user.name):
         raise C.ValueError("Invalid user name: %s" % user.name)
     uid = user.uid - self._uo
     gid = user.gid - self._go
     try:
         cur = self._dbh.execute(
             con, "UPDATE users SET "
             "name=%s, gid=%s, fullname=%s, shell=%s "
             "WHERE uid == %s", user.name, gid, user.fullName, user.shell,
             uid)
     except self._dbh.IntegrityError:
         raise C.AlreadyExistsError("User already exists", user.name)
     if cur.rowcount != 1:
         raise I.UserNotFound("User not found", "changing user record",
                              user.uid)
     con.commit()
Exemple #16
0
 def _db2users(self, mas):
     return [I.UserRecord(uid + self._uo, gid + self._go,
                          str(name), str(fn), s)
             for uid, gid, name, fn, s in mas]
Exemple #17
0
 def _db2groups(self, mas):
     return [I.GroupRecord(gid + self._go, str(name), str(descr))
             for gid, name, descr in mas]
Exemple #18
0
 def delete(self, con, uid, current):
     cur = self._dbh.execute(con, "DELETE FROM users WHERE uid=%s",
                             uid - self._uo)
     if cur.rowcount != 1:
         raise I.UserNotFound("User not found", "deleting user", uid)
     con.commit()