Skip to content

Commit c0039d6

Browse files
chenzhijiaGUIDINGLI
authored andcommitted
libs/libc/pwd: add new member to passwd struct
Add pw_passwd member to pass tlpi example: https://man7.org/tlpi/code/online/dist/users_groups/check_password.c.html Signed-off-by: chenzhijia <chenzhijia@xiaomi.com>
1 parent ff4b654 commit c0039d6

File tree

10 files changed

+32
-23
lines changed

10 files changed

+32
-23
lines changed

include/pwd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
struct passwd
5050
{
5151
FAR char *pw_name;
52+
FAR char *pw_passwd;
5253
uid_t pw_uid;
5354
gid_t pw_gid;
5455
FAR char *pw_gecos;

libs/libc/pwd/lib_find_pwdfile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ static int pwd_foreach(pwd_foreach_match_t match, uintptr_t arg,
289289

290290
*ptr++ = '\0';
291291
entry->pw_shell = ROOT_SHELL;
292+
entry->pw_passwd = ROOT_PASSWD;
292293

293294
/* Check for a match */
294295

libs/libc/pwd/lib_getpwbuf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757

5858
FAR struct passwd *getpwbuf(uid_t uid, gid_t gid, FAR const char *name,
5959
FAR const char *gecos, FAR const char *dir,
60-
FAR const char *shell)
60+
FAR const char *shell, FAR const char *passwd)
6161
{
6262
FAR struct passwd *pwd = NULL;
63-
int ret = getpwbuf_r(uid, gid, name, gecos, dir, shell, &g_passwd,
63+
int ret = getpwbuf_r(uid, gid, name, gecos, dir, shell, passwd, &g_passwd,
6464
g_passwd_buffer, sizeof(g_passwd_buffer), &pwd);
6565
return ret == 0 ? pwd : NULL;
6666
}

libs/libc/pwd/lib_getpwbufr.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,23 @@
6767

6868
int getpwbuf_r(uid_t uid, gid_t gid, FAR const char *name,
6969
FAR const char *gecos, FAR const char *dir,
70-
FAR const char *shell, FAR struct passwd *pwd,
71-
FAR char *buf, size_t buflen, FAR struct passwd **result)
70+
FAR const char *shell, FAR const char *passwd,
71+
FAR struct passwd *pwd, FAR char *buf, size_t buflen,
72+
FAR struct passwd **result)
7273
{
7374
size_t reqdlen;
7475
size_t nsize;
7576
size_t gsize;
7677
size_t dsize;
7778
size_t ssize;
79+
size_t psize;
7880

7981
nsize = strlen(name) + 1;
8082
gsize = strlen(gecos) + 1;
8183
dsize = strlen(dir) + 1;
8284
ssize = strlen(shell) + 1;
83-
reqdlen = nsize + gsize + dsize + ssize;
85+
psize = strlen(passwd) + 1;
86+
reqdlen = nsize + gsize + dsize + ssize + psize;
8487

8588
if (buflen < reqdlen)
8689
{
@@ -90,17 +93,19 @@ int getpwbuf_r(uid_t uid, gid_t gid, FAR const char *name,
9093
return ERANGE;
9194
}
9295

93-
pwd->pw_name = buf;
94-
pwd->pw_gecos = &buf[nsize];
95-
pwd->pw_dir = &buf[nsize + gsize];
96-
pwd->pw_shell = &buf[nsize + gsize + dsize];
96+
pwd->pw_name = buf;
97+
pwd->pw_gecos = &buf[nsize];
98+
pwd->pw_dir = &buf[nsize + gsize];
99+
pwd->pw_shell = &buf[nsize + gsize + dsize];
100+
pwd->pw_passwd = &buf[nsize + gsize + dsize + ssize];
97101

98102
pwd->pw_uid = uid;
99103
pwd->pw_gid = gid;
100104
strlcpy(pwd->pw_name, name, nsize);
101105
strlcpy(pwd->pw_gecos, gecos, gsize);
102106
strlcpy(pwd->pw_dir, dir, dsize);
103107
strlcpy(pwd->pw_shell, shell, ssize);
108+
strlcpy(pwd->pw_passwd, passwd, psize);
104109

105110
*result = pwd;
106111
return 0;

libs/libc/pwd/lib_getpwent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int getpwent_r(FAR struct passwd *pwd,
156156
}
157157

158158
ret = getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_NAME, ROOT_DIR,
159-
ROOT_SHELL, pwd, buf, buflen, result);
159+
ROOT_SHELL, ROOT_PASSWD, pwd, buf, buflen, result);
160160
if (ret == 0)
161161
{
162162
g_passwd_index++;

libs/libc/pwd/lib_getpwnam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ FAR struct passwd *getpwnam(FAR const char *name)
7474
}
7575

7676
return getpwbuf(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR,
77-
ROOT_SHELL);
77+
ROOT_SHELL, ROOT_PASSWD);
7878
#endif
7979
}

libs/libc/pwd/lib_getpwnamr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ int getpwnam_r(FAR const char *name, FAR struct passwd *pwd, FAR char *buf,
8585
}
8686

8787
return getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR,
88-
ROOT_SHELL, pwd, buf, buflen, result);
88+
ROOT_SHELL, ROOT_PASSWD, pwd, buf, buflen, result);
8989
#endif
9090
}

libs/libc/pwd/lib_getpwuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ FAR struct passwd *getpwuid(uid_t uid)
7373
}
7474

7575
return getpwbuf(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR,
76-
ROOT_SHELL);
76+
ROOT_SHELL, ROOT_PASSWD);
7777
#endif
7878
}

libs/libc/pwd/lib_getpwuidr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ int getpwuid_r(uid_t uid, FAR struct passwd *pwd, FAR char *buf,
8484
}
8585

8686
return getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR,
87-
ROOT_SHELL, pwd, buf, buflen, result);
87+
ROOT_SHELL, ROOT_PASSWD, pwd, buf, buflen, result);
8888
#endif
8989
}

libs/libc/pwd/lib_pwd.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939
# define CONFIG_LIBC_PASSWD_LINESIZE 80
4040
#endif
4141

42-
#define ROOT_NAME "root"
43-
#define ROOT_UID 0
44-
#define ROOT_GID 0
45-
#define ROOT_GEOCS "root"
46-
#define ROOT_DIR "/root"
47-
#define ROOT_SHELL "/bin/nsh"
42+
#define ROOT_NAME "root"
43+
#define ROOT_UID 0
44+
#define ROOT_GID 0
45+
#define ROOT_GEOCS "root"
46+
#define ROOT_DIR "/root"
47+
#define ROOT_SHELL "/bin/nsh"
48+
#define ROOT_PASSWD "root"
4849

4950
/****************************************************************************
5051
* Public Data
@@ -70,11 +71,12 @@ EXTERN char g_passwd_buffer[CONFIG_LIBC_PASSWD_LINESIZE];
7071

7172
FAR struct passwd *getpwbuf(uid_t uid, gid_t gid, FAR const char *name,
7273
FAR const char *gecos, FAR const char *dir,
73-
FAR const char *shell);
74+
FAR const char *shell, FAR const char *passwd);
7475
int getpwbuf_r(uid_t uid, gid_t gid, FAR const char *name,
7576
FAR const char *gecos, FAR const char *dir,
76-
FAR const char *shell, FAR struct passwd *pwd,
77-
FAR char *buf, size_t buflen, FAR struct passwd **result);
77+
FAR const char *shell, FAR const char *passwd,
78+
FAR struct passwd *pwd, FAR char *buf, size_t buflen,
79+
FAR struct passwd **result);
7880

7981
#ifdef CONFIG_LIBC_PASSWD_FILE
8082
int pwd_findby_name(FAR const char *uname, FAR struct passwd *entry,

0 commit comments

Comments
 (0)