예제 #1
0
def getent_passwd(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_PASSWD_ALL)
    elif re.match('^\d+$', key):
        con = NslcdClient(constants.NSLCD_ACTION_PASSWD_BYUID)
        con.write_int32(int(key))
    else:
        con = NslcdClient(constants.NSLCD_ACTION_PASSWD_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        print '%s:%s:%d:%d:%s:%s:%s' % (
            con.read_string(),
            con.read_string(),
            con.read_int32(),
            con.read_int32(),
            con.read_string(),
            con.read_string(),
            con.read_string(),
        )
예제 #2
0
def getent_passwd(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_PASSWD_ALL)
    elif re.match('^\d+$', key):
        con = NslcdClient(constants.NSLCD_ACTION_PASSWD_BYUID)
        con.write_int32(int(key))
    else:
        con = NslcdClient(constants.NSLCD_ACTION_PASSWD_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        print '%s:%s:%d:%d:%s:%s:%s' % (
                con.read_string(),
                con.read_string(),
                con.read_int32(),
                con.read_int32(),
                con.read_string(),
                con.read_string(),
                con.read_string(),
            )
예제 #3
0
def getent_aliases(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_ALIAS_ALL)
    else:
        con = NslcdClient(constants.NSLCD_ACTION_ALIAS_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        print '%-16s%s' % (
            con.read_string() + ': ',
            ', '.join(con.read_stringlist()),
        )
예제 #4
0
def getent_aliases(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_ALIAS_ALL)
    else:
        con = NslcdClient(constants.NSLCD_ACTION_ALIAS_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        print '%-16s%s' % (
                con.read_string() + ': ',
                ', '.join(con.read_stringlist()),
            )
예제 #5
0
def getent_ethers(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_ETHER_ALL)
    elif re.match('^[0-9a-fA-F]{1,2}(:[0-9a-fA-F]{1,2}){5}$', key):
        con = NslcdClient(constants.NSLCD_ACTION_ETHER_BYETHER)
        con.write_ether(key)
    else:
        con = NslcdClient(constants.NSLCD_ACTION_ETHER_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        name = con.read_string()
        ether = con.read_ether()
        print '%s %s' % (ether, name)
예제 #6
0
def getent_services(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_SERVICE_ALL)
    else:
        value = key
        protocol = ''
        if '/' in value:
            value, protocol = value.split('/', 1)
        if re.match('^\d+$', value):
            con = NslcdClient(constants.NSLCD_ACTION_SERVICE_BYNUMBER)
            con.write_int32(int(value))
            con.write_string(protocol)
        else:
            con = NslcdClient(constants.NSLCD_ACTION_SERVICE_BYNAME)
            con.write_string(value)
            con.write_string(protocol)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        name = con.read_string()
        aliases = con.read_stringlist()
        number = con.read_int32()
        protocol = con.read_string()
        print '%-21s %d/%s %s' % (name, number, protocol, ' '.join(aliases))
예제 #7
0
def getent_ethers(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_ETHER_ALL)
    elif re.match('^[0-9a-fA-F]{1,2}(:[0-9a-fA-F]{1,2}){5}$', key):
        con = NslcdClient(constants.NSLCD_ACTION_ETHER_BYETHER)
        con.write_ether(key)
    else:
        con = NslcdClient(constants.NSLCD_ACTION_ETHER_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        name = con.read_string()
        ether = con.read_ether()
        print '%s %s' % (ether, name)
예제 #8
0
def getent_services(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_SERVICE_ALL)
    else:
        value = key
        protocol = ''
        if '/' in value:
            value, protocol = value.split('/', 1)
        if re.match('^\d+$', value):
            con = NslcdClient(constants.NSLCD_ACTION_SERVICE_BYNUMBER)
            con.write_int32(int(value))
            con.write_string(protocol)
        else:
            con = NslcdClient(constants.NSLCD_ACTION_SERVICE_BYNAME)
            con.write_string(value)
            con.write_string(protocol)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        name = con.read_string()
        aliases = con.read_stringlist()
        number = con.read_int32()
        protocol = con.read_string()
        print '%-21s %d/%s %s' % (name, number, protocol, ' '.join(aliases))
예제 #9
0
def getent_rpc(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_RPC_ALL)
    elif re.match('^\d+$', key):
        con = NslcdClient(constants.NSLCD_ACTION_RPC_BYNUMBER)
        con.write_int32(int(key))
    else:
        con = NslcdClient(constants.NSLCD_ACTION_RPC_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        name = con.read_string()
        aliases = con.read_stringlist()
        number = con.read_int32()
        print '%-15s %d  %s' % (name, number, ' '.join(aliases))
예제 #10
0
def getent_rpc(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_RPC_ALL)
    elif re.match('^\d+$', key):
        con = NslcdClient(constants.NSLCD_ACTION_RPC_BYNUMBER)
        con.write_int32(int(key))
    else:
        con = NslcdClient(constants.NSLCD_ACTION_RPC_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        name = con.read_string()
        aliases = con.read_stringlist()
        number = con.read_int32()
        print '%-15s %d  %s' % (name, number, ' '.join(aliases))
예제 #11
0
def getent_group(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_GROUP_ALL)
    elif database == 'group.bymember':
        con = NslcdClient(constants.NSLCD_ACTION_GROUP_BYMEMBER)
        con.write_string(key)
    elif re.match('^\d+$', key):
        con = NslcdClient(constants.NSLCD_ACTION_GROUP_BYGID)
        con.write_int32(int(key))
    else:
        con = NslcdClient(constants.NSLCD_ACTION_GROUP_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        print '%s:%s:%d:%s' % (
            con.read_string(),
            con.read_string(),
            con.read_int32(),
            ','.join(con.read_stringlist()),
        )
예제 #12
0
def getent_shadow(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_SHADOW_ALL)
    else:
        con = NslcdClient(constants.NSLCD_ACTION_SHADOW_BYNAME)
        con.write_string(key)
    value2str = lambda x: str(x) if x != -1 else ''
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        print '%s:%s:%s:%s:%s:%s:%s:%s:%s' % (
            con.read_string(),
            con.read_string(),
            value2str(con.read_int32()),
            value2str(con.read_int32()),
            value2str(con.read_int32()),
            value2str(con.read_int32()),
            value2str(con.read_int32()),
            value2str(con.read_int32()),
            value2str(con.read_int32()),
        )
예제 #13
0
def getent_group(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_GROUP_ALL)
    elif database == 'group.bymember':
        con = NslcdClient(constants.NSLCD_ACTION_GROUP_BYMEMBER)
        con.write_string(key)
    elif re.match('^\d+$', key):
        con = NslcdClient(constants.NSLCD_ACTION_GROUP_BYGID)
        con.write_int32(int(key))
    else:
        con = NslcdClient(constants.NSLCD_ACTION_GROUP_BYNAME)
        con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        print '%s:%s:%d:%s' % (
                con.read_string(),
                con.read_string(),
                con.read_int32(),
                ','.join(con.read_stringlist()),
            )
예제 #14
0
def getent_shadow(database, key=None):
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_SHADOW_ALL)
    else:
        con = NslcdClient(constants.NSLCD_ACTION_SHADOW_BYNAME)
        con.write_string(key)
    value2str = lambda x: str(x) if x != -1 else ''
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        print '%s:%s:%s:%s:%s:%s:%s:%s:%s' % (
                con.read_string(),
                con.read_string(),
                value2str(con.read_int32()),
                value2str(con.read_int32()),
                value2str(con.read_int32()),
                value2str(con.read_int32()),
                value2str(con.read_int32()),
                value2str(con.read_int32()),
                value2str(con.read_int32()),
            )
예제 #15
0
def getent_networks(database, key=None):
    db_af = _get_af(database)
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_NETWORK_ALL)
    else:
        ipv4_addr = _get_ipv4(key)
        ipv6_addr = _get_ipv6(key)
        if ipv4_addr and db_af in (socket.AF_INET, None):
            con = NslcdClient(constants.NSLCD_ACTION_NETWORK_BYADDR)
            con.write_address(socket.AF_INET, ipv4_addr)
        elif ipv6_addr and db_af in (socket.AF_INET, None):
            con = NslcdClient(constants.NSLCD_ACTION_NETWORK_BYADDR)
            con.write_address(socket.AF_INET6, ipv6_addr)
        else:
            con = NslcdClient(constants.NSLCD_ACTION_NETWORK_BYNAME)
            con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        names = ' '.join([con.read_string()] + con.read_stringlist())
        for af, address in con.read_addresslist():
            if db_af in (af, None):
                print '%-15s %s' % (address, names)
예제 #16
0
def getent_networks(database, key=None):
    db_af = _get_af(database)
    if not key:
        con = NslcdClient(constants.NSLCD_ACTION_NETWORK_ALL)
    else:
        ipv4_addr = _get_ipv4(key)
        ipv6_addr = _get_ipv6(key)
        if ipv4_addr and db_af in (socket.AF_INET, None):
            con = NslcdClient(constants.NSLCD_ACTION_NETWORK_BYADDR)
            con.write_address(socket.AF_INET, ipv4_addr)
        elif ipv6_addr and db_af in (socket.AF_INET, None):
            con = NslcdClient(constants.NSLCD_ACTION_NETWORK_BYADDR)
            con.write_address(socket.AF_INET6, ipv6_addr)
        else:
            con = NslcdClient(constants.NSLCD_ACTION_NETWORK_BYNAME)
            con.write_string(key)
    while con.get_response() == constants.NSLCD_RESULT_BEGIN:
        names = ' '.join([con.read_string()] + con.read_stringlist())
        for af, address in con.read_addresslist():
            if db_af in (af, None):
                print '%-15s %s' % (address, names)