コード例 #1
0
ファイル: dnsserver.py プロジェクト: sYnfo/samba
 def setUp(self):
     super(DnsserverTests, self).setUp()
     self.server = env_get_var_value("SERVER_IP")
     self.zone = env_get_var_value("REALM").lower()
     self.conn = dnsserver.dnsserver("ncacn_ip_tcp:%s" % (self.server),
                                     self.get_loadparm(),
                                     self.get_credentials())
コード例 #2
0
 def setUp(self):
     super(DnsserverTests, self).setUp()
     self.server = env_get_var_value("SERVER_IP")
     self.zone = env_get_var_value("REALM").lower()
     self.conn = dnsserver.dnsserver("ncacn_ip_tcp:%s" % (self.server),
                                     self.get_loadparm(),
                                     self.get_credentials())
コード例 #3
0
ファイル: dns.py プロジェクト: runt18/samba
def dns_connect(server, lp, creds):
    if server.lower() == 'localhost':
        server = '127.0.0.1'
    binding_str = "ncacn_ip_tcp:{0!s}[sign]".format(server)
    try:
        dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
    except RuntimeError, e:
        raise CommandError('Connecting to DNS RPC server {0!s} failed with {1!s}'.format(server, e))
コード例 #4
0
ファイル: dns.py プロジェクト: yong253535551/android_samba
def dns_connect(server, lp, creds):
    if server.lower() == 'localhost':
        server = '127.0.0.1'
    binding_str = "ncacn_ip_tcp:%s[sign]" % server
    try:
        dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
    except RuntimeError, e:
        raise CommandError('Connecting to DNS RPC server %s failed with %s' % (server, e))
コード例 #5
0
ファイル: dns.py プロジェクト: jkstrick/samba
 def setUp(self):
     super(TestZones, self).setUp()
     self.lp = self.get_loadparm()
     self.creds = self.get_credentials(self.lp)
     self.server = os.getenv("SERVER_IP")
     self.zone = "test.lan"
     self.rpc_conn = dnsserver.dnsserver("ncacn_ip_tcp:%s" % (self.server),
                                         self.lp, self.creds)
コード例 #6
0
 def setUp(self):
     super(TestZones, self).setUp()
     self.lp = self.get_loadparm()
     self.creds = self.get_credentials(self.lp)
     self.server = os.getenv("SERVER_IP")
     self.zone = "test.lan"
     self.rpc_conn = dnsserver.dnsserver("ncacn_ip_tcp:%s" % (self.server),
                                         self.lp, self.creds)
コード例 #7
0
ファイル: __init__.py プロジェクト: vlatko-va/saltstack
def get_dns_zones():
    request_filter = dnsserver.DNS_ZONE_REQUEST_PRIMARY
    server = '127.0.0.1'
    binding_str = 'ncacn_ip_tcp:%s[sign]' % server
    cred_data = open('/vapour/dnsquery').read().split(':')

    creds = Credentials()
    creds.guess(lp)
    creds.set_username(cred_data[0])
    creds.set_password(cred_data[1].rstrip())

    dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
    client_version = dnsserver.DNS_CLIENT_VERSION_LONGHORN

    typeid, res = dns_conn.DnssrvComplexOperation2(
        client_version, 0, server, None, 'EnumZones',
        dnsserver.DNSSRV_TYPEID_DWORD, request_filter)

    return dict(res)
コード例 #8
0
ファイル: dns.py プロジェクト: goutham414/kali-n900
 def setUp(self):
     super(TestZones, self).setUp()
     self.zone = "test.lan"
     self.rpc_conn = dnsserver.dnsserver("ncacn_ip_tcp:%s[sign]" % (self.server_ip),
                                         self.lp, self.creds)
コード例 #9
0
ファイル: dns.py プロジェクト: pombredanne/linuxtrail
def dns_connect(server, lp, creds):
    if server.lower() == 'localhost':
        server = '127.0.0.1'
    binding_str = "ncacn_ip_tcp:%s[sign]" % server
    dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
    return dns_conn
コード例 #10
0
 def setUp(self):
     super(TestRPCRoundtrip, self).setUp()
     self.rpc_conn = dnsserver.dnsserver(
         "ncacn_ip_tcp:%s[sign]" % (self.server_ip), self.lp, self.creds)
コード例 #11
0
    def run(self,
            computername,
            credopts=None,
            sambaopts=None,
            versionopts=None,
            H=None,
            computerou=None,
            description=None,
            prepare_oldjoin=False,
            ip_address_list=None,
            service_principal_name_list=None):

        if ip_address_list is None:
            ip_address_list = []

        if service_principal_name_list is None:
            service_principal_name_list = []

        # check each IP address if provided
        for ip_address in ip_address_list:
            if not _is_valid_ip(ip_address):
                raise CommandError('Invalid IP address {}'.format(ip_address))

        lp = sambaopts.get_loadparm()
        creds = credopts.get_credentials(lp)

        try:
            samdb = SamDB(url=H,
                          session_info=system_session(),
                          credentials=creds,
                          lp=lp)
            samdb.newcomputer(
                computername,
                computerou=computerou,
                description=description,
                prepare_oldjoin=prepare_oldjoin,
                ip_address_list=ip_address_list,
                service_principal_name_list=service_principal_name_list,
            )

            if ip_address_list:
                # if ip_address_list provided, then we need to create DNS
                # records for this computer.

                hostname = re.sub(r"\$$", "", computername)
                if hostname.count('$'):
                    raise CommandError('Illegal computername "%s"' %
                                       computername)

                filters = '(&(sAMAccountName={}$)(objectclass=computer))'.format(
                    ldb.binary_encode(hostname))

                recs = samdb.search(base=samdb.domain_dn(),
                                    scope=ldb.SCOPE_SUBTREE,
                                    expression=filters,
                                    attrs=['primaryGroupID', 'objectSid'])

                group = recs[0]['primaryGroupID'][0]
                owner = ndr_unpack(security.dom_sid, recs[0]["objectSid"][0])

                dns_conn = dnsserver.dnsserver(
                    "ncacn_ip_tcp:{}[sign]".format(samdb.host_dns_name()), lp,
                    creds)

                change_owner_sd = security.descriptor()
                change_owner_sd.owner_sid = owner
                change_owner_sd.group_sid = security.dom_sid(
                    "{}-{}".format(samdb.get_domain_sid(), group), )

                add_dns_records(samdb, hostname, dns_conn, change_owner_sd,
                                samdb.host_dns_name(), ip_address_list,
                                self.get_logger())
        except Exception as e:
            raise CommandError(
                "Failed to create computer '%s': " % computername, e)

        self.outf.write("Computer '%s' created successfully\n" % computername)
コード例 #12
0
 def setUp(self):
     super(TestZones, self).setUp()
     self.zone = "test.lan"
     self.rpc_conn = dnsserver.dnsserver(
         "ncacn_ip_tcp:%s[sign]" % (self.server_ip), self.lp, self.creds)
コード例 #13
0
 def dns_connect(self):
     binding_str = "ncacn_ip_tcp:%s[sign]" % self.server_ip
     return dnsserver.dnsserver(binding_str, self.lp, self.creds)
コード例 #14
0
ファイル: dns.py プロジェクト: goutham414/kali-n900
 def setUp(self):
     super(TestRPCRoundtrip, self).setUp()
     self.rpc_conn = dnsserver.dnsserver("ncacn_ip_tcp:%s[sign]" % (self.server_ip),
                                         self.lp, self.creds)
コード例 #15
0
def dns_connect(server, lp, creds):
    binding_str = "ncacn_ip_tcp:%s[sign]" % server
    dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
    return dns_conn
コード例 #16
0
ファイル: dnsserver.py プロジェクト: sYnfo/samba
        print("Usage: dnsserver.py [options] DNSSERVER DNSZONE NEWNAME")
        sys.exit(1)

    server = args[0]
    dnszone   = args[1]
    newname   = args[2]

    lp = sambaopts.get_loadparm()
    creds = credopts.get_credentials(lp)

    if not creds.authentication_requested():
        parser.error("You must supply credentials")

    binding_str = "ncacn_ip_tcp:%s[print,sign]" % server

    dns_conn = dnsserver.dnsserver(binding_str, lp, creds)

    print("querying a NS record")
    res = dns_conn.DnssrvEnumRecords2(0x00070000,
                                      0,
                                      server,
                                      dnszone,
                                      newname,
                                      None,
                                      dnsp.DNS_TYPE_NS,
                                      0x0f,
                                      None,
                                      None)

    print("adding a NS glue record")
    name = dnsserver.DNS_RPC_NAME()
コード例 #17
0
ファイル: __init__.py プロジェクト: vlatko-va/saltstack
def list_dns():
    from samba.dcerpc import dnsp, dnsserver
    server = '127.0.0.1'
    binding_str = 'ncacn_ip_tcp:%s[sign]' % server

    cred_data = open('/vapour/dnsquery').read().split(':')

    creds = Credentials()
    creds.guess(lp)
    creds.set_username(cred_data[0])
    creds.set_password(cred_data[1].rstrip())
    dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
    zone = get_cur_domain()
    name = '@'
    record_type = dnsp.DNS_TYPE_ALL
    select_flags = dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA

    buflen, res = dns_conn.DnssrvEnumRecords2(
        dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, zone, name, None,
        record_type, select_flags, None, None)
    record_groups = res.rec
    result = []
    for rec_group in record_groups:
        group_name = rec_group.dnsNodeName.str
        for rec in rec_group.records:
            if rec.wType == dnsp.DNS_TYPE_A:
                result.append({
                    'group_name': group_name,
                    'type': 'A',
                    'value': rec.data
                })
            elif rec.wType == dnsp.DNS_TYPE_AAAA:
                result.append({
                    'group_name': group_name,
                    'type': 'AAAA',
                    'value': rec.data
                })
            elif rec.wType == dnsp.DNS_TYPE_PTR:
                result.append({
                    'group_name': group_name,
                    'type': 'PTR',
                    'value': rec.data.str
                })
            elif rec.wType == dnsp.DNS_TYPE_NS:
                result.append({
                    'group_name': group_name,
                    'type': 'NS',
                    'value': rec.data.str
                })
            elif rec.wType == dnsp.DNS_TYPE_CNAME:
                result.append({
                    'group_name': group_name,
                    'type': 'CNAME',
                    'value': rec.data.str
                })
            elif rec.wType == dnsp.DNS_TYPE_SOA:
                result.append({
                    'group_name':
                    group_name,
                    'type':
                    'SOA',
                    'value':
                    'serial=%d, refresh=%d, retry=%d, expire=%d, minttl=%d, ns=%s, email=%s'
                    % (rec.data.dwSerialNo, rec.data.dwRefresh,
                       rec.data.dwRetry, rec.data.dwExpire,
                       rec.data.dwMinimumTtl, rec.data.NamePrimaryServer.str,
                       rec.data.ZoneAdministratorEmail.str)
                })
            elif rec.wType == dnsp.DNS_TYPE_MX:
                result.append({
                    'group_name':
                    group_name,
                    'type':
                    'MX',
                    'value':
                    '%s (%d)' %
                    (rec.data.nameExchange.str, rec.data.wPreference)
                })
            elif rec.wType == dnsp.DNS_TYPE_SRV:
                result.append({
                    'group_name':
                    group_name,
                    'type':
                    'SRV',
                    'value':
                    '%s (%d, %d, %d)' % (rec.data.nameTarget, rec.data.wPort,
                                         rec.data.wPriority, rec.data.wWeight)
                })
            elif rec.wType == dnsp.DNS_TYPE_TXT:
                slist = ['"%s"' % name.str for name in rec.data]
                result.append({
                    'group_name': group_name,
                    'type': 'TXT',
                    'value': ','.join(slist)
                })
    return result
コード例 #18
0
ファイル: computer.py プロジェクト: Alexander--/samba
    def run(self, computername, credopts=None, sambaopts=None, versionopts=None,
            H=None, computerou=None, description=None, prepare_oldjoin=False,
            ip_address_list=None, service_principal_name_list=None):

        if ip_address_list is None:
            ip_address_list = []

        if service_principal_name_list is None:
            service_principal_name_list = []

        # check each IP address if provided
        for ip_address in ip_address_list:
            if not _is_valid_ip(ip_address):
                raise CommandError('Invalid IP address {}'.format(ip_address))

        lp = sambaopts.get_loadparm()
        creds = credopts.get_credentials(lp)

        try:
            samdb = SamDB(url=H, session_info=system_session(),
                          credentials=creds, lp=lp)
            samdb.newcomputer(computername, computerou=computerou,
                              description=description,
                              prepare_oldjoin=prepare_oldjoin,
                              ip_address_list=ip_address_list,
                              service_principal_name_list=service_principal_name_list,
                              )

            if ip_address_list:
                # if ip_address_list provided, then we need to create DNS
                # records for this computer.

                hostname = re.sub(r"\$$", "", computername)
                if hostname.count('$'):
                    raise CommandError('Illegal computername "%s"' % computername)

                filters = '(&(sAMAccountName={}$)(objectclass=computer))'.format(
                    ldb.binary_encode(hostname))

                recs = samdb.search(
                    base=samdb.domain_dn(),
                    scope=ldb.SCOPE_SUBTREE,
                    expression=filters,
                    attrs=['primaryGroupID', 'objectSid'])

                group = recs[0]['primaryGroupID'][0]
                owner = ndr_unpack(security.dom_sid, recs[0]["objectSid"][0])

                dns_conn = dnsserver.dnsserver(
                    "ncacn_ip_tcp:{}[sign]".format(samdb.host_dns_name()),
                    lp, creds)

                change_owner_sd = security.descriptor()
                change_owner_sd.owner_sid = owner
                change_owner_sd.group_sid = security.dom_sid(
                    "{}-{}".format(samdb.get_domain_sid(), group),
                )

                add_dns_records(
                    samdb, hostname, dns_conn,
                    change_owner_sd, samdb.host_dns_name(),
                    ip_address_list, self.get_logger())
        except Exception as e:
            raise CommandError("Failed to create computer '%s': " %
                               computername, e)

        self.outf.write("Computer '%s' created successfully\n" % computername)
コード例 #19
0
ファイル: dns_wildcard.py プロジェクト: Alexander--/samba
 def dns_connect(self):
     binding_str = "ncacn_ip_tcp:%s[sign]" % self.server_ip
     return dnsserver.dnsserver(binding_str, self.lp, self.creds)
コード例 #20
0
        print("Usage: dnsserver.py [options] DNSSERVER DNSZONE NEWNAME")
        sys.exit(1)

    server = args[0]
    dnszone = args[1]
    newname = args[2]

    lp = sambaopts.get_loadparm()
    creds = credopts.get_credentials(lp)

    if not creds.authentication_requested():
        parser.error("You must supply credentials")

    binding_str = "ncacn_ip_tcp:%s[print,sign]" % server

    dns_conn = dnsserver.dnsserver(binding_str, lp, creds)

    print("querying a NS record")
    res = dns_conn.DnssrvEnumRecords2(0x00070000, 0, server, dnszone, newname,
                                      None, dnsp.DNS_TYPE_NS, 0x0f, None, None)

    print("adding a NS glue record")
    name = dnsserver.DNS_RPC_NAME()
    name.str = newname

    addrec = dnsserver.DNS_RPC_RECORD()
    addrec.wType = dnsp.DNS_TYPE_NS
    addrec.dwFlags = 0
    addrec.dwSerial = 0
    addrec.dwTtlSeconds = 3600
    addrec.dwTimeStamp = 0
コード例 #21
0
def dns_connect(server, lp, creds):
    binding_str = "ncacn_ip_tcp:%s[sign]" % server
    dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
    return dns_conn
コード例 #22
0
ファイル: dns.py プロジェクト: hjwsm1989/samba
def dns_connect(server, lp, creds):
    if server.lower() == 'localhost':
        server = '127.0.0.1'
    binding_str = "ncacn_ip_tcp:%s[sign]" % server
    dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
    return dns_conn