Date: Wed, 12 Jan 2000 11:56:29 -0500 (EST) From: ajk@waterspout.com To: FreeBSD-gnats-submit@freebsd.org Cc: George Lebl <jirka@5z.com>, John Ellis <johne@bellatlantic.net>, Michael Zucchi <mzucchi@denr.sa.gov.au>, Miguel de Icaza <miguel@gnu.org>, Timur Bakeyev <timur@gnu.org> Subject: ports/16081: [PATCH] utmp, wtmp, lastlog support for gnome-terminal Message-ID: <200001121656.LAA67226@tsunami.waterspout.com>
next in thread | raw e-mail | index | archive | help
>Number: 16081 >Category: ports >Synopsis: [PATCH] utmp, wtmp, lastlog support for gnome-terminal >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jan 12 09:00:01 PST 2000 >Closed-Date: >Last-Modified: >Originator: Andrew J. Korty >Release: FreeBSD 4.0-CURRENT i386 >Organization: Waterspout Communications >Environment: FreeBSD tempest.waterspout.com 4.0-CURRENT FreeBSD 4.0-CURRENT #24: Sat Dec 4 08:11:45 EST 1999 root@tempest.waterspout.com:/usr/src/sys/compile/TEMPEST i386 >Description: The utmp and wtmp support gnome-terminal is broken, and lastlog support is nonexistent. The gnome-pty-helper program uses seteuid() to give up root privileges but tries to use setuid() to get them back. The patches below fix that problem and add lastlog support. >How-To-Repeat: Run gnome-terminal. >Fix: Apply the following patches to the gnomelibs and gnomecore distributions and reinstall gnome-pty-helper and gnome-terminal. Note that gnome-pty-helper also needs to be setuid-root, not the default, for these features to work. ------- begin gnomelibs patch --- zvt/gnome-pty-helper.c.orig Fri Jan 7 12:42:13 2000 +++ zvt/gnome-pty-helper.c Wed Jan 12 10:25:16 2000 @@ -319,7 +319,7 @@ } static int -open_ptys (int utmp, int wtmp) +open_ptys (int utmp, int wtmp, int lastlog) { char *term_name; int status, master_pty, slave_pty; @@ -486,8 +486,13 @@ #endif status = openpty (&master_pty, &slave_pty, term_name, &term, NULL); +#ifdef HAVE_SETEUID + seteuid(savedUid); + setegid(savedGid); +#else setuid(savedUid); setgid(savedGid); +#endif if (status == -1){ result = 0; @@ -509,8 +514,8 @@ exit (0); } - if (utmp || wtmp){ - p->data = update_dbs (utmp, wtmp, login_name, display_name, term_name); + if (utmp || wtmp || lastlog){ + p->data = update_dbs (utmp, wtmp, lastlog, login_name, display_name, term_name); } return 1; @@ -664,19 +669,35 @@ switch (op){ case GNOME_PTY_OPEN_PTY_UTMP: - open_ptys (1, 0); + open_ptys (1, 0, 0); break; case GNOME_PTY_OPEN_PTY_UWTMP: - open_ptys (1, 1); + open_ptys (1, 1, 0); break; case GNOME_PTY_OPEN_PTY_WTMP: - open_ptys (0, 1); + open_ptys (0, 1, 0); break; + case GNOME_PTY_OPEN_PTY_LASTLOG: + open_ptys (0, 0, 1); + break; + + case GNOME_PTY_OPEN_PTY_LASTLOGUTMP: + open_ptys (1, 0, 1); + break; + + case GNOME_PTY_OPEN_PTY_LASTLOGUWTMP: + open_ptys (1, 1, 1); + break; + + case GNOME_PTY_OPEN_PTY_LASTLOGWTMP: + open_ptys (0, 1, 1); + break; + case GNOME_PTY_OPEN_NO_DB_UPDATE: - open_ptys (0, 0); + open_ptys (0, 0, 0); break; case GNOME_PTY_CLOSE_PTY: --- zvt/gnome-pty.h.orig Wed Jan 12 10:22:01 2000 +++ zvt/gnome-pty.h Wed Jan 12 10:35:06 2000 @@ -5,12 +5,16 @@ GNOME_PTY_OPEN_PTY_UTMP = 1, GNOME_PTY_OPEN_PTY_UWTMP, GNOME_PTY_OPEN_PTY_WTMP, + GNOME_PTY_OPEN_PTY_LASTLOG, + GNOME_PTY_OPEN_PTY_LASTLOGUTMP, + GNOME_PTY_OPEN_PTY_LASTLOGUWTMP, + GNOME_PTY_OPEN_PTY_LASTLOGWTMP, GNOME_PTY_OPEN_NO_DB_UPDATE, GNOME_PTY_CLOSE_PTY } GnomePtyOps; -void *update_dbs (int utmp, int wtmp, char *login_name, char *display_name, char *term_name); -void *write_login_record (char *login_name, char *display_name, char *term_name, int utmp, int wtmp); +void *update_dbs (int utmp, int wtmp, int lastlog, char *login_name, char *display_name, char *term_name); +void *write_login_record (char *login_name, char *display_name, char *term_name, int utmp, int wtmp, int lastlog); void write_logout_record (void *data, int utmp, int wtmp); #endif --- zvt/gnome-utmp.c.orig Wed Jan 12 07:44:41 2000 +++ zvt/gnome-utmp.c Wed Jan 12 11:24:30 2000 @@ -31,6 +31,11 @@ # include <paths.h> #endif +#ifdef _PATH_LASTLOG +#include <sys/types.h> +#include <sys/uio.h> +#endif /* _PATH_LASTLOG */ + #if defined(HAVE_UTMPX_H) # include <utmpx.h> #endif @@ -165,6 +170,30 @@ } #endif +#ifdef _PATH_LASTLOG +static void +update_lastlog(UTMP *ut) +{ + int fd; + struct iovec *p; + struct iovec iov[3]; + + p = iov; + p->iov_base = (char *)&ut->ut_time; + p->iov_len = sizeof ut->ut_time; + (++p)->iov_base = ut->ut_line; + p->iov_len = sizeof ut->ut_line; + (++p)->iov_base = ut->ut_host; + p->iov_len = sizeof ut->ut_host; + if ((fd = open(_PATH_LASTLOG, O_WRONLY, 0)) >= 0) { + (void) lseek(fd, getuid() * sizeof (struct lastlog), + SEEK_SET); + (void) writev(fd, iov, sizeof iov / sizeof (struct iovec)); + (void) close(fd); + } +} +#endif /* _PATH_LASTLOG */ + void write_logout_record (void *data, int utmp, int wtmp) { @@ -197,7 +226,7 @@ } void * -write_login_record (char *login_name, char *display_name, char *term_name, int utmp, int wtmp) +write_login_record (char *login_name, char *display_name, char *term_name, int utmp, int wtmp, int lastlog) { UTMP *ut; char *pty = term_name; @@ -263,6 +292,11 @@ # endif #endif +#ifdef _PATH_LASTLOG + if (lastlog) + update_lastlog(ut); +#endif /* _PATH_LASTLOG */ + if (utmp) update_utmp (ut); @@ -273,7 +307,7 @@ } void * -update_dbs (int utmp, int wtmp, char *login_name, char *display_name, char *term_name) +update_dbs (int utmp, int wtmp, int lastlog, char *login_name, char *display_name, char *term_name) { - return write_login_record (login_name, display_name, term_name, utmp, wtmp); + return write_login_record (login_name, display_name, term_name, utmp, wtmp, lastlog); } --- zvt/subshell.c.orig Wed Jan 12 10:25:30 2000 +++ zvt/subshell.c Wed Jan 12 11:23:49 2000 @@ -25,6 +25,7 @@ #include "subshell-includes.h" #define ZVT_TERM_DO_UTMP_LOG 1 #define ZVT_TERM_DO_WTMP_LOG 2 +#define ZVT_TERM_DO_LASTLOG 4 /* Pid of the helper SUID process */ static pid_t helper_pid; @@ -260,14 +261,22 @@ op = GNOME_PTY_OPEN_NO_DB_UPDATE; if (update_wutmp & ZVT_TERM_DO_UTMP_LOG){ - if (update_wutmp & ZVT_TERM_DO_WTMP_LOG) + if (update_wutmp & (ZVT_TERM_DO_WTMP_LOG | ZVT_TERM_DO_LASTLOG)) + op = GNOME_PTY_OPEN_PTY_LASTLOGUWTMP; + else if (update_wutmp & ZVT_TERM_DO_WTMP_LOG) op = GNOME_PTY_OPEN_PTY_UWTMP; + else if (update_wutmp & ZVT_TERM_DO_LASTLOG) + op = GNOME_PTY_OPEN_PTY_LASTLOGUTMP; else op = GNOME_PTY_OPEN_PTY_UTMP; - } else { - if (update_wutmp & ZVT_TERM_DO_WTMP_LOG) + } else if (update_wutmp & ZVT_TERM_DO_WTMP_LOG) { + if (update_wutmp & (ZVT_TERM_DO_WTMP_LOG | ZVT_TERM_DO_LASTLOG)) + op = GNOME_PTY_OPEN_PTY_LASTLOGWTMP; + else if (update_wutmp & ZVT_TERM_DO_WTMP_LOG) op = GNOME_PTY_OPEN_PTY_WTMP; - } + } else + if (update_wutmp & ZVT_TERM_DO_LASTLOG) + op = GNOME_PTY_OPEN_PTY_LASTLOG; if (write (helper_socket_protocol [0], &op, sizeof (op)) < 0) return NULL; --- zvt/test-utmp.c.orig Wed Jan 12 10:22:06 2000 +++ zvt/test-utmp.c Wed Jan 12 10:24:21 2000 @@ -8,7 +8,7 @@ main () { void *utmp; - utmp = update_dbs (1, 1, "testlogin", ":0", "/dev/ttyp9"); + utmp = update_dbs (1, 1, 1, "testlogin", ":0", "/dev/ttyp9"); sleep (120); write_logout_record (utmp, 1, 1); return 0; --- zvt/zterm.c.orig Wed Jan 12 10:55:55 2000 +++ zvt/zterm.c Wed Jan 12 10:56:13 2000 @@ -264,7 +264,7 @@ gtk_widget_show (window); /* fork the shell/program */ - switch (zvt_term_forkpty(ZVT_TERM (term), ZVT_TERM_DO_UTMP_LOG | ZVT_TERM_DO_WTMP_LOG)) { + switch (zvt_term_forkpty(ZVT_TERM (term), ZVT_TERM_DO_UTMP_LOG | ZVT_TERM_DO_WTMP_LOG | ZVT_TERM_DO_LASTLOG)) { case -1: perror("ERROR: unable to fork:"); exit(1); --- zvt/zvtterm.h.orig Wed Jan 12 10:36:48 2000 +++ zvt/zvtterm.h Wed Jan 12 10:37:21 2000 @@ -177,6 +177,7 @@ /* options for fork */ #define ZVT_TERM_DO_UTMP_LOG 1 #define ZVT_TERM_DO_WTMP_LOG 2 +#define ZVT_TERM_DO_LASTLOG 4 /* background flag options */ #define ZVT_BACKGROUND_SHADED 0x01 /* shade background image. This must be left as 1 for api compat! */ ------- end gnomelibs patch ------- begin gnomecore patch --- gnome-terminal/gnome-terminal.c.orig Thu Nov 11 19:05:12 1999 +++ gnome-terminal/gnome-terminal.c Wed Jan 12 10:42:50 2000 @@ -507,7 +507,8 @@ cfg->termname = NULL; cfg->terminal_id = 0; - cfg->update_records = ZVT_TERM_DO_UTMP_LOG|ZVT_TERM_DO_WTMP_LOG; + cfg->update_records = ZVT_TERM_DO_UTMP_LOG | ZVT_TERM_DO_WTMP_LOG + | ZVT_TERM_DO_LASTLOG; if (strcasecmp (fore_color, back_color) == 0) /* don't let them set identical foreground and background colors */ @@ -2260,6 +2261,8 @@ cfg->update_records |= ZVT_TERM_DO_UTMP_LOG; if (gnome_config_get_bool ("do_wtmp=true")) cfg->update_records |= ZVT_TERM_DO_WTMP_LOG; + if (gnome_config_get_bool ("do_lastlog=true")) + cfg->update_records |= ZVT_TERM_DO_LASTLOG; termid = gnome_config_get_int("terminal_id=-1"); if (termid!=-1) @@ -2367,6 +2370,7 @@ gnome_config_set_string("window_title", cfg->window_title?cfg->window_title:"Terminal"); gnome_config_set_bool("do_utmp", (cfg->update_records & ZVT_TERM_DO_UTMP_LOG) != 0); gnome_config_set_bool("do_wtmp", (cfg->update_records & ZVT_TERM_DO_WTMP_LOG) != 0); + gnome_config_set_bool("do_lastlog", (cfg->update_records & ZVT_TERM_DO_LASTLOG) != 0); gnome_config_pop_prefix (); g_free (prefix); @@ -2417,8 +2421,10 @@ DONOUTMP_KEY = -10, DOWTMP_KEY = -11, DONOWTMP_KEY = -12, - TITLE_KEY = -13, - TERM_KEY = -14 + DOLASTLOG_KEY = -13, + DONOLASTLOG_KEY = -14, + TITLE_KEY = -15, + TERM_KEY = -16 }; static struct poptOption cb_options [] = { @@ -2462,6 +2468,12 @@ { "nowtmp", '\0', POPT_ARG_NONE, NULL, DONOWTMP_KEY, N_("Do not update wtmp entry"), N_("NOWTMP") }, + + { "lastlog", '\0', POPT_ARG_NONE, NULL, DOLASTLOG_KEY, + N_("Update lastlog entry"), N_("LASTLOG") }, + + { "nolastlog", '\0', POPT_ARG_NONE, NULL, DONOLASTLOG_KEY, + N_("Do not update lastlog entry"), N_("NOLASTLOG") }, { "title", 't', POPT_ARG_STRING, NULL, TITLE_KEY, N_("Set the window title"), N_("TITLE") }, @@ -2538,6 +2550,14 @@ case DONOWTMP_KEY: cfg->update_records_and &= ~ZVT_TERM_DO_WTMP_LOG; cfg->update_records_xor &= ~ZVT_TERM_DO_WTMP_LOG; + break; + case DOLASTLOG_KEY: + cfg->update_records_and &= ~ZVT_TERM_DO_LASTLOG; + cfg->update_records_xor |= ZVT_TERM_DO_LASTLOG; + break; + case DONOLASTLOG_KEY: + cfg->update_records_and &= ~ZVT_TERM_DO_LASTLOG; + cfg->update_records_xor &= ~ZVT_TERM_DO_LASTLOG; break; case TITLE_KEY: cfg->window_title = g_strdup(arg); ------- end gnomecore patch >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001121656.LAA67226>