mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
libc/pwd: parse NuttX 5-field passwd records
Accept user#️⃣uid:gid:home lines produced by mkpasswd in addition
to the six-field gecos form, and raise the default line buffer to 256.
Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
This commit is contained in:
parent
fe28fb033c
commit
282d4cb0e9
2 changed files with 37 additions and 14 deletions
|
|
@ -28,7 +28,7 @@ config LIBC_PASSWD_FILEPATH
|
|||
|
||||
config LIBC_PASSWD_LINESIZE
|
||||
int "Maximum line size"
|
||||
default 80
|
||||
default 256
|
||||
---help---
|
||||
The maximum length of one line in the passwd file. This determines
|
||||
the size of the I/O buffer used to access the passwd file.
|
||||
|
|
|
|||
|
|
@ -170,14 +170,18 @@ static int pwd_foreach(pwd_foreach_match_t match, uintptr_t arg,
|
|||
*
|
||||
* The format of the password file is:
|
||||
*
|
||||
* user:x:uid:uid:geos:home
|
||||
* user:x:uid:gid:home
|
||||
*
|
||||
* Or the standard six-field form with an optional gecos field:
|
||||
*
|
||||
* user:x:uid:gid:gecos:home
|
||||
*
|
||||
* Where:
|
||||
* user: User name
|
||||
* x: Encrypted password
|
||||
* uid: User ID
|
||||
* uid: Group ID
|
||||
* geos: User information
|
||||
* gid: Group ID
|
||||
* gecos: User information (optional)
|
||||
* home: Login directory
|
||||
*/
|
||||
|
||||
|
|
@ -259,26 +263,45 @@ static int pwd_foreach(pwd_foreach_match_t match, uintptr_t arg,
|
|||
entry->pw_gid = (gid_t)atoi(save);
|
||||
save = ptr;
|
||||
|
||||
/* Skip to the end of the user information and properly terminate it.
|
||||
* The user information must be terminated with the field delimiter
|
||||
* ':'.
|
||||
/* NuttX passwd files use user:hash:uid:gid:home. Standard passwd
|
||||
* files may include an optional gecos field:
|
||||
* user:hash:uid:gid:gecos:home
|
||||
*/
|
||||
|
||||
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
|
||||
if (*ptr == ':')
|
||||
{
|
||||
}
|
||||
/* Skip to the end of the user information and properly terminate
|
||||
* it. The user information must be terminated with the field
|
||||
* delimiter ':'.
|
||||
*/
|
||||
|
||||
if (*ptr == '\n' || *ptr == '\0')
|
||||
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
|
||||
{
|
||||
}
|
||||
|
||||
if (*ptr == '\n' || *ptr == '\0')
|
||||
{
|
||||
/* Bad line format? */
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
*ptr++ = '\0';
|
||||
entry->pw_gecos = save;
|
||||
entry->pw_dir = ptr;
|
||||
}
|
||||
else if (*save != '\0' && *save != '\n')
|
||||
{
|
||||
entry->pw_gecos = "";
|
||||
entry->pw_dir = save;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bad line format? */
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
*ptr++ = '\0';
|
||||
entry->pw_gecos = save;
|
||||
entry->pw_dir = ptr;
|
||||
|
||||
/* Skip to the end of the home directory and properly terminate it.
|
||||
* The home directory must be the last thing on the line.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue