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 | 154 | ||||
| -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 | 8 | ||||
| -rw-r--r-- | usr.bin/w/w.c | 33 | 
9 files changed, 207 insertions, 91 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..5f9d2670caa3 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -53,79 +53,94 @@ 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; +#ifdef USE_BSM_AUDIT +	bool Aflag; +#endif +	bool 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; +#ifdef USE_BSM_AUDIT +	Aflag = false; +#endif +	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 +149,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 +195,11 @@ main(int argc, char *argv[])  		exit(0);  	} +	if (dflag) { +		dir(pw); +		exit(0); +	} +  	if (Gflag) {  		group(pw, nflag);  		exit(0); @@ -203,6 +220,11 @@ main(int argc, char *argv[])  		exit(0);  	} +	if (sflag) { +		shell(pw); +		exit(0); +	} +  	id_print(pw);  	exit(0);  } @@ -217,7 +239,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 +265,7 @@ pretty(struct passwd *pw)  				(void)printf("rgid\t%u\n", rid);  		}  		(void)printf("groups\t"); -		group(NULL, 1); +		group(NULL, true);  	}  } @@ -366,7 +388,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 +474,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..07663e54534d 100644 --- a/usr.bin/sockstat/main.c +++ b/usr.bin/sockstat/main.c @@ -108,7 +108,8 @@ 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 */ @@ -626,6 +627,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 +679,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)) 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);  	} | 
