rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
ScenarioTest(commands, context=context, descr="get tests").Run()
ScenarioTest(commands, context=context, descr='''CLI get tests''').Run()
def test_get(context): """Test GET a lot.""" commands = [] for category in [ 'config_dir', 'main_config_file', 'extendedgroup_data_file' ]: for mode in [ '', '-s', '-b', '--bourne-shell', '-c', '--c-shell', '-p', '--php-code' ]: commands.append(GET + [ 'configuration', category, mode ]) for category in [ 'skels', 's...
def clean_system(): """ Remove all stuff to make the system clean, testsuite-wise.""" test_message('''cleaning system from previous runs.''') for argument in ( ['user', '''toto,tutu,tata,titi,test,utilisager.normal,''' \ '''test.responsibilly,utilicateur.accentue,user_test,''' \ '''grp-acl-user,utest_267,user_test...
def clean_system(): """ Remove all stuff to make the system clean, testsuite-wise.""" test_message('''cleaning system from previous runs.''') # delete them first in case of a previous failed testsuite run. # don't check exit codes or such, this will be done later. for argument in ( ['user', '''toto,tutu,tata,titi,te...
descr='ADD group with specified skel and descr',
descr='''ADD group with specified skel and descr''',
def chk_acls_cmds(group, subdir=None): return [ 'getfacl', '-R', '%s/%s/%s%s' % ( configuration.defaults.home_base_path, configuration.groups.names.plural, group, '/%s' % subdir if subdir else '') ]
descr='tests of groups commands with --gid option (fix
descr='''tests of groups commands with --gid option (fix
def chk_acls_cmds(group, subdir=None): return [ 'getfacl', '-R', '%s/%s/%s%s' % ( configuration.defaults.home_base_path, configuration.groups.names.plural, group, '/%s' % subdir if subdir else '') ]
descr='''check if a user can be modified with an incorrect shell and with a correct shell'''
descr='''check if a user can be modified with an incorrect shell and ''' '''with a correct shell'''
def chk_acls_cmds(dir): return [ 'getfacl', '-R', dir ]
descr='test add user with --firstname and --lastname options (fix
descr='''test add user with --firstname and --lastname options ''' '''(fix
def chk_acls_cmds(dir): return [ 'getfacl', '-R', dir ]
descr='modify one or more parameters of a user (avoid
descr='''modify one or more parameters of a user (avoid
def chk_acls_cmds(dir): return [ 'getfacl', '-R', dir ]
descr='check option --home of user command (fix
descr='''check option --home of user command (fix
def chk_acls_cmds(dir): return [ 'getfacl', '-R', dir ]
descr='''check messages of --lock and --unlock on mod user command and answer of get user --long (avoid
descr='''check messages of --lock and --unlock on mod user command ''' '''and answer of get user --long (avoid
def chk_acls_cmds(dir): return [ 'getfacl', '-R', dir ]
descr='''Add a profil and check if it has been affected to a new user (avoid
descr='''Add a profil and check if it has been affected to a new ''' '''user (avoid
def chk_acls_cmds(dir): return [ 'getfacl', '-R', dir ]
descr='check add user with --firstname and --lastname (avoid
descr='''check add user with --firstname and --lastname (avoid '''
def chk_acls_cmds(dir): return [ 'getfacl', '-R', dir ]
descr='''(avoid
descr='''avoid
def chk_acls_cmds(dir): return [ 'getfacl', '-R', dir ]
descr='check if a error occurs when a non-existing group is added to a profile'
descr='''check if a error occurs when a non-existing group is added ''' '''to a profile'''
def chk_acls_cmd(user): return [ 'getfacl', '-R', '%s/%s' % ( configuration.users.base_path, user) ]
descr='test short users/groups commands'
descr='''test short users/groups commands'''
def test_short_syntax(): uname = 'user_test' gname = 'group_test' pname = 'profil_test' ScenarioTest([ ADD + [ 'user', uname, '-v' ], GET + [ 'user', uname ], ADD + [ 'group', gname, '-v' ], GET + [ 'group', gname ], ADD + [ 'user', uname, gname, '-v' ], GET + [ 'user', uname, '-l' ], ADD + [ 'group', '%s2' % gname, '...
descr='test short privileges commands'
descr='''test short privileges commands'''
def test_short_syntax(): uname = 'user_test' gname = 'group_test' pname = 'profil_test' ScenarioTest([ ADD + [ 'user', uname, '-v' ], GET + [ 'user', uname ], ADD + [ 'group', gname, '-v' ], GET + [ 'group', gname ], ADD + [ 'user', uname, gname, '-v' ], GET + [ 'user', uname, '-l' ], ADD + [ 'group', '%s2' % gname, '...
descr='test short profiles commands'
descr='''test short profiles commands'''
def test_short_syntax(): uname = 'user_test' gname = 'group_test' pname = 'profil_test' ScenarioTest([ ADD + [ 'user', uname, '-v' ], GET + [ 'user', uname ], ADD + [ 'group', gname, '-v' ], GET + [ 'group', gname ], ADD + [ 'user', uname, gname, '-v' ], GET + [ 'user', uname, '-l' ], ADD + [ 'group', '%s2' % gname, '...
descr='test short chk commands'
descr='''test short chk commands'''
def test_short_syntax(): uname = 'user_test' gname = 'group_test' pname = 'profil_test' ScenarioTest([ ADD + [ 'user', uname, '-v' ], GET + [ 'user', uname ], ADD + [ 'group', gname, '-v' ], GET + [ 'group', gname ], ADD + [ 'user', uname, gname, '-v' ], GET + [ 'user', uname, '-l' ], ADD + [ 'group', '%s2' % gname, '...
if entry[2] == "": users[uid]['shadowLastChange'] = 0 else: users[uid]['shadowLastChange'] = int(entry[2]) if entry[3] == "": users[uid]['shadowInactive'] = 99999 else: users[uid]['shadowInactive'] = int(entry[3]) if entry[4] == "": users[uid]['shadowWarning'] = entry[4] else: users[uid]['shadowWarning'] = int(en...
users[uid]['shadowLastChange'] = int(entry[2]) \ if entry[2] != '' else 0 users[uid]['shadowMin'] = int(entry[3]) \ if entry[3] != '' else 0 users[uid]['shadowMax'] = int(entry[4]) \ if entry[4] != '' else 99999 users[uid]['shadowWarning'] = int(entry[5]) \ if entry[5] != '' else 7 users[uid]['shadowInactive'] = ...
def load_users(self, groups = None): """ Load user accounts from /etc/{passwd,shadow} """ users = {} login_cache = {}
str(users[uid]['shadowWarning']),
def save_users(self): """ Write /etc/passwd and /etc/shadow """
"","",""
str(users[uid]['shadowFlag'])
def save_users(self): """ Write /etc/passwd and /etc/shadow """
['profile', '--group=utilisagers', '--del-users', '--no-archive'], ['profile', '--group=responsibilisateurs', '--del-users', '--no-archive'], ['profile', '--group=profil_test', '--del-users',
['profile', '''--group=utilisagers,responsibilisateurs,''' '''profil_test''', '--del-users',
def clean_system(): """ Remove all stuff to make the system clean, testsuite-wise.""" test_message('''cleaning system from previous runs.''') # delete them first in case of a previous failed testsuite run. # don't check exit codes or such, this will be done later. for argument in ( ['user', '''toto,tutu,tata,titi,te...
\ '''GRP-ACL-test,gtest_267,group_testsys'''], ['privilege', '--name=group_test' ], ):
'''group_test3,GRP-ACL-test,gtest_267,group_testsys''' ], ['privilege', '--name=group_test' ] ):
def clean_system(): """ Remove all stuff to make the system clean, testsuite-wise.""" test_message('''cleaning system from previous runs.''') # delete them first in case of a previous failed testsuite run. # don't check exit codes or such, this will be done later. for argument in ( ['user', '''toto,tutu,tata,titi,te...
DEL + [ 'group', gname ],
DEL + [ 'group', gname ]
def chk_acls_cmds(group, subdir=None): return [ 'sudo', 'getfacl', '-R', '%s/%s/%s%s' % ( configuration.defaults.home_base_path, configuration.groups.names['plural'], group, '/%s' % subdir if subdir else '') ]
GET + [ 'privileges' ], ], context=context, descr='Check if privilege list is up to date after group deletion (fix
GET + [ 'privileges' ] ], context=context, descr='''Check if privilege list is up to date after group deletion''' ''' (fix
def chk_acls_cmds(group, subdir=None): return [ 'sudo', 'getfacl', '-R', '%s/%s/%s%s' % ( configuration.defaults.home_base_path, configuration.groups.names['plural'], group, '/%s' % subdir if subdir else '') ]
GET + [ 'groups' ],
GET + [ 'groups' ]
def chk_acls_cmds(group, subdir=None): return [ 'sudo', 'getfacl', '-R', '%s/%s/%s%s' % ( configuration.defaults.home_base_path, configuration.groups.names['plural'], group, '/%s' % subdir if subdir else '') ]
pname = 'profil_test'
def chk_acls_cmds(dir): return [ 'sudo', 'getfacl', '-R', dir ]
AddUsersInGroup('users', [ u ])
AddUsersInGroup('users', [ u ], batch = True)
def AddUsersInGroup(self, name, users_to_add, batch = False): """ Add a user list in the group 'name'. """
<li><a href="http://dev.licorn.org/wiki/UserDoc/WMI" title="%s">%s</a></li> <li%s><a href="mailto:support@meta-it.fr?subject=[support] " title="%s">%s</a></li>
<li><a href="http://docs.licorn.org/userdoc.html" title="%s">%s</a></li> <li%s><a href="mailto:support@meta-it.fr?subject=[Support Licorn®] " title="%s">%s</a></li>
def __getitem__(self, key): try: return dict.__getitem__(self, key) except KeyError: return self.default
_('Go to online documentation and community website (in new window or new tab).'), _('Documentation'),
_('Go to online documentation website.'), _('Documentation'),
def __getitem__(self, key): try: return dict.__getitem__(self, key) except KeyError: return self.default
from licorn.system import keywords kw = keywords.KeywordsController(configuration) kw.DeleteKeyword(opts.name, opts.del_children)
from licorn.core import keywords keywords.DeleteKeyword(opts.name, opts.del_children)
def delete_keyword(): """ delete a system wide User profile. """ from licorn.system import keywords kw = keywords.KeywordsController(configuration) kw.DeleteKeyword(opts.name, opts.del_children)
getpass.getpass(_('Please enter your LDAP password: ')),
getpass.getpass('Please enter your LDAP password: '),
def bind(self, need_write_access=True): """ Bind as admin or user, when LDAP needs a stronger authentication.""" ltrace('ldap','binding as %s.' % ( styles.stylize(styles.ST_LOGIN, self.bind_dn)))
os.path.dirname(__file__),input_name), 'r'))
'/usr/share/licorn', input_name), 'r'))
def __init__(self, input_name): LDIFParser.__init__(self, open('%s/schemas/%s.ldif' % ( os.path.dirname(__file__),input_name), 'r'))
logging.progress('%s: saving data structures to disk.' % \ self.pretty_name) lock_file = file_locks.FileLock(self.configuration, self.configuration.keywords_data_file) lock_file.Lock() open(self.configuration.keywords_data_file , "w").write(self.__build_cli_output()) lock_file.Unlock()
if self.changed : logging.progress('%s: saving data structures to disk.' % \ self.pretty_name) lock_file = file_locks.FileLock(self.configuration, self.configuration.keywords_data_file) lock_file.Lock() open(self.configuration.keywords_data_file , "w").write(self.__build_cli_output()) lock_file.Unlock() logging.prog...
def WriteConf(self): """ Write the keywords data in appropriate system files.""" logging.progress('%s: saving data structures to disk.' % \ self.pretty_name)
from licorn import system as hzsys
def AddKeyword(self, name = None, parent = "", description = ""): """ Add a new keyword on the system, provided some checks are OK. """ if name is None: raise exceptions.BadArgumentError(logging.SYSK_SPECIFY_KEYWORD)
"""
""" Delete a keyword
def DeleteKeyword(self, name=None, del_children=False, modify_file=True): """ """ if name is None: raise exceptions.BadArgumentError(logging.SYSK_SPECIFY_KEYWORD)
self.WriteConf()
self.changed = True
def DeleteKeyword(self, name=None, del_children=False, modify_file=True): """ """ if name is None: raise exceptions.BadArgumentError(logging.SYSK_SPECIFY_KEYWORD)
self.WriteConf()
self.changed = True
def ChangeParent(self, name, parent): """ Change keyword's parent """ try: self.keywords[parent] self.keywords[name]["parent"] = parent except KeyError, e: raise exceptions.BadArgumentError("The keyword %s doesn't exist on this system." % str(e)) self.WriteConf()
self.WriteConf()
self.changed = True
def RemoveParent(self, name): """ Remove parent of the keyword 'name' """ try: self.keywords[name]["parent"] = "" except KeyError, e: raise exceptions.BadArgumentError("The keyword you specified doesn't exist on this system.") self.WriteConf()
self.WriteConf()
self.changed = True
def ChangeDescription(self, name, description): """ Change the description of a keyword """ try: self.keywords[name]["description"] = description except KeyError, e: raise exceptions.BadArgumentError("The keyword you specified doesn't exist on this system.") self.WriteConf()
if opts.groups_to_del: something_done = True for g in opts.groups_to_del.split(','): if g != '': try: LMC.groups.DeleteUsersFromGroup(name=g, users_to_del=[ uid ]) except exceptions.LicornRuntimeException, e: logging.warning('''Unable to remove user %s from ''' '''group %s (was: %s).''' % ( stylize(ST_LOGIN, opts.login...
def mod_user(self, opts, args): """ Modify a POSIX user account (Samba / LDAP included). """
users.Select(filters.STANDARD) dest = group['memberUid'] source = [ u[uid]['login'] for uid in users.filtered_users ] for current in group['memberUid']:
dest = groups[groups.name_to_gid(gname)]['memberUid'][:] source = [ u[uid]['login'] \ for uid in users.Select(filters.STANDARD) ] for current in dest[:]:
def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name if protected_group(name, complete=False): return w.forgery_error(title) data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[gro...
def refork_as_root_or_die(process_title='licorn-generic', prefunc=None):
def refork_as_root_or_die(process_title='licorn-generic', prefunc=None, group='admins'):
def refork_as_root_or_die(process_title='licorn-generic', prefunc=None): """ check if current user is root. if not, check if he/she is member of group "admins" and then refork ourselves with sudo, to gain root privileges, needed for Licorn® daemon. Do it with traditionnal syscalls, because the rest of Licorn® is not in...
group = 'admins' if pwd.getpwuid(os.getuid()).pw_name in grp.getgrnam(group).gr_mem:
try: gmembers = grp.getgrnam(group).gr_mem except KeyError: logging.error('''group %s doesn't exist and we are not root, ''' '''aborting. Please manually relaunch this program with root ''' '''privileges for the group to be created.''' % group) if pwd.getpwuid(os.getuid()).pw_name in gmembers:
def refork_as_root_or_die(process_title='licorn-generic', prefunc=None): """ check if current user is root. if not, check if he/she is member of group "admins" and then refork ourselves with sudo, to gain root privileges, needed for Licorn® daemon. Do it with traditionnal syscalls, because the rest of Licorn® is not in...
self.users.users[uid]['groups'].sort()
LMC.users[uid]['groups'].sort()
def AddUsersInGroup(self, name=None, gid=None, users_to_add=None, batch=False, listener=None): """ Add a user list in the group 'name'. """
description = 'Les membres du groupe "%s"' % name
description = 'Les membres du groupe “%s”' % name
def AddGroup(self, name, gid=None, description="", skel="", system=False, permissive=False, batch=False): """ Add an Licorn group (the group + the responsible group + the shared dir + permissions). """
raise exceptions.BadArgumentError("Malformed group name `%s', must match /%s/i."
raise exceptions.BadArgumentError("Malformed group name '%s', must match /%s/i."
def AddGroup(self, name, gid=None, description="", skel="", system=False, permissive=False, batch=False): """ Add an Licorn group (the group + the responsible group + the shared dir + permissions). """
('gecos', str),
('gecos', decodestring),
def account_lock(value, tmp_entry=temp_user_dict): try: # get around an error where password is not base64 encoded. password = decodestring(value.split('}',1)[1]) except Exception: password = value
user['cn'] = login
def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """
data = '%s\n%s\n%s' % (w.backto(), __groups_actions(), w.menu(uri))
data = w.page_body_start(uri, http_user, ctxtnav, title, False)
def unlock(uri, http_user, name, sure = False): """ Make a shared group dir permissive. """ title = _("Make group %s permissive") % name data = '%s\n%s\n%s' % (w.backto(), __groups_actions(), w.menu(uri)) if not sure: description = _('''This will permit large access to files and folders in the group shared dir, and ...
data = '%s\n%s\n%s\n' % (w.backto(), __groups_actions(), w.menu(uri))
data = w.page_body_start(uri, http_user, ctxtnav, title, False)
def lock(uri, http_user, name, sure = False): """ Make a group not permissive. """ title = _("Make group %s not permissive") % name data = '%s\n%s\n%s\n' % (w.backto(), __groups_actions(), w.menu(uri)) if not sure: description = _('''This will ensure finer write access to files and folders in the group shared dir. O...
data = '%s\n%s\n%s\n' % (w.backto(), __groups_actions(), w.menu(uri))
data = w.page_body_start(uri, http_user, ctxtnav, title, False)
def delete(uri, http_user, name, sure = False, no_archive = False, yes = None): """ Remove group and archive (or not) group shared dir. """ del yes title = _("Remove group %s") % name data = '%s\n%s\n%s\n' % (w.backto(), __groups_actions(), w.menu(uri)) groups.reload() if groups.is_system_group(name): return w.pag...
data = '%s%s' % (w.backto(), __groups_actions(title))
data = w.page_body_start(uri, http_user, ctxtnav, title, False)
def skel(req, name, sure = False, apply_skel = configuration.users.default_skel): """ TO BE IMPLEMENTED ! reapply a user's skel with confirmation.""" users.reload() profiles.reload() groups.reload() title = _("Skeleton reapplying for group %s") % name data = '%s%s' % (w.backto(), __groups_actions(title)) if not sur...
ltrace('configuration', 'CleanUp().') if os.path.exists(self.tmp_dir):
ltrace('configuration', '> CleanUp()') try:
def CleanUp(self): """This is a sort of destructor. Clean-up before being deleted..."""
if uid > self.configuration.users.system_uid_min \ and uid < self.configuration.users.system_uid_max:
if uid >= self.configuration.users.system_uid_min \ and uid <= self.configuration.users.system_uid_max:
def check_uid(uid, minimal=minimal, batch=batch, auto_answer=auto_answer):
users.LockAccount(uid, opts.lock)
users.LockAccount(uid=uid, lock=opts.lock)
def mod_user(opts, args): """ Modify a POSIX user account (Samba / LDAP included). """ configuration = LicornConfiguration() users = UsersController(configuration) uids_to_mod = cli_select(users, 'user', args, [ (opts.login, users.login_to_uid), (opts.uid, users.confirm_uid) ]) ltrace('mod', '> mod_user(%s)' % uids_...
)
).Run()
def chk_acls_cmds(group, subdir=None): return [ 'sudo', 'getfacl', '-R', '%s/%s/%s%s' % ( configuration.defaults.home_base_path, configuration.groups.names['plural'], group, '/%s' % subdir if subdir else '') ]
self.configuration.groups.names['plural'])):
self.configuration.groups.names['plural'])) \ or home.find('/tmp') != -1:
def validate_home_dir(home=home, login=login, system=system, force=force): """ Do some basic but sane tests on the home dir provided. """
'''and a temporary directory (/var/tmp, /tmp). '''
def validate_home_dir(home=home, login=login, system=system, force=force): """ Do some basic but sane tests on the home dir provided. """
make_path = lambda x: ('_'.join(x)).replace('../', '').replace('//','_').replace('/','_')
make_path = lambda x: ('_'.join(x)).replace('__', '_').replace( './', '').replace('../', '').replace('//','_').replace( '/','_').replace('>','').replace('&', '')
def Prepare(self, cmd): """ Run commands mandatory for func_test to succeed. """
logging.warning('command "%s" failed (retcode %d instead of %d).\nPath: %s' % ( cmdfmt(cmd), retcode, ref_code, self.ref_code_file))
logging.warning( '''command "%s" failed (retcode %d instead of %d).\n''' '''(Reference path: %s)''' % ( styles.stylize(styles.ST_NAME, cmdfmt(cmd)), styles.stylize(styles.ST_BAD,retcode), styles.stylize(styles.ST_OK, ref_code), self.ref_code_file))
def RunAndCheck(self, cmd, batch = False, inverse_test=False): ref_output, ref_code = self.PrepareReferenceOutput(cmd)
gid = manual_gid
if (system and GroupsController.is_system_gid(manual_gid)) \ or (not system and GroupsController.is_standard_gid( manual_gid)): gid = manual_gid else: raise exceptions.BadArgumentError('''GID out of range ''' '''for the kind of group you specified. System GID ''' '''must be between %d and %d, standard GID must be ''' '...
def __add_group(self, name, system, manual_gid=None, description = "", groupSkel = "", batch=False, force=False): """ Add a POSIX group, write the system data files. Return the gid of the group created."""
return (w.HTTP_TYPE_TEXT, w.page(title, w.error(_("Forbidden action"),
return (HTTP_TYPE_TEXT, page(title, error(_("Forbidden action"),
def forgery_error(title): return (w.HTTP_TYPE_TEXT, w.page(title, w.error(_("Forbidden action"), [ _("Some parts of the system cannot be modified.") ], _("insufficient permissions to perform operation."))))
title = _("Showing details of group %s") % name data = '%s\n%s\n%s\n' % (w.backto(), __groups_actions(), w.menu(uri))
title = _("Details of group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title)
def view(uri, http_user, name): """Prepare a group view to be printed.""" users.reload() groups.reload() title = _("Showing details of group %s") % name data = '%s\n%s\n%s\n' % (w.backto(), __groups_actions(), w.menu(uri)) u = users.users g = groups.groups # TODO: should we forbid system group view ? why not ? # A...
members.sort() members_html = ''' <h2>%s</h2><div style="text-align:center;">%s</div> <table class="group_members"> <tr> <td><strong>%s</strong></td> <th><strong>%s</strong></th> <th><strong>%s</strong></th> </tr> ''' % (_('Members'), _('(ordered by login)'), _('Full Name'), _('Identifier'), _('UID')) def user_line(lo...
if members != []: members.sort() members_html = ''' <h2>%s</h2> <div style="text-align:left;">%s</div> <table class="group_members"> <tr> <th><strong>%s</strong></th> <th><strong>%s</strong></th> <th><strong>%s</strong></th> </tr> ''' % ( _('Members'), _('(ordered by login)'), _('Full Name'), _('Identifier'), _('UID')...
def view(uri, http_user, name): """Prepare a group view to be printed.""" users.reload() groups.reload() title = _("Showing details of group %s") % name data = '%s\n%s\n%s\n' % (w.backto(), __groups_actions(), w.menu(uri)) u = users.users g = groups.groups # TODO: should we forbid system group view ? why not ? # A...
resps = groups.all_members(configuration.groups.resp_prefix + name) resps.sort() guests = \ groups.all_members(configuration.groups.guest_prefix + name) guests.sort()
resps = groups.all_members(configuration.groups.resp_prefix + name)
def user_line(login): uid = users.login_to_uid(login) return '''<tr><td>%s</td><td>%s</td><td>%s</td></tr>''' % ( u[uid]['gecos'], login, uid)
<h2>%s</h2><div style="text-align:center;">%s</div>
<h2>%s</h2> <div style="text-align:left;">%s</div>
def user_line(login): uid = users.login_to_uid(login) return '''<tr><td>%s</td><td>%s</td><td>%s</td></tr>''' % ( u[uid]['gecos'], login, uid)
''' % (_('Guests'), _('(ordered by login)'), _('Full Name'), _('Identifier'), _('UID'), "\n".join(map(user_line, guests))) else: guests_html = "<h2>%s</h2>" % _('No guests for this group.')
''' % ( _('Guests'), _('(ordered by login)'), _('Full Name'), _('Identifier'), _('UID'), "\n".join(map(user_line, guests)) ) else: guests_html = "<h2>%s</h2>" % _('No guests in this group.')
def user_line(login): uid = users.login_to_uid(login) return '''<tr><td>%s</td><td>%s</td><td>%s</td></tr>''' % ( u[uid]['gecos'], login, uid)
<div id="content">
<div id="details">
def user_line(login): uid = users.login_to_uid(login) return '''<tr><td>%s</td><td>%s</td><td>%s</td></tr>''' % ( u[uid]['gecos'], login, uid)
if not UsersController.is_system_uid(uid):
if UsersController.is_system_uid(uid): logging.progress("Checking system account %s..." % \ styles.stylize(styles.ST_NAME, user)) if os.path.exists(self.users[uid]['homeDirectory']): home_dir_info = [ { 'path' : self.users[uid]['homeDirectory'], 'user' : user, 'group' : self.groups.groups[ self.use...
def check_user(user, minimal = minimal, batch = batch, auto_answer = auto_answer):
print dir(self.backends)
def SetMissingMandatoryDefauts(self): """ The defaults set here are expected to exist by other parts of the programs. """
raise exceptions.LicornRuntimeError("Filesystem must be mounted with `acl' option:\n\t%s" % e)
raise exceptions.LicornRuntimeError("Filesystem must be mounted with 'acl' option:\n\t%s" % e)
def CheckBaseDirs(self, minimal = True, batch = False, auto_answer = None) : """Check and eventually repair default needed dirs."""
dirs_to_verify = [ { 'path' : self.home_backup_dir, 'user' : 'root', 'group' : 'acl', 'access_acl' : "%s,%s,%s" % (acl_base, acl_admins_ro, acl_mask), 'default_acl' : "%s,%s,%s" % (acl_base, acl_admins_ro, acl_mask), 'content_acl' : ("%s,%s,%s" % (acl_base, acl_admins_ro, a...
home_backup_dir_info['content_acl'] = ("%s,%s,%s" % (acl_base, acl_admins_ro, acl_mask) ).replace('r-x', 'r--').replace('rwx', 'rw-') home_archive_dir_info['content_acl'] = ("%s,%s,%s" % (acl_base, acl_admins_rw, acl_mask) ).replace('r-x', 'r--').replace('rwx', 'rw-') dirs_to_verify = [ home_backup_dir_info, home_arch...
def CheckBaseDirs(self, minimal = True, batch = False, auto_answer = None) : """Check and eventually repair default needed dirs."""
_("Definitely remove account from the LMC.system."))
_("Definitely remove account from the system."))
def html_build_compact(index, accounts = accounts): uid = ordered[index] login = u[uid]['login'] edit = (_('''<em>Click to edit current user account parameters:</em> <br /> UID: <strong>%d</strong><br /> GID: %d (primary group <strong>%s</strong>)<br /><br /> Groups:&#160;<strong>%s</strong><br /><br /> Privileges:&...
'(objectClass=o)')
'(objectClass=organization)')
def last_init_check(self): """ do a quick LDAP content check, to validate everything is valid. """
if login in groups.all_members('remotessh'): description += _("""<br /><br /> But this will not block incoming %s network connections, if the user uses %s %s or %s public/private keys. To block ANY access to the system, <strong>remove him/her from remotessh group</strong>.""") % (w.acr('SSH'), w.acr('SSH'), w.acr('RSA'...
if configuration.ssh.enabled : if login in groups.all_members(configuration.ssh.group): description += _("""<br /><br /> But this will not block incoming %s network connections, if the user uses %s %s or %s public/private keys. To block ANY access to the system, <strong>remove him/her from %s group</strong>.""") % (w.a...
def lock(uri, http_user, login, sure = False, remove_remotessh = False, yes = None): """lock a user account password.""" # forget about it, this is a scoria from the POST FORM to variable conversion. del yes groups.reload() users.reload() title = _("Lock account %s") % login data = w.page_body_start(uri, http_user,...
if remove_remotessh: command.extend(['--del-groups', 'remotessh'])
if configuration.ssh.enabled and remove_remotessh: command.extend(['--del-groups', configuration.ssh.group])
def lock(uri, http_user, login, sure = False, remove_remotessh = False, yes = None): """lock a user account password.""" # forget about it, this is a scoria from the POST FORM to variable conversion. del yes groups.reload() users.reload() title = _("Lock account %s") % login data = w.page_body_start(uri, http_user,...
ProfilesController.configuration.users.base_path,
def ExportCLI(self): """ Export the user profiles list to human readable form. """ data = ""
and gid > LMC.configuration.groups.gid_max
or gid > LMC.configuration.groups.gid_max
def is_restricted_system_gid(self, gid): """ Return true if gid is system, but outside the range of Licorn® controlled GIDs.""" return gid < LMC.configuration.groups.system_gid_min \ and gid > LMC.configuration.groups.gid_max
command = [ "sudo", "mod", "user", "--quiet", "--no-colors", "--login", login, '--apply-skel', skel ]
command = [ "sudo", "mod", "user", "--quiet", "--no-colors", "--login", login, '--apply-skel', apply_skel ]
def filter_skels(pri_group, sk_list): ''' TODO: to be converted to licorn model if pri_group == configuration.mNames['RESPONSABLES_GROUP']: return filter(lambda x: x.rfind("/%s/" % configuration.mNames['RESPONSABLES_GROUP']) != -1, sk_list) elif pri_group == configuration.mNames['USAGERS_GROUP']: return filter(lambda x...
return styles.stylize(styles.ST_NAME, ' '.join(cmd))
return stylize(ST_NAME, ' '.join(cmd))
def cmdfmt(cmd): '''convert a sequence to a colorized string.''' return styles.stylize(styles.ST_NAME, ' '.join(cmd))
% (styles.colors[styles.ST_LOG], msg, styles.colors[styles.ST_NO]) )
% (colors[ST_LOG], msg, colors[ST_NO]) )
def test_message(msg): """ display a message to stderr. """ sys.stderr.write("%s>>> %s%s\n" % (styles.colors[styles.ST_LOG], msg, styles.colors[styles.ST_NO]) )
sys.stderr.write("%s>>> running %s%s%s\n" % (styles.colors[styles.ST_LOG], styles.colors[styles.ST_PATH], command, styles.colors[styles.ST_NO]))
sys.stderr.write("%s>>> running %s%s%s\n" % (colors[ST_LOG], colors[ST_PATH], command, colors[ST_NO]))
def log_and_exec (command, inverse_test=False, result_code=0, comment="", verb=verbose): """Display a command, execute it, and exit if soemthing went wrong.""" #if not command.startswith('colordiff'): # command += ' %s' % ' '.join(args) sys.stderr.write("%s>>> running %s%s%s\n" % (styles.colors[styles.ST_LOG], styles...
% (styles.colors[styles.ST_PATH], styles.colors[styles.ST_BAD], comment, styles.colors[styles.ST_NO]))
% (colors[ST_PATH], colors[ST_BAD], comment, colors[ST_NO]))
def log_and_exec (command, inverse_test=False, result_code=0, comment="", verb=verbose): """Display a command, execute it, and exit if soemthing went wrong.""" #if not command.startswith('colordiff'): # command += ' %s' % ' '.join(args) sys.stderr.write("%s>>> running %s%s%s\n" % (styles.colors[styles.ST_LOG], styles...
% ( styles.colors[styles.ST_LOG], styles.colors[styles.ST_BAD], retcode, styles.colors[styles.ST_LOG], result_code, styles.colors[styles.ST_NO], test) )
% ( colors[ST_LOG], colors[ST_BAD], retcode, colors[ST_LOG], result_code, colors[ST_NO], test) )
def log_and_exec (command, inverse_test=False, result_code=0, comment="", verb=verbose): """Display a command, execute it, and exit if soemthing went wrong.""" #if not command.startswith('colordiff'): # command += ' %s' % ' '.join(args) sys.stderr.write("%s>>> running %s%s%s\n" % (styles.colors[styles.ST_LOG], styles...
return re.sub(r'\s\[\d\d\d\d/\d\d/\d\d\s\d\d:\d\d:\d\d\.\d\d\d\d\]\s',
return re.sub(r'(\.\d\d\d\d\d\d\d\d-\d\d\d\d\d\d|\s\[\d\d\d\d/\d\d/\d\d\s\d\d:\d\d:\d\d\.\d\d\d\d\]\s)',
def strip_dates(str): """ strip dates from warnings and traces, else outputs and references always compare false .""" return re.sub(r'\s\[\d\d\d\d/\d\d/\d\d\s\d\d:\d\d:\d\d\.\d\d\d\d\]\s', r' [D/T] ', str)
class FunctionnalTest:
def save_state(num, state_type='scenarii'): open(state_files[state_type],'w').write('%d' % num) def get_state(state_type='scenarii'): if os.path.exists(state_files[state_type]): return int(open(state_files[state_type]).read()) else: return 0 class ScenarioTest:
def strip_dates(str): """ strip dates from warnings and traces, else outputs and references always compare false .""" return re.sub(r'\s\[\d\d\d\d/\d\d/\d\d\s\d\d:\d\d:\d\d\.\d\d\d\d\]\s', r' [D/T] ', str)
def __init__(self, cmd, pre_cmds=[], chk_cmds=[], manual_output=False, reference_cmd=[], context='std'): if type(cmd) == type(''): self.cmd = cmd.split(' ') else: self.cmd = cmd self.pre_cmds = pre_cmds self.chk_cmds = chk_cmds self.reference_cmd = reference_cmd self.context = context self.manual_outp...
def __init__(self, cmds, context='std', descr=None): self.context = context self.sce_number = ScenarioTest.counter self.cmd_counter = 0 self.name = '%s%s%s%s%s' % ( stylize(ST_NAME, 'Scenario stylize(ST_OK, ScenarioTest.counter), stylize(ST_NAME, ' (%s)' % descr) if descr else '', stylize(ST_NAME, ', context '),...
def __init__(self, cmd, pre_cmds=[], chk_cmds=[], manual_output=False, reference_cmd=[], context='std'):
os.makedirs(os.path.dirname(self.ref_output_file))
os.makedirs('%s/%s' % (self.base_path, cmdnum))
def SaveOutput(self, output, code):
open(self.ref_output_file, 'w').write(strip_dates(output)) open(self.ref_code_file, 'w').write(str(code)) def PrepareReferenceOutput(self, cmd): if os.path.exists(self.ref_output_file): return (open(self.ref_output_file).read(), int(open(self.ref_code_file).read()))
open('%s/%s/cmdline.txt' % (self.base_path, cmdnum), 'w').write( ' '.join(self.cmds[cmdnum])) open('%s/%s/out.txt' % (self.base_path, cmdnum), 'w').write( strip_dates(output)) open('%s/%s/code.txt' % (self.base_path, cmdnum), 'w').write(str(code)) def RunCommand(self, cmdnum, batch=False): if os.path.exists('%s/%s' % ...
def SaveOutput(self, output, code):
logging.notice('no reference output for cmd FunctionnalTest.counter, cmdfmt(cmd), 'referer=%s, ' % cmdfmt(self.reference_cmd) \ if self.reference_cmd != [] else '', self.context)) output, retcode = execute(cmd)
logging.notice('''no reference output for %s, cmd ''' creating one…''' % (self.name, stylize(ST_OK, cmdnum), cmdfmt(self.cmds[cmdnum]))) output, retcode = execute(self.cmds[cmdnum])
def PrepareReferenceOutput(self, cmd):
if logging.ask_for_repair('is this output good to keep as reference for future runs?'): self.SaveOutput(output, retcode)
if logging.ask_for_repair('''is this output good to keep as ''' '''reference for future runs?'''): self.SaveOutput(cmdnum, output, retcode)
def PrepareReferenceOutput(self, cmd):
logging.error('you MUST have a reference output; please fix code or rerun this test.') def RunAndCheck(self, cmd, batch = False, inverse_test=False): ref_output, ref_code = self.PrepareReferenceOutput(cmd) output, retcode = execute(cmd) bad_run = False message = '' if retcode != ref_code: logging.warning( '''command...
logging.error('''you MUST have a reference output; please ''' '''fix code or rerun this test.''') def Run(self, options=[], batch=False, inverse_test=False, ): """ run each command of the scenario, in turn. """ start_scenario = get_state() if self.sce_number < start_scenario: logging.notice('Skipping %s' % stylize(S...
def PrepareReferenceOutput(self, cmd):
test_message('testing integrated help.') for program in (GETENT, ADD, MODIFY, DELETE, CHECK): FunctionnalTest(program).Run(options = [['-h'], ['--help']])
commands = [] for program in (GET, ADD, MOD, DEL, CHK): commands.extend([ program + ['-h'], program + ['--help']])
def test_integrated_help (): """Test extensively argmarser contents and intergated help.""" test_message('testing integrated help.') for program in (GETENT, ADD, MODIFY, DELETE, CHECK): FunctionnalTest(program).Run(options = [['-h'], ['--help']]) if program == ADD: modes = [ 'user', 'users', 'group', 'profile' ] el...
elif program == MODIFY:
elif program == MOD:
def test_integrated_help (): """Test extensively argmarser contents and intergated help.""" test_message('testing integrated help.') for program in (GETENT, ADD, MODIFY, DELETE, CHECK): FunctionnalTest(program).Run(options = [['-h'], ['--help']]) if program == ADD: modes = [ 'user', 'users', 'group', 'profile' ] el...
elif program == DELETE:
elif program == DEL:
def test_integrated_help (): """Test extensively argmarser contents and intergated help.""" test_message('testing integrated help.') for program in (GETENT, ADD, MODIFY, DELETE, CHECK): FunctionnalTest(program).Run(options = [['-h'], ['--help']]) if program == ADD: modes = [ 'user', 'users', 'group', 'profile' ] el...
elif program == GETENT:
elif program == GET:
def test_integrated_help (): """Test extensively argmarser contents and intergated help.""" test_message('testing integrated help.') for program in (GETENT, ADD, MODIFY, DELETE, CHECK): FunctionnalTest(program).Run(options = [['-h'], ['--help']]) if program == ADD: modes = [ 'user', 'users', 'group', 'profile' ] el...
elif program == CHECK:
elif program == CHK:
def test_integrated_help (): """Test extensively argmarser contents and intergated help.""" test_message('testing integrated help.') for program in (GETENT, ADD, MODIFY, DELETE, CHECK): FunctionnalTest(program).Run(options = [['-h'], ['--help']]) if program == ADD: modes = [ 'user', 'users', 'group', 'profile' ] el...
if program == GETENT and mode == 'configuration': FunctionnalTest(program + [mode]).Run()
if program == GET and mode == 'configuration': commands.append(program + [ mode ])
def test_integrated_help (): """Test extensively argmarser contents and intergated help.""" test_message('testing integrated help.') for program in (GETENT, ADD, MODIFY, DELETE, CHECK): FunctionnalTest(program).Run(options = [['-h'], ['--help']]) if program == ADD: modes = [ 'user', 'users', 'group', 'profile' ] el...
FunctionnalTest(program + [mode]).Run(options = [['-h'], ['--help']]) test_message('integrated help testing finished.')
commands.extend([ program + [ mode, '-h'], program + [ mode, '--help'] ]) ScenarioTest(commands, descr="integrated help").Run()
def test_integrated_help (): """Test extensively argmarser contents and intergated help.""" test_message('testing integrated help.') for program in (GETENT, ADD, MODIFY, DELETE, CHECK): FunctionnalTest(program).Run(options = [['-h'], ['--help']]) if program == ADD: modes = [ 'user', 'users', 'group', 'profile' ] el...
test_message('''starting get tests.''')
commands = []
def test_get(context): """Test GET a lot.""" test_message('''starting get tests.''') for category in [ 'config_dir', 'main_config_file', 'extendedgroup_data_file' ]: for mode in [ '', '-s', '-b', '--bourne-shell', '-c', '--c-shell', '-p', '--php-code' ]: FunctionnalTest(GETENT + [ 'configuration', category, mode ], c...