summaryrefslogtreecommitdiff
path: root/usr/src/cmd
diff options
context:
space:
mode:
authorKeith M Wesolowski <wesolows@foobazco.org>2013-10-10 23:23:15 +0000
committerKeith M Wesolowski <wesolows@foobazco.org>2013-10-10 23:32:17 +0000
commite0b0bfaae7148432e8012c03c28865a062269b8a (patch)
tree8eca098b56f70c0163da0d70811cd8fedd72b4f5 /usr/src/cmd
parent7b4aafc0bae4c5843494076dae7433ef7f3e8169 (diff)
parent746f551ddc191f00808cd4121966c1ee42d5b74f (diff)
downloadillumos-joyent-e0b0bfaae7148432e8012c03c28865a062269b8a.tar.gz
[illumos-gate merge]
commit 746f551ddc191f00808cd4121966c1ee42d5b74f 2989 LOGNAME_MAX should be increased to 32 (fix gcc build) commit 23b68ef4aef54d7487e138ec22eafdfc83844017 4016 disk-monitor should activate fault/fail indicators (remove build artifact) commit ad7ed3fec423fe5215f6da8888d44a36514ee898 4182 proto_promisc* miss calls to mac_perim_exit commit 5691611ed44f54317a0e6ff4526c4cc0d8bca9b3 2989 LOGNAME_MAX should be increased to 32 (missing file) commit 0a1278f26ea4b7c8c0285d4f2d6c5b680904aa01 2989 LOGNAME_MAX should be increased to 32 1166 useradd warns on names with more than 8 chars Conflicts: usr/src/cmd/passwd/passwd.c (OS-1836, superceded) usr/src/man/man1m/prstat.1m (OS-1044, keep) usr/src/lib/libc/port/gen/getlogin.c (OS-1836, superceded) usr/src/head/unistd.h (OS-1836, superceded) usr/src/cmd/prstat/prutil.c (OS-1044, keep) usr/src/cmd/prstat/prstat.c (OS-1044, keep)
Diffstat (limited to 'usr/src/cmd')
-rw-r--r--usr/src/cmd/init/init.c179
-rw-r--r--usr/src/cmd/last/last.c49
-rw-r--r--usr/src/cmd/newtask/newtask.c6
-rw-r--r--usr/src/cmd/oamuser/inc/users.h3
-rw-r--r--usr/src/cmd/oamuser/lib/vlogin.c42
-rw-r--r--usr/src/cmd/oamuser/user/Makefile6
-rw-r--r--usr/src/cmd/oamuser/user/messages.c5
-rw-r--r--usr/src/cmd/oamuser/user/messages.h7
-rw-r--r--usr/src/cmd/oamuser/user/useradd.c7
-rw-r--r--usr/src/cmd/oamuser/user/useradd.dfl33
-rw-r--r--usr/src/cmd/oamuser/user/usermod.c8
-rw-r--r--usr/src/cmd/passwd/passwd.c2
-rw-r--r--usr/src/cmd/prstat/prstat.c51
-rw-r--r--usr/src/cmd/prstat/prstat.h3
-rw-r--r--usr/src/cmd/prstat/prtable.c23
-rw-r--r--usr/src/cmd/prstat/prtable.h4
-rw-r--r--usr/src/cmd/prstat/prutil.c39
-rw-r--r--usr/src/cmd/prstat/prutil.h6
-rw-r--r--usr/src/cmd/ps/ps.c203
-rw-r--r--usr/src/cmd/pwck/pwck.c13
-rw-r--r--usr/src/cmd/sgs/error/i386/Makefile4
-rw-r--r--usr/src/cmd/sgs/error/sparc/Makefile4
-rw-r--r--usr/src/cmd/w/w.c23
-rw-r--r--usr/src/cmd/wall/wall.c31
-rw-r--r--usr/src/cmd/who/who.c52
-rw-r--r--usr/src/cmd/whodo/whodo.c37
26 files changed, 569 insertions, 271 deletions
diff --git a/usr/src/cmd/init/init.c b/usr/src/cmd/init/init.c
index d7c8853a08..f6f8bccdbb 100644
--- a/usr/src/cmd/init/init.c
+++ b/usr/src/cmd/init/init.c
@@ -20,6 +20,8 @@
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
*/
@@ -140,6 +142,7 @@
#define FALSE 0
#define FAILURE -1
+#define UT_USER_SZ 32 /* Size of a utmpx ut_user field */
#define UT_LINE_SZ 32 /* Size of a utmpx ut_line field */
#define CHECK_SVC SCF_INSTANCE_FS_MINIMAL
@@ -1605,11 +1608,11 @@ getcmd(struct CMD_LINE *cmd, char *shcmd)
for (proceed = TRUE, ptr = shcmd, state = ID, lastc = '\0';
proceed && c != EOF;
lastc = c, c = fgetc(fp_inittab)) {
- /* If we're not in the FAILURE state and haven't */
- /* yet reached the shell command field, process */
- /* the line, otherwise just look for a real end */
- /* of line. */
- if (state != FAILURE && state != COMMAND) {
+ /* If we're not in the FAILURE state and haven't */
+ /* yet reached the shell command field, process */
+ /* the line, otherwise just look for a real end */
+ /* of line. */
+ if (state != FAILURE && state != COMMAND) {
/*
* Squeeze out spaces and tabs.
*/
@@ -1645,9 +1648,9 @@ getcmd(struct CMD_LINE *cmd, char *shcmd)
* to the next field.
*/
if (c == ':') {
- switch (state) {
+ switch (state) {
- case ID :
+ case ID :
/*
* Check to see that there are only
* 1 to 4 characters for the id.
@@ -1661,7 +1664,7 @@ getcmd(struct CMD_LINE *cmd, char *shcmd)
}
break;
- case LEVELS :
+ case LEVELS :
/*
* Build a mask for all the levels for
* which this command will be legal.
@@ -1682,7 +1685,7 @@ getcmd(struct CMD_LINE *cmd, char *shcmd)
}
break;
- case ACTION :
+ case ACTION :
/*
* Null terminate the string in shcmd buffer and
* then try to match against legal actions. If
@@ -1693,27 +1696,30 @@ getcmd(struct CMD_LINE *cmd, char *shcmd)
if (ptr == shcmd) {
if (isdigit(cmd->c_id[0]) &&
(cmd->c_id[1] == '\0' ||
- isdigit(cmd->c_id[1])) &&
+ isdigit(cmd->c_id[1])) &&
(cmd->c_id[2] == '\0' ||
- isdigit(cmd->c_id[2])) &&
+ isdigit(cmd->c_id[2])) &&
(cmd->c_id[3] == '\0' ||
- isdigit(cmd->c_id[3])))
- cmd->c_action = M_RESPAWN;
+ isdigit(cmd->c_id[3])))
+ cmd->c_action = M_RESPAWN;
else
- cmd->c_action = M_OFF;
+ cmd->c_action = M_OFF;
} else {
- for (cmd->c_action = 0, i = 0, *ptr = '\0';
- i < sizeof (actions)/sizeof (char *);
- i++) {
+ for (cmd->c_action = 0, i = 0,
+ *ptr = '\0';
+ i <
+ sizeof (actions)/sizeof (char *);
+ i++) {
if (strcmp(shcmd, actions[i]) == 0) {
- if ((cmd->c_levels & MASKSU) &&
- !(act_masks[i] & su_acts))
- cmd->c_action = 0;
- else
- cmd->c_action = act_masks[i];
- break;
+ if ((cmd->c_levels & MASKSU) &&
+ !(act_masks[i] & su_acts))
+ cmd->c_action = 0;
+ else
+ cmd->c_action =
+ act_masks[i];
+ break;
+ }
}
- }
}
/*
@@ -1728,38 +1734,38 @@ getcmd(struct CMD_LINE *cmd, char *shcmd)
}
ptr = shcmd + EXEC;
break;
- }
- continue;
+ }
+ continue;
}
- }
-
- /* If the character is a '\n', then this is the end of a */
- /* line. If the '\n' wasn't preceded by a backslash, */
- /* it is also the end of an inittab command. If it was */
- /* preceded by a backslash then the next line is a */
- /* continuation. Note that the continuation '\n' falls */
- /* through and is treated like other characters and is */
- /* stored in the shell command line. */
- if (c == '\n' && lastc != '\\') {
- proceed = FALSE;
- *ptr = '\0';
- break;
- }
+ }
+
+ /* If the character is a '\n', then this is the end of a */
+ /* line. If the '\n' wasn't preceded by a backslash, */
+ /* it is also the end of an inittab command. If it was */
+ /* preceded by a backslash then the next line is a */
+ /* continuation. Note that the continuation '\n' falls */
+ /* through and is treated like other characters and is */
+ /* stored in the shell command line. */
+ if (c == '\n' && lastc != '\\') {
+ proceed = FALSE;
+ *ptr = '\0';
+ break;
+ }
- /* For all other characters just stuff them into the */
- /* command as long as there aren't too many of them. */
- /* Make sure there is room for a terminating '\0' also. */
- if (ptr >= shcmd + MAXCMDL - 1)
+ /* For all other characters just stuff them into the */
+ /* command as long as there aren't too many of them. */
+ /* Make sure there is room for a terminating '\0' also. */
+ if (ptr >= shcmd + MAXCMDL - 1)
state = FAILURE;
- else
+ else
*ptr++ = (char)c;
- /* If the character we just stored was a quoted */
- /* backslash, then change "c" to '\0', so that this */
- /* backslash will not cause a subsequent '\n' to appear */
- /* quoted. In otherwords '\' '\' '\n' is the real end */
- /* of a command, while '\' '\n' is a continuation. */
- if (c == '\\' && lastc == '\\')
+ /* If the character we just stored was a quoted */
+ /* backslash, then change "c" to '\0', so that this */
+ /* backslash will not cause a subsequent '\n' to appear */
+ /* quoted. In otherwords '\' '\' '\n' is the real end */
+ /* of a command, while '\' '\n' is a continuation. */
+ if (c == '\\' && lastc == '\\')
c = '\0';
}
@@ -2112,7 +2118,9 @@ boot_init()
"Command\n\"%s\"\n failed to execute. errno = %d (exec of shell failed)\n",
cmd.c_command, errno);
exit(1);
- } else while (waitproc(process) == FAILURE);
+ } else
+ while (waitproc(process) == FAILURE)
+ ;
process->p_flags = 0;
st_write();
}
@@ -2810,8 +2818,7 @@ static char *
prog_name(char *string)
{
char *ptr, *ptr2;
- /* XXX - utmp - fix name length */
- static char word[_POSIX_LOGIN_NAME_MAX];
+ static char word[UT_USER_SZ + 1];
/*
* Search for the first word skipping leading spaces and tabs.
@@ -2846,8 +2853,7 @@ prog_name(char *string)
* Copy out up to the size of the "ut_user" array into "word",
* null terminate it and return a pointer to it.
*/
- /* XXX - utmp - fix name length */
- for (ptr2 = &word[0]; ptr2 < &word[_POSIX_LOGIN_NAME_MAX - 1] &&
+ for (ptr2 = &word[0]; ptr2 < &word[UT_USER_SZ] &&
ptr < string; /* CSTYLED */)
*ptr2++ = *ptr++;
@@ -2899,22 +2905,22 @@ get_ioctl_syscon()
IOCTLSYSCON);
} else {
- i = fscanf(fp,
+ i = fscanf(fp,
"%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x",
- &iflags, &oflags, &cflags, &lflags,
- &cc[0], &cc[1], &cc[2], &cc[3], &cc[4], &cc[5], &cc[6],
- &cc[7], &cc[8], &cc[9], &cc[10], &cc[11], &cc[12], &cc[13],
- &cc[14], &cc[15], &cc[16], &cc[17]);
-
- if (i == 22) {
- stored_syscon_termios.c_iflag = iflags;
- stored_syscon_termios.c_oflag = oflags;
- stored_syscon_termios.c_cflag = cflags;
- stored_syscon_termios.c_lflag = lflags;
- for (i = 0; i < 18; i++)
- stored_syscon_termios.c_cc[i] = (char)cc[i];
- valid_format = 1;
- } else if (i == 13) {
+ &iflags, &oflags, &cflags, &lflags,
+ &cc[0], &cc[1], &cc[2], &cc[3], &cc[4], &cc[5], &cc[6],
+ &cc[7], &cc[8], &cc[9], &cc[10], &cc[11], &cc[12], &cc[13],
+ &cc[14], &cc[15], &cc[16], &cc[17]);
+
+ if (i == 22) {
+ stored_syscon_termios.c_iflag = iflags;
+ stored_syscon_termios.c_oflag = oflags;
+ stored_syscon_termios.c_cflag = cflags;
+ stored_syscon_termios.c_lflag = lflags;
+ for (i = 0; i < 18; i++)
+ stored_syscon_termios.c_cc[i] = (char)cc[i];
+ valid_format = 1;
+ } else if (i == 13) {
rewind(fp);
i = fscanf(fp, "%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x",
&iflags, &oflags, &cflags, &lflags, &ldisc, &cc[0], &cc[1],
@@ -2931,12 +2937,12 @@ get_ioctl_syscon()
for (i = 0; i < 8; i++)
stored_syscon_termios.c_cc[i] = (char)cc[i];
valid_format = 1;
- }
- (void) fclose(fp);
+ }
+ (void) fclose(fp);
- /* If the file is badly formatted, use the default settings. */
- if (!valid_format)
- stored_syscon_termios = dflt_termios;
+ /* If the file is badly formatted, use the default settings. */
+ if (!valid_format)
+ stored_syscon_termios = dflt_termios;
}
/* If the file had a bad format, rewrite it later. */
@@ -3837,7 +3843,8 @@ increase_proc_table_size()
*/
do
ptr = realloc(g_state, g_state_sz + delta);
- while (ptr == NULL && errno == EAGAIN);
+ while (ptr == NULL && errno == EAGAIN)
+ ;
if (ptr != NULL) {
/* ensure that the new part is initialized to zero */
@@ -3944,13 +3951,15 @@ st_init()
/* Get the size of the file. */
do
ret = fstat(st_fd, &stb);
- while (ret == -1 && errno == EINTR);
+ while (ret == -1 && errno == EINTR)
+ ;
if (ret == -1)
goto new_state;
do
g_state = malloc(stb.st_size);
- while (g_state == NULL && errno == EAGAIN);
+ while (g_state == NULL && errno == EAGAIN)
+ ;
if (g_state == NULL)
goto new_state;
@@ -3996,7 +4005,8 @@ new_state:
((init_num_proc - 1) * sizeof (struct PROC_TABLE));
do
g_state = calloc(1, g_state_sz);
- while (g_state == NULL && errno == EAGAIN);
+ while (g_state == NULL && errno == EAGAIN)
+ ;
if (g_state == NULL) {
/* Fatal error! */
exit(errno);
@@ -4104,7 +4114,8 @@ contract_make_template(uint_t info, uint_t critical, uint_t fatal,
do
fd = open64(CTFS_ROOT "/process/template", O_RDWR);
- while (fd < 0 && errno == EINTR);
+ while (fd < 0 && errno == EINTR)
+ ;
if (fd < 0) {
console(B_TRUE, "Couldn't create process template: %s.\n",
strerror(errno));
@@ -4201,7 +4212,8 @@ contracts_init()
*/
do
fd = open64(CTFS_ROOT "/process/pbundle", O_RDONLY);
- while (fd < 0 && errno == EINTR);
+ while (fd < 0 && errno == EINTR)
+ ;
if (fd < 0) {
console(B_TRUE,
"Couldn't open process pbundle: %s. Core smf(5) services "
@@ -4234,7 +4246,8 @@ contract_getfile(ctid_t id, const char *name, int oflag)
do
fd = contract_open(id, "process", name, oflag);
- while (fd < 0 && errno == EINTR);
+ while (fd < 0 && errno == EINTR)
+ ;
if (fd < 0)
console(B_TRUE, "Couldn't open %s for contract %ld: %s.\n",
diff --git a/usr/src/cmd/last/last.c b/usr/src/cmd/last/last.c
index 10a52b7512..26041d1c1a 100644
--- a/usr/src/cmd/last/last.c
+++ b/usr/src/cmd/last/last.c
@@ -20,6 +20,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -39,8 +41,6 @@
* contributors.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* last
*/
@@ -58,13 +58,16 @@
#include <ctype.h>
/*
- * NMAX, LMAX and HMAX are set to these values for now. They
- * should be much higher because of the max allowed limit in
- * utmpx.h
+ * Use the full lengths from utmpx for NMAX, LMAX and HMAX .
*/
-#define NMAX 8
-#define LMAX 12
+#define NMAX (sizeof (((struct utmpx *)0)->ut_user))
+#define LMAX (sizeof (((struct utmpx *)0)->ut_line))
#define HMAX (sizeof (((struct utmpx *)0)->ut_host))
+
+/* Print minimum field widths. */
+#define LOGIN_WIDTH 8
+#define LINE_WIDTH 12
+
#define SECDAY (24*60*60)
#define CHUNK_SIZE 256
@@ -254,9 +257,9 @@ next_word:
if (want(bp, &ut_host, &ut_user)) {
for (i = 0; i <= lines; i++) {
if (i == lines)
- reallocate_buffer();
+ reallocate_buffer();
if (ttnames[i] == NULL) {
- memory_alloc(i);
+ memory_alloc(i);
/*
* LMAX+HMAX+NMAX+3 bytes have been
* allocated for ttnames[i].
@@ -266,13 +269,13 @@ next_word:
* truncate it to fit ttnames[i].
*/
(void) strlcpy(ttnames[i], bp->ut_line,
- LMAX+1);
+ LMAX+1);
(void) strlcpy(ttnames[i]+LMAX+1,
- ut_host, HMAX+1);
+ ut_host, HMAX+1);
(void) strlcpy(ttnames[i]+LMAX+HMAX+2,
- ut_user, NMAX+1);
+ ut_user, NMAX+1);
record_time(&otime, &print,
- i, bp);
+ i, bp);
break;
} else if (linehostnameq(ttnames[i],
bp->ut_line, ut_host, ut_user)) {
@@ -290,14 +293,14 @@ next_word:
ct = ctime(&bp->ut_xtime);
(void) printf(gettext("%-*.*s %-*.*s "),
- NMAX, NMAX, bp->ut_name,
- LMAX, LMAX, bp->ut_line);
+ LOGIN_WIDTH, NMAX, bp->ut_name,
+ LINE_WIDTH, LMAX, bp->ut_line);
hostf_len = strlen(bp->ut_host);
(void) snprintf(hostf, sizeof (hostf),
"%-*.*s", hostf_len, hostf_len,
bp->ut_host);
fpos = snprintf(timef, sizeof (timef),
- "%10.10s %5.5s ",
+ "%10.10s %5.5s ",
ct, 11 + ct);
if (!lineq(bp->ut_line, "system boot") &&
!lineq(bp->ut_line, "system down")) {
@@ -307,7 +310,7 @@ next_word:
if (fpos < sizeof (timef)) {
/* timef still has room */
(void) snprintf(timef + fpos, sizeof (timef) - fpos,
- gettext(" still logged in"));
+ gettext(" still logged in"));
}
} else {
@@ -331,7 +334,7 @@ next_word:
if (fpos < sizeof (timef)) {
/* timef still has room */
chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos,
- gettext("- %s"), crmsg);
+ gettext("- %s"), crmsg);
fpos += chrcnt;
}
@@ -340,7 +343,7 @@ next_word:
if (fpos < sizeof (timef)) {
/* timef still has room */
chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos,
- gettext("- %5.5s"), ctime(&otime) + 11);
+ gettext("- %5.5s"), ctime(&otime) + 11);
fpos += chrcnt;
}
@@ -351,7 +354,7 @@ next_word:
if (fpos < sizeof (timef)) {
/* timef still has room */
(void) snprintf(timef + fpos, sizeof (timef) - fpos,
- gettext(" (%5.5s)"), asctime(gmtime(&delta)) + 11);
+ gettext(" (%5.5s)"), asctime(gmtime(&delta)) + 11);
}
} else {
@@ -359,7 +362,7 @@ next_word:
if (fpos < sizeof (timef)) {
/* timef still has room */
(void) snprintf(timef + fpos, sizeof (timef) - fpos,
- gettext(" (%ld+%5.5s)"), delta / SECDAY,
+ gettext(" (%ld+%5.5s)"), delta / SECDAY,
asctime(gmtime(&delta)) + 11);
}
@@ -418,8 +421,8 @@ reallocate_buffer()
(void) fprintf(stderr, gettext("Out of memory \n"));
exit(2);
} else {
- ttnames = tmpttnames;
- logouts = tmplogouts;
+ ttnames = tmpttnames;
+ logouts = tmplogouts;
}
for (j = lines-CHUNK_SIZE; j < lines; j++) {
ttnames[j] = NULL;
diff --git a/usr/src/cmd/newtask/newtask.c b/usr/src/cmd/newtask/newtask.c
index 829ec5f723..f4f0c2fe2d 100644
--- a/usr/src/cmd/newtask/newtask.c
+++ b/usr/src/cmd/newtask/newtask.c
@@ -20,12 +20,12 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/types.h>
#include <sys/task.h>
@@ -696,7 +696,7 @@ match_user(uid_t uid, char *projname, int is_my_uid)
if (projname == NULL || getuid() == (uid_t)0)
return (pw);
- (void) strcpy(username, pw->pw_name);
+ (void) strlcpy(username, pw->pw_name, sizeof (username));
if (inproj(username, projname, prbuf, PROJECT_BUFSZ) == 0) {
char **u;
diff --git a/usr/src/cmd/oamuser/inc/users.h b/usr/src/cmd/oamuser/inc/users.h
index 8524060312..16263ebd71 100644
--- a/usr/src/cmd/oamuser/inc/users.h
+++ b/usr/src/cmd/oamuser/inc/users.h
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
*/
@@ -45,6 +47,7 @@
#define UNIQUE 2 /* is unique */
#define TOOBIG 3 /* number too big */
#define INVALID 4
+#define LONGNAME 5 /* string too long */
/*
* Note: constraints checking for warning (release 2.6),
diff --git a/usr/src/cmd/oamuser/lib/vlogin.c b/usr/src/cmd/oamuser/lib/vlogin.c
index 1574a75beb..12a5a53101 100644
--- a/usr/src/cmd/oamuser/lib/vlogin.c
+++ b/usr/src/cmd/oamuser/lib/vlogin.c
@@ -20,6 +20,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright (c) 1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
@@ -27,9 +29,6 @@
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
-
-#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
-
/*LINTLIBRARY*/
#include <sys/types.h>
@@ -37,8 +36,12 @@
#include <ctype.h>
#include <userdefs.h>
#include <users.h>
+#include <deflt.h>
#include <limits.h>
+/* Defaults file */
+#define DEFAULT_USERADD "/etc/default/useradd"
+
/*
* validate string given as login name.
*/
@@ -49,6 +52,7 @@ valid_login(char *login, struct passwd **pptr, int *warning)
char *ptr = login;
int bad1char, badc, clower, len;
char c;
+ char action;
len = 0; clower = 0; badc = 0; bad1char = 0;
*warning = 0;
@@ -68,12 +72,34 @@ valid_login(char *login, struct passwd **pptr, int *warning)
clower++;
}
- /*
- * XXX length checking causes some operational/compatibility problem.
- * This has to be revisited in the future as ARC/standards issue.
- */
+ action = 'w';
+ if (defopen(DEFAULT_USERADD) == 0) {
+ char *defptr;
+
+ if ((defptr = defread("EXCEED_TRAD=")) != NULL) {
+ char let = tolower(*defptr);
+
+ switch (let) {
+ case 'w': /* warning */
+ case 'e': /* error */
+ case 's': /* silent */
+ action = let;
+ break;
+ }
+ }
+ (void) defopen((char *)NULL);
+ }
+
if (len > LOGNAME_MAX)
- *warning = *warning | WARN_NAME_TOO_LONG;
+ return (LONGNAME);
+
+ if (len > LOGNAME_MAX_TRAD) {
+ if (action == 'w')
+ *warning = *warning | WARN_NAME_TOO_LONG;
+ else if (action == 'e')
+ return (LONGNAME);
+ }
+
if (clower == 0)
*warning = *warning | WARN_NO_LOWERCHAR;
if (badc != 0)
diff --git a/usr/src/cmd/oamuser/user/Makefile b/usr/src/cmd/oamuser/user/Makefile
index 9542a967f0..61886b168b 100644
--- a/usr/src/cmd/oamuser/user/Makefile
+++ b/usr/src/cmd/oamuser/user/Makefile
@@ -21,10 +21,13 @@
#
# Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2013 RackTop Systems.
+# Copyright (c) 2013 Gary Mills
#
# cmd/oamuser/user/Makefile
#
+DEFAULTFILES= useradd.dfl
+
include ../../Makefile.cmd
GREP= grep
@@ -101,7 +104,8 @@ $(USERADD): $(ADD_OBJ)
$(USERMOD): $(MOD_OBJ)
$(USERDEL): $(DEL_OBJ)
-install: all .WAIT $(ROOTSKEL) $(INSSBINPROG) $(INSSKELFILE)
+install: all $(ROOTETCDEFAULTFILES) .WAIT \
+ $(ROOTSKEL) $(INSSBINPROG) $(INSSKELFILE)
$(RM) $(ROOTUSRSBIN)/$(ROLEADD)
$(LN) $(ROOTUSRSBIN)/$(USERADD) $(ROOTUSRSBIN)/$(ROLEADD)
$(RM) $(ROOTUSRSBIN)/$(ROLEDEL)
diff --git a/usr/src/cmd/oamuser/user/messages.c b/usr/src/cmd/oamuser/user/messages.c
index 4fcccd9a80..512b123323 100644
--- a/usr/src/cmd/oamuser/user/messages.c
+++ b/usr/src/cmd/oamuser/user/messages.c
@@ -23,12 +23,12 @@
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */
-
char *errmsgs[] = {
"WARNING: uid %ld is reserved.\n",
"WARNING: more than NGROUPS_MAX(%d) groups specified.\n",
@@ -99,6 +99,7 @@ char *errmsgs[] = {
"WARNING: gid %ld is reserved.\n",
"ERROR: Failed to read /etc/group file due to invalid entry or"
" read error.\n",
+ "ERROR: %s is too long. Choose another.\n",
};
int lasterrmsg = sizeof (errmsgs) / sizeof (char *);
diff --git a/usr/src/cmd/oamuser/user/messages.h b/usr/src/cmd/oamuser/user/messages.h
index 6dc89e2d4a..0655e9c402 100644
--- a/usr/src/cmd/oamuser/user/messages.h
+++ b/usr/src/cmd/oamuser/user/messages.h
@@ -23,6 +23,8 @@
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -30,8 +32,6 @@
#ifndef _MESSAGES_H
#define _MESSAGES_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
extern void errmsg(int, ...);
/* WARNING: uid %d is reserved. */
@@ -149,4 +149,7 @@ extern void errmsg(int, ...);
/* ERROR: Failed to read /etc/group file due to invalid entry or read error. */
#define M_READ_ERROR 37
+/* ERROR: %s is too long. Choose another. */
+#define M_TOO_LONG 38
+
#endif /* _MESSAGES_H */
diff --git a/usr/src/cmd/oamuser/user/useradd.c b/usr/src/cmd/oamuser/user/useradd.c
index afb3b17411..f04c3d48e9 100644
--- a/usr/src/cmd/oamuser/user/useradd.c
+++ b/usr/src/cmd/oamuser/user/useradd.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -396,6 +398,11 @@ char *argv[];
errmsg(M_USED, logname);
exit(EX_NAME_EXISTS);
/*NOTREACHED*/
+
+ case LONGNAME:
+ errmsg(M_TOO_LONG, logname);
+ exit(EX_BADARG);
+ /*NOTREACHED*/
}
if (warning)
diff --git a/usr/src/cmd/oamuser/user/useradd.dfl b/usr/src/cmd/oamuser/user/useradd.dfl
new file mode 100644
index 0000000000..492c3905cb
--- /dev/null
+++ b/usr/src/cmd/oamuser/user/useradd.dfl
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright (c) 2013 Gary Mills
+
+# The EXCEED_TRAD indicates the action when the traditional login name
+# length limit of eight characters is exceeded. The value "warning"
+# means to issue a warning message and continue. This is the default.
+# The value "error" means to issue an error message and terminate.
+# The value "silent" means to continue without issuing any message.
+#
+EXCEED_TRAD=warning
+#EXCEED_TRAD=error
+#EXCEED_TRAD=silent
+
diff --git a/usr/src/cmd/oamuser/user/usermod.c b/usr/src/cmd/oamuser/user/usermod.c
index 99f58ca7cd..fa2c018367 100644
--- a/usr/src/cmd/oamuser/user/usermod.c
+++ b/usr/src/cmd/oamuser/user/usermod.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -370,6 +372,12 @@ char **argv;
errmsg(M_USED, new_logname);
exit(EX_NAME_EXISTS);
/*NOTREACHED*/
+
+ case LONGNAME:
+ errmsg(M_TOO_LONG, new_logname);
+ exit(EX_BADARG);
+ /*NOTREACHED*/
+
default:
call_pass = 1;
break;
diff --git a/usr/src/cmd/passwd/passwd.c b/usr/src/cmd/passwd/passwd.c
index c2baf63423..7d993f681b 100644
--- a/usr/src/cmd/passwd/passwd.c
+++ b/usr/src/cmd/passwd/passwd.c
@@ -273,7 +273,7 @@ main(int argc, char *argv[])
argc -= optind;
if (argc < 1) {
- if ((usrname = getxlogin()) == NULL) {
+ if ((usrname = getlogin()) == NULL) {
struct passwd *pass = getpwuid(uid);
if (pass != NULL)
usrname = pass->pw_name;
diff --git a/usr/src/cmd/prstat/prstat.c b/usr/src/cmd/prstat/prstat.c
index e14538a57e..8e4e18aafc 100644
--- a/usr/src/cmd/prstat/prstat.c
+++ b/usr/src/cmd/prstat/prstat.c
@@ -20,6 +20,8 @@
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
@@ -76,6 +78,10 @@
#include <curses.h>
#include <term.h>
+#define LOGIN_WIDTH 8
+#define ZONE_WIDTH 28
+#define PROJECT_WIDTH 28
+
#define PSINFO_HEADER_PROC \
" PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP "
#define PSINFO_HEADER_PROC_LGRP \
@@ -109,8 +115,8 @@
#define PSINFO_LINE_LGRP \
"%6d %-8s %5s %5s %-6s %3s %3s %9s %3.3s%% %4d %-.16s/%d"
#define USAGE_LINE \
-"%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\
-"%3.3s %-.12s/%d"
+"%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\
+"%3.3s %3.3s %-.12s/%d"
#define USER_LINE \
"%6d %-8s %5.5s %5.5s %3.3s%% %9s %3.3s%%"
#define TASK_LINE \
@@ -455,16 +461,23 @@ list_print(list_t *list)
mem = (100 * id->id_pctmem) / total_mem;
else
mem = id->id_pctmem;
- if (list->l_type == LT_USERS)
- pwd_getname(id->id_uid, pname, LOGNAME_MAX + 1,
- opts.o_outpmode & OPT_NORESOLVE);
- else if (list->l_type == LT_ZONES)
+ if (list->l_type == LT_USERS) {
+ pwd_getname(id->id_uid, pname, sizeof (pname),
+ opts.o_outpmode & OPT_NORESOLVE,
+ opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
+ LOGIN_WIDTH);
+ } else if (list->l_type == LT_ZONES) {
getzonename(id->id_zoneid, zonename,
- ZONENAME_MAX);
- else
+ sizeof (zonename),
+ opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
+ ZONE_WIDTH);
+ } else {
getprojname(id->id_projid, projname,
- PROJNAME_MAX,
- opts.o_outpmode & OPT_NORESOLVE);
+ sizeof (projname),
+ opts.o_outpmode & OPT_NORESOLVE,
+ opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
+ PROJECT_WIDTH);
+ }
Format_size(psize, id->id_size, 6);
Format_size(prssize, id->id_rssize, 6);
Format_pct(pmem, mem, 4);
@@ -497,8 +510,10 @@ list_print(list_t *list)
else
lwpid = lwp->li_info.pr_nlwp +
lwp->li_info.pr_nzomb;
- pwd_getname(lwp->li_info.pr_uid, pname, LOGNAME_MAX + 1,
- opts.o_outpmode & OPT_NORESOLVE);
+ pwd_getname(lwp->li_info.pr_uid, pname, sizeof (pname),
+ opts.o_outpmode & OPT_NORESOLVE,
+ opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
+ LOGIN_WIDTH);
if (opts.o_outpmode & OPT_PSINFO) {
Format_size(psize, lwp->li_info.pr_size, 6);
Format_size(prssize, lwp->li_info.pr_rssize, 6);
@@ -531,14 +546,15 @@ list_print(list_t *list)
if (opts.o_outpmode & OPT_LGRP) {
(void) printf(PSINFO_LINE_LGRP,
(int)lwp->li_info.pr_pid, pname,
- psize, prssize, pstate, ppri, pnice,
- ptime, pcpu,
+ psize, prssize, pstate,
+ ppri, pnice, ptime, pcpu,
(int)lwp->li_info.pr_lwp.pr_lgrp,
lwp->li_info.pr_fname, lwpid);
} else {
(void) printf(PSINFO_LINE,
(int)lwp->li_info.pr_pid, pname,
- psize, prssize, pstate, ppri, pnice,
+ psize, prssize,
+ pstate, ppri, pnice,
ptime, pcpu,
lwp->li_info.pr_fname, lwpid);
}
@@ -1376,7 +1392,7 @@ main(int argc, char **argv)
pagesize = sysconf(_SC_PAGESIZE);
while ((opt = getopt(argc, argv,
- "vVcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z")) != (int)EOF) {
+ "vVcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJWz:Z")) != (int)EOF) {
switch (opt) {
case 'r':
opts.o_outpmode |= OPT_NORESOLVE;
@@ -1478,6 +1494,9 @@ main(int argc, char **argv)
case 'L':
opts.o_outpmode |= OPT_LWPS;
break;
+ case 'W':
+ opts.o_outpmode |= OPT_TRUNC;
+ break;
case 'z':
if ((p = strtok(optarg, ", ")) == NULL)
Die(gettext("invalid argument for -z\n"));
diff --git a/usr/src/cmd/prstat/prstat.h b/usr/src/cmd/prstat/prstat.h
index f75bdaf412..bf38b3e2bd 100644
--- a/usr/src/cmd/prstat/prstat.h
+++ b/usr/src/cmd/prstat/prstat.h
@@ -20,6 +20,8 @@
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
@@ -75,6 +77,7 @@ extern "C" {
#define OPT_UDATE 0x20000 /* print unix timestamp */
#define OPT_DDATE 0x40000 /* print timestamp in date(1) format */
#define OPT_NORESOLVE 0x80000 /* no nsswitch lookups */
+#define OPT_TRUNC 0x100000 /* truncate long names */
/*
* Flags to keep track of process or lwp status
diff --git a/usr/src/cmd/prstat/prtable.c b/usr/src/cmd/prstat/prtable.c
index 87d862140b..e144ef7ff8 100644
--- a/usr/src/cmd/prstat/prtable.c
+++ b/usr/src/cmd/prstat/prtable.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
@@ -35,6 +37,7 @@
#include <errno.h>
#include <zone.h>
#include <libzonecfg.h>
+#include <wchar.h>
#include "prstat.h"
#include "prutil.h"
@@ -59,14 +62,28 @@ pwd_getid(char *name)
}
void
-pwd_getname(uid_t uid, char *name, int length, int noresolve)
+pwd_getname(uid_t uid, char *name, size_t length, int noresolve,
+ int trunc, size_t width)
{
struct passwd *pwd;
+ size_t n;
if (noresolve || (pwd = getpwuid(uid)) == NULL) {
- (void) snprintf(name, length, "%u", uid);
+ n = snprintf(NULL, 0, "%u", uid);
+ if (trunc && n > width)
+ (void) snprintf(name, length, "%.*u%c",
+ width - 1, uid, '*');
+ else
+ (void) snprintf(name, length, "%u", uid);
} else {
- (void) snprintf(name, length, "%s", pwd->pw_name);
+ n = mbstowcs(NULL, pwd->pw_name, 0);
+ if (n == (size_t)-1)
+ (void) snprintf(name, length, "%s", "ERROR");
+ else if (trunc && n > width)
+ (void) snprintf(name, length, "%.*s%c",
+ width - 1, pwd->pw_name, '*');
+ else
+ (void) snprintf(name, length, "%s", pwd->pw_name);
}
}
diff --git a/usr/src/cmd/prstat/prtable.h b/usr/src/cmd/prstat/prtable.h
index da8557ac8f..acfc73593c 100644
--- a/usr/src/cmd/prstat/prtable.h
+++ b/usr/src/cmd/prstat/prtable.h
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
@@ -70,7 +72,7 @@ typedef struct plwp { /* linked list of pointers to lwps */
struct plwp *l_next;
} plwp_t;
-extern void pwd_getname(uid_t, char *, int, int);
+extern void pwd_getname(uid_t, char *, size_t, int, int, size_t);
extern void add_uid(uidtbl_t *, char *);
extern int has_uid(uidtbl_t *, uid_t);
extern void add_element(table_t *, long);
diff --git a/usr/src/cmd/prstat/prutil.c b/usr/src/cmd/prstat/prutil.c
index 6ff4f5c49f..7def1bd40b 100644
--- a/usr/src/cmd/prstat/prutil.c
+++ b/usr/src/cmd/prstat/prutil.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
@@ -107,7 +109,7 @@ void
Usage()
{
(void) fprintf(stderr, gettext(
- "Usage:\tprstat [-acHJLmrRtTvVZ] [-u euidlist] [-U uidlist]\n"
+ "Usage:\tprstat [-acHJLmrRtTvVWZ] [-u euidlist] [-U uidlist]\n"
"\t[-p pidlist] [-P cpulist] [-C psrsetlist] [-h lgrouplist]\n"
"\t[-j projidlist] [-k taskidlist] [-z zoneidlist]\n"
"\t[-s key | -S key] [-n nprocs[,nusers]] [-d d|u]\n"
@@ -279,26 +281,45 @@ Priocntl(char *class)
}
void
-getprojname(projid_t projid, char *str, int len, int noresolve)
+getprojname(projid_t projid, char *str, size_t len, int noresolve,
+ int trunc, size_t width)
{
struct project proj;
+ size_t n;
if (noresolve || getprojbyid(projid, &proj, projbuf, PROJECT_BUFSZ) ==
- NULL)
+ NULL) {
(void) snprintf(str, len, "%-6d", (int)projid);
- else
- (void) snprintf(str, len, "%-28s", proj.pj_name);
+ } else {
+ n = mbstowcs(NULL, proj.pj_name, 0);
+ if (n == (size_t)-1)
+ (void) snprintf(str, len, "%-28s", "ERROR");
+ else if (trunc && n > width)
+ (void) snprintf(str, len, "%.*s%c", width - 1,
+ proj.pj_name, '*');
+ else
+ (void) snprintf(str, len, "%-28s", proj.pj_name);
+ }
}
void
-getzonename(zoneid_t zoneid, char *str, int len)
+getzonename(zoneid_t zoneid, char *str, size_t len, int trunc, size_t width)
{
char zone_name[ZONENAME_MAX];
+ size_t n;
- if (getzonenamebyid(zoneid, zone_name, sizeof (zone_name)) < 0)
+ if (getzonenamebyid(zoneid, zone_name, sizeof (zone_name)) < 0) {
(void) snprintf(str, len, "%-6d", (int)zoneid);
- else
- (void) snprintf(str, len, "%-28s", zone_name);
+ } else {
+ n = mbstowcs(NULL, zone_name, 0);
+ if (n == (size_t)-1)
+ (void) snprintf(str, len, "%-28s", "ERROR");
+ else if (trunc && n > width)
+ (void) snprintf(str, len, "%.*s%c", width - 1,
+ zone_name, '*');
+ else
+ (void) snprintf(str, len, "%-28s", zone_name);
+ }
}
/*
diff --git a/usr/src/cmd/prstat/prutil.h b/usr/src/cmd/prstat/prutil.h
index c98b3e7908..cfa2133714 100644
--- a/usr/src/cmd/prstat/prutil.h
+++ b/usr/src/cmd/prstat/prutil.h
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
@@ -50,8 +52,8 @@ extern void *Malloc(size_t);
extern void *Zalloc(size_t);
extern int Setrlimit();
extern void Priocntl(char *);
-extern void getprojname(projid_t, char *, int, int);
-extern void getzonename(projid_t, char *, int);
+extern void getprojname(projid_t, char *, size_t, int, int, size_t);
+extern void getzonename(projid_t, char *, size_t, int, size_t);
extern void stripfname(char *);
#ifdef __cplusplus
diff --git a/usr/src/cmd/ps/ps.c b/usr/src/cmd/ps/ps.c
index 19e2d15655..0a43a92fcb 100644
--- a/usr/src/cmd/ps/ps.c
+++ b/usr/src/cmd/ps/ps.c
@@ -20,6 +20,8 @@
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -76,7 +78,8 @@
*/
#define ARGSIZ ZONENAME_MAX
-#define MAXUGNAME 10 /* max chars in a user/group name or printed u/g id */
+/* Max chars in a user/group name or printed u/g id */
+#define MAXUGNAME (LOGNAME_MAX+2)
/* Structure for storing user or group info */
struct ugdata {
@@ -224,6 +227,7 @@ static int aflg;
static int dflg;
static int Lflg;
static int Pflg;
+static int Wflg;
static int yflg;
static int pflg;
static int fflg;
@@ -424,7 +428,7 @@ stdmain(int argc, char **argv)
fname[F_STIME].width = fname[F_STIME].minwidth = len;
- while ((c = getopt(argc, argv, "jlfceAadLPyZHh:t:p:g:u:U:G:n:s:o:z:"))
+ while ((c = getopt(argc, argv, "jlfceAadLPWyZHh:t:p:g:u:U:G:n:s:o:z:"))
!= EOF)
switch (c) {
case 'H': /* Show home lgroups */
@@ -518,6 +522,9 @@ stdmain(int argc, char **argv)
case 'P': /* show bound processor */
Pflg++;
break;
+ case 'W': /* truncate long names */
+ Wflg++;
+ break;
case 'y': /* omit F & ADDR, report RSS & SZ in Kby */
yflg++;
break;
@@ -1057,7 +1064,7 @@ usage(void) /* print usage message and quit */
int pos = 80, i = 0;
static char usage1[] =
- "ps [ -aAdefHlcjLPyZ ] [ -o format ] [ -t termlist ]";
+ "ps [ -aAdefHlcjLPWyZ ] [ -o format ] [ -t termlist ]";
static char usage2[] =
"\t[ -u userlist ] [ -U userlist ] [ -G grouplist ]";
static char usage3[] =
@@ -1395,19 +1402,50 @@ prcom(psinfo_t *psinfo, char *ttyp)
if (Zflg) { /* ZONE */
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
- (void) printf(" %7.7d ", ((int)psinfo->pr_zoneid));
+ if (snprintf(NULL, 0, "%d",
+ ((int)psinfo->pr_zoneid)) > 7)
+ (void) printf(" %6.6d%c ",
+ ((int)psinfo->pr_zoneid), '*');
+ else
+ (void) printf(" %7.7d ",
+ ((int)psinfo->pr_zoneid));
} else {
- (void) printf("%8.8s ", zonename);
+ size_t nw;
+
+ nw = mbstowcs(NULL, zonename, 0);
+ if (nw == (size_t)-1)
+ (void) printf("%8.8s ", "ERROR");
+ else if (nw > 8)
+ (void) wprintf(L"%7.7s%c ", zonename, '*');
+ else
+ (void) wprintf(L"%8.8s ", zonename);
}
}
if (fflg) { /* UID */
- if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
- (void) printf("%8.8s ", pwd->pw_name);
- else
- (void) printf(" %7.7u ", psinfo->pr_euid);
+ if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
+ size_t nw;
+
+ nw = mbstowcs(NULL, pwd->pw_name, 0);
+ if (nw == (size_t)-1)
+ (void) printf("%8.8s ", "ERROR");
+ else if (nw > 8)
+ (void) wprintf(L"%7.7s%c ", pwd->pw_name, '*');
+ else
+ (void) wprintf(L"%8.8s ", pwd->pw_name);
+ } else {
+ if (snprintf(NULL, 0, "%u",
+ (psinfo->pr_euid)) > 7)
+ (void) printf(" %6.6u%c ", psinfo->pr_euid,
+ '*');
+ else
+ (void) printf(" %7.7u ", psinfo->pr_euid);
+ }
} else if (lflg) {
- (void) printf("%6u ", psinfo->pr_euid);
+ if (snprintf(NULL, 0, "%u", (psinfo->pr_euid)) > 6)
+ (void) printf("%5.5u%c ", psinfo->pr_euid, '*');
+ else
+ (void) printf("%6u ", psinfo->pr_euid);
}
(void) printf("%*d", pidwidth, (int)psinfo->pr_pid); /* PID */
if (lflg || fflg)
@@ -1628,16 +1666,48 @@ print_field(psinfo_t *psinfo, struct field *f, const char *ttyp)
switch (f->fname) {
case F_RUSER:
- if ((pwd = getpwuid(psinfo->pr_uid)) != NULL)
- (void) printf("%*s", width, pwd->pw_name);
- else
- (void) printf("%*u", width, psinfo->pr_uid);
+ if ((pwd = getpwuid(psinfo->pr_uid)) != NULL) {
+ size_t nw;
+
+ nw = mbstowcs(NULL, pwd->pw_name, 0);
+ if (nw == (size_t)-1)
+ (void) printf("%*s ", width, "ERROR");
+ else if (Wflg && nw > width)
+ (void) wprintf(L"%.*s%c", width - 1,
+ pwd->pw_name, '*');
+ else
+ (void) wprintf(L"%*s", width, pwd->pw_name);
+ } else {
+ if (Wflg && snprintf(NULL, 0, "%u",
+ (psinfo->pr_uid)) > width)
+
+ (void) printf("%*u%c", width - 1,
+ psinfo->pr_uid, '*');
+ else
+ (void) printf("%*u", width, psinfo->pr_uid);
+ }
break;
case F_USER:
- if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
- (void) printf("%*s", width, pwd->pw_name);
- else
- (void) printf("%*u", width, psinfo->pr_euid);
+ if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
+ size_t nw;
+
+ nw = mbstowcs(NULL, pwd->pw_name, 0);
+ if (nw == (size_t)-1)
+ (void) printf("%*s ", width, "ERROR");
+ else if (Wflg && nw > width)
+ (void) wprintf(L"%.*s%c", width - 1,
+ pwd->pw_name, '*');
+ else
+ (void) wprintf(L"%*s", width, pwd->pw_name);
+ } else {
+ if (Wflg && snprintf(NULL, 0, "%u",
+ (psinfo->pr_euid)) > width)
+
+ (void) printf("%*u%c", width - 1,
+ psinfo->pr_euid, '*');
+ else
+ (void) printf("%*u", width, psinfo->pr_euid);
+ }
break;
case F_RGROUP:
if ((grp = getgrgid(psinfo->pr_gid)) != NULL)
@@ -1879,13 +1949,30 @@ print_field(psinfo_t *psinfo, struct field *f, const char *ttyp)
char proj_buf[PROJECT_BUFSZ];
if ((getprojbyid(psinfo->pr_projid, &cproj,
- (void *)&proj_buf, PROJECT_BUFSZ)) == NULL)
- (void) printf("%*d", width,
- (int)psinfo->pr_projid);
- else
- (void) printf("%*s", width,
- (cproj.pj_name != NULL) ?
- cproj.pj_name : "---");
+ (void *)&proj_buf, PROJECT_BUFSZ)) == NULL) {
+ if (Wflg && snprintf(NULL, 0, "%d",
+ ((int)psinfo->pr_projid)) > width)
+ (void) printf("%.*d%c", width - 1,
+ ((int)psinfo->pr_projid), '*');
+ else
+ (void) printf("%*d", width,
+ (int)psinfo->pr_projid);
+ } else {
+ size_t nw;
+
+ if (cproj.pj_name != NULL)
+ nw = mbstowcs(NULL, cproj.pj_name, 0);
+ if (cproj.pj_name == NULL)
+ (void) printf("%*s ", width, "---");
+ else if (nw == (size_t)-1)
+ (void) printf("%*s ", width, "ERROR");
+ else if (Wflg && nw > width)
+ (void) wprintf(L"%.*s%c", width - 1,
+ cproj.pj_name, '*');
+ else
+ (void) wprintf(L"%*s", width,
+ cproj.pj_name);
+ }
}
break;
case F_PSET:
@@ -1903,10 +1990,24 @@ print_field(psinfo_t *psinfo, struct field *f, const char *ttyp)
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
- (void) printf("%*d", width,
- ((int)psinfo->pr_zoneid));
+ if (Wflg && snprintf(NULL, 0, "%d",
+ ((int)psinfo->pr_zoneid)) > width)
+ (void) printf("%.*d%c", width - 1,
+ ((int)psinfo->pr_zoneid), '*');
+ else
+ (void) printf("%*d", width,
+ (int)psinfo->pr_zoneid);
} else {
- (void) printf("%*s", width, zonename);
+ size_t nw;
+
+ nw = mbstowcs(NULL, zonename, 0);
+ if (nw == (size_t)-1)
+ (void) printf("%*s ", width, "ERROR");
+ else if (Wflg && nw > width)
+ (void) wprintf(L"%.*s%c", width - 1,
+ zonename, '*');
+ else
+ (void) wprintf(L"%*s", width, zonename);
}
}
break;
@@ -2181,9 +2282,23 @@ przom(psinfo_t *psinfo)
if (Zflg) {
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
- (void) printf(" %7.7d ", ((int)psinfo->pr_zoneid));
+ if (snprintf(NULL, 0, "%d",
+ ((int)psinfo->pr_zoneid)) > 7)
+ (void) printf(" %6.6d%c ",
+ ((int)psinfo->pr_zoneid), '*');
+ else
+ (void) printf(" %7.7d ",
+ ((int)psinfo->pr_zoneid));
} else {
- (void) printf("%8.8s ", zonename);
+ size_t nw;
+
+ nw = mbstowcs(NULL, zonename, 0);
+ if (nw == (size_t)-1)
+ (void) printf("%8.8s ", "ERROR");
+ else if (nw > 8)
+ (void) wprintf(L"%7.7s%c ", zonename, '*');
+ else
+ (void) wprintf(L"%8.8s ", zonename);
}
}
if (Hflg) {
@@ -2191,12 +2306,30 @@ przom(psinfo_t *psinfo)
(void) printf(" %6d", (int)psinfo->pr_lwp.pr_lgrp); /* LGRP */
}
if (fflg) {
- if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
- (void) printf("%8.8s ", pwd->pw_name);
+ if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
+ size_t nw;
+
+ nw = mbstowcs(NULL, pwd->pw_name, 0);
+ if (nw == (size_t)-1)
+ (void) printf("%8.8s ", "ERROR");
+ else if (nw > 8)
+ (void) wprintf(L"%7.7s%c ", pwd->pw_name, '*');
+ else
+ (void) wprintf(L"%8.8s ", pwd->pw_name);
+ } else {
+ if (snprintf(NULL, 0, "%u",
+ (psinfo->pr_euid)) > 7)
+ (void) printf(" %6.6u%c ", psinfo->pr_euid,
+ '*');
+ else
+ (void) printf(" %7.7u ", psinfo->pr_euid);
+ }
+ } else if (lflg) {
+ if (snprintf(NULL, 0, "%u", (psinfo->pr_euid)) > 6)
+ (void) printf("%5.5u%c ", psinfo->pr_euid, '*');
else
- (void) printf(" %7.7u ", psinfo->pr_euid);
- } else if (lflg)
- (void) printf("%6u ", psinfo->pr_euid);
+ (void) printf("%6u ", psinfo->pr_euid);
+ }
(void) printf("%*d", pidwidth, (int)psinfo->pr_pid); /* PID */
if (lflg || fflg)
diff --git a/usr/src/cmd/pwck/pwck.c b/usr/src/cmd/pwck/pwck.c
index 5ba14eea59..dcd413ccc3 100644
--- a/usr/src/cmd/pwck/pwck.c
+++ b/usr/src/cmd/pwck/pwck.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -27,8 +29,6 @@
/* All Rights Reserved */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/types.h>
#include <sys/param.h>
#include <sys/signal.h>
@@ -41,6 +41,7 @@
#include <locale.h>
#include <errno.h>
#include <unistd.h>
+#include <limits.h>
#define ERROR1 "Too many/few fields"
#define ERROR2 "Bad character(s) in logname"
@@ -149,9 +150,9 @@ main(int argc, char **argv)
for (i = 0; buf[i] != ':'; i++) {
if (!isalnum(buf[i]) &&
- buf[i] != '_' &&
- buf[i] != '-' &&
- buf[i] != '.')
+ buf[i] != '_' &&
+ buf[i] != '-' &&
+ buf[i] != '.')
badc++;
else if (islower(buf[i]))
lc++;
@@ -163,7 +164,7 @@ main(int argc, char **argv)
/* Check for valid number of characters in logname */
- if (i <= 0 || i > 8)
+ if (i <= 0 || i > LOGNAME_MAX)
error(ERROR3);
/* Check that UID is numeric and <= MAXUID */
diff --git a/usr/src/cmd/sgs/error/i386/Makefile b/usr/src/cmd/sgs/error/i386/Makefile
index c08963db2a..bafd104413 100644
--- a/usr/src/cmd/sgs/error/i386/Makefile
+++ b/usr/src/cmd/sgs/error/i386/Makefile
@@ -19,6 +19,8 @@
# CDDL HEADER END
#
#
+# Copyright (c) 2013 Gary Mills
+#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -63,6 +65,6 @@ lint: $(LINTOUT)
$(LINTOUT): $(SRCS)
perl ../../tools/lint_hdr.pl $(PROG) > $(LINTOUT)
- $(LINT.c) $(SRCS) 2>&1 | tee -a $(LINTOUT)
+ $(LINT.c) $(SRCS) $(LDLIBS) 2>&1 | tee -a $(LINTOUT)
include ../../../Makefile.targ
diff --git a/usr/src/cmd/sgs/error/sparc/Makefile b/usr/src/cmd/sgs/error/sparc/Makefile
index 5415983e4c..cd3bf66bda 100644
--- a/usr/src/cmd/sgs/error/sparc/Makefile
+++ b/usr/src/cmd/sgs/error/sparc/Makefile
@@ -19,6 +19,8 @@
# CDDL HEADER END
#
#
+# Copyright (c) 2013 Gary Mills
+#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -63,6 +65,6 @@ lint: $(LINTOUT)
$(LINTOUT): $(SRCS)
perl ../../tools/lint_hdr.pl $(PROG) > $(LINTOUT)
- $(LINT.c) $(SRCS) 2>&1 | tee -a $(LINTOUT)
+ $(LINT.c) $(SRCS) $(LDLIBS) 2>&1 | tee -a $(LINTOUT)
include ../../../Makefile.targ
diff --git a/usr/src/cmd/w/w.c b/usr/src/cmd/w/w.c
index dae0680c70..b5eb04d3af 100644
--- a/usr/src/cmd/w/w.c
+++ b/usr/src/cmd/w/w.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -69,19 +71,15 @@
#include <priv_utils.h>
/*
- * utmpx defines wider fields for user and line. For compatibility of output,
- * we are limiting these to the old maximums in utmp. Define UTMPX_NAMELEN
- * to use the full lengths.
+ * Use the full lengths from utmpx for user and line.
*/
-#ifndef UTMPX_NAMELEN
-/* XXX - utmp - fix name length */
-#define NMAX (_POSIX_LOGIN_NAME_MAX - 1)
-#define LMAX 12
-#else /* UTMPX_NAMELEN */
static struct utmpx dummy;
#define NMAX (sizeof (dummy.ut_user))
#define LMAX (sizeof (dummy.ut_line))
-#endif /* UTMPX_NAMELEN */
+
+/* Print minimum field widths. */
+#define LOGIN_WIDTH 8
+#define LINE_WIDTH 12
#define DIV60(t) ((t+30)/60) /* x/60 rounded */
@@ -483,17 +481,18 @@ retry:
continue; /* we're looking for somebody else */
/* print login name of the user */
- PRINTF(("%-*.*s ", NMAX, NMAX, ut->ut_name));
+ PRINTF(("%-*.*s ", LOGIN_WIDTH, NMAX, ut->ut_name));
/* print tty user is on */
if (lflag) {
- PRINTF(("%-*.*s", LMAX, LMAX, ut->ut_line));
+ PRINTF(("%-*.*s", LINE_WIDTH, LMAX, ut->ut_line));
} else {
if (ut->ut_line[0] == 'p' && ut->ut_line[1] == 't' &&
ut->ut_line[2] == 's' && ut->ut_line[3] == '/') {
PRINTF(("%-*.3s", LMAX, &ut->ut_line[4]));
} else {
- PRINTF(("%-*.*s", LMAX, LMAX, ut->ut_line));
+ PRINTF(("%-*.*s", LINE_WIDTH, LMAX,
+ ut->ut_line));
}
}
diff --git a/usr/src/cmd/wall/wall.c b/usr/src/cmd/wall/wall.c
index 64bb4f8918..3336167b12 100644
--- a/usr/src/cmd/wall/wall.c
+++ b/usr/src/cmd/wall/wall.c
@@ -31,6 +31,8 @@
/*
* Copyright 2012 Joyent, Inc. All rights reserved.
+ *
+ * Copyright (c) 2013 Gary Mills
*/
#include <signal.h>
@@ -60,18 +62,10 @@
#include <sys/ctfs.h>
/*
- * utmpx defines wider fields for user and line. For compatibility of output,
- * we are limiting these to the old maximums in utmp. Define UTMPX_NAMELEN
- * to use the full lengths.
+ * Use the full lengths from utmpx for user and line.
*/
-#ifndef UTMPX_NAMELEN
-/* XXX - utmp -fix name length */
-#define NMAX (_POSIX_LOGIN_NAME_MAX - 1)
-#define LMAX 12
-#else /* UTMPX_NAMELEN */
-#define NMAX (sizeof (((struct utmpx *)0)->ut_user)
-#define LMAX (sizeof (((struct utmpx *)0)->ut_line)
-#endif /* UTMPX_NAMELEN */
+#define NMAX (sizeof (((struct utmpx *)0)->ut_user))
+#define LMAX (sizeof (((struct utmpx *)0)->ut_line))
static char mesg[3000];
static char *infile;
@@ -82,7 +76,7 @@ static char line[MAXNAMLEN+1] = "???";
static char systm[MAXNAMLEN+1];
static time_t tloc;
static struct utsname utsn;
-static char who[9] = "???";
+static char who[NMAX+1] = "???";
static char time_buf[50];
#define DATE_FMT "%a %b %e %H:%M:%S"
@@ -226,7 +220,8 @@ main(int argc, char *argv[])
MAXNAMLEN + 1);
if (rsystm[0] != '\0') {
(void) strcpy(systm, rsystm);
- (void) strncpy(rwho, who, 9);
+ (void) strncpy(rwho, who,
+ sizeof (who));
(void) strcpy(line, "rpc.rwalld");
}
}
@@ -428,7 +423,7 @@ sendmes(struct utmpx *p, zoneid_t zid)
(void) fprintf(f, " to group %s", grpname);
(void) fprintf(f, "...\n");
#ifdef DEBUG
- (void) fprintf(f, "DEBUG: To %.8s on %s\n", p->ut_user, s);
+ (void) fprintf(f, "DEBUG: To %.*s on %s\n", NMAX, p->ut_user, s);
#endif
i = strlen(mesg);
for (bp = mesg; --i >= 0; bp++) {
@@ -470,13 +465,11 @@ static int
chkgrp(char *name)
{
int i;
- char *p;
+ char user[NMAX + 1];
+ (void) strlcpy(user, name, sizeof (user));
for (i = 0; pgrp->gr_mem[i] && pgrp->gr_mem[i][0]; i++) {
- for (p = name; *p && *p != ' '; p++)
- ;
- *p = 0;
- if (strncmp(name, pgrp->gr_mem[i], 8) == 0)
+ if (strcmp(user, pgrp->gr_mem[i]) == 0)
return (1);
}
diff --git a/usr/src/cmd/who/who.c b/usr/src/cmd/who/who.c
index bb125b27cb..f7e4071362 100644
--- a/usr/src/cmd/who/who.c
+++ b/usr/src/cmd/who/who.c
@@ -23,12 +23,12 @@
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* This program analyzes information found in /var/adm/utmpx
*
@@ -100,18 +100,14 @@ static void dump(void);
static struct utmpx *utmpp; /* pointer for getutxent() */
/*
- * utmpx defines wider fields for user and line. For compatibility of output,
- * we are limiting these to the old maximums in utmp. Define UTMPX_NAMELEN
- * to use the full lengths.
+ * Use the full lengths from utmpx for user and line.
*/
-#ifndef UTMPX_NAMELEN
-/* XXX - utmp - fix name length */
-#define NMAX (_POSIX_LOGIN_NAME_MAX - 1)
-#define LMAX 12
-#else /* UTMPX_NAMELEN */
#define NMAX (sizeof (utmpp->ut_user))
#define LMAX (sizeof (utmpp->ut_line))
-#endif
+
+/* Print minimum field widths. */
+#define LOGIN_WIDTH 8
+#define LINE_WIDTH 12
static char comment[BUFSIZ]; /* holds inittab comment */
static char errmsg[BUFSIZ]; /* used in snprintf for errors */
@@ -168,7 +164,8 @@ main(int argc, char **argv)
/*
* Strip off path name of this command
*/
- for (i = strlen(argv[0]); i >= 0 && argv[0][i] != '/'; --i);
+ for (i = strlen(argv[0]); i >= 0 && argv[0][i] != '/'; --i)
+ ;
if (i >= 0)
argv[0] += i+1;
program = argv[0];
@@ -243,7 +240,7 @@ main(int argc, char **argv)
if (number < 1) {
(void) fprintf(stderr, gettext(
"%s: Number of users per line must "
- "be at least 1\n"), program);
+ "be at least 1\n"), program);
exit(1);
}
break;
@@ -348,16 +345,16 @@ main(int argc, char **argv)
(void) fprintf(stderr, gettext("t\ttime changes\n"));
(void) fprintf(stderr, gettext(
"T\tstatus of tty (+ writable, - not writable, "
- "? hung)\n"));
+ "? hung)\n"));
(void) fprintf(stderr, gettext("u\tuseful information\n"));
(void) fprintf(stderr,
gettext("m\tinformation only about current terminal\n"));
(void) fprintf(stderr, gettext(
"am i\tinformation about current terminal "
- "(same as -m)\n"));
+ "(same as -m)\n"));
(void) fprintf(stderr, gettext(
"am I\tinformation about current terminal "
- "(same as -m)\n"));
+ "(same as -m)\n"));
exit(1);
}
@@ -393,7 +390,7 @@ main(int argc, char **argv)
*/
if (justme == 1 || (argc == 3 && strcmp(argv[1], "am") == 0 &&
((argv[2][0] == 'i' || argv[2][0] == 'I') &&
- argv[2][1] == '\0'))) {
+ argv[2][1] == '\0'))) {
justme = 1;
myname = nameval;
(void) cuserid(myname);
@@ -509,7 +506,7 @@ dump()
*/
if (((totlusrs - 1) % number) == 0 && totlusrs > 1)
(void) printf("\n");
- (void) printf("%-*s ", NMAX, user);
+ (void) printf("%-*.*s ", LOGIN_WIDTH, NMAX, user);
return;
}
@@ -565,7 +562,8 @@ dump()
/*
* Print the TERSE portion of the output
*/
- (void) printf("%-*s %c %-12s %s", NMAX, user, w, device, time_buf);
+ (void) printf("%-*.*s %c %-12s %s", LOGIN_WIDTH, NMAX, user,
+ w, device, time_buf);
if (!terse) {
/*
@@ -626,7 +624,8 @@ dump()
*/
while ((rc = strncmp(utmpp->ut_id, iinit,
strcspn(iinit, ":"))) != 0) {
- for (; *iinit != '\n'; iinit++);
+ for (; *iinit != '\n'; iinit++)
+ ;
iinit++;
/*
@@ -646,10 +645,12 @@ dump()
* We found our entry
*/
for (iinit++; *iinit != '#' &&
- *iinit != '\n'; iinit++);
+ *iinit != '\n'; iinit++)
+ ;
if (*iinit == '#') {
for (iinit++; *iinit == ' ' ||
- *iinit == '\t'; iinit++);
+ *iinit == '\t'; iinit++)
+ ;
for (rc = 0; *iinit != '\n'; iinit++)
comment[rc++] = *iinit;
comment[rc] = '\0';
@@ -733,7 +734,7 @@ process()
if (strncmp(myname, utmpp->ut_user,
sizeof (utmpp->ut_user)) == 0 &&
strncmp(mytty, utmpp->ut_line,
- sizeof (utmpp->ut_line)) == 0 &&
+ sizeof (utmpp->ut_line)) == 0 &&
utmpp->ut_type == USER_PROCESS) {
/*
* we have have found ourselves
@@ -756,7 +757,8 @@ process()
#ifdef XPG4
if (utmpp->ut_type == LOGIN_PROCESS) {
if ((utmpp->ut_line[0] == '\0') ||
- (strcmp(utmpp->ut_user, "LOGIN") != 0))
+ (strcmp(utmpp->ut_user,
+ "LOGIN") != 0))
continue;
}
#endif /* XPG4 */
@@ -765,7 +767,7 @@ process()
} else {
(void) fprintf(stderr,
gettext("%s: Error --- entry has ut_type "
- "of %d\n"), program, utmpp->ut_type);
+ "of %d\n"), program, utmpp->ut_type);
(void) fprintf(stderr,
gettext(" when maximum is %d\n"), UTMAXTYPE);
}
diff --git a/usr/src/cmd/whodo/whodo.c b/usr/src/cmd/whodo/whodo.c
index a492ba2681..2def679f94 100644
--- a/usr/src/cmd/whodo/whodo.c
+++ b/usr/src/cmd/whodo/whodo.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -68,19 +70,14 @@
#include <priv_utils.h>
/*
- * utmpx defines wider fields for user and line. For compatibility of output,
- * we are limiting these to the old maximums in utmp. Define UTMPX_NAMELEN
- * to use the full lengths.
+ * Use the full lengths from utmpx for user and line.
*/
-#ifndef UTMPX_NAMELEN
-/* XXX - utmp - fix name length */
-#define NMAX (_POSIX_LOGIN_NAME_MAX - 1)
-#define LMAX 12
-#else /* UTMPX_NAMELEN */
-static struct utmpx dummy;
-#define NMAX (sizeof (dummy.ut_user))
-#define LMAX (sizeof (dummy.ut_line))
-#endif /* UTMPX_NAMELEN */
+#define NMAX (sizeof (((struct utmpx *)0)->ut_user))
+#define LMAX (sizeof (((struct utmpx *)0)->ut_line))
+
+/* Print minimum field widths. */
+#define LOGIN_WIDTH 8
+#define LINE_WIDTH 12
#define DIV60(t) ((t+30)/60) /* x/60 rounded */
@@ -473,10 +470,12 @@ retry:
continue; /* we're looking for somebody else */
if (lflag) { /* -l flag format (w command) */
/* print login name of the user */
- (void) printf("%-*.*s ", NMAX, NMAX, ut->ut_name);
+ (void) printf("%-*.*s ", LOGIN_WIDTH, (int)NMAX,
+ ut->ut_name);
/* print tty user is on */
- (void) printf("%-*.*s", LMAX, LMAX, ut->ut_line);
+ (void) printf("%-*.*s", LINE_WIDTH, (int)LMAX,
+ ut->ut_line);
/* print when the user logged in */
tim = ut->ut_xtime;
@@ -494,8 +493,9 @@ retry:
tim = ut->ut_xtime;
tm = localtime(&tim);
(void) printf("\n%-*.*s %-*.*s %2.1d:%2.2d\n",
- LMAX, LMAX, ut->ut_line,
- NMAX, NMAX, ut->ut_name, tm->tm_hour, tm->tm_min);
+ LINE_WIDTH, (int)LMAX, ut->ut_line,
+ LOGIN_WIDTH, (int)NMAX, ut->ut_name, tm->tm_hour,
+ tm->tm_min);
showproc(findhash((pid_t)ut->ut_pid));
}
}
@@ -520,10 +520,11 @@ showproc(struct uproc *up)
/* print the data for this process */
if (up->p_state == ZOMBIE)
(void) printf(" %-*.*s %5d %4.1ld:%2.2ld %s\n",
- LMAX, LMAX, " ?", (int)up->p_upid, 0L, 0L, "<defunct>");
+ LINE_WIDTH, (int)LMAX, " ?", (int)up->p_upid, 0L, 0L,
+ "<defunct>");
else if (up->p_state != NONE) {
(void) printf(" %-*.*s %5d %4.1ld:%2.2ld %s\n",
- LMAX, LMAX, getty(up->p_ttyd), (int)up->p_upid,
+ LINE_WIDTH, (int)LMAX, getty(up->p_ttyd), (int)up->p_upid,
up->p_time / 60L, up->p_time % 60L,
up->p_comm);
}