summaryrefslogtreecommitdiff
path: root/usr/src/cmd/getent
diff options
context:
space:
mode:
authorvp157776 <none@none>2007-04-09 05:58:12 -0700
committervp157776 <none@none>2007-04-09 05:58:12 -0700
commit34a0f871d192b33b865455a8812a3d34c1866315 (patch)
treeb6cc7e9c4c0a6c0df989241e5f49f415f9a7a62f /usr/src/cmd/getent
parentc9503a497f482bf9524b37eea8c69239425bcdf4 (diff)
downloadillumos-joyent-34a0f871d192b33b865455a8812a3d34c1866315.tar.gz
6490974 getent fails when groupname or username begins with a number
Diffstat (limited to 'usr/src/cmd/getent')
-rw-r--r--usr/src/cmd/getent/dogetgr.c29
-rw-r--r--usr/src/cmd/getent/dogetpw.c30
2 files changed, 43 insertions, 16 deletions
diff --git a/usr/src/cmd/getent/dogetgr.c b/usr/src/cmd/getent/dogetgr.c
index bd9fa315cd..fcd7b64f43 100644
--- a/usr/src/cmd/getent/dogetgr.c
+++ b/usr/src/cmd/getent/dogetgr.c
@@ -2,9 +2,8 @@
* 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.
+ * 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.
@@ -19,15 +18,18 @@
*
* CDDL HEADER END
*/
-#ident "%Z%%M% %I% %E% SMI"
/*
- * Copyright (c) 1994, by Sun Microsystems, Inc.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
*/
+#pragma ident "%Z%%M% %I% %E% SMI"
+
#include <stdio.h>
#include <grp.h>
#include <stdlib.h>
+#include <errno.h>
#include "getent.h"
@@ -76,11 +78,22 @@ dogetgr(const char **list)
(void) putgrent(grp, stdout);
} else {
for (; *list != NULL; list++) {
+ errno = 0;
+
+ /*
+ * Here we assume that the argument passed is
+ * a gid, if it can be completely transformed
+ * to a long integer. So we check for gid in
+ * the database and if we fail then we check
+ * for the group name.
+ * If the argument passed is not numeric, then
+ * we take it as the group name and proceed.
+ */
gid = strtol(*list, &ptr, 10);
- if (ptr == *list)
+ if (!(*ptr == '\0' && errno == 0) ||
+ ((grp = getgrgid(gid)) == NULL)) {
grp = getgrnam(*list);
- else
- grp = getgrgid(gid);
+ }
if (grp == NULL)
rc = EXC_NAME_NOT_FOUND;
else
diff --git a/usr/src/cmd/getent/dogetpw.c b/usr/src/cmd/getent/dogetpw.c
index e0ee12dd19..19257ad210 100644
--- a/usr/src/cmd/getent/dogetpw.c
+++ b/usr/src/cmd/getent/dogetpw.c
@@ -2,9 +2,8 @@
* 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.
+ * 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.
@@ -19,15 +18,18 @@
*
* CDDL HEADER END
*/
-#ident "%Z%%M% %I% %E% SMI"
+
+#pragma ident "%Z%%M% %I% %E% SMI"
/*
- * Copyright (c) 1994, by Sun Microsystems, Inc.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
*/
#include <stdio.h>
#include <pwd.h>
#include <stdlib.h>
+#include <errno.h>
#include "getent.h"
/*
@@ -47,11 +49,23 @@ dogetpw(const char **list)
(void) putpwent(pwp, stdout);
} else {
for (; *list != NULL; list++) {
+ errno = 0;
+
+ /*
+ * Here we assume that the argument passed is
+ * a uid, if it can be completely transformed
+ * to a long integer. So we check for uid in
+ * the database and if we fail then we check
+ * for the user name.
+ * If the argument passed is not numeric, then
+ * we take it as the user name and proceed.
+ */
uid = strtol(*list, &ptr, 10);
- if (ptr == *list)
+ if (!(*ptr == '\0' && errno == 0) ||
+ ((pwp = getpwuid(uid)) == NULL)) {
pwp = getpwnam(*list);
- else
- pwp = getpwuid(uid);
+ }
+
if (pwp == NULL)
rc = EXC_NAME_NOT_FOUND;
else