-/* $OpenBSD: cmd-list-clients.c,v 1.38 2021/08/21 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-list-clients.c,v 1.39 2022/03/08 11:28:40 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
#define LIST_CLIENTS_TEMPLATE \
"#{client_name}: #{session_name} " \
"[#{client_width}x#{client_height} #{client_termname}] " \
+ "#{?#{!=:#{client_uid},#{uid}}," \
+ "[user #{?client_user,#{client_user},#{client_uid},}] ,}" \
"#{?client_flags,(,}#{client_flags}#{?client_flags,),}"
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
-/* $OpenBSD: format.c,v 1.300 2022/02/22 11:10:41 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.301 2022/03/08 11:28:40 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
#include <fnmatch.h>
#include <libgen.h>
#include <math.h>
+#include <pwd.h>
#include <regex.h>
#include <stdarg.h>
#include <stdlib.h>
return (NULL);
}
+/* Callback for client_uid. */
+static void *
+format_cb_client_uid(struct format_tree *ft)
+{
+ uid_t uid;
+
+ if (ft->c != NULL) {
+ uid = proc_get_peer_uid(ft->c->peer);
+ if (uid != (uid_t)-1)
+ return (format_printf("%ld", (long)uid));
+ }
+ return (NULL);
+}
+
+/* Callback for client_user. */
+static void *
+format_cb_client_user(struct format_tree *ft)
+{
+ uid_t uid;
+ struct passwd *pw;
+
+ if (ft->c != NULL) {
+ uid = proc_get_peer_uid(ft->c->peer);
+ if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL)
+ return (xstrdup(pw->pw_name));
+ }
+ return (NULL);
+}
+
/* Callback for client_utf8. */
static void *
format_cb_client_utf8(struct format_tree *ft)
return (xstrdup(window_tree_mode.default_format));
}
+/* Callback for uid. */
+static void *
+format_cb_uid(__unused struct format_tree *ft)
+{
+ return (format_printf("%ld", (long)getuid()));
+}
+
+/* Callback for user. */
+static void *
+format_cb_user(__unused struct format_tree *ft)
+{
+ struct passwd *pw;
+
+ if ((pw = getpwuid(getuid())) != NULL)
+ return (xstrdup(pw->pw_name));
+ return NULL;
+}
+
/* Format table type. */
enum format_table_type {
FORMAT_TABLE_STRING,
{ "client_tty", FORMAT_TABLE_STRING,
format_cb_client_tty
},
+ { "client_uid", FORMAT_TABLE_STRING,
+ format_cb_client_uid
+ },
+ { "client_user", FORMAT_TABLE_STRING,
+ format_cb_client_user
+ },
{ "client_utf8", FORMAT_TABLE_STRING,
format_cb_client_utf8
},
{ "tree_mode_format", FORMAT_TABLE_STRING,
format_cb_tree_mode_format
},
+ { "uid", FORMAT_TABLE_STRING,
+ format_cb_uid
+ },
+ { "user", FORMAT_TABLE_STRING,
+ format_cb_user
+ },
{ "version", FORMAT_TABLE_STRING,
format_cb_version
},
-/* $OpenBSD: proc.c,v 1.20 2021/02/11 09:39:29 nicm Exp $ */
+/* $OpenBSD: proc.c,v 1.21 2022/03/08 11:28:40 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
struct imsgbuf ibuf;
struct event event;
+ uid_t uid;
int flags;
#define PEER_BAD 0x1
void (*dispatchcb)(struct imsg *, void *), void *arg)
{
struct tmuxpeer *peer;
+ gid_t gid;
peer = xcalloc(1, sizeof *peer);
peer->parent = tp;
imsg_init(&peer->ibuf, fd);
event_set(&peer->event, fd, EV_READ, proc_event_cb, peer);
+ if (getpeereid(fd, &peer->uid, &gid) != 0)
+ peer->uid = (uid_t)-1;
+
log_debug("add peer %p: %d (%p)", peer, fd, arg);
TAILQ_INSERT_TAIL(&tp->peers, peer, entry);
return (pid);
}
}
+
+uid_t
+proc_get_peer_uid(struct tmuxpeer *peer)
+{
+ return (peer->uid);
+}
-.\" $OpenBSD: tmux.1,v 1.879 2022/02/22 11:10:41 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.880 2022/03/08 11:28:40 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: February 22 2022 $
+.Dd $Mdocdate: March 8 2022 $
.Dt TMUX 1
.Os
.Sh NAME
.It Li "client_termname" Ta "" Ta "Terminal name of client"
.It Li "client_termtype" Ta "" Ta "Terminal type of client, if available"
.It Li "client_tty" Ta "" Ta "Pseudo terminal of client"
+.It Li "client_uid" Ta "" Ta "UID of client process"
+.It Li "client_user" Ta "" Ta "User of client process"
.It Li "client_utf8" Ta "" Ta "1 if client supports UTF-8"
.It Li "client_width" Ta "" Ta "Width of client"
.It Li "client_written" Ta "" Ta "Bytes written to client"
.It Li "session_windows" Ta "" Ta "Number of windows in session"
.It Li "socket_path" Ta "" Ta "Server socket path"
.It Li "start_time" Ta "" Ta "Server start time"
+.It Li "uid" Ta "" Ta "Server UID"
+.It Li "user" Ta "" Ta "Server user"
.It Li "version" Ta "" Ta "Server version"
.It Li "window_active" Ta "" Ta "1 if window active"
.It Li "window_active_clients" Ta "" Ta "Number of clients viewing this window"
.It Li "window_cell_width" Ta "" Ta "Width of each cell in pixels"
.It Li "window_end_flag" Ta "" Ta "1 if window has the highest index"
.It Li "window_flags" Ta "#F" Ta "Window flags with # escaped as ##"
-.It Li "window_raw_flags" Ta "" Ta "Window flags with nothing escaped"
.It Li "window_format" Ta "" Ta "1 if format is for a window"
.It Li "window_height" Ta "" Ta "Height of window"
.It Li "window_id" Ta "" Ta "Unique window ID"
.It Li "window_offset_x" Ta "" Ta "X offset into window if larger than client"
.It Li "window_offset_y" Ta "" Ta "Y offset into window if larger than client"
.It Li "window_panes" Ta "" Ta "Number of panes in window"
+.It Li "window_raw_flags" Ta "" Ta "Window flags with nothing escaped"
.It Li "window_silence_flag" Ta "" Ta "1 if window has silence alert"
.It Li "window_stack_index" Ta "" Ta "Index in session most recent stack"
.It Li "window_start_flag" Ta "" Ta "1 if window has the lowest index"
-/* $OpenBSD: tmux.h,v 1.1161 2022/02/22 11:10:41 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1162 2022/03/08 11:28:40 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
typedef void (*overlay_free_cb)(struct client *, void *);
typedef void (*overlay_resize_cb)(struct client *, void *);
struct client {
- const char *name;
- struct tmuxpeer *peer;
- struct cmdq_list *queue;
+ const char *name;
+ struct tmuxpeer *peer;
+ struct cmdq_list *queue;
- struct client_windows windows;
+ struct client_windows windows;
- struct control_state *control_state;
- u_int pause_age;
+ struct control_state *control_state;
+ u_int pause_age;
- pid_t pid;
- int fd;
- int out_fd;
- struct event event;
- int retval;
+ pid_t pid;
+ int fd;
+ int out_fd;
+ struct event event;
+ int retval;
- struct timeval creation_time;
- struct timeval activity_time;
+ struct timeval creation_time;
+ struct timeval activity_time;
- struct environ *environ;
+ struct environ *environ;
struct format_job_tree *jobs;
- char *title;
- const char *cwd;
+ char *title;
+ const char *cwd;
- char *term_name;
- int term_features;
- char *term_type;
- char **term_caps;
- u_int term_ncaps;
+ char *term_name;
+ int term_features;
+ char *term_type;
+ char **term_caps;
+ u_int term_ncaps;
- char *ttyname;
- struct tty tty;
+ char *ttyname;
+ struct tty tty;
- size_t written;
- size_t discarded;
- size_t redraw;
+ size_t written;
+ size_t discarded;
+ size_t redraw;
- struct event repeat_timer;
+ struct event repeat_timer;
- struct event click_timer;
- u_int click_button;
- struct mouse_event click_event;
+ struct event click_timer;
+ u_int click_button;
+ struct mouse_event click_event;
- struct status_line status;
+ struct status_line status;
#define CLIENT_TERMINAL 0x1
#define CLIENT_LOGIN 0x2
(CLIENT_DEAD| \
CLIENT_SUSPENDED| \
CLIENT_EXIT)
-#define CLIENT_NODETACHFLAGS \
+#define CLIENT_NODETACHFLAGS \
(CLIENT_DEAD| \
CLIENT_EXIT)
#define CLIENT_NOSIZEFLAGS \
(CLIENT_DEAD| \
CLIENT_SUSPENDED| \
CLIENT_EXIT)
- uint64_t flags;
+ uint64_t flags;
enum {
CLIENT_EXIT_RETURN,
CLIENT_EXIT_SHUTDOWN,
CLIENT_EXIT_DETACH
- } exit_type;
- enum msgtype exit_msgtype;
- char *exit_session;
- char *exit_message;
-
- struct key_table *keytable;
-
- uint64_t redraw_panes;
-
- int message_ignore_keys;
- int message_ignore_styles;
- char *message_string;
- struct event message_timer;
-
- char *prompt_string;
- struct utf8_data *prompt_buffer;
- char *prompt_last;
- size_t prompt_index;
- prompt_input_cb prompt_inputcb;
- prompt_free_cb prompt_freecb;
- void *prompt_data;
- u_int prompt_hindex[PROMPT_NTYPES];
- enum { PROMPT_ENTRY, PROMPT_COMMAND } prompt_mode;
- struct utf8_data *prompt_saved;
+ } exit_type;
+ enum msgtype exit_msgtype;
+ char *exit_session;
+ char *exit_message;
+
+ struct key_table *keytable;
+
+ uint64_t redraw_panes;
+
+ int message_ignore_keys;
+ int message_ignore_styles;
+ char *message_string;
+ struct event message_timer;
+
+ char *prompt_string;
+ struct utf8_data *prompt_buffer;
+ char *prompt_last;
+ size_t prompt_index;
+ prompt_input_cb prompt_inputcb;
+ prompt_free_cb prompt_freecb;
+ void *prompt_data;
+ u_int prompt_hindex[PROMPT_NTYPES];
+ enum {
+ PROMPT_ENTRY,
+ PROMPT_COMMAND
+ } prompt_mode;
+ struct utf8_data *prompt_saved;
#define PROMPT_SINGLE 0x1
#define PROMPT_NUMERIC 0x2
#define PROMPT_INCREMENTAL 0x4
#define PROMPT_NOFORMAT 0x8
#define PROMPT_KEY 0x10
- int prompt_flags;
- enum prompt_type prompt_type;
- int prompt_cursor;
+ int prompt_flags;
+ enum prompt_type prompt_type;
+ int prompt_cursor;
- struct session *session;
- struct session *last_session;
+ struct session *session;
+ struct session *last_session;
- int references;
+ int references;
- void *pan_window;
- u_int pan_ox;
- u_int pan_oy;
+ void *pan_window;
+ u_int pan_ox;
+ u_int pan_oy;
- overlay_check_cb overlay_check;
- overlay_mode_cb overlay_mode;
- overlay_draw_cb overlay_draw;
- overlay_key_cb overlay_key;
- overlay_free_cb overlay_free;
- overlay_resize_cb overlay_resize;
- void *overlay_data;
- struct event overlay_timer;
+ overlay_check_cb overlay_check;
+ overlay_mode_cb overlay_mode;
+ overlay_draw_cb overlay_draw;
+ overlay_key_cb overlay_key;
+ overlay_free_cb overlay_free;
+ overlay_resize_cb overlay_resize;
+ void *overlay_data;
+ struct event overlay_timer;
- struct client_files files;
+ struct client_files files;
- TAILQ_ENTRY(client) entry;
+ TAILQ_ENTRY(client) entry;
};
TAILQ_HEAD(clients, client);
void proc_kill_peer(struct tmuxpeer *);
void proc_toggle_log(struct tmuxproc *);
pid_t proc_fork_and_daemon(int *);
+uid_t proc_get_peer_uid(struct tmuxpeer *);
/* cfg.c */
extern int cfg_finished;