Update.
[glibc.git] / nis / nis_print_group_entry.c
blobfbc9ad11bae7dba80f5f5c5c342a498ef3f9fe46
1 /* Copyright (c) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <string.h>
21 #include <rpcsvc/nis.h>
23 void
24 nis_print_group_entry (const_nis_name group)
26 if (group != NULL && strlen (group) > 0)
28 char buf[strlen (group) + 50];
29 char leafbuf[strlen (group) + 3];
30 char domainbuf[strlen (group) + 3];
31 unsigned long mem_exp_cnt = 0, mem_imp_cnt = 0, mem_rec_cnt = 0;
32 unsigned long nomem_exp_cnt = 0, nomem_imp_cnt = 0, nomem_rec_cnt = 0;
33 char **mem_exp, **mem_imp, **mem_rec;
34 char **nomem_exp, **nomem_imp, **nomem_rec;
35 nis_result *res;
36 char *cp, *cp2;
37 u_int i;
39 cp = stpcpy (buf, nis_leaf_of_r (group, leafbuf, sizeof (leafbuf) - 1));
40 cp = stpcpy (cp, ".groups_dir");
41 cp2 = nis_domain_of_r (group, domainbuf, sizeof (domainbuf) - 1);
42 if (cp2 != NULL && strlen (cp2) > 0)
44 *cp++ = '.';
45 stpcpy (cp, cp2);
47 res = nis_lookup (buf, FOLLOW_LINKS | EXPAND_NAME);
49 if (NIS_RES_STATUS(res) != NIS_SUCCESS)
50 return;
52 if ((NIS_RES_NUMOBJ (res) != 1) ||
53 (__type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ))
54 return;
56 mem_exp = malloc (sizeof (char *) * NIS_RES_NUMOBJ (res));
57 mem_imp = malloc (sizeof (char *) * NIS_RES_NUMOBJ (res));
58 mem_rec = malloc (sizeof (char *) * NIS_RES_NUMOBJ (res));
59 nomem_exp = malloc (sizeof (char *) * NIS_RES_NUMOBJ (res));
60 nomem_imp = malloc (sizeof (char *) * NIS_RES_NUMOBJ (res));
61 nomem_rec = malloc (sizeof (char *) * NIS_RES_NUMOBJ (res));
63 for (i = 0;
64 i < NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len; ++i)
66 char *grmem =
67 NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val[i];
68 int neg = grmem[0] == '-';
70 switch (grmem[neg])
72 case '*':
73 if (neg)
75 nomem_imp[nomem_imp_cnt] = grmem;
76 ++nomem_imp_cnt;
78 else
80 mem_imp[mem_imp_cnt] = grmem;
81 ++mem_imp_cnt;
83 break;
84 case '@':
85 if (neg)
87 nomem_rec[nomem_rec_cnt] = grmem;
88 ++nomem_rec_cnt;
90 else
92 mem_rec[mem_rec_cnt] = grmem;
93 ++mem_rec_cnt;
95 break;
96 default:
97 if (neg)
99 nomem_exp[nomem_exp_cnt] = grmem;
100 ++nomem_exp_cnt;
102 else
104 mem_exp[mem_exp_cnt] = grmem;
105 ++mem_exp_cnt;
107 break;
111 char buf[strlen (NIS_RES_OBJECT (res)->zo_domain) + 10];
112 printf (_("Group entry for \"%s.%s\" group:\n"),
113 NIS_RES_OBJECT (res)->zo_name,
114 nis_domain_of_r (NIS_RES_OBJECT (res)->zo_domain,
115 buf, strlen (NIS_RES_OBJECT (res)->zo_domain)
116 + 10));
118 if (mem_exp_cnt)
120 fputs (_(" Explicit members:\n"), stdout);
121 for (i = 0; i < mem_exp_cnt; ++i)
122 printf ("\t%s\n", mem_exp[i]);
124 else
125 fputs (_(" No explicit members\n"), stdout);
126 if (mem_imp_cnt)
128 fputs (_(" Implicit members:\n"), stdout);
129 for (i = 0; i < mem_imp_cnt; ++i)
130 printf ("\t%s\n", &mem_imp[i][2]);
132 else
133 fputs (_(" No implicit members\n"), stdout);
134 if (mem_rec_cnt)
136 fputs (_(" Recursive members:\n"), stdout);
137 for (i = 0; i < mem_rec_cnt; ++i)
138 printf ("\t%s\n", &mem_rec[i][1]);
140 else
141 fputs (_(" No recursive members\n"), stdout);
142 if (nomem_exp_cnt)
144 fputs (_(" Explicit nonmembers:\n"), stdout);
145 for (i = 0; i < nomem_exp_cnt; ++i)
146 printf ("\t%s\n", &nomem_exp[i][1]);
148 else
149 fputs (_(" No explicit nonmembers\n"), stdout);
150 if (nomem_imp_cnt)
152 fputs (_(" Implicit nonmembers:\n"), stdout);
153 for (i = 0; i < nomem_imp_cnt; ++i)
154 printf ("\t%s\n", &mem_imp[i][3]);
156 else
157 fputs (_(" No implicit nonmembers\n"), stdout);
158 if (nomem_rec_cnt)
160 fputs (_(" Explicit nonmembers:\n"), stdout);
161 for (i = 0; i < nomem_rec_cnt; ++i)
162 printf ("\t%s=n", &nomem_rec[i][2]);
164 else
165 fputs (_(" No recursive nonmembers\n"), stdout);
167 free (mem_exp);
168 free (mem_imp);
169 free (mem_rec);
170 free (nomem_exp);
171 free (nomem_imp);
172 free (nomem_rec);
173 nis_freeresult (res);