예제 #1
0
파일: cmd_group.py 프로젝트: jubalfh/cog
def add(ctx, **args):
    """add a group"""
    type = args.pop('groupType')
    data = dict_merge(groups.get(type), args)
    cn = data.get('cn')
    path = data.pop('path', None)
    requires = data.pop('requires', None)
    if not data.get('gidNumber') and 'gidNumber' in requires:
        data['gidNumber'] = dir.get_probably_unique_gidnumber()
    dn = "cn=%s,%s" % (cn, dir.get_group_base(type))
    group_entry = dir.Entry(dn=dn, attrs=data)
    newgroup = Group(cn, group_entry)
    newgroup.add()
예제 #2
0
파일: cmd_group.py 프로젝트: jubalfh/cog
def edit(ctx, **args):
    """edit group"""
    group = Group(args.pop('cn'))
    for attr, val in args.items():
        attr = attr.lower()
        if attr == 'description':
            group.set_description(val)
        elif attr == 'addmemberuid':
            group.add_uid(val)
        elif attr == 'delmemberuid':
            group.del_uid(val)
    group.commit_changes()
예제 #3
0
파일: cmd_user.py 프로젝트: jubalfh/cog
def add(ctx, **args):
    """Adds new user to the directory."""
    account_type = args.pop('accountType')
    user_group = args.pop('userGroup', settings.usergroups)
    user_data = dict_merge(accounts.get(account_type), args)
    name = user_data.pop('uid')
    user_data[user_rdn] = name
    path = user_data.pop('path', None)
    secondary_groups = user_data.pop('group', None)
    requires = user_data.pop('requires', [])
    dn = "%s=%s,%s" % (user_rdn, name, dir.get_account_base(account_type))
    operator_uid = get_current_uid()
    for nameattr in ['cn', 'sn', 'givenName']:
        if not user_data.get(nameattr) and nameattr in requires:
            user_data[nameattr] = '%s (ask %s to fix me)' % (name, operator_uid)
    if 'uidNumber' not in user_data and 'uidNumber' in requires:
        user_data['uidNumber'] = dir.get_probably_unique_uidnumber()
    if 'homeDirectory' not in user_data and 'homeDirectory' in requires:
        user_data['homeDirectory'] = "/home/%s" % user_data['uid']
    user_data['userPassword'] = passwd.make_sha512(passwd.random_string())
    if 'sshpublickey' in user_data:
        ssh_key = read_ssh_keys(user_data.pop('sshpublickey'))
        user_data['sshPublicKey'] = ssh_key
        user_data['objectClass'].append('ldapPublicKey')
    if user_group:
        group_type = account_type if account_type in groups else 'generic'
        group_dn = "cn=%s,%s" % (name, dir.get_group_base(group_type))
        group_id = dir.get_probably_unique_gidnumber()
        group_data = {
            'objectClass': ['posixGroup', 'top'],
            'cn': name,
            'description': 'Personal group for %s.' % name,
            'gidNumber': group_id}
        group_entry = dir.Entry(dn=group_dn, attrs=group_data)
        user_data['gidNumber'] = group_id
        try:
            newgroup = Group(name, group_entry)
            newgroup.add()
        except ldap.LDAPError as e:
            print "A problem occured when creating user group %s – group hasn't been created." % name
    user_entry = dir.Entry(dn=dn, attrs=user_data)
    newuser = User(name, user_entry, groups=secondary_groups)
    newuser.add()
예제 #4
0
파일: user.py 프로젝트: jubalfh/cog
 def delgroup(self, user_group):
     group_obj = Group(user_group)
     for uid in self.uid:
         group_obj.del_uid(uid)
     group_obj.commit_changes()
예제 #5
0
파일: user.py 프로젝트: jubalfh/cog
 def addgroup(self, user_group):
     group_obj = Group(user_group)
     for uid in self.uid:
         group_obj.add_uid(uid)
     group_obj.commit_changes()
예제 #6
0
파일: cmd_group.py 프로젝트: jubalfh/cog
def remove(ctx, cn):
    """remove group from directory"""
    group = Group(cn)
    group.remove()
예제 #7
0
파일: cmd_group.py 프로젝트: jubalfh/cog
def rename(ctx, **args):
    """change group name"""
    group = Group(args.get('cn'))
    group.rename(args.get('newCn'))