diff options
48 files changed, 1224 insertions, 322 deletions
diff --git a/usr/src/cmd/init/init.c b/usr/src/cmd/init/init.c index e04bbecd89..031a053b65 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. */ @@ -139,6 +141,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 */ /* @@ -1603,11 +1606,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. */ @@ -1643,9 +1646,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. @@ -1659,7 +1662,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. @@ -1680,7 +1683,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 @@ -1691,27 +1694,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; + } } - } } /* @@ -1726,38 +1732,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'; } @@ -2110,7 +2116,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(); } @@ -2808,8 +2816,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. @@ -2844,8 +2851,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++; @@ -2897,22 +2903,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], @@ -2929,12 +2935,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. */ @@ -3807,7 +3813,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 */ @@ -3914,13 +3921,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; @@ -3966,7 +3975,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); @@ -4074,7 +4084,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)); @@ -4171,7 +4182,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 " @@ -4204,7 +4216,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/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/prstat/prstat.c b/usr/src/cmd/prstat/prstat.c index 5942cce360..91a5eede04 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. * @@ -75,6 +77,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 \ @@ -108,8 +114,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 \ @@ -446,16 +452,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); @@ -488,8 +501,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); @@ -522,14 +537,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); } @@ -1364,7 +1380,7 @@ main(int argc, char **argv) pagesize = sysconf(_SC_PAGESIZE); while ((opt = getopt(argc, argv, - "vcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z")) != (int)EOF) { + "vcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJWz:Z")) != (int)EOF) { switch (opt) { case 'r': opts.o_outpmode |= OPT_NORESOLVE; @@ -1461,6 +1477,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 eefddcfcc3..293123c5b9 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. * @@ -73,6 +75,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 75db7c3b3b..0f9cbd6c4d 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. * @@ -106,7 +108,7 @@ void Usage() { (void) fprintf(stderr, gettext( - "Usage:\tprstat [-acHJLmrRtTvZ] [-u euidlist] [-U uidlist]\n" + "Usage:\tprstat [-acHJLmrRtTvWZ] [-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" @@ -278,26 +280,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); } diff --git a/usr/src/head/limits.h b/usr/src/head/limits.h index 86fd5e201a..a6cba76cf8 100644 --- a/usr/src/head/limits.h +++ b/usr/src/head/limits.h @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -31,8 +33,6 @@ #ifndef _LIMITS_H #define _LIMITS_H -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.34 */ - #include <sys/feature_tests.h> #include <sys/isa_defs.h> #include <iso/limits_iso.h> @@ -290,7 +290,16 @@ extern long _sysconf(int); /* System Private interface to sysconf() */ #endif /* CLK_TCK */ +#ifdef __USE_LEGACY_LOGNAME__ #define LOGNAME_MAX 8 /* max # of characters in a login name */ +#else /* __USE_LEGACY_LOGNAME__ */ +#define LOGNAME_MAX 32 /* max # of characters in a login name */ + /* Increased for illumos */ +#endif /* __USE_LEGACY_LOGNAME__ */ +#define LOGIN_NAME_MAX (LOGNAME_MAX + 1) /* max buffer size */ +#define LOGNAME_MAX_TRAD 8 /* traditional length */ +#define LOGIN_NAME_MAX_TRAD (LOGNAME_MAX_TRAD + 1) /* and size */ + #define TTYNAME_MAX 128 /* max # of characters in a tty name */ #endif /* if defined(__EXTENSIONS__) || (!defined(_STRICT_STDC) ... */ diff --git a/usr/src/head/stdlib.h b/usr/src/head/stdlib.h index 58aa9cd371..855c31bc39 100644 --- a/usr/src/head/stdlib.h +++ b/usr/src/head/stdlib.h @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. */ @@ -225,7 +227,20 @@ extern char *qfcvt(long double, int, int *, int *); extern char *qgcvt(long double, int, char *); extern char *getcwd(char *, size_t); extern const char *getexecname(void); + +#ifndef __GETLOGIN_DEFINED /* Avoid duplicate in unistd.h */ +#define __GETLOGIN_DEFINED +#ifndef __USE_LEGACY_LOGNAME__ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogin getloginx +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern char *getloginx(void); +#define getlogin getloginx +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* __USE_LEGACY_LOGNAME__ */ extern char *getlogin(void); +#endif /* __GETLOGIN_DEFINED */ + extern int getopt(int, char *const *, const char *); extern char *optarg; extern int optind, opterr, optopt; @@ -333,7 +348,20 @@ extern char *qfcvt(); extern char *qgcvt(); extern char *getcwd(); extern char *getexecname(); + +#ifndef __GETLOGIN_DEFINED /* Avoid duplicate in unistd.h */ +#define __GETLOGIN_DEFINED +#ifndef __USE_LEGACY_LOGNAME__ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogin getloginx +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern char *getloginx(); +#define getlogin getloginx +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* __USE_LEGACY_LOGNAME__ */ extern char *getlogin(); +#endif /* __GETLOGIN_DEFINED */ + extern int getopt(); extern char *optarg; extern int optind, opterr, optopt; diff --git a/usr/src/head/unistd.h b/usr/src/head/unistd.h index ad140cd2e1..aed9eddc14 100644 --- a/usr/src/head/unistd.h +++ b/usr/src/head/unistd.h @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. */ @@ -350,7 +352,20 @@ extern int gethostname(char *, size_t); #elif !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) extern int gethostname(char *, int); #endif + +#ifndef __GETLOGIN_DEFINED /* Avoid duplicate in stdlib.h */ +#define __GETLOGIN_DEFINED +#ifndef __USE_LEGACY_LOGNAME__ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogin getloginx +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern char *getloginx(void); +#define getlogin getloginx +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* __USE_LEGACY_LOGNAME__ */ extern char *getlogin(void); +#endif /* __GETLOGIN_DEFINED */ + #if defined(_XPG4) || defined(__EXTENSIONS__) extern int getopt(int, char *const *, const char *); extern char *optarg; @@ -681,7 +696,20 @@ extern long gethostid(); #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__) extern int gethostname(); #endif + +#ifndef __GETLOGIN_DEFINED /* Avoid duplicate in stdlib.h */ +#define __GETLOGIN_DEFINED +#ifndef __USE_LEGACY_LOGNAME__ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogin getloginx +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern char *getloginx(); +#define getlogin getloginx +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* __USE_LEGACY_LOGNAME__ */ extern char *getlogin(); +#endif /* __GETLOGIN_DEFINED */ + #if defined(_XPG4) || defined(__EXTENSIONS__) extern int getopt(); extern char *optarg; @@ -939,20 +967,24 @@ extern int lockf64(); #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS) +#ifndef __USE_LEGACY_LOGNAME__ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogin_r __posix_getloginx_r +extern int getlogin_r(char *, int); +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern int __posix_getloginx_r(char *, int); +#define getlogin_r __posix_getloginx_r +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#else /* __USE_LEGACY_LOGNAME__ */ #ifdef __PRAGMA_REDEFINE_EXTNAME #pragma redefine_extname getlogin_r __posix_getlogin_r -#pragma redefine_extname ttyname_r __posix_ttyname_r extern int getlogin_r(char *, int); -extern int ttyname_r(int, char *, size_t); #else /* __PRAGMA_REDEFINE_EXTNAME */ - extern int __posix_getlogin_r(char *, int); -extern int __posix_ttyname_r(int, char *, size_t); #ifdef __lint #define getlogin_r __posix_getlogin_r -#define ttyname_r __posix_ttyname_r #else /* !__lint */ @@ -961,6 +993,23 @@ getlogin_r(char *__name, int __len) { return (__posix_getlogin_r(__name, __len)); } + +#endif /* !__lint */ +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* __USE_LEGACY_LOGNAME__ */ + +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname ttyname_r __posix_ttyname_r +extern int ttyname_r(int, char *, size_t); +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern int __posix_ttyname_r(int, char *, size_t); + +#ifdef __lint + +#define ttyname_r __posix_ttyname_r + +#else /* !__lint */ + static int ttyname_r(int __fildes, char *__buf, size_t __size) { @@ -972,7 +1021,16 @@ ttyname_r(int __fildes, char *__buf, size_t __size) #else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ +#ifndef __USE_LEGACY_LOGNAME__ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogin_r getloginx_r +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern char *getloginx_r(char *, int); +#define getlogin_r getloginx_r +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* __USE_LEGACY_LOGNAME__ */ extern char *getlogin_r(char *, int); + extern char *ttyname_r(int, char *, int); #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ @@ -981,20 +1039,24 @@ extern char *ttyname_r(int, char *, int); #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS) +#ifndef __USE_LEGACY_LOGNAME__ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogin_r __posix_getloginx_r +extern int getlogin_r(); +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern int __posix_getloginx_r(); +#define getlogin_r __posix_getloginx_r +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#else /* __USE_LEGACY_LOGNAME__ */ #ifdef __PRAGMA_REDEFINE_EXTNAME #pragma redefine_extname getlogin_r __posix_getlogin_r -#pragma redefine_extname ttyname_r __posix_ttyname_r extern int getlogin_r(); -extern int ttyname_r(); #else /* __PRAGMA_REDEFINE_EXTNAME */ - extern int __posix_getlogin_r(); -extern int __posix_ttyname_r(); #ifdef __lint #define getlogin_r __posix_getlogin_r -#define ttyname_r __posix_ttyname_r #else /* !__lint */ @@ -1005,7 +1067,23 @@ getlogin_r(__name, __len) { return (__posix_getlogin_r(__name, __len)); } -static int +#endif /* !__lint */ +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* __USE_LEGACY_LOGNAME__ */ + +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname ttyname_r __posix_ttyname_r +extern int ttyname_r(); +#else /* __PRAGMA_REDEFINE_EXTNAME */ + +extern int __posix_ttyname_r(); + +#ifdef __lint + +#define ttyname_r __posix_ttyname_r + +#else /* !__lint */ + ttyname_r(__fildes, __buf, __size) int __fildes; char *__buf; @@ -1018,7 +1096,16 @@ ttyname_r(__fildes, __buf, __size) #else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ +#ifndef __USE_LEGACY_LOGNAME__ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogin_r getloginx_r +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern char *getloginx_r(); +#define getlogin_r getloginx_r +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* __USE_LEGACY_LOGNAME__ */ extern char *getlogin_r(); + extern char *ttyname_r(); #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ diff --git a/usr/src/lib/Makefile b/usr/src/lib/Makefile index bae90c4045..7fb2733cc8 100644 --- a/usr/src/lib/Makefile +++ b/usr/src/lib/Makefile @@ -23,6 +23,7 @@ # Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright (c) 2012, Joyent, Inc. All rights reserved. +# Copyright (c) 2013 Gary Mills include ../Makefile.master @@ -197,6 +198,7 @@ SUBDIRS += \ pkcs11 .WAIT \ libpctx .WAIT \ libcpc \ + getloginx \ watchmalloc \ extendedFILE \ madv \ diff --git a/usr/src/lib/getloginx/Makefile b/usr/src/lib/getloginx/Makefile new file mode 100644 index 0000000000..eb6ceec526 --- /dev/null +++ b/usr/src/lib/getloginx/Makefile @@ -0,0 +1,46 @@ +# +# 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 +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +include ../Makefile.lib + +SUBDIRS= $(MACH) +$(BUILD64)SUBDIRS += $(MACH64) + +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +lint := TARGET= lint + +.KEEP_STATE: + +all install clean clobber lint: $(SUBDIRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/lib/getloginx/Makefile.com b/usr/src/lib/getloginx/Makefile.com new file mode 100644 index 0000000000..c72a450862 --- /dev/null +++ b/usr/src/lib/getloginx/Makefile.com @@ -0,0 +1,57 @@ +# +# 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 +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +LIBRARY = getloginx.a +VERS = .1 + +OBJECTS = getloginx.o + +# include library definitions +include ../../Makefile.lib + +SRCDIR = ../common + +LIBS = $(DYNLIB) +LDLIBS += -lc +CFLAGS += $(CCVERBOSE) +CFLAGS64 += $(CCVERBOSE) +CPPFLAGS += -I../common -I../../common/inc -D_REENTRANT +DYNFLAGS += $(ZINTERPOSE) + +.KEEP_STATE: + +all: $(LIBS) + +lint: + $(LINT.c) $(SRCS) $(LDLIBS) + +# include library targets +include ../../Makefile.targ + +pics/%.o: ../common/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) diff --git a/usr/src/lib/getloginx/amd64/Makefile b/usr/src/lib/getloginx/amd64/Makefile new file mode 100644 index 0000000000..904e3c9937 --- /dev/null +++ b/usr/src/lib/getloginx/amd64/Makefile @@ -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 +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +include ../Makefile.com +include ../../Makefile.lib.64 + +.KEEP_STATE: + +install: all $(ROOTLIBS64) diff --git a/usr/src/lib/getloginx/common/getloginx.c b/usr/src/lib/getloginx/common/getloginx.c new file mode 100644 index 0000000000..912ec87ba3 --- /dev/null +++ b/usr/src/lib/getloginx/common/getloginx.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + * + * For old programs that handle long names correctly, + * getlogin() returns a long login name without change. + * + * Use: + * LD_PRELOAD=getloginx.so.1 program args ... + * + */ + +extern char *getloginx(void); + +char * +getlogin(void) +{ + return (getloginx()); +} + +/* */ diff --git a/usr/src/lib/getloginx/common/mapfile-vers b/usr/src/lib/getloginx/common/mapfile-vers new file mode 100644 index 0000000000..c0850bcf2f --- /dev/null +++ b/usr/src/lib/getloginx/common/mapfile-vers @@ -0,0 +1,47 @@ +# +# 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 +# + +# +# MAPFILE HEADER START +# +# WARNING: STOP NOW. DO NOT MODIFY THIS FILE. +# Object versioning must comply with the rules detailed in +# +# usr/src/lib/README.mapfiles +# +# You should not be making modifications here until you've read the most current +# copy of that file. If you need help, contact a gatekeeper for guidance. +# +# MAPFILE HEADER END +# + +$mapfile_version 2 + +SYMBOL_VERSION ILLUMOS_0.1 { # first release of getloginx.so.1 + global: + getlogin; + local: + *; +}; + diff --git a/usr/src/lib/getloginx/i386/Makefile b/usr/src/lib/getloginx/i386/Makefile new file mode 100644 index 0000000000..c1bbe35538 --- /dev/null +++ b/usr/src/lib/getloginx/i386/Makefile @@ -0,0 +1,32 @@ +# +# 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 +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +include ../Makefile.com + +.KEEP_STATE: + +install: all $(ROOTLIBS) diff --git a/usr/src/lib/getloginx/sparc/Makefile b/usr/src/lib/getloginx/sparc/Makefile new file mode 100644 index 0000000000..c1bbe35538 --- /dev/null +++ b/usr/src/lib/getloginx/sparc/Makefile @@ -0,0 +1,32 @@ +# +# 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 +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +include ../Makefile.com + +.KEEP_STATE: + +install: all $(ROOTLIBS) diff --git a/usr/src/lib/getloginx/sparcv9/Makefile b/usr/src/lib/getloginx/sparcv9/Makefile new file mode 100644 index 0000000000..904e3c9937 --- /dev/null +++ b/usr/src/lib/getloginx/sparcv9/Makefile @@ -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 +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +include ../Makefile.com +include ../../Makefile.lib.64 + +.KEEP_STATE: + +install: all $(ROOTLIBS64) diff --git a/usr/src/lib/libc/port/gen/getlogin.c b/usr/src/lib/libc/port/gen/getlogin.c index a3d7b4cf3b..036ed4da49 100644 --- a/usr/src/lib/libc/port/gen/getlogin.c +++ b/usr/src/lib/libc/port/gen/getlogin.c @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -27,10 +29,8 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ -#pragma ident "%Z%%M% %I% %E% SMI" - -#pragma weak _getlogin = getlogin -#pragma weak _getlogin_r = getlogin_r +#pragma weak _getlogin = getloginx +#pragma weak _getlogin_r = getloginx_r #include "lint.h" #include <sys/types.h> @@ -47,28 +47,42 @@ #include <mtlib.h> #include "tsd.h" +/* Revert the renames done in unistd.h */ +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname getlogint getlogin +#pragma redefine_extname getlogint_r getlogin_r +#pragma redefine_extname __posix_getlogint_r __posix_getlogin_r +#else /* __PRAGMA_REDEFINE_EXTNAME */ +#ifdef getlogin +#undef getlogin +#endif /* getlogin */ +#ifdef getlogin_r +#undef getlogin_r +#endif /* getlogin_r */ +#ifdef __posix_getlogin_r +#undef __posix_getlogin_r +#endif /* __posix_getlogin_r */ +#define getlogint getlogin +#define getlogint_r getlogin_r +#define __posix_getlogint_r __posix_getlogin_r +#endif /* __PRAGMA_REDEFINE_EXTNAME */ + /* - * XXX - _POSIX_LOGIN_NAME_MAX limits the length of a login name. The utmpx - * interface provides for a 32 character login name, but for the sake of - * compatibility, we are still using the old utmp-imposed limit. + * Use the full length of a login name. + * The utmpx interface provides for a 32 character login name. */ +#define NMAX (sizeof (((struct utmpx *)0)->ut_user)) /* - * POSIX.1c Draft-6 version of the function getlogin_r. - * It was implemented by Solaris 2.3. + * Common function */ -char * -getlogin_r(char *answer, int namelen) +static char * +getl_r_common(char *answer, size_t namelen, size_t maxlen) { int uf; off64_t me; struct futmpx ubuf; - if (namelen < _POSIX_LOGIN_NAME_MAX) { - errno = ERANGE; - return (NULL); - } - if ((me = (off64_t)ttyslot()) < 0) return (NULL); if ((uf = open64(UTMPX_FILE, 0)) < 0) @@ -81,24 +95,82 @@ getlogin_r(char *answer, int namelen) (void) close(uf); if (ubuf.ut_user[0] == '\0') return (NULL); - (void) strncpy(&answer[0], &ubuf.ut_user[0], - _POSIX_LOGIN_NAME_MAX - 1); - answer[_POSIX_LOGIN_NAME_MAX - 1] = '\0'; + + /* Insufficient buffer size */ + if (namelen < strnlen(&ubuf.ut_user[0], maxlen)) { + errno = ERANGE; + return (NULL); + } + (void) strncpy(&answer[0], &ubuf.ut_user[0], maxlen); + answer[maxlen] = '\0'; return (&answer[0]); } /* + * POSIX.1c Draft-6 version of the function getlogin_r. + * It was implemented by Solaris 2.3. + */ +char * +getlogint_r(char *answer, int namelen) +{ + return (getl_r_common(answer, (size_t)namelen, LOGNAME_MAX_TRAD)); +} + +/* + * POSIX.1c standard version of the function getlogin_r. + * User gets it via static getlogin_r from the header file. + */ +int +__posix_getlogint_r(char *name, int namelen) +{ + int nerrno = 0; + int oerrno = errno; + + errno = 0; + if (getl_r_common(name, (size_t)namelen, LOGNAME_MAX_TRAD) == NULL) { + if (errno == 0) + nerrno = EINVAL; + else + nerrno = errno; + } + errno = oerrno; + return (nerrno); +} + +char * +getlogint(void) +{ + char *answer = tsdalloc(_T_LOGIN, LOGIN_NAME_MAX_TRAD, NULL); + + if (answer == NULL) + return (NULL); + return (getl_r_common(answer, LOGIN_NAME_MAX_TRAD, LOGNAME_MAX_TRAD)); +} + +/* + * POSIX.1c Draft-6 version of the function getlogin_r. + * It was implemented by Solaris 2.3. + * For extended login names, selected by redefine_extname in unistd.h. + */ +char * +getloginx_r(char *answer, int namelen) +{ + return (getl_r_common(answer, (size_t)namelen, NMAX)); +} + +/* * POSIX.1c standard version of the function getlogin_r. * User gets it via static getlogin_r from the header file. + * For extended login names, selected by redefine_extname in unistd.h. */ int -__posix_getlogin_r(char *name, int namelen) +__posix_getloginx_r(char *name, int namelen) { int nerrno = 0; int oerrno = errno; errno = 0; - if (getlogin_r(name, namelen) == NULL) { + if (getl_r_common(name, (size_t)namelen, NMAX) == NULL) { if (errno == 0) nerrno = EINVAL; else @@ -108,12 +180,15 @@ __posix_getlogin_r(char *name, int namelen) return (nerrno); } +/* + * For extended login names, selected by redefine_extname in unistd.h. + */ char * -getlogin(void) +getloginx(void) { - char *answer = tsdalloc(_T_LOGIN, _POSIX_LOGIN_NAME_MAX, NULL); + char *answer = tsdalloc(_T_LOGIN, LOGIN_NAME_MAX, NULL); if (answer == NULL) return (NULL); - return (getlogin_r(answer, _POSIX_LOGIN_NAME_MAX)); + return (getl_r_common(answer, LOGIN_NAME_MAX, NMAX)); } diff --git a/usr/src/lib/libc/port/gen/sysconf.c b/usr/src/lib/libc/port/gen/sysconf.c index 8c2e6f4eb2..8e852ce1c8 100644 --- a/usr/src/lib/libc/port/gen/sysconf.c +++ b/usr/src/lib/libc/port/gen/sysconf.c @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -372,7 +374,7 @@ sysconf(int name) return ((long)NSS_BUFLEN_PASSWD); case _SC_LOGIN_NAME_MAX: - return ((long)(LOGNAME_MAX + 1)); + return ((long)(LOGIN_NAME_MAX)); case _SC_THREAD_KEYS_MAX: return (-1L); diff --git a/usr/src/lib/libc/port/llib-lc b/usr/src/lib/libc/port/llib-lc index 1781f34b2b..eb2fb4357b 100644 --- a/usr/src/lib/libc/port/llib-lc +++ b/usr/src/lib/libc/port/llib-lc @@ -23,6 +23,7 @@ * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved. + * Copyright (c) 2013 Gary Mills */ /* LINTLIBRARY */ @@ -194,6 +195,7 @@ char *__posix_asctime_r(const struct tm *_RESTRICT_KYWD, char *_RESTRICT_KYWD); char *__posix_ctime_r(const time_t *, char *); int __posix_ttyname_r(int, char *, size_t); int __posix_getlogin_r(char *, int); +int __posix_getloginx_r(char *, int); /* * XPG4 versions of standard libc routines; these aren't extracted @@ -477,7 +479,15 @@ int gethz(void); uint_t getisax(uint32_t *, uint_t); /* getlogin.c */ +char *getloginx(void); +char *getloginx_r(char *, int); +#ifdef getlogin +#undef getlogin +#endif /* getlogin */ char *getlogin(void); +#ifdef getlogin_r +#undef getlogin_r +#endif /* getlogin_r */ char *getlogin_r(char *, int); /* getmntent.c */ diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index d6907e359d..c30ed85d24 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -26,6 +26,8 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. +# Copyright (c) 2013 Gary Mills +# # # MAPFILE HEADER START @@ -90,6 +92,13 @@ $if _x86 && _ELF64 $add amd64 $endif +SYMBOL_VERSION ILLUMOS_0.6 { # Illumos additions + protected: + getloginx; + getloginx_r; + __posix_getloginx_r; +} ILLUMOS_0.5; + SYMBOL_VERSION ILLUMOS_0.5 { # common C++ ABI exit handlers protected: __cxa_atexit; diff --git a/usr/src/man/man1/ps.1 b/usr/src/man/man1/ps.1 index 8e97b196c2..7ff574f12b 100644 --- a/usr/src/man/man1/ps.1 +++ b/usr/src/man/man1/ps.1 @@ -2,6 +2,7 @@ .\" Copyright 1989 AT&T .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved .\" Copyright (c) 2012, Joyent, Inc. All Rights Reserved +.\" Copyright (c) 2013 Gary Mills .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text @@ -11,13 +12,13 @@ .\" 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] -.TH PS 1 "Aug 16, 2009" +.TH PS 1 "Apr 16, 2013" .SH NAME ps \- report process status .SH SYNOPSIS .LP .nf -\fBps\fR [\fB-aAcdefjHlLPyZ\fR] [\fB-g\fR \fIgrplist\fR] [\fB-h\fR \fIlgrplist\fR] +\fBps\fR [\fB-aAcdefjHlLPWyZ\fR] [\fB-g\fR \fIgrplist\fR] [\fB-h\fR \fIlgrplist\fR] [\fB-n\fR \fInamelist\fR] [\fB-o\fR \fIformat\fR]... [\fB-p\fR \fIproclist\fR] [\fB-s\fR \fIsidlist\fR] [\fB-t\fR \fIterm\fR] [\fB-u\fR \fIuidlist\fR] [\fB-U\fR \fIuidlist\fR] [\fB-G\fR \fIgidlist\fR] [\fB-z\fR \fIzonelist\fR] @@ -261,6 +262,18 @@ form of a blank- or comma-separated list. .sp .ne 2 .na +\fB\fB-W\fR\fR +.ad +.RS 15n +Truncate long names even when \fBps\fR would normally print them +in full. +A trailing asterisk marks a long name that has been truncated +to fit the column. +.RE + +.sp +.ne 2 +.na \fB\fB-y\fR\fR .ad .RS 15n @@ -405,6 +418,8 @@ Zombie state: process terminated and parent not waiting. .RS 14n The effective user \fBID\fR number of the process (the login name is printed under the \fB-f\fR option). +A trailing asterisk marks a long name that has been truncated +to fit the column. .RE .sp @@ -612,8 +627,9 @@ text. The fields specified are written in the order specified on the command line, and should be arranged in columns in the output. The field widths are selected by the system to be at least as wide as the header text (default or overridden value). If the header text is null, such as \fB-o\fR \fIuser=,\fR -the field width is at least as wide as the default header text. If all header -text fields are null, no header line is written. +the field width is at least as wide as the default header text. +Long names are not truncated in this mode. +If all header text fields are null, no header line is written. .sp .LP The following names are recognized in the POSIX locale: diff --git a/usr/src/man/man1m/prstat.1m b/usr/src/man/man1m/prstat.1m index b70124b9b8..d86e653971 100644 --- a/usr/src/man/man1m/prstat.1m +++ b/usr/src/man/man1m/prstat.1m @@ -1,18 +1,19 @@ '\" te +.\" Copyright (c) 2013 Gary Mills .\" Copyright (c) 2006, 2009 Sun Microsystems, Inc. All Rights Reserved. .\" 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] -.TH PRSTAT 1M "Jun 25, 2009" +.TH PRSTAT 1M "Apr 15, 2013" .SH NAME prstat \- report active process statistics .SH SYNOPSIS .LP .nf -\fBprstat\fR [\fB-acHJLmRrtTv\fR] [\fB-d\fR u | d] [\fB-C\fR \fIpsrsetlist\fR] [\fB-h\fR \fIlgrplist\fR] +\fBprstat\fR [\fB-acHJLmRrtTvWZ\fR] [\fB-d\fR u | d] [\fB-C\fR \fIpsrsetlist\fR] [\fB-h\fR \fIlgrplist\fR] [\fB-j\fR \fIprojlist\fR] [\fB-k\fR \fItasklist\fR] [\fB-n\fR \fIntop\fR[,\fInbottom\fR]] [\fB-p\fR \fIpidlist\fR] [\fB-P\fR \fIcpulist\fR] [\fB-s\fR \fIkey\fR | \fB-S\fR \fIkey\fR ] - [\fB-u\fR \fIeuidlist\fR] [\fB-U\fR \fIuidlist\fR] [\fB-z\fR \fIzoneidlist\fR] [\fB-Z\fR] + [\fB-u\fR \fIeuidlist\fR] [\fB-U\fR \fIuidlist\fR] [\fB-z\fR \fIzoneidlist\fR] [\fIinterval\fR [\fIcount\fR]] .fi @@ -56,6 +57,7 @@ displays separate reports about processes and users at the same time. .sp .6 .RS 4n Print new reports below previous reports instead of overprinting them. +Long names are not truncated in this mode. .RE .sp @@ -128,6 +130,8 @@ project \fBID\fR. See \fBproject\fR(4). .RS 4n Report information about processes and projects. In this mode \fBprstat\fR displays separate reports about processes and projects at the same time. +A trailing asterisk marks a long name that has been truncated +to fit the column. .RE .sp @@ -364,6 +368,19 @@ with the \fB-\fR sign. .sp .ne 2 .na +\fB\fB-W\fR\fR +.ad +.sp .6 +.RS 4n +Truncate long names even when \fBprstat\fR would normally print them +in full. +A trailing asterisk marks a long name that has been truncated +to fit the column. +.RE + +.sp +.ne 2 +.na \fB\fB-z\fR \fIzoneidlist\fR\fR .ad .sp .6 @@ -382,6 +399,8 @@ can be specified as either a zone name or a numerical zone ID. See .RS 4n Report information about processes and zones. In this mode, \fBprstat\fR displays separate reports about processes and zones at the same time. +A trailing asterisk marks a long name that has been truncated +to fit the column. .RE .SH OUTPUT @@ -407,6 +426,8 @@ The process \fBID\fR of the process. .sp .6 .RS 4n The real user (login) name or real user \fBID\fR. +A trailing asterisk marks a long name that has been truncated +to fit the column. .RE .sp diff --git a/usr/src/man/man1m/useradd.1m b/usr/src/man/man1m/useradd.1m index 6829f782b4..9e0fe52d07 100644 --- a/usr/src/man/man1m/useradd.1m +++ b/usr/src/man/man1m/useradd.1m @@ -1,10 +1,11 @@ '\" te +.\" Copyright (c) 2013 Gary Mills .\" Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. .\" Copyright 1989 AT&T .\" 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] -.TH USERADD 1M "Feb 19, 2008" +.TH USERADD 1M "Apr 16, 2013" .SH NAME useradd \- administer a new user login on the system .SH SYNOPSIS @@ -59,6 +60,11 @@ this limit. \fBuseradd\fR requires that usernames be in the format described in \fBpasswd\fR(4). A warning message is displayed if these restrictions are not met. See \fBpasswd\fR(4) for the requirements for usernames. +.LP +To change the action of \fBuseradd\fR when the traditional login name +length limit of eight characters is exceeded, edit the file +\fB/etc/default/useradd\fR by removing the \fB#\fR (pound sign) before the +appropriate \fBEXCEED_TRAD=\fR entry, and adding it before the others. .SH OPTIONS .sp .LP @@ -416,6 +422,9 @@ reserved for allocation by the Solaris Operating System. .SH FILES .sp .LP +\fB/etc/default/useradd\fR +.sp +.LP \fB/etc/datemsk\fR .sp .LP diff --git a/usr/src/man/man3c/getlogin.3c b/usr/src/man/man3c/getlogin.3c index 3334791c69..6813834356 100644 --- a/usr/src/man/man3c/getlogin.3c +++ b/usr/src/man/man3c/getlogin.3c @@ -1,4 +1,5 @@ '\" te +.\" Copyright (c) 2013 Gary Mills .\" Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved. .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. @@ -9,7 +10,7 @@ .\" 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] -.TH GETLOGIN 3C "May 18, 2004" +.TH GETLOGIN 3C "May 25, 2013" .SH NAME getlogin, getlogin_r \- get login name .SH SYNOPSIS @@ -42,6 +43,28 @@ locate the correct password file entry when the same user \fBID\fR is shared by several login names. .sp .LP +The login name plus the terminating null byte can be up to 33 characters +in length. +Newly-compiled programs should use the \fBLOGIN_NAME_MAX\fR symbol, +defined in <\fBlimits.h\fR>, to size the buffer. +Older programs that call \fBgetlogin()\fR expect only the legacy +9-character length. +These automatically link to a version of the \fBgetlogin()\fR functions that +truncates longer login names. +It's also possible to compile new programs that link to truncating versions +of these functions by defining \fB__USE_LEGACY_LOGNAME__\fR in the +compile environment. +.sp +.LP +Some older programs will correctly handle long login names returned +by the \fBgetlogin()\fR function. +For this case, the user compatibility library +\fB/usr/lib/getloginx.so.1\fR redirects to a version of the \fBgetlogin()\fR +function that returns the long name. +This library should be added to such an application +at runtime using \fBLD_PRELOAD\fR. +.sp +.LP If \fBgetlogin()\fR is called within a process that is not attached to a terminal, it returns a null pointer. The correct procedure for determining the login name is to call \fBcuserid\fR(3C), or to call \fBgetlogin()\fR and if it @@ -51,7 +74,7 @@ fails to call \fBgetpwuid\fR(3C). The \fBgetlogin_r()\fR function has the same functionality as \fBgetlogin()\fR except that the caller must supply a buffer \fIname\fR with length \fInamelen\fR to store the result. The \fIname\fR buffer must be at least -\fB_POSIX_LOGIN_NAME_MAX\fR bytes in size (defined in <\fBlimits.h\fR>). The +\fBLOGIN_NAME_MAX\fR bytes in size (defined in <\fBlimits.h\fR>). The POSIX version (see \fBstandards\fR(5)) of \fBgetlogin_r()\fR takes a \fInamesize\fR parameter of type \fBsize_t\fR. .SH RETURN VALUES @@ -151,6 +174,24 @@ returns the name associated with the real user ID of the process. user access and administration information .RE +.sp +.ne 2 +.na +\fB\fB/usr/lib/getloginx.so.1\fR\fR +.ad +.RS 18n +A compatibility library that returns long login names to older applications. +.RE + +.sp +.ne 2 +.na +\fB\fB/usr/lib/64/getloginx.so.1\fR\fR +.ad +.RS 18n +A 64-bit compatibility library to return long login names. +.RE + .SH ATTRIBUTES .sp .LP diff --git a/usr/src/man/man3c/sysconf.3c b/usr/src/man/man3c/sysconf.3c index a200a3ac6c..78a75e64a7 100644 --- a/usr/src/man/man3c/sysconf.3c +++ b/usr/src/man/man3c/sysconf.3c @@ -1,4 +1,5 @@ '\" te +.\" Copyright (c) 2013 Gary Mills .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Copyright 1989 AT&T @@ -9,7 +10,7 @@ .\" 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] -.TH SYSCONF 3C "Mar 26, 2008" +.TH SYSCONF 3C "Apr 16, 2013" .SH NAME sysconf \- get configurable system variables .SH SYNOPSIS @@ -142,7 +143,7 @@ _SC_JOB_CONTROL _POSIX_JOB_CONTROL Job control supported? _SC_LINE_MAX LINE_MAX Max length of input line -_SC_LOGIN_NAME_MAX LOGNAME_MAX + 1 Max length of login +_SC_LOGIN_NAME_MAX LOGIN_NAME_MAX Max length of login name _SC_LOGNAME_MAX LOGNAME_MAX _SC_MAPPED_FILES _POSIX_MAPPED_FILES Supports Memory diff --git a/usr/src/man/man4/passwd.4 b/usr/src/man/man4/passwd.4 index c7e2cf2639..5e5670d694 100644 --- a/usr/src/man/man4/passwd.4 +++ b/usr/src/man/man4/passwd.4 @@ -1,10 +1,11 @@ '\" te +.\" Copyright (c) 2013 Gary Mills .\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright 1989 AT&T .\" 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] -.TH PASSWD 4 "Jul 28, 2004" +.TH PASSWD 4 "Apr 16, 2013" .SH NAME passwd \- password file .SH SYNOPSIS @@ -47,7 +48,7 @@ where is the user's login name. .sp The login (\fBlogin\fR) and role (\fBrole\fR) fields accept a string of no more -than eight bytes consisting of characters from the set of alphabetic +than 32 bytes consisting of characters from the set of alphabetic characters, numeric characters, period (\fB\&.\fR), underscore (\fB_\fR), and hyphen (\fB-\fR). The first character should be alphabetic and the field should contain at least one lower case alphabetic character. A warning message is diff --git a/usr/src/pkg/manifests/SUNWcs.mf b/usr/src/pkg/manifests/SUNWcs.mf index a477cc0e65..983615a9d9 100644 --- a/usr/src/pkg/manifests/SUNWcs.mf +++ b/usr/src/pkg/manifests/SUNWcs.mf @@ -22,6 +22,7 @@ # # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. # Copyright 2012 Nexenta Systems, Inc. All rights reserved. +# Copyright (c) 2013 Gary Mills # <include SUNWcs.man1.inc> @@ -346,6 +347,7 @@ file path=etc/default/passwd group=sys preserve=true file path=etc/default/su group=sys preserve=true file path=etc/default/syslogd group=sys preserve=true file path=etc/default/tar group=sys preserve=true +file path=etc/default/useradd group=sys preserve=true file path=etc/default/utmpd group=sys preserve=true file path=etc/dev/reserved_devnames group=sys preserve=true file path=etc/device.tab group=root mode=0444 preserve=true diff --git a/usr/src/pkg/manifests/system-library.mf b/usr/src/pkg/manifests/system-library.mf index 9ec73f889c..8421d61163 100644 --- a/usr/src/pkg/manifests/system-library.mf +++ b/usr/src/pkg/manifests/system-library.mf @@ -23,6 +23,7 @@ # Copyright 2011 Nexenta Systems, Inc. All rights reserved. # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. # Copyright 2012 OmniTI Computer Consulting, Inc. All rights reserved. +# Copyright (c) 2013 Gary Mills # <include system-library.man3.inc> @@ -316,6 +317,7 @@ file path=lib/nss_files.so.1 file path=lib/nss_nis.so.1 file path=lib/nss_user.so.1 file path=usr/lib/$(ARCH64)/0@0.so.1 +file path=usr/lib/$(ARCH64)/getloginx.so.1 file path=usr/lib/$(ARCH64)/libadutils.so.1 file path=usr/lib/$(ARCH64)/libast.so.1 file path=usr/lib/$(ARCH64)/libbsdmalloc.so.1 @@ -384,6 +386,7 @@ file path=usr/lib/cfgadm/scsi.so.1 file path=usr/lib/cfgadm/shp.so.1 file path=usr/lib/cfgadm/usb.so.1 file path=usr/lib/extendedFILE.so.1 +file path=usr/lib/getloginx.so.1 file path=usr/lib/lib.b mode=0444 file path=usr/lib/libadutils.so.1 file path=usr/lib/libast.so.1 |