7600 zfs rollback should pass target snapshot to kernel
[unleashed.git] / usr / src / cmd / bnu / strsave.c
blob44f460f367b7cbb191243dc09aa2f7eab2cc5dd1
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:strsave.c 1.5 */
28 #include "uucp.h"
30 /* #include <errno.h> */
31 /* #include <malloc.h> */
32 /* #include <string.h> */
33 /* #include <sys/types.h> */
34 /* #include <sys/stat.h> */
36 /* copy str into data space -- caller should report errors. */
38 GLOBAL char *
39 strsave(str)
40 register char *str;
42 register char *rval;
44 rval = (char *)malloc(strlen(str) + 1);
45 if (rval != 0)
46 strcpy(rval, str);
47 return(rval);
50 /* Determine if the effective user id has the appropriate permission
51 on a file. Modeled after access(2).
52 amode:
53 00 just checks for file existence.
54 04 checks read permission.
55 02 checks write permission.
56 01 checks execute/search permission.
57 other bits are ignored quietly.
60 GLOBAL int
61 eaccess( path, amode )
62 char *path;
63 register mode_t amode;
65 struct stat s;
66 uid_t euid;
68 if( stat( path, &s ) == -1 )
69 return(-1); /* can't stat file */
70 amode &= 07;
72 if( (euid = geteuid()) == 0 )
73 return(0); /* root can do all */
74 if( euid == s.st_uid )
75 s.st_mode >>= 6; /* use owner bits */
76 else if( getegid() == s.st_gid )
77 s.st_mode >>= 3; /* use group bits */
79 if( (amode & s.st_mode) == amode )
80 return(0); /* access permitted */
81 errno = EACCES;
82 return(-1);