Allow non-US-ASCII characters in the GECOS fields ("name", "room number",

and "other info" fields).
This commit is contained in:
nekral-guest 2008-04-27 00:24:49 +00:00
parent 4d7d6a1a9f
commit 4196525702
5 changed files with 50 additions and 18 deletions

View File

@ -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> 2008-04-17 Nicolas François <nicolas.francois@centraliens.net>
* NEWS, src/newgrp.c: Fix compilation failure when compiled with * NEWS, src/newgrp.c: Fix compilation failure when compiled with

3
NEWS
View File

@ -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 file; and fail if the feature is requested but not present on the
system. system.
* Fix build failure when configured with audit support. * 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 shadow-4.1.0 -> shadow-4.1.1 02-04-2008

View File

@ -38,21 +38,31 @@
/* /*
* valid_field - insure that a field contains all legal characters * valid_field - insure that a field contains all legal characters
* *
* The supplied field is scanned for non-printing and other illegal * The supplied field is scanned for non-printable and other illegal
* characters. If any illegal characters are found, valid_field * characters.
* returns -1. Zero is returned for success. * + -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) int valid_field (const char *field, const char *illegal)
{ {
const char *cp; const char *cp;
int err = 0;
for (cp = field; for (cp = field; *cp && !strchr (illegal, *cp); cp++);
*cp && isprint (*cp & 0x7F) && !strchr (illegal, *cp); cp++);
if (*cp) if (*cp) {
return -1; err = -1;
else } else {
return 0; for (cp = field; *cp && isprint (*cp); cp++);
if (*cp) {
err = 1;
}
}
return err;
} }
/* /*

View File

@ -46,14 +46,17 @@
GECOS field. GECOS field.
</para> </para>
<para>The only restriction placed on the contents of the fields is that <para>
no control characters may be present, nor any of comma, colon, or These fields must not contain any colons. Except for the
equal sign. The <emphasis remap='I'>other</emphasis> field does not <emphasis remap='I'>other</emphasis> field, they should not contain
have this restriction, and is used to store accounting information any comma or equal sign. It is also recommended to avoid
used by other applications. 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>
<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 operates in an interactive fashion, prompting the user with the
current values for all of the fields. Enter the new value to change 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 the field, or leave the line blank to use the current value. The

View File

@ -536,12 +536,19 @@ static void get_old_fields (const char *gecos)
*/ */
static void check_fields (void) 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); fprintf (stderr, _("%s: invalid name: '%s'\n"), Prog, fullnm);
closelog (); closelog ();
exit (E_NOPERM); 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"), fprintf (stderr, _("%s: invalid room number: '%s'\n"),
Prog, roomno); Prog, roomno);
closelog (); closelog ();
@ -559,7 +566,10 @@ static void check_fields (void)
closelog (); closelog ();
exit (E_NOPERM); 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, fprintf (stderr,
_("%s: '%s' contains illegal characters\n"), _("%s: '%s' contains illegal characters\n"),
Prog, slop); Prog, slop);