/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <utmpx.h>
#include <pwd.h>
#include <dirent.h>
#include "ttymon.h"
#include "tmextern.h"
#include "tmstruct.h"
static char *devname;
static int parse_args();
static void ttymon_options();
static void getty_options();
static void usage();
static char *find_ttyname();
extern void tmchild();
extern int vml();
/* cannot include libdevinfo.h */
extern int di_devperm_logout(const char *);
/*
* ttymon_express - This is call when ttymon is invoked with args
* or invoked as getty
* - This special version of ttymon will monitor
* one port only
* - It is intended to be used when some process
* wants to have a login session on the fly
*/
void
{
extern int Retry;
extern void open_device();
extern void read_ttydefs();
extern int checkut_line();
#ifdef DEBUG
extern void opendebug();
#endif
#ifdef DEBUG
#endif
log("ttymon_express: ALLOC_PMTAB failed");
exit(1);
}
log("ttymon_express: parse_args failed");
exit(1);
}
sleep(15);
devname = find_ttyname(0);
log("ttyname cannot find the device on fd 0");
exit(1);
}
#ifdef DEBUG
#endif
/*
* become session leader
* fd 0 is closed and reopened just to make sure
* controlling tty is set up right
*/
(void) setsid();
(void) close(0);
exit(1);
}
exit(1);
}
exit(1);
} else {
(void) setsid();
(void) close(0);
if (Retry) /* open failed */
exit(1);
}
}
/*
* parse_arg - parse cmd line arguments
*/
static int
{
extern char *lastname();
extern void getty_account();
/* initialize fields to some default first */
pmtab->p_ttyflags = 0;
} else {
int cn_fd;
/*
* The following code is only reached if -g was specified.
* It attempts to determine a suitable terminal type for
* the console login process.
*
* to the console device to query the TERM type.
*
* If any of the tests, system calls, or ioctls fail
* then pmtab->p_termtype retains its default value
* of "". otherwise it is set to a term type value
* that was returned.
*/
}
}
return (0);
}
/*
* ttymon_options - scan and check args for ttymon express
*/
static void
{
int c; /* option letter */
char *timeout;
int size = 0;
extern char *optarg;
extern int optind;
extern void copystr();
extern char *strsave();
extern char *getword();
switch (c) {
case 'g':
gflag = 1;
break;
case 'd':
break;
case 'h':
break;
case 'T':
break;
/*
* case 'b':
* pmtab->p_ttyflags |= B_FLAG;
* pmtab->p_ttyflags |= R_FLAG;
* break;
*/
case 't':
while (*optarg) {
log("Invalid argument for "
"\"-t\" -- number expected.");
usage();
}
}
break;
case 'p':
break;
case 'm':
usage();
break;
case 'l':
break;
case '?':
usage();
break; /*NOTREACHED*/
}
}
usage();
if (!gflag)
usage();
}
/*
* usage - print out a usage message
*/
static void
usage()
{
"[-l ttylabel] [-t timeout] [-p prompt] [-m modules]\n";
if (isatty(STDERR_FILENO))
else
exit(1);
}
/*
* getty_options - this is cut from getty.c
* - it scan getty cmd args
* - modification is made to stuff args in pmtab
*/
static void
int argc;
char **argv;
{
char *ptr;
/*
* the pre-4.0 getty's hang_up_line() is a no-op.
* For compatibility, H_FLAG cannot be set for this "getty".
*/
switch (*ptr) {
case 'h':
break;
case 't':
ptr--;
} else if (--argc) {
else {
log("getty: timeout argument <%s> "
"invalid", *argv);
exit(1);
}
}
break;
case 'c':
exit(0);
default:
break;
}
}
if (argc < 1) {
log("getty: no terminal line specified.");
exit(1);
} else {
}
if (--argc > 0) {
}
/*
* every thing after this will be ignored
* i.e. termtype and linedisc are ignored
*/
}
/*
* find_ttyname(fd) - find the name of device associated with fd.
* - it first tries utmpx to see if an entry exists
* - with my pid and ut_line is defined. If ut_line
* - is defined, it will see if the major and minor
* - number of fd and devname from utmpx match.
* - If utmpx search fails, ttyname(fd) will be called.
*/
static char *
int fd;
{
struct utmpx *u;
setutxent();
if (*(u->ut_line) != '/') {
sizeof (u->ut_line));
} else {
sizeof (u->ut_line));
}
}
else
u = NULL;
break;
}
}
endutxent();
if ((u != NULL) &&
#ifdef DEBUG
debug("ttymon_express: find device name from utmpx.");
#endif
return (buf);
} else {
#ifdef DEBUG
debug("ttymon_express: calling ttyname to find device name.");
#endif
}
}
/*
* Revoke all access to a device node and make sure that there are
* no interposed streams devices attached. Must be called before a
* device is actually opened.
* When fdetach is called, the underlying device node is revealed; it
* will have the previous owner and that owner can re-attach; so we
* retry until we win.
* Ignore non-existent devices.
*/
void
{
do {
return;
/* Remove ACLs */
}