summaryrefslogtreecommitdiff
path: root/gnome-pty-helper
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@src.gnome.org>2002-09-11 06:10:47 +0000
committerNalin Dahyabhai <nalin@src.gnome.org>2002-09-11 06:10:47 +0000
commit2149ce6c7878cb4161f882c15d29e6dc68e182a0 (patch)
tree9729a079b3e91ab80426bbcbb18df3df2355593e /gnome-pty-helper
parent8b212c6c4399fb2cf07cd6bb95eac17a6b790297 (diff)
Skip lookups for padding information if we're pretty sure we're using a
* src/vte.c: Skip lookups for padding information if we're pretty sure we're using a monospaced font. * src/vte.c: Fix from Brian Cameron for uninitialized GError in vte_wc_from_unichar(). * src/interpret.c, src/iso2022.c, src/pty.c, src/ring.h, src/table.c, src/table.h, src/trie.c, src/vte.c, src/vteaccess.c: Signed/unsigned int/size_t/gsize and pointer typecast warning fixes from Brian Cameron. * src/vte.c: Avoid invalidating the cursor in the cursor blink timeout unless we have focus. * src/pty.c, src/pty.h: Add vte_pty_close() and vte_pty_open_with_logging(), breaking the ABI but not the existing API. * src/vte.c, src/vte.h: Add vte_terminal_fork_logged_command(), breaking the ABI but not the existing API. * gnome-pty-helper/*: Swallow the pty helper bits of gnome-libs, but install into $pkglibdir instead of $sbindir so that existing packages don't suddenly start breaking. * src/termcap.c(_vte_termcap_find_string_length): Fix signature to match the declaration in termcap.h. From patch by Jacob Berkman. * configure.in: Add $X_PRE_LIBS to the front of $X_LIBS, -lX11 and $X_EXTRA_LIBS to the end of $X_LIBS. Remove some cruftiness and set CPPFLAGS when checking for Xft. Check for the existence of wchar.h, because it might not exist. Use an automake conditional to make compilation of the Python bindings non-critical. From patch by Jacob Berkman. * src/pty.c: Silence compiler warning when exec() fails. From patch by Jacob Berkman. * src/interpret.c, src/vte.c: Stop including langinfo.h since we don't call nl_langinfo() any more. Adapted from patch by Jacob Berkman. * src/caps.c: Fill in a couple of missing initializers. * src/vte.c, src/vte.h: Add accessor functions for use in language bindings, breaking the ABI but not the API. * python/vte.defs: Add defs for the new accessor functions. * python/vte-demo.py: Add a scrollbar to the sample window, handle more of the options the C version handles. Stop expecting additional arguments with a signal that doesn't include any. * python/Makefile.am: We only have one target, so don't bother with target-specific primaries if we can avoid it (#92252). * vte.pc.in: Note build dependencies on ATK, Pango, and PangoX.
Diffstat (limited to 'gnome-pty-helper')
-rw-r--r--gnome-pty-helper/AUTHORS4
-rw-r--r--gnome-pty-helper/COPYING481
-rw-r--r--gnome-pty-helper/Makefile.am13
-rw-r--r--gnome-pty-helper/NEWS0
-rw-r--r--gnome-pty-helper/README4
-rw-r--r--gnome-pty-helper/acinclude.m4243
-rwxr-xr-xgnome-pty-helper/autogen.sh71
-rw-r--r--gnome-pty-helper/configure.in17
-rw-r--r--gnome-pty-helper/gnome-login-support.c329
-rw-r--r--gnome-pty-helper/gnome-login-support.h38
-rw-r--r--gnome-pty-helper/gnome-pty-helper.c760
-rw-r--r--gnome-pty-helper/gnome-pty.h21
-rw-r--r--gnome-pty-helper/gnome-utmp.c348
13 files changed, 2329 insertions, 0 deletions
diff --git a/gnome-pty-helper/AUTHORS b/gnome-pty-helper/AUTHORS
new file mode 100644
index 0000000..99a686f
--- /dev/null
+++ b/gnome-pty-helper/AUTHORS
@@ -0,0 +1,4 @@
+Michael Zucchi <zucchi@helixcode.com>
+Dugan Porter
+Miguel de Icaza <miguel@gnu.org>
+Timur Bakeyev <timur@gnu.org>
diff --git a/gnome-pty-helper/COPYING b/gnome-pty-helper/COPYING
new file mode 100644
index 0000000..eb685a5
--- /dev/null
+++ b/gnome-pty-helper/COPYING
@@ -0,0 +1,481 @@
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ 675 Mass Ave, Cambridge, MA 02139, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL. It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it. You can use it for
+your libraries, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the library, or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library. If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software. To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+ Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs. This
+license, the GNU Library General Public License, applies to certain
+designated libraries. This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+ The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it. Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program. However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+ Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries. We
+concluded that weaker conditions might promote sharing better.
+
+ However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves. This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them. (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.) The hope is that this
+will lead to faster development of free libraries.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+ Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License"). Each licensee is
+addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ c) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ d) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the source code distributed need not include anything that is normally
+distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Library General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ Appendix: How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/gnome-pty-helper/Makefile.am b/gnome-pty-helper/Makefile.am
new file mode 100644
index 0000000..3a63230
--- /dev/null
+++ b/gnome-pty-helper/Makefile.am
@@ -0,0 +1,13 @@
+vtelibdir = $(libdir)/vte
+vtelib_PROGRAMS = gnome-pty-helper
+
+gnome_pty_helper_SOURCES = \
+ gnome-pty.h \
+ gnome-login-support.c \
+ gnome-login-support.h \
+ gnome-pty-helper.c \
+ gnome-utmp.c
+
+install-exec-hook:
+ chown root.utmp $(DESTDIR)/$(vtelibdir)/gnome-pty-helper || true
+ chmod g+s $(DESTDIR)/$(vtelibdir)/gnome-pty-helper || true
diff --git a/gnome-pty-helper/NEWS b/gnome-pty-helper/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gnome-pty-helper/NEWS
diff --git a/gnome-pty-helper/README b/gnome-pty-helper/README
new file mode 100644
index 0000000..c2380f6
--- /dev/null
+++ b/gnome-pty-helper/README
@@ -0,0 +1,4 @@
+This is some bits from gnome-libs CVS extracted to make a more-or-less
+standalone gnome-pty-helper kit (except for the default installation directory
+being hard-coded to ${libdir}/vte). Like the rest of gnome-libs, its license
+is the LGPL.
diff --git a/gnome-pty-helper/acinclude.m4 b/gnome-pty-helper/acinclude.m4
new file mode 100644
index 0000000..c0eb916
--- /dev/null
+++ b/gnome-pty-helper/acinclude.m4
@@ -0,0 +1,243 @@
+# Checks for availability of various utmp fields
+#
+# Original code by Bernhard Rosenkraenzer (bero@linux.net.eu.org), 1998.
+# Modifications by Timur Bakeyev (timur@gnu.org), 1999.
+#
+
+dnl GPH_CHECK_UTMP()
+dnl Test for presence of the field and define HAVE_UT_UT_field macro
+dnl
+
+AC_DEFUN(GPH_CHECK_UTMP,[
+
+AC_CHECK_HEADERS(sys/time.h utmp.h utmpx.h)
+AC_HEADER_TIME
+
+if test "$ac_cv_header_utmpx_h" = "yes"; then
+ AC_DEFINE(UTMP,[struct utmpx],[Define to the name of a structure which holds utmp data.])
+else
+ AC_DEFINE(UTMP,[struct utmp],[Define to the name of a structure which holds utmp data.])
+fi
+
+dnl some systems (BSD4.4-like) require time.h to be included before utmp.h :/
+AC_MSG_CHECKING(for ut_host field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; char *p; p=ut.ut_host;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_HOST,1,[Define if your utmp struct contains a ut_host field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_pid field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; int i; i=ut.ut_pid;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_PID,1,[Define if your utmp struct contains a ut_pid field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_id field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; char *p; p=ut.ut_id;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_ID,1,[Define if your utmp struct contains a ut_id field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_name field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; char *p; p=ut.ut_name;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_NAME,1,[Define if your utmp struct contains a ut_name field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_type field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; int i; i=(int) ut.ut_type;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_TYPE,1,[Define if your utmp struct contains a ut_type field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_exit.e_termination field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; ut.ut_exit.e_termination=0;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_EXIT_E_TERMINATION,1,[Define if your utmp struct contains a ut_exit.e_termination field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_user field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; char *p; p=ut.ut_user;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_USER,1,[Define if your utmp struct contains a ut_user field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_time field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; ut.ut_time=0;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_TIME,1,[Define if your utmp struct contains a ut_time field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_tv field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; ut.ut_tv={0, 0};],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_TV,1,[Define if your utmp struct contains a ut_tv field.])
+fi
+AC_MSG_RESULT($result)
+
+AC_MSG_CHECKING(for ut_syslen field in the utmp structure)
+AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif],[UTMP ut; ut.ut_syslen=0;],result=yes,result=no)
+if test "$result" = "yes"; then
+ AC_DEFINE(HAVE_UT_UT_SYSLEN,1,[Define if your utmp struct contains a ut_syslen field.])
+fi
+AC_MSG_RESULT($result)
+
+])
diff --git a/gnome-pty-helper/autogen.sh b/gnome-pty-helper/autogen.sh
new file mode 100755
index 0000000..c28ea23
--- /dev/null
+++ b/gnome-pty-helper/autogen.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+# Run this to generate all the initial makefiles, etc.
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+ORIGDIR=`pwd`
+cd $srcdir
+PROJECT=gnome-pty-helper
+TEST_TYPE=-f
+
+DIE=0
+
+(autoconf --version) < /dev/null > /dev/null 2>&1 || {
+ echo
+ echo "You must have autoconf installed to compile $PROJECT."
+ echo "libtool the appropriate package for your distribution,"
+ echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
+ DIE=1
+}
+
+have_automake=false
+if automake --version < /dev/null > /dev/null 2>&1 ; then
+ automake_version=`automake --version | grep 'automake (GNU automake.*)' | sed 's/^[^0-9]*\(.*\)/\1/'`
+ case $automake_version in
+ 1.2*|1.3*|1.4*)
+ ;;
+ *)
+ have_automake=true
+ ;;
+ esac
+fi
+if $have_automake ; then : ; else
+ echo
+ echo "You must have automake 1.5 installed to compile $PROJECT."
+ echo "Get ftp://ftp.gnu.org/pub/gnu/automake/automake-1.5.tar.gz"
+ echo "(or a newer version if it is available)"
+ DIE=1
+fi
+
+if test "$DIE" -eq 1; then
+ exit 1
+fi
+
+if test -z "$AUTOGEN_SUBDIR_MODE"; then
+ if test -z "$*"; then
+ echo "I am going to run ./configure with no arguments - if you wish "
+ echo "to pass any to it, please specify them on the $0 command line."
+ fi
+fi
+
+case $CC in
+*xlc | *xlc\ * | *lcc | *lcc\ *) am_opt=--include-deps;;
+esac
+
+touch config.h.in
+aclocal $ACLOCAL_FLAGS
+
+# optionally feature autoheader
+(autoheader --version) < /dev/null > /dev/null 2>&1 && autoheader
+
+automake -a -c $am_opt
+autoconf
+cd $ORIGDIR
+
+if test -z "$AUTOGEN_SUBDIR_MODE"; then
+ $srcdir/configure --enable-maintainer-mode "$@"
+ chmod -Rf u+w $srcdir
+ echo
+ echo "Now type 'make' to compile $PROJECT."
+fi
diff --git a/gnome-pty-helper/configure.in b/gnome-pty-helper/configure.in
new file mode 100644
index 0000000..a36e701
--- /dev/null
+++ b/gnome-pty-helper/configure.in
@@ -0,0 +1,17 @@
+AC_INIT(gnome-pty.h)
+
+AM_INIT_AUTOMAKE(gnome-pty-helper,1.95.0)
+
+AC_ISC_POSIX
+AC_PROG_CC
+AC_STDC_HEADERS
+AM_PROG_CC_STDC
+
+AM_MAINTAINER_MODE
+
+AC_CHECK_HEADERS(sys/syslimits.h sys/time.h sys/types.h sys/un.h alloca.h lastlog.h libutil.h paths.h pty.h stropts.h termios.h ttyent.h util.h utmp.h utmpx.h)
+AC_CHECK_FUNCS(endutent fcntl forkpty getttyent getutent getutmpx grantpt flock login_tty openpty revoke sendmsg seteuid setreuid setutent strrchr updwtmp updwtmpx utmpname utmpxname)
+GPH_CHECK_UTMP
+
+AM_CONFIG_HEADER(config.h)
+AC_OUTPUT(Makefile)
diff --git a/gnome-pty-helper/gnome-login-support.c b/gnome-pty-helper/gnome-login-support.c
new file mode 100644
index 0000000..2397b54
--- /dev/null
+++ b/gnome-pty-helper/gnome-login-support.c
@@ -0,0 +1,329 @@
+/*
+ * gnome-login-support.c:
+ * Replacement for systems that lack login_tty, open_pty and forkpty
+ *
+ * Author:
+ * Miguel de Icaza (miguel@gnu.org)
+ *
+ *
+ */
+#include <config.h>
+#include <termios.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <grp.h>
+#include <sys/types.h>
+#include "gnome-login-support.h"
+
+/*
+ * HAVE_OPENPTY => HAVE_FORKPTY
+ */
+
+#ifndef HAVE_LOGIN_TTY
+int
+login_tty (int fd)
+{
+ pid_t pid = getpid ();
+
+ /* Create the session */
+ setsid ();
+
+#ifdef TIOCSCTTY
+ if (ioctl (fd, TIOCSCTTY, 0) == -1)
+ return -1;
+#else /* !TIOCSTTY */
+ /* Hackery to set controlling tty on SVR4 -
+ on SVR4 the first terminal we open after sesid()
+ becomes our controlling terminal, thus we must
+ find the name of, open, and re-close the tty
+ since we already have it open at this point. */
+ {
+ char *ctty;
+ int ct_fdes;
+
+ ctty = ttyname(fd);
+ ct_fdes = open(ctty, O_RDWR);
+ close(ct_fdes);
+ }
+#endif /* !TIOCSTTY */
+
+#if defined (_POSIX_VERSION) || defined (__svr4__)
+ tcsetpgrp (0, pid);
+#elif defined (TIOCSPGRP)
+ ioctl (0, TIOCSPGRP, &pid);
+#endif
+
+ dup2 (fd, 0);
+ dup2 (fd, 1);
+ dup2 (fd, 2);
+ if (fd > 2)
+ close (fd);
+
+ return 0;
+}
+#endif
+
+#ifndef HAVE_OPENPTY
+static int
+pty_open_master_bsd (char *pty_name, int *used_bsd)
+{
+ int pty_master;
+ char *ptr1, *ptr2;
+
+ *used_bsd = 1;
+
+ strcpy (pty_name, "/dev/ptyXX");
+ for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1; ++ptr1)
+ {
+ pty_name [8] = *ptr1;
+ for (ptr2 = "0123456789abcdef"; *ptr2; ++ptr2)
+ {
+ pty_name [9] = *ptr2;
+
+ /* Try to open master */
+ if ((pty_master = open (pty_name, O_RDWR)) == -1) {
+ if (errno == ENOENT) /* Different from EIO */
+ return -1; /* Out of pty devices */
+ else
+ continue; /* Try next pty device */
+ }
+ pty_name [5] = 't'; /* Change "pty" to "tty" */
+ if (access (pty_name, 6)){
+ close (pty_master);
+ pty_name [5] = 'p';
+ continue;
+ }
+ return pty_master;
+ }
+ }
+ return -1; /* Ran out of pty devices */
+}
+
+static int
+pty_open_slave_bsd (const char *pty_name)
+{
+ int pty_slave;
+ struct group *group_info = getgrnam ("tty");
+
+ if (group_info != NULL)
+ {
+ /* The following two calls will only succeed if we are root */
+
+ chown (pty_name, getuid (), group_info->gr_gid);
+ chmod (pty_name, S_IRUSR | S_IWUSR | S_IWGRP);
+ }
+ else
+ {
+ chown (pty_name, getuid (), -1);
+ chmod (pty_name, S_IRUSR | S_IWUSR | S_IWGRP);
+ }
+
+#ifdef HAVE_REVOKE
+ revoke (pty_name);
+#endif
+
+ if ((pty_slave = open (pty_name, O_RDWR)) == -1){
+ return -1;
+ }
+
+ return pty_slave;
+}
+
+/* SystemVish pty opening */
+#if defined (HAVE_GRANTPT)
+
+#ifdef HAVE_STROPTS_H
+# include <stropts.h>
+#endif
+
+static int
+pty_open_slave (const char *pty_name)
+{
+ int pty_slave = open (pty_name, O_RDWR);
+
+ if (pty_slave == -1)
+ return -1;
+
+#ifdef HAVE_STROPTS_H
+#if !defined(__osf__)
+ if (!ioctl (pty_slave, I_FIND, "ptem"))
+ if (ioctl (pty_slave, I_PUSH, "ptem") == -1){
+ close (pty_slave);
+ return -1;
+ }
+
+ if (!ioctl (pty_slave, I_FIND, "ldterm"))
+ if (ioctl (pty_slave, I_PUSH, "ldterm") == -1){
+ close (pty_slave);
+ return -1;
+ }
+
+#if !defined(sgi) && !defined(__sgi)
+ if (!ioctl (pty_slave, I_FIND, "ttcompat"))
+ if (ioctl (pty_slave, I_PUSH, "ttcompat") == -1)
+ {
+ perror ("ioctl (pty_slave, I_PUSH, \"ttcompat\")");
+ close (pty_slave);
+ return -1;
+ }
+#endif /* sgi || __sgi */
+#endif /* __osf__ */
+#endif /* HAVE_STROPTS_H */
+
+ return pty_slave;
+}
+
+static int
+pty_open_master (char *pty_name, int *used_bsd)
+{
+ int pty_master;
+ char *slave_name;
+
+ strcpy (pty_name, "/dev/ptmx");
+
+ pty_master = open (pty_name, O_RDWR);
+
+ /*
+ * Try BSD open, this is needed for Linux which
+ * might have Unix98 devices but no kernel support
+ * for those.
+ */
+ if (pty_master == -1){
+ *used_bsd = 1;
+ return pty_open_master_bsd (pty_name, used_bsd);
+ }
+ *used_bsd = 0;
+
+ if (grantpt (pty_master) == -1 || unlockpt (pty_master) == -1){
+ close (pty_master);
+ return -1;
+ }
+ if ((slave_name = ptsname (pty_master)) == NULL){
+ close (pty_master);
+ return -1;
+ }
+ strcpy (pty_name, slave_name);
+ return pty_master;
+}
+#else
+# define pty_open_master pty_open_master_bsd
+# define pty_open_slave pty_open_slave_bsd
+#endif
+
+int
+openpty (int *master_fd, int *slave_fd, char *name, struct termios *termp, struct winsize *winp)
+{
+ int pty_master, pty_slave, used_bsd = 0;
+ struct group *group_info;
+ char line [256];
+
+ pty_master = pty_open_master (line, &used_bsd);
+ fcntl (pty_master, F_SETFD, FD_CLOEXEC);
+
+ if (pty_master == -1)
+ return -1;
+
+ group_info = getgrnam ("tty");
+
+ if (group_info != NULL){
+ chown (line, getuid (), group_info->gr_gid);
+ chmod (line, S_IRUSR | S_IWUSR | S_IWGRP);
+ }
+ else
+ {
+ chown (line, getuid (), -1);
+ chmod (line, S_IRUSR | S_IWUSR | S_IWGRP);
+ }
+
+#ifdef HAVE_REVOKE
+ revoke (line);
+#endif
+
+ /* Open slave side */
+ if (used_bsd)
+ pty_slave = pty_open_slave_bsd (line);
+ else
+ pty_slave = pty_open_slave (line);
+
+ if (pty_slave == -1){
+ close (pty_master);
+
+ errno = ENOENT;
+ return -1;
+ }
+ fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
+
+ *master_fd = pty_master;
+ *slave_fd = pty_slave;
+
+ if (termp)
+ tcsetattr (pty_slave, TCSAFLUSH, termp);
+
+ if (winp)
+ ioctl (pty_slave, TIOCSWINSZ, winp);
+
+ if (name)
+ strcpy (name, line);
+
+ return 0;
+}
+
+pid_t
+forkpty (int *master_fd, char *name, struct termios *termp, struct winsize *winp)
+{
+ int master, slave;
+ pid_t pid;
+
+ if (openpty (&master, &slave, name, termp, winp) == -1)
+ return -1;
+
+ pid = fork ();
+
+ if (pid == -1)
+ return -1;
+
+ /* Child */
+ if (pid == 0){
+ close (master);
+ login_tty (slave);
+ } else {
+ *master_fd = master;
+ close (slave);
+ }
+
+ return pid;
+}
+#endif /* HAVE_OPENPTY */
+
+int
+n_read (int fd, void *buffer, int n)
+{
+ int left, nread;
+ char *ptr;
+
+ ptr = buffer;
+ left = n;
+ while (left > 0){
+ if ((nread = read (fd, ptr, left)) < 0){
+ if (errno == EINTR)
+ nread = 0;
+ else
+ return -1;
+ } else if (nread == 0)
+ break; /* EOF */
+
+ left -= nread;
+ ptr += nread;
+ }
+
+ return n - left;
+}
+
diff --git a/gnome-pty-helper/gnome-login-support.h b/gnome-pty-helper/gnome-login-support.h
new file mode 100644
index 0000000..ff65d02
--- /dev/null
+++ b/gnome-pty-helper/gnome-login-support.h
@@ -0,0 +1,38 @@
+#ifndef _GNOME_LOGIN_SUPPORT_H
+#define _GNOME_LOGIN_SUPPORT_H
+
+#ifdef HAVE_OPENPTY
+#if defined(HAVE_PTY_H)
+# include <pty.h>
+#elif defined(HAVE_UTIL_H) /* OpenBSD */
+# include <util.h>
+#elif defined(HAVE_LIBUTIL_H) /* FreeBSD */
+# include <libutil.h>
+#elif defined(HAVE_LIBUTIL) /* BSDI has libutil, but no libutil.h */
+/* Avoid pulling in all the include files for no need */
+struct termios;
+struct winsize;
+struct utmp;
+
+void login (struct utmp *ut);
+int login_tty (int fd);
+int logout (char *line);
+void logwtmp (const char *line, const char *name, const char *host);
+int openpty (int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp);
+int forkpty (int *amaster, char *name, struct termios *termp, struct winsize *winp);
+#endif
+#else
+int openpty (int *master_fd, int *slavefd, char *name, struct termios *termp, struct winsize *winp);
+pid_t forkpty (int *master_fd, char *name, struct termios *termp, struct winsize *winp);
+#endif
+
+#ifndef HAVE_LOGIN_TTY
+int login_tty (int fd);
+#elif defined(HAVE_UTMP_H)
+/* Get the prototype from utmp.h */
+#include <utmp.h>
+#endif
+
+int n_read (int fd, void *buffer, int size);
+
+#endif /* _GNOME_LOGIN_SUPPORT_H */
diff --git a/gnome-pty-helper/gnome-pty-helper.c b/gnome-pty-helper/gnome-pty-helper.c
new file mode 100644
index 0000000..48565db
--- /dev/null
+++ b/gnome-pty-helper/gnome-pty-helper.c
@@ -0,0 +1,760 @@
+/*
+ * gnome-pty.c: Helper setuid application used to open a pseudo-
+ * terminal, set the permissions, ownership and record user login
+ * information
+ *
+ * Author:
+ * Miguel de Icaza (miguel@gnu.org)
+ *
+ * Parent application talks to us via a couple of sockets that are strategically
+ * placed on file descriptors 0 and 1 (STDIN_FILENO and STDOUT_FILENO).
+ *
+ * We use the STDIN_FILENO to read and write the protocol information and we use
+ * the STDOUT_FILENO to pass the file descriptors (we need two different file
+ * descriptors as using a socket for both data transfers and file descriptor
+ * passing crashes some BSD kernels according to Theo de Raadt)
+ *
+ * A simple protocol is used:
+ *
+ * OPEN_PTY => 1 <tag> <master-pty-fd> <slave-pty-fd>
+ * => 0
+ *
+ * CLOSE_PTY <tag> => void
+ *
+ * <tag> is a pointer. If tag is NULL, then the ptys were not allocated.
+ * ptys are passed using file descriptor passing on the stdin file descriptor
+ *
+ * We use as little as possible external libraries.
+ */
+#include <config.h>
+
+/* Use this to pull SCM_RIGHTS definition on IRIX */
+#if defined(irix) || defined (__irix__) || defined(sgi) || defined (__sgi__)
+# define _XOPEN_SOURCE 1
+extern char *strdup(const char *);
+#endif
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <errno.h>
+#include <malloc.h>
+#include <termios.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <utmp.h>
+#include <grp.h>
+#include "gnome-pty.h"
+#include "gnome-login-support.h"
+
+
+/* GNU autoconf alloca incantation */
+/* AIX requires this to be the first thing in the file. */
+#ifdef __GNUC__
+# ifndef alloca
+# define alloca __builtin_alloca
+# endif
+#else
+# if HAVE_ALLOCA_H
+# include <alloca.h>
+# else
+# ifdef _AIX
+ #pragma alloca
+# else
+# ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+# endif
+# endif
+# endif
+#endif
+
+/* For PATH_MAX on BSD-like systems. */
+#ifdef HAVE_SYS_SYSLIMITS_H
+#include <sys/syslimits.h>
+#endif
+
+static struct passwd *pwent;
+static char login_name_buffer [48];
+static char *login_name, *display_name;
+
+struct pty_info {
+ struct pty_info *next;
+ int master_fd, slave_fd;
+ char *line;
+ void *data;
+ char utmp, wtmp;
+};
+
+typedef struct pty_info pty_info;
+
+static pty_info *pty_list;
+
+#ifdef HAVE_SENDMSG
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+#ifdef HAVE_SYS_UN_H /* Linux libc5 */
+#include <sys/un.h>
+#endif
+
+#ifndef CMSG_DATA /* Linux libc5 */
+/* Ancillary data object manipulation macros. */
+#if !defined __STRICT_ANSI__ && defined __GNUC__ && __GNUC__ >= 2
+# define CMSG_DATA(cmsg) ((cmsg)->cmsg_data)
+#else
+# define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))
+#endif
+#endif /* CMSG_DATA */
+
+#define CONTROLLEN (sizeof (struct cmsghdr) + sizeof (int))
+
+static struct cmsghdr *cmptr;
+
+static int
+init_msg_pass ()
+{
+ cmptr = malloc (CONTROLLEN);
+
+ if (cmptr)
+ return 0;
+
+ return -1;
+}
+
+static int
+pass_fd (int client_fd, int fd)
+{
+ struct iovec iov[1];
+ struct msghdr msg;
+ char buf [1];
+
+ iov [0].iov_base = buf;
+ iov [0].iov_len = 1;
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_control = (caddr_t) cmptr;
+ msg.msg_controllen = CONTROLLEN;
+
+ cmptr->cmsg_level = SOL_SOCKET;
+ cmptr->cmsg_type = SCM_RIGHTS;
+ cmptr->cmsg_len = CONTROLLEN;
+ *(int *)CMSG_DATA (cmptr) = fd;
+
+ if (sendmsg (client_fd, &msg, 0) != 1)
+ return -1;
+
+ return 0;
+}
+
+#elif defined(__sgi) && !defined(HAVE_SENDMSG)
+
+/*
+ * IRIX 6.2 is like 4.3BSD; it will not have HAVE_SENDMSG set,
+ * because msghdr used msg_accrights and msg_accrightslen rather
+ * than the newer msg_control and msg_controllen fields configure
+ * checks. The SVR4 code below doesn't work because pipe()
+ * semantics are controlled by the svr3pipe systune variable,
+ * which defaults to uni-directional pipes. Also sending
+ * file descriptors through pipes isn't implemented.
+ */
+
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+static int
+init_msg_pass ()
+{
+ return 0;
+}
+
+static int
+pass_fd (int client_fd, int fd)
+{
+ struct iovec iov[1];
+ struct msghdr msg;
+ char buf [1];
+
+ iov [0].iov_base = buf;
+ iov [0].iov_len = 1;
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_accrights = (caddr_t) &fd;
+ msg.msg_accrightslen = sizeof(fd);
+
+ if (sendmsg (client_fd, &msg, 0) != 1)
+ return -1;
+
+ return 0;
+}
+
+#else
+#include <stropts.h>
+static int
+init_msg_pass ()
+{
+ /* nothing */
+ return 0;
+}
+
+int
+pass_fd (int client_fd, int fd)
+{
+ if (ioctl (client_fd, I_SENDFD, fd) < 0)
+ return -1;
+ return 0;
+}
+#endif
+
+static void
+pty_free (pty_info *pi)
+{
+ free (pi);
+}
+
+static void
+pty_remove (pty_info *pi)
+{
+ pty_info *l, *last;
+
+ last = (void *) 0;
+
+ for (l = pty_list; l; l = l->next){
+ if (l == pi){
+ if (last == (void *) 0)
+ pty_list = pi->next;
+ else
+ last->next = pi->next;
+ free (pi->line);
+ pty_free (pi);
+ return;
+ }
+ last = l;
+ }
+
+ exit (1);
+}
+
+static void
+shutdown_pty (pty_info *pi)
+{
+ if (pi->utmp || pi->wtmp)
+ if (pi->data)
+ write_logout_record (pi->data, pi->utmp, pi->wtmp);
+
+ close (pi->master_fd);
+ close (pi->slave_fd);
+
+ pty_remove (pi);
+}
+
+static void
+shutdown_helper (void)
+{
+ pty_info *pi;
+
+ for (pi = pty_list; pi; pi = pty_list)
+ shutdown_pty (pi);
+}
+
+static pty_info *
+pty_add (int utmp, int wtmp, int master_fd, int slave_fd, char *line)
+{
+ pty_info *pi = malloc (sizeof (pty_info));
+
+ if (pi == NULL){
+ shutdown_helper ();
+ exit (1);
+ }
+
+ memset (pi, 0, sizeof (pty_info));
+
+ if (strncmp (line, "/dev/", 5))
+ pi->line = strdup (line);
+ else
+ pi->line = strdup (line+5);
+
+ if (pi->line == NULL){
+ shutdown_helper ();
+ exit (1);
+ }
+
+ pi->master_fd = master_fd;
+ pi->slave_fd = slave_fd;
+ pi->next = pty_list;
+ pi->utmp = utmp;
+ pi->wtmp = wtmp;
+
+ pty_list = pi;
+
+ return pi;
+}
+
+static int
+path_max (void)
+{
+#ifdef _PC_PATH_MAX
+ return pathconf ("/", _PC_PATH_MAX);
+#else
+# ifdef PATH_MAX
+ return PATH_MAX;
+# else
+ return 1024;
+# endif
+#endif
+}
+
+static struct termios*
+init_term_with_defaults(struct termios* term)
+{
+ /*
+ * openpty assumes POSIX termios so this should be portable.
+ * Don't change this to a structure init - POSIX doesn't say
+ * anything about field order.
+ */
+ memset(term, 0, sizeof(struct termios));
+
+ term->c_iflag = 0
+#ifdef BRKINT
+ | BRKINT
+#endif
+#ifdef ICRNL
+ | ICRNL
+#endif
+#ifdef IMAXBEL
+ | IMAXBEL
+#endif
+#ifdef IXON
+ | IXON
+#endif
+#ifdef IXANY
+ | IXANY
+#endif
+ ;
+ term->c_oflag = 0
+#ifdef OPOST
+ | OPOST
+#endif
+#ifdef ONLCR
+ | ONLCR
+#endif
+#ifdef NL0
+ | NL0
+#endif
+#ifdef CR0
+ | CR0
+#endif
+#ifdef TAB0
+ | TAB0
+#endif
+#ifdef BS0
+ | BS0
+#endif
+#ifdef VT0
+ | VT0
+#endif
+#ifdef FF0
+ | FF0
+#endif
+ ;
+ term->c_cflag = 0
+#ifdef CREAD
+ | CREAD
+#endif
+#ifdef CS8
+ | CS8
+#endif
+#ifdef HUPCL
+ | HUPCL
+#endif
+ ;
+#ifdef EXTB
+ cfsetispeed(term, EXTB);
+ cfsetospeed(term, EXTB);
+#else
+# ifdef B38400
+ cfsetispeed(term, B38400);
+ cfsetospeed(term, B38400);
+# else
+# ifdef B9600
+ cfsetispeed(term, B9600);
+ cfsetospeed(term, B9600);
+# endif
+# endif
+#endif /* EXTB */
+
+ term->c_lflag = 0
+#ifdef ECHO
+ | ECHO
+#endif
+#ifdef ICANON
+ | ICANON
+#endif
+#ifdef ISIG
+ | ISIG
+#endif
+#ifdef IEXTEN
+ | IEXTEN
+#endif
+#ifdef ECHOE
+ | ECHOE
+#endif
+#ifdef ECHOKE
+ | ECHOKE
+#endif
+#ifdef ECHOCTL
+ | ECHOCTL
+#endif
+ ;
+
+#ifdef N_TTY
+ /* should really be a check for c_line, but maybe this is good enough */
+ term->c_line = N_TTY;
+#endif
+
+ /* These two may overlap so set them first */
+ /* That setup means, that read() will be blocked untill */
+ /* at least 1 symbol will be read. */
+ term->c_cc[VMIN] = 1;
+ term->c_cc[VTIME] = 0;
+
+ /*
+ * Now set the characters. This is of course a religious matter
+ * but we use the defaults, with erase bound to the key gnome-terminal
+ * maps.
+ *
+ * These are the ones set by "stty sane".
+ */
+
+ term->c_cc[VINTR] = 'C'-64;
+ term->c_cc[VQUIT] = '\\'-64;
+ term->c_cc[VERASE] = 127;
+ term->c_cc[VKILL] = 'U'-64;
+ term->c_cc[VEOF] = 'D'-64;
+#ifdef VSWTC
+ term->c_cc[VSWTC] = 255;
+#endif
+ term->c_cc[VSTART] = 'Q'-64;
+ term->c_cc[VSTOP] = 'S'-64;
+ term->c_cc[VSUSP] = 'Z'-64;
+ term->c_cc[VEOL] = 255;
+
+ /*
+ * Extended stuff.
+ */
+
+#ifdef VREPRINT
+ term->c_cc[VREPRINT] = 'R'-64;
+#endif
+#ifdef VSTATUS
+ term->c_cc[VSTATUS] = 'T'-64;
+#endif
+#ifdef VDISCARD
+ term->c_cc[VDISCARD] = 'O'-64;
+#endif
+#ifdef VWERASE
+ term->c_cc[VWERASE] = 'W'-64;
+#endif
+#ifdef VLNEXT
+ term->c_cc[VLNEXT] = 'V'-64;
+#endif
+#ifdef VDSUSP
+ term->c_cc[VDSUSP] = 'Y'-64;
+#endif
+#ifdef VEOL2
+ term->c_cc[VEOL2] = 255;
+#endif
+ return(term);
+}
+
+static int
+open_ptys (int utmp, int wtmp, int lastlog)
+{
+ char *term_name;
+ int status, master_pty, slave_pty;
+ pty_info *p;
+ int result;
+ uid_t savedUid;
+ gid_t savedGid;
+ struct group *group_info;
+ struct termios term;
+
+ term_name = ((char *) alloca (path_max())) + 1;
+
+ if (term_name == NULL){
+ exit (1);
+ }
+ /* Initialize term */
+ init_term_with_defaults(&term);
+
+ /* root privileges */
+ savedUid = geteuid();
+ savedGid = getegid();
+
+ /* drop privileges to the user level */
+#if defined(HAVE_SETEUID)
+ seteuid (pwent->pw_uid);
+ setegid (pwent->pw_gid);
+#elif defined(HAVE_SETREUID)
+ setreuid (savedUid, pwent->pw_uid);
+ setregid (savedGid, pwent->pw_gid);
+#else
+#error "No means to drop privileges! Huge security risk! Won't compile."
+#endif
+ /* Open pty with privileges of the user */
+ status = openpty (&master_pty, &slave_pty, term_name, &term, NULL);
+
+ /* Restore saved privileges to root */
+#ifdef HAVE_SETEUID
+ seteuid (savedUid);
+ setegid (savedGid);
+#elif defined(HAVE_SETREUID)
+ setreuid (pwent->pw_uid, savedUid);
+ setregid (pwent->pw_gid, savedGid);
+#else
+#error "No means to raise privileges! Huge security risk! Won't compile."
+#endif
+ /* openpty() failed, reject request */
+ if (status == -1){
+ result = 0;
+ write (STDIN_FILENO, &result, sizeof (result));
+ return 0;
+ }
+
+ /* a bit tricky, we re-do the part of the openpty() */
+ /* that required root privileges, and, hence, failed */
+ group_info = getgrnam ("tty");
+ fchown (slave_pty, getuid (), group_info ? group_info->gr_gid : -1);
+ fchmod (slave_pty, S_IRUSR | S_IWUSR | S_IWGRP);
+ /* It's too late to call revoke at this time... */
+ /* revoke(term_name); */
+
+ /* add pty to the list of allocated by us */
+ p = pty_add (utmp, wtmp, master_pty, slave_pty, term_name);
+ result = 1;
+
+ if (write (STDIN_FILENO, &result, sizeof (result)) == -1 ||
+ write (STDIN_FILENO, &p, sizeof (p)) == -1 ||
+ pass_fd (STDOUT_FILENO, master_pty) == -1 ||
+ pass_fd (STDOUT_FILENO, slave_pty) == -1){
+ exit (0);
+ }
+
+ if (utmp || wtmp || lastlog){
+ p->data = write_login_record (login_name, display_name, term_name, utmp, wtmp, lastlog);
+ }
+
+ return 1;
+}
+
+static void
+close_pty_pair (void *tag)
+{
+ pty_info *pi;
+
+ for (pi = pty_list; pi; pi = pi->next){
+ if (tag == pi){
+ shutdown_pty (pi);
+ break;
+ }
+ }
+}
+
+#define MB (1024*1024)
+
+struct {
+ int limit;
+ int value;
+} sensible_limits [] = {
+ { RLIMIT_CPU, 120 },
+ { RLIMIT_FSIZE, 1 * MB },
+ { RLIMIT_DATA, 1 * MB },
+ { RLIMIT_STACK, 1 * MB },
+#ifdef RLIMIT_AS
+ { RLIMIT_AS, 1 * MB },
+#endif
+ { RLIMIT_NOFILE, 10 },
+#ifdef RLIMIT_NPROC
+ { RLIMIT_NPROC, 5 },
+#endif
+ { -1, -1 }
+};
+
+static void
+sanity_checks (void)
+{
+ int stderr_fd;
+ int i, open_max;
+ int flag;
+
+ /*
+ * Make sure stdin/stdout are open. This is a requirement
+ * for our program to work and closes potential security holes.
+ */
+ if ((fcntl (0, F_GETFL, &flag) == -1 && errno == EBADF) ||
+ (fcntl (1, F_GETFL, &flag) == -1 && errno == EBADF)){
+ exit (1);
+ }
+
+ /*
+ * File descriptors 0 and 1 have been setup by the parent process
+ * to be used for the protocol exchange and for transfering
+ * file descriptors.
+ *
+ * Make stderr point to a terminal.
+ */
+ if (fcntl (2, F_GETFL, &flag) == -1 && errno == EBADF){
+ stderr_fd = open ("/dev/tty", O_RDWR);
+ if (stderr_fd == -1){
+ stderr_fd = open ("/dev/null", O_RDWR);
+ if (stderr_fd == -1)
+ exit (1);
+ }
+
+ if (stderr_fd != 2)
+ while (dup2 (stderr_fd, 2) == -1 && errno == EINTR)
+ ;
+ }
+
+ /* Close any file descriptor we do not use */
+ open_max = sysconf (_SC_OPEN_MAX);
+ for (i = 3; i < open_max; i++){
+ close (i);
+ }
+
+ /* Check sensible resource limits */
+ for (i = 0; sensible_limits [i].value != -1; i++){
+ struct rlimit rlim;
+
+ if (getrlimit (sensible_limits [i].limit, &rlim) != 0)
+ continue;
+
+ if (rlim.rlim_cur != RLIM_INFINITY &&
+ rlim.rlim_cur < sensible_limits [i].value){
+ fprintf (stderr, "Living environment not ok\n");
+ exit (1);
+ }
+ }
+
+ /* Make sure SIGIO/SIGINT is SIG_IGN */
+ {
+ struct sigaction sa;
+ sigset_t sigset;
+
+ sa.sa_handler = SIG_IGN;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ sigemptyset(&sigset);
+ sigaddset(&sigset, SIGIO);
+ sigaddset(&sigset, SIGINT);
+ sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+
+ sigaction (SIGIO, &sa, NULL);
+ sigaction (SIGINT, &sa, NULL);
+ }
+}
+
+int
+main (int argc, char *argv [])
+{
+ int res, n;
+ void *tag;
+ GnomePtyOps op;
+
+ sanity_checks ();
+
+ pwent = getpwuid (getuid ());
+ if (pwent)
+ login_name = pwent->pw_name;
+ else {
+ sprintf (login_name_buffer, "#%u", (unsigned int)getuid ());
+ login_name = login_name_buffer;
+ }
+
+ display_name = getenv ("DISPLAY");
+ if (!display_name)
+ display_name = "localhost";
+
+
+ if (init_msg_pass () == -1)
+ exit (1);
+
+ for (;;){
+ res = n_read (STDIN_FILENO, &op, sizeof (op));
+
+ if (res != sizeof (op) || res == -1){
+ shutdown_helper ();
+ return 1;
+ }
+
+ if (res == 0) {
+ shutdown_helper ();
+ return 1;
+ }
+
+ switch (op){
+ case GNOME_PTY_OPEN_PTY_UTMP:
+ open_ptys (1, 0, 0);
+ break;
+
+ case GNOME_PTY_OPEN_PTY_UWTMP:
+ open_ptys (1, 1, 0);
+ break;
+
+ case GNOME_PTY_OPEN_PTY_WTMP:
+ 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, 0);
+ break;
+
+ case GNOME_PTY_RESET_TO_DEFAULTS:
+ break;
+
+ case GNOME_PTY_CLOSE_PTY:
+ n = n_read (STDIN_FILENO, &tag, sizeof (tag));
+ if (n == -1 || n != sizeof (tag)){
+ shutdown_helper ();
+ return 1;
+ }
+ close_pty_pair (tag);
+ break;
+ }
+
+ }
+
+ return 0;
+}
+
diff --git a/gnome-pty-helper/gnome-pty.h b/gnome-pty-helper/gnome-pty.h
new file mode 100644
index 0000000..186b81a
--- /dev/null
+++ b/gnome-pty-helper/gnome-pty.h
@@ -0,0 +1,21 @@
+#ifndef GNOME_PTY_H
+#define GNOME_PTY_H
+
+typedef enum {
+ 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_RESET_TO_DEFAULTS,
+ GNOME_PTY_CLOSE_PTY
+} GnomePtyOps;
+
+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
diff --git a/gnome-pty-helper/gnome-utmp.c b/gnome-pty-helper/gnome-utmp.c
new file mode 100644
index 0000000..c3fcc77
--- /dev/null
+++ b/gnome-pty-helper/gnome-utmp.c
@@ -0,0 +1,348 @@
+/*
+ * utmp/wtmp file updating
+ *
+ * Authors:
+ * Miguel de Icaza (miguel@gnu.org).
+ * Timur I. Bakeyev (timur@gnu.org).
+ *
+ * FIXME: Do we want to register the PID of the process running *under* the subshell
+ * or the PID of the parent process? (we are doing the latter now).
+ *
+ * FIXME: Solaris (utmpx) stuff need to be checked.
+ */
+
+#include <config.h>
+#include <sys/types.h>
+#include <sys/file.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <errno.h>
+
+#if defined(TIME_WITH_SYS_TIME)
+# include <sys/time.h>
+#include <time.h>
+#else
+# if defined(HAVE_SYS_TIME_H)
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+#include <utmp.h>
+
+#if defined(HAVE_LASTLOG_H)
+# include <lastlog.h>
+#endif
+
+#if defined(HAVE_PATHS_H)
+# include <paths.h>
+#endif
+
+#if defined(HAVE_UTMPX_H)
+# include <utmpx.h>
+#endif
+
+#if defined(HAVE_TTYENT_H)
+# include <ttyent.h>
+#endif
+
+#include "gnome-pty.h"
+#include "gnome-login-support.h"
+
+
+
+#if !defined(UTMP_OUTPUT_FILENAME)
+# if defined(UTMP_FILE)
+# define UTMP_OUTPUT_FILENAME UTMP_FILE
+# elif defined(_PATH_UTMP) /* BSD systems */
+# define UTMP_OUTPUT_FILENAME _PATH_UTMP
+# else
+# define UTMP_OUTPUT_FILENAME "/etc/utmp"
+# endif
+#endif
+
+#if !defined(WTMP_OUTPUT_FILENAME)
+# if defined(WTMPX_FILE)
+# define WTMP_OUTPUT_FILENAME WTMPX_FILE
+# elif defined(_PATH_WTMPX)
+# define WTMP_OUTPUT_FILENAME _PATH_WTMPX
+# elif defined(WTMPX_FILENAME)
+# define WTMP_OUTPUT_FILENAME WTMPX_FILENAME
+# elif defined(WTMP_FILE)
+# define WTMP_OUTPUT_FILENAME WTMP_FILE
+# elif defined(_PATH_WTMP) /* BSD systems */
+# define WTMP_OUTPUT_FILENAME _PATH_WTMP
+# else
+# define WTMP_OUTPUT_FILENAME "/etc/wtmp"
+# endif
+#endif
+
+#if defined(_PATH_LASTLOG) /* BSD systems */
+# define LASTLOG_OUTPUT_FILE _PATH_LASTLOG
+#else
+# define LASTLOG_OUTPUT_FILE "/var/log/lastlog"
+#endif
+
+#if defined(HAVE_UPDWTMPX)
+#define update_wtmp updwtmpx
+#elif defined(HAVE_UPDWTMP)
+#define update_wtmp updwtmp
+#else /* !HAVE_UPDWTMPX && !HAVE_UPDWTMP */
+static void
+update_wtmp (char *file, UTMP *putmp)
+{
+ int fd, times = 3;
+#if defined(HAVE_FCNTL)
+ struct flock lck;
+
+ lck.l_whence = SEEK_END;
+ lck.l_len = 0;
+ lck.l_start = 0;
+ lck.l_type = F_WRLCK;
+#endif
+
+ if ((fd = open (file, O_WRONLY|O_APPEND, 0)) < 0)
+ return;
+
+#if defined(HAVE_FCNTL) || defined(HAVE_FLOCK)
+ while (times--)
+# if defined(HAVE_FCNTL)
+ if ((fcntl (fd, F_SETLK, &lck) < 0)){
+ if (errno != EAGAIN && errno != EACCES){
+# elif defined(HAVE_FLOCK)
+ if (flock(fd, LOCK_EX | LOCK_NB) < 0){
+ if (errno != EWOULDBLOCK){
+# endif
+ close (fd);
+ return;
+ }
+ sleep (1); /*?!*/
+ } else
+ break;
+#endif /* HAVE_FCNTL || HAVE_FLOCK */
+
+ lseek (fd, 0, SEEK_END);
+ write (fd, putmp, sizeof(UTMP));
+
+ /* unlock the file */
+#if defined(HAVE_FCNTL)
+ lck.l_type = F_UNLCK;
+ fcntl (fd, F_SETLK, &lck);
+#elif defined(HAVE_FLOCK)
+ flock (fd, LOCK_UN);
+#endif
+ close (fd);
+}
+#endif /* !HAVE_GETUTMPX */
+
+
+#if defined(HAVE_GETUTMPX)
+static void
+update_utmp (UTMP *ut)
+{
+ setutxent();
+ pututxline (ut);
+}
+#elif defined(HAVE_GETUTENT)
+static void
+update_utmp (UTMP *ut)
+{
+ setutent();
+ pututline (ut);
+}
+#elif defined(HAVE_GETTTYENT)
+/* This variant is sutable for most BSD */
+static void
+update_utmp (UTMP *ut)
+{
+ struct ttyent *ty;
+ int fd, pos = 0;
+
+ if ((fd = open (UTMP_OUTPUT_FILENAME, O_RDWR|O_CREAT, 0644)) < 0)
+ return;
+
+ setttyent ();
+ while ((ty = getttyent ()) != NULL)
+ {
+ ++pos;
+ if (strncmp (ty->ty_name, ut->ut_line, sizeof (ut->ut_line)) == 0)
+ {
+ lseek (fd, (off_t)(pos * sizeof(UTMP)), SEEK_SET);
+ write(fd, ut, sizeof(UTMP));
+ }
+ }
+ endttyent ();
+
+ close(fd);
+}
+#else
+#define update_utmp(ut)
+#endif
+
+#if !defined(HAVE_LASTLOG)
+#define update_lastlog(login_name, ut)
+#else
+static void
+update_lastlog(char* login_name, UTMP *ut)
+{
+ struct passwd *pwd;
+ struct lastlog ll;
+ int fd;
+
+ if ((fd = open(LASTLOG_OUTPUT_FILE, O_WRONLY, 0)) < 0)
+ return;
+
+ if ((pwd=getpwnam(login_name)) == NULL)
+ return;
+
+ memset (&ll, 0, sizeof(ll));
+
+ lseek (fd, (off_t)pwd->pw_uid * sizeof (ll), SEEK_SET);
+
+ time (&ll.ll_time);
+
+ strncpy (ll.ll_line, ut->ut_line, sizeof (ll.ll_line));
+
+#if defined(HAVE_UT_UT_HOST)
+ if (ut->ut_host)
+ strncpy (ll.ll_host, ut->ut_host, sizeof (ll.ll_host));
+#endif
+
+ write (fd, (void *)&ll, sizeof (ll));
+ close (fd);
+}
+#endif /* HAVE_LASTLOG */
+
+void
+write_logout_record (void *data, int utmp, int wtmp)
+{
+ UTMP put, *ut = data;
+
+ memset (&put, 0, sizeof(UTMP));
+
+#if defined(HAVE_UT_UT_TYPE)
+ put.ut_type = DEAD_PROCESS;
+#endif
+#if defined(HAVE_UT_UT_ID)
+ strncpy (put.ut_id, ut->ut_id, sizeof (put.ut_id));
+#endif
+
+ strncpy (put.ut_line, ut->ut_line, sizeof (put.ut_line));
+
+#if defined(HAVE_UT_UT_TV)
+ gettimeofday ((struct timeval*) &put.ut_tv, NULL);
+#elif defined(HAVE_UT_UT_TIME)
+ time (&put.ut_time);
+#endif
+
+ if (utmp)
+ update_utmp (&put);
+
+ if (wtmp)
+ update_wtmp (WTMP_OUTPUT_FILENAME, &put);
+
+ free (ut);
+}
+
+void *
+write_login_record (char *login_name, char *display_name, char *term_name, int utmp, int wtmp, int lastlog)
+{
+ UTMP *ut;
+ char *pty = term_name;
+
+ if((ut=(UTMP *) malloc (sizeof (UTMP))) == NULL)
+ return NULL;
+
+ memset (ut, 0, sizeof (UTMP));
+
+#if defined(HAVE_UT_UT_NAME)
+ strncpy (ut->ut_name, login_name, sizeof (ut->ut_name));
+#elif defined(HAVE_UT_UT_USER)
+ strncpy (ut->ut_user, login_name, sizeof (ut->ut_user));
+#endif
+
+ /* This shouldn't happen */
+ if (strncmp (pty, "/dev/", 5) == 0)
+ pty += 5;
+
+#if defined(HAVE_STRRCHR)
+ {
+ char *p;
+
+ if (strncmp (pty, "pts", 3) &&
+ (p = strrchr (pty, '/')) != NULL)
+ pty = p + 1;
+ }
+#endif
+
+#if defined(HAVE_UT_UT_ID)
+ /* Just a safe-guard */
+ ut->ut_id [0] = '\0';
+
+ /* BSD-like terminal name */
+ if (strncmp (pty, "pts", 3) == 0 ||
+ strncmp (pty, "pty", 3) == 0 ||
+ strncmp (pty, "tty", 3) == 0) {
+ strncpy (ut->ut_id, pty+3, sizeof (ut->ut_id));
+ }
+ else {
+ unsigned int num;
+ char buf[10];
+ /* Try to get device number and convert it to gnome-terminal # */
+ if (sscanf (pty, "%*[^0-9a-f]%x", &num) == 1) {
+ sprintf (buf, "gt%02.2x", num);
+ strncpy (ut->ut_id, buf, sizeof (ut->ut_id));
+ }
+ }
+#endif
+
+ /* For utmpx ut_line should be null terminated */
+ /* We do that for both cases to be sure */
+ strncpy (ut->ut_line, pty, sizeof (ut->ut_line));
+ ut->ut_line[sizeof (ut->ut_line)-1] = '\0';
+
+ /* We want parent's pid, not our own */
+#if defined(HAVE_UT_UT_PID)
+ ut->ut_pid = getppid ();
+#endif
+
+#if defined(HAVE_UT_UT_TYPE)
+ ut->ut_type = USER_PROCESS;
+#endif
+ /* If structure has ut_tv it doesn't need ut_time */
+#if defined(HAVE_UT_UT_TV)
+ gettimeofday ((struct timeval*) &(ut->ut_tv), NULL);
+#elif defined(HAVE_UT_UT_TIME)
+ time (&ut->ut_time);
+#endif
+ /* ut_ host supposed to be null terminated or len should */
+ /* be specifid in additional field. We do both :) */
+#if defined(HAVE_UT_UT_HOST)
+ strncpy (ut->ut_host, display_name, sizeof (ut->ut_host));
+ ut->ut_host [sizeof (ut->ut_host)-1] = '\0';
+# if defined(HAVE_UT_UT_SYSLEN)
+ ut->ut_syslen = strlen (ut->ut_host);
+# endif
+#endif
+ if (utmp)
+ update_utmp (ut);
+
+ if (wtmp)
+ update_wtmp (WTMP_OUTPUT_FILENAME, ut);
+
+ if (lastlog)
+ update_lastlog(login_name, ut);
+
+ return ut;
+}
+
+void *
+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, lastlog);
+}