tuilogin

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit f6eb09965829fa7a88e1253c71ace6bbfccda59a
parent 92f73a6858a7fd710f8fbcaa31739b81f22deecd
Author: mrgrouse <mrgrouse@mrgrouse.com>
Date:   Fri, 17 Jul 2026 15:08:41 -0400

tuilogin.c: login after user inputs correct data, set environment variables, cd to home and exec their shell

Diffstat:
Mtuilogin.c | 34+++++++++++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/tuilogin.c b/tuilogin.c @@ -5,17 +5,27 @@ /* for writing to file descriptors */ #include <unistd.h> +/* for getting errors from library functions */ +#include <errno.h> + +/* for setting environment variables */ +#include <stdlib.h> + /* user & password handling */ #include <sys/types.h> #include <pwd.h> -int main() +/* for initgroups() */ +#include <grp.h> + +int main(void) { FIELD *field[3]; FORM *login_form; int row, col; char user[32]; char password[255]; + struct passwd *userinfo; initscr(); /* initialize */ cbreak(); /* fix tty from 'cooked' mode */ @@ -54,18 +64,36 @@ int main() write(3, "\n", 2); close(3); + /* since we utilize readiness notifs we are just going to error out if there's a bad password/user and rely on the supervision to restart us */ // TODO: error handling if password is wrong mvgetnstr(prow, pcol, user, 32); noecho(); mvgetnstr(prow + 2, pcol, password, 255); + /* free our forms and fields */ unpost_form(login_form); free_form(login_form); free_field(field[0]); free_field(field[1]); - endwin(); /* safely close ncurses */ - return 0; + /* getting our password info from the user */ + errno = 0; + userinfo = getpwnam(user); + if (userinfo == NULL) { + if (errno) + printf("getpwnam %s:\n", user); + else + printf("wrong username.\n"); + } + initgroups(userinfo->pw_name, userinfo->pw_gid); + setgid(userinfo->pw_gid); + setuid(userinfo->pw_uid); + + setenv("HOME", userinfo->pw_dir, 1); + setenv("SHELL", userinfo->pw_shell, 1); + chdir(userinfo->pw_dir); + execl(userinfo->pw_shell, userinfo->pw_shell, NULL); + return errno; }