mirror of
git://anongit.mindrot.org/openssh.git
synced 2024-12-22 10:00:14 +00:00
- (djm) Enable new setproctitle emulation for Linux, AIX and HP/UX. More
systems may be added later.
This commit is contained in:
parent
13b2e55c36
commit
a8ed44b79e
@ -1,3 +1,7 @@
|
||||
20030110
|
||||
- (djm) Enable new setproctitle emulation for Linux, AIX and HP/UX. More
|
||||
systems may be added later.
|
||||
|
||||
20030108
|
||||
- (djm) Sync openbsd-compat/ with OpenBSD -current
|
||||
- (djm) Avoid redundant xstrdup/xfree in auth2-pam.c. From Solar via markus@
|
||||
@ -965,4 +969,4 @@
|
||||
save auth method before monitor_reset_key_state(); bugzilla bug #284;
|
||||
ok provos@
|
||||
|
||||
$Id: ChangeLog,v 1.2557 2003/01/09 04:09:30 tim Exp $
|
||||
$Id: ChangeLog,v 1.2558 2003/01/09 22:53:12 djm Exp $
|
||||
|
4
TODO
4
TODO
@ -13,7 +13,7 @@ Programming:
|
||||
- Write a test program that calls stat() to search for EGD/PRNGd socket
|
||||
rather than use the (non-portable) "test -S".
|
||||
|
||||
- Replacement for setproctitle() - HP-UX support only currently
|
||||
- More platforms for for setproctitle() emulation (testing needed)
|
||||
|
||||
- Handle changing passwords for the non-PAM expired password case
|
||||
|
||||
@ -133,4 +133,4 @@ PrivSep Issues:
|
||||
- Cygwin
|
||||
+ Privsep for Pre-auth only (no fd passing)
|
||||
|
||||
$Id: TODO,v 1.51 2002/09/05 06:32:03 djm Exp $
|
||||
$Id: TODO,v 1.52 2003/01/09 22:53:12 djm Exp $
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $Id: configure.ac,v 1.97 2003/01/09 01:22:59 tim Exp $
|
||||
# $Id: configure.ac,v 1.98 2003/01/09 22:53:12 djm Exp $
|
||||
|
||||
AC_INIT
|
||||
AC_CONFIG_SRCDIR([ssh.c])
|
||||
@ -380,7 +380,7 @@ AC_CHECK_HEADERS(bstring.h crypt.h endian.h floatingpoint.h \
|
||||
netinet/in_systm.h paths.h pty.h readpassphrase.h \
|
||||
rpc/types.h security/pam_appl.h shadow.h stddef.h stdint.h \
|
||||
strings.h sys/bitypes.h sys/bsdtty.h sys/cdefs.h \
|
||||
sys/mman.h sys/select.h sys/stat.h \
|
||||
sys/mman.h sys/pstat.h sys/select.h sys/stat.h \
|
||||
sys/stropts.h sys/sysmacros.h sys/time.h \
|
||||
sys/un.h time.h tmpdir.h ttyent.h usersec.h \
|
||||
util.h utime.h utmp.h utmpx.h)
|
||||
@ -598,7 +598,7 @@ AC_CHECK_FUNCS(arc4random b64_ntop bcopy bindresvport_sa \
|
||||
getaddrinfo getcwd getgrouplist getnameinfo getopt getpeereid\
|
||||
getrlimit getrusage getttyent glob inet_aton inet_ntoa \
|
||||
inet_ntop innetgr login_getcapbool md5_crypt memmove \
|
||||
mkdtemp mmap ngetaddrinfo openpty ogetaddrinfo readpassphrase \
|
||||
mkdtemp mmap ngetaddrinfo openpty ogetaddrinfo pstat readpassphrase \
|
||||
realpath recvmsg rresvport_af sendmsg setdtablesize setegid \
|
||||
setenv seteuid setgroups setlogin setproctitle setresgid setreuid \
|
||||
setrlimit setsid setpcred setvbuf sigaction sigvec snprintf \
|
||||
|
@ -23,15 +23,20 @@
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
RCSID("$Id: bsd-misc.c,v 1.10 2002/07/08 21:09:41 mouring Exp $");
|
||||
RCSID("$Id: bsd-misc.c,v 1.11 2003/01/09 22:53:13 djm Exp $");
|
||||
|
||||
/*
|
||||
* NB. duplicate __progname in case it is an alias for argv[0]
|
||||
* Otherwise it may get clobbered by setproctitle()
|
||||
*/
|
||||
char *get_progname(char *argv0)
|
||||
{
|
||||
#ifdef HAVE___PROGNAME
|
||||
extern char *__progname;
|
||||
|
||||
return __progname;
|
||||
return xstrdup(__progname);
|
||||
#else
|
||||
char *p;
|
||||
|
||||
@ -42,7 +47,8 @@ char *get_progname(char *argv0)
|
||||
p = argv0;
|
||||
else
|
||||
p++;
|
||||
return p;
|
||||
|
||||
return xstrdup(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1,102 +1,250 @@
|
||||
/*
|
||||
* Modified for OpenSSH by Kevin Steves
|
||||
* October 2000
|
||||
* Based on src/backend/utils/misc/pg_status.c from
|
||||
* PostgreSQL Database Management System
|
||||
*
|
||||
* Portions Copyright (c) 1996-2001, The PostgreSQL Global Development Group
|
||||
*
|
||||
* Portions Copyright (c) 1994, The Regents of the University of California
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose, without fee, and without a written agreement
|
||||
* is hereby granted, provided that the above copyright notice and this
|
||||
* paragraph and the following two paragraphs appear in all copies.
|
||||
*
|
||||
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
|
||||
* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
|
||||
* DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Christopher G. Demetriou
|
||||
* All rights reserved.
|
||||
/*--------------------------------------------------------------------
|
||||
* ps_status.c
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Christopher G. Demetriou
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
* Routines to support changing the ps display of PostgreSQL backends
|
||||
* to contain some useful information. Mechanism differs wildly across
|
||||
* platforms.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* $Header: /var/cvs/openssh/openbsd-compat/setproctitle.c,v 1.3 2003/01/09 22:53:13 djm Exp $
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
* various details abducted from various places
|
||||
*--------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.8 2001/11/06 19:21:40 art Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
|
||||
#define SPT_NONE 0
|
||||
#define SPT_PSTAT 1
|
||||
|
||||
#ifndef SPT_TYPE
|
||||
#define SPT_TYPE SPT_NONE
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_SYS_PSTAT_H
|
||||
#include <sys/pstat.h> /* for HP-UX */
|
||||
#endif
|
||||
#ifdef HAVE_PS_STRINGS
|
||||
#include <machine/vmparam.h> /* for old BSD */
|
||||
#include <sys/exec.h>
|
||||
#endif
|
||||
|
||||
#if SPT_TYPE == SPT_PSTAT
|
||||
#include <sys/param.h>
|
||||
#include <sys/pstat.h>
|
||||
#endif /* SPT_TYPE == SPT_PSTAT */
|
||||
extern char **environ;
|
||||
|
||||
#define MAX_PROCTITLE 2048
|
||||
/*------
|
||||
* Alternative ways of updating ps display:
|
||||
*
|
||||
* PS_USE_PSTAT
|
||||
* use the pstat(PSTAT_SETCMD, )
|
||||
* (HPUX)
|
||||
* PS_USE_PS_STRINGS
|
||||
* assign PS_STRINGS->ps_argvstr = "string"
|
||||
* (some BSD systems)
|
||||
* PS_USE_CHANGE_ARGV
|
||||
* assign argv[0] = "string"
|
||||
* (some other BSD systems)
|
||||
* PS_USE_CLOBBER_ARGV
|
||||
* write over the argv and environment area
|
||||
* (most SysV-like systems)
|
||||
* PS_USE_NONE
|
||||
* don't update ps display
|
||||
* (This is the default, as it is safest.)
|
||||
*/
|
||||
#if defined(HAVE_PSTAT) && defined(PSTAT_SETCMD)
|
||||
#define PS_USE_PSTAT
|
||||
#elif defined(HAVE_PS_STRINGS)
|
||||
#define PS_USE_PS_STRINGS
|
||||
#elif defined(BSD) || defined(__bsdi__) || defined(__hurd__)
|
||||
#define PS_USE_CHANGE_ARGV
|
||||
#elif defined(__linux__) || defined(_AIX)
|
||||
#define PS_USE_CLOBBER_ARGV
|
||||
#else
|
||||
#define PS_USE_NONE
|
||||
#endif
|
||||
|
||||
/* Different systems want the buffer padded differently */
|
||||
#if defined(_AIX) || defined(__linux__) || defined(__QNX__) || defined(__svr4__)
|
||||
#define PS_PADDING '\0'
|
||||
#else
|
||||
#define PS_PADDING ' '
|
||||
#endif
|
||||
|
||||
/*
|
||||
* argv clobbering uses existing argv space, all other methods need a buffer
|
||||
*/
|
||||
#ifndef PS_USE_CLOBBER_ARGV
|
||||
static char ps_buffer[256];
|
||||
static const size_t ps_buffer_size = sizeof(ps_buffer);
|
||||
#else /* PS_USE_CLOBBER_ARGV */
|
||||
static char *ps_buffer; /* will point to argv area */
|
||||
static size_t ps_buffer_size; /* space determined at run time */
|
||||
#endif /* PS_USE_CLOBBER_ARGV */
|
||||
|
||||
/* save the original argv[] location here */
|
||||
static int save_argc;
|
||||
static char **save_argv;
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
/*
|
||||
* Set Process Title (SPT) defines. Modeled after sendmail's
|
||||
* SPT type definition strategy.
|
||||
*
|
||||
* SPT_TYPE:
|
||||
*
|
||||
* SPT_NONE: Don't set the process title. Default.
|
||||
* SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific.
|
||||
* Call this to update the ps status display to a fixed prefix plus an
|
||||
* indication of what you're currently doing passed in the argument.
|
||||
*/
|
||||
|
||||
void
|
||||
setproctitle(const char *fmt, ...)
|
||||
{
|
||||
#if SPT_TYPE != SPT_NONE
|
||||
va_list ap;
|
||||
|
||||
char buf[MAX_PROCTITLE];
|
||||
size_t used;
|
||||
|
||||
#if SPT_TYPE == SPT_PSTAT
|
||||
#ifdef PS_USE_PSTAT
|
||||
union pstun pst;
|
||||
#endif /* SPT_TYPE == SPT_PSTAT */
|
||||
#endif
|
||||
#ifndef PS_USE_NONE
|
||||
ssize_t used;
|
||||
va_list ap;
|
||||
|
||||
/* no ps display if you didn't call save_ps_display_args() */
|
||||
if (save_argv == NULL)
|
||||
return;
|
||||
#ifdef PS_USE_CLOBBER_ARGV
|
||||
/* If ps_buffer is a pointer, it might still be null */
|
||||
if (ps_buffer == NULL)
|
||||
return;
|
||||
#endif /* PS_USE_CLOBBER_ARGV */
|
||||
|
||||
/*
|
||||
* Overwrite argv[] to point at appropriate space, if needed
|
||||
*/
|
||||
#ifdef PS_USE_CHANGE_ARGV
|
||||
save_argv[0] = ps_buffer;
|
||||
save_argv[1] = NULL;
|
||||
#endif /* PS_USE_CHANGE_ARGV */
|
||||
|
||||
#ifdef PS_USE_CLOBBER_ARGV
|
||||
save_argv[1] = NULL;
|
||||
#endif /* PS_USE_CLOBBER_ARGV */
|
||||
|
||||
/*
|
||||
* Make fixed prefix of ps display.
|
||||
*/
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL) {
|
||||
used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname);
|
||||
if (used >= MAX_PROCTITLE)
|
||||
used = MAX_PROCTITLE - 1;
|
||||
(void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap);
|
||||
} else
|
||||
(void)snprintf(buf, MAX_PROCTITLE, "%s", __progname);
|
||||
if (fmt == NULL)
|
||||
snprintf(ps_buffer, ps_buffer_size, "%s", __progname);
|
||||
else {
|
||||
used = snprintf(ps_buffer, ps_buffer_size, "%s: ", __progname);
|
||||
if (used == -1 || used >= ps_buffer_size)
|
||||
used = ps_buffer_size;
|
||||
vsnprintf(ps_buffer + used, ps_buffer_size - used, fmt, ap);
|
||||
}
|
||||
va_end(ap);
|
||||
used = strlen(buf);
|
||||
|
||||
#if SPT_TYPE == SPT_PSTAT
|
||||
pst.pst_command = buf;
|
||||
pstat(PSTAT_SETCMD, pst, used, 0, 0);
|
||||
#endif /* SPT_TYPE == SPT_PSTAT */
|
||||
#if 0
|
||||
error("XXXXXXXXX %s", __progname);
|
||||
error("XXXXXXXXX %d", ps_buffer_size);
|
||||
error("XXXXXXXXX %s", ps_buffer);
|
||||
#endif
|
||||
|
||||
#endif /* SPT_TYPE != SPT_NONE */
|
||||
#ifdef PS_USE_PSTAT
|
||||
pst.pst_command = ps_buffer;
|
||||
pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
|
||||
#endif /* PS_USE_PSTAT */
|
||||
|
||||
#ifdef PS_USE_PS_STRINGS
|
||||
PS_STRINGS->ps_nargvstr = 1;
|
||||
PS_STRINGS->ps_argvstr = ps_buffer;
|
||||
#endif /* PS_USE_PS_STRINGS */
|
||||
|
||||
#ifdef PS_USE_CLOBBER_ARGV
|
||||
/* pad unused memory */
|
||||
used = strlen(ps_buffer);
|
||||
memset(ps_buffer + used, PS_PADDING, ps_buffer_size - used);
|
||||
#endif /* PS_USE_CLOBBER_ARGV */
|
||||
|
||||
#endif /* PS_USE_NONE */
|
||||
}
|
||||
|
||||
#endif /* HAVE_SETPROCTITLE */
|
||||
|
||||
/*
|
||||
* Call this early in startup to save the original argc/argv values.
|
||||
*
|
||||
* argv[] will not be overwritten by this routine, but may be overwritten
|
||||
* during setproctitle. Also, the physical location of the environment
|
||||
* strings may be moved, so this should be called before any code that
|
||||
* might try to hang onto a getenv() result.
|
||||
*/
|
||||
void
|
||||
compat_init_setproctitle(int argc, char *argv[])
|
||||
{
|
||||
#ifdef PS_USE_CLOBBER_ARGV
|
||||
char *end_of_area = NULL;
|
||||
char **new_environ;
|
||||
int i;
|
||||
#endif
|
||||
|
||||
save_argc = argc;
|
||||
save_argv = argv;
|
||||
|
||||
#ifdef PS_USE_CLOBBER_ARGV
|
||||
/*
|
||||
* If we're going to overwrite the argv area, count the available
|
||||
* space. Also move the environment to make additional room.
|
||||
*/
|
||||
|
||||
/*
|
||||
* check for contiguous argv strings
|
||||
*/
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (i == 0 || end_of_area + 1 == argv[i])
|
||||
end_of_area = argv[i] + strlen(argv[i]);
|
||||
}
|
||||
|
||||
/* probably can't happen? */
|
||||
if (end_of_area == NULL) {
|
||||
ps_buffer = NULL;
|
||||
ps_buffer_size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* check for contiguous environ strings following argv
|
||||
*/
|
||||
for (i = 0; environ[i] != NULL; i++) {
|
||||
if (end_of_area + 1 == environ[i])
|
||||
end_of_area = environ[i] + strlen(environ[i]);
|
||||
}
|
||||
|
||||
ps_buffer = argv[0];
|
||||
ps_buffer_size = end_of_area - argv[0] - 1;
|
||||
|
||||
/*
|
||||
* Duplicate and move the environment out of the way
|
||||
*/
|
||||
new_environ = malloc(sizeof(char *) * (i + 1));
|
||||
for (i = 0; environ[i] != NULL; i++)
|
||||
new_environ[i] = strdup(environ[i]);
|
||||
new_environ[i] = NULL;
|
||||
environ = new_environ;
|
||||
#endif /* PS_USE_CLOBBER_ARGV */
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: setproctitle.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */
|
||||
/* $Id: setproctitle.h,v 1.3 2003/01/09 22:53:13 djm Exp $ */
|
||||
|
||||
#ifndef _BSD_SETPROCTITLE_H
|
||||
#define _BSD_SETPROCTITLE_H
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
void setproctitle(const char *fmt, ...);
|
||||
void compat_init_setproctitle(int argc, char *argv[]);
|
||||
#endif
|
||||
|
||||
#endif /* _BSD_SETPROCTITLE_H */
|
||||
|
11
session.c
11
session.c
@ -2002,13 +2002,22 @@ session_tty_list(void)
|
||||
{
|
||||
static char buf[1024];
|
||||
int i;
|
||||
char *cp;
|
||||
|
||||
buf[0] = '\0';
|
||||
for (i = 0; i < MAX_SESSIONS; i++) {
|
||||
Session *s = &sessions[i];
|
||||
if (s->used && s->ttyfd != -1) {
|
||||
|
||||
if (strncmp(s->tty, "/dev/", 5) != 0) {
|
||||
cp = strrchr(s->tty, '/');
|
||||
cp = (cp == NULL) ? s->tty : cp + 1;
|
||||
} else
|
||||
cp = s->tty + 5;
|
||||
|
||||
if (buf[0] != '\0')
|
||||
strlcat(buf, ",", sizeof buf);
|
||||
strlcat(buf, strrchr(s->tty, '/') + 1, sizeof buf);
|
||||
strlcat(buf, cp, sizeof buf);
|
||||
}
|
||||
}
|
||||
if (buf[0] == '\0')
|
||||
|
10
sshd.c
10
sshd.c
@ -827,9 +827,17 @@ main(int ac, char **av)
|
||||
__progname = get_progname(av[0]);
|
||||
init_rng();
|
||||
|
||||
/* Save argv. */
|
||||
/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
|
||||
saved_argc = ac;
|
||||
saved_argv = av;
|
||||
saved_argv = xmalloc(sizeof(*saved_argv) * ac);
|
||||
for (i = 0; i < ac; i++)
|
||||
saved_argv[i] = xstrdup(av[i]);
|
||||
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
/* Prepare for later setproctitle emulation */
|
||||
compat_init_setproctitle(ac, av);
|
||||
#endif
|
||||
|
||||
/* Initialize configuration options to their default values. */
|
||||
initialize_server_options(&options);
|
||||
|
Loading…
Reference in New Issue
Block a user