diff options
author | William Jon McCann <jmccann@redhat.com> | 2009-02-11 21:51:41 -0500 |
---|---|---|
committer | William Jon McCann <jmccann@redhat.com> | 2009-02-11 21:51:41 -0500 |
commit | 87703597e24ba94c400ac8878a6835d86571da91 (patch) | |
tree | 800542d6ab5a4c6d255413f92cd8e8fd6e8ccc00 /tools | |
parent | 739b39203166eda0174672541a06ceeb182b6ed3 (diff) |
parse gecos field to get real name
Diffstat (limited to 'tools')
-rw-r--r-- | tools/list-sessions.c | 15 |
1 files changed, 13 insertions, 2 deletions
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; |