dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / getent / dogetproject.c
blobf5a7ffa6e9b6916a15a7b35188b99d738da995e7
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 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <grp.h>
31 #include <stdlib.h>
32 #include <project.h>
33 #include "getent.h"
35 static int
36 putprojent(const struct project *proj, FILE *fp)
38 char **names;
40 if (proj == NULL)
41 return (1);
43 if (fprintf(fp, "%s:%ld:%s:",
44 proj->pj_name != NULL ? proj->pj_name : "",
45 proj->pj_projid,
46 proj->pj_comment != NULL ? proj->pj_comment : "") == EOF)
47 return (1);
48 names = proj->pj_users;
49 if (names != NULL) {
50 if (*names != NULL)
51 if (fputs(*names++, fp) == EOF)
52 return (1);
53 while (*names != NULL)
54 if (fprintf(fp, ",%s", *names++) == EOF)
55 return (1);
57 if (putc(':', fp) == EOF)
58 return (1);
59 names = proj->pj_groups;
60 if (names != NULL) {
61 if (*names != NULL)
62 if (fputs(*names++, fp) == EOF)
63 return (1);
64 while (*names != NULL)
65 if (fprintf(fp, ",%s", *names++) == EOF)
66 return (1);
68 if (putc(':', fp) == EOF)
69 return (1);
70 if (fprintf(fp, "%s\n",
71 proj->pj_attr != NULL ? proj->pj_attr : "") == EOF)
72 return (1);
73 return (0);
76 int
77 dogetproject(const char **list)
79 struct project proj;
80 struct project *pproj;
81 projid_t projid;
82 void *buf[PROJECT_BUFSZ];
83 int rc = EXC_SUCCESS;
84 char *ptr;
86 if (list == NULL || *list == NULL) {
87 setprojent();
88 while ((pproj = getprojent(&proj, buf, PROJECT_BUFSZ)) != NULL)
89 (void) putprojent(pproj, stdout);
90 endprojent();
91 } else {
92 for (; *list != NULL; list++) {
93 projid = strtol(*list, &ptr, 10);
94 if (ptr == *list)
95 pproj = getprojbyname(*list, &proj,
96 buf, PROJECT_BUFSZ);
97 else
98 pproj = getprojbyid(projid, &proj,
99 buf, PROJECT_BUFSZ);
100 if (pproj == NULL)
101 rc = EXC_NAME_NOT_FOUND;
102 else
103 (void) putprojent(pproj, stdout);
107 return (rc);