Subject: Re: [patch] fixup GECOS handling

From: Kyle Hayes <[email-masked]>
Date: Fri, 22 Apr 2005 09:16:39 -0700

On Fri, 2005-04-22 at 16:23 +0200, Martin Schlemmer wrote:
> Hi,
> 
> This still applies - any reason for not doing this?

Seems like this will break on certain kinds of data.  See below.

>         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] = '@';

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

-- 
Kyle Hayes <[email-masked]>
Marchex Inc.