summaryrefslogtreecommitdiff
path: root/pkd_stub.py
diff options
context:
space:
mode:
authorCarson Fleming <cflems@cflems.net>2023-03-24 07:08:56 -0700
committerCarson Fleming <cflems@cflems.net>2023-03-24 07:08:56 -0700
commit9c3765f9b87ee2941c6e330fbb3377c1e61fae0e (patch)
tree98a6a6d2054986af596643bbd833c8f32b8e9050 /pkd_stub.py
parentf0e4edecc73f48d72b4a1cedc2d16793f368d49c (diff)
downloadpk-9c3765f9b87ee2941c6e330fbb3377c1e61fae0e.tar.gz
Synchronize PTY stop sequence
Diffstat (limited to 'pkd_stub.py')
-rw-r--r--pkd_stub.py44
1 files changed, 29 insertions, 15 deletions
diff --git a/pkd_stub.py b/pkd_stub.py
index f3ff1f7..c7209b2 100644
--- a/pkd_stub.py
+++ b/pkd_stub.py
@@ -139,14 +139,14 @@ def screens_pty(sel, screen, client):
os.environ['TERM'] = 'xterm-256color'
client['osc'].send(bytes(os.environ['TERM'], 'utf-8'))
except:
- tcp_unpty(sel, client)
+ tcp_unpty(sel, client, catchup=False)
tcp_disconnect(sel, client)
try:
screen['sock'].sendall(b'\xc0\xdepty')
except:
screens_detach(sel, screen)
- tcp_unpty(sel, client)
+ tcp_send_npty(sel, client)
return
def screens_read(sel, sock, screen):
@@ -160,7 +160,7 @@ def screens_read(sel, sock, screen):
if not data or data == b'\xde\xad':
screens_detach(sel, screen)
if screen['pty']:
- tcp_unpty(sel, screen['pty'], npty_screen=False)
+ tcp_send_npty(sel, screen['pty'])
return
if screen['pty']:
@@ -285,14 +285,15 @@ def register_screens(sel, socket_file):
def tcp_disconnect(sel, client):
global tcp_clients
+ if client not in tcp_clients:
+ return
+
sel.unregister(client['sock'])
client['sock'].close()
client['alive'] = False
-
- if client in tcp_clients:
- idx = tcp_clients.index(client)
- del tcp_clients[idx]
- brint('[INFO] TCP Client %d disconnected.' % idx)
+ idx = tcp_clients.index(client)
+ del tcp_clients[idx]
+ brint('[INFO] TCP Client %d disconnected.' % idx)
def tcp_dumpq(sel, client):
global cmdq
@@ -303,17 +304,30 @@ def tcp_dumpq(sel, client):
except:
tcp_disconnect(sel, client)
-def tcp_unpty(sel, client, catchup=True, npty_screen=True):
+def tcp_send_npty(sel, client):
+ try:
+ client['osc'].send(b'\xc0\xdenpty')
+ except:
+ tcp_disconnect(sel, client)
+
+def tcp_unpty(sel, client, catchup=True):
if type(client['pty']) == dict:
client['pty']['pty'] = False
- if npty_screen and client['pty']['alive']:
+ if client['pty']['alive']:
try:
client['pty']['sock'].sendall(b'\xc0\xdenpty')
except:
screens_detach(sel, client['pty'])
- del client['isc']
- del client['osc']
+
+ try:
+ client['osc'].send(b'\xc0\xdeack')
+ except:
+ tcp_disconnect(sel, client)
+ # this will become stop_stream(backtrack)
+ del client['isc']
+ del client['osc']
client['pty'] = False
+
if catchup:
tcp_dumpq(sel, client)
@@ -333,15 +347,15 @@ def tcp_transport(sel, sock, client):
return
elif not client['pty']:
brint('[%d]' % tcp_clients.index(client), data, end='', prompt=False)
- elif data == b'\xc0\xdenpty':
- tcp_unpty(sel, client)
+ elif data[:6] == b'\xc0\xdenpty':
+ tcp_unpty(sel, client, catchup=True)
print('[INFO] npty acknowledged')
else:
try:
client['pty']['sock'].sendall(data)
except:
screens_detach(sel, client['pty'])
- tcp_unpty(sel, client, npty_screen=False)
+ tcp_send_npty(client)
def tcp_handshake(sock):
global privkey, bits, exp