Index: usr.sbin/pw/pw.c =================================================================== --- usr.sbin/pw/pw.c (revision 283961) +++ usr.sbin/pw/pw.c (working copy) @@ -106,9 +106,9 @@ static const char *opts[W_NUM][M_NUM] = { { /* user */ - "R:V:C:qn:u:c:d:e:p:g:G:mM:k:s:oL:i:w:h:H:Db:NPy:Y", - "R:V:C:qn:u:rY", - "R:V:C:qn:u:c:d:e:p:g:G:mM:l:k:s:w:L:h:H:FNPY", + "R:V:C:qn:u:c:d:E:e:p:g:G:mM:k:s:oL:i:w:h:H:Db:NPy:Y", + "R:V:C:qn:u:rYE:", + "R:V:C:qn:u:c:d:E:e:p:g:G:mM:l:k:s:w:L:h:H:FNPY", "R:V:C:qn:u:FPa7", "R:V:C:q", "R:V:C:q", Index: usr.sbin/pw/pw_user.c =================================================================== --- usr.sbin/pw/pw_user.c (revision 283961) +++ usr.sbin/pw/pw_user.c (working copy) @@ -134,6 +134,7 @@ FILE *fp; char *dmode_c; void *set = NULL; + int endianness = PWDB_NATIVE; static struct passwd fakeuser = { @@ -152,6 +153,17 @@ #endif }; + if ((arg = getarg(args, 'E')) != NULL) { + if (arg->val == NULL) + errx(EXIT_FAILURE, "Missing argument for option -E"); + if (strcmp(arg->val, "le") == 0) + endianness = PWDB_LE; + else if (strcmp(arg->val, "be") == 0) + endianness = PWDB_BE; + else + errx(EXIT_FAILURE, "Invalid arguent for option -E: " + "'%s' expected 'le' or 'be'", arg->val); + } /* * With M_NEXT, we only need to return the @@ -435,7 +447,7 @@ else grname[0] = '\0'; - rc = delpwent(pwd); + rc = delpwent(pwd, endianness); if (rc == -1) err(EX_IOERR, "user '%s' does not exist", pwd->pw_name); else if (rc != 0) @@ -726,7 +738,7 @@ if (mode == M_ADD) { edited = 1; /* Always */ - rc = addpwent(pwd); + rc = addpwent(pwd, endianness); if (rc == -1) errx(EX_IOERR, "user '%s' already exists", pwd->pw_name); @@ -742,7 +754,7 @@ } } else if (mode == M_UPDATE || mode == M_LOCK || mode == M_UNLOCK) { if (edited) { /* Only updated this if required */ - rc = chgpwent(a_name->val, pwd); + rc = chgpwent(a_name->val, pwd, endianness); if (rc == -1) errx(EX_IOERR, "user '%s' does not exist (NIS?)", pwd->pw_name); else if (rc != 0) Index: usr.sbin/pw/pwupd.c =================================================================== --- usr.sbin/pw/pwupd.c (revision 283960) +++ usr.sbin/pw/pwupd.c (working copy) @@ -102,10 +102,11 @@ } static int -pw_update(struct passwd * pwd, char const * user) +pw_update(struct passwd * pwd, char const * user, int endian) { struct passwd *pw = NULL; struct passwd *old_pw = NULL; + const char *name = NULL; int rc, pfd, tfd; if ((rc = pwdb_check()) != 0) @@ -132,10 +133,14 @@ err(1, "pw_copy()"); } /* - * in case of deletion of a user, the whole database - * needs to be regenerated + * In case of deletion of a user, the whole database needs to be + * regenerated + * In case the endianness is specified regenerate the whole database to + * ensure it is generated in the right endianness */ - if (pw_mkdb(pw != NULL ? pw->pw_name : NULL) == -1) { + if (pw != NULL && endian == PWDB_NATIVE) + name = pw->pw_name; + if (pw_mkdb2(name, endian) == -1) { pw_fini(); err(1, "pw_mkdb()"); } @@ -146,22 +151,22 @@ } int -addpwent(struct passwd * pwd) +addpwent(struct passwd * pwd, int endian) { - return (pw_update(pwd, NULL)); + return (pw_update(pwd, NULL, endian)); } int -chgpwent(char const * login, struct passwd * pwd) +chgpwent(char const * login, struct passwd * pwd, int endian) { - return (pw_update(pwd, login)); + return (pw_update(pwd, login, endian)); } int -delpwent(struct passwd * pwd) +delpwent(struct passwd * pwd, int endian) { - return (pw_update(NULL, pwd->pw_name)); + return (pw_update(NULL, pwd->pw_name, endian)); } Index: usr.sbin/pw/pwupd.h =================================================================== --- usr.sbin/pw/pwupd.h (revision 283961) +++ usr.sbin/pw/pwupd.h (working copy) @@ -87,9 +87,9 @@ #endif __BEGIN_DECLS -int addpwent(struct passwd * pwd); -int delpwent(struct passwd * pwd); -int chgpwent(char const * login, struct passwd * pwd); +int addpwent(struct passwd * pwd, int endian); +int delpwent(struct passwd * pwd, int endian); +int chgpwent(char const * login, struct passwd * pwd, int endian); int setpwdir(const char * dir); char * getpwpath(char const * file);