aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorIan Lepore <ian@FreeBSD.org>2018-07-26 18:34:38 +0000
committerIan Lepore <ian@FreeBSD.org>2018-07-26 18:34:38 +0000
commit34e9190d82ac021bae00937cc1a663920aa19309 (patch)
treed49d5f54fe51ee8dc25972315969baa2a806a711 /lib/libutil
parent8cfbc812e56e9be091997b5f90193ebd1f585859 (diff)
Notes
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/libutil.h1
-rw-r--r--lib/libutil/pw_util.318
-rw-r--r--lib/libutil/pw_util.c11
3 files changed, 27 insertions, 3 deletions
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index c79eaac5a5fa..2ac5e975a2d7 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -155,6 +155,7 @@ int pw_edit(int _notsetuid);
int pw_equal(const struct passwd *_pw1, const struct passwd *_pw2);
void pw_fini(void);
int pw_init(const char *_dir, const char *_master);
+void pw_initpwd(struct passwd *_pw);
char *pw_make(const struct passwd *_pw);
char *pw_make_v7(const struct passwd *_pw);
int pw_mkdb(const char *_user);
diff --git a/lib/libutil/pw_util.3 b/lib/libutil/pw_util.3
index 901135e02b94..ad5dcaaeccc3 100644
--- a/lib/libutil/pw_util.3
+++ b/lib/libutil/pw_util.3
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 02, 2015
+.Dd July 26, 2018
.Dt PW_UTIL 3
.Os
.Sh NAME
@@ -59,6 +59,8 @@
.Fn pw_fini "void"
.Ft int
.Fn pw_init "const char *dir" const char *master"
+.Ft void
+.Fn pw_initpwd "struct passwd *pw"
.Ft "char *"
.Fn pw_make "const struct passwd *pw"
.Ft "char *"
@@ -179,7 +181,7 @@ if any.
.Pp
The
.Fn pw_init
-initialize the static variable representing the path a password file.
+initializes the static variable representing the path to a password file.
.Fa dir
is the directory where the password file is located.
If set to
@@ -194,6 +196,18 @@ it will default to
.Pa master.passwd
.Pp
The
+.Fn pw_initpwd
+function initializes the
+.Vt passwd
+struct to canonical values.
+The entire structure is zeroed, then
+.Va pw_uid
+and
+.Va pw_gid
+are set to -1, and all string pointers are set to point at
+an internally-defined zero-length string.
+.Pp
+The
.Fn pw_make
function creates a properly formatted
.Bx
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c
index 112b6d8af45a..1659c97a7fcd 100644
--- a/lib/libutil/pw_util.c
+++ b/lib/libutil/pw_util.c
@@ -652,8 +652,16 @@ pw_dup(const struct passwd *pw)
#include "pw_scan.h"
/*
- * Wrapper around an internal libc function
+ * Wrapper around some internal libc functions.
*/
+
+void
+pw_initpwd(struct passwd *pw)
+{
+
+ __pw_initpwd(pw);
+}
+
struct passwd *
pw_scan(const char *line, int flags)
{
@@ -662,6 +670,7 @@ pw_scan(const char *line, int flags)
if ((bp = strdup(line)) == NULL)
return (NULL);
+ __pw_initpwd(&pw);
if (!__pw_scan(bp, &pw, flags)) {
free(bp);
return (NULL);