diff --git a/libs/libc/pwd/Kconfig b/libs/libc/pwd/Kconfig index 2fc6e0fbd54..88d5ba4e922 100644 --- a/libs/libc/pwd/Kconfig +++ b/libs/libc/pwd/Kconfig @@ -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. diff --git a/libs/libc/pwd/lib_find_pwdfile.c b/libs/libc/pwd/lib_find_pwdfile.c index 97ac7abbfa1..88da93bbdac 100644 --- a/libs/libc/pwd/lib_find_pwdfile.c +++ b/libs/libc/pwd/lib_find_pwdfile.c @@ -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. */