165
165
DICT *dict_cidr_open(const char *mapname, int open_flags, int dict_flags)
167
167
DICT_CIDR *dict_cidr;
170
VSTRING *line_buffer;
170
VSTRING *line_buffer = 0;
172
172
DICT_CIDR_ENTRY *rule;
173
173
DICT_CIDR_ENTRY *last_rule = 0;
177
* Let the optimizer worry about eliminating redundant code.
179
#define DICT_CIDR_OPEN_RETURN(d) do { \
181
if (map_fp != 0 && vstream_fclose(map_fp)) \
182
msg_fatal("cidr map %s: read error: %m", mapname); \
183
if (line_buffer != 0) \
184
vstring_free(line_buffer); \
179
193
if (open_flags != O_RDONLY)
180
return (dict_surrogate(DICT_TYPE_CIDR, mapname, open_flags, dict_flags,
181
"%s:%s map requires O_RDONLY access mode",
182
DICT_TYPE_CIDR, mapname));
194
DICT_CIDR_OPEN_RETURN(dict_surrogate(DICT_TYPE_CIDR, mapname,
195
open_flags, dict_flags,
196
"%s:%s map requires O_RDONLY access mode",
197
DICT_TYPE_CIDR, mapname));
185
200
* Open the configuration file.
187
202
if ((map_fp = vstream_fopen(mapname, O_RDONLY, 0)) == 0)
188
return (dict_surrogate(DICT_TYPE_CIDR, mapname, open_flags, dict_flags,
189
"open %s: %m", mapname));
203
DICT_CIDR_OPEN_RETURN(dict_surrogate(DICT_TYPE_CIDR, mapname,
204
open_flags, dict_flags,
205
"open %s: %m", mapname));
190
206
if (fstat(vstream_fileno(map_fp), &st) < 0)
191
207
msg_fatal("fstat %s: %m", mapname);
194
* No early returns without memory leaks.
196
209
line_buffer = vstring_alloc(100);
197
210
why = vstring_alloc(100);
224
237
last_rule = rule;
230
if (vstream_fclose(map_fp))
231
msg_fatal("cidr map %s: read error: %m", mapname);
232
vstring_free(line_buffer);
235
return (DICT_DEBUG (&dict_cidr->dict));
240
DICT_CIDR_OPEN_RETURN(DICT_DEBUG (&dict_cidr->dict));