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"
37 * putgrent() function to write a group structure to a file
38 * supports the use of group names that with + or -
41 putgrent(struct group
*grpstr
, FILE *to
)
43 char **memptr
; /* member vector pointer */
45 if (grpstr
->gr_name
[0] == '+' || grpstr
->gr_name
[0] == '-') {
47 * if the groupname starts with either a '+' or '-' then
48 * write out what we can as best as we can
49 * we assume that fgetgrent() set gr_gid to 0 so
50 * write a null entry instead of 0
51 * This should not break /etc/nsswitch.conf for any of
52 * "group: compat", "group: files", "group: nis"
55 (void) fprintf(to
, "%s:%s:", grpstr
->gr_name
,
56 grpstr
->gr_passwd
!= NULL
? grpstr
->gr_passwd
: "");
58 if (grpstr
->gr_gid
== 0) {
59 (void) fprintf(to
, ":");
61 (void) fprintf(to
, "%ld:", grpstr
->gr_gid
);
64 memptr
= grpstr
->gr_mem
;
66 while (memptr
!= NULL
&& *memptr
!= NULL
) {
67 (void) fprintf(to
, "%s", *memptr
);
69 if (memptr
!= NULL
&& *memptr
!= NULL
)
70 (void) fprintf(to
, ",");
73 (void) fprintf(to
, "\n");
76 * otherwise write out all the fields in the group structure
79 (void) fprintf(to
, "%s:%s:%ld:", grpstr
->gr_name
,
80 grpstr
->gr_passwd
, grpstr
->gr_gid
);
82 memptr
= grpstr
->gr_mem
;
84 while (*memptr
!= NULL
) {
85 (void) fprintf(to
, "%s", *memptr
);
88 (void) fprintf(to
, ",");
91 (void) fprintf(to
, "\n");