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