1 /* Copyright (c) 1997, 1998, 1999, 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <rpcsvc/nis.h>
23 /* internal_nis_ismember ()
24 return codes: -1 principal is in -group
25 0 principal isn't in any group
26 1 pirncipal is in group */
28 internal_ismember (const_nis_name principal
, const_nis_name group
)
30 size_t grouplen
= strlen (group
);
31 char buf
[grouplen
+ 50];
32 char leafbuf
[grouplen
+ 2];
33 char domainbuf
[grouplen
+ 2];
38 cp
= stpcpy (buf
, nis_leaf_of_r (group
, leafbuf
, sizeof (leafbuf
) - 1));
39 cp
= stpcpy (cp
, ".groups_dir");
40 cp2
= nis_domain_of_r (group
, domainbuf
, sizeof (domainbuf
) - 1);
41 if (cp2
!= NULL
&& cp2
[0] != '\0')
47 res
= nis_lookup (buf
, EXPAND_NAME
|FOLLOW_LINKS
);
48 if (res
== NULL
|| NIS_RES_STATUS (res
) != NIS_SUCCESS
)
54 if ((NIS_RES_NUMOBJ (res
) != 1) ||
55 (__type_of (NIS_RES_OBJECT (res
)) != NIS_GROUP_OBJ
))
61 /* We search twice in the list, at first, if we have the name
62 with a "-", then if without. "-member" has priority */
63 for (i
= 0; i
< NIS_RES_OBJECT(res
)->GR_data
.gr_members
.gr_members_len
; ++i
)
65 cp
= NIS_RES_OBJECT (res
)->GR_data
.gr_members
.gr_members_val
[i
];
68 if (strcmp (&cp
[1], principal
) == 0)
74 switch (internal_ismember (principal
, &cp
[2]))
88 char buf1
[strlen (principal
) + 2];
89 char buf2
[strlen (cp
) + 2];
91 if (strcmp (nis_domain_of_r (principal
, buf1
, sizeof buf1
),
92 nis_domain_of_r (cp
, buf2
, sizeof buf2
)) == 0)
101 for (i
= 0; i
< NIS_RES_OBJECT (res
)->GR_data
.gr_members
.gr_members_len
; ++i
)
103 cp
= NIS_RES_OBJECT (res
)->GR_data
.gr_members
.gr_members_val
[i
];
106 if (strcmp (cp
, principal
) == 0)
108 nis_freeresult (res
);
112 switch (internal_ismember (principal
, &cp
[1]))
115 nis_freeresult (res
);
118 nis_freeresult (res
);
126 char buf1
[strlen (principal
) + 2];
127 char buf2
[strlen (cp
) + 2];
129 if (strcmp (nis_domain_of_r (principal
, buf1
, sizeof buf1
),
130 nis_domain_of_r (cp
, buf2
, sizeof buf2
)) == 0)
132 nis_freeresult (res
);
138 nis_freeresult (res
);
143 nis_ismember (const_nis_name principal
, const_nis_name group
)
145 if (group
!= NULL
&& group
[0] != '\0' && principal
!= NULL
)
146 return internal_ismember (principal
, group
) == 1 ? TRUE
: FALSE
;