add directory bin
This commit is contained in:
34
bin/qpl-init/README
Normal file
34
bin/qpl-init/README
Normal file
@@ -0,0 +1,34 @@
|
||||
Although there are other people working on init/getty/login,
|
||||
I couldn't wait. Being dumped into root is not so nice.
|
||||
|
||||
There is no getty here. I put /bin/login in the getty field of /etc/ttytab.
|
||||
|
||||
What is here:
|
||||
a patch to init/main.c that makes it exec /etc/init.
|
||||
init.c
|
||||
getttyent.c
|
||||
getttynam.c
|
||||
ttyent.h (from BSD)
|
||||
login.c
|
||||
|
||||
init.c:
|
||||
written based on sunos init(8) manpage. differences are
|
||||
that the -sb switches are ignored, the window="command" in
|
||||
/etc/ttytab is ignored, runs only /etc/rc and ignores
|
||||
the result code, utmp and wtmp are not updated, SIGTERM
|
||||
is ignored, does not create /etc/ttys, and any
|
||||
undiscovered bugs.
|
||||
since the manpage doesn't say how the getty entry in
|
||||
/etc/ttytab is parsed, using strtok seems reasonable.
|
||||
works for /dev/tty0 in 0.11. should be able to hang
|
||||
terminals off the serial ports, but i can't test it
|
||||
without terminals or cables.
|
||||
|
||||
getttyent.c, getttynam.c, ttyent.h:
|
||||
functions to read /etc/ttytab.
|
||||
|
||||
login.c:
|
||||
does the basic login stuff. accepts and ignores -p switch.
|
||||
uses stuff in getttyent.o and getttynam.o to set TERM.
|
||||
makes a better filler in /etc/ttytab than /bin/sh, making
|
||||
it easier to avoid being root.
|
||||
191
bin/qpl-init/getttyent/getttyent.c
Normal file
191
bin/qpl-init/getttyent/getttyent.c
Normal file
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
getttyent, getttynam, setttyent, endttyent for linux
|
||||
by qpliu@phoenix.princeton.edu 1992
|
||||
$Id$
|
||||
simple test appears to be duplicate the sun library version
|
||||
*/
|
||||
/*
|
||||
my computer is a puny 2meg 386sx, and can't run gcc.
|
||||
so I made cc1 on my account on a sun 4/490 (soon to be
|
||||
4/690MP, which is good because the load avg is usually 10-20),
|
||||
and compile to .s on the sun. however, it dies with
|
||||
SIGIOT when trying to optimize some stuff, thus this is
|
||||
a bit more contorted to make it compile
|
||||
*/
|
||||
#define GCC_O_BUSTED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ttyent.h>
|
||||
|
||||
#define ENTRY_SIZE 120 /* what's the standard way to do this? */
|
||||
|
||||
#define isspace(c) (c==' '||c=='\t'||c=='\n')
|
||||
|
||||
static struct ttyent *entry = (struct ttyent *)NULL;
|
||||
static FILE *tabfile = (FILE *)NULL;
|
||||
static char *tabbuf = (char *)NULL; /* buffer to read line of ttytab */
|
||||
|
||||
static void __read_ttyent (void);
|
||||
static void __free_bufs (void);
|
||||
|
||||
static void read_flags (char *, struct ttyent *);
|
||||
|
||||
struct ttyent *
|
||||
getttyent ()
|
||||
{
|
||||
if (!tabfile)
|
||||
if (!(tabfile = fopen (_PATH_TTYTAB, "r"))) {
|
||||
__free_bufs ();
|
||||
return (struct ttyent *)NULL;
|
||||
}
|
||||
|
||||
if (!entry)
|
||||
if (!(entry = (struct ttyent *)malloc(sizeof(struct ttyent)))) {
|
||||
fclose (tabfile);
|
||||
tabfile = (FILE *)NULL;
|
||||
return (struct ttyent *)NULL;
|
||||
}
|
||||
|
||||
if (!tabbuf)
|
||||
if (!(tabbuf = (char *)malloc (ENTRY_SIZE))) {
|
||||
fclose (tabfile);
|
||||
tabfile = (FILE *)NULL;
|
||||
__free_bufs ();
|
||||
return (struct ttyent *)NULL;
|
||||
}
|
||||
|
||||
__read_ttyent ();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
int
|
||||
setttyent ()
|
||||
{
|
||||
if (tabfile)
|
||||
rewind (tabfile);
|
||||
}
|
||||
|
||||
int
|
||||
endttyent ()
|
||||
{
|
||||
if (tabfile) {
|
||||
fclose (tabfile);
|
||||
tabfile = (FILE *)NULL;
|
||||
}
|
||||
|
||||
__free_bufs ();
|
||||
}
|
||||
|
||||
static void
|
||||
__free_bufs ()
|
||||
{
|
||||
if (tabbuf) {
|
||||
free (tabbuf);
|
||||
tabbuf = (char *)NULL;
|
||||
}
|
||||
|
||||
if (entry) {
|
||||
free (entry);
|
||||
entry = (struct ttyent *)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
__read_ttyent ()
|
||||
{
|
||||
char *c, dump[ENTRY_SIZE];
|
||||
/* one label for gotos, used when discarding bad lines */
|
||||
restart:
|
||||
*tabbuf = '#';
|
||||
c = tabbuf;
|
||||
while (*c == '#') { /* skip comments */
|
||||
if (!fgets (tabbuf, ENTRY_SIZE, tabfile)) { /* EOF */
|
||||
__free_bufs ();
|
||||
return;
|
||||
}
|
||||
c = tabbuf;
|
||||
while (isspace (*c) && *c) ++c;
|
||||
if (!*c) goto restart;
|
||||
}
|
||||
|
||||
/* discard the end of lines longer than ENTRY_SIZE */
|
||||
if (tabbuf [strlen (tabbuf) - 1] != '\n')
|
||||
do {
|
||||
if (!fgets (dump, ENTRY_SIZE, tabfile)) break;
|
||||
} while (dump [strlen (dump) - 1] != '\n');
|
||||
|
||||
entry->ty_name = c; /* get name */
|
||||
while (*c && !isspace (*c)) ++c;
|
||||
if (!*c) goto restart;
|
||||
*(c++) = '\0';
|
||||
while (*c && isspace (*c)) ++c;
|
||||
if (!*c) goto restart;
|
||||
if (*c == '"') { /* getty is quoted */
|
||||
entry->ty_getty = ++c;
|
||||
while (*c && *c != '"') ++c;
|
||||
if (!*c) goto restart;
|
||||
*(c++) = '\0';
|
||||
} else { /* getty in not quoted */
|
||||
entry->ty_getty = c;
|
||||
while (*c && !isspace (*c)) ++c;
|
||||
if (!*c) goto restart;
|
||||
*(c++) = '\0';
|
||||
}
|
||||
while (*c && isspace (*c)) ++c;
|
||||
if (!*c) goto restart;
|
||||
entry->ty_type = c; /* term type */
|
||||
while (*c && !isspace (*c)) ++c;
|
||||
if (*c) *(c++) = '\0';
|
||||
|
||||
/* defaults for optional parts */
|
||||
entry->ty_status = 0;
|
||||
entry->ty_window = (char *)NULL;
|
||||
entry->ty_comment = (char *)NULL;
|
||||
|
||||
/* check for remaining flags, don't truly enforce format */
|
||||
read_flags (c, entry);
|
||||
}
|
||||
|
||||
void
|
||||
read_flags (char *c, struct ttyent *entry)
|
||||
{
|
||||
int ts_off = strlen (_TTYS_OFF),
|
||||
ts_on = strlen (_TTYS_ON),
|
||||
ts_local = strlen (_TTYS_LOCAL),
|
||||
ts_secure = strlen (_TTYS_SECURE),
|
||||
ts_window = strlen (_TTYS_WINDOW);
|
||||
|
||||
while (*c) {
|
||||
if (!strncmp (c, _TTYS_OFF, ts_off)) {
|
||||
entry->ty_status &= ~TTY_ON;
|
||||
c += ts_off;
|
||||
} else if (!strncmp (c, _TTYS_ON, ts_on)) {
|
||||
entry->ty_status |= TTY_ON;
|
||||
c += ts_on;
|
||||
} else if (!strncmp (c, _TTYS_LOCAL, ts_local)) {
|
||||
entry->ty_status |= TTY_LOCAL;
|
||||
c += ts_local;
|
||||
} else if (!strncmp (c, _TTYS_SECURE, ts_secure)) {
|
||||
entry->ty_status |= TTY_SECURE;
|
||||
c += ts_secure;
|
||||
} else if (!strncmp (c, _TTYS_WINDOW, ts_window)) {
|
||||
c += ts_window;
|
||||
/* window="pathname of window thing" */
|
||||
if (*c) break;
|
||||
if (*++c) break; /* skip the = */
|
||||
if (*++c) break; /* skip the quote */
|
||||
entry->ty_window = c;
|
||||
while (*c && *c != '"') ++c;
|
||||
if (*c) *(c++) = '\0';
|
||||
} else if (*c == '#') {
|
||||
/* keep the trailing newline? */
|
||||
++c;
|
||||
while (isspace (*c)) ++c;
|
||||
entry->ty_comment = c;
|
||||
break;
|
||||
}
|
||||
while (isspace (*c)) ++c;
|
||||
}
|
||||
}
|
||||
19
bin/qpl-init/getttyent/getttynam.c
Normal file
19
bin/qpl-init/getttyent/getttynam.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
getttyent, getttynam, setttyent, endttyent for linux
|
||||
by qpliu@phoenix.princeton.edu 1992
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ttyent.h>
|
||||
|
||||
struct ttyent *
|
||||
getttynam (const char *nam)
|
||||
{
|
||||
struct ttyent *ent;
|
||||
setttyent ();
|
||||
while (ent = getttyent ())
|
||||
if (!strcmp(ent->ty_name, nam)) break;
|
||||
return ent;
|
||||
}
|
||||
13
bin/qpl-init/getttyent/test.c
Normal file
13
bin/qpl-init/getttyent/test.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ttyent.h>
|
||||
|
||||
main()
|
||||
{
|
||||
struct ttyent *ent;
|
||||
while (ent = getttyent ()) {
|
||||
printf("name: %s, getty: %s, type: %s, comment: %s st: %d\n",
|
||||
ent->ty_name, ent->ty_getty, ent->ty_type,
|
||||
ent->ty_comment, ent->ty_status);
|
||||
}
|
||||
}
|
||||
80
bin/qpl-init/getttyent/ttyent.h
Normal file
80
bin/qpl-init/getttyent/ttyent.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* the <sys/cdefs.h> stuff hacked out,
|
||||
* presumably it allows include files to declare functions either with
|
||||
* traditional prototypes or ansi prototypes with a single include file
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)ttyent.h 5.7 (Berkeley) 4/3/91
|
||||
*/
|
||||
|
||||
#ifndef _TTYENT_H_
|
||||
#define _TTYENT_H_
|
||||
|
||||
#define _PATH_TTYS "/etc/ttys"
|
||||
#define _PATH_TTYTAB "/etc/ttytab"
|
||||
|
||||
#define _TTYS_OFF "off"
|
||||
#define _TTYS_ON "on"
|
||||
#define _TTYS_LOCAL "local"
|
||||
#define _TTYS_SECURE "secure"
|
||||
#define _TTYS_WINDOW "window"
|
||||
|
||||
struct ttyent {
|
||||
char *ty_name; /* terminal device name */
|
||||
char *ty_getty; /* command to execute, usually getty */
|
||||
char *ty_type; /* terminal type for termcap */
|
||||
#define TTY_ON 0x01 /* enable logins (start ty_getty program) */
|
||||
#define TTY_SECURE 0x02 /* allow uid of 0 to login */
|
||||
#define TTY_LOCAL 0x04 /* soft carrier */
|
||||
int ty_status; /* status flags */
|
||||
char *ty_window; /* command to start up window manager */
|
||||
char *ty_comment; /* comment field */
|
||||
};
|
||||
|
||||
/* take this stuff out, linux only has gcc
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
struct ttyent *getttyent __P((void));
|
||||
struct ttyent *getttynam __P((const char *));
|
||||
int setttyent __P((void));
|
||||
int endttyent __P((void));
|
||||
__END_DECLS
|
||||
*/
|
||||
|
||||
struct ttyent *getttyent (void);
|
||||
struct ttyent *getttynam (const char *);
|
||||
int setttyent (void);
|
||||
int endttyent (void);
|
||||
|
||||
#endif /* !_TTYENT_H_ */
|
||||
277
bin/qpl-init/init/init.c
Normal file
277
bin/qpl-init/init/init.c
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
init.c does some of the stuff /etc/init should do.
|
||||
by qpliu@phoenix.princeton.edu 1992
|
||||
run /etc/rc,
|
||||
then run getty for each entry in /etc/ttytab
|
||||
SIGHUP makes it reread /etc/ttytab
|
||||
SIGTSTP makes it stop forking
|
||||
SIGTERM is ignored
|
||||
|
||||
ugly error messages might get stuck on console, syslog stuff?
|
||||
|
||||
imported stuff from original init function
|
||||
*/
|
||||
/*
|
||||
my computer is a puny 2meg 386sx, and can't run gcc.
|
||||
so I made cc1 on my account on a sun 4/490
|
||||
and compile to .s on the sun. however, cc1 dies with
|
||||
SIGIOT when trying to optimize some of the inlined string.h stuff
|
||||
when used in a big function.
|
||||
*/
|
||||
#define GCC_O_BUSTED
|
||||
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <linux/tty.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/head.h>
|
||||
#include <asm/system.h>
|
||||
#include <asm/io.h>
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <linux/fs.h>
|
||||
#include <ttyent.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
struct ttytablist {
|
||||
int pid;
|
||||
char *dev, *getty;
|
||||
struct ttytablist *next;
|
||||
};
|
||||
|
||||
static struct ttyent *ent;
|
||||
static struct ttytablist *tablist0, *tablist;
|
||||
static char **getty_argv;
|
||||
|
||||
#ifdef GCC_O_BUSTED
|
||||
static char *strtok1 (char *, const char *);
|
||||
#else
|
||||
#define strtok1 strtok
|
||||
#endif GCC_O_BUSTED
|
||||
|
||||
static char * argv_rc[] = { "/bin/bash", NULL };
|
||||
static char * envp_rc[] = { "HOME=/", NULL };
|
||||
static char * argv[] = { "-bash", NULL };
|
||||
static char * envp[] = { "HOME=/", NULL };
|
||||
|
||||
static char got_tstp = 0;
|
||||
|
||||
#define GETTY_RETRY_DLAY 30
|
||||
|
||||
static void rc ();
|
||||
static void child ();
|
||||
static void read_ttytab ();
|
||||
static void free_ttytab (struct ttytablist *);
|
||||
static void single_user ();
|
||||
static void hup_handler ();
|
||||
static void tstp_handler ();
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
rc ();
|
||||
read_ttytab (); /* initially, tablist->pid = 0 if off, -1 if on */
|
||||
|
||||
/* run getty */
|
||||
tablist = tablist0;
|
||||
while (tablist) {
|
||||
if (tablist->pid) {
|
||||
if (!(tablist->pid = fork()))
|
||||
child ();
|
||||
if (tablist->pid == -1) {
|
||||
printf ("Fork failed in init for %s\n\r",
|
||||
tablist->dev);
|
||||
tablist->pid = 0; /* waste memory */
|
||||
}
|
||||
}
|
||||
tablist = tablist->next;
|
||||
}
|
||||
|
||||
signal (SIGHUP, hup_handler);
|
||||
signal (SIGTERM, single_user);
|
||||
signal (SIGTSTP, tstp_handler);
|
||||
|
||||
/* reap children, restart getty unless got_tstp */
|
||||
for (;;) {
|
||||
int pid, i;
|
||||
|
||||
pid = wait (&i);
|
||||
if (!got_tstp) {
|
||||
tablist = tablist0;
|
||||
while (tablist) {
|
||||
if (tablist->pid == pid) {
|
||||
if (!(tablist->pid = fork()))
|
||||
child ();
|
||||
if (tablist->pid == -1) {
|
||||
printf ("Fork failed in init for %s\n\r", tablist->dev);
|
||||
tablist->pid = 0; /* waste memory */
|
||||
}
|
||||
}
|
||||
tablist = tablist->next;
|
||||
}
|
||||
}
|
||||
sync();
|
||||
}
|
||||
_exit(0); /* NOTE! _exit, not exit() */
|
||||
}
|
||||
|
||||
static void
|
||||
rc ()
|
||||
{
|
||||
int i, pid;
|
||||
|
||||
if (!(pid=fork())) {
|
||||
close(0);
|
||||
if (open("/etc/rc",O_RDONLY,0))
|
||||
_exit(1);
|
||||
execve("/bin/bash",argv_rc,envp_rc);
|
||||
_exit(2);
|
||||
}
|
||||
if (pid>0)
|
||||
while (pid != wait(&i))
|
||||
/* nothing */;
|
||||
}
|
||||
|
||||
static void
|
||||
free_ttytab (struct ttytablist *t)
|
||||
{
|
||||
struct ttytablist *u;
|
||||
|
||||
/* free all that malloced stuff */
|
||||
endttyent ();
|
||||
do {
|
||||
u = t->next;
|
||||
free (t->dev);
|
||||
free (t->getty);
|
||||
free (t);
|
||||
} while (t = u);
|
||||
}
|
||||
|
||||
static void
|
||||
read_ttytab ()
|
||||
{
|
||||
tablist0 = (struct ttytablist *)malloc (sizeof (struct ttytablist));
|
||||
if (!tablist0) {
|
||||
printf ("Malloc failed in init\n\r");
|
||||
_exit (0);
|
||||
}
|
||||
tablist0->next = (struct ttytablist *)0;
|
||||
tablist = tablist0;
|
||||
ent = getttyent ();
|
||||
if (!ent) {
|
||||
printf ("Getttyent failed in init, check /etc/ttytab\n\r");
|
||||
/* should probably enter single-user mode */
|
||||
_exit (0);
|
||||
}
|
||||
|
||||
/* assume first entry is on, if it's off, waste some memory */
|
||||
tablist->pid = 0;
|
||||
for (;;) {
|
||||
tablist->next = (struct ttytablist *)0;
|
||||
tablist->dev = (char *)malloc (5 + strlen (ent->ty_name));
|
||||
strcpy (tablist->dev, "/dev/");
|
||||
strcat (tablist->dev, ent->ty_name);
|
||||
tablist->getty = (char *)malloc (strlen (ent->ty_getty));
|
||||
strcpy (tablist->getty, ent->ty_getty);
|
||||
if (ent->ty_status & TTY_ON) tablist->pid = -1;
|
||||
else tablist->pid = 0;
|
||||
|
||||
/* don't waste memory to store off entries */
|
||||
do {
|
||||
ent = getttyent ();
|
||||
if (!ent) {
|
||||
endttyent ();
|
||||
break;
|
||||
}
|
||||
} while (ent->ty_status & TTY_ON);
|
||||
if (!ent) break;
|
||||
|
||||
tablist->next = (struct ttytablist *)malloc (sizeof (struct ttytablist));
|
||||
tablist = tablist->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
child ()
|
||||
{
|
||||
int i;
|
||||
char *c, *g = (char *)malloc (strlen (tablist->getty) * sizeof (char));
|
||||
|
||||
close(0);close(1);close(2);
|
||||
setsid();
|
||||
(void) open(tablist->dev,O_RDWR,0);
|
||||
(void) dup(0);
|
||||
(void) dup(0);
|
||||
|
||||
/* find argc for getty */
|
||||
strcpy (g, tablist->getty);
|
||||
i = 1; strtok1 (g, " \t\n");
|
||||
while (strtok1 ((char *)0, " \t\n")) ++i;
|
||||
getty_argv = (char **)malloc (i * sizeof (char **));
|
||||
strcpy (g, tablist->getty);
|
||||
i = 1; c = strtok1 (g, " \t\n"); *getty_argv = c;
|
||||
while (c = strtok1 ((char *)NULL, " \t\n"))
|
||||
*(getty_argv + i++) = c;
|
||||
|
||||
free_ttytab (tablist0);
|
||||
|
||||
execve (*getty_argv, getty_argv, envp);
|
||||
sleep (GETTY_RETRY_DLAY); /* don't hog system */
|
||||
_exit (0);
|
||||
}
|
||||
|
||||
static void
|
||||
hup_handler ()
|
||||
{
|
||||
struct ttytablist *t = tablist0, *u, *v;
|
||||
|
||||
got_tstp = 0;
|
||||
signal (SIGHUP, SIG_IGN);
|
||||
read_ttytab ();
|
||||
|
||||
/* copy running pids that still map onto enabled terminals */
|
||||
for (u = tablist0; u; u = u->next)
|
||||
if (u->pid) {
|
||||
for (v = t; v; v = v->next) /* simple-minded */
|
||||
if (!strcmp (v->dev, u->dev)) {
|
||||
u->pid = v->pid;
|
||||
break;
|
||||
}
|
||||
|
||||
/* check if new terminal enabled */
|
||||
if (!v) {
|
||||
if (!(u->pid = fork()))
|
||||
child ();
|
||||
if (u->pid == -1) {
|
||||
printf ("Fork failed in init for %s\n\r", tablist->dev);
|
||||
u->pid = 0; /* waste memory */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free_ttytab (t);
|
||||
signal (SIGHUP, hup_handler);
|
||||
}
|
||||
|
||||
static void
|
||||
tstp_handler ()
|
||||
{
|
||||
got_tstp = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
single_user ()
|
||||
{
|
||||
}
|
||||
|
||||
/* don't want this inlined with -finline-functions, so put it last */
|
||||
#ifdef GCC_O_BUSTED
|
||||
static char *strtok1 (char *a, const char *b)
|
||||
{
|
||||
return strtok (a, b);
|
||||
}
|
||||
#endif GCC_O_BUSTED
|
||||
27
bin/qpl-init/init/main-.12.diff
Normal file
27
bin/qpl-init/init/main-.12.diff
Normal file
@@ -0,0 +1,27 @@
|
||||
*** main-.12.c.orig Wed Jan 15 21:50:23 1992
|
||||
--- main-.12.c Wed Jan 15 22:03:56 1992
|
||||
***************
|
||||
*** 116,121 ****
|
||||
--- 116,124 ----
|
||||
static long main_memory_start = 0;
|
||||
static char term[32];
|
||||
|
||||
+ static char * argv_init[] = { "/etc/init", NULL };
|
||||
+ static char * envp_init[] = { "HOME=/", NULL };
|
||||
+
|
||||
static char * argv_rc[] = { "/bin/sh", NULL };
|
||||
static char * envp_rc[] = { "HOME=/", NULL ,NULL };
|
||||
|
||||
***************
|
||||
*** 198,203 ****
|
||||
--- 201,210 ----
|
||||
printf("%d buffers = %d bytes buffer space\n\r",NR_BUFFERS,
|
||||
NR_BUFFERS*BLOCK_SIZE);
|
||||
printf("Free mem: %d bytes\n\r",memory_end-main_memory_start);
|
||||
+
|
||||
+ execve("/etc/init",argv_init,envp_init);
|
||||
+ /* if this fails, fall through to original stuff */
|
||||
+
|
||||
if (!(pid=fork())) {
|
||||
close(0);
|
||||
if (open("/etc/rc",O_RDONLY,0))
|
||||
148
bin/qpl-init/login/login.c
Normal file
148
bin/qpl-init/login/login.c
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
login.c
|
||||
by qpliu@phoenix.princeton.edu 1992
|
||||
a rudimentary way to avoid being root on linux 0.11
|
||||
no motd or other messages or .hushlogin
|
||||
no passwords
|
||||
no /etc/nologin
|
||||
no checking if term is secure
|
||||
*/
|
||||
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ttyent.h>
|
||||
|
||||
#define DEFAULT_SHELL "/bin/bash"
|
||||
#define TIMEOUT 60
|
||||
#define STIMEOUT "60"
|
||||
|
||||
extern char **environ;
|
||||
static void do_login (char *);
|
||||
static int check_passwd (struct passwd *);
|
||||
static void timeout ();
|
||||
static void setenviron ();
|
||||
static char savenv = 0;
|
||||
static struct passwd *entry;
|
||||
|
||||
void
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char login[L_cuserid];
|
||||
|
||||
if (argc > 1)
|
||||
if (!(strcmp ("-p", *(argv + 1)))) {
|
||||
--argc; ++argv; savenv = 1;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
do_login (*++argv);
|
||||
|
||||
for (;;) {
|
||||
fputs ("login: ", stdout);
|
||||
fflush (stdout);
|
||||
signal (SIGALRM, timeout);
|
||||
alarm (TIMEOUT);
|
||||
fgets (login, L_cuserid, stdin);
|
||||
alarm (0);
|
||||
signal (SIGALRM, SIG_DFL);
|
||||
if (feof (stdin)) exit(0);
|
||||
if (*login == '\n') continue;
|
||||
|
||||
if (login [strlen (login) - 1] == '\n')
|
||||
login [strlen (login) - 1] = '\0';
|
||||
else { /* discard rest of line */
|
||||
char junk[80];
|
||||
do fgets (junk, 80, stdin);
|
||||
while (junk [strlen (junk) - 1] != '\n');
|
||||
}
|
||||
|
||||
do_login (login);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_login (char *login)
|
||||
{
|
||||
entry = getpwnam (login);
|
||||
if (check_passwd (entry)) {
|
||||
puts ("Login incorrect");
|
||||
return;
|
||||
}
|
||||
|
||||
if (setgid (entry->pw_gid)) {
|
||||
perror ("setgid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (setuid (entry->pw_uid)) {
|
||||
setgid (0);
|
||||
perror ("setuid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (chdir (entry->pw_dir))
|
||||
perror ("Couldn't chdir");
|
||||
|
||||
{
|
||||
char *p, *d, *e;
|
||||
if (!(e = entry->pw_shell)) e = DEFAULT_SHELL;
|
||||
p = strrchr (e, '/');
|
||||
if (!p++) p = e;
|
||||
if (!p) p = DEFAULT_SHELL;
|
||||
d = (char *)malloc (strlen(p) + 1);
|
||||
*d = '-'; *(d+1) = '\0';
|
||||
strcat(d, p);
|
||||
setenviron ();
|
||||
execl(e, d, (char *)0);
|
||||
perror("No shell");
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
check_passwd (struct passwd *entry)
|
||||
{
|
||||
/* room to get and check actual (yuck) passwords */
|
||||
return entry ? 0 : 1;
|
||||
}
|
||||
|
||||
static void
|
||||
timeout ()
|
||||
{
|
||||
/* printf ("Login timed out after %d seconds\n", TIMEOUT); */
|
||||
/* 8k for 1 printf too big */
|
||||
puts ("Login timed out after " STIMEOUT " seconds");
|
||||
exit (0);
|
||||
}
|
||||
|
||||
extern char *ttyname (int);
|
||||
|
||||
static void
|
||||
setenviron ()
|
||||
{
|
||||
/* too much bother, man pages say HOME, SHELL, TERM, USER set */
|
||||
char **c = environ, *d;
|
||||
|
||||
while (*c) free (*(c++));
|
||||
free (environ);
|
||||
|
||||
c = (char **)malloc (5 * sizeof (char *));
|
||||
environ = c;
|
||||
|
||||
d = ttyname (0);
|
||||
if (d) {
|
||||
d += 5; /* "/dev/" */
|
||||
d = getttynam (d)->ty_type;
|
||||
}
|
||||
*c = (char *)malloc ((5 + strlen (entry->pw_dir)) * sizeof (char));
|
||||
strcpy (*c, "HOME="); strcat (*c, entry->pw_dir);
|
||||
*++c = (char *)malloc ((6 + strlen (entry->pw_shell)) * sizeof (char));
|
||||
strcpy (*c, "SHELL="); strcat (*c, entry->pw_shell);
|
||||
*++c = (char *)malloc ((5 + strlen (d)) * sizeof (char));
|
||||
strcpy (*c, "TERM="); strcat (*c, d);
|
||||
*++c = (char *)malloc ((5 + strlen (entry->pw_name)) * sizeof (char));
|
||||
strcpy (*c, "NAME="); strcat (*c, entry->pw_name);
|
||||
*++c = (char *)0;
|
||||
endttyent ();
|
||||
}
|
||||
Reference in New Issue
Block a user