From: Karel Zak Date: Wed, 5 Oct 2011 21:07:45 +0000 (+0200) Subject: login: use TTYGROUP from login.defs X-Git-Tag: v2.21-rc1~282 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45d0a30ea385fc8e32caba256c93d44c3f2b535c;p=thirdparty%2Futil-linux.git login: use TTYGROUP from login.defs Note that Suse login(1) does not use any default for TTYGROUP, it means that TTYGROUP has to be explicitly defined otherwise user\'s primary group is used. The util-linux login(1) uses 'tty' group name as a default value. Signed-off-by: Karel Zak --- diff --git a/login-utils/login.1 b/login-utils/login.1 index 1d3ae1a5df..cce4672316 100644 --- a/login-utils/login.1 +++ b/login-utils/login.1 @@ -149,6 +149,15 @@ The default value is 5. .RS 4 The terminal permissions. The default value is 0600. .RE +.PP +\fBTTYGROUP\fR (string) +.RS 4 +The login tty will be owned by the +\fBTTYGROUP\fR. The default value is 'tty'. If the \fBTTYGROUP\fR does not exist +then the ownership of the terminal is set to the user\'s primary group. +.SP +The \fBTTYGROUP\fR can be either the name of a group or a numeric group identifier. +.RE .SH FILES .nf diff --git a/login-utils/login.c b/login-utils/login.c index 4ad962ae85..17a3137108 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -264,13 +264,20 @@ static void open_tty(const char *tty) static void chown_tty(struct login_context *cxt) { - struct group *gr; + const char *grname; uid_t uid = cxt->pwd->pw_uid; gid_t gid = cxt->pwd->pw_gid; - gr = getgrnam(TTYGRPNAME); - if (gr) - gid = gr->gr_gid; + grname = getlogindefs_str("TTYGROUP", TTYGRPNAME); + if (grname && *grname) { + if (*grname >= 0 && *grname <= 9) /* group by ID */ + gid = getlogindefs_num("TTYGROUP", gid); + else { /* group by name */ + struct group *gr = getgrnam(grname); + if (gr) + gid = gr->gr_gid; + } + } if (fchown(0, uid, gid)) /* tty */ chown_err(cxt->tty_name, uid, gid);