~ubuntu-branches/ubuntu/gutsy/dhcp/gutsy-security

« back to all changes in this revision

Viewing changes to common/alloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2004-10-30 21:07:22 UTC
  • Revision ID: james.westby@ubuntu.com-20041030210722-p0u4682vtncfxnnn
Tags: upstream-2.0pl5
ImportĀ upstreamĀ versionĀ 2.0pl5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* alloc.c
 
2
 
 
3
   Memory allocation... */
 
4
 
 
5
/*
 
6
 * Copyright (c) 1995, 1996, 1998 The Internet Software Consortium.
 
7
 * All rights reserved.
 
8
 *
 
9
 * Redistribution and use in source and binary forms, with or without
 
10
 * modification, are permitted provided that the following conditions
 
11
 * are met:
 
12
 *
 
13
 * 1. Redistributions of source code must retain the above copyright
 
14
 *    notice, this list of conditions and the following disclaimer.
 
15
 * 2. Redistributions in binary form must reproduce the above copyright
 
16
 *    notice, this list of conditions and the following disclaimer in the
 
17
 *    documentation and/or other materials provided with the distribution.
 
18
 * 3. Neither the name of The Internet Software Consortium nor the names
 
19
 *    of its contributors may be used to endorse or promote products derived
 
20
 *    from this software without specific prior written permission.
 
21
 *
 
22
 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
 
23
 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
24
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
25
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
26
 * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
 
27
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
28
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
29
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 
30
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
31
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
32
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 
33
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
34
 * SUCH DAMAGE.
 
35
 *
 
36
 * This software has been written for the Internet Software Consortium
 
37
 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
 
38
 * Enterprises.  To learn more about the Internet Software Consortium,
 
39
 * see ``http://www.vix.com/isc''.  To learn more about Vixie
 
40
 * Enterprises, see ``http://www.vix.com''.
 
41
 */
 
42
 
 
43
#ifndef lint
 
44
static char copyright[] =
 
45
"$Id: alloc.c,v 1.13.2.2 1999/03/26 16:39:36 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 
46
#endif /* not lint */
 
47
 
 
48
#include "dhcpd.h"
 
49
 
 
50
struct dhcp_packet *dhcp_free_list;
 
51
struct packet *packet_free_list;
 
52
 
 
53
VOIDPTR dmalloc (size, name)
 
54
        int size;
 
55
        char *name;
 
56
{
 
57
        VOIDPTR foo = (VOIDPTR)malloc (size);
 
58
        if (!foo)
 
59
                warn ("No memory for %s.", name);
 
60
        else
 
61
                memset (foo, 0, size);
 
62
        return foo;
 
63
}
 
64
 
 
65
void dfree (ptr, name)
 
66
        VOIDPTR ptr;
 
67
        char *name;
 
68
{
 
69
        if (!ptr) {
 
70
                warn ("dfree %s: free on null pointer.", name);
 
71
                return;
 
72
        }
 
73
        free (ptr);
 
74
}
 
75
 
 
76
struct packet *new_packet (name)
 
77
        char *name;
 
78
{
 
79
        struct packet *rval;
 
80
        rval = (struct packet *)dmalloc (sizeof (struct packet), name);
 
81
        return rval;
 
82
}
 
83
 
 
84
struct dhcp_packet *new_dhcp_packet (name)
 
85
        char *name;
 
86
{
 
87
        struct dhcp_packet *rval;
 
88
        rval = (struct dhcp_packet *)dmalloc (sizeof (struct dhcp_packet),
 
89
                                              name);
 
90
        return rval;
 
91
}
 
92
 
 
93
struct tree *new_tree (name)
 
94
        char *name;
 
95
{
 
96
        struct tree *rval = dmalloc (sizeof (struct tree), name);
 
97
        return rval;
 
98
}
 
99
 
 
100
struct tree_cache *free_tree_caches;
 
101
 
 
102
struct tree_cache *new_tree_cache (name)
 
103
        char *name;
 
104
{
 
105
        struct tree_cache *rval;
 
106
 
 
107
        if (free_tree_caches) {
 
108
                rval = free_tree_caches;
 
109
                free_tree_caches =
 
110
                        (struct tree_cache *)(rval -> value);
 
111
        } else {
 
112
                rval = dmalloc (sizeof (struct tree_cache), name);
 
113
                if (!rval)
 
114
                        error ("unable to allocate tree cache for %s.", name);
 
115
        }
 
116
        return rval;
 
117
}
 
118
 
 
119
struct hash_table *new_hash_table (count, name)
 
120
        int count;
 
121
        char *name;
 
122
{
 
123
        struct hash_table *rval = dmalloc (sizeof (struct hash_table)
 
124
                                           - (DEFAULT_HASH_SIZE
 
125
                                              * sizeof (struct hash_bucket *))
 
126
                                           + (count
 
127
                                              * sizeof (struct hash_bucket *)),
 
128
                                           name);
 
129
        rval -> hash_count = count;
 
130
        return rval;
 
131
}
 
132
 
 
133
struct hash_bucket *new_hash_bucket (name)
 
134
        char *name;
 
135
{
 
136
        struct hash_bucket *rval = dmalloc (sizeof (struct hash_bucket), name);
 
137
        return rval;
 
138
}
 
139
 
 
140
struct lease *new_leases (n, name)
 
141
        int n;
 
142
        char *name;
 
143
{
 
144
        struct lease *rval = dmalloc (n * sizeof (struct lease), name);
 
145
        return rval;
 
146
}
 
147
 
 
148
struct lease *new_lease (name)
 
149
        char *name;
 
150
{
 
151
        struct lease *rval = dmalloc (sizeof (struct lease), name);
 
152
        return rval;
 
153
}
 
154
 
 
155
struct subnet *new_subnet (name)
 
156
        char *name;
 
157
{
 
158
        struct subnet *rval = dmalloc (sizeof (struct subnet), name);
 
159
        return rval;
 
160
}
 
161
 
 
162
struct class *new_class (name)
 
163
        char *name;
 
164
{
 
165
        struct class *rval = dmalloc (sizeof (struct class), name);
 
166
        return rval;
 
167
}
 
168
 
 
169
struct shared_network *new_shared_network (name)
 
170
        char *name;
 
171
{
 
172
        struct shared_network *rval =
 
173
                dmalloc (sizeof (struct shared_network), name);
 
174
        return rval;
 
175
}
 
176
 
 
177
struct group *new_group (name)
 
178
        char *name;
 
179
{
 
180
        struct group *rval =
 
181
                dmalloc (sizeof (struct group), name);
 
182
        return rval;
 
183
}
 
184
 
 
185
struct protocol *new_protocol (name)
 
186
        char *name;
 
187
{
 
188
        struct protocol *rval = dmalloc (sizeof (struct protocol), name);
 
189
        return rval;
 
190
}
 
191
 
 
192
struct lease_state *free_lease_states;
 
193
 
 
194
struct lease_state *new_lease_state (name)
 
195
        char *name;
 
196
{
 
197
        struct lease_state *rval;
 
198
 
 
199
        if (free_lease_states) {
 
200
                rval = free_lease_states;
 
201
                free_lease_states =
 
202
                        (struct lease_state *)(free_lease_states -> next);
 
203
        } else {
 
204
                rval = dmalloc (sizeof (struct lease_state), name);
 
205
        }
 
206
        return rval;
 
207
}
 
208
 
 
209
struct domain_search_list *new_domain_search_list (name)
 
210
        char *name;
 
211
{
 
212
        struct domain_search_list *rval =
 
213
                dmalloc (sizeof (struct domain_search_list), name);
 
214
        return rval;
 
215
}
 
216
 
 
217
struct name_server *new_name_server (name)
 
218
        char *name;
 
219
{
 
220
        struct name_server *rval =
 
221
                dmalloc (sizeof (struct name_server), name);
 
222
        return rval;
 
223
}
 
224
 
 
225
void free_name_server (ptr, name)
 
226
        struct name_server *ptr;
 
227
        char *name;
 
228
{
 
229
        dfree ((VOIDPTR)ptr, name);
 
230
}
 
231
 
 
232
void free_domain_search_list (ptr, name)
 
233
        struct domain_search_list *ptr;
 
234
        char *name;
 
235
{
 
236
        dfree ((VOIDPTR)ptr, name);
 
237
}
 
238
 
 
239
void free_lease_state (ptr, name)
 
240
        struct lease_state *ptr;
 
241
        char *name;
 
242
{
 
243
        if (ptr -> prl)
 
244
                dfree (ptr -> prl, name);
 
245
        ptr -> next = free_lease_states;
 
246
        free_lease_states = ptr;
 
247
}
 
248
 
 
249
void free_protocol (ptr, name)
 
250
        struct protocol *ptr;
 
251
        char *name;
 
252
{
 
253
        dfree ((VOIDPTR)ptr, name);
 
254
}
 
255
 
 
256
void free_group (ptr, name)
 
257
        struct group *ptr;
 
258
        char *name;
 
259
{
 
260
        dfree ((VOIDPTR)ptr, name);
 
261
}
 
262
 
 
263
void free_shared_network (ptr, name)
 
264
        struct shared_network *ptr;
 
265
        char *name;
 
266
{
 
267
        dfree ((VOIDPTR)ptr, name);
 
268
}
 
269
 
 
270
void free_class (ptr, name)
 
271
        struct class *ptr;
 
272
        char *name;
 
273
{
 
274
        dfree ((VOIDPTR)ptr, name);
 
275
}
 
276
 
 
277
void free_subnet (ptr, name)
 
278
        struct subnet *ptr;
 
279
        char *name;
 
280
{
 
281
        dfree ((VOIDPTR)ptr, name);
 
282
}
 
283
 
 
284
void free_lease (ptr, name)
 
285
        struct lease *ptr;
 
286
        char *name;
 
287
{
 
288
        dfree ((VOIDPTR)ptr, name);
 
289
}
 
290
 
 
291
void free_hash_bucket (ptr, name)
 
292
        struct hash_bucket *ptr;
 
293
        char *name;
 
294
{
 
295
        dfree ((VOIDPTR)ptr, name);
 
296
}
 
297
 
 
298
void free_hash_table (ptr, name)
 
299
        struct hash_table *ptr;
 
300
        char *name;
 
301
{
 
302
        dfree ((VOIDPTR)ptr, name);
 
303
}
 
304
 
 
305
void free_tree_cache (ptr, name)
 
306
        struct tree_cache *ptr;
 
307
        char *name;
 
308
{
 
309
        ptr -> value = (unsigned char *)free_tree_caches;
 
310
        free_tree_caches = ptr;
 
311
}
 
312
 
 
313
void free_packet (ptr, name)
 
314
        struct packet *ptr;
 
315
        char *name;
 
316
{
 
317
        dfree ((VOIDPTR)ptr, name);
 
318
}
 
319
 
 
320
void free_dhcp_packet (ptr, name)
 
321
        struct dhcp_packet *ptr;
 
322
        char *name;
 
323
{
 
324
        dfree ((VOIDPTR)ptr, name);
 
325
}
 
326
 
 
327
void free_tree (ptr, name)
 
328
        struct tree *ptr;
 
329
        char *name;
 
330
{
 
331
        dfree ((VOIDPTR)ptr, name);
 
332
}