Merge commit '00f1a4f432b3d8aad1aa270e91c44c57f03ef407'
[unleashed.git] / usr / src / cmd / oamuser / lib / putgrent.c
blobabede6c4053658c788c4b75a6eaadb01d36e2b28
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
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"
32 #include <stdio.h>
33 #include <grp.h>
34 #include <unistd.h>
37 * putgrent() function to write a group structure to a file
38 * supports the use of group names that with + or -
40 void
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, ":");
60 } else {
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);
68 memptr++;
69 if (memptr != NULL && *memptr != NULL)
70 (void) fprintf(to, ",");
73 (void) fprintf(to, "\n");
74 } else {
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);
86 memptr++;
87 if (*memptr != NULL)
88 (void) fprintf(to, ",");
91 (void) fprintf(to, "\n");