]> granicus.if.org Git - shadow/commitdiff
Allow non-US-ASCII characters in the GECOS fields ("name", "room number",
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 27 Apr 2008 00:24:49 +0000 (00:24 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 27 Apr 2008 00:24:49 +0000 (00:24 +0000)
and "other info" fields).

ChangeLog
NEWS
libmisc/fields.c
man/chfn.1.xml
src/chfn.c

index bf94b05fde824a9f367790d8e527c7b1fc84e37e..608d0bbc885b56dc9a700c674268416869444269 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-04-27  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * NEWS, libmisc/fields.c, src/chfn.c, man/chfn.1.xml: Allow
+       non-US-ASCII characters in the GECOS fields ("name", "room
+       number", and "other info" fields).
+
 2008-04-17  Nicolas François  <nicolas.francois@centraliens.net>
 
        * NEWS, src/newgrp.c: Fix compilation failure when compiled with
diff --git a/NEWS b/NEWS
index 424c3078be3d10081eab8dbef480634190ab0337..6ce02c0563ecc204a7576a007838b58b830be1c3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ shadow-4.1.1 -> shadow-4.1.2                                            UNRELEASED
     file; and fail if the feature is requested but not present on the
     system.
   * Fix build failure when configured with audit support.
+- chfn
+  * Allow non-US-ASCII characters in the GECOS fields ("name", "room
+    number", and "other info" fields).
 
 shadow-4.1.0 -> shadow-4.1.1                                           02-04-2008
 
index e021f06d11873264354c01ca4745d3db5d2f8a07..c07492f2a1cd07f19b68cf6a945beb0c9e459d86 100644 (file)
 /*
  * valid_field - insure that a field contains all legal characters
  *
- * The supplied field is scanned for non-printing and other illegal
- * characters.  If any illegal characters are found, valid_field
- * returns -1.  Zero is returned for success.
+ * The supplied field is scanned for non-printable and other illegal
+ * characters.
+ *  + -1 is returned if an illegal character is present.
+ *  +  1 is returned if no illegal characters are present, but the field
+ *       contains a non-printable character.
+ *  +  0 is returned otherwise.
  */
 int valid_field (const char *field, const char *illegal)
 {
        const char *cp;
+       int err = 0;
 
-       for (cp = field;
-            *cp && isprint (*cp & 0x7F) && !strchr (illegal, *cp); cp++);
+       for (cp = field; *cp && !strchr (illegal, *cp); cp++);
 
-       if (*cp)
-               return -1;
-       else
-               return 0;
+       if (*cp) {
+               err = -1;
+       } else {
+               for (cp = field; *cp && isprint (*cp); cp++);
+
+               if (*cp) {
+                       err = 1;
+               }
+       }
+
+       return err;
 }
 
 /*
index cd9fd39ad94989cf44ce34ea366f2d5a8cced564..89607c98ae688a204417afeae6b765de4799bbd5 100644 (file)
       GECOS field.
     </para>
 
-    <para>The only restriction placed on the contents of the fields is that
-      no control characters may be present, nor any of comma, colon, or
-      equal sign. The <emphasis remap='I'>other</emphasis> field does not
-      have this restriction, and is used to store accounting information
-      used by other applications.
+    <para>
+      These fields must not contain any colons. Except for the
+      <emphasis remap='I'>other</emphasis> field, they should not contain
+      any comma or equal sign. It is also recommended to avoid
+      non-US-ASCII characters, but this is only enforced for the phone
+      numbers. The <emphasis remap='I'>other</emphasis> field is used to
+      store accounting information used by other applications.
     </para>
 
-    <para> If none of the options are selected, <command>chfn</command>
+    <para>
+      If none of the options are selected, <command>chfn</command>
       operates in an interactive fashion, prompting the user with the
       current values for all of the fields. Enter the new value to change
       the field, or leave the line blank to use the current value. The
index 027467d7fb33621169ab1c1c04f82c7cd77474c5..f927274b4dba2ba974f2fd3590730a8d83405de6 100644 (file)
@@ -536,12 +536,19 @@ static void get_old_fields (const char *gecos)
  */
 static void check_fields (void)
 {
-       if (valid_field (fullnm, ":,=")) {
+       int err;
+       err = valid_field (fullnm, ":,=");
+       if (err > 0) {
+               fprintf (stderr, _("%s: name with non-ASCII characters: '%s'\n"), Prog, fullnm);
+       } else if (err < 0) {
                fprintf (stderr, _("%s: invalid name: '%s'\n"), Prog, fullnm);
                closelog ();
                exit (E_NOPERM);
        }
-       if (valid_field (roomno, ":,=")) {
+       err = valid_field (roomno, ":,=");
+       if (err > 0) {
+               fprintf (stderr, _("%s: room number with non-ASCII characters: '%s'\n"), Prog, roomno);
+       } else if (err < 0) {
                fprintf (stderr, _("%s: invalid room number: '%s'\n"),
                         Prog, roomno);
                closelog ();
@@ -559,7 +566,10 @@ static void check_fields (void)
                closelog ();
                exit (E_NOPERM);
        }
-       if (valid_field (slop, ":")) {
+       err = valid_field (slop, ":");
+       if (err > 0) {
+               fprintf (stderr, _("%s: '%s' contains non-ASCII characters\n"), Prog, slop);
+       } else if (err < 0) {
                fprintf (stderr,
                         _("%s: '%s' contains illegal characters\n"),
                         Prog, slop);