summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2015-06-03 20:48:28 +0000
committerbapt <bapt@FreeBSD.org>2015-06-03 20:48:28 +0000
commitd5461fcfc0503ca55628583baa835aadc87e2c6f (patch)
tree2a29081eaa0e2501c9edc132199a1aa8fe090d87 /lib/libutil
parent5ad0e0e2f396ec9665428165c49c83d65c3a424e (diff)
downloadFreeBSD-src-d5461fcfc0503ca55628583baa835aadc87e2c6f.zip
FreeBSD-src-d5461fcfc0503ca55628583baa835aadc87e2c6f.tar.gz
Add a pw_mkdb2(3) function which does the same thing as pw_mkdb(3) except
it takes a new argument allowing to specify the endianness of the database to generate Differential Revision: https://reviews.freebsd.org/D2730 Reviewed by: ian
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/Makefile1
-rw-r--r--lib/libutil/libutil.h4
-rw-r--r--lib/libutil/pw_util.324
-rw-r--r--lib/libutil/pw_util.c28
4 files changed, 53 insertions, 4 deletions
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index 2f68628..2214339 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -78,6 +78,7 @@ MLINKS+=pw_util.3 pw_copy.3 \
pw_util.3 pw_make.3 \
pw_util.3 pw_make_v7.3 \
pw_util.3 pw_mkdb.3 \
+ pw_util.3 pw_mkdb2.3 \
pw_util.3 pw_lock.3 \
pw_util.3 pw_scan.3 \
pw_util.3 pw_tempname.3 \
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index b20ffa2..fc32fe7 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -144,6 +144,9 @@ char *fparseln(FILE *_fp, size_t *_len, size_t *_lineno,
#endif
#ifdef _PWD_H_
+#define PWDB_NATIVE 0
+#define PWDB_LE 1
+#define PWDB_BE 2
int pw_copy(int _ffd, int _tfd, const struct passwd *_pw,
struct passwd *_old_pw);
struct passwd
@@ -155,6 +158,7 @@ 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_mkdb2(const char *_user, int endian);
int pw_lock(void);
struct passwd *
pw_scan(const char *_line, int _flags);
diff --git a/lib/libutil/pw_util.3 b/lib/libutil/pw_util.3
index 706368f..73150d5 100644
--- a/lib/libutil/pw_util.3
+++ b/lib/libutil/pw_util.3
@@ -37,6 +37,7 @@
.Nm pw_make ,
.Nm pw_make_v7 ,
.Nm pw_mkdb ,
+.Nm pw_mkdb2 ,
.Nm pw_lock ,
.Nm pw_scan ,
.Nm pw_tempname ,
@@ -66,6 +67,8 @@
.Ft int
.Fn pw_mkdb "const char *user"
.Ft int
+.Fn pw_mkdb "const char *user" "int endian"
+.Ft int
.Fn pw_lock "void"
.Ft "struct passwd *"
.Fn pw_scan "const char *line" "int flags"
@@ -225,11 +228,30 @@ function regenerates the password database by running
.Xr pwd_mkdb 8 .
If
.Fa user
-only the record corresponding to that user will be updated.
+is set, only the record corresponding to that user will be updated.
The
.Fn pw_mkdb
function returns 0 in case of success and -1 in case of failure.
.Pp
+.Fn pw_mkdb2
+function regenerates the password database by running
+.Xr pwd_mkdb 8 .
+If
+.Fa user
+is set, only the record corresponding to that user will be updated.
+.Pp
+The
+.Fa endian
+variable can take the following values
+.Bl -tag -width PWDB_NATIVE
+.It Dv PWDB_NATIVE
+the database will be generated in host native endianness.
+.It Dv PWDB_LE
+the database will be generated in Little-endian.
+.It Dv PWDB_BE
+the database will be generated in Big-endian.
+.El
+.Pp
The
.Fn pw_lock
function locks the master password file.
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c
index befd1fb..b0bdad1 100644
--- a/lib/libutil/pw_util.c
+++ b/lib/libutil/pw_util.c
@@ -242,14 +242,36 @@ pw_tmp(int mfd)
return (tfd);
}
+int
+pw_mkdb(const char *user)
+{
+
+ return (pw_mkdb2(user, PWDB_NATIVE));
+}
+
/*
* Regenerate the password database.
*/
int
-pw_mkdb(const char *user)
+pw_mkdb2(const char *user, int endian)
{
int pstat;
pid_t pid;
+ const char *arg;
+
+ switch (endian) {
+ case PWDB_NATIVE:
+ arg = "-p";
+ break;
+ case PWDB_LE:
+ arg = "-pL";
+ break;
+ case PWDB_BE:
+ arg = "-pB";
+ break;
+ default:
+ return (-1);
+ }
(void)fflush(stderr);
switch ((pid = fork())) {
@@ -258,10 +280,10 @@ pw_mkdb(const char *user)
case 0:
/* child */
if (user == NULL)
- execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p",
+ execl(_PATH_PWD_MKDB, "pwd_mkdb", arg,
"-d", passwd_dir, tempname, (char *)NULL);
else
- execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p",
+ execl(_PATH_PWD_MKDB, "pwd_mkdb", arg,
"-d", passwd_dir, "-u", user, tempname,
(char *)NULL);
_exit(1);
OpenPOWER on IntegriCloud