...
 
Commits (2)
  • Nolan's avatar
    23292caf
  • Nolan's avatar
    fake_vagrant_sshd fixes. · 4aa5d8cb
    Nolan authored
    The big one is handling '' cmds immediately, instead of waiting
    for the client to say something.  This makes boot up way faster, and
    reliable.
    
    A smaller one is to flush stdout on print.  Apparently python doesn't
    switch to unbuffered when you redirect to a file and so nothing shows
    up in the logfile until way later.  Not sure what is going on there.
    4aa5d8cb
......@@ -116,6 +116,8 @@ Vagrant.configure("2") do |config|
sudo apt-get install -y --no-install-recommends network-manager xvfb x11vnc \
python3-cffi-backend python3-paramiko libnss3-tools
sudo cp /vagrant/fake_vagrant_sshd.py /usr/local/sbin/
sudo cp /vagrant/client/rc.local /etc/
sudo chmod a+x /etc/rc.local
sudo /etc/rc.local
......@@ -162,7 +164,7 @@ Vagrant.configure("2") do |config|
#Redirect this to our python dummy sshd
server.ssh.port=22222
server.ssh.host = "localhost"
server.ssh.host = "127.0.0.1"
server.vm.synced_folder ".", "/vagrant", disabled: true
#XXX Need to figure out how to get pebble's root cert into the os...
......
......@@ -6,4 +6,8 @@ while [ ! -f /usr/local/share/ca-certificates/fakeroot.crt ]; do
done
update-ca-certificates
if ! ps ax | grep -q "fake_vagrant_sshd[.]py"; then
python3 /usr/local/sbin/fake_vagrant_sshd.py &>/var/log/fake_vagrant_sshd.log &
fi
exit 0
#!/usr/bin/env python
import socket
import sys
import threading
import socket, sys, threading
import paramiko
#Python doesn't switch to unbuffered if stdout/err are redirected?
import functools
print = functools.partial(print, flush=True)
class Server(paramiko.ServerInterface):
def check_channel_request(self, kind, chanid):
if kind == 'session':
......@@ -21,6 +23,11 @@ class Server(paramiko.ServerInterface):
def check_channel_pty_request(self, channel, term, width, height,
pixelwidth, pixelheight, modes):
assert(False)
return False
def check_channel_env_request(self, channel, name, value):
assert(False)
return False
def handle_cmd(self, cmd, chan):
ret = self.handle_cmd_streams(cmd.decode(), chan.makefile('r'),
......@@ -31,7 +38,9 @@ class Server(paramiko.ServerInterface):
def handle_cmd_streams(self, cmd, stdin, stdout, stderr):
last_exit = 0
print("cmd:", cmd)
if cmd == '' or 'bash -l' in cmd:
if cmd == '':
pass #vagrant seems to send these randomly. Just return success.
elif 'bash -l' in cmd:
for line in stdin:
line=line[:-1]
print('line:', line)
......@@ -51,7 +60,8 @@ class Server(paramiko.ServerInterface):
elif cmd.startswith('scp -t '):
#Assume they're only sending 1 file, and respond to all msgs.
stdout.write('\0' * 7)
print('XXX \'%s\'' % stdin.read())
stdout.flush()
print('scp uploaded: \'%s\'' % stdin.read())
return last_exit
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
......@@ -66,6 +76,6 @@ while True:
t = paramiko.Transport(client)
t.set_gss_host(socket.getfqdn(""))
t.load_server_moduli()
t.add_server_key( paramiko.RSAKey.generate(bits=1024))
t.add_server_key(paramiko.RSAKey.generate(bits=1024))
print("Starting ssh session")
t.start_server(server=Server())
......@@ -32,8 +32,6 @@ Xvfb &> .xvfb.log &
sleep 1
DISPLAY=:0 x11vnc -forever -shared &> .x11vnc.log &
python3 /vagrant/fake_vagrant_sshd.py &
DISPLAY=:0 python3 /vagrant/test_client.py -d &
while ! ss -tln | grep -q ':9999'; do
sleep 1
......@@ -41,9 +39,8 @@ done
ZIPFILE_NAME="$1" BROWSER=/vagrant/fake_browser.sh boundery-linux-client/Boundery\ Client &
fg %4 #tester
fg %3 #tester
jobs
kill -9 %5 #client
kill -9 %3 #fake_vagrant_sshd.py
kill -9 %4 #client
kill -9 %2 #x11vnc
kill -9 %1 #Xvfb