1 /*
2  * gestr120.c
3  *
4  * This module contains routines that read in structures from
5  * GECHO configuration files in a portable way, i.E. they will even
6  * work in cases where a fread(&structure, sizeof(structure), 1, stream)
7  * would fail because of structure packing or big endian problems.
8  *
9  * Only those structures that are of importance to MsgEd have been
10  * implemented.
11  *
12  * Written 03-Oct-98 by Tobias Ernst and donated to the Public Domain.
13  *
14  */
15 
16 #include <assert.h>
17 #include <stdio.h>
18 #include <string.h>
19 
20 #include "gestr120.h"
21 #include "memextra.h"
22 
23 /*
24  *  get_dword
25  *
26  *  Reads in a 4 byte word that is stored in little endian (Intel) notation
27  *  and converts it to the local representation n an architecture-
28  *  independent manner
29  */
30 
31 #define get_dword(ptr)            \
32    ((dword)((ptr)[0]) |           \
33     (((dword)((ptr)[1])) << 8)  | \
34     (((dword)((ptr)[2])) << 16) | \
35     (((dword)((ptr)[3])) << 24))  \
36 
37 /*
38  *  get_word
39  *
40  *  Reads in a 2 byte word that is stored in little endian (Intel) notation
41  *  and converts it to the local representation in an architecture-
42  *  independent manner
43  */
44 
45 #define get_word(ptr)         \
46     ((word)(ptr)[0] |         \
47      (((word)(ptr)[1]) << 8 ))
48 
49 
50 /*
51  * read_setup_ge
52  *
53  * reads a SETUP_GE structure.
54  *
55  */
56 
read_setup_ge(SETUP_GE * Setup,FILE * fp)57 int read_setup_ge(SETUP_GE *Setup, FILE *fp)
58 {
59     unsigned char *buffer = xmalloc(SETUP_GE_SIZE);
60     unsigned char *pbuf;
61     int i;
62 
63     pbuf = buffer;
64 
65     if (fread(buffer, SETUP_GE_SIZE, 1, fp) != 1)
66     {
67         xfree(buffer);
68         return -1;
69     }
70 
71     Setup->sysrev     = get_word(pbuf); pbuf += 2;
72     Setup->options    = get_word(pbuf); pbuf += 2;
73     Setup->autorenum  = get_word(pbuf); pbuf += 2;
74     Setup->maxpktsize = get_word(pbuf); pbuf += 2;
75 
76     Setup->logstyle        = *pbuf++;
77     Setup->oldnetmailboard = *pbuf++;
78     Setup->oldbadboard     = *pbuf++;
79     Setup->olddupboard     = *pbuf++;
80     Setup->recoveryboard   = *pbuf++;
81     Setup->filebuffer      = *pbuf++;
82     Setup->days            = *pbuf++;
83     Setup->swapping        = *pbuf++;
84     Setup->compr_default   = *pbuf++;
85 
86     memcpy(Setup->pmcolor, pbuf, 15); pbuf += 15;
87 
88     for (i=0; i < OLDAKAS; i++)
89     {
90         Setup->oldaka[i].zone  = get_word(pbuf); pbuf += 2;
91         Setup->oldaka[i].net   = get_word(pbuf); pbuf += 2;
92         Setup->oldaka[i].node  = get_word(pbuf); pbuf += 2;
93         Setup->oldaka[i].point = get_word(pbuf); pbuf += 2;
94     }
95 
96     for (i=0; i < OLDAKAS; i++)
97     {
98         Setup->oldpointnet[i] = get_word(pbuf); pbuf += 2;
99     }
100 
101     Setup->gekey  = get_dword(pbuf); pbuf += 4;
102     Setup->mbukey = get_dword(pbuf); pbuf += 4;
103 
104     memcpy(Setup->geregto, pbuf, 51); pbuf += 51;
105     memcpy(Setup->mburegto, pbuf, 51); pbuf += 51;
106     for (i = 0; i < USERS; i++)
107     {
108         memcpy(Setup->username[i], pbuf, 36); pbuf += 36;
109     }
110     memcpy(Setup->hmbpath, pbuf, 53); pbuf += 53;
111     memcpy(Setup->mailpath, pbuf, 53); pbuf += 53;
112     memcpy(Setup->inbound_path, pbuf, 53); pbuf += 53;
113     memcpy(Setup->outbound_path, pbuf, 53); pbuf += 53;
114     memcpy(Setup->echotoss_file, pbuf, 65); pbuf += 65;
115     memcpy(Setup->nodepath, pbuf, 53); pbuf += 53;
116     memcpy(Setup->areasfile, pbuf, 65); pbuf += 65;
117     memcpy(Setup->logfile, pbuf, 65); pbuf += 65;
118     memcpy(Setup->mgrlogfile, pbuf, 65); pbuf += 65;
119     memcpy(Setup->swap_path, pbuf, 53); pbuf += 53;
120     memcpy(Setup->tear_line, pbuf, 31); pbuf += 31;
121     for (i = 0; i < 20; i++)
122     {
123         memcpy(Setup->originline[i], pbuf, 61); pbuf += 61;
124     }
125     for (i = 0; i < 10; i++)
126     {
127         memcpy(Setup->compr_prog[i], pbuf, 13); pbuf += 13;
128     }
129     for (i = 0; i < 10; i++)
130     {
131         memcpy(Setup->compr_switches[i], pbuf, 20); pbuf += 20;
132     }
133     for (i = 0; i < 10; i++)
134     {
135         memcpy(Setup->decompr_prog[i], pbuf, 13); pbuf += 13;
136     }
137     for (i = 0; i < 10; i++)
138     {
139         memcpy(Setup->decompr_switches[i], pbuf, 20); pbuf += 20;
140     }
141     for (i = 0; i < 26; i++)
142     {
143         memcpy(Setup->oldgroups[i], pbuf, 21); pbuf += 21;
144     }
145 
146     Setup->lockmode = *pbuf++;
147 
148     memcpy(Setup->secure_path, pbuf, 53); pbuf += 53;
149     memcpy(Setup->rcvdmailpath, pbuf, 53); pbuf += 53;
150     memcpy(Setup->sentmailpath, pbuf, 53); pbuf += 53;
151     memcpy(Setup->semaphorepath, pbuf, 53); pbuf += 53;
152 
153     Setup->version_major = *pbuf++;
154     Setup->version_minor = *pbuf++;
155     Setup->semaphore_mode = *pbuf++;
156 
157     memcpy(Setup->badecho_path, pbuf, 53); pbuf += 53;
158 
159     Setup->mailer_type = *pbuf++;
160 
161     Setup->loglevel = get_word(pbuf); pbuf += 2;
162 
163     for (i = 0; i < 20; i++)
164     {
165         Setup->akamatch[i].zone = get_word(pbuf); pbuf += 2;
166         Setup->akamatch[i].net  = get_word(pbuf); pbuf += 2;
167         Setup->akamatch[i].aka  = *pbuf++;
168     }
169 
170     memcpy(Setup->mbulogfile, pbuf, 65); pbuf += 65;
171 
172     Setup->maxqqqs = get_word(pbuf); pbuf += 2;
173     Setup->maxqqqopen = *pbuf++;
174     Setup->maxhandles = *pbuf++;
175     Setup->maxarcsize = get_word(pbuf); pbuf += 2;
176     Setup->delfuture = get_word(pbuf); pbuf += 2;
177     Setup->extraoptions = get_word(pbuf); pbuf += 2;
178     Setup->firstboard = *pbuf++;
179     Setup->reserved1 = get_word(pbuf); pbuf += 2;
180     Setup->copy_persmail = get_word(pbuf); pbuf += 2;
181 
182     memcpy(Setup->oldpersmailboard, pbuf, USERS); pbuf += USERS;
183 
184     Setup->old_public_groups = get_dword(pbuf); pbuf += 4;
185     Setup->dupentries = get_word(pbuf); pbuf += 2;
186     Setup->oldrcvdboard = *pbuf++;
187     Setup->oldsentboard = *pbuf++;
188 
189     memcpy(Setup->oldakaboard, pbuf, OLDAKAS); pbuf += OLDAKAS;
190     memcpy(Setup->olduserboard, pbuf, USERS); pbuf += USERS;
191 
192     Setup->reserved2 = *pbuf++;
193 
194     for (i = 0; i < OLDUPLINKS; i++)
195     {
196         Setup->uplink[i].address.zone = get_word(pbuf); pbuf += 2;
197         Setup->uplink[i].address.net = get_word(pbuf); pbuf += 2;
198         Setup->uplink[i].address.node = get_word(pbuf); pbuf += 2;
199         Setup->uplink[i].address.point = get_word(pbuf); pbuf += 2;
200 
201         memcpy(Setup->uplink[i].areafix, pbuf, 9); pbuf += 9;
202         memcpy(Setup->uplink[i].password, pbuf, 17); pbuf += 17;
203         memcpy(Setup->uplink[i].filename, pbuf, 13); pbuf += 13;
204         memcpy(Setup->uplink[i].unused, pbuf, 6); pbuf += 6;
205 
206         Setup->uplink[i].options = *pbuf++;
207         Setup->uplink[i].filetype = *pbuf++;
208         Setup->uplink[i].groups = get_dword(pbuf); pbuf += 4;
209         Setup->uplink[i].origin = *pbuf++;
210     }
211 
212     memcpy(Setup->persmail_path, pbuf, 53); pbuf += 53;
213     memcpy(Setup->outpkts_path, pbuf, 53); pbuf += 53;
214 
215     for (i = 0; i < 10; i++)
216     {
217         Setup->compr_mem[i] = get_word(pbuf); pbuf += 2;
218     }
219     for (i = 0; i < 10; i++)
220     {
221         Setup->decompr_mem[i] = get_word(pbuf); pbuf += 2;
222     }
223 
224     Setup->pwdcrc = get_dword(pbuf); pbuf += 4;
225     Setup->default_maxmsgs = get_word(pbuf); pbuf += 2;
226     Setup->default_maxdays = get_word(pbuf); pbuf += 2;
227 
228     memcpy(Setup->gus_prog, pbuf, 13); pbuf += 13;
229     memcpy(Setup->gus_switches, pbuf, 20); pbuf += 20;
230 
231     Setup->gus_mem = get_word(pbuf); pbuf += 2;
232     Setup->default_maxrcvddays = get_word(pbuf); pbuf += 2;
233     Setup->checkname = *pbuf++;
234     Setup->maxareacachesize = *pbuf++;
235 
236     memcpy(Setup->inpkts_path, pbuf, 53); pbuf += 53;
237     memcpy(Setup->pkt_prog, pbuf, 13); pbuf += 13;
238     memcpy(Setup->pkt_switches, pbuf, 20); pbuf += 20;
239 
240     Setup->pkt_mem = get_word(pbuf); pbuf += 2;
241     Setup->maxareas = get_word(pbuf); pbuf += 2;
242     Setup->maxconnections = get_word(pbuf); pbuf += 2;
243     Setup->maxnodes = get_word(pbuf); pbuf += 2;
244     Setup->default_minmsgs = get_word(pbuf); pbuf += 2;
245 
246     Setup->bbs_type = *pbuf++;
247     Setup->decompress_ext = *pbuf++;
248     Setup->reserved3 = *pbuf++;
249     Setup->change_tearline = *pbuf++;
250     Setup->prog_notavail = get_word(pbuf); pbuf += 2;
251 
252     Setup->gscolor.bg_char = *pbuf++;
253     Setup->gscolor.headerframe = *pbuf++;
254     Setup->gscolor.headertext = *pbuf++;
255     Setup->gscolor.background = *pbuf++;
256     Setup->gscolor.bottomline = *pbuf++;
257     Setup->gscolor.bottomtext = *pbuf++;
258     Setup->gscolor.bottomkey = *pbuf++;
259     Setup->gscolor.errorframe = *pbuf++;
260     Setup->gscolor.errortext = *pbuf++;
261     Setup->gscolor.helpframe = *pbuf++;
262     Setup->gscolor.helptitle = *pbuf++;
263     Setup->gscolor.helptext = *pbuf++;
264     Setup->gscolor.helpfound = *pbuf++;
265     Setup->gscolor.winframe = *pbuf++;
266     Setup->gscolor.wintitle = *pbuf++;
267     Setup->gscolor.winline = *pbuf++;
268     Setup->gscolor.wintext = *pbuf++;
269     Setup->gscolor.winkey = *pbuf++;
270     Setup->gscolor.windata = *pbuf++;
271     Setup->gscolor.winselect = *pbuf++;
272     Setup->gscolor.inputdata = *pbuf++;
273     Setup->gscolor.exportonly = *pbuf++;
274     Setup->gscolor.importonly = *pbuf++;
275     Setup->gscolor.lockedout = *pbuf++;
276 
277     memcpy(Setup->reserved4, pbuf, 9); pbuf += 9;
278 
279     for (i = 0; i < AKAS; i++)
280     {
281         Setup->aka[i].zone  = get_word(pbuf); pbuf += 2;
282         Setup->aka[i].net   = get_word(pbuf); pbuf += 2;
283         Setup->aka[i].node  = get_word(pbuf); pbuf += 2;
284         Setup->aka[i].point = get_word(pbuf); pbuf += 2;
285     }
286     for (i = 0; i < AKAS; i++)
287     {
288         Setup->pointnet[i]  = get_word(pbuf); pbuf += 2;
289     }
290     for (i = 0; i < AKAS; i++)
291     {
292         Setup->akaarea[i]  = get_word(pbuf); pbuf += 2;
293     }
294     for (i = 0; i < USERS; i++)
295     {
296         Setup->userarea[i]  = get_word(pbuf); pbuf += 2;
297     }
298     for (i = 0; i < USERS; i++)
299     {
300         Setup->persmailarea[i]  = get_word(pbuf); pbuf += 2;
301     }
302 
303     Setup->rcvdarea = get_word(pbuf); pbuf += 2;
304     Setup->sentarea = get_word(pbuf); pbuf += 2;
305     Setup->badarea = get_word(pbuf); pbuf += 2;
306     Setup->reserved5 = get_word(pbuf); pbuf += 2;
307 
308     memcpy(Setup->jampath, pbuf, 53); pbuf += 53;
309     memcpy(Setup->userbase, pbuf, 53); pbuf += 53;
310     memcpy(Setup->dos4gw_exe, pbuf, 65); pbuf += 65;
311 
312     memcpy(Setup->public_groups, pbuf, GROUPBYTES); pbuf += GROUPBYTES;
313 
314     Setup->maxgroupconnections = get_word(pbuf); pbuf += 2;
315     Setup->maxmsgsize = get_word(pbuf); pbuf += 2;
316     Setup->diskspace_threshold = get_word(pbuf); pbuf += 2;
317     Setup->pktsort = *pbuf++;
318 
319     memcpy(Setup->wildcatpath, pbuf, 53); pbuf += 53;
320 
321     assert(pbuf - buffer == SETUP_GE_SIZE);
322 
323     xfree(buffer);
324 
325     return 0;
326 }
327 
328 /*
329  * read_areafile_hdr
330  *
331  * reads an AREAFILE_HDR structure.
332  *
333  */
334 
read_areafile_hdr(AREAFILE_HDR * AreaHdr,FILE * fp)335 int read_areafile_hdr(AREAFILE_HDR *AreaHdr, FILE *fp)
336 {
337     unsigned char buffer[AREAFILE_HDR_SIZE], *pbuf = buffer;
338 
339     if (fread(buffer, AREAFILE_HDR_SIZE, 1, fp) != 1)
340     {
341         return -1;
342     }
343 
344     AreaHdr->hdrsize        = get_word(pbuf); pbuf += 2;
345     AreaHdr->recsize        = get_word(pbuf); pbuf += 2;
346     AreaHdr->maxconnections = get_word(pbuf); pbuf += 2;
347 
348     assert(pbuf - buffer == AREAFILE_HDR_SIZE);
349 
350     return 0;
351 }
352 
353 
354 /*
355  * read_areafile_ge
356  *
357  * reads a AREAFILE_GE structure.
358  *
359  */
360 
read_areafile_ge(AREAFILE_GE * Area,FILE * fp)361 int read_areafile_ge(AREAFILE_GE *Area, FILE *fp)
362 {
363     unsigned char buffer[AREAFILE_GE_SIZE], *pbuf = buffer;
364 
365     if (fread(buffer, AREAFILE_GE_SIZE, 1, fp) != 1)
366     {
367         return -1;
368     }
369 
370     memcpy(Area->name, pbuf, 51); pbuf += 51;
371     memcpy(Area->comment, pbuf, 61); pbuf += 61;
372     memcpy(Area->path, pbuf, 51); pbuf += 51;
373     memcpy(Area->originline, pbuf, 61); pbuf += 61;
374 
375     Area->areanumber = get_word(pbuf); pbuf += 2;
376     Area->group = *pbuf++;
377     Area->options = get_word(pbuf); pbuf += 2;
378     Area->originlinenr = *pbuf++;
379     Area->pkt_origin = *pbuf++;
380     Area->seenbys = get_dword(pbuf); pbuf += 4;
381     Area->maxmsgs = get_word(pbuf); pbuf += 2;
382     Area->maxdays = get_word(pbuf); pbuf += 2;
383     Area->maxrcvddays = get_word(pbuf); pbuf += 2;
384     Area->areatype = *pbuf++;
385     Area->areaformat = *pbuf++;
386     Area->extraoptions = *pbuf++;
387 
388     assert(pbuf - buffer == AREAFILE_GE_SIZE);
389 
390     return 0;
391 }
392