Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-3]: src/usr.sbin/user Pull up revision 1.79 (requested by peter i...



details:   https://anonhg.NetBSD.org/src/rev/6b40b0ab7b1e
branches:  netbsd-3
changeset: 575334:6b40b0ab7b1e
user:      tron <tron%NetBSD.org@localhost>
date:      Wed Apr 13 15:59:37 2005 +0000

description:
Pull up revision 1.79 (requested by peter in ticket #136):
Do some Common Subexpression Elimination when testing for valid characters
in login and group names.

diffstat:

 usr.sbin/user/user.c |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (46 lines):

diff -r 71b8ec23ab1d -r 6b40b0ab7b1e usr.sbin/user/user.c
--- a/usr.sbin/user/user.c      Wed Apr 13 15:58:51 2005 +0000
+++ b/usr.sbin/user/user.c      Wed Apr 13 15:59:37 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.77.2.1 2005/04/13 15:58:51 tron Exp $ */
+/* $NetBSD: user.c,v 1.77.2.2 2005/04/13 15:59:37 tron Exp $ */
 
 /*
  * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -35,7 +35,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999 \
                The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.77.2.1 2005/04/13 15:58:51 tron Exp $");
+__RCSID("$NetBSD: user.c,v 1.77.2.2 2005/04/13 15:59:37 tron Exp $");
 #endif
 
 #include <sys/types.h>
@@ -633,6 +633,9 @@
        return 1;
 }
 
+/* the valid characters for login and group names */
+#define VALID_CHAR(c)  (isalnum(c) || (c) == '.' || (c) == '_' || (c) == '-')
+
 /* return 1 if `login' is a valid login name */
 static int
 valid_login(char *login_name, int allow_samba)
@@ -643,7 +646,7 @@
                return 0;
        }
        for (cp = login_name ; *cp ; cp++) {
-               if (!isalnum(*cp) && *cp != '.' && *cp != '_' && *cp != '-') {
+               if (!VALID_CHAR(*cp)) {
 #ifdef EXTENSIONS
                        /* check for a trailing '$' in a Samba user name */
                        if (allow_samba && *cp == '$' && *(cp + 1) == 0x0) {
@@ -663,7 +666,7 @@
        unsigned char   *cp;
 
        for (cp = group ; *cp ; cp++) {
-               if (!isalnum(*cp) && *cp != '.' && *cp != '_' && *cp != '-') {
+               if (!VALID_CHAR(*cp)) {
                        return 0;
                }
        }



Home | Main Index | Thread Index | Old Index