]>
Commit | Line | Data |
---|---|---|
32abdb71 | 1 | /* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc. |
51702635 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. */ | |
19 | ||
20 | #include <string.h> | |
21 | #include <rpcsvc/nis.h> | |
51702635 UD |
22 | |
23 | nis_error | |
24 | nis_removemember (const_nis_name member, const_nis_name group) | |
25 | { | |
a53bad16 | 26 | if (group != NULL && group[0] != '\0') |
51702635 | 27 | { |
a53bad16 UD |
28 | size_t grouplen = strlen (group); |
29 | char buf[grouplen + 14 + NIS_MAXNAMELEN]; | |
30 | char leafbuf[grouplen + 2]; | |
31 | char domainbuf[grouplen + 2]; | |
51702635 UD |
32 | nis_name *newmem; |
33 | nis_result *res, *res2; | |
34 | nis_error status; | |
35 | char *cp, *cp2; | |
714a562f | 36 | unsigned long int i, j, k; |
51702635 UD |
37 | |
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); | |
a53bad16 | 41 | if (cp2 != NULL && cp2[0] != '\0') |
51702635 UD |
42 | { |
43 | cp = stpcpy (cp, "."); | |
714a562f | 44 | stpcpy (cp, cp2); |
51702635 UD |
45 | } |
46 | res = nis_lookup (buf, FOLLOW_LINKS|EXPAND_NAME); | |
32abdb71 | 47 | if (res == NULL || NIS_RES_STATUS (res) != NIS_SUCCESS) |
51702635 | 48 | { |
32abdb71 UD |
49 | if (res) |
50 | { | |
51 | status = NIS_RES_STATUS (res); | |
52 | nis_freeresult (res); | |
53 | } | |
54 | else | |
55 | return NIS_NOMEMORY; | |
51702635 UD |
56 | return status; |
57 | } | |
dfd2257a | 58 | |
51702635 | 59 | if ((res->objects.objects_len != 1) || |
dfd2257a | 60 | (__type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ)) |
32abdb71 UD |
61 | { |
62 | nis_freeresult (res); | |
63 | return NIS_INVALIDOBJ; | |
64 | } | |
51702635 | 65 | |
dfd2257a | 66 | newmem = |
32abdb71 | 67 | calloc (NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len, |
dfd2257a | 68 | sizeof (char *)); |
91eee4dd UD |
69 | if (newmem == NULL) |
70 | return NIS_NOMEMORY; | |
32abdb71 | 71 | |
dfd2257a | 72 | k = NIS_RES_OBJECT (res)[0].GR_data.gr_members.gr_members_len; |
51702635 | 73 | j = 0; |
dfd2257a | 74 | for (i = 0; i < NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len; |
714a562f | 75 | ++i) |
51702635 | 76 | { |
dfd2257a | 77 | if (strcmp (NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_val[i], |
714a562f | 78 | member) != 0) |
51702635 | 79 | { |
dfd2257a | 80 | newmem[j] = NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_val[i]; |
51702635 UD |
81 | ++j; |
82 | } | |
714a562f UD |
83 | else |
84 | { | |
dfd2257a | 85 | free (NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_val[i]); |
714a562f UD |
86 | --k; |
87 | } | |
51702635 | 88 | } |
dfd2257a | 89 | free (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val); |
714a562f | 90 | newmem = realloc (newmem, k * sizeof (char*)); |
91eee4dd UD |
91 | if (newmem == NULL) |
92 | return NIS_NOMEMORY; | |
32abdb71 | 93 | |
dfd2257a UD |
94 | NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val = newmem; |
95 | NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len = k; | |
714a562f | 96 | |
dfd2257a | 97 | cp = stpcpy (buf, NIS_RES_OBJECT (res)->zo_name); |
714a562f | 98 | *cp++ = '.'; |
dfd2257a UD |
99 | strncpy (cp, NIS_RES_OBJECT (res)->zo_domain, NIS_MAXNAMELEN); |
100 | res2 = nis_modify (buf, NIS_RES_OBJECT (res)); | |
91eee4dd | 101 | status = NIS_RES_STATUS (res2); |
51702635 UD |
102 | nis_freeresult (res); |
103 | nis_freeresult (res2); | |
104 | ||
105 | return status; | |
106 | } | |
107 | else | |
108 | return NIS_FAIL; | |
109 | } |