xref: /onnv-gate/usr/src/cmd/mail/pipletr.c (revision 373:5de22f2b7283)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*373Sceastha /*
23*373Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*373Sceastha  * Use is subject to license terms.
25*373Sceastha  */
26*373Sceastha 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include "mail.h"
330Sstevel@tonic-gate 
34*373Sceastha int
dowait(pid_t pidval)35*373Sceastha dowait(pid_t pidval)
360Sstevel@tonic-gate {
37*373Sceastha 	pid_t w;
380Sstevel@tonic-gate 	int status;
390Sstevel@tonic-gate 	void (*istat)(), (*qstat)();
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 	/*
420Sstevel@tonic-gate 		Parent temporarily ignores signals so it will remain
430Sstevel@tonic-gate 		around for command to finish
440Sstevel@tonic-gate 	*/
450Sstevel@tonic-gate 	istat = signal(SIGINT, SIG_IGN);
460Sstevel@tonic-gate 	qstat = signal(SIGQUIT, SIG_IGN);
470Sstevel@tonic-gate 
480Sstevel@tonic-gate 	while ((w = wait(&status)) != pidval && w != CERROR);
490Sstevel@tonic-gate 	if (w == CERROR) {
500Sstevel@tonic-gate 		status = -errno;
510Sstevel@tonic-gate 		signal(SIGINT, istat);
520Sstevel@tonic-gate 		signal(SIGQUIT, qstat);
530Sstevel@tonic-gate 		return (status);
540Sstevel@tonic-gate 	}
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	signal(SIGINT, istat);
570Sstevel@tonic-gate 	signal(SIGQUIT, qstat);
580Sstevel@tonic-gate 	status = ((status>>8)&0xFF);  		/* extract 8 high order bits */
590Sstevel@tonic-gate 	return (status);
600Sstevel@tonic-gate }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate 	invoke shell to execute command waiting for command to terminate
640Sstevel@tonic-gate 		s	-> command string
650Sstevel@tonic-gate 	return:
660Sstevel@tonic-gate 		status	-> command exit status
670Sstevel@tonic-gate */
68*373Sceastha int
systm(char * s)69*373Sceastha systm(char *s)
700Sstevel@tonic-gate {
710Sstevel@tonic-gate 	pid_t	pid;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	/*
740Sstevel@tonic-gate 		Spawn the shell to execute command, however, since the
750Sstevel@tonic-gate 		mail command runs setgid mode reset the effective group
760Sstevel@tonic-gate 		id to the real group id so that the command does not
770Sstevel@tonic-gate 		acquire any special privileges
780Sstevel@tonic-gate 	*/
790Sstevel@tonic-gate 	if ((pid = fork()) == CHILD) {
800Sstevel@tonic-gate 		setuid(my_uid);
810Sstevel@tonic-gate 		setgid(my_gid);
820Sstevel@tonic-gate #ifdef SVR3
830Sstevel@tonic-gate 		execl("/bin/sh", "sh", "-c", s, (char*)NULL);
840Sstevel@tonic-gate #else
850Sstevel@tonic-gate 		execl("/usr/bin/sh", "sh", "-c", s, (char*)NULL);
860Sstevel@tonic-gate #endif
870Sstevel@tonic-gate 		exit(127);
880Sstevel@tonic-gate 	}
890Sstevel@tonic-gate 	return (dowait(pid));
900Sstevel@tonic-gate }
91