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]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * 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"
36 extern struct group
*fgetgrent(FILE *);
39 * putgrent() function to write a group structure to a file
40 * supports the use of group names that with + or -
43 putgrent(struct group
*grpstr
, FILE *to
)
45 char **memptr
; /* member vector pointer */
47 if (grpstr
->gr_name
[0] == '+' || grpstr
->gr_name
[0] == '-') {
49 * if the groupname starts with either a '+' or '-' then
50 * write out what we can as best as we can
51 * we assume that fgetgrent() set gr_gid to 0 so
52 * write a null entry instead of 0
53 * This should not break /etc/nsswitch.conf for any of
54 * "group: compat", "group: files", "group: nis"
57 (void) fprintf(to
, "%s:%s:", grpstr
->gr_name
,
58 grpstr
->gr_passwd
!= NULL
? grpstr
->gr_passwd
: "");
60 if (grpstr
->gr_gid
== 0) {
61 (void) fprintf(to
, ":");
63 (void) fprintf(to
, "%ld:", grpstr
->gr_gid
);
66 memptr
= grpstr
->gr_mem
;
68 while (memptr
!= NULL
&& *memptr
!= NULL
) {
69 (void) fprintf(to
, "%s", *memptr
);
71 if (memptr
!= NULL
&& *memptr
!= NULL
)
72 (void) fprintf(to
, ",");
75 (void) fprintf(to
, "\n");
78 * otherwise write out all the fields in the group structure
81 (void) fprintf(to
, "%s:%s:%ld:", grpstr
->gr_name
,
82 grpstr
->gr_passwd
, grpstr
->gr_gid
);
84 memptr
= grpstr
->gr_mem
;
86 while (*memptr
!= NULL
) {
87 (void) fprintf(to
, "%s", *memptr
);
90 (void) fprintf(to
, ",");
93 (void) fprintf(to
, "\n");