summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith M Wesolowski <wesolows@foobazco.org>2013-01-28 18:26:28 +0000
committerKeith M Wesolowski <wesolows@foobazco.org>2013-01-29 00:43:26 +0000
commit7ade4aeb90d841655b5f8accbab8e0c91a88ecc6 (patch)
tree8c832283fb67aa34fc36e5ac0797e7e628ce0706
parentccce5498e8acd2956467f73c04fa66e83fe9ddae (diff)
downloadillumos-joyent-7ade4aeb90d841655b5f8accbab8e0c91a88ecc6.tar.gz
OS-1836 passwd command truncates usernames to 8 chars by default
Reviewed-by: Robert Mustacchi <rm@joyent.com>
-rw-r--r--usr/src/cmd/passwd/Makefile4
-rw-r--r--usr/src/cmd/passwd/passwd.c10
-rw-r--r--usr/src/head/unistd.h3
-rw-r--r--usr/src/lib/libc/port/gen/getlogin.c78
-rw-r--r--usr/src/lib/libc/port/mapfile-vers1
5 files changed, 68 insertions, 28 deletions
diff --git a/usr/src/cmd/passwd/Makefile b/usr/src/cmd/passwd/Makefile
index d53cad2cd6..079e8b6050 100644
--- a/usr/src/cmd/passwd/Makefile
+++ b/usr/src/cmd/passwd/Makefile
@@ -33,9 +33,7 @@ lint := LDLIBS += -lpasswdutil
LDFLAGS += $(ZIGNORE)
LDLIBS += -lbsm -lpam -lnsl
-CERRWARN += -_gcc=-Wno-switch
-CERRWARN += -_gcc=-Wno-parentheses
-CERRWARN += -_gcc=-Wno-uninitialized
+CPPFLAGS += -D__EXTENSIONS__
FILEMODE = 06555
XGETFLAGS += -a -x $(PROG).xcl
diff --git a/usr/src/cmd/passwd/passwd.c b/usr/src/cmd/passwd/passwd.c
index 851de6f237..c2baf63423 100644
--- a/usr/src/cmd/passwd/passwd.c
+++ b/usr/src/cmd/passwd/passwd.c
@@ -236,7 +236,7 @@ main(int argc, char *argv[])
int updated_reps;
- if (prognamep = strrchr(argv[0], '/'))
+ if ((prognamep = strrchr(argv[0], '/')) != NULL)
++prognamep;
else
prognamep = argv[0];
@@ -273,7 +273,7 @@ main(int argc, char *argv[])
argc -= optind;
if (argc < 1) {
- if ((usrname = getlogin()) == NULL) {
+ if ((usrname = getxlogin()) == NULL) {
struct passwd *pass = getpwuid(uid);
if (pass != NULL)
usrname = pass->pw_name;
@@ -1240,10 +1240,10 @@ get_attr(char *username, pwu_repository_t *repository, attrlist **attributes)
void
display_attr(char *usrname, attrlist *attributes)
{
- char *status;
+ char *status = NULL;
char *passwd;
long lstchg;
- int min, max, warn;
+ int min = 0, max = 0, warn = 0;
while (attributes) {
switch (attributes->type) {
@@ -1275,6 +1275,8 @@ display_attr(char *usrname, attrlist *attributes)
case ATTR_WARN:
warn = attributes->data.val_i;
break;
+ default:
+ break;
}
attributes = attributes->next;
}
diff --git a/usr/src/head/unistd.h b/usr/src/head/unistd.h
index 75078dd318..4b464d5c47 100644
--- a/usr/src/head/unistd.h
+++ b/usr/src/head/unistd.h
@@ -348,6 +348,9 @@ extern int gethostname(char *, size_t);
extern int gethostname(char *, int);
#endif
extern char *getlogin(void);
+#if defined(__EXTENSIONS__)
+extern char *getxlogin(void);
+#endif
#if defined(_XPG4) || defined(__EXTENSIONS__)
extern int getopt(int, char *const *, const char *);
extern char *optarg;
diff --git a/usr/src/lib/libc/port/gen/getlogin.c b/usr/src/lib/libc/port/gen/getlogin.c
index a3d7b4cf3b..db86ceef4c 100644
--- a/usr/src/lib/libc/port/gen/getlogin.c
+++ b/usr/src/lib/libc/port/gen/getlogin.c
@@ -27,7 +27,9 @@
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
-#pragma ident "%Z%%M% %I% %E% SMI"
+/*
+ * Copyright (c) 2013 Joyent, Inc. All rights reserved.
+ */
#pragma weak _getlogin = getlogin
#pragma weak _getlogin_r = getlogin_r
@@ -35,6 +37,7 @@
#include "lint.h"
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
@@ -51,40 +54,54 @@
* 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.
+ *
+ * If you want the full name, use the Consolidation Private getxlogin().
*/
-/*
- * POSIX.1c Draft-6 version of the function getlogin_r.
- * It was implemented by Solaris 2.3.
- */
-char *
-getlogin_r(char *answer, int namelen)
+static int
+generic_getlogin(char *answer, int namelen, boolean_t truncate)
{
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);
+ return (-1);
if ((uf = open64(UTMPX_FILE, 0)) < 0)
- return (NULL);
+ return (-1);
(void) lseek64(uf, me * sizeof (ubuf), SEEK_SET);
if (read(uf, &ubuf, sizeof (ubuf)) != sizeof (ubuf)) {
(void) close(uf);
- return (NULL);
+ return (-1);
}
(void) close(uf);
if (ubuf.ut_user[0] == '\0')
+ return (-1);
+ if (strlen(ubuf.ut_user) >= namelen && !truncate) {
+ errno = ERANGE;
+ return (-1);
+ }
+ (void) strlcpy(answer, ubuf.ut_user, namelen);
+
+ return (0);
+}
+
+/*
+ * POSIX.1c Draft-6 version of the function getlogin_r.
+ * It was implemented by Solaris 2.3.
+ */
+char *
+getlogin_r(char *answer, int namelen)
+{
+ if (namelen < _POSIX_LOGIN_NAME_MAX) {
+ errno = ERANGE;
return (NULL);
- (void) strncpy(&answer[0], &ubuf.ut_user[0],
- _POSIX_LOGIN_NAME_MAX - 1);
- answer[_POSIX_LOGIN_NAME_MAX - 1] = '\0';
- return (&answer[0]);
+ }
+
+ if (generic_getlogin(answer, _POSIX_LOGIN_NAME_MAX, B_TRUE) == 0)
+ return (answer);
+
+ return (NULL);
}
/*
@@ -98,7 +115,7 @@ __posix_getlogin_r(char *name, int namelen)
int oerrno = errno;
errno = 0;
- if (getlogin_r(name, namelen) == NULL) {
+ if (getlogin_r(name, namelen) != 0) {
if (errno == 0)
nerrno = EINVAL;
else
@@ -111,9 +128,28 @@ __posix_getlogin_r(char *name, int namelen)
char *
getlogin(void)
{
- char *answer = tsdalloc(_T_LOGIN, _POSIX_LOGIN_NAME_MAX, NULL);
+ struct futmpx fu;
+ char *answer = tsdalloc(_T_LOGIN,
+ MAX(sizeof (fu.ut_user), _POSIX_LOGIN_NAME_MAX), NULL);
if (answer == NULL)
return (NULL);
return (getlogin_r(answer, _POSIX_LOGIN_NAME_MAX));
}
+
+char *
+getxlogin(void)
+{
+ struct futmpx fu;
+ char *answer = tsdalloc(_T_LOGIN,
+ MAX(sizeof (fu.ut_user), _POSIX_LOGIN_NAME_MAX), NULL);
+
+ if (answer == NULL)
+ return (NULL);
+
+ if (generic_getlogin(answer,
+ MAX(sizeof (fu.ut_user), _POSIX_LOGIN_NAME_MAX), B_FALSE) != 0)
+ return (NULL);
+
+ return (answer);
+}
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index 6715f006b4..c5587adf3d 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -2725,6 +2725,7 @@ $endif
getvmusage;
__getwchar_xpg5;
__getwc_xpg5;
+ getxlogin;
gtty;
__idmap_flush_kcache;
__idmap_reg;