From 5eafb0a9959c9a485046a4ec7096d970f96ce359 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 18 Nov 2013 22:55:28 +0100 Subject: set user and group MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/cerberus.c | 7 ++++++- src/login.c | 21 +++++++++++++++++++++ src/login.h | 7 +++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/cerberus.c b/src/cerberus.c index d61f541..f60f64c 100644 --- a/src/cerberus.c +++ b/src/cerberus.c @@ -18,6 +18,8 @@ */ #include "cerberus.h" +/* TODO use log */ + /** * Mane method @@ -177,7 +179,10 @@ int main(int argc, char** argv) reenable_echo(); - /* TODO login */ + /* Login */ + /* TODO verify that user is enabled */ + set_user(entry); + /* TODO set supplemental groups */ chdir_home(entry); ensure_shell(entry); set_environ(entry, preserve_env); diff --git a/src/login.c b/src/login.c index 5a97fb6..46bf4e2 100644 --- a/src/login.c +++ b/src/login.c @@ -32,6 +32,27 @@ extern char** environ; +/** + * Set the user gid and uid + * + * @param entry The user entry in the password file + */ +void set_user(struct passwd* entry) +{ + if (setgid(entry->pw_gid) && entry->pw_gid) + { + perror("setgid"); + _exit(1); + } + + if (setuid(entry->pw_uid) && entry->pw_uid) + { + perror("setuid"); + _exit(1); + } +} + + /** * Change directory to the user's home directory * diff --git a/src/login.h b/src/login.h index 43cb302..14014f2 100644 --- a/src/login.h +++ b/src/login.h @@ -22,6 +22,13 @@ #include +/** + * Set the user gid and uid + * + * @param entry The user entry in the password file + */ +void set_user(struct passwd* entry); + /** * Change directory to the user's home directory * -- cgit v1.2.3-70-g09d2