Print this page
8485 Remove set but unused variables in usr/src/cmd
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/krb5/ldap_util/kdb5_ldap_list.c
+++ new/usr/src/cmd/krb5/ldap_util/kdb5_ldap_list.c
1 -#pragma ident "%Z%%M% %I% %E% SMI"
2 -
3 1 /*
4 2 * kadmin/ldap_util/kdb5_ldap_list.c
5 3 */
6 4
7 5 /* Copyright (c) 2004-2005, Novell, Inc.
8 6 * All rights reserved.
9 7 *
10 8 * Redistribution and use in source and binary forms, with or without
11 9 * modification, are permitted provided that the following conditions are met:
12 10 *
13 11 * * Redistributions of source code must retain the above copyright notice,
14 12 * this list of conditions and the following disclaimer.
15 13 * * Redistributions in binary form must reproduce the above copyright
16 14 * notice, this list of conditions and the following disclaimer in the
17 15 * documentation and/or other materials provided with the distribution.
18 16 * * The copyright holder's name is not used to endorse or promote products
19 17 * derived from this software without specific prior written permission.
20 18 *
21 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 29 * POSSIBILITY OF SUCH DAMAGE.
32 30 */
33 31
34 32 /*
35 33 * Miscellaneous functions for managing the string and integer lists
36 34 */
37 35
38 36 #include <k5-int.h>
39 37 #include "kdb5_ldap_list.h"
40 38
41 39 /*
42 40 * Counts the number of entries in the given array of strings
43 41 */
44 42 int list_count_str_array(char **list)
45 43 {
46 44 int i = 0;
47 45
48 46 if (list == NULL)
49 47 return 0;
50 48
51 49 for (i = 0; *list != NULL; list++) {
52 50 i++;
53 51 }
54 52
55 53 return i;
56 54 }
57 55
58 56
59 57 /*
60 58 * Counts the number of entries in the given array of integers
61 59 */
62 60 int list_count_int_array(int *list)
63 61 {
64 62 int i = 0;
65 63
66 64 if (list == NULL)
67 65 return 0;
68 66
69 67 for (i = 0; *list != END_OF_LIST; list++) {
70 68 i++;
71 69 }
72 70
73 71 return i;
74 72 }
75 73
76 74
77 75 /*
78 76 * Frees the entries in a given list and not the list pointer
79 77 */
80 78 void krb5_free_list_entries(list)
81 79 char **list;
82 80 {
83 81 if (list == NULL)
84 82 return;
85 83 for (; *list != NULL; list++) {
86 84 free(*list);
87 85 *list = NULL;
88 86 }
89 87
90 88 return;
91 89 }
92 90
93 91
94 92 /*
95 93 * Tokenize the given string based on the delimiter provided
96 94 * and return the result as a list
97 95 */
98 96 krb5_error_code
99 97 krb5_parse_list(buffer, delimiter, list)
100 98 char *buffer;
101 99 char *delimiter;
102 100 char **list;
103 101 {
104 102 char *str = NULL;
105 103 char *token = NULL;
106 104 char *ptrptr = NULL;
107 105 char **plist = list;
108 106 krb5_error_code retval = 0;
109 107 int count = 0;
110 108
111 109 if ((buffer == NULL) || (list == NULL) || (delimiter == NULL)) {
112 110 return EINVAL;
113 111 }
114 112
115 113 str = strdup(buffer);
116 114 if (str == NULL)
117 115 return ENOMEM;
118 116
119 117 token = strtok_r(str, delimiter, &ptrptr);
120 118 for (count = 1; ((token != NULL) && (count < MAX_LIST_ENTRIES));
121 119 plist++, count++) {
122 120 *plist = strdup(token);
123 121 if (*plist == NULL) {
124 122 retval = ENOMEM;
125 123 goto cleanup;
126 124 }
127 125 token = strtok_r(NULL, delimiter, &ptrptr);
128 126 }
129 127 *plist = NULL;
130 128
131 129 cleanup:
132 130 if (str) {
133 131 free(str);
134 132 str = NULL;
135 133 }
136 134 if (retval)
137 135 krb5_free_list_entries(list);
138 136
139 137 return retval;
140 138 }
141 139
142 140
143 141 int compare_int(m1, m2)
144 142 const void *m1;
145 143 const void *m2;
146 144 {
147 145 int mi1 = *(const int *)m1;
148 146 int mi2 = *(const int *)m2;
149 147
150 148 return (mi1 - mi2);
151 149 }
152 150
153 151
154 152 /*
155 153 * Modifies the destination list to contain or not to contain the
156 154 * entries present in the source list, depending on the mode
↓ open down ↓ |
144 lines elided |
↑ open up ↑ |
157 155 * (ADD or DELETE).
158 156 */
159 157 void list_modify_str_array(destlist, sourcelist, mode)
160 158 char ***destlist;
161 159 const char **sourcelist;
162 160 int mode;
163 161 {
164 162 char **dlist = NULL, **tmplist = NULL;
165 163 const char **slist = NULL;
166 164 int dcount = 0, scount = 0, copycount = 0;
167 - int found = 0;
168 165
169 166 if ((destlist == NULL) || (*destlist == NULL) || (sourcelist == NULL))
170 167 return;
171 168
172 169 /* We need to add every entry present in the source list to
173 170 * the destination list */
174 171 if (mode == LIST_MODE_ADD) {
175 172 /* Traverse throught the end of destlist for appending */
176 173 for (dlist = *destlist, dcount = 0; *dlist != NULL;
177 174 dlist++, dcount++) {
178 175 ; /* NULL statement */
179 176 }
180 177 /* Count the number of entries in the source list */
181 178 for (slist = sourcelist, scount = 0; *slist != NULL;
182 179 slist++, scount++) {
183 180 ; /* NULL statement */
184 181 }
185 182 /* Reset the slist pointer to the start of source list */
186 183 slist = sourcelist;
187 184
188 185 /* Now append the source list to the existing destlist */
189 186 if ((dcount + scount) < MAX_LIST_ENTRIES)
190 187 copycount = scount;
191 188 else
192 189 /* Leave the last entry for list terminator(=NULL) */
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
193 190 copycount = (MAX_LIST_ENTRIES -1) - dcount;
194 191
195 192 memcpy(dlist, slist, (sizeof(char *) * copycount));
196 193 dlist += copycount;
197 194 *dlist = NULL;
198 195 } else if (mode == LIST_MODE_DELETE) {
199 196 /* We need to delete every entry present in the source list
200 197 * from the destination list */
201 198 for (slist = sourcelist; *slist != NULL; slist++) {
202 199 for (dlist = *destlist; *dlist != NULL; dlist++) {
203 - found = 0; /* value not found */
204 200 /* DN is case insensitive string */
205 201 if (strcasecmp(*dlist, *slist) == 0) {
206 - found = 1;
207 202 free(*dlist);
208 203 /* Advance the rest of the entries by one */
209 204 for (tmplist = dlist; *tmplist != NULL; tmplist++) {
210 205 *tmplist = *(tmplist+1);
211 206 }
212 207 break;
213 208 }
214 209 }
215 210 }
216 211 }
217 212
218 213 return;
219 214 }
220 215
221 216
222 217 /*
223 218 * Modifies the destination list to contain or not to contain the
224 219 * entries present in the source list, depending on the mode
225 220 * (ADD or DELETE). where the list is array of integers.
226 221 */
227 222 int list_modify_int_array(destlist, sourcelist, mode)
228 223 int *destlist;
229 224 const int *sourcelist;
230 225 int mode;
231 226 {
232 227 int *dlist = NULL, *tmplist = NULL;
233 228 const int *slist = NULL;
234 229 int dcount = 0, scount = 0, copycount = 0;
235 230 int tcount = 0;
236 231
237 232 if ((destlist == NULL) || (sourcelist == NULL))
238 233 return 0;
239 234
240 235 /* We need to add every entry present in the source list to the
241 236 * destination list */
242 237 if (mode == LIST_MODE_ADD) {
243 238 /* Traverse throught the end of destlist for appending */
244 239 for (dlist = destlist, dcount = 0; *dlist != END_OF_LIST;
245 240 dlist++, dcount++)
246 241 ; /* NULL statement */
247 242
248 243 /* Count the number of entries in the source list */
249 244 for (slist = sourcelist, scount = 0; *slist != END_OF_LIST;
250 245 slist++, scount++)
251 246 ; /* NULL statement */
252 247
253 248 /* Reset the slist pointer to the start of source list */
254 249 slist = sourcelist;
255 250
256 251 /* Now append the source list to the existing destlist */
257 252 if ((dcount + scount) < MAX_LIST_ENTRIES)
258 253 copycount = scount;
259 254 else
260 255 /* Leave the last entry for list terminator(=NULL) */
261 256 copycount = (MAX_LIST_ENTRIES -1) - dcount;
262 257
263 258 memcpy(dlist, slist, (sizeof(int) * copycount));
264 259 dlist += copycount;
265 260 *dlist = END_OF_LIST;
266 261 tcount = dcount + copycount;
267 262 } else if (mode == LIST_MODE_DELETE) {
268 263 /* We need to delete every entry present in the source list from
269 264 * the destination list */
270 265 for (slist = sourcelist; *slist != END_OF_LIST; slist++) {
271 266 for (dlist = destlist; *dlist != END_OF_LIST; dlist++) {
272 267 if (*dlist == *slist) {
273 268 /* Advance the rest of the entries by one */
274 269 for (tmplist = dlist; *tmplist != END_OF_LIST; tmplist++) {
275 270 *tmplist = *(tmplist+1);
276 271 }
277 272 break;
278 273 }
279 274 }
280 275 }
281 276 /* count the number of entries */
282 277 for (dlist = destlist, tcount = 0; *dlist != END_OF_LIST; dlist++) {
283 278 tcount++;
284 279 }
285 280 }
286 281
287 282 return tcount;
288 283 }
289 284
↓ open down ↓ |
73 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX