Fix support of 15 and 16 character lognames.

Warn if the logname is changed within a session - usually a missing setsid.
(approved by christos)
This commit is contained in:
dsl 2003-02-15 18:10:15 +00:00
parent 7707c16daa
commit aed442201d
4 changed files with 26 additions and 13 deletions

View File

@ -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 <sys/cdefs.h>
__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;

View File

@ -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 <sys/cdefs.h>
__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 <sys/timeb.h>
#include <sys/times.h>
#include <sys/malloc.h>
#include <sys/syslog.h>
#include <sys/mount.h>
#include <sys/sa.h>
@ -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;
}

View File

@ -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 <sys/cdefs.h>
__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':

View File

@ -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 */