/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
#include <signal.h>
#include "ttymon.h"
#include "tmstruct.h"
#include "tmextern.h"
extern char *strsave();
extern void set_softcar();
extern int vml();
void purge();
static int get_flags();
static int get_ttyflags();
static int same_entry();
static int check_pmtab();
static void insert_pmtab();
static void free_pmtab();
static char *expand();
int check_identity();
int strcheck();
/*
* read_pmtab()
* - read and parse pmtab
* - store table in linked list pointed by global variable "PMtab"
* - exit if file does not exist or error detected.
*/
void
{
char oldc;
static char *states[] = {
"","tag","flags","identity","reserved1","reserved2","reserved3",
"device","ttyflags","count","service", "timeout","ttylabel",
"modules","prompt","disable msg","terminal type","soft-carrier"
};
# ifdef DEBUG
debug("in read_pmtab");
# endif
}
Nentries = 0;
fatal("check pmtab version failed");
}
}
}
linenum = 0;
do {
linenum++;
line[0] = '\0';
break;
}
*ptr = '\0';
/* skip rest of the line */
if (rawc != '#')
log("Entry too long.\n");
;
}
}
/* if empty line, skip */
;
if (*ptr == '\0') continue;
#ifdef DEBUG
#endif
/* Now we have the complete line */
fatal("memory allocation failed");
/* set hangup flag, this is the default */
/*
* For compatibility reasons, we cannot rely on these
* having values assigned from pmtab.
*/
switch(state) {
case P_TAG:
break;
case P_FLAGS:
}
break;
case P_IDENTITY:
break;
case P_RES1:
break;
case P_RES2:
break;
case P_RES3:
break;
case P_DEVICE:
break;
case P_TTYFLAGS:
}
break;
case P_COUNT:
log("wait_read count must be a positive number");
}
else
break;
case P_SERVER:
break;
case P_TIMEOUT:
log("timeout value must be a positive number");
}
else
break;
case P_TTYLABEL:
break;
case P_MODULES:
}
break;
case P_PROMPT:
break;
case P_DMSG:
break;
case P_TERMTYPE:
break;
case P_SOFTCAR:
break;
} /* end switch */
break;
if (*ptr == ':') {
ptr++; /* Skip the ':' */
state++ ;
} else if (*ptr != '\0') {
}
if (*ptr == '\0') {
/*
* Maintain compatibility with older ttymon
* pmtab files. If Sun-added fields are
* missing, this should not be an error.
*/
} else {
}
}
} /* end for loop */
if (check_pmtab(gptr) == 0) {
else {
log("can't add more entries to "
"pmtab, Maxfds = %d", Maxfds);
return;
}
}
else {
log("-------------------------------------------");
}
} else {
*++ptr = '\0';
log("Parsing failure in the \"%s\" field,\n%s"
log("-------------------------------------------");
}
return;
}
/*
* get_flags - scan flags field to set U_FLAG and X_FLAG
*/
static int
char *wptr; /* pointer to the input string */
long *flags; /* pointer to the flag to set */
{
register char *p;
for (p = wptr; *p; p++) {
switch (*p) {
case 'x':
break;
case 'u':
break;
default:
log("Invalid flag -- %c", *p);
return(-1);
}
}
return(0);
}
/*
* get_ttyflags - scan ttyflags field to set corresponding flags
*/
static int
char *wptr; /* pointer to the input string */
long *ttyflags; /* pointer to the flag to be set*/
{
register char *p;
for (p = wptr; *p; p++) {
switch (*p) {
case 'c':
break;
case 'h': /* h means don't hangup */
break;
case 'b':
break;
case 'r':
break;
case 'I':
break;
default:
log("Invalid ttyflag -- %c", *p);
return(-1);
}
}
return(0);
}
# ifdef DEBUG
/*
* pflags - put service flags into intelligible form for output
*/
char *
long flags; /* binary representation of the flags */
{
register int i; /* scratch counter */
if (flags == 0)
return("-");
i = 0;
buf[i++] = 'u';
}
buf[i++] = 'x';
}
if (flags)
log("Internal error in pflags");
buf[i] = '\0';
return(buf);
}
/*
* pttyflags - put ttyflags into intelligible form for output
*/
char *
long flags; /* binary representation of ttyflags */
{
register int i; /* scratch counter */
if (flags == 0)
return("h");
i = 0;
buf[i++] = 'c';
}
else
buf[i++] = 'h';
buf[i++] = 'b';
}
buf[i++] = 'r';
}
buf[i++] = 'I';
}
if (flags)
log("Internal error in p_ttyflags");
buf[i] = '\0';
return(buf);
}
void
{
debug("in dump_pmtab");
log("********** dumping pmtab **********");
log(" ");
log("-------------------------------------------");
log(" ");
}
log("********** end dumping pmtab **********");
}
# endif
/*
* same_entry(e1,e2) - compare 2 entries of pmtab
* if the fields are different, copy e2 to e1
* return 1 if same, return 0 if different
*/
static int
{
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
/*
* compare lowest 4 bits only,
* because A_FLAG is not part of original ttyflags
*/
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(1);
}
/*
* insert_pmtab - insert a pmtab entry into the linked list
*/
static void
{
# ifdef DEBUG
debug("in insert_pmtab");
# endif
/*
* find the correct place to insert this element
*/
while (tsp) {
if (ret > 0) {
/* keep on looking */
continue;
}
else if (ret == 0) {
/* this is a duplicate entry, ignore it */
log("Ignoring duplicate entry for <%s>",
}
else {
}
else { /* entry changed */
/* disabled entry */
}
else {
# ifdef DEBUG
# endif
/* replace old entry */
}
else {
}
sp->p_inservice =
}
}
Nentries++;
}
free_pmtab(sp);
return;
}
else {
free_pmtab(sp);
return;
}
/*
* Set the state of soft-carrier.
* Since this is a one-time only operation,
* we do it when this service is added to
* the enabled list.
*/
/* insert it here */
}
else {
}
# ifdef DEBUG
# endif
Nentries++;
/* this entry is "current" */
return;
}
}
/*
* either an empty list or should put element at end of list
*/
return;
}
/*
* Set the state of soft-carrier.
* Since this is a one-time only operation,
* we do it when this service is added to
* the enabled list.
*/
else
# ifdef DEBUG
# endif
++Nentries;
/* this entry is "current" */
}
/*
* purge - purge linked list of "old" entries
*/
void
purge()
{
# ifdef DEBUG
debug("in purge");
# endif
while (sp) {
# ifdef DEBUG
debug("p_status not 0");
# endif
}
else {
}
else
# ifdef DEBUG
# endif
}
}
}
/*
* free_pmtab - free one pmtab entry
*/
static void
free_pmtab(p)
struct pmtab *p;
{
#ifdef DEBUG
debug("in free_pmtab");
#endif
free(p->p_identity);
free(p->p_ttylabel);
free(p->p_termtype);
if (p->p_dir)
free(p);
}
/*
* check_pmtab - check the fields to make sure things are correct
* - return 0 if everything is ok
* - return -1 if something is wrong
*/
static int
check_pmtab(p)
struct pmtab *p;
{
if (p == NULL) {
log("pmtab ptr is NULL");
return(-1);
}
/* check service tag */
return(-1);
}
MAXID-1);
return(-1);
}
return(-1);
}
if (check_identity(p) != 0) {
return(-1);
}
if (check_device(p->p_device) != 0)
return(-1);
return(-1);
return(0);
}
extern void endpwent();
extern void endgrent();
/*
* check_identity - check to see if the identity is a valid user
* - log name in the passwd file,
* - and if its group id is a valid one
* - return 0 if everything is ok. Otherwise, return -1
*/
int
struct pmtab *p;
{
log("identity field is missing");
return(-1);
}
endpwent();
return(-1);
}
endgrent();
endpwent();
return(-1);
}
endgrent();
endpwent();
return(0);
}
/*
* expand(cmdp, devp) - expand %d to device name and %% to %,
* - any other characters are untouched.
* - return the expanded string
*/
static char *
char *cmdp; /* ptr to cmd string */
char *devp; /* ptr to device name */
{
while (*cp) {
if (*cp != '%') {
continue;
}
switch (*++cp) {
case 'd':
while (*dp) {
}
cp++;
break;
case '%':
break;
default:
break;
}
}
*np = '\0';
return(buf);
}