mirror of
https://github.com/tmux/tmux.git
synced 2024-11-17 18:08:51 +00:00
Add formats for client and server UID and user (for multiuser setups).
This commit is contained in:
parent
a731b1a916
commit
98cd8e4cad
@ -31,6 +31,8 @@
|
|||||||
#define LIST_CLIENTS_TEMPLATE \
|
#define LIST_CLIENTS_TEMPLATE \
|
||||||
"#{client_name}: #{session_name} " \
|
"#{client_name}: #{session_name} " \
|
||||||
"[#{client_width}x#{client_height} #{client_termname}] " \
|
"[#{client_width}x#{client_height} #{client_termname}] " \
|
||||||
|
"#{?#{!=:#{client_uid},#{uid}}," \
|
||||||
|
"[user #{?client_user,#{client_user},#{client_uid},}] ,}" \
|
||||||
"#{?client_flags,(,}#{client_flags}#{?client_flags,),}"
|
"#{?client_flags,(,}#{client_flags}#{?client_flags,),}"
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
|
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
|
||||||
|
60
format.c
60
format.c
@ -24,6 +24,7 @@
|
|||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -1387,6 +1388,35 @@ format_cb_client_tty(struct format_tree *ft)
|
|||||||
return (NULL);
|
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. */
|
/* Callback for client_utf8. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_client_utf8(struct format_tree *ft)
|
format_cb_client_utf8(struct format_tree *ft)
|
||||||
@ -2521,6 +2551,24 @@ format_cb_tree_mode_format(__unused struct format_tree *ft)
|
|||||||
return (xstrdup(window_tree_mode.default_format));
|
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. */
|
/* Format table type. */
|
||||||
enum format_table_type {
|
enum format_table_type {
|
||||||
FORMAT_TABLE_STRING,
|
FORMAT_TABLE_STRING,
|
||||||
@ -2627,6 +2675,12 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "client_tty", FORMAT_TABLE_STRING,
|
{ "client_tty", FORMAT_TABLE_STRING,
|
||||||
format_cb_client_tty
|
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,
|
{ "client_utf8", FORMAT_TABLE_STRING,
|
||||||
format_cb_client_utf8
|
format_cb_client_utf8
|
||||||
},
|
},
|
||||||
@ -2906,6 +2960,12 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "tree_mode_format", FORMAT_TABLE_STRING,
|
{ "tree_mode_format", FORMAT_TABLE_STRING,
|
||||||
format_cb_tree_mode_format
|
format_cb_tree_mode_format
|
||||||
},
|
},
|
||||||
|
{ "uid", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_uid
|
||||||
|
},
|
||||||
|
{ "user", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_user
|
||||||
|
},
|
||||||
{ "version", FORMAT_TABLE_STRING,
|
{ "version", FORMAT_TABLE_STRING,
|
||||||
format_cb_version
|
format_cb_version
|
||||||
},
|
},
|
||||||
|
11
proc.c
11
proc.c
@ -55,6 +55,7 @@ struct tmuxpeer {
|
|||||||
|
|
||||||
struct imsgbuf ibuf;
|
struct imsgbuf ibuf;
|
||||||
struct event event;
|
struct event event;
|
||||||
|
uid_t uid;
|
||||||
|
|
||||||
int flags;
|
int flags;
|
||||||
#define PEER_BAD 0x1
|
#define PEER_BAD 0x1
|
||||||
@ -296,6 +297,7 @@ proc_add_peer(struct tmuxproc *tp, int fd,
|
|||||||
void (*dispatchcb)(struct imsg *, void *), void *arg)
|
void (*dispatchcb)(struct imsg *, void *), void *arg)
|
||||||
{
|
{
|
||||||
struct tmuxpeer *peer;
|
struct tmuxpeer *peer;
|
||||||
|
gid_t gid;
|
||||||
|
|
||||||
peer = xcalloc(1, sizeof *peer);
|
peer = xcalloc(1, sizeof *peer);
|
||||||
peer->parent = tp;
|
peer->parent = tp;
|
||||||
@ -306,6 +308,9 @@ proc_add_peer(struct tmuxproc *tp, int fd,
|
|||||||
imsg_init(&peer->ibuf, fd);
|
imsg_init(&peer->ibuf, fd);
|
||||||
event_set(&peer->event, fd, EV_READ, proc_event_cb, peer);
|
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);
|
log_debug("add peer %p: %d (%p)", peer, fd, arg);
|
||||||
TAILQ_INSERT_TAIL(&tp->peers, peer, entry);
|
TAILQ_INSERT_TAIL(&tp->peers, peer, entry);
|
||||||
|
|
||||||
@ -361,3 +366,9 @@ proc_fork_and_daemon(int *fd)
|
|||||||
return (pid);
|
return (pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uid_t
|
||||||
|
proc_get_peer_uid(struct tmuxpeer *peer)
|
||||||
|
{
|
||||||
|
return (peer->uid);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user