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. */
21 #include <rpcsvc/nis.h>
22 #include <rpcsvc/nislib.h>
24 /* internal_nis_ismember ()
25 return codes: -1 principal is in -group
26 0 principal isn't in any group
27 1 pirncipal is in group */
29 internal_ismember (const_nis_name principal, const_nis_name group)
31 if (group != NULL && strlen (group) > 0)
33 char buf[strlen (group) + 50];
34 char leafbuf[strlen (group) + 2];
35 char domainbuf[strlen (group) + 2];
40 cp = stpcpy (buf, nis_leaf_of_r (group, leafbuf, sizeof (leafbuf) - 1));
41 cp = stpcpy (cp, ".groups_dir");
42 cp2 = nis_domain_of_r (group, domainbuf, sizeof (domainbuf) - 1);
43 if (cp2 != NULL && strlen (cp2) > 0)
48 res = nis_lookup (buf, EXPAND_NAME|FOLLOW_LINKS);
49 if (res->status != NIS_SUCCESS && res->status != NIS_S_SUCCESS)
52 if ((res->objects.objects_len != 1) ||
53 (res->objects.objects_val[0].zo_data.zo_type != GROUP_OBJ))
56 /* We search twice in the list, at first, if we have the name
57 with a "-", then if without. "-member" has priority */
59 i < res->objects.objects_val[0].GR_data.gr_members.gr_members_len;
62 cp =res->objects.objects_val[0].GR_data.gr_members.gr_members_val[i];
65 if (strcmp (&cp[1], principal) == 0)
68 switch (internal_ismember (principal, &cp[2]))
80 char buf1[strlen (principal) + 2];
81 char buf2[strlen (cp) + 2];
83 strcpy (buf1, nis_domain_of (principal));
84 strcpy (buf2, nis_domain_of (cp));
85 if (strcmp (buf1, buf2) == 0)
91 i < res->objects.objects_val[0].GR_data.gr_members.gr_members_len;
94 cp =res->objects.objects_val[0].GR_data.gr_members.gr_members_val[i];
97 if (strcmp (cp, principal) == 0)
100 switch (internal_ismember (principal, &cp[1]))
112 char buf1[strlen (principal) + 2];
113 char buf2[strlen (cp) + 2];
115 if (strcmp (nis_domain_of_r (principal, buf1, sizeof buf1),
116 nis_domain_of_r (cp, buf2, sizeof buf2)) == 0)
127 nis_ismember (const_nis_name principal, const_nis_name group)
129 if (group != NULL && strlen (group) > 0)
130 return internal_ismember (principal, group) == 1 ? TRUE : FALSE;