当前位置: 首页>>代码示例>>Python>>正文


Python ndr.ndr_pack函数代码示例

本文整理汇总了Python中samba.ndr.ndr_pack函数的典型用法代码示例。如果您正苦于以下问题:Python ndr_pack函数的具体用法?Python ndr_pack怎么用?Python ndr_pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ndr_pack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: verify_packet

    def verify_packet(self, response, response_packet, request_mac=""):
        self.assertEqual(response.additional[0].rr_type, dns.DNS_QTYPE_TSIG)

        tsig_record = response.additional[0].rdata
        mac = ''.join([chr(x) for x in tsig_record.mac])

        # Cut off tsig record from dns response packet for MAC verification
        # and reset additional record count.
        key_name_len = len(self.key_name) + 2
        tsig_record_len = len(ndr.ndr_pack(tsig_record)) + key_name_len + 10

        response_packet_list = list(response_packet)
        del response_packet_list[-tsig_record_len:]
        response_packet_list[11] = chr(0)
        response_packet_wo_tsig = ''.join(response_packet_list)

        fake_tsig = dns.fake_tsig_rec()
        fake_tsig.name = self.key_name
        fake_tsig.rr_class = dns.DNS_QCLASS_ANY
        fake_tsig.ttl = 0
        fake_tsig.time_prefix = tsig_record.time_prefix
        fake_tsig.time = tsig_record.time
        fake_tsig.algorithm_name = tsig_record.algorithm_name
        fake_tsig.fudge = tsig_record.fudge
        fake_tsig.error = 0
        fake_tsig.other_size = 0
        fake_tsig_packet = ndr.ndr_pack(fake_tsig)

        data = request_mac + response_packet_wo_tsig + fake_tsig_packet
        self.g.check_packet(data, data, mac)
开发者ID:Alexander--,项目名称:samba,代码行数:30,代码来源:dns_base.py

示例2: add_at_record

def add_at_record(samdb, container_dn, prefix, hostname, dnsdomain, hostip, hostip6):

    fqdn_hostname = "%s.%s" % (hostname, dnsdomain)

    at_records = []

    # SOA record
    at_soa_record = SOARecord(fqdn_hostname, "hostmaster.%s" % dnsdomain)
    at_records.append(ndr_pack(at_soa_record))

    # NS record
    at_ns_record = NSRecord(fqdn_hostname)
    at_records.append(ndr_pack(at_ns_record))

    if hostip is not None:
        # A record
        at_a_record = ARecord(hostip)
        at_records.append(ndr_pack(at_a_record))

    if hostip6 is not None:
        # AAAA record
        at_aaaa_record = AAAARecord(hostip6)
        at_records.append(ndr_pack(at_aaaa_record))

    msg = ldb.Message(ldb.Dn(samdb, "[email protected],%s" % container_dn))
    msg["objectClass"] = ["top", "dnsNode"]
    msg["dnsRecord"] = ldb.MessageElement(at_records, ldb.FLAG_MOD_ADD, "dnsRecord")
    samdb.add(msg)
开发者ID:andrew-aladev,项目名称:samba-talloc-debug,代码行数:28,代码来源:sambadns.py

示例3: test_no_active_forwarder

    def test_no_active_forwarder(self):
        ad = contact_real_server(server_ip, 53)

        name = "dsfsfds.dsfsdfs"
        p = self.make_name_packet(dns.DNS_OPCODE_QUERY)
        questions = []

        q = self.make_name_question(name, dns.DNS_QTYPE_TXT, dns.DNS_QCLASS_IN)
        questions.append(q)

        self.finish_name_packet(p, questions)
        send_packet = ndr.ndr_pack(p)

        self.finish_name_packet(p, questions)
        p.operation |= dns.DNS_FLAG_RECURSION_DESIRED
        send_packet = ndr.ndr_pack(p)

        ad.send(send_packet, 0)
        ad.settimeout(timeout)
        try:
            data = ad.recv(0xffff + 2, 0)
            data = ndr.ndr_unpack(dns.name_packet, data)
            self.assert_dns_rcode_equals(data, dns.DNS_RCODE_SERVFAIL)
            self.assertEqual(data.ancount, 0)
        except socket.timeout:
            self.fail("DNS server is too slow (timeout %s)" % timeout)
开发者ID:encukou,项目名称:samba,代码行数:26,代码来源:dns_forwarder.py

示例4: _samdb_fetch_pfm_and_schi

    def _samdb_fetch_pfm_and_schi(self):
        """Fetch prefixMap and schemaInfo stored in SamDB using LDB connection"""
        samdb = self.ldb_dc1
        res = samdb.search(base=samdb.get_schema_basedn(), scope=SCOPE_BASE,
                           attrs=["prefixMap", "schemaInfo"])

        pfm = ndr_unpack(drsblobs.prefixMapBlob,
                         str(res[0]['prefixMap']))

        schi = drsuapi.DsReplicaOIDMapping()
        schi.id_prefix = 0

        if 'schemaInfo' in res[0]:
            schi.oid.length = len(map(ord, str(res[0]['schemaInfo'])))
            schi.oid.binary_oid = map(ord, str(res[0]['schemaInfo']))
        else:
            schema_info = drsblobs.schemaInfoBlob()
            schema_info.revision = 0
            schema_info.marker = 0xFF
            schema_info.invocation_id = misc.GUID(samdb.get_invocation_id())
            schi.oid.length = len(map(ord, ndr_pack(schema_info)))
            schi.oid.binary_oid = map(ord, ndr_pack(schema_info))

        pfm.ctr.mappings = pfm.ctr.mappings + [schi]
        pfm.ctr.num_mappings += 1
        return pfm.ctr
开发者ID:encukou,项目名称:samba,代码行数:26,代码来源:getnc_exop.py

示例5: test_no_flag_recursive_forwarder

    def test_no_flag_recursive_forwarder(self):
        ad = contact_real_server(server_ip, 53)

        name = "dsfsfds.dsfsdfs"
        p = self.make_name_packet(dns.DNS_OPCODE_QUERY)
        questions = []

        q = self.make_name_question(name, dns.DNS_QTYPE_TXT, dns.DNS_QCLASS_IN)
        questions.append(q)

        self.finish_name_packet(p, questions)
        send_packet = ndr.ndr_pack(p)

        self.finish_name_packet(p, questions)
        # Leave off the recursive flag
        send_packet = ndr.ndr_pack(p)

        ad.send(send_packet, 0)
        ad.settimeout(timeout)
        try:
            data = ad.recv(0xffff + 2, 0)
            data = ndr.ndr_unpack(dns.name_packet, data)
            self.assert_dns_rcode_equals(data, dns.DNS_RCODE_NXDOMAIN)
            self.assertEqual(data.ancount, 0)
        except socket.timeout:
            self.fail("DNS server is too slow (timeout %s)" % timeout)
开发者ID:encukou,项目名称:samba,代码行数:26,代码来源:dns_forwarder.py

示例6: dns_transaction_tcp

    def dns_transaction_tcp(self, packet, host,
                            dump=False, timeout=None):
        "send a DNS query and read the reply, also return the raw packet"
        s = None
        if timeout is None:
            timeout = self.timeout
        try:
            send_packet = ndr.ndr_pack(packet)
            if dump:
                print(self.hexdump(send_packet))
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
            s.settimeout(timeout)
            s.connect((host, 53))
            tcp_packet = struct.pack('!H', len(send_packet))
            tcp_packet += send_packet
            s.sendall(tcp_packet)

            recv_packet = s.recv(0xffff + 2, 0)
            if dump:
                print(self.hexdump(recv_packet))
            response = ndr.ndr_unpack(dns.name_packet, recv_packet[2:])

        finally:
            if s is not None:
                s.close()

        # unpacking and packing again should produce same bytestream
        my_packet = ndr.ndr_pack(response)
        self.assertEquals(my_packet, recv_packet[2:])

        return (response, recv_packet[2:])
开发者ID:Alexander--,项目名称:samba,代码行数:31,代码来源:dns_base.py

示例7: __init__

 def __init__(self, attid, flags, identifier, targetGUID):
     self.attid = attid
     self.flags = flags
     self.identifier = str(identifier)
     self.selfGUID_blob = ndr_pack(identifier)
     self.targetGUID = str(targetGUID)
     self.targetGUID_blob = ndr_pack(targetGUID)
开发者ID:encukou,项目名称:samba,代码行数:7,代码来源:drs_base.py

示例8: _test_pack_unpack

    def _test_pack_unpack(self, desc, cycles=5000, cls=security.descriptor):
        blob2 = ndr_pack(desc)

        for i in range(SCALE * cycles):
            blob = ndr_pack(desc)
            desc = ndr_unpack(cls, blob)

        self.assertEqual(blob, blob2)
开发者ID:DavidMulder,项目名称:samba,代码行数:8,代码来源:ndr_pack_performance.py

示例9: s4_zone_create

def s4_zone_create(s4connector, object):
	_d=ud.function('s4_zone_create')

	zoneDn, zoneName=__create_default_s4_zone_dn(s4connector, object)
		
	# Create the forward zone in S4 if it does not exist
	try:
		searchResult=s4connector.lo_s4.lo.search_s(zoneDn, ldap.SCOPE_BASE, '(objectClass=*)',['dn'])
	except ldap.NO_SUCH_OBJECT:
		__create_s4_forward_zone(s4connector, zoneDn, zoneName)
	
	# Create @ object
	zoneDnAt='[email protected],%s' % zoneDn

	old_dnsRecords=[]

	try:
		searchResult=s4connector.lo_s4.lo.search_s(zoneDnAt, ldap.SCOPE_BASE, '(objectClass=*)')
		if searchResult and searchResult[0][1]:
			old_dnsRecords=searchResult[0][1].get('dnsRecord')
	except ldap.NO_SUCH_OBJECT:
		__create_s4_forward_zone_at(s4connector, zoneDnAt, zoneName)

	dnsRecords=[]

	__pack_nsRecord(object, dnsRecords)

	__pack_soaRecord(object, dnsRecords)

	# The IP address of the DNS forward zone will be used to determine the
	# sysvol share. On a selective replicated DC only a short list of DCs
	# should be returned
	aRecords = s4connector.configRegistry.get('connector/s4/mapping/dns/forward_zone/%s/static/ipv4' % zoneName[0].lower())
	aAAARecords = s4connector.configRegistry.get('connector/s4/mapping/dns/forward_zone/%s/static/ipv6' % zoneName[0].lower())
	if aRecords or aAAARecords:
		#IPv4
		if aRecords:
			for a in aRecords.split(' '):
				a=univention.s4connector.s4.compatible_modstring(a)
				a_record=ARecord(a)
				dnsRecords.append(ndr_pack(a_record))

		#IPv6
		if aAAARecords:
			for a in aAAARecords.split(' '):
				a=univention.s4connector.s4.compatible_modstring(a)
				a_record=AAAARecord(a)
				dnsRecords.append(ndr_pack(a_record))
	else:
		__pack_aRecord(object, dnsRecords)

	__pack_mxRecord(object, dnsRecords)

	s4connector.lo_s4.modify(zoneDnAt, [('dnsRecord', old_dnsRecords, dnsRecords)])

	return True
开发者ID:B-Rich,项目名称:smart,代码行数:56,代码来源:dns.py

示例10: save_profile

 def save_profile(self, profile):
     # Check if profile exists
     cn = profile.get('cn', None)
     # Check if profile exists
     old_profile = None
     if cn is not None:
         ldap_filter = '(CN=%s)' % cn
         old_profile_data = self._get_ldap_profile_data(ldap_filter)
         if old_profile_data:
             old_profile = self._data_to_profile(old_profile_data)
     if old_profile is not None:
         logging.debug('Profile with cn %s already exists. Modifying' % cn)
         logging.debug('Old profile: %s' % old_profile)
         logging.debug('New profile: %s' % profile)
         # Modify existing profile
         sd = self._security_descriptor_from_profile(profile)
         gpo_uuid = profile['cn']
         ldif = [
             (ldap.MOD_REPLACE, 'displayName',
                 (FC_PROFILE_PREFIX % profile['name']).encode()),
             (ldap.MOD_REPLACE, 'description',
                 profile['description'].encode()),
             (ldap.MOD_REPLACE, 'nTSecurityDescriptor',
                 ndr_pack(sd)),
         ]
         logging.debug('LDIF data to be sent to LDAP: %s' % ldif)
         dn = "CN=%s,CN=Policies,CN=System,%s" % (
             gpo_uuid, self._get_domain_dn())
         logging.debug('Modifying profile under %s' % dn)
         self.connection.modify_s(dn, ldif)
         self._save_smb_data(gpo_uuid, profile, sd.as_sddl())
     else:
         logging.debug('Saving new profile')
         # Create new profile
         gpo_uuid = self._generate_gpo_uuid()
         logging.debug('New profile UUID = %s' % gpo_uuid)
         attrs = self.GPO_BASE_ATTRIBUTES.copy()
         attrs['cn'] = gpo_uuid.encode()
         attrs['displayName'] = (FC_PROFILE_PREFIX % profile['name']).encode()
         attrs['description'] = profile['description'].encode()
         attrs['gPCFileSysPath'] = (GPO_SMB_PATH % (
             self._get_server_name(), self.domain, gpo_uuid)).encode()
         logging.debug('Preparing security descriptor')
         sd = self._security_descriptor_from_profile(profile)
         attrs['nTSecurityDescriptor'] = ndr_pack(sd)
         logging.debug('Profile data to be sent to LDAP: %s' % attrs)
         ldif = ldap.modlist.addModlist(attrs)
         logging.debug('LDIF data to be sent to LDAP: %s' % ldif)
         dn = "CN=%s,CN=Policies,CN=System,%s" % (
             gpo_uuid, self._get_domain_dn())
         logging.debug('Adding profile under %s' % dn)
         self.connection.add_s(dn, ldif)
         # Save SMB data
         self._save_smb_data(gpo_uuid, profile, sd.as_sddl())
     return gpo_uuid
开发者ID:fleet-commander,项目名称:fc-admin,代码行数:55,代码来源:fcad.py

示例11: __pack_mxRecord

def __pack_mxRecord(object, dnsRecords):
	for mXRecord in object['attributes'].get('mXRecord', []):
		if mXRecord:
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % mXRecord)
			mXRecord=univention.s4connector.s4.compatible_modstring(mXRecord)
			mx=mXRecord.split(' ')
			priority=mx[0]
			name=mx[1]
			mx_record=MXRecord(name, int(priority))
			dnsRecords.append(ndr_pack(mx_record))
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % ndr_pack(mx_record))
开发者ID:B-Rich,项目名称:smart,代码行数:11,代码来源:dns.py

示例12: add_host_record

def add_host_record(samdb, container_dn, prefix, hostip, hostip6):
    host_records = []
    if hostip:
        a_record = ARecord(hostip)
        host_records.append(ndr_pack(a_record))
    if hostip6:
        aaaa_record = AAAARecord(hostip6)
        host_records.append(ndr_pack(aaaa_record))
    if host_records:
        msg = ldb.Message(ldb.Dn(samdb, "%s,%s" % (prefix, container_dn)))
        msg["objectClass"] = ["top", "dnsNode"]
        msg["dnsRecord"] = ldb.MessageElement(host_records, ldb.FLAG_MOD_ADD, "dnsRecord")
        samdb.add(msg)
开发者ID:andrew-aladev,项目名称:samba-talloc-debug,代码行数:13,代码来源:sambadns.py

示例13: __pack_aRecord

def __pack_aRecord(object, dnsRecords):
	# add aRecords

	#IPv4
	for a in object['attributes'].get('aRecord', []):
		a=univention.s4connector.s4.compatible_modstring(a)
		a_record=ARecord(a)
		dnsRecords.append(ndr_pack(a_record))

	#IPv6
	for a in object['attributes'].get('aAAARecord', []):
		a=univention.s4connector.s4.compatible_modstring(a)
		a_record=AAAARecord(a)
		dnsRecords.append(ndr_pack(a_record))
开发者ID:B-Rich,项目名称:smart,代码行数:14,代码来源:dns.py

示例14: add_domain_record

def add_domain_record(samdb, domaindn, prefix, dnsdomain, domainsid, dnsadmins_sid):
    # DC=<DNSDOMAIN>,CN=MicrosoftDNS,<PREFIX>,<DOMAINDN>
    sddl = "O:SYG:BAD:AI" \
    "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)" \
    "(A;;CC;;;AU)" \
    "(A;;RPLCLORC;;;WD)" \
    "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
    "(A;CI;RPWPCRCCDCLCRCWOWDSDDTSW;;;ED)" \
    "(A;CIID;RPWPCRCCDCLCRCWOWDSDDTSW;;;%s)" \
    "(A;CIID;RPWPCRCCDCLCRCWOWDSDDTSW;;;ED)" \
    "(OA;CIID;RPWPCR;91e647de-d96f-4b70-9557-d63ff4f3ccd8;;PS)" \
    "(A;CIID;RPWPCRCCDCLCLORCWOWDSDDTSW;;;EA)" \
    "(A;CIID;LC;;;RU)" \
    "(A;CIID;RPWPCRCCLCLORCWOWDSDSW;;;BA)" \
    "S:AI" % dnsadmins_sid
    sec = security.descriptor.from_sddl(sddl, domainsid)
    props = []
    props.append(ndr_pack(TypeProperty()))
    props.append(ndr_pack(AllowUpdateProperty()))
    props.append(ndr_pack(SecureTimeProperty()))
    props.append(ndr_pack(NorefreshIntervalProperty(norefresh_interval=168)))
    props.append(ndr_pack(RefreshIntervalProperty(refresh_interval=168)))
    props.append(ndr_pack(AgingStateProperty()))
    props.append(ndr_pack(AgingEnabledTimeProperty()))
    msg = ldb.Message(ldb.Dn(samdb, "DC=%s,CN=MicrosoftDNS,%s,%s" % (dnsdomain, prefix, domaindn)))
    msg["objectClass"] = ["top", "dnsZone"]
    msg["ntSecurityDescriptor"] = ldb.MessageElement(ndr_pack(sec), ldb.FLAG_MOD_ADD,
        "nTSecurityDescriptor")
    msg["dNSProperty"] = ldb.MessageElement(props, ldb.FLAG_MOD_ADD, "dNSProperty")
    samdb.add(msg)
开发者ID:andrew-aladev,项目名称:samba-talloc-debug,代码行数:30,代码来源:sambadns.py

示例15: test_one_a_reply

    def test_one_a_reply(self):
        "send a reply instead of a query"

        p = self.make_name_packet(dns.DNS_OPCODE_QUERY)
        questions = []

        name = "%s.%s" % ('fakefakefake', self.get_dns_domain())
        q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN)
        print "asking for ", q.name
        questions.append(q)

        self.finish_name_packet(p, questions)
        p.operation |= dns.DNS_FLAG_REPLY
        s = None
        try:
            send_packet = ndr.ndr_pack(p)
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
            host=os.getenv('SERVER_IP')
            s.connect((host, 53))
            tcp_packet = struct.pack('!H', len(send_packet))
            tcp_packet += send_packet
            s.send(tcp_packet, 0)
            recv_packet = s.recv(0xffff + 2, 0)
            self.assertEquals(0, len(recv_packet))
        finally:
            if s is not None:
                s.close()
开发者ID:jkstrick,项目名称:samba,代码行数:27,代码来源:dns.py


注:本文中的samba.ndr.ndr_pack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。