#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# Fix_getty
# Fix_login
# Fix_util
# ttyaction.3
# ttyaction.5
# ttyaction.c
# ttyact.c
# This archive created: Fri Nov 8 16:27:53 1996
export PATH; PATH=/bin:$PATH
if test -f 'Fix_getty'
then
echo shar: will not over-write existing file "'Fix_getty'"
else
cat << \SHAR_EOF > 'Fix_getty'
*** main.c.orig Mon Nov 4 20:15:40 1996
--- main.c Fri Nov 8 16:22:55 1996
***************
*** 209,214 ****
--- 209,216 ----
chown(ttyn, 0, 0);
chmod(ttyn, 0600);
revoke(ttyn);
+ if (ttyaction(ttyn, "getty", "root"))
+ syslog(LOG_ERR,"%s: ttyaction failed", ttyn);
/*
* Delay the open so DTR stays down long enough to be detected.
*/
SHAR_EOF
fi # end of overwriting check
if test -f 'Fix_login'
then
echo shar: will not over-write existing file "'Fix_login'"
else
cat << \SHAR_EOF > 'Fix_login'
*** login.c.orig Mon Nov 4 20:14:54 1996
--- login.c Fri Nov 8 16:18:26 1996
***************
*** 379,384 ****
--- 379,388 ----
(void)chown(ttyn, pwd->pw_uid,
(gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid);
+
+ if (ttyaction(ttyn, "login", pwd->pw_name))
+ (void)printf("Warning: ttyaction failed.\n");
+
#if defined(KERBEROS) || defined(KERBEROS5)
/* Fork so that we can call kdestroy */
if (krbtkfile_env)
SHAR_EOF
fi # end of overwriting check
if test -f 'Fix_util'
then
echo shar: will not over-write existing file "'Fix_util'"
else
cat << \SHAR_EOF > 'Fix_util'
*** util.h.~1~ Fri Nov 8 13:53:05 1996
--- util.h Fri Nov 8 13:54:02 1996
***************
*** 62,67 ****
--- 62,68 ----
pid_t forkpty __P((int *, char *, struct termios *, struct winsize *));
int getmaxpartitions __P((void));
int getrawpartition __P((void));
+ int ttyaction __P((char *tty, char *act, char *user));
__END_DECLS
#endif /* !_UTIL_H_ */
SHAR_EOF
fi # end of overwriting check
if test -f 'ttyaction.3'
then
echo shar: will not over-write existing file "'ttyaction.3'"
else
cat << \SHAR_EOF > 'ttyaction.3'
\" $NetBSD$
\"
\" Copyright (c) 1996 The NetBSD Foundation, Inc.
\" All rights reserved.
\"
\" This code is derived from software contributed to The NetBSD Foundation
\" by Gordon W. Ross.
\"
\" 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 NetBSD
\" Foundation, Inc. and its contributors.
\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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.
\"
Dd August 24, 1996
Dt TTYACTION 3
Os
Sh NAME
Nm ttyaction
Nd ttyaction utility function
Sh SYNOPSIS
Fd #include <util.h>
Ft void
Fn ttyaction "char *ttyname" "char *action" "char *username"
Sh DESCRIPTION
The
Fn ttyaction
function is used by
Nm login
and
Nm getty
to execute site-specific commands
when a login session begins and ends.
Pp
The
Fn ttyaction
function scans the
Pa /etc/ttyaction
file for any records that match the current
Fa ttyname
and
Fa action
parameters, and for each matching record, runs the shell command
shown in that record. The record format is described in
Xr ttyaction 5 .
The parameter
Fa username
is the name of the new owner of the
Fa ttyname
device.
Sh RETURN VALUES
Fn ttyaction
returns the status of the last command it executed,
or zero if no matching commands were found.
Sh FILES
Bl -tag -width /etc/ttyaction -compact
It Pa /dev/\(**
It Pa /etc/ttyactions
El
Sh SEE ALSO
Xr ttyaction 5
Sh AUTHORS
The following people contributed to this design:
Bd -literal -offset indent
Gordon W. Ross <
[email protected]>
Chris G Demetriou <
[email protected]>
Ty Sarna <
[email protected]>
[Did I miss anyone? -gwr]
Ed
Sh BUGS
There should be some
Em other
mechanism to allow selection of different access control policies
on a per-line basis. It has been suggested that the same
Nm ttyaction
mechanism should also be used for determining access control, but
it was decided (after much discussion) that
Nm ttyaction
should only describe actions to be performed
Em after
the system has decided to change the ownership of some tty.
Access control policies will be handled by a separate mechanism.
SHAR_EOF
fi # end of overwriting check
if test -f 'ttyaction.5'
then
echo shar: will not over-write existing file "'ttyaction.5'"
else
cat << \SHAR_EOF > 'ttyaction.5'
\" $NetBSD$
\"
\" Copyright (c) 1996 The NetBSD Foundation, Inc.
\" All rights reserved.
\"
\" This code is derived from software contributed to The NetBSD Foundation
\" by Gordon W. Ross.
\"
\" 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 NetBSD
\" Foundation, Inc. and its contributors.
\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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.
\"
Dd August 24, 1996
Dt TTYACTION 5
Os
Sh NAME
Nm ttyaction
Nd ttyaction file format
Sh DESCRIPTION
The
Nm ttyaction
file specifies site-specific commands to run
when a login session begins and ends. The
Nm ttyaction
file contains a list of newline separated records, where
each record has the following three fields:
Bl -tag -width username
It ttyname
Name of the tty line(s) on which this line should apply.
The name is relative to the
Pa /dev
directory, similar to how such devices are named in the
Pa /etc/ttys
file.
It action
Name of the action for which this line should apply.
The action names currently defined are "login" and "getty"
which indicate which program is processing this file.
It command
What command to run if this record matches.
El
Pp
The first two fields are delimited with blanks or tabs,
and the command field is all text to the end of the line.
Either or both of first two fields may contain wildcard
match patterns (interpreted like filename wildcards).
Pp
All command strings are executed by passing them to
Pa /bin/sh \-c
with an environment containing:
Bd -literal -offset indent
TTY=ttyname
ACT=action
USER=username
PATH=_PATH_STDPATH
Ed
Pp
These variables may be used directly in the shell command
part of the record for simple tasks such as changing the
ownership of related devices. For example:
Bd -literal -offset indent
console * chown ${USER}.tty /dev/mouse
Ed
Pp
will
Fa chown
the mouse to when the console owner changes.
Sh EXAMPLE
Here are some more example records:
Bd -literal -offset indent
tty0 login /somewhere/tty_setup ${TTY}
tty0 getty /somewhere/tty_clean ${TTY}
* * /somewhere/ttyfrob ${TTY} ${ACT}
Ed
Pp
Sh SEE ALSO
Xr ttyaction 3
Sh HISTORY
The ideas for the
Pa /etc/ttyaction
file were inspired by the
Pa /etc/fbtab
file under SunOS.
SHAR_EOF
fi # end of overwriting check
if test -f 'ttyaction.c'
then
echo shar: will not over-write existing file "'ttyaction.c'"
else
cat << \SHAR_EOF > 'ttyaction.c'
/* $NetBSD$ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Gordon W. Ross.
*
* 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 NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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.
*/
/*
* For each matching "tty" and "action" run the "command."
* See fnmatch() for matching the tty name.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <paths.h>
#include "util.h"
#ifndef _PATH_TTYACTION
#define _PATH_TTYACTION "/etc/ttyaction"
#endif
static char *actfile = _PATH_TTYACTION;
static char *pathenv = "PATH=" _PATH_STDPATH;
int
ttyaction(tty, act, user)
char *tty;
char *act;
char *user;
{
FILE *fp;
char *p1, *p2;
char *argv[4];
char *envp[8];
char line[1024];
char env_tty[64];
char env_act[64];
char env_user[256];
int err, linenum, pid, status;
fp = fopen(actfile, "r");
if (fp == NULL)
return 0;
/* Args will be: "sh -c ..." */
argv[0] = _PATH_BSHELL;
argv[1] = "-c";
argv[2] = NULL; /* see below */
argv[3] = NULL;
/* Environment needs: TTY, ACT, USER */
sprintf(env_tty, "TTY=%.63s", tty);
sprintf(env_act, "ACT=%.63s", act);
sprintf(env_user, "USER=%.255s", user);
envp[0] = pathenv;
envp[1] = env_tty;
envp[2] = env_act;
envp[3] = env_user;
envp[4] = NULL;
linenum = 0;
status = 0;
while (fgets(line, sizeof(line), fp)) {
linenum++;
p1 = strtok(line, " \t");
p2 = strtok(NULL, " \t");
/* This arg goes to end of line. */
argv[2] = strtok(NULL, "\n");
if (!p1 || !p2 || !argv[2]) {
warnx("%s: line %d format error", actfile, linenum);
continue;
}
if (fnmatch(p1, tty, 0) || fnmatch(p2, act, 0))
continue;
/* OK, this is a match. Run the command. */
pid = fork();
if (pid == -1) {
warnx("fork failed: %s", strerror(errno));
continue;
}
if (pid == 0) {
/* This is the child. */
err = execve(argv[0], argv, envp);
/* If we get here, it is an error. */
warnx("%s: line %d: exec failed: %s",
actfile, linenum, strerror(errno));
continue;
}
/* This is the parent. */
err = waitpid(pid, &status, 0);
if (err == -1) {
warnx("%s: line %d: wait failed: %s",
actfile, linenum, strerror(errno));
continue;
}
if (WTERMSIG(status)) {
warnx("%s: line %d: child died with signal %d",
actfile, linenum, WTERMSIG(status));
continue;
}
}
fclose(fp);
return status;
}
SHAR_EOF
fi # end of overwriting check
if test -f 'ttyact.c'
then
echo shar: will not over-write existing file "'ttyact.c'"
else
cat << \SHAR_EOF > 'ttyact.c'
#include <stdio.h>
#include "util.h"
main(argc, argv)
int argc;
char **argv;
{
int err;
if (argc < 4) {
fprintf(stderr, "args: ttyname action username\n");
exit(1);
}
err = ttyaction(argv[1], argv[2], argv[3]);
printf("ttyaction returned %d\n", err);
return 0;
}
SHAR_EOF
fi # end of overwriting check
# End of shell archive
exit 0