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
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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
29 #pragma ident "%Z%%M% %I% %E% SMI"
32 * accton - calls syscall with super-user privileges
36 #include <sys/types.h>
37 #include <sys/param.h>
51 main(int argc
, char **argv
)
56 if ((pwd
= getpwnam("adm")) == NULL
) {
57 perror("cannot determine adm's uid"), exit(1);
60 if (uid
== ROOT
|| uid
== admuid
) {
61 if (setuid(ROOT
) == ERR
) {
62 perror("cannot setuid (check command mode and owner)");
67 if (acct(argc
> 1 ? argv
[1] : 0) < 0) {
68 perror(argv
[1]), exit(1);
73 fprintf(stderr
, "%s: permission denied\n", argv
[0]);
81 struct stat
*s
= &stbuf
;
84 if ((fd
= open(admfile
, O_RDONLY
|O_CREAT
, 0644)) == ERR
) {
85 perror("creat"), exit(1);
88 if (fstat(fd
, s
) == ERR
) {
93 if (s
->st_uid
!= admuid
|| s
->st_gid
!= (gid_t
)admuid
)
94 if (fchown(fd
, admuid
, (gid_t
)admuid
) == ERR
) {
95 perror("cannot change owner"), exit(1);
98 /* was if(s->st_mode & 0777 != 0664) */
99 if ((s
->st_mode
& S_IAMB
) != S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWUSR
|S_IROTH
)
100 if (fchmod(fd
, S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWUSR
|S_IROTH
) == ERR
) {
101 perror("cannot chmod"), exit(1);