]> granicus.if.org Git - shadow/commitdiff
* libmisc/chkname.h, libmisc/chkname.c: check_group_name (resp.
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 25 May 2008 20:58:16 +0000 (20:58 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 25 May 2008 20:58:16 +0000 (20:58 +0000)
check_user_name) renamed to is_valid_user_name (resp.
is_valid_group_name). is_valid_user_name and is_valid_group_name
return a bool.
* src/grpck.c, src/newusers.c, src/usermod.c, src/useradd.c,
src/groupmod.c, src/pwck.c, src/groupadd.c: Use is_valid_user_name
and is_valid_group_name, following above change.
* libmisc/chkname.c: Avoid implicit conversion of chars to
booleans. Add brackets and parenthesis.

ChangeLog
libmisc/chkname.c
libmisc/chkname.h
src/groupadd.c
src/groupmod.c
src/grpck.c
src/newusers.c
src/pwck.c
src/useradd.c
src/usermod.c

index 38825b55ae6f0f66d4114a32533e9418f7e0624e..d0e07da219b40116ddbe0f45b97352e384ef7a83 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-05-25  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * libmisc/chkname.h, libmisc/chkname.c: check_group_name (resp.
+       check_user_name) renamed to is_valid_user_name (resp.
+       is_valid_group_name). is_valid_user_name and is_valid_group_name
+       return a bool.
+       * src/grpck.c, src/newusers.c, src/usermod.c, src/useradd.c,
+       src/groupmod.c, src/pwck.c, src/groupadd.c: Use is_valid_user_name
+       and is_valid_group_name, following above change.
+       * libmisc/chkname.c: Avoid implicit conversion of chars to
+       booleans. Add brackets and parenthesis.
+
 2008-05-25  Nicolas François  <nicolas.francois@centraliens.net>
 
        * libmisc/xmalloc.c: Avoid implicit conversion of integers /
index a0aa738f6b6392e012dd4f746042dc1e17096824..2bdc06b64c7b1e6f9856da186f42cec5b2eef519 100644 (file)
  */
 
 /*
- * check_user_name(), check_group_name() - check the new user/group
- * name for validity; return value: 1 - OK, 0 - bad name
+ * is_valid_user_name(), is_valid_group_name() - check the new user/group
+ * name for validity;
+ * return values:
+ *   true  - OK
+ *   false - bad name
  */
 
 #include <config.h>
 #else
 #include <utmp.h>
 #endif
-static int good_name (const char *name)
+
+static bool is_valid_name (const char *name)
 {
        /*
         * User/group names must match [a-z_][a-z0-9_-]*[$]
         */
-       if (!*name || !((*name >= 'a' && *name <= 'z') || *name == '_'))
-               return 0;
+       if (('\0' == *name) ||
+           !((('a' <= *name) && ('z' >= *name)) || ('_' == *name))) {
+               return false;
+       }
 
-       while (*++name) {
-               if (!((*name >= 'a' && *name <= 'z') ||
-                     (*name >= '0' && *name <= '9') ||
-                     *name == '_' || *name == '-' ||
-                     (*name == '$' && *(name + 1) == '\0')))
-                       return 0;
+       while ('\0' != *++name) {
+               if (!(( ('a' <= *name) && ('z' >= *name) ) ||
+                     ( ('0' <= *name) && ('9' >= *name) ) ||
+                     ('_' == *name) ||
+                     ('-' == *name) ||
+                     ( ('$' == *name) && ('\0' == *(name + 1)) )
+                    )) {
+                       return false;
+               }
        }
 
-       return 1;
+       return true;
 }
 
-int check_user_name (const char *name)
+bool is_valid_user_name (const char *name)
 {
 #if HAVE_UTMPX_H
        struct utmpx ut;
@@ -78,21 +87,23 @@ int check_user_name (const char *name)
         * User names are limited by whatever utmp can
         * handle (usually max 8 characters).
         */
-       if (strlen (name) > sizeof (ut.ut_user))
-               return 0;
+       if (strlen (name) > sizeof (ut.ut_user)) {
+               return false;
+       }
 
-       return good_name (name);
+       return is_valid_name (name);
 }
 
-int check_group_name (const char *name)
+bool is_valid_group_name (const char *name)
 {
        /*
         * Arbitrary limit for group names - max 16
         * characters (same as on HP-UX 10).
         */
-       if (strlen (name) > 16)
-               return 0;
+       if (strlen (name) > 16) {
+               return false;
+       }
 
-       return good_name (name);
+       return is_valid_name (name);
 }
 
index 7660eefe6bad90561a90f107db0e01e1685664e6..82c915984ed180f2ce7ced7762debc4a52929fe8 100644 (file)
 #define _CHKNAME_H_
 
 /*
- * check_user_name(), check_group_name() - check the new user/group
- * name for validity; return value: 1 - OK, 0 - bad name
+ * is_valid_user_name(), is_valid_group_name() - check the new user/group
+ * name for validity;
+ * return values:
+ *   true  - OK
+ *   false - bad name
  */
 
 #include "defines.h"
 
-extern int check_user_name (const char *);
-extern int check_group_name (const char *name);
+extern bool is_valid_user_name (const char *name);
+extern bool is_valid_group_name (const char *name);
 
 #endif
index 07802452d638d58b72a051a2c71e2e346aed8eb3..709884faa90b923a6d6fc2424f89c65e0aa0f430 100644 (file)
@@ -220,7 +220,7 @@ static void grp_update (void)
  */
 static void check_new_name (void)
 {
-       if (check_group_name (group_name)) {
+       if (is_valid_group_name (group_name)) {
                return;
        }
 
index bdd929af852b336fe343e6122d1884a0fa63f0ae..ddd5eb918a59f8aef7cbf2b9a9acac41a916107f 100644 (file)
@@ -328,7 +328,7 @@ static void check_new_name (void)
                return;
        }
 
-       if (check_group_name (group_newname)) {
+       if (is_valid_group_name (group_newname)) {
 
                /*
                 * If the entry is found, too bad.
index 02924fce2d20212b6d0a19c7d259d835c5005baf..cb12d6abaedce3258166c00524bcfb8b7c0ae285 100644 (file)
@@ -497,7 +497,7 @@ static void check_grp_file (int *errors, int *changed)
                /*
                 * Check for invalid group names.  --marekm
                 */
-               if (!check_group_name (grp->gr_name)) {
+               if (!is_valid_group_name (grp->gr_name)) {
                        *errors += 1;
                        printf (_("invalid group name '%s'\n"), grp->gr_name);
                }
index 97a970710218bc85c74c1d7844526089df161f01..82550dab59ea4559c9749ce39c1dedbb91fc67d3 100644 (file)
@@ -214,7 +214,7 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid)
        }
 
        /* Check if this is a valid group name */
-       if (check_group_name (grent.gr_name) == 0) {
+       if (!is_valid_group_name (grent.gr_name)) {
                fprintf (stderr,
                         _("%s: invalid group name `%s'\n"),
                         Prog, grent.gr_name);
@@ -318,7 +318,7 @@ static int add_user (const char *name, uid_t uid, gid_t gid)
        struct passwd pwent;
 
        /* Check if this is a valid user name */
-       if (check_user_name (name) == 0) {
+       if (!is_valid_user_name (name)) {
                fprintf (stderr,
                         _("%s: invalid user name `%s'\n"),
                         Prog, name);
index 0b42a86d338ff0508ac5025f12aa9625b6c174f2..d319008c5bd2108b7457433626ae4e3712de7e76 100644 (file)
@@ -354,7 +354,7 @@ static void check_pw_file (int *errors, int *changed)
                /*
                 * Check for invalid usernames.  --marekm
                 */
-               if (!check_user_name (pwd->pw_name)) {
+               if (!is_valid_user_name (pwd->pw_name)) {
                        printf (_("invalid user name '%s'\n"), pwd->pw_name);
                        *errors += 1;
                }
index b606c90e9a8063963f7265d38fd0503314a84a80..b4211769daf38cb0b93a91b7aaf9f0bf4eadf9b2 100644 (file)
@@ -1123,7 +1123,7 @@ static void process_flags (int argc, char **argv)
                        usage ();
 
                user_name = argv[optind];
-               if (!check_user_name (user_name)) {
+               if (!is_valid_user_name (user_name)) {
                        fprintf (stderr,
                                 _
                                 ("%s: invalid user name '%s'\n"),
index c09907a95236f59cc9d10e2b39393882ebf7dc86..e75111a5c616f90f36e7b51a76a9205662aa3839 100644 (file)
@@ -917,7 +917,7 @@ static void process_flags (int argc, char **argv)
                                Gflg++;
                                break;
                        case 'l':
-                               if (!check_user_name (optarg)) {
+                               if (!is_valid_user_name (optarg)) {
                                        fprintf (stderr,
                                                 _("%s: invalid field '%s'\n"),
                                                 Prog, optarg);