diff options
author | Sami Kerola | 2014-12-14 14:28:57 +0100 |
---|---|---|
committer | Sami Kerola | 2014-12-19 10:11:03 +0100 |
commit | 58985f6712d4f869eb68bfe1fee8ca2074cf226f (patch) | |
tree | f5784c6c0ca07a12d02595ac4c7b0403234cafed /login-utils/chfn.c | |
parent | chfn: fix usage() regression (diff) | |
download | kernel-qcow2-util-linux-58985f6712d4f869eb68bfe1fee8ca2074cf226f.tar.gz kernel-qcow2-util-linux-58985f6712d4f869eb68bfe1fee8ca2074cf226f.tar.xz kernel-qcow2-util-linux-58985f6712d4f869eb68bfe1fee8ca2074cf226f.zip |
chfn: simplify parse_passwd() by using strsep()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/chfn.c')
-rw-r--r-- | login-utils/chfn.c | 51 |
1 files changed, 15 insertions, 36 deletions
diff --git a/login-utils/chfn.c b/login-utils/chfn.c index 9833591e8..7ba1a5180 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -191,42 +191,21 @@ static int parse_argv(int argc, char *argv[], struct finfo *pinfo) static void parse_passwd(struct passwd *pw, struct finfo *pinfo) { char *gecos; - char *cp; - - if (pw) { - pinfo->pw = pw; - pinfo->username = pw->pw_name; - /* use pw_gecos - we take a copy since PAM destroys the original */ - gecos = xstrdup(pw->pw_gecos); - cp = (gecos ? gecos : ""); - pinfo->full_name = cp; - cp = strchr(cp, ','); - if (cp) { - *cp = 0, cp++; - } else - return; - pinfo->office = cp; - cp = strchr(cp, ','); - if (cp) { - *cp = 0, cp++; - } else - return; - pinfo->office_phone = cp; - cp = strchr(cp, ','); - if (cp) { - *cp = 0, cp++; - } else - return; - pinfo->home_phone = cp; - /* extra fields contain site-specific information, and can - * not be changed by this version of chfn. */ - cp = strchr(cp, ','); - if (cp) { - *cp = 0, cp++; - } else - return; - pinfo->other = cp; - } + + if (!pw) + return; + pinfo->pw = pw; + pinfo->username = pw->pw_name; + /* use pw_gecos - we take a copy since PAM destroys the original */ + gecos = xstrdup(pw->pw_gecos); + /* extract known fields */ + pinfo->full_name = strsep(&gecos, ","); + pinfo->office = strsep(&gecos, ","); + pinfo->office_phone = strsep(&gecos, ","); + pinfo->home_phone = strsep(&gecos, ","); + /* extra fields contain site-specific information, and can + * not be changed by this version of chfn. */ + pinfo->other = strsep(&gecos, ","); } /* |