Skip to content

Commit

Permalink
[ssh] mwrging code
Browse files Browse the repository at this point in the history
  • Loading branch information
cr409 committed Mar 28, 2012
2 parents a1f5dd7 + d7313e6 commit de15a5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client_tactics/ssh/server
Expand Up @@ -6,5 +6,5 @@ CONFIG_DIR=$1
/usr/sbin/sshd -p 10000 -e -h $CONFIG_DIR/signpost.pem \
-o "AllowUsers=root" -o "PermitTunnel=yes" \
-o "AuthorizedKeysFile=.ssh/signpost_tunnel" \
-o "PermitRootLogin=forced-commands-only" \
-o "PermitRootLogin=yes" \
-o "PidFile=/tmp/signpost_sshd.pid"
33 changes: 19 additions & 14 deletions lib/ssh.ml
Expand Up @@ -66,25 +66,30 @@ module Manager = struct
let run_server () =
(* TODO: Check if pid is still running *)
match conn_db.server_pid with
| None ->(
try
let cmd = Unix.getcwd () ^ "/client_tactics/ssh/server" in
let _ = Unix.create_process cmd [| cmd; Config.conf_dir |]
Unix.stdin Unix.stdout Unix.stderr in
let buf = String.create 100 in
let fd = Unix.openfile "/tmp/signpost_sshd.pid" [Unix.O_RDONLY] 0o640 in
let len = Unix.read fd buf 0 100 in
conn_db.server_pid <- Some(int_of_string (String.sub buf 0 (len-1)));
Printf.printf "[ssh] process created with pid %s...\n" (String.sub buf 0 (len-1));
return("OK")
with err ->
Printf.eprintf "[ssh] error : %s\n%!" (Printexc.to_string err);
failwith (Printexc.to_string err)
| None ->(
try
let cmd = Unix.getcwd () ^ "/client_tactics/ssh/server" in
let _ = Unix.create_process cmd [| cmd; Config.conf_dir |]
Unix.stdin Unix.stdout Unix.stderr in
lwt _ = Lwt_unix.sleep 2.0 in
let buf = String.create 100 in
let fd = Unix.openfile "/tmp/signpost_sshd.pid" [Unix.O_RDONLY] 0o640 in
let len = Unix.read fd buf 0 100 in
conn_db.server_pid <- Some(int_of_string (String.sub buf 0 (len-1)));
Printf.printf "[ssh] process created with pid %s...\n" (String.sub buf 0 (len-1));
return("OK")
with err ->
Printf.eprintf "[ssh] error : %s\n%!" (Printexc.to_string err);
failwith (Printexc.to_string err)
)
| Some(_) ->
Printf.printf "[ssh] ssh server already started...\n%!";
return("OK")

(*TODO:
* - timeout connect
* - if all tests fail how do I notify the server?
* - remove ips that match local ips *)
let run_client port ips =
(* check if I can connect to ssh port on a remote ip *)
let send_pkt_to port ip =
Expand Down

0 comments on commit de15a5d

Please sign in to comment.