4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
32 #include <sys/types.h>
38 #define GRPTMP "/etc/gtmp"
39 #define GRPBUFSIZ 5120
43 char *group
; /* name of group to add */
44 gid_t gid
; /* gid of group to add */
46 FILE *etcgrp
; /* /etc/group file */
47 FILE *etctmp
; /* temp file */
48 int o_mask
; /* old umask value */
49 int newdone
= 0; /* set true when new entry done */
50 struct stat sb
; /* stat buf to copy modes */
53 if ((etcgrp
= fopen(GROUP
, "r")) == NULL
) {
57 if (fstat(fileno(etcgrp
), &sb
) < 0) {
58 /* If we can't get mode, take a default */
59 sb
.st_mode
= S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
;
63 etctmp
= fopen(GRPTMP
, "w+");
71 if (fchmod(fileno(etctmp
), sb
.st_mode
) != 0 ||
72 fchown(fileno(etctmp
), sb
.st_uid
, sb
.st_gid
) != 0 ||
73 lockf(fileno(etctmp
), F_LOCK
, 0) != 0) {
80 while (fgets(buf
, GRPBUFSIZ
, etcgrp
) != NULL
) {
81 /* Check for NameService reference */
82 if (!newdone
&& (buf
[0] == '+' || buf
[0] == '-')) {
83 (void) fprintf(etctmp
, "%s::%u:\n", group
, gid
);
91 (void) fclose(etcgrp
);
94 (void) fprintf(etctmp
, "%s::%u:\n", group
, gid
);
97 if (rename(GRPTMP
, GROUP
) < 0) {
103 (void) fclose(etctmp
);