From aed442201dd02d17e62a346972cfc2a4491cf304 Mon Sep 17 00:00:00 2001 From: dsl Date: Sat, 15 Feb 2003 18:10:15 +0000 Subject: [PATCH] Fix support of 15 and 16 character lognames. Warn if the logname is changed within a session - usually a missing setsid. (approved by christos) --- sys/kern/kern_proc.c | 5 +++-- sys/kern/kern_prot.c | 23 ++++++++++++++++------- sys/kern/kern_sig.c | 7 ++++--- sys/sys/proc.h | 4 +++- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index e6a29ccf50df..75e7a0c76564 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_proc.c,v 1.57 2003/02/01 06:23:43 thorpej Exp $ */ +/* $NetBSD: kern_proc.c,v 1.58 2003/02/15 18:10:16 dsl Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.57 2003/02/01 06:23:43 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.58 2003/02/15 18:10:16 dsl Exp $"); #include "opt_kstack.h" @@ -429,6 +429,7 @@ enterpgrp(p, pgid, mksess) sess->s_count = 1; sess->s_ttyvp = NULL; sess->s_ttyp = NULL; + sess->s_flags = p->p_session->s_flags & ~S_LOGIN_SET; memcpy(sess->s_login, p->p_session->s_login, sizeof(sess->s_login)); p->p_flag &= ~P_CONTROLT; diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 54aeed48ae9e..94e15727d7b6 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_prot.c,v 1.71 2003/02/01 06:23:43 thorpej Exp $ */ +/* $NetBSD: kern_prot.c,v 1.72 2003/02/15 18:10:16 dsl Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1990, 1991, 1993 @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_prot.c,v 1.71 2003/02/01 06:23:43 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_prot.c,v 1.72 2003/02/15 18:10:16 dsl Exp $"); #include "opt_compat_43.h" @@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_prot.c,v 1.71 2003/02/01 06:23:43 thorpej Exp $ #include #include #include +#include #include #include @@ -801,13 +802,21 @@ sys___setlogin(l, v, retval) syscallarg(const char *) namebuf; } */ *uap = v; struct proc *p = l->l_proc; + struct session *s = p->p_pgrp->pg_session; + char newname[sizeof s->s_login + 1]; int error; if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); - error = copyinstr(SCARG(uap, namebuf), p->p_pgrp->pg_session->s_login, - sizeof(p->p_pgrp->pg_session->s_login) - 1, (size_t *)0); - if (error == ENAMETOOLONG) - error = EINVAL; - return (error); + error = copyinstr(SCARG(uap, namebuf), &newname, sizeof newname, NULL); + if (error != 0) + return error == ENAMETOOLONG ? EINVAL : error; + + if (s->s_flags & S_LOGIN_SET && p->p_pid != s->s_sid && + strncmp(newname, s->s_login, sizeof s->s_login) != 0) + log(LOG_WARNING, "%s (pid %d) changing logname from %.*s to %s", + p->p_comm, p->p_pid, (int)sizeof s->s_login, s->s_login, newname); + s->s_flags |= S_LOGIN_SET; + strncpy(s->s_login, newname, sizeof s->s_login); + return 0; } diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 919edb0c4edc..c70f4ffafd93 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.133 2003/02/07 21:43:18 nathanw Exp $ */ +/* $NetBSD: kern_sig.c,v 1.134 2003/02/15 18:10:16 dsl Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.133 2003/02/07 21:43:18 nathanw Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.134 2003/02/15 18:10:16 dsl Exp $"); #include "opt_ktrace.h" #include "opt_compat_sunos.h" @@ -1709,7 +1709,8 @@ build_corename(struct proc *p, char dst[MAXPATHLEN]) i = snprintf(d, end - d, "%d", p->p_pid); break; case 'u': - i = snprintf(d, end - d, "%s", + i = snprintf(d, end - d, "%.*s", + (int)sizeof p->p_pgrp->pg_session->s_login, p->p_pgrp->pg_session->s_login); break; case 't': diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 17b5a8d0a8a4..a6f7268f91fb 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $NetBSD: proc.h,v 1.158 2003/02/14 10:11:56 dsl Exp $ */ +/* $NetBSD: proc.h,v 1.159 2003/02/15 18:10:15 dsl Exp $ */ /*- * Copyright (c) 1986, 1989, 1991, 1993 @@ -61,6 +61,8 @@ */ struct session { int s_count; /* Ref cnt; pgrps in session */ + u_int s_flags; +#define S_LOGIN_SET 1 /* s_login set in this session */ struct proc *s_leader; /* Session leader */ struct vnode *s_ttyvp; /* Vnode of controlling terminal */ struct tty *s_ttyp; /* Controlling terminal */