Exemplo n.º 1
0
def rename(ctx, cn, newCn):
    """change netgroup name"""
    netgroup = Netgroup(cn)
    if netgroup.exists:
        netgroup.rename(args.get('newCn'))
    else:
        click.echo("Group %s does not exist." % cn)
        sys.exit(1)
Exemplo n.º 2
0
def add(ctx, **args):
    """add a netgroup"""
    type = args.pop('nisNetgroupType')
    data = dict_merge(netgroups.get(type), args)
    cn = data.get('cn')
    path = data.pop('path', None)
    requires = data.pop('requires', None)
    dn = "cn=%s,%s" % (cn, dir.get_netgroup_base(type))
    netgroup_entry = dir.Entry(dn=dn, attrs=data)
    newnetgroup = Netgroup(cn, netgroup_entry)
    newnetgroup.add()
Exemplo n.º 3
0
def add_netgroup(args, netgroup_type):
    netgroup_data = util.merge(netgroups.get(netgroup_type), args)
    if netgroup_type in netgroups.keys():
        cn = netgroup_data.get('cn')
        path = netgroup_data.pop('path', None)
        requires = netgroup_data.pop('requires', None)
        dn = "cn=%s,%s" % (cn, dir.get_netgroup_base(netgroup_type))
        netgroup_entry = dir.Entry(dn=dn, attrs=netgroup_data)
        newnetgroup = Netgroup(cn, netgroup_entry)
        newnetgroup.add()
    else:
        print "Netgroup type %s is not exactly known." % netgroup_type
        sys.exit(1)
Exemplo n.º 4
0
def edit_netgroup(args):
    netgroup = Netgroup(args.pop('cn'))
    for attr, val in args.iteritems():
        attr = attr.lower()
        if attr == 'description':
            netgroup.set_description(val)
        elif attr == 'addnetgrouptriple':
            netgroup.add_triple(val)
        elif attr == 'delnetgrouptriple':
            netgroup.del_triple(val)
    netgroup.commit_changes()
Exemplo n.º 5
0
def get_access_group(name, priv_level):
    """
    Gets a netgroup handle. Creates the group when necessary.
    """
    group_type = 'security'
    group_data = dict_merge(netgroups.get(group_type), {})
    path = group_data.pop('path')
    requires = group_data.pop('requires')
    group_name = '%s-%s' % (name, priv_level)
    description = 'Users with %s access to %s.' % (access_levels[priv_level], name)

    dn = 'cn=%s,%s' % (group_name, dir.get_netgroup_base(group_type))
    access_group = Netgroup(group_name, dir.Entry(dn=dn,
                                                  attrs=group_data,
                                                  use_dn=True))
    if not access_group.exists:
        access_group.add()
        access_group.set_description(description)
    return access_group
Exemplo n.º 6
0
def get_access_group(name, access_type=granted):
    """
    Gets a netgroup handle. Creates the group when necessary.
    """
    group_type = 'security'
    group_data = util.merge(netgroups.get(group_type), {})
    path = group_data.pop('path')
    requires = group_data.pop('requires')
    if access_type:
        group_name = '%s-granted' %(name)
        description = 'Users allowed to access %s.' % name
    else:
        group_name = '%s-denied' % (name)
        description = 'Users denied access to %s.' % name

    dn = 'cn=%s,%s' % (group_name, dir.get_netgroup_base(group_type))
    access_group = Netgroup(group_name, dir.Entry(dn=dn, attrs=group_data, use_dn=True))
    if not access_group.exists:
        access_group.add()
        access_group.set_description(description)
    return access_group
Exemplo n.º 7
0
def edit(ctx, **args):
    """edit a netgroup"""
    netgroup = Netgroup(args.pop('cn'))
    for attr, val in args.items():
        attr = attr.lower()
        if attr == 'description':
            netgroup.set_description(val)
        elif attr == 'addnisnetgrouptriple':
            netgroup.add_triple(val)
        elif attr == 'delnisnetgrouptriple':
            netgroup.del_triple(val)
        elif attr == 'addmembernisnetgroup':
            netgroup.add_member(val)
        elif attr == 'delmembernisnetgroup':
            netgroup.del_member(val)
    netgroup.commit_changes()
Exemplo n.º 8
0
def remove(ctx, **args):
    """remove a netgroup"""
    netgroup = Netgroup(cn)
    if netgroup.exists:
        netgroup.remove()