diff options
author | bapt <bapt@FreeBSD.org> | 2012-01-05 10:40:24 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2012-01-05 10:40:24 +0000 |
commit | a00247bc12bcc9f7ffc985f0bfc07a7aa615d0d4 (patch) | |
tree | ed5c8cca1cefe991199cc9d49049e6b470f15afb /lib | |
parent | 064404aac96133ca2cd46ae6156b2369418f8c0a (diff) | |
download | FreeBSD-src-a00247bc12bcc9f7ffc985f0bfc07a7aa615d0d4.zip FreeBSD-src-a00247bc12bcc9f7ffc985f0bfc07a7aa615d0d4.tar.gz |
Add new pw_make_v7 to make a passwd line (in v7 format) out of a struct passwd
while here, fix missing parentheses of the return statement of pw_make.
Approved by: des (mentor)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libutil/libutil.h | 1 | ||||
-rw-r--r-- | lib/libutil/pw_util.c | 16 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index dea14cf..47896c1 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -144,6 +144,7 @@ int pw_equal(const struct passwd *_pw1, const struct passwd *_pw2); void pw_fini(void); int pw_init(const char *_dir, const char *_master); char *pw_make(const struct passwd *_pw); +char *pw_make_v7(const struct passwd *_pw); int pw_mkdb(const char *_user); int pw_lock(void); struct passwd *pw_scan(const char *_line, int _flags); diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c index 1068eff..5cd27b1 100644 --- a/lib/libutil/pw_util.c +++ b/lib/libutil/pw_util.c @@ -406,7 +406,21 @@ pw_make(const struct passwd *pw) pw->pw_passwd, (uintmax_t)pw->pw_uid, (uintmax_t)pw->pw_gid, pw->pw_class, (uintmax_t)pw->pw_change, (uintmax_t)pw->pw_expire, pw->pw_gecos, pw->pw_dir, pw->pw_shell); - return line; + return (line); +} + +/* + * Make a passwd line (in v7 format) out of a struct passwd + */ +char * +pw_make_v7(const struct passwd *pw) +{ + char *line; + + asprintf(&line, "%s:*:%ju:%ju:%s:%s:%s", pw->pw_name, + (uintmax_t)pw->pw_uid, (uintmax_t)pw->pw_gid, + pw->pw_gecos, pw->pw_dir, pw->pw_shell); + return (line); } /* |