xref: /illumos-gate/usr/src/cmd/bnu/xqt.c (revision d8e10381a0083d7717710b0db7e64707bc0f3ff8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1988 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 /*
30  * Copyright (c) 2016 by Delphix. All rights reserved.
31  */
32 
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include "uucp.h"
37 
38 static void euucico();
39 
40 /*
41  * start up uucico for rmtname
42  * return:
43  *	none
44  */
45 void
46 xuucico(rmtname)
47 char *rmtname;
48 {
49 	/*
50 	 * start uucico for rmtname system
51 	 */
52 	if (fork() == 0) {	/* can't vfork() */
53 		/*
54 		 * hide the uid of the initiator of this job so that it
55 		 * doesn't get notified about things that don't concern it.
56 		 */
57 		(void) setuid(geteuid());
58 		euucico(rmtname);
59 	}
60 	return;
61 }
62 
63 static void
64 euucico(rmtname)
65 char	*rmtname;
66 {
67 	char opt[100];
68 
69 	(void) close(0);
70 	(void) close(1);
71 	(void) close(2);
72 	(void) open("/dev/null", 0);
73 	(void) open("/dev/null", 1);
74 	(void) open("/dev/null", 1);
75 	(void) signal(SIGINT, SIG_IGN);
76 	(void) signal(SIGHUP, SIG_IGN);
77 	(void) signal(SIGQUIT, SIG_IGN);
78 	ucloselog();
79 	if (rmtname[0] != '\0')
80 		(void) sprintf(opt, "-s%s", rmtname);
81 	else
82 		opt[0] = '\0';
83 	(void) execle(UUCICO, "UUCICO", "-r1", opt, (char *) 0, Env);
84 	exit(100);
85 }
86 
87 
88 /*
89  * start up uuxqt
90  * return:
91  *	none
92  */
93 void
94 xuuxqt(rmtname)
95 char	*rmtname;
96 {
97 	char	opt[100];
98 	register int i, maxfiles;
99 
100 	if (rmtname && rmtname[0] != '\0')
101 		(void) sprintf(opt, "-s%s", rmtname);
102 	else
103 		opt[0] = '\0';
104 	/*
105 	 * start uuxqt
106 	 */
107 	if (vfork() == 0) {
108 		(void) close(0);
109 		(void) close(1);
110 		(void) close(2);
111 		(void) open("/dev/null", 2);
112 		(void) open("/dev/null", 2);
113 		(void) open("/dev/null", 2);
114 		(void) signal(SIGINT, SIG_IGN);
115 		(void) signal(SIGHUP, SIG_IGN);
116 		(void) signal(SIGQUIT, SIG_IGN);
117 		ucloselog();
118 #ifdef ATTSVR3
119 		maxfiles = ulimit(4, 0);
120 #else /* !ATTSVR3 */
121 #ifdef BSD4_2
122 		maxfiles = getdtablesize();
123 #else /* BSD4_2 */
124 		maxfiles = NOFILE;
125 #endif /* BSD4_2 */
126 #endif /* ATTSVR3 */
127 		for (i = 3; i < maxfiles; i++)
128 			(void) close(i);
129 		/*
130 		 * hide the uid of the initiator of this job so that it
131 		 * doesn't get notified about things that don't concern it.
132 		 */
133 		(void) setuid(geteuid());
134 		(void) execle(UUXQT, "UUXQT", opt, (char *) 0, Env);
135 		_exit(100);
136 	}
137 	return;
138 }
139