def AddGroup(self, groupname, gid, sender, connection): """Add Group. @param groupname: Group name @param gid: Group ID @raise dbus.DBusException: @rtype dbus.Int64: The GID from recently created Group. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.addgroup') init_group = self.__libuser.initGroup(groupname) init_group.set(libuser.GIDNUMBER, gid) try: self.__libuser.addGroup(init_group) except RuntimeError, error: msg = 'org.mandrivalinux.mcc2.Users.Error.AddGroupFailed' #FIXME: What's the others libuser errors? if str(error) == 'entry already present in file': msg = 'org.mandrivalinux.mcc2.Users.Error.GroupAlreadyExist' raise dbus.DBusException, msg
def ModifyGroup(self, groupInfo, sender, connection): """Modify Group. @param group_info:A dbus.Dictionary with user information with the following content: * groupname: * new_groupname: This is optional. * members: Example: groupInfo = { 'oldGroupName': 'john', 'newGroupName': 'johns' 'members': ['john', 'users', 'wheel'] } @raise dbus.DBusException: @rtype dbus.Int32: 1 ok or 0 fail. """ checkAuthorization(sender, connection, self.__action) groupEntity = self.__libuser.lookupGroupByName( groupInfo['oldGroupName']) if groupInfo.has_key('members'): if groupInfo['members'][0] == '': groupInfo['members'] = [] groupEntity.set(libuser.MEMBERNAME, groupInfo['members']) if groupInfo.has_key('newGroupName'): groupEntity.set(libuser.GROUPNAME, groupInfo['newGroupName']) return dbus.Int32(self.__libuser.modifyGroup(groupEntity))
def ModifyGroup(self, groupInfo, sender, connection): """Modify Group. @param group_info:A dbus.Dictionary with user information with the following content: * groupname: * new_groupname: This is optional. * members: Example: groupInfo = { 'oldGroupName': 'john', 'newGroupName': 'johns' 'members': ['john', 'users', 'wheel'] } @raise dbus.DBusException: @rtype dbus.Int32: 1 ok or 0 fail. """ checkAuthorization(sender, connection, self.__action) groupEntity = self.__libuser.lookupGroupByName(groupInfo['oldGroupName']) if groupInfo.has_key('members'): if groupInfo['members'][0] == '': groupInfo['members'] = [] groupEntity.set(libuser.MEMBERNAME, groupInfo['members']) if groupInfo.has_key('newGroupName'): groupEntity.set(libuser.GROUPNAME, groupInfo['newGroupName']) return dbus.Int32(self.__libuser.modifyGroup(groupEntity))
def AddUser(self, user_info, sender, connection): """Add User. @param group_info: A dbus.Dictionary with user information with the following content: * fullname: * username: * shell: * uid: * gid: * home_directory: * password: Example: user_info = { 'fullName': 'John Doe', 'userName': '******', 'loginShell': '/bin/bash', 'uid': 666, 'gid': 666, 'homeDirectory': '/home/john', 'password': '******', 'createHome': True } @raise dbus.DBusException: @return dbus.Int64: The UID from recently created User. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.adduser') user_entity = self.__libuser.initUser(user_info['userName']) # libuser won't respect that always the fullname will be set by username # if a fullname was not set. if user_info.has_key('fullName'): user_entity.set(libuser.GECOS, [user_info['fullName']]) if user_info.has_key('gid'): user_entity.set(libuser.GIDNUMBER, [user_info['gid']]) user_entity.set(libuser.UIDNUMBER, [user_info['uid']]) user_entity.set(libuser.HOMEDIRECTORY, [user_info['homeDirectory']]) user_entity.set(libuser.LOGINSHELL, [user_info['loginShell']]) try: self.__libuser.addUser( user_entity, mkhomedir = user_info['createHome']) except RuntimeError, error: msg = 'org.mandrivalinux.mcc2.Users.Error.AddUserFailed' # FIXME: What's the others libuser errors? if str(error) == 'entry already present in file': msg = 'org.mandrivalinux.mcc2.Users.Error.UserAlreadyExist' raise dbus.DBusException, msg
def AddUser(self, user_info, sender, connection): """Add User. @param group_info: A dbus.Dictionary with user information with the following content: * fullname: * username: * shell: * uid: * gid: * home_directory: * password: Example: user_info = { 'fullName': 'John Doe', 'userName': '******', 'loginShell': '/bin/bash', 'uid': 666, 'gid': 666, 'homeDirectory': '/home/john', 'password': '******', 'createHome': True } @raise dbus.DBusException: @return dbus.Int64: The UID from recently created User. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.adduser') user_entity = self.__libuser.initUser(user_info['userName']) # libuser won't respect that always the fullname will be set by username # if a fullname was not set. if user_info.has_key('fullName'): user_entity.set(libuser.GECOS, [user_info['fullName']]) if user_info.has_key('gid'): user_entity.set(libuser.GIDNUMBER, [user_info['gid']]) user_entity.set(libuser.UIDNUMBER, [user_info['uid']]) user_entity.set(libuser.HOMEDIRECTORY, [user_info['homeDirectory']]) user_entity.set(libuser.LOGINSHELL, [user_info['loginShell']]) try: self.__libuser.addUser(user_entity, mkhomedir=user_info['createHome']) except RuntimeError, error: msg = 'org.mandrivalinux.mcc2.Users.Error.AddUserFailed' # FIXME: What's the others libuser errors? if str(error) == 'entry already present in file': msg = 'org.mandrivalinux.mcc2.Users.Error.UserAlreadyExist' raise dbus.DBusException, msg
def UnLockUser(self, username, sender, connection): """ Unlock user @param username: A dbus.String with user name as it value. @raise dbus.DBusException: @rtype dbus.Int32: 1 ok or 0 fail. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.unlockuser') user_entity = self.__libuser.lookupUserByName(username) return dbus.Int32(self.__libuser.unlockUser(user_entity))
def UnLockGroup(self, groupname, sender, connection): """ Unlock group @param groupname: A dbus.String with group name as it value. @raise dbus.DBusException: @rtype dbus.Int32: 1 ok or 0 fail. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.unlockgroup') group_entity = self.__libuser.lookupGroupByName(groupname) return dbus.Int32(self.__libuser.unlockGroup(group_entity))
def Stop(self, name, mode, sender, connection): """Stop unit. @param name: Unit name (ie: network.service). @param mode: Must be one of "fail" or "replace". @raise dbus.DBusException: @rtype dbus.Interface: Job path. """ if not self.is_systemd_running: raise dbus.DBusException, self.msg['not_running'] checkAuthorization(sender, connection, self.__action) return self.__systemd_interface.StopUnit(name, mode)
def DeleteUser(self, username, sender, connection): """Delete an User. @param username: User name. @raise dbus.DBusException: @rtype: dbus.Dictionary: Recent removed user id and groupname. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.deleteuser') user_entity = self.__libuser.lookupUserByName(username) uid = user_entity.get(libuser.UIDNUMBER)[0] name = user_entity.get(libuser.USERNAME)[0] #user_entity = self.__libuser.initUser(username) try: self.__libuser.deleteUser(user_entity) except RuntimeError, error: msg = 'org.mandrivalinux.mcc2.Users.Error.DeleteUserFailed' raise dbus.DBusException, msg
def DeleteGroup(self, groupname, sender, connection): """Delete a Group. @param groupname: Group name. @raise dbus.DBusException: @rtype: dbus.Dictionary: Recent removed group id and groupname. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.deletegroup') group_entity = self.__libuser.lookupGroupByName(groupname) gid = group_entity.get(libuser.GIDNUMBER)[0] name = group_entity.get(libuser.GROUPNAME)[0] init_group = self.__libuser.initGroup(groupname) try: self.__libuser.deleteGroup(init_group) except RuntimeError, error: msg = 'org.mandrivalinux.mcc2.Users.Error.DeleteGroupFailed' raise dbus.DBusException, msg
def ModifyUser(self, user_info, sender, connection): """Modify User. @param user_info: A dbus.Dictionary with user information with the following content: * fullname: User full name * username: Yes, you guess! * shell: Shell to use, you can get a list of available shells using ListUserShells. All shadow_* dictionaty keys is optional and only be used if present. Example: user_info = { 'oldUserName': '******' 'newUserName': '******', 'fullName': 'Johns Does', 'loginShell': '/bin/bash', 'uid': 666, 'gid': 666, 'homeDirectory': '/home/john', 'password': '******', 'shadowExpire': '15071', # in days 'shadowMin': 0, 'shadowMax', 99999, 'shadowWarning': 7, 'shadowInactive': -1, 'shadowLastChange': '15071' # in days } @raise dbus.DBusException: * org.mandrivalinux.mcc2.Users.Error.InvalidDate: * org.mandrivalinux.mcc2.Users.Error.YearIsTooBig: @rtype dbus.Int32: 1 ok or 0 fail. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.modifyuser') user_entity = self.__libuser.lookupUserByName(user_info['oldUserName']) if user_info.has_key('fullName'): user_entity.set(libuser.GECOS, [user_info['fullName']]) #TODO: Check if gid can be converted to int() # if not raise an error if user_info.has_key('gid'): user_entity.set(libuser.GIDNUMBER, [user_info['gid']]) # Change UID is not permited #user_entity.set(libuser.UIDNUMBER, [user_info['uid']]) if user_info.has_key('homeDirectory'): user_entity.set(libuser.HOMEDIRECTORY, [user_info['homeDirectory']]) if user_info.has_key('loginShell'): user_entity.set(libuser.LOGINSHELL, [user_info['loginShell']]) if user_info.has_key('newUserName'): user_entity.set(libuser.USERNAME, [user_info['newUserName']]) if user_info.has_key('shadowExpire'): user_entity.set(libuser.SHADOWEXPIRE, [user_info['shadowExpire']]) if user_info.has_key('shadowMin'): user_entity.set(libuser.SHADOWMIN, int(user_info['shadowMin'])) if user_info.has_key('shadowMax'): user_entity.set(libuser.SHADOWMAX, int(user_info['shadowMax'])) if user_info.has_key('shadowWarning'): user_entity.set( libuser.SHADOWWARNING, int(user_info['shadowWarning'])) if user_info.has_key('shadowInactive'): user_entity.set( libuser.SHADOWINACTIVE, int(user_info['shadowInactive'])) #if user_info.has_key('shadow_last_change'): # user_entity.set( # libuser.SHADOWLASTCHANGE, # int(user_info['shadow_last_change'])) if user_info.has_key('password'): self.__libuser.setpassUser(user_entity, user_info['password'], 0) return self.__libuser.modifyUser(user_entity)
def ModifyUser(self, user_info, sender, connection): """Modify User. @param user_info: A dbus.Dictionary with user information with the following content: * fullname: User full name * username: Yes, you guess! * shell: Shell to use, you can get a list of available shells using ListUserShells. All shadow_* dictionaty keys is optional and only be used if present. Example: user_info = { 'oldUserName': '******' 'newUserName': '******', 'fullName': 'Johns Does', 'loginShell': '/bin/bash', 'uid': 666, 'gid': 666, 'homeDirectory': '/home/john', 'password': '******', 'shadowExpire': '15071', # in days 'shadowMin': 0, 'shadowMax', 99999, 'shadowWarning': 7, 'shadowInactive': -1, 'shadowLastChange': '15071' # in days } @raise dbus.DBusException: * org.mandrivalinux.mcc2.Users.Error.InvalidDate: * org.mandrivalinux.mcc2.Users.Error.YearIsTooBig: @rtype dbus.Int32: 1 ok or 0 fail. """ checkAuthorization(sender, connection, self.__action) #checkAuthorization(sender, connection, # 'org.mandrivalinux.mcc2.users.modifyuser') user_entity = self.__libuser.lookupUserByName(user_info['oldUserName']) if user_info.has_key('fullName'): user_entity.set(libuser.GECOS, [user_info['fullName']]) #TODO: Check if gid can be converted to int() # if not raise an error if user_info.has_key('gid'): user_entity.set(libuser.GIDNUMBER, [user_info['gid']]) # Change UID is not permited #user_entity.set(libuser.UIDNUMBER, [user_info['uid']]) if user_info.has_key('homeDirectory'): user_entity.set(libuser.HOMEDIRECTORY, [user_info['homeDirectory']]) if user_info.has_key('loginShell'): user_entity.set(libuser.LOGINSHELL, [user_info['loginShell']]) if user_info.has_key('newUserName'): user_entity.set(libuser.USERNAME, [user_info['newUserName']]) if user_info.has_key('shadowExpire'): user_entity.set(libuser.SHADOWEXPIRE, [user_info['shadowExpire']]) if user_info.has_key('shadowMin'): user_entity.set(libuser.SHADOWMIN, int(user_info['shadowMin'])) if user_info.has_key('shadowMax'): user_entity.set(libuser.SHADOWMAX, int(user_info['shadowMax'])) if user_info.has_key('shadowWarning'): user_entity.set(libuser.SHADOWWARNING, int(user_info['shadowWarning'])) if user_info.has_key('shadowInactive'): user_entity.set(libuser.SHADOWINACTIVE, int(user_info['shadowInactive'])) #if user_info.has_key('shadow_last_change'): # user_entity.set( # libuser.SHADOWLASTCHANGE, # int(user_info['shadow_last_change'])) if user_info.has_key('password'): self.__libuser.setpassUser(user_entity, user_info['password'], 0) result = self.__libuser.modifyUser(user_entity) for group in self.__libuser.enumerateGroups(): members = self.__libuser.enumerateUsersByGroup(group) groupEntity = self.__libuser.lookupGroupByName(group) username = user_entity.get(libuser.USERNAME)[0] if group in user_info['groups']: if username not in members: members.append(username) groupEntity.set(libuser.MEMBERNAME, members) self.__libuser.modifyGroup(groupEntity) else: if username in members: members.remove(username) groupEntity.set(libuser.MEMBERNAME, members) self.__libuser.modifyGroup(groupEntity) shutil.copy2( user_info['userPhoto'], '/usr/share/faces/%s.png' % user_entity.get(libuser.USERNAME)[0]) return result