mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 05:08:41 +08:00
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>
This commit is contained in:
parent
ff4b654be0
commit
c0039d6623
10 changed files with 32 additions and 23 deletions
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue