diff --git a/Makefile.am b/Makefile.am index f3ade8f5..4dad3e63 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,9 @@ endif CFLAGS += -Wno-unused-parameter -Wno-unused-variable CFLAGS += -Ilibssh/include/ -Imsgpack/src +if IS_DEVENV +CFLAGS += -DDEVENV +endif # Set flags for gcc. gcc4 whines abouts silly stuff so it needs slightly # different flags. diff --git a/configure.ac b/configure.ac index 013cd655..5856e556 100644 --- a/configure.ac +++ b/configure.ac @@ -40,6 +40,13 @@ AC_CHECK_HEADERS( ] ) +AC_ARG_ENABLE( + devenv, + AC_HELP_STRING(--enable-devenv, "dev env (port 2200, no random tokens)"), + found_devenv=$enable_devenv +) +AM_CONDITIONAL(IS_DEVENV, test "x$found_devenv" = xyes) + # Is this a debug build? #found_debug=yes AC_ARG_ENABLE( diff --git a/log.c b/log.c index 564a082f..56c0fa31 100644 --- a/log.c +++ b/log.c @@ -27,6 +27,7 @@ #include #include "tmux.h" +#include "tmate.h" /* Log file, if needed. */ FILE *log_file; @@ -84,7 +85,7 @@ log_vwrite(const char *msg, va_list ap) if (log_file == NULL) return; - if (asprintf(&fmt, "[%d] %s\n", getpid(), msg) == -1) + if (asprintf(&fmt, "[%s] %s\n", tmate_session_token, msg) == -1) exit(1); if (vfprintf(log_file, fmt, ap) == -1) exit(1); diff --git a/tmate-slave.c b/tmate-slave.c index bdf56286..39ef29b2 100644 --- a/tmate-slave.c +++ b/tmate-slave.c @@ -16,7 +16,7 @@ struct tmate_encoder *tmate_encoder; int tmux_socket_fd; -const char *tmate_session_token; +const char *tmate_session_token = "main"; extern FILE *log_file; extern int server_create_socket(void); @@ -30,7 +30,7 @@ static void usage(void) int main(int argc, char **argv) { int opt; - int port = 22; + int port = TMATE_DEFAULT_PORT; char *log_path = NULL; /* stderr */ while ((opt = getopt(argc, argv, "p:l:v")) != -1) { @@ -78,16 +78,15 @@ static char *get_random_token(void) int i; char *token = xmalloc(TMATE_TOKEN_LEN + 1); -#if 0 - strcpy(token, "TOKENTOKENTOKENTOKENTOKEN"); - return token; -#endif - ssh_get_random(token, TMATE_TOKEN_LEN, 0); for (i = 0; i < TMATE_TOKEN_LEN; i++) token[i] = tmate_token_digits[token[i] % NUM_DIGITS]; token[i] = 0; +#ifdef DEVENV + strcpy(token, "SUPERSECURETOKENFORDEVENV"); +#endif + return token; } @@ -209,7 +208,7 @@ static void tmate_spawn_slave_server(struct tmate_ssh_client *client) set_session_token(token); free(token); - tmate_debug("Spawning tmux slave server %s", tmate_session_token); + tmate_debug("Spawning tmux slave server"); tmux_socket_fd = server_create_socket(); if (tmux_socket_fd < 0) @@ -250,7 +249,7 @@ static void tmate_spawn_slave_client(struct tmate_ssh_client *client) set_session_token(token); - tmate_debug("Spawn tmux slave client %s", tmate_session_token); + tmate_debug("Spawn tmux slave client"); tmux_socket_fd = client_connect(socket_path, 0); if (tmux_socket_fd < 0) { diff --git a/tmate.h b/tmate.h index ea434f9e..4bbe0118 100644 --- a/tmate.h +++ b/tmate.h @@ -100,12 +100,19 @@ extern void tmate_ssh_server_main(int port); /* tmate-slave.c */ +#ifdef DEVENV +#define TMATE_DEFAULT_PORT 2200 +#else +#define TMATE_DEFAULT_PORT 22 +#endif + #define TMATE_TOKEN_LEN 25 #define TMATE_WORKDIR "/tmp/tmate" #define TMATE_JAIL_USER "nobody" extern struct tmate_encoder *tmate_encoder; extern int tmux_socket_fd; +extern const char *tmate_session_token; extern void tmate_spawn_slave(struct tmate_ssh_client *client);