From f4fefef930aa03f0ad63a2ef4bad1cde5717b62d Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 1 Apr 2020 15:33:09 -0400 Subject: provide space for gecos and password, set missing password to "--" --- user.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/user.c b/user.c index 9eaa7e1..831ee4a 100644 --- a/user.c +++ b/user.c @@ -25,6 +25,7 @@ #define _POSIX_C_SOURCE 200809L #include #include +#include #include #include #include @@ -33,13 +34,17 @@ #include #include +#ifndef LINE_MAX +#define LINE_MAX _POSIX2_LINE_MAX +#endif + #define USERS_DIRECTORY "/var/secure/users" static DIR *users_dir = NULL; struct user { struct passwd pw; - char *gecos; - char *password; + char gecos[LINE_MAX]; + char password[LINE_MAX]; }; enum selection { UID, NAME, ALL }; @@ -62,10 +67,10 @@ static struct user *user_read(char *name) u.pw.pw_name = name; u.pw.pw_uid = st.st_uid; u.pw.pw_gid = st.st_gid; - u.pw.pw_dir = "/"; // TODO: read symlink at userfd, home - u.pw.pw_shell = "/bin/sh"; // TOOD: read symlink at userfd, shell - u.gecos = name; // TODO: read file at userfd, gecos - u.password = ""; // TODO: read file at userfd, password + u.pw.pw_dir = "/"; // TODO: read symlink at userfd, home + u.pw.pw_shell = "/bin/sh"; // TOOD: read symlink at userfd, shell + strcpy(u.gecos, name); // TODO: read file at userfd, gecos + strcpy(u.password, "--"); // TODO: read file at userfd, password close(user); -- cgit v1.2.1