-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: rxvt-unicode-sixel
action: commit
revision:
path_from:
revision_from: 325d12fbfaed5dd4af0c4e5f84f9308e3c5487a7:
path_to:
revision_to:

git.thebackupbox.net

rxvt-unicode-sixel

git://git.thebackupbox.net/rxvt-unicode-sixel

commit 325d12fbfaed5dd4af0c4e5f84f9308e3c5487a7
Author: Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
Date:   Mon May 30 21:24:43 2011 +0000

    Embed libptytty.

diff --git a/MANIFEST b/MANIFEST

index daa6ad9c4d44717f1f7022f8102bb6235d81c4fb..

index ..f980e5e07c54d55d04e928ec25a05b079717d222 100644

--- a/MANIFEST
+++ b/MANIFEST
@@ -5,13 +5,11 @@ INSTALL
 MANIFEST
 README.configure
 README.FAQ
-update_ptytty
 configure
 configure.ac
 config.sub
 config.guess
 aclocal.m4
-ptytty.m4
 autogen.sh
 config.h.in
 Makefile.in
@@ -49,6 +47,7 @@ src/command.C
 src/command.h
 src/encoding.C
 src/encoding.h
+src/fdpass_wrapper.C
 src/feature.h
 src/hookinc.h
 src/init.C
@@ -60,6 +59,7 @@ src/keyboard.h
 src/main.C
 src/misc.C
 src/optinc.h
+src/ptytty_wrapper.C
 src/rxvtutil.C
 src/rxvtutil.h
 src/rxvttoolkit.C
@@ -85,13 +85,14 @@ src/scrollbar.h
 src/version.h
 src/xdefaults.C

-src/libptytty.h
-src/ptytty_conf.h
-src/ptytty.h
-src/ptytty.C
-src/proxy.C
-src/logging.C
-src/fdpass.C
+libptytty/ptytty.m4
+libptytty/src/libptytty.h
+libptytty/src/ptytty_conf.h
+libptytty/src/ptytty.h
+libptytty/src/ptytty.C
+libptytty/src/proxy.C
+libptytty/src/logging.C
+libptytty/src/fdpass.C

 src/gentables
 src/gencompose
diff --git a/aclocal.m4 b/aclocal.m4

index 205e7cd5bd9cdaa8b55099c42d18a7d842cb812e..

index ..106fac667f705cffd8ae7d880b4ae38f508efcbc 100644

--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,2 +1,2 @@
-m4_include([ptytty.m4])
+m4_include([libptytty/ptytty.m4])

diff --git a/ptytty.m4 b/ptytty.m4
deleted file mode 100644
index 702017c7da16c25b0517fa1a3c3f2b4d130f3aae..0000000000000000000000000000000000000000
--- a/ptytty.m4
+++ /dev/null
@@ -1,450 +0,0 @@
-dnl this file is part of libptytty, do not make local modifications
-dnl http://software.schmorp.de/pkg/libptytty
-
-AC_DEFUN([PTY_CHECK],
-[
-AC_CHECK_HEADERS( \
-  pty.h \
-  util.h \
-  libutil.h \
-  sys/ioctl.h \
-  sys/stropts.h \
-  stropts.h \
-)
-
-AC_CHECK_FUNCS( \
-  revoke \
-  _getpty \
-  getpt \
-  posix_openpt \
-  isastream \
-  setuid \
-  seteuid \
-  setreuid \
-  setresuid \
-)
-
-have_clone=no
-
-AC_MSG_CHECKING(for /dev/ptc)
-if test -e /dev/ptc; then
-  AC_MSG_RESULT(yes)
-  AC_DEFINE(CLONE_DEVICE, "/dev/ptc", [clone device filename])
-  have_clone=yes
-else
-  AC_MSG_RESULT(no)
-fi
-
-case $host in
-  *-*-cygwin*)
-    have_clone=yes
-    AC_DEFINE(CLONE_DEVICE, "/dev/ptmx", [clone device filename])
-    ;;
-  *)
-    AC_MSG_CHECKING(for /dev/ptmx)
-    if test -e /dev/ptmx; then
-      AC_MSG_RESULT(yes)
-      AC_DEFINE(HAVE_DEV_PTMX, 1, [Define to 1 if you have /dev/ptmx])
-      AC_DEFINE(CLONE_DEVICE, "/dev/ptmx", [clone device filename])
-      have_clone=yes
-    else
-      AC_MSG_RESULT(no)
-    fi
-    ;;
-esac
-
-if test x$ac_cv_func_getpt = xyes -o x$ac_cv_func_posix_openpt = xyes -o x$have_clone = xyes; then
-  AC_MSG_CHECKING(for UNIX98 ptys)
-  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>]],
-              [[grantpt(0);unlockpt(0);ptsname(0);]])],
-              [unix98_pty=yes
-               AC_DEFINE(UNIX98_PTY, 1, "")
-               AC_MSG_RESULT(yes)],
-              [AC_MSG_RESULT(no)])
-fi
-
-if test -z "$unix98_pty"; then
-  AC_SEARCH_LIBS(openpty, util, AC_DEFINE(HAVE_OPENPTY, 1, ""))
-fi
-])
-
-AC_DEFUN([UTMP_CHECK],
-[
-support_utmp=yes
-support_wtmp=yes
-support_lastlog=yes
-
-AC_ARG_ENABLE(utmp,
-  [AS_HELP_STRING([--enable-utmp],[enable utmp (utmpx) support])],
-  [if test x$enableval = xyes -o x$enableval = xno; then
-    support_utmp=$enableval
-  fi])
-
-AC_ARG_ENABLE(wtmp,
-  [AS_HELP_STRING([--enable-wtmp],[enable wtmp (wtmpx) support (requires --enable-utmp)])],
-  [if test x$enableval = xyes -o x$enableval = xno; then
-    support_wtmp=$enableval
-  fi])
-
-AC_ARG_ENABLE(lastlog,
-  [AS_HELP_STRING([--enable-lastlog],[enable lastlog support (requires --enable-utmp)])],
-  [if test x$enableval = xyes -o x$enableval = xno; then
-    support_lastlog=$enableval
-  fi])
-
-if test x$support_utmp = xyes; then
-  AC_DEFINE(UTMP_SUPPORT, 1, Define if you want to have utmp/utmpx support)
-fi
-if test x$support_wtmp = xyes; then
-  AC_DEFINE(WTMP_SUPPORT, 1, Define if you want to have wtmp support when utmp/utmpx is enabled)
-fi
-if test x$support_lastlog = xyes; then
-  AC_DEFINE(LASTLOG_SUPPORT, 1, Define if you want to have lastlog support when utmp/utmpx is enabled)
-fi
-
-AC_CHECK_FUNCS( \
-	updwtmp \
-	updwtmpx \
-	updlastlogx \
-)
-
-AC_CHECK_HEADERS(lastlog.h)
-
-dnl# --------------------------------------------------------------------------
-dnl# DO ALL UTMP AND WTMP CHECKING
-dnl# --------------------------------------------------------------------------
-dnl# check for host field in utmp structure
-
-dnl# --------------------------------------------
-AC_CHECK_HEADERS(utmp.h,
-[AC_CACHE_CHECK([for struct utmp], pt_cv_struct_utmp,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <utmp.h>]], [[struct utmp ut;]])],[pt_cv_struct_utmp=yes],[pt_cv_struct_utmp=no])])
-if test x$pt_cv_struct_utmp = xyes; then
-  AC_DEFINE(HAVE_STRUCT_UTMP, 1, Define if utmp.h has struct utmp)
-fi
-]
-
-AC_CACHE_CHECK(for ut_host in utmp struct, pt_cv_struct_utmp_host,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <utmp.h>]], [[struct utmp ut; ut.ut_host;]])],[pt_cv_struct_utmp_host=yes],[pt_cv_struct_utmp_host=no])])
-if test x$pt_cv_struct_utmp_host = xyes; then
-  AC_DEFINE(HAVE_UTMP_HOST, 1, Define if struct utmp contains ut_host)
-fi
-
-AC_CACHE_CHECK(for ut_pid in utmp struct, pt_cv_struct_utmp_pid,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <utmp.h>]], [[struct utmp ut; ut.ut_pid;]])],[pt_cv_struct_utmp_pid=yes],[pt_cv_struct_utmp_pid=no])])
-if test x$pt_cv_struct_utmp_pid = xyes; then
-  AC_DEFINE(HAVE_UTMP_PID, 1, Define if struct utmp contains ut_pid)
-fi
-) dnl# AC_CHECK_HEADERS(utmp.h
-
-dnl# --------------------------------------------
-
-AC_CHECK_HEADERS(utmpx.h,
-[AC_CACHE_CHECK([for struct utmpx], pt_cv_struct_utmpx,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <utmpx.h>]], [[struct utmpx ut;]])],[pt_cv_struct_utmpx=yes],[pt_cv_struct_utmpx=no])])
-if test x$pt_cv_struct_utmpx = xyes; then
-  AC_DEFINE(HAVE_STRUCT_UTMPX, 1, Define if utmpx.h has struct utmpx)
-fi
-]
-
-AC_CACHE_CHECK(for host in utmpx struct, pt_cv_struct_utmpx_host,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <utmpx.h>]], [[struct utmpx utx; utx.ut_host;]])],[pt_cv_struct_utmpx_host=yes],[pt_cv_struct_utmpx_host=no])])
-if test x$pt_cv_struct_utmpx_host = xyes; then
-  AC_DEFINE(HAVE_UTMPX_HOST, 1, Define if struct utmpx contains ut_host)
-fi
-
-AC_CACHE_CHECK(for session in utmpx struct, pt_cv_struct_utmpx_session,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <utmpx.h>]], [[struct utmpx utx; utx.ut_session;]])],[pt_cv_struct_utmpx_session=yes],[pt_cv_struct_utmpx_session=no])])
-if test x$pt_cv_struct_utmpx_session = xyes; then
-  AC_DEFINE(HAVE_UTMPX_SESSION, 1, Define if struct utmpx contains ut_session)
-fi
-) dnl# AC_CHECK_HEADERS(utmpx.h
-
-dnl# --------------------------------------------------------------------------
-dnl# check for struct lastlog
-AC_CACHE_CHECK(for struct lastlog, pt_cv_struct_lastlog,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <utmp.h>
-#ifdef HAVE_LASTLOG_H
-#include <lastlog.h>
-#endif
-]], [[struct lastlog ll;]])],[pt_cv_struct_lastlog=yes],[pt_cv_struct_lastlog=no])])
-if test x$pt_cv_struct_lastlog = xyes; then
-  AC_DEFINE(HAVE_STRUCT_LASTLOG, 1, Define if utmp.h or lastlog.h has struct lastlog)
-fi
-
-dnl# check for struct lastlogx
-AC_CACHE_CHECK(for struct lastlogx, pt_cv_struct_lastlogx,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <utmpx.h>
-#ifdef HAVE_LASTLOG_H
-#include <lastlog.h>
-#endif
-]], [[struct lastlogx ll;]])],[pt_cv_struct_lastlogx=yes],[pt_cv_struct_lastlogx=no])])
-if test x$pt_cv_struct_lastlogx = xyes; then
-  AC_DEFINE(HAVE_STRUCT_LASTLOGX, 1, Define if utmpx.h or lastlog.h has struct lastlogx)
-fi
-
-dnl# --------------------------------------------------------------------------
-dnl# FIND FILES
-dnl# --------------------------------------------------------------------------
-
-dnl# find utmp
-AC_CACHE_CHECK(where utmp is located, pt_cv_path_utmp,
-[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <utmp.h>
-#include <errno.h>
-int main()
-{
-    char **u, *utmplist[] = {
-    "/var/run/utmp", "/var/adm/utmp", "/etc/utmp", "/usr/etc/utmp", "/usr/adm/utmp", NULL };
-    FILE *a, *f=fopen("conftestval", "w");
-    if (!f) exit(1);
-#ifdef UTMP_FILE
-    fprintf(f, "%s\n", UTMP_FILE);
-    exit(0);
-#endif
-#ifdef _PATH_UTMP
-    fprintf(f, "%s\n", _PATH_UTMP);
-    exit(0);
-#endif
-    for (u = utmplist; *u; u++) {
-	if ((a = fopen(*u, "r")) != NULL || errno == EACCES) {
-	    fprintf(f, "%s\n", *u);
-	    exit(0);
-	}
-    }
-    exit(0);
-}]])],[pt_cv_path_utmp=`cat conftestval`],[pt_cv_path_utmp=],[dnl
-  AC_MSG_WARN(Define UTMP_FILE in config.h manually)])])
-if test x$pt_cv_path_utmp != x; then
-  AC_DEFINE_UNQUOTED(UTMP_FILE, "$pt_cv_path_utmp", Define location of utmp)
-fi
-
-dnl# --------------------------------------------------------------------------
-
-dnl# find wtmp
-AC_CACHE_CHECK(where wtmp is located, pt_cv_path_wtmp,
-[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#ifdef HAVE_UTMP_H
-#include <utmp.h>
-#endif
-#include <errno.h>
-int main()
-{
-    char **w, *wtmplist[] = {
-    "/var/log/wtmp", "/var/adm/wtmp", "/etc/wtmp", "/usr/etc/wtmp", "/usr/adm/wtmp", NULL };
-    FILE *a, *f=fopen("conftestval", "w");
-    if (!f) exit(1);
-#ifdef WTMP_FILE
-    fprintf(f, "%s\n", WTMP_FILE);
-    exit(0);
-#endif
-#ifdef _PATH_WTMP
-    fprintf(f, "%s\n", _PATH_WTMP);
-    exit(0);
-#endif
-    for (w = wtmplist; *w; w++) {
-	if ((a = fopen(*w, "r")) != NULL || errno == EACCES) {
-	    fprintf(f, "%s\n", *w);
-	    exit(0);
-	}
-    }
-    exit(0);
-}]])],[pt_cv_path_wtmp=`cat conftestval`],[pt_cv_path_wtmp=],[dnl
-  AC_MSG_WARN(Define WTMP_FILE in config.h manually)])])
-if test x$pt_cv_path_wtmp != x; then
-  AC_DEFINE_UNQUOTED(WTMP_FILE, "$pt_cv_path_wtmp", Define location of wtmp)
-fi
-dnl# --------------------------------------------------------------------------
-
-dnl# find wtmpx
-AC_CACHE_CHECK(where wtmpx is located, pt_cv_path_wtmpx,
-[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
-#include <stdlib.h>
-#ifdef HAVE_UTMPX_H
-#include <utmpx.h>
-#endif
-#include <errno.h>
-int main()
-{
-    char **w, *wtmplist[] = {
-    "/var/log/wtmpx", "/var/adm/wtmpx", NULL };
-    FILE *a, *f=fopen("conftestval", "w");
-    if (!f) exit(1);
-#ifdef WTMPX_FILE
-    fprintf(f, "%s\n", WTMPX_FILE);
-    exit(0);
-#endif
-#ifdef _PATH_WTMPX
-    fprintf(f, "%s\n", _PATH_WTMPX);
-    exit(0);
-#endif
-    for (w = wtmplist; *w; w++) {
-	if ((a = fopen(*w, "r")) != NULL || errno == EACCES) {
-	    fprintf(f, "%s\n", *w);
-	    exit(0);
-	}
-    }
-    exit(0);
-}]])],[pt_cv_path_wtmpx=`cat conftestval`],[pt_cv_path_wtmpx=],[dnl
-  AC_MSG_WARN(Define WTMPX_FILE in config.h manually)])])
-if test x$pt_cv_path_wtmpx != x; then
-  AC_DEFINE_UNQUOTED(WTMPX_FILE, "$pt_cv_path_wtmpx", Define location of wtmpx)
-fi
-dnl# --------------------------------------------------------------------------
-
-dnl# find lastlog
-AC_CACHE_CHECK(where lastlog is located, pt_cv_path_lastlog,
-[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#ifdef HAVE_UTMPX_H
-#include <utmpx.h>
-#elif defined(HAVE_UTMP_H)
-#include <utmp.h>
-#endif
-#ifdef HAVE_LASTLOG_H
-#include <lastlog.h>
-#endif
-#include <errno.h>
-int main()
-{
-    char **w, *lastloglist[] = { "/var/log/lastlog", NULL };
-    FILE *a, *f=fopen("conftestval", "w");
-    if (!f) exit(1);
-#ifdef LASTLOG_FILE
-    fprintf(f, "%s\n", LASTLOG_FILE);
-    exit(0);
-#endif
-#ifdef _PATH_LASTLOG
-    fprintf(f, "%s\n", _PATH_LASTLOG);
-    exit(0);
-#endif
-    for (w = lastloglist; *w; w++) {
-	if ((a = fopen(*w, "r")) != NULL || errno == EACCES) {
-	    fprintf(f, "%s\n", *w);
-	    exit(0);
-	}
-    }
-    exit(0);
-}]])],[pt_cv_path_lastlog=`cat conftestval`],[pt_cv_path_lastlog=],[dnl
-  AC_MSG_WARN(Define LASTLOG_FILE in config.h manually)])])
-if test x$pt_cv_path_lastlog != x; then
-  AC_DEFINE_UNQUOTED(LASTLOG_FILE, "$pt_cv_path_lastlog", Define location of lastlog)
-fi
-dnl# --------------------------------------------------------------------------
-
-dnl# find lastlogx
-AC_CACHE_CHECK(where lastlogx is located, pt_cv_path_lastlogx,
-[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
-#include <stdlib.h>
-#ifdef HAVE_UTMPX_H
-#include <utmpx.h>
-#endif
-#include <errno.h>
-int main()
-{
-    char **w, *wtmplist[] = { "/var/log/lastlogx", "/var/adm/lastlogx", NULL };
-    FILE *a, *f=fopen("conftestval", "w");
-    if (!f) exit(1);
-#ifdef LASTLOGX_FILE
-    fprintf(f, "%s\n", LASTLOGX_FILE);
-    exit(0);
-#endif
-#ifdef _PATH_LASTLOGX
-    fprintf(f, "%s\n", _PATH_LASTLOGX);
-    exit(0);
-#endif
-    for (w = wtmplist; *w; w++) {
-	if ((a = fopen(*w, "r")) != NULL || errno == EACCES) {
-	    fprintf(f, "%s\n", *w);
-	    exit(0);
-	}
-    }
-    exit(0);
-}]])],[pt_cv_path_lastlogx=`cat conftestval`],[pt_cv_path_lastlogx=],[dnl
-  AC_MSG_WARN(Define LASTLOGX_FILE in config.h manually)])])
-if test x$pt_cv_path_lastlogx != x; then
-  AC_DEFINE_UNQUOTED(LASTLOGX_FILE, "$pt_cv_path_lastlogx", Define location of lastlogx)
-fi
-])
-
-AC_DEFUN([SCM_RIGHTS_CHECK],
-[
-AC_CACHE_CHECK(for unix-compliant filehandle passing ability, pt_cv_can_pass_fds,
-[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-#include <cstddef> // broken bsds (is that redundant?) need this
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-]], [[
-{
-  msghdr msg;
-  iovec iov;
-  char buf [100];
-  char data = 0;
-
-  iov.iov_base = &data;
-  iov.iov_len  = 1;
-
-  msg.msg_iov        = &iov;
-  msg.msg_iovlen     = 1;
-  msg.msg_control    = buf;
-  msg.msg_controllen = sizeof buf;
-
-  cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
-  cmsg->cmsg_level = SOL_SOCKET;
-  cmsg->cmsg_type  = SCM_RIGHTS;
-  cmsg->cmsg_len   = 100;
-
-  *(int *)CMSG_DATA (cmsg) = 5;
-
-  return sendmsg (3, &msg, 0);
-}
-]])],[pt_cv_can_pass_fds=yes],[pt_cv_can_pass_fds=no])])
-if test x$pt_cv_can_pass_fds = xyes; then
-   AC_DEFINE(HAVE_UNIX_FDPASS, 1, Define if sys/socket.h defines the necessary macros/functions for file handle passing)
-else
-   AC_MSG_ERROR([libptytty requires unix-compliant filehandle passing ability])
-fi
-])
-
-AC_DEFUN([TTY_GROUP_CHECK],
-[
-AC_CACHE_CHECK([for tty group], pt_cv_tty_group,
-[AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <grp.h>
-
-int main()
-{
-  struct stat st;
-  struct group *gr;
-  char *tty;
-  gr = getgrnam("tty");
-  tty = ttyname(0);
-  if (gr != 0
-      && tty != 0
-      && (stat(tty, &st)) == 0
-      && st.st_gid == gr->gr_gid)
-    return 0;
-  else
-    return 1;
-}]])],[pt_cv_tty_group=yes],[pt_cv_tty_group=no],[pt_cv_tty_group=no])])
-if test x$pt_cv_tty_group = xyes; then
-  AC_DEFINE(TTY_GID_SUPPORT, 1, "")
-fi])
-
diff --git a/src/Makefile.in b/src/Makefile.in

index d811b7907acb1d2863c5c23fccea746627fd2843..

index ..be7f84997ae8e79bddb92dc6bd337d6c3f169c64 100644

--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -21,7 +21,7 @@ DEFS = @DEFS@
 LIBS = @LIBS@
 XINC = @X_CFLAGS@ @AFTERIMAGE_CFLAGS@ @PIXBUF_CFLAGS@
 XLIB = @X_LIBS@ @AFTERIMAGE_LIBS@ -lX11 @X_EXTRA_LIBS@ @PIXBUF_LIBS@
-COMPILE = $(CXX) -I.. -I$(srcdir) -I. -I$(srcdir)/../libev -I$(srcdir)/../libecb $(DEFS) $(CPPFLAGS) $(CXXFLAGS) $(XINC)
+COMPILE = $(CXX) -I.. -I$(srcdir) -I. -I$(srcdir)/../libev -I$(srcdir)/../libptytty/src -I$(srcdir)/../libecb $(DEFS) $(CPPFLAGS) $(CXXFLAGS) $(XINC)
 LINK = @LINKER@ $(LDFLAGS)
 EXEEXT = @EXEEXT@
 PERLFLAGS = @PERLFLAGS@
@@ -34,11 +34,11 @@ first_rule: all
 dummy:

 COMMON = \
-	background.o command.o rxvtfont.o init.o logging.o main.o misc.o \
-	ptytty.o proxy.o screen.o scrollbar.o scrollbar-next.o scrollbar-rxvt.o \
+	background.o command.o rxvtfont.o init.o main.o misc.o \
+	screen.o scrollbar.o scrollbar-next.o scrollbar-rxvt.o \
 	scrollbar-xterm.o scrollbar-plain.o xdefaults.o encoding.o \
 	rxvttoolkit.o rxvtutil.o keyboard.o \
-	fdpass.o ev_cpp.o @PERL_O@
+	ev_cpp.o fdpass_wrapper.o ptytty_wrapper.o @PERL_O@

 COMMON_DAEMON = rxvtdaemon.o

@@ -67,8 +67,8 @@ rxvt: rxvt.o $(COMMON)
 rxvtd: rxvtd.o $(COMMON) $(COMMON_DAEMON)
 	$(LINK) -o $@ rxvtd.o $(COMMON) $(COMMON_DAEMON) $(LIBS) $(XLIB) $(PERLLIB)

-rxvtc: rxvtc.o $(COMMON_DAEMON) fdpass.o
-	$(LINK) -o $@ rxvtc.o $(COMMON_DAEMON) fdpass.o $(LIBS)
+rxvtc: rxvtc.o $(COMMON_DAEMON) fdpass_wrapper.o
+	$(LINK) -o $@ rxvtc.o $(COMMON_DAEMON) fdpass_wrapper.o $(LIBS)

 #-------------------------------------------------------------------------

@@ -121,18 +121,20 @@ rxvtperl.o: rxvtperl.C perlxsi.c
 	$(COMPILE) $(PERLFLAGS) -DLIBDIR="\"$(libdir)/urxvt\"" -c $<

 depend:
-	makedepend -f Makefile.in -I. -I.. -I../libev -Y *.C >/dev/null 2>&1
+	makedepend -f Makefile.in -I. -I.. -I../libev -I../libptytty/src -Y *.C >/dev/null 2>&1

 # DO NOT DELETE: nice dependency list follows

 background.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 background.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h
-background.o: ../libev/ev.h callback.h scrollbar.h salloc.h libptytty.h
-background.o: rxvtperl.h hookinc.h rsinc.h optinc.h
+background.o: ../libev/ev.h callback.h scrollbar.h salloc.h
+background.o: ../libptytty/src/libptytty.h rxvtperl.h hookinc.h rsinc.h
+background.o: optinc.h
 command.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 command.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-command.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-command.o: rsinc.h optinc.h version.h command.h keyboard.h
+command.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+command.o: rxvtperl.h hookinc.h rsinc.h optinc.h version.h command.h
+command.o: keyboard.h
 encoding.o: ../config.h encoding.h rxvtutil.h table/iso8859_1.h
 encoding.o: table/iso8859_15.h table/iso8859_2.h table/iso8859_3.h
 encoding.o: table/iso8859_4.h table/iso8859_5.h table/iso8859_6.h
@@ -150,84 +152,86 @@ encoding.o: table/jis0212_1990_0.h table/jis0213_1.h table/jis0213_2.h
 encoding.o: table/compose.h table/category.h
 ev_cpp.o: ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h ../libev/ev.c
 ev_cpp.o: ../libev/ev_vars.h ../libev/ev_epoll.c ../libev/ev_select.c
-fdpass.o: ../config.h libptytty.h
+fdpass_wrapper.o: ../libptytty/src/fdpass.C ../config.h
+fdpass_wrapper.o: ../libptytty/src/libptytty.h
 init.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 init.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-init.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-init.o: rsinc.h optinc.h init.h keyboard.h
+init.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+init.o: rxvtperl.h hookinc.h rsinc.h optinc.h init.h keyboard.h
 keyboard.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 keyboard.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-keyboard.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-keyboard.o: rsinc.h optinc.h keyboard.h command.h
-logging.o: ../config.h ptytty.h libptytty.h ptytty_conf.h rxvt.h feature.h
-logging.o: encoding.h rxvtutil.h rxvtfont.h rxvttoolkit.h ev_cpp.h
-logging.o: ../libev/ev++.h ../libev/ev.h callback.h scrollbar.h salloc.h
-logging.o: rxvtperl.h hookinc.h rsinc.h optinc.h
+keyboard.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+keyboard.o: rxvtperl.h hookinc.h rsinc.h optinc.h keyboard.h command.h
 main.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 main.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-main.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-main.o: rsinc.h optinc.h init.h keyboard.h
+main.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+main.o: rxvtperl.h hookinc.h rsinc.h optinc.h init.h keyboard.h
 misc.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 misc.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-misc.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-misc.o: rsinc.h optinc.h
-proxy.o: ../config.h ptytty.h libptytty.h ptytty_conf.h rxvt.h feature.h
-proxy.o: encoding.h rxvtutil.h rxvtfont.h rxvttoolkit.h ev_cpp.h
-proxy.o: ../libev/ev++.h ../libev/ev.h callback.h scrollbar.h salloc.h
-proxy.o: rxvtperl.h hookinc.h rsinc.h optinc.h
-ptytty.o: ../config.h ptytty.h libptytty.h ptytty_conf.h rxvt.h feature.h
-ptytty.o: encoding.h rxvtutil.h rxvtfont.h rxvttoolkit.h ev_cpp.h
-ptytty.o: ../libev/ev++.h ../libev/ev.h callback.h scrollbar.h salloc.h
-ptytty.o: rxvtperl.h hookinc.h rsinc.h optinc.h
+misc.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+misc.o: rxvtperl.h hookinc.h rsinc.h optinc.h
+ptytty_wrapper.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h
+ptytty_wrapper.o: rxvtfont.h rxvttoolkit.h ev_cpp.h ../libev/ev++.h
+ptytty_wrapper.o: ../libev/ev.h callback.h scrollbar.h salloc.h
+ptytty_wrapper.o: ../libptytty/src/libptytty.h rxvtperl.h hookinc.h rsinc.h
+ptytty_wrapper.o: optinc.h ../libptytty/src/logging.C
+ptytty_wrapper.o: ../libptytty/src/ptytty.h ../libptytty/src/ptytty_conf.h
+ptytty_wrapper.o: ../libptytty/src/proxy.C ../libptytty/src/ptytty.C
 rxvt.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 rxvt.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-rxvt.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-rxvt.o: rsinc.h optinc.h
-rxvtc.o: ../config.h rxvtdaemon.h rxvtutil.h libptytty.h
+rxvt.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+rxvt.o: rxvtperl.h hookinc.h rsinc.h optinc.h
+rxvtc.o: ../config.h rxvtdaemon.h rxvtutil.h ../libptytty/src/libptytty.h
 rxvtd.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 rxvtd.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-rxvtd.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-rxvtd.o: rsinc.h optinc.h rxvtdaemon.h
+rxvtd.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+rxvtd.o: rxvtperl.h hookinc.h rsinc.h optinc.h rxvtdaemon.h
 rxvtdaemon.o: rxvtdaemon.h rxvtutil.h
 rxvtfont.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 rxvtfont.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-rxvtfont.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-rxvtfont.o: rsinc.h optinc.h table/linedraw.h
+rxvtfont.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+rxvtfont.o: rxvtperl.h hookinc.h rsinc.h optinc.h table/linedraw.h
 rxvtperl.o: ../config.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
 rxvtperl.o: rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h rxvttoolkit.h
-rxvtperl.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-rxvtperl.o: rsinc.h optinc.h keyboard.h perlxsi.c iom_perl.h
+rxvtperl.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+rxvtperl.o: rxvtperl.h hookinc.h rsinc.h optinc.h keyboard.h perlxsi.c
+rxvtperl.o: iom_perl.h
 rxvttoolkit.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 rxvttoolkit.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h
-rxvttoolkit.o: ../libev/ev.h callback.h scrollbar.h salloc.h libptytty.h
-rxvttoolkit.o: rxvtperl.h hookinc.h rsinc.h optinc.h
+rxvttoolkit.o: ../libev/ev.h callback.h scrollbar.h salloc.h
+rxvttoolkit.o: ../libptytty/src/libptytty.h rxvtperl.h hookinc.h rsinc.h
+rxvttoolkit.o: optinc.h
 rxvtutil.o: rxvtutil.h
 salloc.o: salloc.h
 screen.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 screen.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-screen.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-screen.o: rsinc.h optinc.h salloc.C
+screen.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+screen.o: rxvtperl.h hookinc.h rsinc.h optinc.h salloc.C
 scrollbar-next.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h
 scrollbar-next.o: rxvtfont.h rxvttoolkit.h ev_cpp.h ../config.h
 scrollbar-next.o: ../libev/ev++.h ../libev/ev.h callback.h scrollbar.h
-scrollbar-next.o: salloc.h libptytty.h rxvtperl.h hookinc.h rsinc.h optinc.h
+scrollbar-next.o: salloc.h ../libptytty/src/libptytty.h rxvtperl.h hookinc.h
+scrollbar-next.o: rsinc.h optinc.h
 scrollbar-plain.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h
 scrollbar-plain.o: rxvtfont.h rxvttoolkit.h ev_cpp.h ../config.h
 scrollbar-plain.o: ../libev/ev++.h ../libev/ev.h callback.h scrollbar.h
-scrollbar-plain.o: salloc.h libptytty.h rxvtperl.h hookinc.h rsinc.h optinc.h
+scrollbar-plain.o: salloc.h ../libptytty/src/libptytty.h rxvtperl.h hookinc.h
+scrollbar-plain.o: rsinc.h optinc.h
 scrollbar-rxvt.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h
 scrollbar-rxvt.o: rxvtfont.h rxvttoolkit.h ev_cpp.h ../config.h
 scrollbar-rxvt.o: ../libev/ev++.h ../libev/ev.h callback.h scrollbar.h
-scrollbar-rxvt.o: salloc.h libptytty.h rxvtperl.h hookinc.h rsinc.h optinc.h
+scrollbar-rxvt.o: salloc.h ../libptytty/src/libptytty.h rxvtperl.h hookinc.h
+scrollbar-rxvt.o: rsinc.h optinc.h
 scrollbar-xterm.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h
 scrollbar-xterm.o: rxvtfont.h rxvttoolkit.h ev_cpp.h ../config.h
 scrollbar-xterm.o: ../libev/ev++.h ../libev/ev.h callback.h scrollbar.h
-scrollbar-xterm.o: salloc.h libptytty.h rxvtperl.h hookinc.h rsinc.h optinc.h
+scrollbar-xterm.o: salloc.h ../libptytty/src/libptytty.h rxvtperl.h hookinc.h
+scrollbar-xterm.o: rsinc.h optinc.h
 scrollbar.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 scrollbar.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-scrollbar.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-scrollbar.o: rsinc.h optinc.h
+scrollbar.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+scrollbar.o: rxvtperl.h hookinc.h rsinc.h optinc.h
 xdefaults.o: ../config.h rxvt.h feature.h encoding.h rxvtutil.h rxvtfont.h
 xdefaults.o: rxvttoolkit.h ev_cpp.h ../config.h ../libev/ev++.h ../libev/ev.h
-xdefaults.o: callback.h scrollbar.h salloc.h libptytty.h rxvtperl.h hookinc.h
-xdefaults.o: rsinc.h optinc.h version.h keyboard.h
+xdefaults.o: callback.h scrollbar.h salloc.h ../libptytty/src/libptytty.h
+xdefaults.o: rxvtperl.h hookinc.h rsinc.h optinc.h version.h keyboard.h
diff --git a/src/fdpass.C b/src/fdpass.C
deleted file mode 100644
index fed20a7f246c91a8f976d6c1a466e35b265195fc..0000000000000000000000000000000000000000
--- a/src/fdpass.C
+++ /dev/null
@@ -1,123 +0,0 @@
-// This file is part of libptytty. Do not make local modifications.
-// http://software.schmorp.de/pkg/libptytty
-
-/*----------------------------------------------------------------------*
- * File:	fdpass.C
- *----------------------------------------------------------------------*
- *
- * All portions of code are copyright by their respective author/s.
- * Copyright (c) 2005-2006 Marc Lehmann <schmorp@schmorp.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *----------------------------------------------------------------------*/
-
-#include "config.h"
-
-#include <cstddef> // needed by broken bsds for NULL used in sys/uio.h
-#include <cstdlib>
-
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-
-#include "libptytty.h"
-
-// CMSG_SPACE & CMSG_LEN are rfc2292 extensions to unix
-#ifndef CMSG_SPACE
-# define CMSG_SPACE(len) (sizeof (cmsghdr) + len)
-#endif
-
-#ifndef CMSG_LEN
-# define CMSG_LEN(len) (sizeof (cmsghdr) + len)
-#endif
-
-bool
-ptytty::send_fd (int socket, int fd)
-{
-  void *buf = malloc (CMSG_SPACE (sizeof (int)));
-
-  if (!buf)
-    return 0;
-
-  msghdr msg;
-  iovec iov;
-  cmsghdr *cmsg;
-  char data = 0;
-
-  iov.iov_base = &data;
-  iov.iov_len  = 1;
-
-  msg.msg_name       = 0;
-  msg.msg_namelen    = 0;
-  msg.msg_iov        = &iov;
-  msg.msg_iovlen     = 1;
-  msg.msg_control    = buf;
-  msg.msg_controllen = CMSG_SPACE (sizeof (int));
-
-  cmsg = CMSG_FIRSTHDR (&msg);
-  cmsg->cmsg_level = SOL_SOCKET;
-  cmsg->cmsg_type  = SCM_RIGHTS;
-  cmsg->cmsg_len   = CMSG_LEN (sizeof (int));
-
-  *(int *)CMSG_DATA (cmsg) = fd;
-
-  ssize_t result = sendmsg (socket, &msg, 0);
-
-  free (buf);
-
-  return result >= 0;
-}
-
-int
-ptytty::recv_fd (int socket)
-{
-  void *buf = malloc (CMSG_SPACE (sizeof (int)));
-
-  if (!buf)
-    return -1;
-
-  msghdr msg;
-  iovec iov;
-  char data = 1;
-
-  iov.iov_base = &data;
-  iov.iov_len  = 1;
-
-  msg.msg_name       = 0;
-  msg.msg_namelen    = 0;
-  msg.msg_iov        = &iov;
-  msg.msg_iovlen     = 1;
-  msg.msg_control    = buf;
-  msg.msg_controllen = CMSG_SPACE (sizeof (int));
-
-  int fd = -1;
-
-  if (recvmsg (socket, &msg, 0) >  0
-      && data                   == 0
-      && msg.msg_controllen     >= CMSG_SPACE (sizeof (int)))
-    {
-      cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
-
-      if (cmsg->cmsg_level   == SOL_SOCKET
-          && cmsg->cmsg_type == SCM_RIGHTS
-          && cmsg->cmsg_len  >= CMSG_LEN (sizeof (int)))
-        fd = *(int *)CMSG_DATA (cmsg);
-    }
-
-  free (buf);
-
-  return fd;
-}
-
diff --git a/src/fdpass_wrapper.C b/src/fdpass_wrapper.C
new file mode 100644
index 0000000000000000000000000000000000000000..e341aee39e5d6dfcac367867aaaf63ebb6c7175b
--- /dev/null
+++ b/src/fdpass_wrapper.C
@@ -0,0 +1 @@
+#include "fdpass.C"
diff --git a/src/feature.h b/src/feature.h

index 3507ccae9c7a597d5021137df55a93d8ebed8560..

index ..5aa786fdb1b5808f0a153340aa4103e1acb5b2b8 100644

--- a/src/feature.h
+++ b/src/feature.h
@@ -34,21 +34,6 @@
 # define XAPPLOADDIRLOCALE	X11LIBDIR "/%s/app-defaults"
 #endif

-/*-------------------------------SECURITY-------------------------------*/
-
-/*
- * Default mode to restore when releasing the PTS device. It is relaxed to be
- * compatible with most systems, change it to a more secure value if your
- * system supports it (0640 for example).
- */
-#define RESTORE_TTY_MODE 0666
-
-/*
- * Define if you want to use a separate process for pty/tty handling
- * when running setuid/setgid. You need this when making it setuid/setgid.
- */
-#define PTYTTY_HELPER 1
-
 /*-----------------------SCREEN OPTIONS AND COLOURS---------------------*/

 /*
diff --git a/src/libptytty.h b/src/libptytty.h
deleted file mode 100644
index 2a644a4f7fe8782e1541dfc37baacec26b122ae1..0000000000000000000000000000000000000000
--- a/src/libptytty.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// This file is part of libptytty. Do not make local modifications.
-// http://software.schmorp.de/pkg/libptytty
-
-#ifndef LIBPTYTTY_H_ /* public libptytty header file */
-#define LIBPTYTTY_H_
-
-#ifdef __cplusplus
-
-// C++ API
-
-struct ptytty {
-  int pty; // pty file descriptor; connected to terminal emulator
-  int tty; // tty file descriptor; connected to child
-
-  virtual ~ptytty ()
-  {
-  }
-
-  virtual bool get () = 0;
-  virtual void login (int cmd_pid, bool login_shell, const char *hostname) = 0;
-
-  void close_tty ();
-  bool make_controlling_tty ();
-  void set_utf8_mode (bool on);
-
-  static void sanitise_stdfd ();
-  static void init ();
-  static ptytty *create (); // create a new pty object
-
-  static void drop_privileges ();
-  static void use_helper ();
-
-  static bool send_fd (int socket, int fd);
-  static int recv_fd (int socket);
-
-protected:
-
-  ptytty ()
-  : pty(-1), tty(-1)
-  {
-  }
-};
-
-#else
-
-// C API
-
-typedef void *PTYTTY;
-
-int ptytty_pty (PTYTTY ptytty);
-int ptytty_tty (PTYTTY ptytty);
-void ptytty_delete (PTYTTY ptytty);
-int ptytty_get (PTYTTY ptytty);
-void ptytty_login (PTYTTY ptytty, int cmd_pid, int login_shell, const char *hostname);
-
-void ptytty_close_tty (PTYTTY ptytty);
-int ptytty_make_controlling_tty (PTYTTY ptytty);
-void ptytty_set_utf8_mode (PTYTTY ptytty, int on);
-
-void ptytty_sanitise_stdfd ();
-void ptytty_init ();
-PTYTTY ptytty_create ();
-
-void ptytty_drop_privileges ();
-void ptytty_use_helper ();
-
-#endif
-
-#endif
-
diff --git a/src/logging.C b/src/logging.C
deleted file mode 100644
index 0c15a8adfb2e06018d74b11f3fdd5f627957b69a..0000000000000000000000000000000000000000
--- a/src/logging.C
+++ /dev/null
@@ -1,433 +0,0 @@
-// This file is part of libptytty. Do not make local modifications.
-// http://software.schmorp.de/pkg/libptytty
-
-/*----------------------------------------------------------------------*
- * File:	logging.C
- *----------------------------------------------------------------------*
- *
- * All portions of code are copyright by their respective author/s.
- * Copyright (c) 1992      John Bovey <jdb@ukc.ac.uk>
- *				- original version
- * Copyright (c) 1993      lipka
- * Copyright (c) 1993      Brian Stempien <stempien@cs.wmich.edu>
- * Copyright (c) 1995      Raul Garcia Garcia <rgg@tid.es>
- * Copyright (c) 1995      Piet W. Plomp <piet@idefix.icce.rug.nl>
- * Copyright (c) 1997      Raul Garcia Garcia <rgg@tid.es>
- * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
- * 				- extensive modifications
- * Copyright (c) 1999      D J Hawkey Jr <hawkeyd@visi.com>
- *				- lastlog support
- * Copyright (c) 2004-2006 Marc Lehmann <schmorp@schmorp.de>
- * Copyright (c) 2006      Emanuele Giaquinta <e.giaquinta@glauco.it>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *----------------------------------------------------------------------*/
-
-#include "config.h"
-
-#include "ptytty.h"
-
-#if UTMP_SUPPORT
-
-#include <cstdio>
-#include <cstring>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <time.h>
-#include <errno.h>
-
-/*
- * BSD style utmp entry
- *      ut_line, ut_name, ut_host, ut_time
- * SYSV style utmp (and utmpx) entry
- *      ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time
- */
-
-/* ------------------------------------------------------------------------- */
-/*
- * Write a BSD style utmp entry
- */
-#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
-static int
-write_bsd_utmp (int utmp_pos, struct utmp *wu)
-{
-  int             fd;
-
-  if (utmp_pos <= 0 || (fd = open (UTMP_FILE, O_WRONLY)) == -1)
-    return 0;
-
-  if (lseek (fd, (off_t) (utmp_pos * sizeof (struct utmp)), SEEK_SET) != -1)
-    write (fd, wu, sizeof (struct utmp));
-  close (fd);
-  return 1;
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-/*
- * Update a BSD style wtmp entry
- */
-#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP)
-static void
-update_wtmp (const char *fname, const struct utmp *putmp)
-{
-  int             fd, gotlock, retry;
-  struct flock    lck;	/* fcntl locking scheme */
-  struct stat     sbuf;
-
-  if ((fd = open (fname, O_WRONLY | O_APPEND, 0)) < 0)
-    return;
-
-  lck.l_whence = SEEK_END;	/* start lock at current eof */
-  lck.l_len = 0;		/* end at ``largest possible eof'' */
-  lck.l_start = 0;
-  lck.l_type = F_WRLCK;	/* we want a write lock */
-
-  /* attempt lock with F_SETLK; F_SETLKW would cause a deadlock! */
-  for (retry = 10, gotlock = 0; retry--;)
-    if (fcntl (fd, F_SETLK, &lck) != -1)
-      {
-        gotlock = 1;
-        break;
-      }
-    else if (errno != EAGAIN && errno != EACCES)
-      break;
-  if (!gotlock)
-    {
-      /* give it up */
-      close (fd);
-      return;
-    }
-  if (fstat (fd, &sbuf) == 0)
-    if (write (fd, putmp, sizeof (struct utmp)) != sizeof (struct utmp))
-      ftruncate (fd, sbuf.st_size);	/* remove bad writes */
-
-  lck.l_type = F_UNLCK;	/* unlocking the file */
-  fcntl (fd, F_SETLK, &lck);
-  close (fd);
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-#ifdef LASTLOG_SUPPORT
-static void
-update_lastlog (const char *fname, const char *pty, const char *host)
-{
-# if defined(HAVE_STRUCT_LASTLOGX) && defined(HAVE_UPDLASTLOGX)
-  struct lastlogx llx;
-# endif
-# ifdef HAVE_STRUCT_LASTLOG
-  int             fd;
-  struct lastlog  ll;
-  char            lastlogfile[256];
-  struct passwd  *pwent;
-  struct stat     st;
-# endif
-
-# if defined(HAVE_STRUCT_LASTLOGX) && defined(HAVE_UPDLASTLOGX)
-  memset (&llx, 0, sizeof (llx));
-  llx.ll_tv.tv_sec = time (NULL);
-  llx.ll_tv.tv_usec = 0;
-  strncpy (llx.ll_line, pty, sizeof (llx.ll_line));
-  strncpy (llx.ll_host, host, sizeof (llx.ll_host));
-  updlastlogx (LASTLOGX_FILE, getuid (), &llx);
-# endif
-
-# ifdef HAVE_STRUCT_LASTLOG
-  pwent = getpwuid (getuid ());
-  if (!pwent)
-    {
-      ptytty_warn ("no entry in password file, not updating lastlog.\n", 0);
-      return;
-    }
-
-  memset (&ll, 0, sizeof (ll));
-  ll.ll_time = time (NULL);
-  strncpy (ll.ll_line, pty, sizeof (ll.ll_line));
-  strncpy (ll.ll_host, host, sizeof (ll.ll_host));
-  if (stat (fname, &st) != 0)
-    return;
-  if (S_ISDIR (st.st_mode))
-    {
-      snprintf (lastlogfile, sizeof (lastlogfile), "%s/%s", fname,
-               (!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown"
-               : pwent->pw_name);
-      if ((fd = open (lastlogfile, O_WRONLY | O_CREAT, 0644)) >= 0)
-        {
-          write (fd, &ll, sizeof (ll));
-          close (fd);
-        }
-    }
-  else if (S_ISREG (st.st_mode))
-    if ((fd = open (fname, O_RDWR)) != -1)
-      {
-        if (lseek (fd, (off_t) ((long)pwent->pw_uid * sizeof (ll)),
-                   SEEK_SET) != -1)
-          write (fd, &ll, sizeof (ll));
-        close (fd);
-      }
-# endif /* HAVE_STRUCT_LASTLOG */
-}
-#endif /* LASTLOG_SUPPORT */
-
-/* ------------------------------------------------------------------------- */
-
-/*
- * make and write utmp and wtmp entries
- */
-void
-ptytty_unix::login (int cmd_pid, bool login_shell, const char *hostname)
-{
-  const char *pty = name;
-
-  if (!pty || !*pty)
-    return;
-
-  this->cmd_pid     = cmd_pid;
-  this->login_shell = login_shell;
-
-#ifdef HAVE_STRUCT_UTMP
-  struct utmp *ut = &this->ut;
-#endif
-#ifdef HAVE_STRUCT_UTMPX
-  struct utmpx *utx = &this->utx;
-#endif
-  int i;
-  struct passwd *pwent = getpwuid (getuid ());
-  const char *name = (pwent && pwent->pw_name) ? pwent->pw_name : "?";
-
-  if (!strncmp (pty, "/dev/", 5))
-    pty += 5;		/* skip /dev/ prefix */
-
-#if defined(HAVE_UTMP_PID) || defined(HAVE_STRUCT_UTMPX)
-  if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3))
-    strncpy (ut_id, pty + 3, sizeof (ut_id));
-  else if (sscanf (pty, "pts/%d", &i) == 1)
-    sprintf (ut_id, "vt%02x", (i & 0xff));	/* sysv naming */
-  else
-    {
-      ptytty_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty);
-      return;
-    }
-#endif
-
-#ifdef HAVE_STRUCT_UTMP
-  memset (ut, 0, sizeof (struct utmp));
-# ifdef HAVE_UTMP_PID
-  setutent ();
-  strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id));
-  ut->ut_type = DEAD_PROCESS;
-  getutid (ut);		/* position to entry in utmp file */
-# endif
-#endif
-
-#ifdef HAVE_STRUCT_UTMPX
-  memset (utx, 0, sizeof (struct utmpx));
-  setutxent ();
-  strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id));
-  utx->ut_type = DEAD_PROCESS;
-  getutxid (utx);		/* position to entry in utmp file */
-#endif
-
-#ifdef HAVE_STRUCT_UTMP
-  strncpy (ut->ut_line, pty, sizeof (ut->ut_line));
-# ifdef HAVE_UTMP_HOST
-  strncpy (ut->ut_host, hostname, sizeof (ut->ut_host));
-# endif
-  ut->ut_time = time (NULL);
-# ifdef HAVE_UTMP_PID
-  strncpy (ut->ut_user, name, sizeof (ut->ut_user));
-  strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id));
-  ut->ut_pid = cmd_pid;
-  ut->ut_type = USER_PROCESS;
-  pututline (ut);
-  endutent ();			/* close the file */
-  utmp_pos = 0;
-# else
-  strncpy (ut->ut_name, name, sizeof (ut->ut_name));
-# endif
-#endif
-
-#ifdef HAVE_STRUCT_UTMPX
-  strncpy (utx->ut_line, pty, sizeof (utx->ut_line));
-  strncpy (utx->ut_user, name, sizeof (utx->ut_user));
-  strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id));
-# if HAVE_UTMPX_SESSION
-  utx->ut_session = getsid (0);
-# endif
-  utx->ut_tv.tv_sec = time (NULL);
-  utx->ut_tv.tv_usec = 0;
-  utx->ut_pid = cmd_pid;
-# ifdef HAVE_UTMPX_HOST
-  strncpy (utx->ut_host, hostname, sizeof (utx->ut_host));
-#  if 0
-  {
-    char           *colon;
-
-    if ((colon = strrchr (ut->ut_host, ':')) != NULL)
-      *colon = '\0';
-  }
-#  endif
-# endif
-  utx->ut_type = USER_PROCESS;
-  pututxline (utx);
-  endutxent ();		/* close the file */
-  utmp_pos = 0;
-#endif
-
-#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
-  {
-# if 1
-    int fdstdin = dup (STDIN_FILENO);
-    dup2 (tty, STDIN_FILENO);
-
-    i = ttyslot ();
-    if (write_bsd_utmp (i, ut))
-      utmp_pos = i;
-
-    dup2 (fdstdin, STDIN_FILENO);
-    close (fdstdin);
-# endif
-  }
-#endif
-
-#ifdef WTMP_SUPPORT
-#ifdef LOG_ONLY_ON_LOGIN
-  if (login_shell)
-#endif
-    {
-# ifdef HAVE_STRUCT_UTMP
-#  ifdef HAVE_UPDWTMP
-      updwtmp (WTMP_FILE, ut);
-#  else
-      update_wtmp (WTMP_FILE, ut);
-#  endif
-# endif
-# if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX)
-      updwtmpx (WTMPX_FILE, utx);
-# endif
-    }
-#endif
-#if defined(LASTLOG_SUPPORT) && defined(LASTLOG_FILE)
-#ifdef LOG_ONLY_ON_LOGIN
-  if (login_shell)
-#endif
-    update_lastlog (LASTLOG_FILE, pty, hostname);
-#endif
-}
-
-/* ------------------------------------------------------------------------- */
-/*
- * remove utmp and wtmp entries
- */
-void
-ptytty_unix::logout ()
-{
-  if (!cmd_pid)
-    return;
-
-#ifdef HAVE_STRUCT_UTMP
-  struct utmp *tmput, *ut = &this->ut;
-#endif
-#ifdef HAVE_STRUCT_UTMPX
-  struct utmpx *tmputx, *utx = &this->utx;
-#endif
-
-#ifdef HAVE_STRUCT_UTMP
-# ifdef HAVE_UTMP_PID
-  memset (ut, 0, sizeof (struct utmp));
-  setutent ();
-  strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id));
-  ut->ut_type = USER_PROCESS;
-  if ((tmput = getutid (ut)))		/* position to entry in utmp file */
-    ut = tmput;
-  ut->ut_type = DEAD_PROCESS;
-# else
-  memset (ut->ut_name, 0, sizeof (ut->ut_name));
-#  ifdef HAVE_UTMP_HOST
-  memset (ut->ut_host, 0, sizeof (ut->ut_host));
-#  endif
-# endif
-  ut->ut_time = time (NULL);
-#endif
-
-#ifdef HAVE_STRUCT_UTMPX
-  memset (utx, 0, sizeof (struct utmpx));
-  setutxent ();
-  strncpy (utx->ut_id, this->ut_id, sizeof (utx->ut_id));
-  utx->ut_type = USER_PROCESS;
-  if ((tmputx = getutxid (utx)))	/* position to entry in utmp file */
-    utx = tmputx;
-  utx->ut_type = DEAD_PROCESS;
-# if HAVE_UTMPX_SESSION
-  utx->ut_session = getsid (0);
-# endif
-  utx->ut_tv.tv_sec = time (NULL);
-  utx->ut_tv.tv_usec = 0;
-#endif
-
-  /*
-   * Write ending wtmp entry
-   */
-#ifdef WTMP_SUPPORT
-#ifdef LOG_ONLY_ON_LOGIN
-  if (login_shell)
-#endif
-    {
-# ifdef HAVE_STRUCT_UTMP
-#  ifdef HAVE_UPDWTMP
-      updwtmp (WTMP_FILE, ut);
-#  else
-      update_wtmp (WTMP_FILE, ut);
-#  endif
-# endif
-# if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX)
-      updwtmpx (WTMPX_FILE, utx);
-# endif
-    }
-#endif
-
-  /*
-   * Write utmp entry
-   */
-#ifdef HAVE_STRUCT_UTMP
-# ifdef HAVE_UTMP_PID
-  if (ut->ut_pid == cmd_pid)
-    pututline (ut);
-  endutent ();
-# else
-  memset (ut, 0, sizeof (struct utmp));
-  write_bsd_utmp (utmp_pos, ut);
-# endif
-#endif
-#ifdef HAVE_STRUCT_UTMPX
-  if (utx->ut_pid == cmd_pid)
-    pututxline (utx);
-  endutxent ();
-#endif
-
-  cmd_pid = 0;
-}
-
-#else
-void
-ptytty_unix::login (int cmd_pid, bool login_shell, const char *hostname)
-{
-}
-#endif
-
diff --git a/src/proxy.C b/src/proxy.C
deleted file mode 100644
index ab9ca0a7c02115a3c5dfc3a4f058632d7e5ca783..0000000000000000000000000000000000000000
--- a/src/proxy.C
+++ /dev/null
@@ -1,366 +0,0 @@
-// This file is part of libptytty. Do not make local modifications.
-// http://software.schmorp.de/pkg/libptytty
-
-/*----------------------------------------------------------------------*
- * File:	proxy.C
- *----------------------------------------------------------------------*
- *
- * All portions of code are copyright by their respective author/s.
- * Copyright (c) 2006      Marc Lehmann <schmorp@schmorp.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *---------------------------------------------------------------------*/
-
-#include "config.h"
-
-#include "ptytty.h"
-
-#include <cstdio>
-#include <cstring>
-#include <csignal>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-// helper/proxy support
-
-#if PTYTTY_HELPER
-
-static int sock_fd = -1, lock_fd = -1;
-static int helper_pid, owner_pid;
-
-struct command
-{
-  enum { get, login, destroy } type;
-
-  ptytty *id;
-
-  bool login_shell;
-  int cmd_pid;
-  char hostname[512]; // arbitrary, but should be plenty
-};
-
-struct ptytty_proxy : ptytty
-{
-  ptytty *id;
-
-  ptytty_proxy ()
-  : id(0)
-  {
-  }
-
-  ~ptytty_proxy ();
-
-  bool get ();
-  void login (int cmd_pid, bool login_shell, const char *hostname);
-};
-
-#if PTYTTY_REENTRANT
-# define NEED_TOKEN do { char ch; read  (lock_fd, &ch, 1); } while (0)
-# define GIVE_TOKEN do { char ch; write (lock_fd, &ch, 1); } while (0)
-#else
-# define NEED_TOKEN (void)0
-# define GIVE_TOKEN (void)0
-#endif
-
-bool
-ptytty_proxy::get ()
-{
-  NEED_TOKEN;
-
-  command cmd;
-
-  cmd.type = command::get;
-
-  write (sock_fd, &cmd, sizeof (cmd));
-
-  if (read (sock_fd, &id, sizeof (id)) != sizeof (id))
-    ptytty_fatal ("protocol error while creating pty using helper process, aborting.\n");
-
-  if (!id)
-    {
-      GIVE_TOKEN;
-      return false;
-    }
-
-  if ((pty = recv_fd (sock_fd)) < 0
-      || (tty = recv_fd (sock_fd)) < 0)
-    ptytty_fatal ("protocol error while reading pty/tty fds from helper process, aborting.\n");
-
-  GIVE_TOKEN;
-  return true;
-}
-
-void
-ptytty_proxy::login (int cmd_pid, bool login_shell, const char *hostname)
-{
-  NEED_TOKEN;
-
-  command cmd;
-
-  cmd.type = command::login;
-  cmd.id = id;
-  cmd.cmd_pid = cmd_pid;
-  cmd.login_shell = login_shell;
-  strncpy (cmd.hostname, hostname, sizeof (cmd.hostname));
-
-  write (sock_fd, &cmd, sizeof (cmd));
-
-  GIVE_TOKEN;
-}
-
-ptytty_proxy::~ptytty_proxy ()
-{
-  if (id)
-    {
-      close_tty ();
-
-      if (pty >= 0)
-        close (pty);
-
-      NEED_TOKEN;
-
-      command cmd;
-
-      cmd.type = command::destroy;
-      cmd.id = id;
-
-      write (sock_fd, &cmd, sizeof (cmd));
-
-      GIVE_TOKEN;
-    }
-}
-
-static
-void serve ()
-{
-  command cmd;
-  vector<ptytty *> ptys;
-
-  for (;;)
-    {
-      GIVE_TOKEN;
-
-      if (read (sock_fd, &cmd, sizeof (command)) != sizeof (command))
-        break;
-
-      if (cmd.type == command::get)
-        {
-          // -> id ptyfd ttyfd
-          cmd.id = new ptytty_unix;
-
-          if (cmd.id->get ())
-            {
-              write (sock_fd, &cmd.id, sizeof (cmd.id));
-              ptys.push_back (cmd.id);
-
-              ptytty::send_fd (sock_fd, cmd.id->pty);
-              ptytty::send_fd (sock_fd, cmd.id->tty);
-            }
-          else
-            {
-              delete cmd.id;
-              cmd.id = 0;
-              write (sock_fd, &cmd.id, sizeof (cmd.id));
-            }
-        }
-      else if (cmd.type == command::login)
-        {
-#if UTMP_SUPPORT
-          if (find (ptys.begin (), ptys.end (), cmd.id) != ptys.end ())
-            {
-              cmd.hostname[sizeof (cmd.hostname) - 1] = 0;
-              cmd.id->login (cmd.cmd_pid, cmd.login_shell, cmd.hostname);
-            }
-#endif
-        }
-      else if (cmd.type == command::destroy)
-        {
-          vector<ptytty *>::iterator pty = find (ptys.begin (), ptys.end (), cmd.id);
-
-          if (pty != ptys.end ())
-            {
-              delete *pty;
-              ptys.erase (pty);
-            }
-        }
-      else
-        break;
-
-      NEED_TOKEN;
-    }
-
-  // destroy all ptys
-  for (vector<ptytty *>::iterator i = ptys.end (); i-- > ptys.begin (); )
-    delete *i;
-}
-
-void
-ptytty::use_helper ()
-{
-#ifndef PTYTTY_NO_PID_CHECK
-  int pid = getpid ();
-#endif
-
-  if (sock_fd >= 0
-#ifndef PTYTTY_NO_PID_CHECK
-      && pid == owner_pid
-#endif
-      )
-    return;
-
-#ifndef PTYTTY_NO_PID_CHECK
-  owner_pid = pid;
-#endif
-
-  int sv[2];
-
-  if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv))
-    ptytty_fatal ("could not create socket to communicate with pty/sessiondb helper, aborting.\n");
-
-#ifdef PTYTTY_REENTRANT
-  int lv[2];
-
-  if (socketpair (AF_UNIX, SOCK_STREAM, 0, lv))
-    ptytty_fatal ("could not create socket to communicate with pty/sessiondb helper, aborting.\n");
-#endif
-
-  helper_pid = fork ();
-
-  if (helper_pid < 0)
-    ptytty_fatal ("could not create pty/sessiondb helper process, aborting.\n");
-
-  if (helper_pid)
-    {
-      // client, process
-      sock_fd = sv[0];
-      close (sv[1]);
-      fcntl (sock_fd, F_SETFD, FD_CLOEXEC);
-#ifdef PTYTTY_REENTRANT
-      lock_fd = lv[0];
-      close (lv[1]);
-      fcntl (lock_fd, F_SETFD, FD_CLOEXEC);
-#endif
-    }
-  else
-    {
-      // server, pty-helper
-      sock_fd = sv[1];
-#ifdef PTYTTY_REENTRANT
-      lock_fd = lv[1];
-#endif
-
-      chdir ("/");
-
-      signal (SIGHUP,  SIG_IGN);
-      signal (SIGTERM, SIG_IGN);
-      signal (SIGINT,  SIG_IGN);
-      signal (SIGPIPE, SIG_IGN);
-
-      for (int fd = 0; fd < 1023; fd++)
-        if (fd != sock_fd && fd != lock_fd)
-          close (fd);
-
-      serve ();
-      _exit (EXIT_SUCCESS);
-    }
-}
-
-#endif
-
-ptytty *
-ptytty::create ()
-{
-#if PTYTTY_HELPER
-  if (helper_pid
-# ifndef PTYTTY_NO_PID_CHECK
-      && getpid () == owner_pid
-# endif
-      )
-    // use helper process
-    return new ptytty_proxy;
-  else
-#endif
-    return new ptytty_unix;
-}
-
-void
-ptytty::sanitise_stdfd ()
-{
-  // sanitise stdin/stdout/stderr to point to *something*.
-  for (int fd = 0; fd <= 2; ++fd)
-    if (fcntl (fd, F_GETFL) < 0 && errno == EBADF)
-      {
-        int fd2 = open ("/dev/tty", fd ? O_WRONLY : O_RDONLY);
-
-        if (fd2 < 0)
-          fd2 = open ("/dev/null", fd ? O_WRONLY : O_RDONLY);
-
-        if (fd2 != fd)
-          abort ();
-      }
-}
-
-void
-ptytty::init ()
-{
-  sanitise_stdfd ();
-
-  uid_t uid = getuid ();
-  gid_t gid = getgid ();
-
-  // before doing anything else, check for setuid/setgid operation,
-  // start the helper process and drop privileges
-  if (uid != geteuid ()
-      || gid != getegid ())
-    {
-#if PTYTTY_HELPER
-      use_helper ();
-#else
-      ptytty_warn ("running setuid/setgid without pty helper compiled in, continuing unprivileged.\n", 0);
-#endif
-
-      drop_privileges ();
-    }
-}
-
-void
-ptytty::drop_privileges ()
-{
-  uid_t uid = getuid ();
-  gid_t gid = getgid ();
-
-  // drop privileges
-#if HAVE_SETRESUID
-  setresgid (gid, gid, gid);
-  setresuid (uid, uid, uid);
-#elif HAVE_SETREUID
-  setregid (gid, gid);
-  setreuid (uid, uid);
-#elif HAVE_SETUID
-  setgid (gid);
-  setuid (uid);
-#else
-# error no way to drop privileges, configure failed?
-#endif
-
-  if (uid != geteuid ()
-      || gid != getegid ())
-    ptytty_fatal ("unable to drop privileges, aborting.\n");
-}
-
diff --git a/src/ptytty.C b/src/ptytty.C
deleted file mode 100644
index 73f44fb0257ac2681db341ebb1492bf5cc99fa70..0000000000000000000000000000000000000000
--- a/src/ptytty.C
+++ /dev/null
@@ -1,380 +0,0 @@
-// This file is part of libptytty. Do not make local modifications.
-// http://software.schmorp.de/pkg/libptytty
-
-/*----------------------------------------------------------------------*
- * File:	ptytty.C
- *----------------------------------------------------------------------*
- *
- * All portions of code are copyright by their respective author/s.
- * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
- * Copyright (c) 2004-2006 Marc Lehmann <schmorp@schmorp.de>
- * Copyright (c) 2006      Emanuele Giaquinta <e.giaquinta@glauco.it>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *---------------------------------------------------------------------*/
-
-#include "config.h"
-
-#include "ptytty.h"
-
-#include <cstdlib>
-#include <cstring>
-#include <csignal>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#ifdef HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#if defined(HAVE_DEV_PTMX) && defined(HAVE_SYS_STROPTS_H)
-# include <sys/stropts.h>      /* for I_PUSH */
-#endif
-#if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H)
-# include <stropts.h>
-#endif
-#if defined(HAVE_PTY_H)
-# include <pty.h>
-#elif defined(HAVE_LIBUTIL_H)
-# include <libutil.h>
-#elif defined(HAVE_UTIL_H)
-# include <util.h>
-#endif
-#ifdef TTY_GID_SUPPORT
-#include <grp.h>
-#endif
-
-#include <cstdio>
-
-/////////////////////////////////////////////////////////////////////////////
-
-/* ------------------------------------------------------------------------- *
- *                  GET PSEUDO TELETYPE - MASTER AND SLAVE                   *
- * ------------------------------------------------------------------------- */
-/*
- * Returns pty file descriptor, or -1 on failure
- * If successful, ttydev is set to the name of the slave device.
- * fd_tty _may_ also be set to an open fd to the slave device
- */
-#if defined(UNIX98_PTY)
-
-  static int
-  get_pty (int *fd_tty, char **ttydev)
-  {
-    int pfd;
-
-# if defined(HAVE_GETPT)
-    pfd = getpt();
-# elif defined(HAVE_POSIX_OPENPT)
-    pfd = posix_openpt (O_RDWR);
-# else
-    pfd = open (CLONE_DEVICE, O_RDWR | O_NOCTTY, 0);
-# endif
-
-    if (pfd >= 0)
-      {
-        if (grantpt (pfd) == 0	/* change slave permissions */
-            && unlockpt (pfd) == 0)
-          {
-            /* slave now unlocked */
-            *ttydev = strdup (ptsname (pfd));	/* get slave's name */
-            return pfd;
-          }
-
-        close (pfd);
-      }
-
-    return -1;
-  }
-
-#elif defined(HAVE_OPENPTY)
-
-  static int
-  get_pty (int *fd_tty, char **ttydev)
-  {
-    int pfd;
-    int res;
-
-    res = openpty (&pfd, fd_tty, NULL, NULL, NULL);
-
-    if (res != -1)
-      {
-        *ttydev = strdup (ttyname (*fd_tty));
-        return pfd;
-      }
-
-    return -1;
-  }
-
-#elif defined(HAVE__GETPTY)
-
-  static int
-  get_pty (int *fd_tty, char **ttydev)
-  {
-    int pfd;
-    char *slave;
-
-    slave = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0);
-
-    if (slave != NULL)
-      {
-        *ttydev = strdup (slave);
-        return pfd;
-      }
-
-    return -1;
-  }
-
-#else
-
-  /* Based on the code in openssh/openbsd-compat/bsd-openpty.c */
-  static int
-  get_pty (int *fd_tty, char **ttydev)
-  {
-    int pfd;
-    int i;
-    char pty_name[32];
-    char tty_name[32];
-    const char *majors = "pqrstuvwxyzabcde";
-    const char *minors = "0123456789abcdef";
-
-    for (i = 0; i < 256; i++)
-      {
-        snprintf(pty_name, 32, "/dev/pty%c%c", majors[i / 16], minors[i % 16]);
-        snprintf(tty_name, 32, "/dev/tty%c%c", majors[i / 16], minors[i % 16]);
-
-        if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1)
-          {
-            snprintf(pty_name, 32, "/dev/ptyp%d", i);
-            snprintf(tty_name, 32, "/dev/ttyp%d", i);
-            if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1)
-              continue;
-          }
-
-        if (access (tty_name, R_OK | W_OK) == 0)
-          {
-            *ttydev = strdup (tty_name);
-            return pfd;
-          }
-
-        close (pfd);
-      }
-
-    return -1;
-  }
-
-#endif
-
-/*----------------------------------------------------------------------*/
-/*
- * Returns tty file descriptor, or -1 on failure
- */
-static int
-get_tty (char *ttydev)
-{
-  return open (ttydev, O_RDWR | O_NOCTTY, 0);
-}
-
-/*----------------------------------------------------------------------*/
-/*
- * Make our tty a controlling tty so that /dev/tty points to us
- */
-static int
-control_tty (int fd_tty)
-{
-  int fd;
-
-  setsid ();
-
-#if defined(HAVE_DEV_PTMX) && defined(I_PUSH)
-  /*
-   * Push STREAMS modules:
-   *    ptem: pseudo-terminal hardware emulation module.
-   *    ldterm: standard terminal line discipline.
-   *    ttcompat: V7, 4BSD and XENIX STREAMS compatibility module.
-   *
-   * After we push the STREAMS modules, the first open () on the slave side
-   * (i.e. the next section between the dashes giving us "tty opened OK")
-   * should make the "ptem" (or "ldterm" depending upon either which OS
-   * version or which set of manual pages you have) module give us a
-   * controlling terminal.  We must already have close ()d the master side
-   * fd in this child process before we push STREAMS modules on because the
-   * documentation is really unclear about whether it is any close () on
-   * the master side or the last close () - i.e. a proper STREAMS dismantling
-   * close () - on the master side which causes a hang up to be sent
-   * through - Geoff Wing
-   */
-#if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H)
-  if (isastream (fd_tty) == 1)
-# endif
-    {
-      ioctl (fd_tty, I_PUSH, "ptem");
-      ioctl (fd_tty, I_PUSH, "ldterm");
-      ioctl (fd_tty, I_PUSH, "ttcompat");
-    }
-#endif
-
-#ifdef TIOCSCTTY
-  ioctl (fd_tty, TIOCSCTTY, NULL);
-#else
-  fd = open (ttyname (fd_tty), O_RDWR);
-  if (fd >= 0)
-    close (fd);
-#endif
-
-  fd = open ("/dev/tty", O_WRONLY);
-  if (fd < 0)
-    return -1; /* fatal */
-
-  close (fd);
-
-  return 0;
-}
-
-void
-ptytty::close_tty ()
-{
-  if (tty < 0)
-    return;
-
-  close (tty);
-  tty = -1;
-}
-
-bool
-ptytty::make_controlling_tty ()
-{
-  return control_tty (tty) >= 0;
-}
-
-void
-ptytty::set_utf8_mode (bool on)
-{
-#ifdef IUTF8
-  if (pty < 0)
-    return;
-
-  struct termios tio;
-
-  if (tcgetattr (pty, &tio) != -1)
-    {
-      tcflag_t new_cflag = tio.c_iflag;
-
-      if (on)
-        new_cflag |= IUTF8;
-      else
-        new_cflag &= ~IUTF8;
-
-      if (new_cflag != tio.c_iflag)
-        {
-          tio.c_iflag = new_cflag;
-          tcsetattr (pty, TCSANOW, &tio);
-        }
-    }
-#endif
-}
-
-static struct ttyconf {
-  gid_t gid;
-  mode_t mode;
-
-  ttyconf ()
-    {
-#ifdef TTY_GID_SUPPORT
-      struct group *gr = getgrnam ("tty");
-
-      if (gr)
-        {
-          /* change group ownership of tty to "tty" */
-          mode = S_IRUSR | S_IWUSR | S_IWGRP;
-          gid = gr->gr_gid;
-        }
-      else
-#endif /* TTY_GID_SUPPORT */
-        {
-          mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
-          gid = 0;
-        }
-    }
-} ttyconf;
-
-ptytty_unix::ptytty_unix ()
-{
-  name = 0;
-#if UTMP_SUPPORT
-  cmd_pid = 0;
-#endif
-}
-
-ptytty_unix::~ptytty_unix ()
-{
-#if UTMP_SUPPORT
-  logout ();
-#endif
-  put ();
-}
-
-void
-ptytty_unix::put ()
-{
-  if (name)
-    {
-      chmod (name, RESTORE_TTY_MODE);
-      chown (name, 0, ttyconf.gid);
-    }
-
-  close_tty ();
-
-  if (pty >= 0)
-    close (pty);
-
-  free (name);
-
-  pty = tty = -1;
-  name = 0;
-}
-
-bool
-ptytty_unix::get ()
-{
-  /* get master (pty) */
-  if ((pty = get_pty (&tty, &name)) < 0)
-    return false;
-
-  fcntl (pty, F_SETFL, O_NONBLOCK);
-
-  /* get slave (tty) */
-  if (tty < 0)
-    {
-#ifndef NO_SETOWNER_TTYDEV
-      chown (name, getuid (), ttyconf.gid);      /* fail silently */
-      chmod (name, ttyconf.mode);
-# ifdef HAVE_REVOKE
-      revoke (name);
-# endif
-#endif
-
-      if ((tty = get_tty (name)) < 0)
-        {
-          put ();
-          return false;
-        }
-    }
-
-  return true;
-}
-
diff --git a/src/ptytty.h b/src/ptytty.h
deleted file mode 100644
index 8375150b79dfddc04762020bebc2bfeef4432dba..0000000000000000000000000000000000000000
--- a/src/ptytty.h
+++ /dev/null
@@ -1,92 +0,0 @@
-// This file is part of libptytty. Do not make local modifications.
-// http://software.schmorp.de/pkg/libptytty
-
-#ifndef PTYTTY_H
-#define PTYTTY_H
-
-#include "libptytty.h"
-#include "ptytty_conf.h"
-
-#if PTYTTY_REENTRANT
-# define PTYTTY_NO_PID_CHECK 1
-#endif
-
-#if defined(HAVE__GETPTY) || defined(HAVE_OPENPTY) || defined(UNIX98_PTY)
-# define NO_SETOWNER_TTYDEV 1
-#endif
-
-#if UTMP_SUPPORT
-# if !defined(HAVE_STRUCT_UTMPX) || defined(__GLIBC__)
-#  undef HAVE_UTMPX_H
-#  undef HAVE_STRUCT_UTMPX
-# endif
-# if !defined(UTMP_FILE) || !defined(HAVE_STRUCT_UTMP)
-#  undef HAVE_UTMP_H
-#  undef HAVE_STRUCT_UTMP
-# endif
-
-# ifdef HAVE_UTMPX_H
-#  include <utmpx.h>
-# endif
-# ifdef HAVE_UTMP_H
-#  include <utmp.h>
-# endif
-
-# if ! defined(HAVE_STRUCT_UTMPX) && ! defined(HAVE_STRUCT_UTMP)
-#  error cannot build with utmp support - no utmp or utmpx struct found
-# endif
-
-# ifdef HAVE_LASTLOG_H
-#  include <lastlog.h>
-# endif
-
-# include <pwd.h>
-
-# ifdef UTMP_SYSV
-#  ifndef USER_PROCESS
-#   define USER_PROCESS		7
-#  endif
-#  ifndef DEAD_PROCESS
-#   define DEAD_PROCESS		8
-#  endif
-# endif
-
-#endif
-
-#define fatal(msg) do { write (2, msg, sizeof (msg) - 1); _exit (255); } while (0)
-
-struct ptytty_unix : ptytty
-{
-  char *name;
-
-public:
-
-  ptytty_unix ();
-  ~ptytty_unix ();
-
-  bool get ();
-  void put ();
-
-  void login (int cmd_pid, bool login_shell, const char *hostname);
-
-#if UTMP_SUPPORT
-  int utmp_pos;
-  int cmd_pid;
-  bool login_shell;
-
-#ifdef HAVE_STRUCT_UTMP
-  struct utmp ut;
-#endif
-#ifdef HAVE_STRUCT_UTMPX
-  struct utmpx utx;
-#endif
-#if (defined(HAVE_STRUCT_UTMP) && defined(HAVE_UTMP_PID)) || defined(HAVE_STRUCT_UTMPX)
-  char ut_id[5];
-#endif
-
-  void logout ();
-#endif
-};
-
-#endif
-
diff --git a/src/ptytty_conf.h b/src/ptytty_conf.h
deleted file mode 100644
index 2f83dc5453b6ea0805c72cc028163475bc90a4c7..0000000000000000000000000000000000000000
--- a/src/ptytty_conf.h
+++ /dev/null
@@ -1,9 +0,0 @@
-
-#include "rxvt.h"
-
-#define ptytty_fatal rxvt_fatal
-#define ptytty_warn  rxvt_warn
-
-#define PTYTTY_REENTRANT 1
-#define PTYTTY_NO_PID_CHECK 1
-
diff --git a/src/ptytty_wrapper.C b/src/ptytty_wrapper.C
new file mode 100644
index 0000000000000000000000000000000000000000..75cc684288cad41147f3ad6eea08e6698b5f293a
--- /dev/null
+++ b/src/ptytty_wrapper.C
@@ -0,0 +1,11 @@
+#include <config.h>
+#include "rxvt.h"
+
+#define PTYTTY_NO_LIBCPP
+
+#define PTYTTY_FATAL rxvt_fatal
+#define PTYTTY_WARN  rxvt_warn
+
+#include "logging.C"
+#include "proxy.C"
+#include "ptytty.C"
diff --git a/update_ptytty b/update_ptytty
deleted file mode 100755
index b2ea177a8164826f89712984987e30e981d98d14..0000000000000000000000000000000000000000
--- a/update_ptytty
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-# updates libptytty from pristine sources, check out libptytty
-# as a sibling of rxvt-unicode
-
-for i in ptytty.m4 src/{libptytty.h,ptytty.C,proxy.C,ptytty.h,logging.C,fdpass.C}; do
-   cp ../libptytty/$i $i
-done

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 13:21:05 2024