mirror of
https://github.com/tmate-io/tmate-ssh-server.git
synced 2020-11-18 19:53:51 -08:00
Random socket path (we don't support multi sessions)
This commit is contained in:
parent
a50dcb09b5
commit
5d847fb0aa
14
tmux.c
14
tmux.c
@ -165,6 +165,7 @@ makesocketpath(const char *label)
|
|||||||
char base[MAXPATHLEN], realbase[MAXPATHLEN], *path, *s;
|
char base[MAXPATHLEN], realbase[MAXPATHLEN], *path, *s;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
u_int uid;
|
u_int uid;
|
||||||
|
int do_random_label = 1;
|
||||||
|
|
||||||
uid = getuid();
|
uid = getuid();
|
||||||
if ((s = getenv("TMPDIR")) == NULL || *s == '\0')
|
if ((s = getenv("TMPDIR")) == NULL || *s == '\0')
|
||||||
@ -189,7 +190,16 @@ makesocketpath(const char *label)
|
|||||||
if (realpath(base, realbase) == NULL)
|
if (realpath(base, realbase) == NULL)
|
||||||
strlcpy(realbase, base, sizeof realbase);
|
strlcpy(realbase, base, sizeof realbase);
|
||||||
|
|
||||||
|
if (!label) {
|
||||||
|
do_random_label = 1;
|
||||||
|
label = "XXXXXX";
|
||||||
|
}
|
||||||
|
|
||||||
xasprintf(&path, "%s/%s", realbase, label);
|
xasprintf(&path, "%s/%s", realbase, label);
|
||||||
|
|
||||||
|
if (do_random_label)
|
||||||
|
mktemp(path);
|
||||||
|
|
||||||
return (path);
|
return (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,18 +391,14 @@ main(int argc, char **argv)
|
|||||||
if (label == NULL) {
|
if (label == NULL) {
|
||||||
if (environ_path != NULL)
|
if (environ_path != NULL)
|
||||||
path = xstrdup(environ_path);
|
path = xstrdup(environ_path);
|
||||||
else
|
|
||||||
label = xstrdup("default");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -L or default set. */
|
/* -L or default set. */
|
||||||
if (label != NULL) {
|
|
||||||
if ((path = makesocketpath(label)) == NULL) {
|
if ((path = makesocketpath(label)) == NULL) {
|
||||||
fprintf(stderr, "can't create socket\n");
|
fprintf(stderr, "can't create socket\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free(label);
|
free(label);
|
||||||
strlcpy(socket_path, path, sizeof socket_path);
|
strlcpy(socket_path, path, sizeof socket_path);
|
||||||
free(path);
|
free(path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user