mirror of
https://github.com/tmate-io/tmate-ssh-server.git
synced 2020-11-18 19:53:51 -08:00
Keys can be specified with -k
This commit is contained in:
parent
8e610ba024
commit
fb733d9433
@ -26,7 +26,7 @@ extern int client_connect(char *path, int start_server);
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: tmate-slave [-l logfile] [-p PORT] [-v]\n");
|
||||
fprintf(stderr, "usage: tmate-slave [-k keys_dir] [-l logfile] [-p PORT] [-v]\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -34,8 +34,9 @@ int main(int argc, char **argv)
|
||||
int opt;
|
||||
int port = TMATE_DEFAULT_PORT;
|
||||
char *log_path = NULL; /* stderr */
|
||||
char *keys_dir = "keys";
|
||||
|
||||
while ((opt = getopt(argc, argv, "p:l:v")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "p:l:vk:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
port = atoi(optarg);
|
||||
@ -43,6 +44,9 @@ int main(int argc, char **argv)
|
||||
case 'l':
|
||||
log_path = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
keys_dir = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
debug_level++;
|
||||
break;
|
||||
@ -63,7 +67,7 @@ int main(int argc, char **argv)
|
||||
|
||||
tmate_preload_trace_lib();
|
||||
|
||||
tmate_ssh_server_main(port);
|
||||
tmate_ssh_server_main(keys_dir, port);
|
||||
return 0;
|
||||
}
|
||||
static void set_session_token(struct tmate_ssh_client *client,
|
||||
|
@ -258,16 +258,13 @@ static int get_ip(int fd, char *dst, size_t len)
|
||||
|
||||
struct tmate_ssh_client tmate_client;
|
||||
|
||||
void tmate_ssh_server_main(int port)
|
||||
static ssh_bind prepare_ssh(const char *keys_dir, int port)
|
||||
{
|
||||
struct tmate_ssh_client *client = &tmate_client;
|
||||
ssh_bind bind;
|
||||
pid_t pid;
|
||||
|
||||
char buffer[PATH_MAX];
|
||||
int verbosity = SSH_LOG_NOLOG;
|
||||
//int verbosity = SSH_LOG_PACKET;
|
||||
|
||||
setup_signals();
|
||||
ssh_callbacks_init(&ssh_session_callbacks);
|
||||
|
||||
bind = ssh_bind_new();
|
||||
@ -275,16 +272,32 @@ void tmate_ssh_server_main(int port)
|
||||
tmate_fatal("Cannot initialize ssh");
|
||||
|
||||
ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BINDPORT, &port);
|
||||
ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BANNER, SSH_BANNER);
|
||||
ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BANNER, TMATE_SSH_BANNER);
|
||||
ssh_bind_options_set(bind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &verbosity);
|
||||
ssh_bind_options_set(bind, SSH_BIND_OPTIONS_DSAKEY, "keys/ssh_host_dsa_key");
|
||||
ssh_bind_options_set(bind, SSH_BIND_OPTIONS_RSAKEY, "keys/ssh_host_rsa_key");
|
||||
|
||||
sprintf(buffer, "%s/ssh_host_dsa_key", keys_dir);
|
||||
ssh_bind_options_set(bind, SSH_BIND_OPTIONS_DSAKEY, buffer);
|
||||
|
||||
sprintf(buffer, "%s/ssh_host_rsa_key", keys_dir);
|
||||
ssh_bind_options_set(bind, SSH_BIND_OPTIONS_RSAKEY, buffer);
|
||||
|
||||
if (ssh_bind_listen(bind) < 0)
|
||||
tmate_fatal("Error listening to socket: %s\n", ssh_get_error(bind));
|
||||
|
||||
tmate_info("Accepting connections on %d", port);
|
||||
|
||||
return bind;
|
||||
}
|
||||
|
||||
void tmate_ssh_server_main(const char *keys_dir, int port)
|
||||
{
|
||||
struct tmate_ssh_client *client = &tmate_client;
|
||||
ssh_bind bind;
|
||||
pid_t pid;
|
||||
|
||||
setup_signals();
|
||||
bind = prepare_ssh(keys_dir, port);
|
||||
|
||||
for (;;) {
|
||||
client->session = ssh_new();
|
||||
client->channel = NULL;
|
||||
|
4
tmate.h
4
tmate.h
@ -113,10 +113,10 @@ extern void tmate_flush_pty(struct tmate_ssh_client *client);
|
||||
|
||||
/* tmate-ssh-server.c */
|
||||
|
||||
#define SSH_BANNER "tmate"
|
||||
#define TMATE_SSH_BANNER "tmate"
|
||||
|
||||
extern struct tmate_ssh_client tmate_client;
|
||||
extern void tmate_ssh_server_main(int port);
|
||||
extern void tmate_ssh_server_main(const char *keys_dir, int port);
|
||||
|
||||
/* tmate-slave.c */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user