Subject: trailing commas in GECOS field with chfn
To: None <netbsd-users@netbsd.org>
From: Rasputin <rasputin@idoru.mine.nu>
List: netbsd-users
Date: 07/11/2002 17:29:37
--lrZ03NoBR/3+SXJZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Are these annoying anyone else :) ?

Whenever a user  edits information with chfn, their
entries in /etc/passwd change from

rasputin:*:<UID>:<GID>:Rasputin:<HOMEDIR>:<SHELL>

to:

rasputin:*:<UID>:<GID>:Rasputin,,,:<HOMEDIR>:<SHELL>

(if you leave your phone nunmber, etc blank)

This 'trailing comma' pattern looks a bit rough in mails, etc.
and if you want to fix this, you need root.

I've attached a little patch to fix it [1], but wondered if it
would break anything?
Do other programs rely on GECOS info having these commas?
I doubt it, as they only appear after chfn has been run on a passwd entry.

Let me know and I'll send-pr(1) it.

Cheers

[1] - No, it doesn't fix multiple adjacent commas - give me a break,
I'm only halfway through K&R chapter 2.

-- 
Rasputin :: Jack of All Trades - Master of Nuns

--lrZ03NoBR/3+SXJZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="chpass.diff"

--- /usr/src/usr.bin/chpass/edit.c	Thu Jul 11 17:00:28 2002
+++ /home/rasputin/src/edit.c	Thu Jul 11 17:25:21 2002
@@ -214,6 +214,18 @@
 		err(1, "malloc");
 	(void)snprintf(p, len, "%s,%s,%s,%s", list[E_NAME].save,
 	    list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save);
+
+
+	{
+	    char *foo = p;
+	    /* strip trailing commas from gecos */
+	    while (*(foo+1) != '\0') { foo++; }
+	    while (*foo == ',') {
+	        *foo = '\0';
+	        foo--;
+	        }
+	}
+
 	pw->pw_gecos = p;
 
 	if (snprintf(buf, sizeof(buf),

--lrZ03NoBR/3+SXJZ--