From 87703597e24ba94c400ac8878a6835d86571da91 Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Wed, 11 Feb 2009 21:51:41 -0500 Subject: parse gecos field to get real name --- tools/list-sessions.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/list-sessions.c b/tools/list-sessions.c index 0a026c8..3933772 100644 --- a/tools/list-sessions.c +++ b/tools/list-sessions.c @@ -148,8 +148,19 @@ get_real_name (uid_t uid) pwent = getpwuid (uid); - if (pwent != NULL) { - realname = g_strdup (pwent->pw_gecos); + if (pwent != NULL + && pwent->pw_gecos + && *pwent->pw_gecos != '\0') { + char **gecos_fields; + char **name_parts; + + /* split the gecos field and substitute '&' */ + gecos_fields = g_strsplit (pwent->pw_gecos, ",", 0); + name_parts = g_strsplit (gecos_fields[0], "&", 0); + pwent->pw_name[0] = g_ascii_toupper (pwent->pw_name[0]); + realname = g_strjoinv (pwent->pw_name, name_parts); + g_strfreev (gecos_fields); + g_strfreev (name_parts); } return realname; -- cgit