xref: /titanic_41/usr/src/cmd/bnu/gwd.c (revision 84ab085a13f931bc78e7415e7ce921dbaa14fcb3)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* from SVR4 bnu:gwd.c 2.5 */
27 
28 #include "uucp.h"
29 
30 /*
31  *	gwd - get working directory
32  *	Uid and Euid are global
33  *	return
34  *		0 - ok
35  *	 	FAIL - failed
36  */
37 
38 int
39 gwd(wkdir)
40 char *wkdir;
41 {
42 	FILE *fp;
43 	char cmd[BUFSIZ];
44 
45 	*wkdir = '\0';
46 	(void) sprintf(cmd, "%s pwd 2>&-", PATH);
47 
48 #ifndef V7
49 	(void) setuid(Uid);
50 	fp = popen(cmd, "r");
51 	(void) setuid(Euid);
52 #else
53 	fp = popen(cmd, "r");
54 #endif
55 
56 	if (fp == NULL)
57 		return(FAIL);
58 
59 	if (fgets(wkdir, MAXFULLNAME, fp) == NULL) {
60 		(void) pclose(fp);
61 		return(FAIL);
62 	}
63 	if (wkdir[strlen(wkdir)-1] == '\n')
64 		wkdir[strlen(wkdir)-1] = '\0';
65 	(void) pclose(fp);
66 	return(0);
67 }
68 
69 
70 /*
71  * uidstat(file, &statbuf)
72  * This is a stat call with the uid set from Euid to Uid.
73  * Used from uucp.c and uux.c to permit file copies
74  * from directories that may not be searchable by other.
75  * return:
76  *	same as stat()
77  */
78 
79 int
80 uidstat(file, buf)
81 char *file;
82 struct stat *buf;
83 {
84 #ifndef V7
85 	register ret;
86 
87 	(void) setuid(Uid);
88 	ret = stat(file, buf);
89 	(void) setuid(Euid);
90 	return(ret);
91 #else /* V7 */
92 	int	ret;
93 
94 	if (vfork() == 0) {
95 		(void) setuid(Uid);
96 		_exit(stat(file, buf));
97 	}
98 	wait(&ret);
99 	return(ret);
100 #endif /* V7 */
101 }
102