fixup GECOS handling
PATCH 1/1 fixup GECOS handling
Hi,
The gecos is delimited by ',' or ';', so we should only use whatever before the first ',' or ';' for the full name, and not just strip those. Also, a '.' may be valid in the full name (Foo B. Zooman) or email ([email protected]).
commit-tree.c: ec53a4565ec0033aaf6df2a48d233ccf4823e8b0
commit-tree.c 2005-04-18 12:22:18.000000000 +0200 renamed from commit-tree.c +5 -15
@@ -96,21 +96,6 @@ if (!c) break; } - - /* - * Go back, and remove crud from the end: some people - * have commas etc in their gecos field - */ - dst--; - while (--dst >= p) { - unsigned char c = *dst; - switch (c) { - case ',': case ';': case '.': - *dst = 0; - continue; - } - break; - } } static const char *month_names[] = {
@@ -313,6 +298,11 @@ if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos; + /* The name is seperated from the room no., tel no, etc via [,;] */ + if (strchr(realgecos, ',')) + realgecos[strchr(realgecos, ',') - realgecos] = '\0'; + else if (strchr(realgecos, ';')) + realgecos[strchr(realgecos, ';') - realgecos] = '\0'; len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';
Signature · 1 line
Martin Schlemmer
commit-tree.c: ec53a4565ec0033aaf6df2a48d233ccf4823e8b0
commit-tree.c +5 -15
@@ -96,21 +96,6 @@if (!c)break ; } - -/* -* Go back, and remove crud from the end: some people -* have commas etc in their gecos field -*/ - dst--; -while (--dst >= p) { -unsigned char c = *dst; -switch (c) { -case ',' :case ';' :case '.' : - *dst =0 ; -continue ; - } -break ; - } }static const char *month_names[] = {
@@ -313,6 +298,11 @@if (!pw)die ("You don't exist. Go away!" ); realgecos = pw->pw_gecos; +/* The name is seperated from the room no., tel no, etc via ',' or ';' */ +if (strchr (realgecos,',' )) + realgecos[strchr (realgecos,',' ) - realgecos] ='\0' ; +else if (strchr (realgecos,';' )) + realgecos[strchr (realgecos,';' ) - realgecos] ='\0' ; len =strlen (pw->pw_name);memcpy (realemail, pw->pw_name, len); realemail[len] ='@' ;
Quoted 1 line · Martin Schlemmer
realgecos[strchr(realgecos, ',') - realgecos] = '\0';
Er, *strchr(realgecos, ',') = 0; surely? Even if the compiler is clever enough to optimise out the gratuitous addition and subtraction, that's no real excuse for it.
Signature · 1 line
dwmw2
Quoted 7 lines · David Woodhouse
Quoted 1 line · Martin Schlemmer
realgecos[strchr(realgecos, ',') - realgecos] = '\0';
Er, *strchr(realgecos, ',') = 0; surely? Even if the compiler is clever enough to optimise out the gratuitous addition and subtraction, that's no real excuse for it.
Err, right. Updated patch.
The gecos is delimited by ',' or ';', so we should only use whatever before the first ',' or ';' for the full name, and not just strip those.
commit-tree.c: ec53a4565ec0033aaf6df2a48d233ccf4823e8b0
commit-tree.c 2005-04-18 12:22:18.000000000 +0200 renamed from commit-tree.c +5 -15
@@ -96,21 +96,6 @@ if (!c) break; } - - /* - * Go back, and remove crud from the end: some people - * have commas etc in their gecos field - */ - dst--; - while (--dst >= p) { - unsigned char c = *dst; - switch (c) { - case ',': case ';': case '.': - *dst = 0; - continue; - } - break; - } } static const char *month_names[] = {
@@ -313,6 +298,11 @@ if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos; + /* The name is seperated from the room no., tel no, etc via [,;] */ + if (strchr(realgecos, ',')) + *strchr(realgecos, ',') = 0; + else if (strchr(realgecos, ';')) + *strchr(realgecos, ';') = 0; len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';
Signature · 1 line
Martin Schlemmer
commit-tree.c: ec53a4565ec0033aaf6df2a48d233ccf4823e8b0
commit-tree.c +5 -15
@@ -96,21 +96,6 @@if (!c)break ; } - -/* -* Go back, and remove crud from the end: some people -* have commas etc in their gecos field -*/ - dst--; -while (--dst >= p) { -unsigned char c = *dst; -switch (c) { -case ',' :case ';' :case '.' : - *dst =0 ; -continue ; - } -break ; - } }static const char *month_names[] = {
@@ -313,6 +298,11 @@if (!pw)die ("You don't exist. Go away!" ); realgecos = pw->pw_gecos; +/* The name is seperated from the room no., tel no, etc via ',' or ';' */ +if (strchr (realgecos,',' )) + *strchr (realgecos,',' ) =0 ; +else if (strchr (realgecos,';' )) + *strchr (realgecos,';' ) =0 ; len =strlen (pw->pw_name);memcpy (realemail, pw->pw_name, len); realemail[len] ='@' ;
PATCH 1/1 fixup GECOS handling
In reply to David WoodhouseHi,
This still applies - any reason for not doing this?
Thanks,
----
The GECOS is delimited by ',' or ';', so we should only use whatever is before the first ',' or ';' for the full name, rather than just stripping those.
commit-tree.c: ec53a4565ec0033aaf6df2a48d233ccf4823e8b0
commit-tree.c 2005-04-18 12:22:18.000000000 +0200 renamed from commit-tree.c +5 -15
@@ -96,21 +96,6 @@ if (!c) break; } - - /* - * Go back, and remove crud from the end: some people - * have commas etc in their gecos field - */ - dst--; - while (--dst >= p) { - unsigned char c = *dst; - switch (c) { - case ',': case ';': case '.': - *dst = 0; - continue; - } - break; - } } static const char *month_names[] = {
@@ -313,6 +298,11 @@ if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos; + /* The name is seperated from the room no., tel no, etc via [,;] */ + if (strchr(realgecos, ',')) + *strchr(realgecos, ',') = 0; + else if (strchr(realgecos, ';')) + *strchr(realgecos, ';') = 0; len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';
Signature · 1 line
Martin Schlemmer
commit-tree.c: ec53a4565ec0033aaf6df2a48d233ccf4823e8b0
commit-tree.c +5 -15
@@ -96,21 +96,6 @@if (!c)break ; } - -/* -* Go back, and remove crud from the end: some people -* have commas etc in their gecos field -*/ - dst--; -while (--dst >= p) { -unsigned char c = *dst; -switch (c) { -case ',' :case ';' :case '.' : - *dst =0 ; -continue ; - } -break ; - } }static const char *month_names[] = {
@@ -313,6 +298,11 @@if (!pw)die ("You don't exist. Go away!" ); realgecos = pw->pw_gecos; +/* The name is seperated from the room no., tel no, etc via ',' or ';' */ +if (strchr (realgecos,',' )) + *strchr (realgecos,',' ) =0 ; +else if (strchr (realgecos,';' )) + *strchr (realgecos,';' ) =0 ; len =strlen (pw->pw_name);memcpy (realemail, pw->pw_name, len); realemail[len] ='@' ;
Quoted 3 lines · Martin Schlemmer
Hi,
This still applies - any reason for not doing this?
Seems like this will break on certain kinds of data. See below.
commit-tree.c 2005-04-18 12:22:18.000000000 +0200 line 308
Quoted 11 lines
if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos;commit-tree.c 2005-04-18 12:22:18.000000000 +0200 renamed from commit-tree.c +5
-0+ /* The name is seperated from the room no., tel no, etc via [,;] */ + if (strchr(realgecos, ',')) + *strchr(realgecos, ',') = 0; + else if (strchr(realgecos, ';')) + *strchr(realgecos, ';') = 0; len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';
Suppose that the GECOS field is:
Hayes, Kyle; Room 42; 424-424-4242; foo bar baz...
You'll search for the first comma, find it, truncate my name to "Hayes", and continue.
I have seen this kind of GECOS in larger environments where the individual users are not the ones that administrate their machines. Using the LastName, FirstName style of name is not rare.
I think you want something like this (not tested):
char *comma,*semi;
comma = strchr(realgecos,',');
semi = strchr(realgecos,';');
if(comma)
if(semi) /* lastname, firstname; room #; phone # format */ *semi = 0; else *comma = 0; else if(semi) *semi = 0;
(hopefully Evolution won't trash the indentation...)
Best,
Kyle
Signature · 2 lines
Kyle Hayes <[email protected]> Marchex Inc.
Quoted 21 lines · Kyle Hayes
Quoted 3 lines · Martin Schlemmer
Hi,
This still applies - any reason for not doing this?
Seems like this will break on certain kinds of data. See below.
commit-tree.c 2005-04-18 12:22:18.000000000 +0200 line 308
Quoted 11 lines
if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos;commit-tree.c 2005-04-18 12:22:18.000000000 +0200 renamed from commit-tree.c +5
-0+ /* The name is seperated from the room no., tel no, etc via [,;] */ + if (strchr(realgecos, ',')) + *strchr(realgecos, ',') = 0; + else if (strchr(realgecos, ';')) + *strchr(realgecos, ';') = 0; len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';Suppose that the GECOS field is:
Quoted 9 lines
Hayes, Kyle; Room 42; 424-424-4242; foo bar baz...
You'll search for the first comma, find it, truncate my name to "Hayes", and continue.
I have seen this kind of GECOS in larger environments where the individual users are not the ones that administrate their machines. Using the LastName, FirstName style of name is not rare.
What OS? With Linux at least, this is what chfn's manpage say:
----
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 other field does not have this restriction, and is used to store accounting information used by other applications.
----
Meaning, if they use a ',' in one of the fields (and it is a linux system with the chfn most probably from the shadow package), then they are looking for trouble. The only reason I added the ';' was because somebody said whatever OS used it instead of a ','.
Thanks,
Signature · 1 line
Martin Schlemmer
Quoted 8 lines · Martin Schlemmer
Quoted 7 lines · Kyle Hayes
Suppose that the GECOS field is:
Hayes, Kyle; Room 42; 424-424-4242; foo bar baz...
You'll search for the first comma, find it, truncate my name to "Hayes", and continue.
Quoted 6 lines
Quoted 4 lines
I have seen this kind of GECOS in larger environments where the individual users are not the ones that administrate their machines. Using the LastName, FirstName style of name is not rare.
What OS? With Linux at least, this is what chfn's manpage say:
Can't remember, it's been a while (years). We had AIX, Solaris, Linux and BSD machines at the time. Might have been AIX, I think. The memory of which OS is vague, but not the annoyance of finding the problem :-(
Quoted 6 lines
----
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 other field does not have this restriction, and is used to store accounting information used by other applications.
----
Quoted 6 lines
Meaning, if they use a ',' in one of the fields (and it is a linux system with the chfn most probably from the shadow package), then they are looking for trouble. The only reason I added the ';' was because somebody said whatever OS used it instead of a ','.
From the AIX version of chfn:
----
You can use any printable characters in the gecos information string except a : (colon), which is an attribute delimiter.
----
The AIX examples show use of semicolon as a separator.
So, at least on AIX, it is appears valid to use the style I showed above. I don't have access to Solaris machines right now. The BSD (FreeBSD 4.11) version of man 5 passwd:
----
The gecos field normally contains comma (`,') separated subfields as follows:...
----
Best,
Kyle
Signature · 2 lines
Kyle Hayes <[email protected]> Marchex Inc.
Dear diary, on Fri, Apr 22, 2005 at 06:58:25PM CEST, I got a letter where Martin Schlemmer <[email protected]> told me that...
Quoted 4 lines
Meaning, if they use a ',' in one of the fields (and it is a linux system with the chfn most probably from the shadow package), then they are looking for trouble. The only reason I added the ';' was because somebody said whatever OS used it instead of a ','.
What about just swapping the two tests so that ; is cut off and , only when no ; is around?
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Quoted 10 lines · Petr Baudis
Dear diary, on Fri, Apr 22, 2005 at 06:58:25PM CEST, I got a letter where Martin Schlemmer <[email protected]> told me that...
Quoted 4 lines
Meaning, if they use a ',' in one of the fields (and it is a linux system with the chfn most probably from the shadow package), then they are looking for trouble. The only reason I added the ';' was because somebody said whatever OS used it instead of a ','.
What about just swapping the two tests so that ; is cut off and , only when no ; is around?
Actually, maybe just leave it. Its not a train smash, and in theory on linux ';' is a valid char in the gecos.
Signature · 1 line
Martin Schlemmer
Quoted 9 lines · Petr Baudis
Dear diary, on Fri, Apr 22, 2005 at 06:58:25PM CEST, I got a letter where Martin Schlemmer <[email protected]> told me that...
Quoted 4 lines
Meaning, if they use a ',' in one of the fields (and it is a linux system with the chfn most probably from the shadow package), then they are looking for trouble. The only reason I added the ';' was because somebody said whatever OS used it instead of a ','.
What about just swapping the two tests so that ; is cut off and , only when no ; is around?
Even nicer. I like it. Very clean!
Best,
Kyle
Signature · 2 lines
Kyle Hayes <[email protected]> Marchex Inc.
Quoted 8 lines · Kyle Hayes
Quoted 7 lines · Petr Baudis
Dear diary, on Fri, Apr 22, 2005 at 06:58:25PM CEST, I got a letter where Martin Schlemmer <[email protected]> told me that...
Quoted 4 lines
Meaning, if they use a ',' in one of the fields (and it is a linux system with the chfn most probably from the shadow package), then they are looking for trouble. The only reason I added the ';' was because somebody said whatever OS used it instead of a ','.
Quoted 5 lines
Quoted 2 lines
What about just swapping the two tests so that ; is cut off and , only when no ; is around?
Even nicer. I like it. Very clean!
Right, but ';' is not cutoff on linux for one, and from what you said freebsd as well. How about this rather (note that I assumed that the use of ';' as delimiter will be in the minority, but we can switch things around if it turns out the other way):
----
(not signed off, etc, as just for comments)
commit-tree.c (mode:100644) renamed from commit-tree.c (mode:100644 sha1:c0b07f89286c3f6cceae8122b4c3142c8efaf8e1) +11 -15
@@ -96,21 +96,6 @@ if (!c) break; } - - /* - * Go back, and remove crud from the end: some people - * have commas etc in their gecos field - */ - dst--; - while (--dst >= p) { - unsigned char c = *dst; - switch (c) { - case ',': case ';': case '.': - *dst = 0; - continue; - } - break; - } } static const char *month_names[] = {
@@ -311,6 +296,17 @@ if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos; + /* + * The GECOS fields are seperated via ',' on Linux, FreeBSD, etc, + * and ';' on AIX. + */ +#if defined(__aix__) + if (strchr(realgecos, ';')) + *strchr(realgecos, ';') = 0; +#else + if (strchr(realgecos, ',')) + *strchr(realgecos, ',') = 0; +#endif len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';
Signature · 1 line
Martin Schlemmer
Quoted 4 lines · Martin Schlemmer
Right, but ';' is not cutoff on linux for one, and from what you said freebsd as well. How about this rather (note that I assumed that the use of ';' as delimiter will be in the minority, but we can switch things around if it turns out the other way):
I'm not sure that __aix__ is defined, but it is close enough. Someone with an AIX compiler can correct it if needed. Anyone know about HP-UX and Tru64 and all those other ones?
Note that the original code also cuts on '.'. Is that used by some *nix in GECOS?
Best,
Kyle
Quoted 49 lines
----
(not signed off, etc, as just for comments)Index:
commit-tree.c
===================================================================commit-tree.c (mode:100644) renamed from commit-tree.c (mode:100644 sha1:c0b07f89286c3f6cceae8122b4c3142c8efaf8e1) +11
-15@@ -96,21 +96,6 @@ if (!c) break; } - - /* - * Go back, and remove crud from the end: some people - * have commas etc in their gecos field - */ - dst--; - while (--dst >= p) { - unsigned char c = *dst; - switch (c) { - case ',': case ';': case '.': - *dst = 0; - continue; - } - break; - } } static const char *month_names[] = {@@ -311,6 +296,17 @@ if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos; + /* + * The GECOS fields are seperated via ',' on Linux, FreeBSD, etc, + * and ';' on AIX. + */ +#if defined(__aix__) + if (strchr(realgecos, ';')) + *strchr(realgecos, ';') = 0; +#else + if (strchr(realgecos, ',')) + *strchr(realgecos, ',') = 0; +#endif len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';
Signature · 2 lines
Kyle Hayes <[email protected]> Marchex Inc.
Dear diary, on Fri, Apr 22, 2005 at 09:06:43PM CEST, I got a letter where Martin Schlemmer <[email protected]> told me that...
Quoted 8 lines
commit-tree.c (mode:100644) renamed from commit-tree.c (mode:100644 sha1:c0b07f89286c3f6cceae8122b4c3142c8efaf8e1) +4
-0@@ -311,6 +296,17 @@ if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos; + /* + * The GECOS fields are seperated via ',' on Linux, FreeBSD, etc, + * and ';' on AIX. + */
commit-tree.c (mode:100644) line 312
Quoted 10 lines
commit-tree.c (mode:100644) renamed from commit-tree.c (mode:100644 sha1:c0b07f89286c3f6cceae8122b4c3142c8efaf8e1) +7
-0+#if defined(__aix__) + if (strchr(realgecos, ';')) + *strchr(realgecos, ';') = 0; +#else + if (strchr(realgecos, ',')) + *strchr(realgecos, ',') = 0; +#endif len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';
I'm confused, what does this has to do with AIX? Do we even have / can expect to have any major AIX users?
I'm not too happy with this, I have to say. It seems it won't do always the right thing anyway. I would still favour the approach when you cut off everything after ';', and everything after ',' if no ';' is found. Seems simplest, safest, etc.
Tell me about anyone who has a semicolon in his realname.
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Quoted 15 lines · Petr Baudis
Dear diary, on Fri, Apr 22, 2005 at 09:06:43PM CEST, I got a letter where Martin Schlemmer <[email protected]> told me that...
Quoted 13 lines
commit-tree.c (mode:100644) renamed from commit-tree.c (mode:100644 sha1:c0b07f89286c3f6cceae8122b4c3142c8efaf8e1) +9
-0@@ -311,6 +296,17 @@ if (!pw) die("You don't exist. Go away!"); realgecos = pw->pw_gecos; + /* + * The GECOS fields are seperated via ',' on Linux, FreeBSD, etc, + * and ';' on AIX. + */ +#if defined(__aix__) + if (strchr(realgecos, ';')) + *strchr(realgecos, ';') = 0; +#else + if (strchr(realgecos, ','))
Quoted 9 lines
commit-tree.c (mode:100644) line 312
Quoted 5 lines
commit-tree.c (mode:100644) renamed from commit-tree.c (mode:100644 sha1:c0b07f89286c3f6cceae8122b4c3142c8efaf8e1) +2
-0+ *strchr(realgecos, ',') = 0; +#endif len = strlen(pw->pw_name); memcpy(realemail, pw->pw_name, len); realemail[len] = '@';I'm confused, what does this has to do with AIX? Do we even have / can expect to have any major AIX users?
Given.
Quoted 7 lines
I'm not too happy with this, I have to say. It seems it won't do always the right thing anyway. I would still favour the approach when you cut off everything after ';', and everything after ',' if no ';' is found. Seems simplest, safest, etc.
Tell me about anyone who has a semicolon in his realname.
Point I guess is still that the only valid delimiter on linux is ',', and the only reason for the ';' was because of some aix/whatever user saying that is a delimiter as well. But like I said: cat $this
Quoted 1 line
/dev/null... This is basically the same type of discussion as the
hash collision one, and I'm sure we all have better things to do.
Thanks,
Signature · 1 line
Martin Schlemmer
Quoted 8 lines · Kyle Hayes
if(comma)
if(semi) /* lastname, firstname; room #; phone # format */ *semi = 0; else *comma = 0; else if(semi) *semi = 0;
That's a really complicated way of writing
if(semi) *semi = 0;
else if(comma) *comma = 0;
(The two code fragments are precisely identical. Mmmm, strength reduction.)
-andy
Quoted 10 lines · Andy Isaacson
Quoted 8 lines · Kyle Hayes
if(comma)
if(semi) /* lastname, firstname; room #; phone # format */ *semi = 0; else *comma = 0; else if(semi) *semi = 0;
Quoted 7 lines
That's a really complicated way of writing
if(semi) *semi = 0;
else if(comma) *comma = 0;(The two code fragments are precisely identical. Mmmm, strength reduction.)
Indeed :-)
As someone else noted, this was too complex. As another person noted, this (like the SHA1 thread) has been thrashed around more than enough.
Best,
Kyle
Signature · 2 lines
Kyle Hayes <[email protected]> Marchex Inc.