From 57079e3acba29917c5a35cb5cdcdab61cd5d7731 Mon Sep 17 00:00:00 2001 From: "vivian, zhang" Date: Sun, 3 Jun 2012 11:39:20 +0800 Subject: [PATCH] Initial import package mingetty: A compact getty program for virtual consoles only --- COPYING | 340 +++++++++++++++++++++++++++++ Makefile | 17 ++ mingetty-0.9.4-autologin.patch | 130 ++++++++++++ mingetty.8 | 118 +++++++++++ mingetty.c | 436 ++++++++++++++++++++++++++++++++++++++ packaging/mingetty-1.00-opt.patch | 11 + packaging/mingetty.changes | 2 + packaging/mingetty.spec | 126 +++++++++++ 8 files changed, 1180 insertions(+) create mode 100644 COPYING create mode 100644 Makefile create mode 100644 mingetty-0.9.4-autologin.patch create mode 100644 mingetty.8 create mode 100644 mingetty.c create mode 100644 packaging/mingetty-1.00-opt.patch create mode 100644 packaging/mingetty.changes create mode 100644 packaging/mingetty.spec diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..dc63aac --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 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. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, 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 software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, 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 redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +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 give any other recipients of the Program a copy of this License +along with the Program. + +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 Program or any portion +of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +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 Program, 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 Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) 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; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, 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 executable. 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. + +If distribution of executable or 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 counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program 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. + + 5. 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 Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program 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. + + 7. 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 Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program 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 Program. + +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. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program 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. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 Program +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 Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, 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 + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. 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 PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), 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 Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. 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. + + + Copyright (C) 19yy + + 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. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e66d843 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +DESTDIR= +CC=gcc +CFLAGS=-O2 -Wall -W -pipe -D_GNU_SOURCE +MANDIR=/usr/share/man/man8 +SBINDIR=/sbin + +all: mingetty + +install: all + install -m 0755 mingetty $(DESTDIR)$(SBINDIR) + install -m 0644 mingetty.8 $(DESTDIR)$(MANDIR) + +mingetty: mingetty.o + +clean: + rm -f *.o mingetty + diff --git a/mingetty-0.9.4-autologin.patch b/mingetty-0.9.4-autologin.patch new file mode 100644 index 0000000..27018e0 --- /dev/null +++ b/mingetty-0.9.4-autologin.patch @@ -0,0 +1,130 @@ +--- mingetty-0.9.4/mingetty.c.autologin Sun Nov 26 10:54:13 2000 ++++ mingetty-0.9.4/mingetty.c Sun Nov 26 10:28:29 2000 +@@ -49,6 +49,20 @@ + #endif + + #ifdef linux ++/* Autologin stuff. Currently Linux-specific, since there's no ++ standard way of getting the system boot time. The kernel.h and the ++ sysinfo prototype are used to get the system uptime under Linux. */ ++#include ++int sysinfo(struct sysinfo *info); ++ ++/* AUTO_LAST points to a timestamp file used to limit autologins to ++ one per system boot. */ ++#define AUTO_LAST "/var/log/autologin" ++ ++/* AUTO_TTY is the tty on which autologins will be accepted. If set ++ to an empty string, autologins will be accepted on any tty. */ ++#define AUTO_TTY "tty1" ++ + #include + #define USE_SYSLOG + #endif +@@ -80,7 +94,8 @@ + static int noclear = 0; + /* Print the whole string of gethostname() instead of just until the next "." */ + static int longhostname = 0; +- ++/* If supplied, attempt an automatic login with this username. */ ++static char *autologin_name = NULL; + + /* + * output error messages +@@ -385,6 +400,62 @@ + return logname; + } + ++/* ++ * autologin_ok -- returns 1 if it's okay to auto-login when: ++ * this login is from /dev/tty1; and ++ * there was a login name passed with the --autologin option; and ++ * the autologin_name contains only "nice" characters; and ++ * this is the first autologin attempt since the last boot; ++ * return 0 otherwise. ++ */ ++static int autologin_ok(void) ++{ ++ char c, *cp; ++ int stat_err, fd; ++ struct sysinfo info; ++ struct stat sbuf; ++ ++ /* Autologins are restricted to AUTO_TTY if non-empty. */ ++ if (AUTO_TTY[0] && strcmp(tty, AUTO_TTY)) ++ return 0; ++ ++ /* An all-alphanumeric autologin name must be supplied. */ ++ if (autologin_name == NULL || autologin_name[0] == '\0') ++ return 0; ++ for (cp = autologin_name; (c = *cp); cp++) ++ if (!isalnum(c) && c != '_') ++ return 0; ++ ++ /* Get the uptime in info.uptime, and the last autologin time ++ in sbuf.st_mtime. */ ++ sysinfo(&info); ++ stat_err = stat(AUTO_LAST, &sbuf); ++ ++ /* If a stat error other than "no such file" occurs, I don't ++ know what went wrong, so I'll proceed with caution by ++ denying the autologin request. */ ++ if (stat_err && errno != ENOENT) ++ return 0; ++ ++ /* If there's been an autologin granted since the last boot, ++ deny this and any subsequent attempts. Note that this test ++ is skipped if the AUTO_LAST file doesn't exist. */ ++ if (!stat_err && time(NULL) - info.uptime < sbuf.st_mtime) ++ return 0; ++ ++ /* Create the AUTO_LAST file. The mtime of this file provides ++ a persistent record of the last time that an autologin ++ request was granted. Deny the autologin request if either ++ the file open or file close fails. */ ++ if ((fd=open(AUTO_LAST, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) ++ return 0; ++ if (close(fd) != 0) ++ return 0; ++ ++ /* All tests are okay, so grant the autologin request. */ ++ return 1; ++} ++ + static void usage (void) + { + error ("usage: '%s tty' with e.g. tty=tty1", progname); +@@ -393,6 +464,7 @@ + static struct option const long_options[] = { + { "noclear", no_argument, &noclear, 1}, + { "long-hostname", no_argument, &longhostname, 1}, ++ { "autologin", required_argument, NULL, 'a'}, + { 0, 0, 0, 0 } + }; + +@@ -418,6 +490,9 @@ + switch (c) { + case 0: + break; ++ case 'a': ++ autologin_name = optarg; ++ break; + default: + usage (); + } +@@ -438,9 +513,12 @@ + /* flush input and output queues, important for modems */ + ioctl (0, TCFLSH, 2); + +- while ((logname = get_logname ()) == 0); +- +- execl (_PATH_LOGIN, _PATH_LOGIN, "--", logname, NULL); ++ if (autologin_ok()) { ++ execl (_PATH_LOGIN, _PATH_LOGIN, "-f", autologin_name, NULL); ++ } else { ++ while ((logname = get_logname ()) == 0) ; ++ execl (_PATH_LOGIN, _PATH_LOGIN, "--", logname, NULL); ++ } + error ("%s: can't exec " _PATH_LOGIN ": %s", tty, sys_errlist[errno]); + exit (0); + } diff --git a/mingetty.8 b/mingetty.8 new file mode 100644 index 0000000..a7b8886 --- /dev/null +++ b/mingetty.8 @@ -0,0 +1,118 @@ +.TH MINGETTY 8 "6 Apr 1996" "Debian-Local" "Linux Programmer's Manual" +.SH NAME +mingetty \- minimal getty for consoles +.SH SYNOPSIS +.B mingetty +[\-\-noclear] [\-\-nonewline] [\-\-noissue] [\-\-nohangup] [\-\-nohostname] +[\-\-long\-hostname] [\-\-loginprog=/bin/login] [\-\-nice=10] [\-\-delay=5] +[\-\-chdir=/home] [\-\-chroot=/chroot] [\-\-autologin username] +[\-\-loginpause] +.I tty +.PP +.SH DESCRIPTION +.B mingetty +is a minimal getty for use on virtual consoles. +Unlike +.BR agetty (8), +.B mingetty +is not suitable for serial lines. +I recommend using +.BR mgetty (8) +for this purpose. +.PP +.SH OPTIONS +.TP +.B \-\-noclear +Do not clear the screen before prompting for the login name (the screen +is normally cleared). +.TP +.B \-\-nonewline +Do not print a newline before writing out /etc/issue. +.TP +.B \-\-noissue +Do not output /etc/issue. +.TP +.B \-\-nohangup +Do not call vhangup() to disable writing to this tty by +other applications. +.TP +.B \-\-nohostname +Do not print the hostname before the login prompt. +.TP +.B \-\-long\-hostname +By default the hostname is only printed until the first dot. +With this option enabled, the full text from gethostname() is shown. +.TP +.B \-\-loginprog /bin/login +Change the login app. +.TP +.B \-\-nice 10 +Change the priority by calling nice(). +.TP +.B \-\-delay 5 +Sleep this many seconds after startup of mingetty. +.TP +.B \-\-chdir /home +Change into this directory before calling the login prog. +.TP +.B \-\-chroot /chroot +Call chroot() with this directory name. +.TP +.B \-\-autologin username +Log the specified user automatically in without asking for +a login name and password. Check the \-f option from +.B /bin/login +for this. +.TP +.B \-\-loginpause +Wait for any key before dropping to the login prompt. +Can be combined with \fB\-\-autologin\fR to save memory by lazily spawning +shells. +.PP +.SH "ISSUE ESCAPES" +.B mingetty +recognizes the following escapes sequences which might be embedded in the +.I /etc/issue +file: +.IP \fB\ed\fP +insert current day (localtime), +.IP \fB\el\fP +insert line on which +.B mingetty +is running, +.IP \fB\em\fP +inserts machine architecture (uname -m), +.IP \fB\en\fP +inserts machine's network node hostname (uname -n), +.IP \fB\eo\fP +inserts domain name, +.IP \fB\er\fP +inserts operating system release (uname -r), +.IP \fB\et\fP +insert current time (localtime), +.IP \fB\es\fP +inserts operating system name, +.IP \fB\eu\fP +resp. \fB\eU\fP +the current number of users which are currently logged in. +\\U inserts "\fIn\fP users", where as \\u only inserts "\fIn\fP". +.IP \fB\ev\fP +inserts operating system version (uname -v). +.PP +.SH EXAMPLE +"\fBLinux\ eos\ i386\ #1\ Tue\ Mar\ 19\ 21:54:09\ MET\ 1996\fP" was produced +by putting "\fB\\s\ \\n\ \\m\ \\v\fP" into +.IR /etc/issue . +.PP +.SH FILES +.IR /etc/issue , +.IR /var/run/utmp . +.PP +.SH "SEE ALSO" +.BR mgetty (8), +.BR agetty (8). +.PP +.SH AUTHOR +Copyright \(co 1996 Florian La Roche . +Man-page written by David Frey and +Florian La Roche. diff --git a/mingetty.c b/mingetty.c new file mode 100644 index 0000000..084ebdf --- /dev/null +++ b/mingetty.c @@ -0,0 +1,436 @@ +/* mingetty.c + * + * Copyright (C) 1996 Florian La Roche + * Copyright (C) 2002, 2003 Red Hat, Inc + * + * This getty can only be used as a small console getty. Look at mgetty + * for a real modem getty. + * + * 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. + */ + +/* TODO: + * - autologin only at first login + * - /etc/mingetty.conf that can be used instead of /etc/inittab for + * command line options + * - Can UTF-8 setup be done within mingetty? + * - Also add /bin/login-type functionality in here? + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* name of this program (argv[0]) */ +static char *progname; +/* on which tty line are we sitting? (e.g. tty1) */ +static char *tty; +/* some information about this host */ +static struct utsname uts; +/* the hostname */ +static char hn[MAXHOSTNAMELEN + 1]; +/* process and session ID of this program */ +static pid_t pid, sid; +/* login program invoked */ +static char *loginprog = "/bin/login"; +/* Do not send a reset string to the terminal. */ +static int noclear = 0; +/* Do not print a newline. */ +static int nonewline = 0; +/* Do not print /etc/issue. */ +static int noissue = 0; +/* Do not call vhangup() on the tty. */ +static int nohangup = 0; +/* Do not print any hostname. */ +static int nohostname = 0; +/* Print the whole string of gethostname() instead of just until the next "." */ +static int longhostname = 0; +/* time to wait, seconds */ +static int delay = 0; +/* chroot directory */ +static char *ch_root = NULL; +/* working directory to change into */ +static char *ch_dir = NULL; +/* 'nice' level of the program */ +static int priority = 0; +/* automatic login with this user */ +static char *autologin = NULL; +/* try to read a char before dropping to login prompt */ +static int loginpause = 0; + +/* error() - output error messages */ +static void error (const char *fmt, ...) +{ + va_list va_alist; + + va_start (va_alist, fmt); + openlog (progname, LOG_PID, LOG_AUTH); + vsyslog (LOG_ERR, fmt, va_alist); + /* no need, we exit anyway: closelog (); */ + va_end (va_alist); + sleep (5); + exit (EXIT_FAILURE); +} + +/* update_utmp() - update our utmp entry */ +static void update_utmp (void) +{ + struct utmp ut; + struct utmp *utp; + time_t cur_time; + + setutent (); + while ((utp = getutent ())) + if (utp->ut_type == INIT_PROCESS && utp->ut_pid == pid) + break; + + if (utp) { + memcpy (&ut, utp, sizeof (ut)); + } else { + /* some inits don't initialize utmp... */ + const char *x = tty; + memset (&ut, 0, sizeof (ut)); + if (strncmp (x, "tty", 3) == 0) + x += 3; + if (strlen (x) > sizeof (ut.ut_id)) + x += strlen (x) - sizeof (ut.ut_id); + strncpy (ut.ut_id, x, sizeof (ut.ut_id)); + } + + strncpy (ut.ut_user, "LOGIN", sizeof (ut.ut_user)); + strncpy (ut.ut_line, tty, sizeof (ut.ut_line)); + time (&cur_time); + ut.ut_time = cur_time; + ut.ut_type = LOGIN_PROCESS; + ut.ut_pid = pid; + ut.ut_session = sid; + + pututline (&ut); + endutent (); + + updwtmp (_PATH_WTMP, &ut); +} + +/* open_tty - set up tty as standard { input, output, error } */ +static void open_tty (void) +{ + struct sigaction sa, sa_old; + char buf[40]; + int fd; + + /* Set up new standard input. */ + if (tty[0] == '/') + strcpy (buf, tty); + else { + strcpy (buf, "/dev/"); + strcat (buf, tty); + } + /* There is always a race between this reset and the call to + vhangup() that s.o. can use to get access to your tty. */ + if (chown (buf, 0, 0) || chmod (buf, 0600)) + if (errno != EROFS) + error ("%s: %s", tty, strerror (errno)); + + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + sigemptyset (&sa.sa_mask); + sigaction (SIGHUP, &sa, &sa_old); + + /* vhangup() will replace all open file descriptors in the kernel + that point to our controlling tty by a dummy that will deny + further reading/writing to our device. It will also reset the + tty to sane defaults, so we don't have to modify the tty device + for sane settings. We also get a SIGHUP/SIGCONT. + */ + if ((fd = open (buf, O_RDWR, 0)) < 0) + error ("%s: cannot open tty: %s", tty, strerror (errno)); + if (ioctl (fd, TIOCSCTTY, (void *) 1) == -1) + error ("%s: no controlling tty: %s", tty, strerror (errno)); + if (!isatty (fd)) + error ("%s: not a tty", tty); + + if (nohangup == 0) { + if (vhangup ()) + error ("%s: vhangup() failed", tty); + /* Get rid of the present stdout/stderr. */ + close (2); + close (1); + close (0); + close (fd); + if ((fd = open (buf, O_RDWR, 0)) != 0) + error ("%s: cannot open tty: %s", tty, + strerror (errno)); + if (ioctl (fd, TIOCSCTTY, (void *) 1) == -1) + error ("%s: no controlling tty: %s", tty, + strerror (errno)); + } + /* Set up stdin/stdout/stderr. */ + if (dup2 (fd, 0) != 0 || dup2 (fd, 1) != 1 || dup2 (fd, 2) != 2) + error ("%s: dup2(): %s", tty, strerror (errno)); + if (fd > 2) + close (fd); + + /* Write a reset string to the terminal. This is very linux-specific + and should be checked for other systems. */ + if (noclear == 0) + write (0, "\033c", 2); + + sigaction (SIGHUP, &sa_old, NULL); +} + +static void output_special_char (unsigned char c) +{ + switch (c) { + case 's': + printf ("%s", uts.sysname); + break; + case 'n': + printf ("%s", uts.nodename); + break; + case 'r': + printf ("%s", uts.release); + break; + case 'v': + printf ("%s", uts.version); + break; + case 'm': + printf ("%s", uts.machine); + break; + case 'o': + printf ("%s", uts.domainname); + break; + case 'd': + case 't': + { + time_t cur_time; + struct tm *tm; +#if 0 + char buff[20]; + + time (&cur_time); + tm = localtime (&cur_time); + strftime (buff, sizeof (buff), + c == 'd'? "%a %b %d %Y" : "%X", tm); + fputs (buff, stdout); + break; +#else + time (&cur_time); + tm = localtime (&cur_time); + if (c == 'd') /* ISO 8601 */ + printf ("%d-%02d-%02d", 1900 + tm->tm_year, + tm->tm_mon + 1, tm->tm_mday); + else + printf ("%02d:%02d:%02d", tm->tm_hour, + tm->tm_min, tm->tm_sec); + break; +#endif + } + + case 'l': + printf ("%s", tty); + break; + case 'u': + case 'U': + { + int users = 0; + struct utmp *ut; + setutent (); + while ((ut = getutent ())) + if (ut->ut_type == USER_PROCESS) + users++; + endutent (); + printf ("%d", users); + if (c == 'U') + printf (" user%s", users == 1 ? "" : "s"); + break; + } + default: + putchar (c); + } +} + +/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */ +static void do_prompt (int showlogin) +{ + FILE *fd; + int c; + + if (nonewline == 0) + putchar ('\n'); + if (noissue == 0 && (fd = fopen ("/etc/issue", "r"))) { + while ((c = getc (fd)) != EOF) { + if (c == '\\') + output_special_char (getc (fd)); + else + putchar (c); + } + fclose (fd); + } + if (loginpause) { + puts ("[press ENTER to login]"); + getc (stdin); + } + if (nohostname == 0) + printf ("%s ", hn); + if (showlogin) + printf ("login: "); + fflush (stdout); +} + +static char *get_logname (void) +{ + static char logname[40]; + char *bp; + unsigned char c; + + tcflush (0, TCIFLUSH); /* flush pending input */ + for (*logname = 0; *logname == 0;) { + do_prompt (1); + for (bp = logname;;) { + if (read (0, &c, 1) < 1) { + if (errno == EINTR || errno == EIO + || errno == ENOENT) + exit (EXIT_SUCCESS); + error ("%s: read: %s", tty, strerror (errno)); + } + if (c == '\n' || c == '\r') { + *bp = 0; + break; + } else if (!isprint (c)) + error ("%s: invalid character 0x%x in login" + " name", tty, c); + else if ((size_t)(bp - logname) >= sizeof (logname) - 1) + error ("%s: too long login name", tty); + else + *bp++ = c; + } + } + return logname; +} + +static void usage (void) +{ + error ("usage: '%s [--noclear] [--nonewline] [--noissue] " + "[--nohangup] [--nohostname] [--long-hostname] " + "[--loginprog=/bin/login] [--nice=10] [--delay=10] " + "[--chdir=/home] [--chroot=/chroot] [--autologin=user] " + "[--loginpause] " + "tty' with e.g. tty=tty1", progname); +} + +static struct option const long_options[] = { + { "autologin", required_argument, NULL, 'a' }, + { "loginpause", no_argument, &loginpause, 'p' }, + { "chdir", required_argument, NULL, 'w' }, + { "chroot", required_argument, NULL, 'r' }, + { "delay", required_argument, NULL, 'd' }, + { "noclear", no_argument, &noclear, 1 }, + { "nonewline", no_argument, &nonewline, 1 }, + { "noissue", no_argument, &noissue, 1 }, + { "nohangup", no_argument, &nohangup, 1 }, + { "no-hostname", no_argument, &nohostname, 1 }, /* compat option */ + { "nohostname", no_argument, &nohostname, 1 }, + { "loginprog", required_argument, NULL, 'l' }, + { "long-hostname", no_argument, &longhostname, 1 }, + { "nice", required_argument, NULL, 'n' }, + { 0, 0, 0, 0 } +}; + +int main (int argc, char **argv) +{ + char *logname, *s; + int c; + + progname = argv[0]; + if (!progname) + progname = "mingetty"; + uname (&uts); + gethostname (hn, MAXHOSTNAMELEN); + hn[MAXHOSTNAMELEN] = '\0'; + pid = getpid (); + sid = getsid (0); +#if defined(s390) || defined(__s390__) + putenv ("TERM=dumb"); +#else + putenv ("TERM=linux"); +#endif + + while ((c = getopt_long (argc, argv, "a:p:d:l:n:w:r:", long_options, + (int *) 0)) != EOF) { + switch (c) { + case 0: + break; + case 'a': + autologin = optarg; + break; + case 'd': + delay = atoi (optarg); + break; + case 'l': + loginprog = optarg; + break; + case 'n': + priority = atoi (optarg); + break; + case 'r': + ch_root = optarg; + break; + case 'w': + ch_dir = optarg; + break; + default: + usage (); + } + } + if (longhostname == 0 && (s = strchr (hn, '.'))) + *s = '\0'; + tty = argv[optind]; + if (!tty) + usage (); + + if (strncmp (tty, "/dev/", 5) == 0) /* ignore leading "/dev/" */ + tty += 5; + + update_utmp (); + if (delay) + sleep (delay); + open_tty (); + if (autologin) { + do_prompt (0); + printf ("login: %s (automatic login)\n", autologin); + logname = autologin; + } else + while ((logname = get_logname ()) == 0) + /* do nothing */ ; + + if (ch_root) + chroot (ch_root); + if (ch_dir) + chdir (ch_dir); + if (priority) + nice (priority); + + execl (loginprog, loginprog, autologin? "-f" : "--", logname, NULL); + error ("%s: can't exec %s: %s", tty, loginprog, strerror (errno)); + sleep (5); + exit (EXIT_FAILURE); +} diff --git a/packaging/mingetty-1.00-opt.patch b/packaging/mingetty-1.00-opt.patch new file mode 100644 index 0000000..25fb27b --- /dev/null +++ b/packaging/mingetty-1.00-opt.patch @@ -0,0 +1,11 @@ +--- mingetty-1.00/Makefile.rpm Mon Mar 4 15:27:11 2002 ++++ mingetty-1.00/Makefile Mon Mar 4 15:27:34 2002 +@@ -1,6 +1,7 @@ + DESTDIR= + CC=gcc +-CFLAGS=-O2 -Wall -W -pipe -D_GNU_SOURCE ++CFLAGS=$(RPM_OPTS) -Wall -D_GNU_SOURCE ++LDFLAGS=$(RPM_OPTS) + MANDIR=/usr/share/man/man8 + SBINDIR=/sbin + diff --git a/packaging/mingetty.changes b/packaging/mingetty.changes new file mode 100644 index 0000000..437cf49 --- /dev/null +++ b/packaging/mingetty.changes @@ -0,0 +1,2 @@ +* Fri Jun 01 2012 vivian zhang - 1.08 +- Initial import for Tizen diff --git a/packaging/mingetty.spec b/packaging/mingetty.spec new file mode 100644 index 0000000..a394726 --- /dev/null +++ b/packaging/mingetty.spec @@ -0,0 +1,126 @@ +#specfile originally created for Fedora, modified for Moblin Linux +Summary: A compact getty program for virtual consoles only +Name: mingetty +Version: 1.08 +License: GPLv2+ +Release: 3.9 +Group: System/Base +URL: http://sourceforge.net/projects/mingetty/ +Source: http://downloads.sourceforge.net/%{name}/%{name}-%{version}.tar.gz +Patch: mingetty-1.00-opt.patch +BuildRoot: %{_tmppath}/%{name}-root + +%description +The mingetty program is a lightweight, minimalist getty program for +use only on virtual consoles. Mingetty is not suitable for serial +lines (you should use the mgetty program in that case). + +%prep +%setup -q +%patch -p1 + +%build +make "RPM_OPTS=$RPM_OPT_FLAGS" + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT/{sbin,%{_mandir}/man8} + +install -m 0755 mingetty $RPM_BUILD_ROOT/sbin/ +install -m 0644 mingetty.8 $RPM_BUILD_ROOT/%{_mandir}/man8/ + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +%doc COPYING +/sbin/mingetty +%doc %{_mandir}/man8/mingetty.* + +%changelog +* Wed Jul 23 2008 Martin Xu +- add %%doc to man file +* Tue Feb 19 2008 Fedora Release Engineering - 1.08-2 +- Autorebuild for GCC 4.3 +* Fri Jan 18 2008 Florian La Roche - 1.08-1 +- change Source: tag +- Bernardo Innocenti bernie at codewiz.org: add LDFLAGS to opt patch + to enable cross building on 64bit host +- release 1.08 with loginpause option from Bernardo Innocenti bernie at codewiz.org +* Tue Jan 8 2008 Florian La Roche - 1.07-8 +- add sf.net project url +- add dist macro to release +* Sun Jan 6 2008 Florian La Roche - 1.07-7 +- add rpmlint changes to .spec file from Jon Ciesla limb at jcomserv.net +* Tue Aug 21 2007 Florian La Roche - 1.07-6 +- rebuild +* Wed Jul 12 2006 Jesse Keating - 1.07-5.2.2 +- rebuild +* Fri Feb 10 2006 Jesse Keating - 1.07-5.2.1 +- bump again for double-long bug on ppc(64) +* Tue Feb 7 2006 Jesse Keating - 1.07-5.2 +- rebuilt for new gcc4.1 snapshot and glibc changes +* Fri Dec 9 2005 Jesse Keating +- rebuilt +* Wed Mar 2 2005 Karsten Hopp 1.07-5 +- build with gcc-4 +* Wed Feb 9 2005 Karsten Hopp 1.07-4 +- rebuilt +* Tue Jun 15 2004 Elliot Lee +- rebuilt +* Fri Feb 13 2004 Elliot Lee +- rebuilt +* Sat Jan 3 2004 Florian La Roche +- 1.07 +* Wed Jun 4 2003 Elliot Lee +- rebuilt +* Sat May 24 2003 Florian La Roche +- update to 1.06 +* Sat Apr 12 2003 Florian La Roche +- update to 1.05 +* Sun Mar 30 2003 Florian La Roche +- update to 1.04 +* Sat Feb 8 2003 Florian La Roche +- small source cleanups +* Wed Jan 22 2003 Tim Powers +- rebuilt +* Tue Nov 19 2002 Tim Powers +- rebuild on all arches +* Fri Jun 21 2002 Tim Powers +- automated rebuild +* Thu May 23 2002 Tim Powers +- automated rebuild +* Mon Mar 4 2002 Florian La Roche +- re-release as 1.00 +* Thu Jul 5 2001 Florian La Roche +- rebuild +* Wed Apr 11 2001 Bill Nottingham +- rebuild (missing ia64 packages) +* Fri Apr 6 2001 Florian La Roche +- fix man-page bug #34991 +- fix syslog() call to be more secure #17349 +* Thu Jan 11 2001 Florian La Roche +- set TERM=dumb for s390 console +* Mon Nov 13 2000 Oliver Paukstadt +- fgetc returns int not char +* Wed Jul 12 2000 Prospector +- automatic rebuild +* Sun Jun 18 2000 Matt Wilson +- use %%%%{_mandir} for man pages +* Thu Feb 3 2000 Bill Nottingham +- handle compressed man pages +* Sun Mar 21 1999 Cristian Gafton +- auto rebuild in the new build environment (release 10) +* Wed Jan 6 1999 Cristian Gafton +- build for glibc 2.1 +* Sun Aug 16 1998 Jeff Johnson +- build root +* Fri May 1 1998 Prospector System +- translations modified for de, fr, tr +* Thu Apr 30 1998 Cristian Gafton +- fixed build problems on intel and alpha for manhattan +* Tue Oct 21 1997 Donnie Barnes +- spec file cleanups +* Mon Jun 2 1997 Erik Troan + ~- built against glibc -- 2.7.4