=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/format.c,v retrieving revision 1.300 retrieving revision 1.301 diff -c -r1.300 -r1.301 *** src/usr.bin/tmux/format.c 2022/02/22 11:10:41 1.300 --- src/usr.bin/tmux/format.c 2022/03/08 11:28:40 1.301 *************** *** 1,4 **** ! /* $OpenBSD: format.c,v 1.300 2022/02/22 11:10:41 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: format.c,v 1.301 2022/03/08 11:28:40 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott *************** *** 24,29 **** --- 24,30 ---- #include #include #include + #include #include #include #include *************** *** 1387,1392 **** --- 1388,1422 ---- 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) *************** *** 2521,2526 **** --- 2551,2574 ---- 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, *************** *** 2627,2632 **** --- 2675,2686 ---- { "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 }, *************** *** 2905,2910 **** --- 2959,2970 ---- }, { "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