LibC: Add pw_passwd and pw_gecos to passwd structure

This information is available in /etc/passwd either way so why not
expose it to the user. Practically all UNIX-likes have these either way
This commit is contained in:
Bananymous 2025-06-02 12:23:06 +03:00
parent bbff9f89b0
commit 755d41ca4e
2 changed files with 16 additions and 11 deletions

View File

@ -14,11 +14,13 @@ __BEGIN_DECLS
struct passwd
{
char* pw_name; /* User's login name. */
uid_t pw_uid; /* Numerical user ID. */
gid_t pw_gid; /* Numerical group ID. */
char* pw_dir; /* Initial working directory. */
char* pw_shell; /* Program to use as shell. */
char* pw_name; /* User's login name. */
char* pw_passwd; /* User's hashed password. */
uid_t pw_uid; /* Numerical user ID. */
gid_t pw_gid; /* Numerical group ID. */
char* pw_gecos; /* User's information. */
char* pw_dir; /* Initial working directory. */
char* pw_shell; /* Program to use as shell. */
};
void endpwent(void);

View File

@ -71,12 +71,14 @@ struct passwd* getpwent(void)
switch (i)
{
case 0:
s_pwent_struct.pw_name = (char*)malloc(field_len + 1);
s_pwent_struct.pw_name = strndup(ptr, field_len + 1);
if (!s_pwent_struct.pw_name)
return nullptr;
strcpy(s_pwent_struct.pw_name, ptr);
break;
case 1:
s_pwent_struct.pw_passwd = strndup(ptr, field_len + 1);
if (!s_pwent_struct.pw_passwd)
return nullptr;
break;
case 2:
ASSERT(1 <= field_len && field_len <= 9);
@ -91,18 +93,19 @@ struct passwd* getpwent(void)
s_pwent_struct.pw_gid = atoi(ptr);
break;
case 4:
s_pwent_struct.pw_gecos = strndup(ptr, field_len + 1);
if (!s_pwent_struct.pw_gecos)
return nullptr;
break;
case 5:
s_pwent_struct.pw_dir = (char*)malloc(field_len + 1);
s_pwent_struct.pw_dir = strndup(ptr, field_len + 1);
if (!s_pwent_struct.pw_dir)
return nullptr;
strcpy(s_pwent_struct.pw_dir, ptr);
break;
case 6:
s_pwent_struct.pw_shell = (char*)malloc(field_len + 1);
s_pwent_struct.pw_shell = strndup(ptr, field_len + 1);
if (!s_pwent_struct.pw_shell)
return nullptr;
strcpy(s_pwent_struct.pw_shell, ptr);
break;
}