hello
Im trying with this one ![]()
as the process descriibed here :
but...
when I try to patch the tftpd.py with the patch (1.patch in my case) :
patch tftpd.py 1.patch
patching file tftpd.py
Hunk #1 FAILED at 190.
Hunk #2 FAILED at 198.
2 out of 2 hunks FAILED -- saving rejects to file tftpd.py.rej
but :
cat 1.patch
--- a/tftp_common.py
+++ b/tftp_common.py
@@ -190,7 +190,7 @@ class RQPacket(TFTPPacket):
@staticmethod
def parse_rq(packet: bytes, constructor):
block_size = 512
window_size = 1
window_size = 2 # temporarily changed bad_opts = False packet = packet[2:].split(b'\0') for i in range(2, len(packet), 2):@@ -198,6 +198,8 @@ class RQPacket(TFTPPacket):
block_size = int(packet[i + 1])
elif packet[i].lower() == b'windowsize':
window_size = int(packet[i + 1])
elif packet[i].lower() == b'timeout': return constructor(packet[0], TransferModes.get_mode(packet[1]), block_size, window_size, bad_opts)pass # not implemented, temporarily ignoring elif packet[i] != b'': bad_opts = True
cat tftpd.py
#!/usr/bin/env python3
import socket
import sys
import threading
from tftp_common import TFTPConnection, TransferModes, ErrorPacket, ErrorCodes, RRQPacket, DEBUG, TFTPPacket,
OACKPacket, ACKPacket
class TFTPServerConnection(TFTPConnection):
def init(self, client_address, base_path: bytes):
connection = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
connection.bind(('', 0))
super().init(connection, client_address)
self.base_path = base_path
def handle_file_request(self, packet: RRQPacket):
if packet.bad_opts:
if DEBUG:
print('Bad opts')
self.send_packet(ErrorPacket(ErrorCodes.UNSUPPORTED_OPTS, b'Only blksize and windowsize opts supported'))
return
if packet.mode != TransferModes.OCTET:
if DEBUG:
print('Bad mode: ', packet.mode)
self.send_packet(ErrorPacket(ErrorCodes.ILLEGAL_OPERATION, b'Only octet mode supported'))
return
if packet.block_size != 512 or packet.window_size != 1:
counter = 0
while counter < 20:
counter += 1
self.send_packet(OACKPacket(packet.block_size, packet.window_size))
try:
packed, _ = self.receive_packet()
except TimeoutError:
pass
if isinstance(packet, ACKPacket):
if packet.ack_id == 0:
break
try:
file = open(self.base_path + packet.filename, 'rb')
self.transmit_file(file, packet.block_size, packet.window_size)
file.close()
except IOError as er:
self.send_packet(ErrorPacket(ErrorCodes.FILE_NOT_FOUND, str(er).encode('utf8')))
class TFTPServer:
def init(self, bind_to: str = '', port: int = 6969, base_path: bytes = b''):
self.master_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.master_socket.bind((bind_to, port))
self.base_path = base_path
def file_request(self, packet: RRQPacket, client_address):
if DEBUG:
print('File requested ', packet.filename)
connection = TFTPServerConnection(client_address, base_path=self.base_path)
connection.handle_file_request(packet)
connection.close()
def run(self):
while True:
frame, client_address = self.master_socket.recvfrom(65535)
if DEBUG:
print('Connection form ', client_address)
packet = TFTPPacket.decode(frame)
if isinstance(packet, RRQPacket):
threading.Thread(target=self.file_request, args=(packet, client_address)).run()
path = sys.argv[2].encode('utf8')
if path[-1] != b'/':
path += b'/'
TFTPServer(port=int(sys.argv[1]), base_path=path).run()
what am I doing wrong ? looks like the wiki's page doesnt explain that clear ![]()
(first time I use patch process/command..)
thank you