mirror of
https://github.com/tmux/tmux.git
synced 2026-05-30 14:16:18 +00:00
Tighten up read-only checks on attach-session, detach-client and
switch-client so that a user should be able to only detach their own client. Reported by John Walker.
This commit is contained in:
@@ -61,6 +61,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
|||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
char *cwd, *cause;
|
char *cwd, *cause;
|
||||||
enum msgtype msgtype;
|
enum msgtype msgtype;
|
||||||
|
uid_t uid;
|
||||||
|
|
||||||
if (RB_EMPTY(&sessions)) {
|
if (RB_EMPTY(&sessions)) {
|
||||||
cmdq_error(item, "no sessions");
|
cmdq_error(item, "no sessions");
|
||||||
@@ -106,8 +107,16 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
|||||||
}
|
}
|
||||||
if (fflag)
|
if (fflag)
|
||||||
server_client_set_flags(c, fflag);
|
server_client_set_flags(c, fflag);
|
||||||
if (rflag)
|
if (rflag) {
|
||||||
|
if (c->flags & CLIENT_READONLY) {
|
||||||
|
uid = proc_get_peer_uid(c->peer);
|
||||||
|
if (uid != getuid()) {
|
||||||
|
cmdq_error(item, "client is read-only");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
c->flags |= (CLIENT_READONLY|CLIENT_IGNORESIZE);
|
c->flags |= (CLIENT_READONLY|CLIENT_IGNORESIZE);
|
||||||
|
}
|
||||||
|
|
||||||
c->last_session = c->session;
|
c->last_session = c->session;
|
||||||
if (c->session != NULL) {
|
if (c->session != NULL) {
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = cmd_get_args(self);
|
||||||
struct cmd_find_state *source = cmdq_get_source(item);
|
struct cmd_find_state *source = cmdq_get_source(item);
|
||||||
|
struct client *c = cmdq_get_client(item);
|
||||||
struct client *tc = cmdq_get_target_client(item), *loop;
|
struct client *tc = cmdq_get_target_client(item), *loop;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
enum msgtype msgtype;
|
enum msgtype msgtype;
|
||||||
@@ -69,6 +70,13 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c->flags & CLIENT_READONLY) {
|
||||||
|
if (args_has(args, 's') || args_has(args, 'a') || c != tc) {
|
||||||
|
cmdq_error(item, "client is read-only");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args_has(args, 'P'))
|
if (args_has(args, 'P'))
|
||||||
msgtype = MSG_DETACHKILL;
|
msgtype = MSG_DETACHKILL;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
const char *tflag = args_get(args, 't');
|
const char *tflag = args_get(args, 't');
|
||||||
enum cmd_find_type type;
|
enum cmd_find_type type;
|
||||||
int flags;
|
int flags;
|
||||||
|
struct client *c = cmdq_get_client(item);
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
@@ -61,6 +63,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
const char *tablename;
|
const char *tablename;
|
||||||
struct key_table *table;
|
struct key_table *table;
|
||||||
struct sort_criteria sort_crit;
|
struct sort_criteria sort_crit;
|
||||||
|
uid_t uid;
|
||||||
|
|
||||||
if (tflag != NULL &&
|
if (tflag != NULL &&
|
||||||
(tflag[strcspn(tflag, ":.%")] != '\0' || strcmp(tflag, "=") == 0)) {
|
(tflag[strcspn(tflag, ":.%")] != '\0' || strcmp(tflag, "=") == 0)) {
|
||||||
@@ -77,6 +80,13 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
wp = target.wp;
|
wp = target.wp;
|
||||||
|
|
||||||
if (args_has(args, 'r')) {
|
if (args_has(args, 'r')) {
|
||||||
|
if (tc->flags & CLIENT_READONLY) {
|
||||||
|
uid = proc_get_peer_uid(c->peer);
|
||||||
|
if (uid != getuid()) {
|
||||||
|
cmdq_error(item, "client is read-only");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (tc->flags & CLIENT_READONLY)
|
if (tc->flags & CLIENT_READONLY)
|
||||||
tc->flags &= ~(CLIENT_READONLY|CLIENT_IGNORESIZE);
|
tc->flags &= ~(CLIENT_READONLY|CLIENT_IGNORESIZE);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user