diff options
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/cut/cut.c | 4 | ||||
| -rw-r--r-- | usr.bin/id/id.1 | 28 | ||||
| -rw-r--r-- | usr.bin/id/id.c | 148 | ||||
| -rw-r--r-- | usr.bin/kyua/Makefile | 10 | ||||
| -rw-r--r-- | usr.bin/mandoc/mandoc.ucl | 20 | ||||
| -rw-r--r-- | usr.bin/netstat/inet.c | 37 | ||||
| -rw-r--r-- | usr.bin/netstat/main.c | 4 | ||||
| -rw-r--r-- | usr.bin/sockstat/main.c | 178 | ||||
| -rw-r--r-- | usr.bin/sockstat/sockstat.1 | 7 | ||||
| -rw-r--r-- | usr.bin/truss/syscalls.c | 2 | ||||
| -rw-r--r-- | usr.bin/w/w.c | 33 |
11 files changed, 338 insertions, 133 deletions
diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c index 60ff5a31062a..e4e322b4e5c9 100644 --- a/usr.bin/cut/cut.c +++ b/usr.bin/cut/cut.c @@ -448,8 +448,8 @@ f_cut(FILE *fp, const char *fname) break; } if (*pos) - for (i = 0; i < (int)clen; i++) - putchar(p[i - clen]); + (void)fwrite(p - clen, 1, clen, + stdout); } if (ch == '\n') break; diff --git a/usr.bin/id/id.1 b/usr.bin/id/id.1 index b8dafb6650b0..62c941f84798 100644 --- a/usr.bin/id/id.1 +++ b/usr.bin/id/id.1 @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 5, 2011 +.Dd October 23, 2025 .Dt ID 1 .Os .Sh NAME @@ -50,12 +50,18 @@ .Nm .Fl c .Nm +.Fl d +.Op Ar user +.Nm .Fl g Op Fl nr .Op Ar user .Nm .Fl p .Op Ar user .Nm +.Fl s +.Op Ar user +.Nm .Fl u Op Fl nr .Op Ar user .Sh DESCRIPTION @@ -90,6 +96,8 @@ Ignored for compatibility with other implementations. .It Fl c Display current login class. +.It Fl d +Display the home directory of the current or specified user. .It Fl g Display the effective group ID as a number. .It Fl n @@ -128,6 +136,8 @@ Display the real ID for the and .Fl u options instead of the effective ID. +.It Fl s +Display the shell of the current or specified user. .It Fl u Display the effective user ID as a number. .El @@ -174,8 +184,20 @@ bob pts/5 Dec 4 19:51 .Sh STANDARDS The .Nm -function is expected to conform to -.St -p1003.2 . +utility is expected to conform to +.St -p1003.1-2024 . +The +.Fl A , +.Fl M , +.Fl P , +.Fl c , +.Fl d , +.Fl p , +and +.Fl s +options are +.Fx +extensions. .Sh HISTORY The historic diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c index 7112e0dddb91..7ba07daad11e 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -53,79 +53,88 @@ static void pretty(struct passwd *); #ifdef USE_BSM_AUDIT static void auditid(void); #endif -static void group(struct passwd *, int); +static void group(struct passwd *, bool); static void maclabel(void); +static void dir(struct passwd *); +static void shell(struct passwd *); static void usage(void); static struct passwd *who(char *); -static int isgroups, iswhoami; +static bool isgroups, iswhoami; int main(int argc, char *argv[]) { struct group *gr; struct passwd *pw; - int Gflag, Mflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; - int Aflag, cflag; - int error; - const char *myname; + bool Aflag, Gflag, Mflag, Pflag; + bool cflag, dflag, gflag, nflag, pflag, rflag, sflag, uflag; + int ch, combo, error, id; + const char *myname, *optstr; char loginclass[MAXLOGNAME]; - Gflag = Mflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; - Aflag = cflag = 0; + Aflag = Gflag = Mflag = Pflag = false; + cflag = dflag = gflag = nflag = pflag = rflag = sflag = uflag = false; - myname = strrchr(argv[0], '/'); - myname = (myname != NULL) ? myname + 1 : argv[0]; + myname = getprogname(); + optstr = "AGMPacdgnprsu"; if (strcmp(myname, "groups") == 0) { - isgroups = 1; - Gflag = nflag = 1; + isgroups = true; + optstr = ""; + Gflag = nflag = true; } else if (strcmp(myname, "whoami") == 0) { - iswhoami = 1; - uflag = nflag = 1; + iswhoami = true; + optstr = ""; + uflag = nflag = true; } - while ((ch = getopt(argc, argv, - (isgroups || iswhoami) ? "" : "APGMacgnpru")) != -1) + while ((ch = getopt(argc, argv, optstr)) != -1) { switch(ch) { #ifdef USE_BSM_AUDIT case 'A': - Aflag = 1; + Aflag = true; break; #endif case 'G': - Gflag = 1; + Gflag = true; break; case 'M': - Mflag = 1; + Mflag = true; break; case 'P': - Pflag = 1; + Pflag = true; break; case 'a': break; case 'c': - cflag = 1; + cflag = true; + break; + case 'd': + dflag = true; break; case 'g': - gflag = 1; + gflag = true; break; case 'n': - nflag = 1; + nflag = true; break; case 'p': - pflag = 1; + pflag = true; break; case 'r': - rflag = 1; + rflag = true; + break; + case 's': + sflag = true; break; case 'u': - uflag = 1; + uflag = true; break; - case '?': default: usage(); } + } argc -= optind; argv += optind; @@ -134,16 +143,13 @@ main(int argc, char *argv[]) if ((cflag || Aflag || Mflag) && argc > 0) usage(); - switch(Aflag + Gflag + Mflag + Pflag + gflag + pflag + uflag) { - case 1: - break; - case 0: - if (!nflag && !rflag) - break; - /* FALLTHROUGH */ - default: + combo = Aflag + Gflag + Mflag + Pflag + gflag + pflag + uflag; + if (combo + dflag + sflag > 1) + usage(); + if (combo > 1) + usage(); + if (combo == 0 && (nflag || rflag)) usage(); - } pw = *argv ? who(*argv) : NULL; @@ -183,6 +189,11 @@ main(int argc, char *argv[]) exit(0); } + if (dflag) { + dir(pw); + exit(0); + } + if (Gflag) { group(pw, nflag); exit(0); @@ -203,6 +214,11 @@ main(int argc, char *argv[]) exit(0); } + if (sflag) { + shell(pw); + exit(0); + } + id_print(pw); exit(0); } @@ -217,7 +233,7 @@ pretty(struct passwd *pw) if (pw) { (void)printf("uid\t%s\n", pw->pw_name); (void)printf("groups\t"); - group(pw, 1); + group(pw, true); } else { if ((login = getlogin()) == NULL) err(1, "getlogin"); @@ -243,7 +259,7 @@ pretty(struct passwd *pw) (void)printf("rgid\t%u\n", rid); } (void)printf("groups\t"); - group(NULL, 1); + group(NULL, true); } } @@ -366,7 +382,7 @@ auditid(void) #endif static void -group(struct passwd *pw, int nflag) +group(struct passwd *pw, bool nflag) { struct group *gr; int cnt, id, lastid, ngroups; @@ -452,41 +468,57 @@ who(char *u) static void pline(struct passwd *pw) { - - if (!pw) { + if (pw == NULL) { if ((pw = getpwuid(getuid())) == NULL) err(1, "getpwuid"); } - (void)printf("%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n", pw->pw_name, - pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class, - (long)pw->pw_change, (long)pw->pw_expire, pw->pw_gecos, - pw->pw_dir, pw->pw_shell); + pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class, + (long)pw->pw_change, (long)pw->pw_expire, pw->pw_gecos, + pw->pw_dir, pw->pw_shell); } +static void +dir(struct passwd *pw) +{ + if (pw == NULL) { + if ((pw = getpwuid(getuid())) == NULL) + err(1, "getpwuid"); + } + printf("%s\n", pw->pw_dir); +} static void -usage(void) +shell(struct passwd *pw) { + if (pw == NULL) { + if ((pw = getpwuid(getuid())) == NULL) + err(1, "getpwuid"); + } + printf("%s\n", pw->pw_shell); +} +static void +usage(void) +{ if (isgroups) (void)fprintf(stderr, "usage: groups [user]\n"); else if (iswhoami) (void)fprintf(stderr, "usage: whoami\n"); else - (void)fprintf(stderr, "%s\n%s%s\n%s\n%s\n%s\n%s\n%s\n%s\n", - "usage: id [user]", + (void)fprintf(stderr, + "usage: id [user]\n" #ifdef USE_BSM_AUDIT - " id -A\n", -#else - "", + " id -A\n" #endif - " id -G [-n] [user]", - " id -M", - " id -P [user]", - " id -c", - " id -g [-nr] [user]", - " id -p [user]", - " id -u [-nr] [user]"); + " id -G [-n] [user]\n" + " id -M\n" + " id -P [user]\n" + " id -c\n" + " id -d [user]\n" + " id -g [-nr] [user]\n" + " id -p [user]\n" + " id -s [user]\n" + " id -u [-nr] [user]\n"); exit(1); } diff --git a/usr.bin/kyua/Makefile b/usr.bin/kyua/Makefile index 178a1d083b79..d6131651afbf 100644 --- a/usr.bin/kyua/Makefile +++ b/usr.bin/kyua/Makefile @@ -182,25 +182,25 @@ FILESGROUPS+= EXAMPLES CONFS= kyua.conf-default CONFSDIR= ${KYUA_CONFDIR} CONFSNAME= kyua.conf -CONFSDIRTAGS= package=tests +CONFSDIRTAGS= package=kyua DOCS= AUTHORS CONTRIBUTORS LICENSE DOCSDIR= ${KYUA_DOCDIR} -DOCSTAGS= package=tests +DOCSTAGS= package=kyua EXAMPLES= Kyuafile.top kyua.conf EXAMPLESDIR= ${KYUA_EGDIR} -EXAMPLESTAGS= package=tests +EXAMPLESTAGS= package=kyua .PATH: ${KYUA_SRCDIR}/examples MISC= context.html index.html report.css test_result.html MISCDIR= ${KYUA_MISCDIR} -MISCTAGS= package=tests +MISCTAGS= package=kyua .PATH: ${KYUA_SRCDIR}/misc STORE= migrate_v1_v2.sql migrate_v2_v3.sql schema_v3.sql STOREDIR= ${KYUA_STOREDIR} -STORETAGS= package=tests +STORETAGS= package=kyua .PATH: ${KYUA_SRCDIR}/store CLEANFILES+= ${MAN} diff --git a/usr.bin/mandoc/mandoc.ucl b/usr.bin/mandoc/mandoc.ucl index f320b6f547fd..75b8123d55cc 100644 --- a/usr.bin/mandoc/mandoc.ucl +++ b/usr.bin/mandoc/mandoc.ucl @@ -1,10 +1,14 @@ -path_glob: "/usr/share/man/*" +path_glob: [ + "/usr/share/man/*", + "/usr/share/openssl/man/*", +] cleanup: { type: lua sandbox: false script: <<EOD os.remove("/usr/share/man/mandoc.db") + os.remove("/usr/share/openssl/man/mandoc.db") EOD } @@ -12,7 +16,17 @@ trigger: { type: lua sandbox: false script: <<EOD - print("Generating apropos(1) database...") - pkg.exec({"/usr/bin/makewhatis", "/usr/share/man"}) + + local dirs = { + "/usr/share/man", + "/usr/share/openssl/man", + } + + for _,dir in ipairs(dirs) do + if pkg.stat(dir) then + print("Generating apropos(1) database for "..dir.."...") + pkg.exec({"/usr/bin/makewhatis", dir}) + end + end EOD } diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 5f36b1599cad..dee245b63a87 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -83,7 +83,7 @@ static void inetprint(const char *, struct in_addr *, int, const char *, int, const int); #endif #ifdef INET6 -static int udp_done, tcp_done, sdp_done; +static int udp_done, udplite_done, tcp_done, sdp_done; #endif /* INET6 */ static int @@ -100,6 +100,9 @@ pcblist_sysctl(int proto, const char *name, char **bufp) case IPPROTO_UDP: mibvar = "net.inet.udp.pcblist"; break; + case IPPROTO_UDPLITE: + mibvar = "net.inet.udplite.pcblist"; + break; default: mibvar = "net.inet.raw.pcblist"; break; @@ -222,11 +225,18 @@ protopr(u_long off, const char *name, int af1, int proto) udp_done = 1; #endif break; + case IPPROTO_UDPLITE: +#ifdef INET6 + if (udplite_done != 0) + return; + else + udplite_done = 1; +#endif + break; } if (!pcblist_sysctl(proto, name, &buf)) return; - if (istcp && (cflag || Cflag)) { fnamelen = strlen("Stack"); cnamelen = strlen("CC"); @@ -318,18 +328,18 @@ protopr(u_long off, const char *name, int af1, int proto) "Proto", "Listen", "Local Address"); else if (Tflag) xo_emit((Aflag && !Wflag) ? - "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%s}" : + "{T:/%-9.9s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%s}" : ((!Wflag || af1 == AF_INET) ? - "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%s}" : - "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%s}"), + "{T:/%-9.9s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%s}" : + "{T:/%-9.9s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%s}"), "Proto", "Rexmit", "OOORcv", "0-win", "Local Address", "Foreign Address"); else { xo_emit((Aflag && !Wflag) ? - "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%-18.18s}" : + "{T:/%-9.9s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%-18.18s}" : ((!Wflag || af1 == AF_INET) ? - "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%-22.22s}" : - "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%-45.45s}"), + "{T:/%-9.9s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%-22.22s}" : + "{T:/%-9.9s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%-45.45s}"), "Proto", "Recv-Q", "Send-Q", "Local Address", "Foreign Address"); if (!xflag && !Rflag) @@ -382,9 +392,14 @@ protopr(u_long off, const char *name, int af1, int proto) vchar = ((inp->inp_vflag & INP_IPV4) != 0) ? "4" : ""; if (istcp && (tp->t_flags & TF_TOE) != 0) - xo_emit("{:protocol/%-3.3s%-2.2s/%s%s} ", "toe", vchar); - else - xo_emit("{:protocol/%-3.3s%-2.2s/%s%s} ", name, vchar); + xo_emit("{:protocol/%-3.3s%-6.6s/%s%s} ", "toe", vchar); + else { + int len; + + len = max (2, 9 - strlen(name)); + xo_emit("{:protocol/%.7s%-*.*s/%s%s} ", name, len, len, + vchar); + } if (Lflag) { char buf1[33]; diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index e8f657006982..79830049948a 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -83,6 +83,8 @@ static struct protox { tcp_stats, NULL, "tcp", 1, IPPROTO_TCP }, { -1 , N_UDPSTAT, 1, protopr, udp_stats, NULL, "udp", 1, IPPROTO_UDP }, + { -1, -1, 1, protopr, + NULL, NULL, "udplite", 1, IPPROTO_UDPLITE }, #ifdef SCTP { -1, N_SCTPSTAT, 1, sctp_protopr, sctp_stats, NULL, "sctp", 1, IPPROTO_SCTP }, @@ -131,6 +133,8 @@ static struct protox ip6protox[] = { tcp_stats, NULL, "tcp", 1, IPPROTO_TCP }, { -1 , N_UDPSTAT, 1, protopr, udp_stats, NULL, "udp", 1, IPPROTO_UDP }, + { -1, -1, 1, protopr, + NULL, NULL, "udplite", 1, IPPROTO_UDPLITE }, { -1 , N_IP6STAT, 1, protopr, ip6_stats, ip6_ifstats, "ip6", 1, IPPROTO_RAW }, { -1 , N_ICMP6STAT, 1, protopr, diff --git a/usr.bin/sockstat/main.c b/usr.bin/sockstat/main.c index abb73acafc2f..1f174d827e1a 100644 --- a/usr.bin/sockstat/main.c +++ b/usr.bin/sockstat/main.c @@ -88,6 +88,7 @@ static bool opt_A; /* Show kernel address of pcb */ static bool opt_b; /* Show BBLog state */ static bool opt_C; /* Show congestion control */ static bool opt_c; /* Show connected sockets */ +static bool opt_F; /* Show sockets for selected user only */ static bool opt_f; /* Show FIB numbers */ static bool opt_I; /* Show spliced socket addresses */ static bool opt_i; /* Show inp_gencnt */ @@ -108,12 +109,19 @@ static bool show_path_state = false; /* * Default protocols to use if no -P was defined. */ -static const char *default_protos[] = {"sctp", "tcp", "udp", "divert" }; +static const char *default_protos[] = {"sctp", "tcp", "udp", "udplite", + "divert" }; static size_t default_numprotos = nitems(default_protos); static int *protos; /* protocols to use */ static size_t numprotos; /* allocated size of protos[] */ +/* + * Show sockets for user username or UID specified + */ +static char *filter_user_optarg = NULL; /* saved optarg for username/UID resolving */ +static uid_t filter_user_uid; /* UID to show sockets for */ + struct addr { union { struct sockaddr_storage address; @@ -216,6 +224,18 @@ _enforce_ksize(size_t received_size, size_t expected_size, const char *struct_na } #define enforce_ksize(_sz, _struct) (_enforce_ksize(_sz, sizeof(_struct), #_struct)) +static inline bool +filtered_uid(uid_t i_uid) +{ + return ((i_uid) == filter_user_uid); +} + +static inline bool +need_nosocks(void) +{ + return !(opt_F || (opt_j >= 0)); +} + static int get_proto_type(const char *proto) { @@ -626,6 +646,10 @@ gather_inet(int proto) varname = "net.inet.udp.pcblist"; protoname = "udp"; break; + case IPPROTO_UDPLITE: + varname = "net.inet.udplite.pcblist"; + protoname = "udplite"; + break; case IPPROTO_DIVERT: varname = "net.inet.divert.pcblist"; protoname = "div"; @@ -674,6 +698,7 @@ gather_inet(int proto) protoname = xtp->t_flags & TF_TOE ? "toe" : "tcp"; break; case IPPROTO_UDP: + case IPPROTO_UDPLITE: case IPPROTO_DIVERT: xip = (struct xinpcb *)xig; if (!check_ksize(xip->xi_len, struct xinpcb)) @@ -752,7 +777,8 @@ gather_inet(int proto) if (sock->socket != 0) RB_INSERT(socks_t, &socks, sock); else - SLIST_INSERT_HEAD(&nosocks, sock, socket_list); + if (need_nosocks()) + SLIST_INSERT_HEAD(&nosocks, sock, socket_list); } out: free(buf); @@ -856,6 +882,8 @@ getfiles(void) struct xfile *xfiles; size_t len, olen; + int filenum = 0; + olen = len = sizeof(*xfiles); if ((xfiles = malloc(len)) == NULL) xo_err(1, "malloc()"); @@ -874,14 +902,23 @@ getfiles(void) if ((files = malloc(nfiles * sizeof(struct file))) == NULL) xo_err(1, "malloc()"); + /* Fill files structure, optionally for specified user */ for (int i = 0; i < nfiles; i++) { - files[i].xf_data = xfiles[i].xf_data; - files[i].xf_pid = xfiles[i].xf_pid; - files[i].xf_uid = xfiles[i].xf_uid; - files[i].xf_fd = xfiles[i].xf_fd; - RB_INSERT(files_t, &ftree, &files[i]); + if (opt_F && !filtered_uid(xfiles[i].xf_uid)) + continue; + files[filenum].xf_data = xfiles[i].xf_data; + files[filenum].xf_pid = xfiles[i].xf_pid; + files[filenum].xf_uid = xfiles[i].xf_uid; + files[filenum].xf_fd = xfiles[i].xf_fd; + RB_INSERT(files_t, &ftree, &files[filenum]); + filenum++; } + /* Adjust global nfiles to match the number of files we + * actually filled into files[] array + */ + nfiles = filenum; + free(xfiles); } @@ -1578,6 +1615,24 @@ display_sock(struct sock *s, struct col_widths *cw, char *buf, size_t bufsize) static void display(void) { + static const char *__HDR_USER="USER", + *__HDR_COMMAND="COMMAND", + *__HDR_PID="PID", + *__HDR_FD="FD", + *__HDR_PROTO="PROTO", + *__HDR_LOCAL_ADDRESS="LOCAL ADDRESS", + *__HDR_FOREIGN_ADDRESS="FOREIGN ADDRESS", + *__HDR_PCB_KVA="PCB KVA", + *__HDR_FIB="FIB", + *__HDR_SPLICE_ADDRESS="SPLICE ADDRESS", + *__HDR_ID="ID", + *__HDR_ENCAPS="ENCAPS", + *__HDR_PATH_STATE="PATH STATE", + *__HDR_CONN_STATE="CONN STATE", + *__HDR_BBLOG_STATE="BBLOG STATE", + *__HDR_STACK="STACK", + *__HDR_CC="CC"; + struct passwd *pwd; struct file *xf; struct sock *s; @@ -1592,23 +1647,23 @@ display(void) if (!is_xo_style_encoding) { cw = (struct col_widths) { - .user = strlen("USER"), + .user = strlen(__HDR_USER), .command = 10, - .pid = strlen("PID"), - .fd = strlen("FD"), - .proto = strlen("PROTO"), - .local_addr = opt_w ? strlen("LOCAL ADDRESS") : 21, - .foreign_addr = opt_w ? strlen("FOREIGN ADDRESS") : 21, + .pid = strlen(__HDR_PID), + .fd = strlen(__HDR_FD), + .proto = strlen(__HDR_PROTO), + .local_addr = opt_w ? strlen(__HDR_LOCAL_ADDRESS) : 21, + .foreign_addr = opt_w ? strlen(__HDR_FOREIGN_ADDRESS) : 21, .pcb_kva = 18, - .fib = strlen("FIB"), - .splice_address = strlen("SPLICE ADDRESS"), - .inp_gencnt = strlen("ID"), - .encaps = strlen("ENCAPS"), - .path_state = strlen("PATH STATE"), - .conn_state = strlen("CONN STATE"), - .bblog_state = strlen("BBLOG STATE"), - .stack = strlen("STACK"), - .cc = strlen("CC"), + .fib = strlen(__HDR_FIB), + .splice_address = strlen(__HDR_SPLICE_ADDRESS), + .inp_gencnt = strlen(__HDR_ID), + .encaps = strlen(__HDR_ENCAPS), + .path_state = strlen(__HDR_PATH_STATE), + .conn_state = strlen(__HDR_CONN_STATE), + .bblog_state = strlen(__HDR_BBLOG_STATE), + .stack = strlen(__HDR_STACK), + .cc = strlen(__HDR_CC), }; calculate_column_widths(&cw); } else @@ -1619,34 +1674,34 @@ display(void) xo_open_list("socket"); if (!opt_q) { xo_emit("{T:/%-*s} {T:/%-*s} {T:/%*s} {T:/%*s} {T:/%-*s} " - "{T:/%-*s} {T:/%-*s}", cw.user, "USER", cw.command, - "COMMAND", cw.pid, "PID", cw.fd, "FD", cw.proto, - "PROTO", cw.local_addr, "LOCAL ADDRESS", - cw.foreign_addr, "FOREIGN ADDRESS"); + "{T:/%-*s} {T:/%-*s}", cw.user, __HDR_USER, cw.command, + __HDR_COMMAND, cw.pid, __HDR_PID, cw.fd, __HDR_FD, cw.proto, + __HDR_PROTO, cw.local_addr, __HDR_LOCAL_ADDRESS, + cw.foreign_addr, __HDR_FOREIGN_ADDRESS); if (opt_A) - xo_emit(" {T:/%-*s}", cw.pcb_kva, "PCB KVA"); + xo_emit(" {T:/%-*s}", cw.pcb_kva, __HDR_PCB_KVA); if (opt_f) /* RT_MAXFIBS is 65535. */ - xo_emit(" {T:/%*s}", cw.fib, "FIB"); + xo_emit(" {T:/%*s}", cw.fib, __HDR_FIB); if (opt_I) xo_emit(" {T:/%-*s}", cw.splice_address, - "SPLICE ADDRESS"); + __HDR_SPLICE_ADDRESS); if (opt_i) - xo_emit(" {T:/%*s}", cw.inp_gencnt, "ID"); + xo_emit(" {T:/%*s}", cw.inp_gencnt, __HDR_ID); if (opt_U) - xo_emit(" {T:/%*s}", cw.encaps, "ENCAPS"); + xo_emit(" {T:/%*s}", cw.encaps, __HDR_ENCAPS); if (opt_s) { if (show_path_state) xo_emit(" {T:/%-*s}", cw.path_state, - "PATH STATE"); - xo_emit(" {T:/%-*s}", cw.conn_state, "CONN STATE"); + __HDR_PATH_STATE); + xo_emit(" {T:/%-*s}", cw.conn_state, __HDR_CONN_STATE); } if (opt_b) - xo_emit(" {T:/%-*s}", cw.bblog_state, "BBLOG STATE"); + xo_emit(" {T:/%-*s}", cw.bblog_state, __HDR_BBLOG_STATE); if (opt_S) - xo_emit(" {T:/%-*s}", cw.stack, "STACK"); + xo_emit(" {T:/%-*s}", cw.stack, __HDR_STACK); if (opt_C) - xo_emit(" {T:/%-*s}", cw.cc, "CC"); + xo_emit(" {T:/%-*s}", cw.cc, __HDR_CC); xo_emit("\n"); } cap_setpassent(cappwd, 1); @@ -1678,7 +1733,7 @@ display(void) xo_close_instance("socket"); } } - if (opt_j >= 0) + if (!need_nosocks()) goto out; SLIST_FOREACH(s, &nosocks, socket_list) { if (!check_ports(s)) @@ -1769,11 +1824,44 @@ jail_getvnet(int jid) return (vnet); } +/* + * Parse username and/or UID + */ +static bool +parse_filter_user(void) +{ + struct passwd *pwd; + char *ep; + uid_t uid; + bool rv = false; + + uid = (uid_t)strtol(filter_user_optarg, &ep, 10); + + /* Open and/or rewind capsicumized password file */ + cap_setpassent(cappwd, 1); + + if (*ep == '\0') { + /* We have an UID specified, check if it's valid */ + if ((pwd = cap_getpwuid(cappwd, uid)) == NULL) + goto out; + filter_user_uid = uid; + } else { + /* Check if we have a valid username */ + if ((pwd = cap_getpwnam(cappwd, filter_user_optarg)) == NULL) + goto out; + filter_user_uid = pwd->pw_uid; + } + + rv = true; +out: + return (rv); +} + static void usage(void) { xo_error( -"usage: sockstat [--libxo ...] [-46AbCcfIiLlnqSsUuvw] [-j jid] [-p ports]\n" +"usage: sockstat [--libxo ...] [-46AbCcfIiLlnqSsUuvw] [-F uid/username] [-j jid] [-p ports]\n" " [-P protocols]\n"); exit(1); } @@ -1783,8 +1871,8 @@ main(int argc, char *argv[]) { cap_channel_t *capcas; cap_net_limit_t *limit; - const char *pwdcmds[] = { "setpassent", "getpwuid" }; - const char *pwdfields[] = { "pw_name" }; + const char *pwdcmds[] = { "setpassent", "getpwuid", "getpwnam" }; + const char *pwdfields[] = { "pw_name", "pw_uid" }; int protos_defined = -1; int o, i, err; @@ -1797,7 +1885,7 @@ main(int argc, char *argv[]) is_xo_style_encoding = true; } opt_j = -1; - while ((o = getopt(argc, argv, "46AbCcfIij:Llnp:P:qSsUuvw")) != -1) + while ((o = getopt(argc, argv, "46AbCcF:fIij:Llnp:P:qSsUuvw")) != -1) switch (o) { case '4': opt_4 = true; @@ -1817,6 +1905,11 @@ main(int argc, char *argv[]) case 'c': opt_c = true; break; + case 'F': + /* Save optarg for later use when we enter capabilities mode */ + filter_user_optarg = optarg; + opt_F = true; + break; case 'f': opt_f = true; break; @@ -1928,6 +2021,9 @@ main(int argc, char *argv[]) if (cap_pwd_limit_fields(cappwd, pwdfields, nitems(pwdfields)) < 0) xo_err(1, "Unable to apply pwd commands limits"); + if (opt_F && !parse_filter_user()) + xo_errx(1, "Invalid username or UID specified"); + if ((!opt_4 && !opt_6) && protos_defined != -1) opt_4 = opt_6 = true; if (!opt_4 && !opt_6 && !opt_u) diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1 index 1498fb1d88f7..b0fae81ee566 100644 --- a/usr.bin/sockstat/sockstat.1 +++ b/usr.bin/sockstat/sockstat.1 @@ -25,7 +25,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 14, 2025 +.Dd October 29, 2025 .Dt SOCKSTAT 1 .Os .Sh NAME @@ -35,6 +35,7 @@ .Nm .Op Fl -libxo .Op Fl 46AbCcfIiLlnqSsUuvw +.Op Fl F Ar user .Op Fl j Ar jail .Op Fl p Ar ports .Op Fl P Ar protocols @@ -73,6 +74,10 @@ Display the congestion control module, if applicable. This is currently only implemented for TCP. .It Fl c Show connected sockets. +.It Fl F Ar user +Show sockets for specified +.Ar user +(user name or UID) only. .It Fl f Show the FIB number of each socket. .It Fl I diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index 656d642e1f19..7b299bd2e1ff 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -403,7 +403,7 @@ static const struct syscall_decode decoded_syscalls[] = { { .name = "nanosleep", .ret_type = 1, .nargs = 1, .args = { { Timespec, 0 } } }, { .name = "nmount", .ret_type = 1, .nargs = 3, - .args = { { Ptr, 0 }, { UInt, 1 }, { Mountflags, 2 } } }, + .args = { { Iovec | IN, 0 }, { UInt, 1 }, { Mountflags, 2 } } }, { .name = "open", .ret_type = 1, .nargs = 3, .args = { { Name | IN, 0 }, { Open, 1 }, { Octal, 2 } } }, { .name = "openat", .ret_type = 1, .nargs = 4, diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index ac1df96077d3..502bf5a412b9 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -473,7 +473,7 @@ main(int argc, char *argv[]) static void pr_header(time_t *nowp, int nusers) { - char buf[64]; + char buf[64], *s, *e; struct sbuf upbuf; double avenrun[3]; struct timespec tp; @@ -484,8 +484,15 @@ pr_header(time_t *nowp, int nusers) * Print time of day. */ if (strftime(buf, sizeof(buf), - use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)) != 0) - xo_emit("{:time-of-day/%s} ", buf); + use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)) != 0) { + s = buf; + if (xo_get_style(NULL) != XO_STYLE_TEXT) { + /* trim leading whitespace */ + while (isspace((unsigned char)*s)) + s++; + } + xo_emit("{:time-of-day/%s} ", s); + } /* * Print how long system has been up. */ @@ -516,21 +523,31 @@ pr_header(time_t *nowp, int nusers) if (days > 0) sbuf_printf(&upbuf, " %ld day%s,", - days, days > 1 ? "s" : ""); + days, days > 1 ? "s" : ""); if (hrs > 0 && mins > 0) sbuf_printf(&upbuf, " %2ld:%02ld,", hrs, mins); else if (hrs > 0) sbuf_printf(&upbuf, " %ld hr%s,", - hrs, hrs > 1 ? "s" : ""); + hrs, hrs > 1 ? "s" : ""); else if (mins > 0) sbuf_printf(&upbuf, " %ld min%s,", - mins, mins > 1 ? "s" : ""); + mins, mins > 1 ? "s" : ""); else sbuf_printf(&upbuf, " %ld sec%s,", - secs, secs > 1 ? "s" : ""); + secs, secs > 1 ? "s" : ""); if (sbuf_finish(&upbuf) != 0) xo_err(1, "Could not generate output"); - xo_emit("{:uptime-human/%s}", sbuf_data(&upbuf)); + s = sbuf_data(&upbuf); + if (xo_get_style(NULL) != XO_STYLE_TEXT) { + e = s + sbuf_len(&upbuf) - 1; + /* trim leading whitespace */ + while (isspace((unsigned char)*s)) + s++; + /* trim trailing comma */ + if (e > s && *e == ',') + *e = '\0'; + } + xo_emit("{:uptime-human/%s}", s); sbuf_delete(&upbuf); } |
