Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/user Do some Common Subexpression Elimination when ...



details:   https://anonhg.NetBSD.org/src/rev/b45f18f19c06
branches:  trunk
changeset: 580037:b45f18f19c06
user:      agc <agc%NetBSD.org@localhost>
date:      Tue Apr 05 22:54:26 2005 +0000

description:
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 a32a78232edb -r b45f18f19c06 usr.sbin/user/user.c
--- a/usr.sbin/user/user.c      Tue Apr 05 22:03:57 2005 +0000
+++ b/usr.sbin/user/user.c      Tue Apr 05 22:54:26 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.78 2005/04/05 22:03:57 peter Exp $ */
+/* $NetBSD: user.c,v 1.79 2005/04/05 22:54:26 agc 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.78 2005/04/05 22:03:57 peter Exp $");
+__RCSID("$NetBSD: user.c,v 1.79 2005/04/05 22:54:26 agc 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