17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*fea9cb91Slq150181 * Common Development and Distribution License (the "License"). 6*fea9cb91Slq150181 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*fea9cb91Slq150181 227c478bd9Sstevel@tonic-gate /* 23*fea9cb91Slq150181 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <stdio.h> 337c478bd9Sstevel@tonic-gate #include <stdlib.h> 347c478bd9Sstevel@tonic-gate #include <unistd.h> 357c478bd9Sstevel@tonic-gate #include <fcntl.h> 367c478bd9Sstevel@tonic-gate #include <errno.h> 377c478bd9Sstevel@tonic-gate #include <ctype.h> 387c478bd9Sstevel@tonic-gate #include <string.h> 397c478bd9Sstevel@tonic-gate #include <signal.h> 407c478bd9Sstevel@tonic-gate #include <sys/stat.h> 417c478bd9Sstevel@tonic-gate #include <utmpx.h> 427c478bd9Sstevel@tonic-gate #include <pwd.h> 437c478bd9Sstevel@tonic-gate #include <dirent.h> 447c478bd9Sstevel@tonic-gate #include <sys/param.h> 457c478bd9Sstevel@tonic-gate #include <sys/acl.h> 46*fea9cb91Slq150181 #include <sys/stat.h> 47*fea9cb91Slq150181 #include <sys/types.h> 48*fea9cb91Slq150181 #include <sys/console.h> 497c478bd9Sstevel@tonic-gate #include "ttymon.h" 507c478bd9Sstevel@tonic-gate #include "tmextern.h" 517c478bd9Sstevel@tonic-gate #include "tmstruct.h" 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate static char devbuf[BUFSIZ]; 547c478bd9Sstevel@tonic-gate static char *devname; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate static int parse_args(); 577c478bd9Sstevel@tonic-gate static void ttymon_options(); 587c478bd9Sstevel@tonic-gate static void getty_options(); 597c478bd9Sstevel@tonic-gate static void usage(); 607c478bd9Sstevel@tonic-gate static char *find_ttyname(); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate extern void tmchild(); 637c478bd9Sstevel@tonic-gate extern int vml(); 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate void revokedevaccess(char *, uid_t, gid_t, mode_t); 667c478bd9Sstevel@tonic-gate /* cannot include libdevinfo.h */ 677c478bd9Sstevel@tonic-gate extern int di_devperm_logout(const char *); 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * ttymon_express - This is call when ttymon is invoked with args 717c478bd9Sstevel@tonic-gate * or invoked as getty 727c478bd9Sstevel@tonic-gate * - This special version of ttymon will monitor 737c478bd9Sstevel@tonic-gate * one port only 747c478bd9Sstevel@tonic-gate * - It is intended to be used when some process 757c478bd9Sstevel@tonic-gate * wants to have a login session on the fly 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate void 787c478bd9Sstevel@tonic-gate ttymon_express(int argc, char **argv) 797c478bd9Sstevel@tonic-gate { 807c478bd9Sstevel@tonic-gate struct pmtab *pmtab; 817c478bd9Sstevel@tonic-gate struct sigaction sigact; 827c478bd9Sstevel@tonic-gate extern int Retry; 837c478bd9Sstevel@tonic-gate extern void open_device(); 847c478bd9Sstevel@tonic-gate extern void read_ttydefs(); 857c478bd9Sstevel@tonic-gate extern int checkut_line(); 867c478bd9Sstevel@tonic-gate #ifdef DEBUG 877c478bd9Sstevel@tonic-gate extern FILE *Debugfp; 887c478bd9Sstevel@tonic-gate extern void opendebug(); 897c478bd9Sstevel@tonic-gate #endif 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #ifdef DEBUG 927c478bd9Sstevel@tonic-gate opendebug(TRUE); 937c478bd9Sstevel@tonic-gate #endif 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate sigact.sa_flags = 0; 967c478bd9Sstevel@tonic-gate sigact.sa_handler = SIG_IGN; 977c478bd9Sstevel@tonic-gate (void) sigemptyset(&sigact.sa_mask); 987c478bd9Sstevel@tonic-gate (void) sigaction(SIGINT, &sigact, NULL); 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate if ((pmtab = ALLOC_PMTAB) == PNULL) { 1017c478bd9Sstevel@tonic-gate log("ttymon_express: ALLOC_PMTAB failed"); 1027c478bd9Sstevel@tonic-gate exit(1); 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate if (parse_args(argc, argv, pmtab) != 0) { 1067c478bd9Sstevel@tonic-gate log("ttymon_express: parse_args failed"); 1077c478bd9Sstevel@tonic-gate exit(1); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate read_ttydefs(NULL, FALSE); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate if ((pmtab->p_device != NULL) && (*(pmtab->p_device) != '\0') && 1137c478bd9Sstevel@tonic-gate strcmp(pmtab->p_device, "/dev/console") == 0) { 1147c478bd9Sstevel@tonic-gate while (checkut_line(pmtab->p_device)) 1157c478bd9Sstevel@tonic-gate sleep(15); 1167c478bd9Sstevel@tonic-gate } 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate if ((pmtab->p_device == NULL) || (*(pmtab->p_device) == '\0')) { 1197c478bd9Sstevel@tonic-gate devname = find_ttyname(0); 1207c478bd9Sstevel@tonic-gate if ((devname == NULL) || (*devname == '\0')) { 1217c478bd9Sstevel@tonic-gate log("ttyname cannot find the device on fd 0"); 1227c478bd9Sstevel@tonic-gate exit(1); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate pmtab->p_device = devname; 1257c478bd9Sstevel@tonic-gate #ifdef DEBUG 1267c478bd9Sstevel@tonic-gate debug("ttymon_express: devname = %s", devname); 1277c478bd9Sstevel@tonic-gate #endif 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * become session leader 1307c478bd9Sstevel@tonic-gate * fd 0 is closed and reopened just to make sure 1317c478bd9Sstevel@tonic-gate * controlling tty is set up right 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate (void) setsid(); 1347c478bd9Sstevel@tonic-gate (void) close(0); 1357c478bd9Sstevel@tonic-gate revokedevaccess(pmtab->p_device, 0, 0, 0); 1367c478bd9Sstevel@tonic-gate if (open(pmtab->p_device, O_RDWR) < 0) { 1377c478bd9Sstevel@tonic-gate log("open %s failed: %s", pmtab->p_device, 1387c478bd9Sstevel@tonic-gate strerror(errno)); 1397c478bd9Sstevel@tonic-gate exit(1); 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate if ((pmtab->p_modules != NULL) && 1427c478bd9Sstevel@tonic-gate (*(pmtab->p_modules) != '\0')) { 1437c478bd9Sstevel@tonic-gate if (push_linedisc(0, pmtab->p_modules, 1447c478bd9Sstevel@tonic-gate pmtab->p_device) == -1) 1457c478bd9Sstevel@tonic-gate exit(1); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate if (initial_termio(0, pmtab) == -1) 1487c478bd9Sstevel@tonic-gate exit(1); 1497c478bd9Sstevel@tonic-gate di_devperm_logout((const char *)pmtab->p_device); 1507c478bd9Sstevel@tonic-gate } else { 1517c478bd9Sstevel@tonic-gate (void) setsid(); 1527c478bd9Sstevel@tonic-gate (void) close(0); 1537c478bd9Sstevel@tonic-gate Retry = FALSE; 1547c478bd9Sstevel@tonic-gate open_device(pmtab); 1557c478bd9Sstevel@tonic-gate if (Retry) /* open failed */ 1567c478bd9Sstevel@tonic-gate exit(1); 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate tmchild(pmtab); 1597c478bd9Sstevel@tonic-gate exit(1); /*NOTREACHED*/ 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * parse_arg - parse cmd line arguments 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate static int 1667c478bd9Sstevel@tonic-gate parse_args(int argc, char **argv, struct pmtab *pmtab) 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate static char p_server[] = "/usr/bin/login"; 1697c478bd9Sstevel@tonic-gate extern char *lastname(); 1707c478bd9Sstevel@tonic-gate extern void getty_account(); 171*fea9cb91Slq150181 static char termbuf[MAX_TERM_TYPE_LEN]; 172*fea9cb91Slq150181 static struct cons_getterm cnterm = {sizeof (termbuf), termbuf}; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate /* initialize fields to some default first */ 1757c478bd9Sstevel@tonic-gate pmtab->p_tag = ""; 1767c478bd9Sstevel@tonic-gate pmtab->p_flags = 0; 1777c478bd9Sstevel@tonic-gate pmtab->p_identity = "root"; 1787c478bd9Sstevel@tonic-gate pmtab->p_res1 = "reserved"; 1797c478bd9Sstevel@tonic-gate pmtab->p_res2 = "reserved"; 1807c478bd9Sstevel@tonic-gate pmtab->p_res3 = "reserved"; 1817c478bd9Sstevel@tonic-gate pmtab->p_uid = 0; 1827c478bd9Sstevel@tonic-gate pmtab->p_gid = 0; 1837c478bd9Sstevel@tonic-gate pmtab->p_dir = "/"; 1847c478bd9Sstevel@tonic-gate pmtab->p_ttyflags = 0; 1857c478bd9Sstevel@tonic-gate pmtab->p_count = 0; 1867c478bd9Sstevel@tonic-gate pmtab->p_server = p_server; 1877c478bd9Sstevel@tonic-gate pmtab->p_timeout = 0; 1887c478bd9Sstevel@tonic-gate pmtab->p_modules = ""; 1897c478bd9Sstevel@tonic-gate pmtab->p_prompt = "login: "; 1907c478bd9Sstevel@tonic-gate pmtab->p_dmsg = ""; 1917c478bd9Sstevel@tonic-gate pmtab->p_termtype = ""; 1927c478bd9Sstevel@tonic-gate pmtab->p_device = ""; 1937c478bd9Sstevel@tonic-gate pmtab->p_status = GETTY; 1947c478bd9Sstevel@tonic-gate if (strcmp(lastname(argv[0]), "getty") == 0) { 1957c478bd9Sstevel@tonic-gate pmtab->p_ttylabel = "300"; 1967c478bd9Sstevel@tonic-gate getty_options(argc, argv, pmtab); 1977c478bd9Sstevel@tonic-gate } else { 198*fea9cb91Slq150181 int cn_fd; 199*fea9cb91Slq150181 2007c478bd9Sstevel@tonic-gate pmtab->p_ttylabel = "9600"; 2017c478bd9Sstevel@tonic-gate ttymon_options(argc, argv, pmtab); 202*fea9cb91Slq150181 203*fea9cb91Slq150181 /* 204*fea9cb91Slq150181 * The following code is only reached if -g was specified. 205*fea9cb91Slq150181 * It attempts to determine a suitable terminal type for 206*fea9cb91Slq150181 * the console login process. 207*fea9cb91Slq150181 * 208*fea9cb91Slq150181 * If -d /dev/console also specified, we send an ioctl 209*fea9cb91Slq150181 * to the console device to query the TERM type. 210*fea9cb91Slq150181 * 211*fea9cb91Slq150181 * If any of the tests, system calls, or ioctls fail 212*fea9cb91Slq150181 * then pmtab->p_termtype retains its default value 213*fea9cb91Slq150181 * of "". otherwise it is set to a term type value 214*fea9cb91Slq150181 * that was returned. 215*fea9cb91Slq150181 */ 216*fea9cb91Slq150181 if ((strlen(pmtab->p_termtype) == 0) && 217*fea9cb91Slq150181 (strcmp(pmtab->p_device, "/dev/console") == 0) && 218*fea9cb91Slq150181 ((cn_fd = open("/dev/console", O_RDONLY)) != -1)) { 219*fea9cb91Slq150181 220*fea9cb91Slq150181 if (ioctl(cn_fd, CONS_GETTERM, &cnterm) != -1) 221*fea9cb91Slq150181 pmtab->p_termtype = cnterm.cn_term_type; 222*fea9cb91Slq150181 (void) close(cn_fd); 2237c478bd9Sstevel@tonic-gate } 224*fea9cb91Slq150181 } 225*fea9cb91Slq150181 2267c478bd9Sstevel@tonic-gate if ((pmtab->p_device != NULL) && (*(pmtab->p_device) != '\0')) 2277c478bd9Sstevel@tonic-gate getty_account(pmtab->p_device); /* utmp accounting */ 2287c478bd9Sstevel@tonic-gate return (0); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate /* 2337c478bd9Sstevel@tonic-gate * ttymon_options - scan and check args for ttymon express 2347c478bd9Sstevel@tonic-gate */ 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate static void 2377c478bd9Sstevel@tonic-gate ttymon_options(int argc, char **argv, struct pmtab *pmtab) 2387c478bd9Sstevel@tonic-gate { 2397c478bd9Sstevel@tonic-gate int c; /* option letter */ 2407c478bd9Sstevel@tonic-gate char *timeout; 2417c478bd9Sstevel@tonic-gate int gflag = 0; /* -g seen */ 2427c478bd9Sstevel@tonic-gate int size = 0; 2437c478bd9Sstevel@tonic-gate char tbuf[BUFSIZ]; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate extern char *optarg; 2467c478bd9Sstevel@tonic-gate extern int optind; 2477c478bd9Sstevel@tonic-gate extern void copystr(); 2487c478bd9Sstevel@tonic-gate extern char *strsave(); 2497c478bd9Sstevel@tonic-gate extern char *getword(); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "T:gd:ht:p:m:l:")) != -1) { 2527c478bd9Sstevel@tonic-gate switch (c) { 2537c478bd9Sstevel@tonic-gate case 'g': 2547c478bd9Sstevel@tonic-gate gflag = 1; 2557c478bd9Sstevel@tonic-gate break; 2567c478bd9Sstevel@tonic-gate case 'd': 2577c478bd9Sstevel@tonic-gate pmtab->p_device = optarg; 2587c478bd9Sstevel@tonic-gate break; 2597c478bd9Sstevel@tonic-gate case 'h': 2607c478bd9Sstevel@tonic-gate pmtab->p_ttyflags &= ~H_FLAG; 2617c478bd9Sstevel@tonic-gate break; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate case 'T': 2647c478bd9Sstevel@tonic-gate pmtab->p_termtype = optarg; 2657c478bd9Sstevel@tonic-gate break; 2667c478bd9Sstevel@tonic-gate /* 2677c478bd9Sstevel@tonic-gate * case 'b': 2687c478bd9Sstevel@tonic-gate * pmtab->p_ttyflags |= B_FLAG; 2697c478bd9Sstevel@tonic-gate * pmtab->p_ttyflags |= R_FLAG; 2707c478bd9Sstevel@tonic-gate * break; 2717c478bd9Sstevel@tonic-gate */ 2727c478bd9Sstevel@tonic-gate case 't': 2737c478bd9Sstevel@tonic-gate timeout = optarg; 2747c478bd9Sstevel@tonic-gate while (*optarg) { 2757c478bd9Sstevel@tonic-gate if (!isdigit(*optarg++)) { 2767c478bd9Sstevel@tonic-gate log("Invalid argument for " 2777c478bd9Sstevel@tonic-gate "\"-t\" -- number expected."); 2787c478bd9Sstevel@tonic-gate usage(); 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate pmtab->p_timeout = atoi(timeout); 2827c478bd9Sstevel@tonic-gate break; 2837c478bd9Sstevel@tonic-gate case 'p': 2847c478bd9Sstevel@tonic-gate copystr(tbuf, optarg); 2857c478bd9Sstevel@tonic-gate pmtab->p_prompt = strsave(getword(tbuf, &size, TRUE)); 2867c478bd9Sstevel@tonic-gate break; 2877c478bd9Sstevel@tonic-gate case 'm': 2887c478bd9Sstevel@tonic-gate pmtab->p_modules = optarg; 2897c478bd9Sstevel@tonic-gate if (vml(pmtab->p_modules) != 0) 2907c478bd9Sstevel@tonic-gate usage(); 2917c478bd9Sstevel@tonic-gate break; 2927c478bd9Sstevel@tonic-gate case 'l': 2937c478bd9Sstevel@tonic-gate pmtab->p_ttylabel = optarg; 2947c478bd9Sstevel@tonic-gate break; 2957c478bd9Sstevel@tonic-gate case '?': 2967c478bd9Sstevel@tonic-gate usage(); 2977c478bd9Sstevel@tonic-gate break; /*NOTREACHED*/ 2987c478bd9Sstevel@tonic-gate } 2997c478bd9Sstevel@tonic-gate } 3007c478bd9Sstevel@tonic-gate if (optind < argc) 3017c478bd9Sstevel@tonic-gate usage(); 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate if (!gflag) 3047c478bd9Sstevel@tonic-gate usage(); 3057c478bd9Sstevel@tonic-gate } 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate /* 3087c478bd9Sstevel@tonic-gate * usage - print out a usage message 3097c478bd9Sstevel@tonic-gate */ 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate static void 3127c478bd9Sstevel@tonic-gate usage() 3137c478bd9Sstevel@tonic-gate { 3147c478bd9Sstevel@tonic-gate char *umsg = "Usage: ttymon\n ttymon -g [-h] [-d device] " 3157c478bd9Sstevel@tonic-gate "[-l ttylabel] [-t timeout] [-p prompt] [-m modules]\n"; 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate if (isatty(STDERR_FILENO)) 3187c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s", umsg); 3197c478bd9Sstevel@tonic-gate else 3207c478bd9Sstevel@tonic-gate cons_printf(umsg); 3217c478bd9Sstevel@tonic-gate exit(1); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * getty_options - this is cut from getty.c 3267c478bd9Sstevel@tonic-gate * - it scan getty cmd args 3277c478bd9Sstevel@tonic-gate * - modification is made to stuff args in pmtab 3287c478bd9Sstevel@tonic-gate */ 3297c478bd9Sstevel@tonic-gate static void 3307c478bd9Sstevel@tonic-gate getty_options(argc, argv, pmtab) 3317c478bd9Sstevel@tonic-gate int argc; 3327c478bd9Sstevel@tonic-gate char **argv; 3337c478bd9Sstevel@tonic-gate struct pmtab *pmtab; 3347c478bd9Sstevel@tonic-gate { 3357c478bd9Sstevel@tonic-gate char *ptr; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate /* 3387c478bd9Sstevel@tonic-gate * the pre-4.0 getty's hang_up_line() is a no-op. 3397c478bd9Sstevel@tonic-gate * For compatibility, H_FLAG cannot be set for this "getty". 3407c478bd9Sstevel@tonic-gate */ 3417c478bd9Sstevel@tonic-gate pmtab->p_ttyflags &= ~(H_FLAG); 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate while (--argc && **++argv == '-') { 3447c478bd9Sstevel@tonic-gate for (ptr = *argv + 1; *ptr; ptr++) 3457c478bd9Sstevel@tonic-gate switch (*ptr) { 3467c478bd9Sstevel@tonic-gate case 'h': 3477c478bd9Sstevel@tonic-gate break; 3487c478bd9Sstevel@tonic-gate case 't': 3497c478bd9Sstevel@tonic-gate if (isdigit(*++ptr)) { 3507c478bd9Sstevel@tonic-gate (void) sscanf(ptr, "%d", &(pmtab->p_timeout)); 3517c478bd9Sstevel@tonic-gate while (isdigit(*++ptr)); 3527c478bd9Sstevel@tonic-gate ptr--; 3537c478bd9Sstevel@tonic-gate } else if (--argc) { 3547c478bd9Sstevel@tonic-gate if (isdigit(*(ptr = *++argv))) 3557c478bd9Sstevel@tonic-gate (void) sscanf(ptr, "%d", 3567c478bd9Sstevel@tonic-gate &(pmtab->p_timeout)); 3577c478bd9Sstevel@tonic-gate else { 3587c478bd9Sstevel@tonic-gate log("getty: timeout argument <%s> " 3597c478bd9Sstevel@tonic-gate "invalid", *argv); 3607c478bd9Sstevel@tonic-gate exit(1); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate break; 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate case 'c': 3667c478bd9Sstevel@tonic-gate log("Use \"sttydefs -l\" to check /etc/ttydefs."); 3677c478bd9Sstevel@tonic-gate exit(0); 3687c478bd9Sstevel@tonic-gate default: 3697c478bd9Sstevel@tonic-gate break; 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate } 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate if (argc < 1) { 3747c478bd9Sstevel@tonic-gate log("getty: no terminal line specified."); 3757c478bd9Sstevel@tonic-gate exit(1); 3767c478bd9Sstevel@tonic-gate } else { 3777c478bd9Sstevel@tonic-gate (void) strcat(devbuf, "/dev/"); 3787c478bd9Sstevel@tonic-gate (void) strcat(devbuf, *argv); 3797c478bd9Sstevel@tonic-gate pmtab->p_device = devbuf; 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate if (--argc > 0) { 3837c478bd9Sstevel@tonic-gate pmtab->p_ttylabel = *++argv; 3847c478bd9Sstevel@tonic-gate } 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate /* 3877c478bd9Sstevel@tonic-gate * every thing after this will be ignored 3887c478bd9Sstevel@tonic-gate * i.e. termtype and linedisc are ignored 3897c478bd9Sstevel@tonic-gate */ 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate /* 3937c478bd9Sstevel@tonic-gate * find_ttyname(fd) - find the name of device associated with fd. 3947c478bd9Sstevel@tonic-gate * - it first tries utmpx to see if an entry exists 3957c478bd9Sstevel@tonic-gate * - with my pid and ut_line is defined. If ut_line 3967c478bd9Sstevel@tonic-gate * - is defined, it will see if the major and minor 3977c478bd9Sstevel@tonic-gate * - number of fd and devname from utmpx match. 3987c478bd9Sstevel@tonic-gate * - If utmpx search fails, ttyname(fd) will be called. 3997c478bd9Sstevel@tonic-gate */ 4007c478bd9Sstevel@tonic-gate static char * 4017c478bd9Sstevel@tonic-gate find_ttyname(fd) 4027c478bd9Sstevel@tonic-gate int fd; 4037c478bd9Sstevel@tonic-gate { 4047c478bd9Sstevel@tonic-gate pid_t ownpid; 4057c478bd9Sstevel@tonic-gate struct utmpx *u; 4067c478bd9Sstevel@tonic-gate static struct stat statf, statu; 4077c478bd9Sstevel@tonic-gate static char buf[BUFSIZ]; 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate ownpid = getpid(); 4107c478bd9Sstevel@tonic-gate setutxent(); 4117c478bd9Sstevel@tonic-gate while ((u = getutxent()) != NULL) { 4127c478bd9Sstevel@tonic-gate if (u->ut_pid == ownpid) { 4137c478bd9Sstevel@tonic-gate if (strlen(u->ut_line) != 0) { 4147c478bd9Sstevel@tonic-gate if (*(u->ut_line) != '/') { 4157c478bd9Sstevel@tonic-gate (void) strcpy(buf, "/dev/"); 4167c478bd9Sstevel@tonic-gate (void) strncat(buf, u->ut_line, 4177c478bd9Sstevel@tonic-gate sizeof (u->ut_line)); 4187c478bd9Sstevel@tonic-gate } else { 4197c478bd9Sstevel@tonic-gate (void) strncat(buf, u->ut_line, 4207c478bd9Sstevel@tonic-gate sizeof (u->ut_line)); 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate else 4247c478bd9Sstevel@tonic-gate u = NULL; 4257c478bd9Sstevel@tonic-gate break; 4267c478bd9Sstevel@tonic-gate } 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate endutxent(); 4297c478bd9Sstevel@tonic-gate if ((u != NULL) && 4307c478bd9Sstevel@tonic-gate (fstat(fd, &statf) == 0) && 4317c478bd9Sstevel@tonic-gate (stat(buf, &statu) == 0) && 4327c478bd9Sstevel@tonic-gate (statf.st_dev == statu.st_dev) && 4337c478bd9Sstevel@tonic-gate (statf.st_rdev == statu.st_rdev)) { 4347c478bd9Sstevel@tonic-gate #ifdef DEBUG 4357c478bd9Sstevel@tonic-gate debug("ttymon_express: find device name from utmpx."); 4367c478bd9Sstevel@tonic-gate #endif 4377c478bd9Sstevel@tonic-gate return (buf); 4387c478bd9Sstevel@tonic-gate } else { 4397c478bd9Sstevel@tonic-gate #ifdef DEBUG 4407c478bd9Sstevel@tonic-gate debug("ttymon_express: calling ttyname to find device name."); 4417c478bd9Sstevel@tonic-gate #endif 4427c478bd9Sstevel@tonic-gate return (ttyname(fd)); 4437c478bd9Sstevel@tonic-gate } 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate /* 4477c478bd9Sstevel@tonic-gate * Revoke all access to a device node and make sure that there are 4487c478bd9Sstevel@tonic-gate * no interposed streams devices attached. Must be called before a 4497c478bd9Sstevel@tonic-gate * device is actually opened. 4507c478bd9Sstevel@tonic-gate * When fdetach is called, the underlying device node is revealed; it 4517c478bd9Sstevel@tonic-gate * will have the previous owner and that owner can re-attach; so we 4527c478bd9Sstevel@tonic-gate * retry until we win. 4537c478bd9Sstevel@tonic-gate * Ignore non-existent devices. 4547c478bd9Sstevel@tonic-gate */ 4557c478bd9Sstevel@tonic-gate void 4567c478bd9Sstevel@tonic-gate revokedevaccess(char *dev, uid_t uid, gid_t gid, mode_t mode) 4577c478bd9Sstevel@tonic-gate { 4587c478bd9Sstevel@tonic-gate do { 4597c478bd9Sstevel@tonic-gate if (chown(dev, uid, gid) == -1) 4607c478bd9Sstevel@tonic-gate return; 4617c478bd9Sstevel@tonic-gate } while (fdetach(dev) == 0); 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate /* Remove ACLs */ 4647c478bd9Sstevel@tonic-gate 465fa9e4066Sahrens (void) acl_strip(dev, uid, gid, mode); 4667c478bd9Sstevel@tonic-gate } 467