dyndns

Check-in [5ccae59986]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Adapt logging to not be buried by stray/malicious queries. Drop debug stops.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:5ccae5998690989372a5f64b9ee7f77890dd4d44d0b08ae875db07cc53cd35e6
User & Date: ajv-899-334-8894@vsta.org 2017-05-12 16:28:16
Context
2017-05-13
16:51
Can't cache, sigh--there's a per-request ID which changes. We want the client to be a standalone bit of python, so also drop the utils.py factoring. check-in: 68e0d11ff8 user: ajv-899-334-8894@vsta.org tags: master, trunk
2017-05-12
16:28
Adapt logging to not be buried by stray/malicious queries. Drop debug stops. check-in: 5ccae59986 user: ajv-899-334-8894@vsta.org tags: master, trunk
16:21
Example account file contents check-in: 426ea7616f user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to server.py.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
143







144

145
146
147
148
149
150
151
# dyndns_server.py
#	Field UDP DNS updates, serve a dynamic DNS sub-domain
#
import sys, time, socket, threading, json, hashlib, os
from dnslib import \
    SOA, NS, A, DNSRecord, DNSHeader, QTYPE, RR, CNAME
from utils import tohex, fold
import pdb

# Use once and discard (nonces)
used = set()

# Dict of known host names (key), their PSK (value)
touched = None
accounts = {}
................................................................................
	self.set_soa()

    # Construct an A query response for a dynamic address host
    def dns_response(self, data):
	global hosts

	# Parse request
	import pdb
	pdb.set_trace()
	request = DNSRecord.parse(data)

	# We only answer 'A' records
	q = request.q
	qt = QTYPE[q.qtype]
	if qt != 'A':
	    return None
................................................................................
	reply.add_answer(RR(rname=D,
	    rtype=QTYPE.NS, rclass=1, ttl=TTL, rdata=NS(D.ns1)))
	# Authority
	reply.add_answer(RR(rname=D,
	    rtype=QTYPE.SOA, rclass=1, ttl=TTL, rdata=self.soa_record))

	# Formatted answer, cached
	resp = reply.pack()
	self.cache[host] = resp
	return resp

    def serve_dns(self):
	sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	sock.bind(('', 53))

	while True:
	    buf,who = sock.recvfrom(8192)
	    sys.stderr.write("Query %s %s\n" % (who, time.asctime()))
	    try:
		res = self.dns_response(buf)
	    except:
		sys.stderr.write(" malformed request\n")
		continue
	    if res is None:
		sys.stderr.write(" no response for this query\n")
		continue







	    sys.stderr.write(" response\n")

	    sock.sendto(res, who)

def load_accounts():
    global accounts, touched

    f = open("etc/accounts", "r")
    st = os.fstat(f.fileno())







<







 







<
<







 







|






>


<

|

|

|
|

>
>
>
>
>
>
>
|
>







2
3
4
5
6
7
8

9
10
11
12
13
14
15
..
73
74
75
76
77
78
79


80
81
82
83
84
85
86
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# dyndns_server.py
#	Field UDP DNS updates, serve a dynamic DNS sub-domain
#
import sys, time, socket, threading, json, hashlib, os
from dnslib import \
    SOA, NS, A, DNSRecord, DNSHeader, QTYPE, RR, CNAME
from utils import tohex, fold


# Use once and discard (nonces)
used = set()

# Dict of known host names (key), their PSK (value)
touched = None
accounts = {}
................................................................................
	self.set_soa()

    # Construct an A query response for a dynamic address host
    def dns_response(self, data):
	global hosts

	# Parse request


	request = DNSRecord.parse(data)

	# We only answer 'A' records
	q = request.q
	qt = QTYPE[q.qtype]
	if qt != 'A':
	    return None
................................................................................
	reply.add_answer(RR(rname=D,
	    rtype=QTYPE.NS, rclass=1, ttl=TTL, rdata=NS(D.ns1)))
	# Authority
	reply.add_answer(RR(rname=D,
	    rtype=QTYPE.SOA, rclass=1, ttl=TTL, rdata=self.soa_record))

	# Formatted answer, cached
	resp = (host, reply.pack())
	self.cache[host] = resp
	return resp

    def serve_dns(self):
	sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	sock.bind(('', 53))
	ignored = 0
	while True:
	    buf,who = sock.recvfrom(8192)

	    try:
		tup = self.dns_response(buf)
	    except:
		ignored += 1
		continue
	    if tup is None:
		ignored += 1
		continue
	    host,res = tup

	    # DNS typically receives a *lot* of junk
	    if ignored:
		sys.stderr.write("(%d previously ignored)\n" % (ignored,))
		ignored = 0

	    sys.stderr.write("Query %s %s %s\n" %
		(who, host, time.asctime()))
	    sock.sendto(res, who)

def load_accounts():
    global accounts, touched

    f = open("etc/accounts", "r")
    st = os.fstat(f.fileno())