diff --git a/include/pwd.h b/include/pwd.h index cea9eaeb93..8856710ad4 100644 --- a/include/pwd.h +++ b/include/pwd.h @@ -49,6 +49,7 @@ struct passwd { FAR char *pw_name; + FAR char *pw_passwd; uid_t pw_uid; gid_t pw_gid; FAR char *pw_gecos; diff --git a/libs/libc/pwd/lib_find_pwdfile.c b/libs/libc/pwd/lib_find_pwdfile.c index 8368eed1d2..97ac7abbfa 100644 --- a/libs/libc/pwd/lib_find_pwdfile.c +++ b/libs/libc/pwd/lib_find_pwdfile.c @@ -289,6 +289,7 @@ static int pwd_foreach(pwd_foreach_match_t match, uintptr_t arg, *ptr++ = '\0'; entry->pw_shell = ROOT_SHELL; + entry->pw_passwd = ROOT_PASSWD; /* Check for a match */ diff --git a/libs/libc/pwd/lib_getpwbuf.c b/libs/libc/pwd/lib_getpwbuf.c index 91e259718f..c05659c641 100644 --- a/libs/libc/pwd/lib_getpwbuf.c +++ b/libs/libc/pwd/lib_getpwbuf.c @@ -57,10 +57,10 @@ FAR struct passwd *getpwbuf(uid_t uid, gid_t gid, FAR const char *name, FAR const char *gecos, FAR const char *dir, - FAR const char *shell) + FAR const char *shell, FAR const char *passwd) { FAR struct passwd *pwd = NULL; - int ret = getpwbuf_r(uid, gid, name, gecos, dir, shell, &g_passwd, + int ret = getpwbuf_r(uid, gid, name, gecos, dir, shell, passwd, &g_passwd, g_passwd_buffer, sizeof(g_passwd_buffer), &pwd); return ret == 0 ? pwd : NULL; } diff --git a/libs/libc/pwd/lib_getpwbufr.c b/libs/libc/pwd/lib_getpwbufr.c index 1139210bfb..0a378e061e 100644 --- a/libs/libc/pwd/lib_getpwbufr.c +++ b/libs/libc/pwd/lib_getpwbufr.c @@ -67,20 +67,23 @@ int getpwbuf_r(uid_t uid, gid_t gid, FAR const char *name, FAR const char *gecos, FAR const char *dir, - FAR const char *shell, FAR struct passwd *pwd, - FAR char *buf, size_t buflen, FAR struct passwd **result) + FAR const char *shell, FAR const char *passwd, + FAR struct passwd *pwd, FAR char *buf, size_t buflen, + FAR struct passwd **result) { size_t reqdlen; size_t nsize; size_t gsize; size_t dsize; size_t ssize; + size_t psize; nsize = strlen(name) + 1; gsize = strlen(gecos) + 1; dsize = strlen(dir) + 1; ssize = strlen(shell) + 1; - reqdlen = nsize + gsize + dsize + ssize; + psize = strlen(passwd) + 1; + reqdlen = nsize + gsize + dsize + ssize + psize; if (buflen < reqdlen) { @@ -90,10 +93,11 @@ int getpwbuf_r(uid_t uid, gid_t gid, FAR const char *name, return ERANGE; } - pwd->pw_name = buf; - pwd->pw_gecos = &buf[nsize]; - pwd->pw_dir = &buf[nsize + gsize]; - pwd->pw_shell = &buf[nsize + gsize + dsize]; + pwd->pw_name = buf; + pwd->pw_gecos = &buf[nsize]; + pwd->pw_dir = &buf[nsize + gsize]; + pwd->pw_shell = &buf[nsize + gsize + dsize]; + pwd->pw_passwd = &buf[nsize + gsize + dsize + ssize]; pwd->pw_uid = uid; pwd->pw_gid = gid; @@ -101,6 +105,7 @@ int getpwbuf_r(uid_t uid, gid_t gid, FAR const char *name, strlcpy(pwd->pw_gecos, gecos, gsize); strlcpy(pwd->pw_dir, dir, dsize); strlcpy(pwd->pw_shell, shell, ssize); + strlcpy(pwd->pw_passwd, passwd, psize); *result = pwd; return 0; diff --git a/libs/libc/pwd/lib_getpwent.c b/libs/libc/pwd/lib_getpwent.c index b91e2a34cc..0e9ba86d7c 100644 --- a/libs/libc/pwd/lib_getpwent.c +++ b/libs/libc/pwd/lib_getpwent.c @@ -156,7 +156,7 @@ int getpwent_r(FAR struct passwd *pwd, } ret = getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_NAME, ROOT_DIR, - ROOT_SHELL, pwd, buf, buflen, result); + ROOT_SHELL, ROOT_PASSWD, pwd, buf, buflen, result); if (ret == 0) { g_passwd_index++; diff --git a/libs/libc/pwd/lib_getpwnam.c b/libs/libc/pwd/lib_getpwnam.c index d5c21aabc3..3b26f9c56d 100644 --- a/libs/libc/pwd/lib_getpwnam.c +++ b/libs/libc/pwd/lib_getpwnam.c @@ -74,6 +74,6 @@ FAR struct passwd *getpwnam(FAR const char *name) } return getpwbuf(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR, - ROOT_SHELL); + ROOT_SHELL, ROOT_PASSWD); #endif } diff --git a/libs/libc/pwd/lib_getpwnamr.c b/libs/libc/pwd/lib_getpwnamr.c index bb32683aac..2f3add4c2b 100644 --- a/libs/libc/pwd/lib_getpwnamr.c +++ b/libs/libc/pwd/lib_getpwnamr.c @@ -85,6 +85,6 @@ int getpwnam_r(FAR const char *name, FAR struct passwd *pwd, FAR char *buf, } return getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR, - ROOT_SHELL, pwd, buf, buflen, result); + ROOT_SHELL, ROOT_PASSWD, pwd, buf, buflen, result); #endif } diff --git a/libs/libc/pwd/lib_getpwuid.c b/libs/libc/pwd/lib_getpwuid.c index 049666c0f7..8c61e7111f 100644 --- a/libs/libc/pwd/lib_getpwuid.c +++ b/libs/libc/pwd/lib_getpwuid.c @@ -73,6 +73,6 @@ FAR struct passwd *getpwuid(uid_t uid) } return getpwbuf(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR, - ROOT_SHELL); + ROOT_SHELL, ROOT_PASSWD); #endif } diff --git a/libs/libc/pwd/lib_getpwuidr.c b/libs/libc/pwd/lib_getpwuidr.c index ce349549e7..e96359a224 100644 --- a/libs/libc/pwd/lib_getpwuidr.c +++ b/libs/libc/pwd/lib_getpwuidr.c @@ -84,6 +84,6 @@ int getpwuid_r(uid_t uid, FAR struct passwd *pwd, FAR char *buf, } return getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR, - ROOT_SHELL, pwd, buf, buflen, result); + ROOT_SHELL, ROOT_PASSWD, pwd, buf, buflen, result); #endif } diff --git a/libs/libc/pwd/lib_pwd.h b/libs/libc/pwd/lib_pwd.h index f9f80d88ea..a917913c23 100644 --- a/libs/libc/pwd/lib_pwd.h +++ b/libs/libc/pwd/lib_pwd.h @@ -39,12 +39,13 @@ # define CONFIG_LIBC_PASSWD_LINESIZE 80 #endif -#define ROOT_NAME "root" -#define ROOT_UID 0 -#define ROOT_GID 0 -#define ROOT_GEOCS "root" -#define ROOT_DIR "/root" -#define ROOT_SHELL "/bin/nsh" +#define ROOT_NAME "root" +#define ROOT_UID 0 +#define ROOT_GID 0 +#define ROOT_GEOCS "root" +#define ROOT_DIR "/root" +#define ROOT_SHELL "/bin/nsh" +#define ROOT_PASSWD "root" /**************************************************************************** * Public Data @@ -70,11 +71,12 @@ EXTERN char g_passwd_buffer[CONFIG_LIBC_PASSWD_LINESIZE]; FAR struct passwd *getpwbuf(uid_t uid, gid_t gid, FAR const char *name, FAR const char *gecos, FAR const char *dir, - FAR const char *shell); + FAR const char *shell, FAR const char *passwd); int getpwbuf_r(uid_t uid, gid_t gid, FAR const char *name, FAR const char *gecos, FAR const char *dir, - FAR const char *shell, FAR struct passwd *pwd, - FAR char *buf, size_t buflen, FAR struct passwd **result); + FAR const char *shell, FAR const char *passwd, + FAR struct passwd *pwd, FAR char *buf, size_t buflen, + FAR struct passwd **result); #ifdef CONFIG_LIBC_PASSWD_FILE int pwd_findby_name(FAR const char *uname, FAR struct passwd *entry,