1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
|
/*
* libdpkg - Debian packaging suite library routines
* fields.c - parsing of all the different fields, when reading in
*
* Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
* Copyright © 2001 Wichert Akkerman
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2,
* or (at your option) any later version.
*
* This is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with dpkg; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <dpkg.h>
#include <dpkg-db.h>
#include <dpkg-priv.h>
#include "parsedump.h"
static int
convert_string(const char *filename, int lno, const char *what, int otherwise,
const struct pkginfo *pigp,
const char *startp, const struct namevalue *ivip,
const char **endpp)
{
const char *ep;
int c, l = 0;
struct namevalue *nvip= NULL;
memcpy(&nvip,&ivip,sizeof(struct namevalue *));
ep= startp;
if (!*ep)
parse_error(filename, lno, pigp, _("%s is missing"), what);
while (nvip->name) {
if ((l= nvip->length) == 0) {
l= strlen(nvip->name);
nvip->length= (const int)l;
}
if (strncasecmp(nvip->name,startp,l) || nvip->name[l])
nvip++;
else
break;
}
if (!nvip->name) {
if (otherwise != -1) return otherwise;
parse_error(filename, lno, pigp, _("`%.*s' is not allowed for %s"),
l > 50 ? 50 : l, startp, what);
}
ep = startp + l;
c = *ep;
while (isspace(c)) c= *++ep;
if (c && !endpp)
parse_error(filename, lno, pigp, _("junk after %s"), what);
if (endpp) *endpp= ep;
return nvip->value;
}
void f_name(struct pkginfo *pigp, struct pkginfoperfile *pifp, enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
const char *e;
if ((e= illegal_packagename(value,NULL)) != NULL)
parse_error(filename, lno, pigp, _("invalid package name (%.250s)"), e);
pigp->name= findpackage(value)->name;
/* We use the new name, as findpackage() may have
done a tolower for us.
*/
}
void f_filecharf(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
struct filedetails *fdp, **fdpp;
char *cpos, *space;
int allowextend;
if (!*value)
parse_error(filename, lno, pigp, _("empty file details field `%s'"), fip->name);
if (!(flags & pdb_recordavailable))
parse_error(filename, lno, pigp,
_("file details field `%s' not allowed in status file"),
fip->name);
allowextend= !pigp->files;
fdpp= &pigp->files;
cpos= nfstrsave(value);
while (*cpos) {
space= cpos; while (*space && !isspace(*space)) space++;
if (*space) *space++= 0;
fdp= *fdpp;
if (!fdp) {
if (!allowextend)
parse_error(filename, lno, pigp,
_("too many values in file details field `%s' "
"(compared to others)"), fip->name);
fdp= nfmalloc(sizeof(struct filedetails));
fdp->next= NULL;
fdp->name= fdp->msdosname= fdp->size= fdp->md5sum= NULL;
*fdpp= fdp;
}
FILEFFIELD(fdp,fip->integer,const char*)= cpos;
fdpp= &fdp->next;
while (*space && isspace(*space)) space++;
cpos= space;
}
if (*fdpp)
parse_error(filename, lno, pigp,
_("too few values in file details field `%s' "
"(compared to others)"), fip->name);
}
void f_charfield(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
if (*value) PKGPFIELD(pifp,fip->integer,char*)= nfstrsave(value);
}
void f_boolean(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
pifp->essential = *value ?
convert_string(filename, lno, _("yes/no in boolean field"),
-1, pigp, value, booleaninfos, NULL) :
0;
}
void f_section(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
if (!*value) return;
pigp->section= nfstrsave(value);
}
void f_priority(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
if (!*value) return;
pigp->priority = convert_string(filename, lno, _("word in `priority' field"),
pri_other, pigp, value, priorityinfos, NULL);
if (pigp->priority == pri_other) pigp->otherpriority= nfstrsave(value);
}
void f_status(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
const char *ep;
if (flags & pdb_rejectstatus)
parse_error(filename, lno, pigp,
_("value for `status' field not allowed in this context"));
if (flags & pdb_recordavailable) return;
pigp->want = convert_string(filename, lno,
_("first (want) word in `status' field"), -1,
pigp, value, wantinfos, &ep);
pigp->eflag = convert_string(filename, lno,
_("second (error) word in `status' field"), -1,
pigp, ep, eflaginfos, &ep);
if (pigp->eflag & eflagf_obsoletehold) {
pigp->want= want_hold;
pigp->eflag &= ~eflagf_obsoletehold;
}
pigp->status= convert_string(filename,lno,_("third (status) word in `status' field"), -1,
pigp, ep, statusinfos, NULL);
}
void f_version(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
const char *emsg;
emsg= parseversion(&pifp->version,value);
if (emsg)
parse_error(filename, lno, pigp,
_("error in Version string `%.250s': %.250s"), value, emsg);
}
void f_revision(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
char *newversion;
parse_warn(filename, lno, warnto, warncount, pigp,
_("obsolete `Revision' or `Package-Revision' field used"));
if (!*value) return;
if (pifp->version.revision && *pifp->version.revision) {
newversion= nfmalloc(strlen(pifp->version.version)+strlen(pifp->version.revision)+2);
sprintf(newversion,"%s-%s",pifp->version.version,pifp->version.revision);
pifp->version.version= newversion;
}
pifp->version.revision= nfstrsave(value);
}
void f_configversion(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
const char *emsg;
if (flags & pdb_rejectstatus)
parse_error(filename, lno, pigp,
_("value for `config-version' field not allowed in this context"));
if (flags & pdb_recordavailable) return;
emsg= parseversion(&pigp->configversion,value);
if (emsg)
parse_error(filename, lno, pigp,
_("error in Config-Version string `%.250s': %.250s"),
value, emsg);
}
static void conffvalue_lastword(const char *value, const char *from,
const char *endent,
const char **word_start_r, int *word_len_r,
const char **new_from_r,
const char *filename, int lno,
struct pkginfo *pigp)
{
/* the code in f_conffiles ensures that value[-1]==' ', which is helpful */
const char *lastspc;
if (from <= value+1) goto malformed;
for (lastspc= from-1; *lastspc != ' '; lastspc--);
if (lastspc <= value+1 || lastspc >= endent-1) goto malformed;
*new_from_r= lastspc;
*word_start_r= lastspc + 1;
*word_len_r= (int)(from - *word_start_r);
return;
malformed:
parse_error(filename, lno, pigp,
_("value for `conffiles' has malformatted line `%.*s'"),
(int)(endent - value > 250 ? 250 : endent - value), value);
}
void f_conffiles(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
static const char obsolete_str[]= "obsolete";
struct conffile **lastp, *newlink;
const char *endent, *endfn, *hashstart;
int c, namelen, hashlen, obsolete;
char *newptr;
lastp= &pifp->conffiles;
while (*value) {
c= *value++;
if (c == '\n') continue;
if (c != ' ')
parse_error(filename, lno, pigp,
_("value for `conffiles' has line starting with non-space `%c'"),
c);
for (endent= value; (c= *endent)!=0 && c != '\n'; endent++);
conffvalue_lastword(value, endent, endent,
&hashstart, &hashlen, &endfn,
filename, lno, pigp);
obsolete= (hashlen == sizeof(obsolete_str)-1 &&
!memcmp(hashstart, obsolete_str, hashlen));
if (obsolete)
conffvalue_lastword(value, endfn, endent,
&hashstart, &hashlen, &endfn,
filename, lno, pigp);
newlink= nfmalloc(sizeof(struct conffile));
value= skip_slash_dotslash(value);
namelen= (int)(endfn-value);
if (namelen <= 0)
parse_error(filename, lno, pigp,
_("root or null directory is listed as a conffile"));
newptr = nfmalloc(namelen+2);
newptr[0]= '/';
memcpy(newptr+1,value,namelen);
newptr[namelen+1]= 0;
newlink->name= newptr;
newptr= nfmalloc(hashlen+1);
memcpy(newptr,hashstart,hashlen); newptr[hashlen]= 0;
newlink->hash= newptr;
newlink->obsolete= obsolete;
newlink->next =NULL;
*lastp= newlink;
lastp= &newlink->next;
value= endent;
}
}
void f_dependency(struct pkginfo *pigp, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip) {
char c1, c2;
const char *p, *emsg;
const char *depnamestart, *versionstart;
int depnamelength, versionlength;
static int depnameused= 0, versionused= 0;
static char *depname= NULL, *version= NULL;
struct dependency *dyp, **ldypp;
struct deppossi *dop, **ldopp;
if (!*value) return; /* empty fields are ignored */
p= value;
ldypp= &pifp->depends; while (*ldypp) ldypp= &(*ldypp)->next;
for (;;) { /* loop creating new struct dependency's */
dyp= nfmalloc(sizeof(struct dependency));
dyp->up= NULL; /* Set this to zero for now, as we don't know what our real
* struct pkginfo address (in the database) is going to be yet.
*/
dyp->next= NULL; *ldypp= dyp; ldypp= &dyp->next;
dyp->list= NULL; ldopp= &dyp->list;
dyp->type= fip->integer;
for (;;) { /* loop creating new struct deppossi's */
depnamestart= p;
/* skip over package name characters */
while (*p && !isspace(*p) && *p != '(' && *p != ',' && *p != '|') {
p++;
}
depnamelength= p - depnamestart ;
if (depnamelength >= depnameused) {
depnameused= depnamelength;
depname = m_realloc(depname, depnamelength + 1);
}
strncpy(depname, depnamestart, depnamelength);
*(depname + depnamelength)= 0;
if (!*depname)
parse_error(filename, lno, pigp,
_("`%s' field, missing package name, or garbage where "
"package name expected"), fip->name);
emsg= illegal_packagename(depname,NULL);
if (emsg)
parse_error(filename, lno, pigp,
_("`%s' field, invalid package name `%.255s': %s"),
fip->name, depname, emsg);
dop= nfmalloc(sizeof(struct deppossi));
dop->up= dyp;
dop->ed= findpackage(depname);
dop->next= NULL; *ldopp= dop; ldopp= &dop->next;
dop->nextrev= NULL; /* Don't link this (which is after all only `newpig' from */
dop->backrev= NULL; /* the main parsing loop in parsedb) into the depended on
* packages' lists yet. This will be done later when we
* install this (in parse.c). For the moment we do the
* `forward' links in deppossi (`ed') only, and the backward
* links from the depended on packages to dop are left undone.
*/
dop->cyclebreak= 0;
/* skip whitespace after packagename */
while (isspace(*p)) p++;
if (*p == '(') { /* if we have a versioned relation */
p++; while (isspace(*p)) p++;
c1= *p;
if (c1 == '<' || c1 == '>') {
c2= *++p;
dop->verrel= (c1 == '<') ? dvrf_earlier : dvrf_later;
if (c2 == '=') {
dop->verrel |= (dvrf_orequal | dvrf_builtup);
p++;
} else if (c2 == c1) {
dop->verrel |= (dvrf_strict | dvrf_builtup);
p++;
} else if (c2 == '<' || c2 == '>') {
parse_error(filename, lno, pigp,
_("`%s' field, reference to `%.255s':\n"
" bad version relationship %c%c"),
fip->name, depname, c1, c2);
dop->verrel= dvr_none;
} else {
parse_warn(filename, lno, warnto, warncount, pigp,
_("`%s' field, reference to `%.255s':\n"
" `%c' is obsolete, use `%c=' or `%c%c' instead"),
fip->name, depname, c1, c1, c1, c1);
dop->verrel |= (dvrf_orequal | dvrf_builtup);
}
} else if (c1 == '=') {
dop->verrel= dvr_exact;
p++;
} else {
parse_warn(filename, lno, warnto, warncount, pigp,
_("`%s' field, reference to `%.255s':\n"
" implicit exact match on version number, "
"suggest using `=' instead"),
fip->name, depname);
dop->verrel= dvr_exact;
}
if ((dop->verrel!=dvr_exact) && (fip->integer==dep_provides))
parse_warn(filename, lno, warnto, warncount, pigp,
_("Only exact versions may be used for Provides"));
if (!isspace(*p) && !isalnum(*p)) {
parse_warn(filename, lno, warnto, warncount, pigp,
_("`%s' field, reference to `%.255s':\n"
" version value starts with non-alphanumeric, "
"suggest adding a space"),
fip->name, depname);
}
/* skip spaces between the relation and the version */
while (isspace(*p)) p++;
versionstart= p;
while (*p && *p != ')' && *p != '(') {
if (isspace(*p)) break;
p++;
}
versionlength= p - versionstart;
while (isspace(*p)) p++;
if (*p == '(')
parse_error(filename, lno, pigp,
_("`%s' field, reference to `%.255s': "
"version contains `%c'"), fip->name,depname, ')');
else if (*p != ')')
parse_error(filename, lno, pigp,
_("`%s' field, reference to `%.255s': "
"version contains `%c'"), fip->name,depname, ' ');
else if (*p == 0)
parse_error(filename, lno, pigp,
_("`%s' field, reference to `%.255s': "
"version unterminated"), fip->name, depname);
if (versionlength >= versionused) {
versionused= versionlength;
version = m_realloc(version, versionlength + 1);
}
strncpy(version, versionstart, versionlength);
*(version + versionlength)= 0;
emsg= parseversion(&dop->version,version);
if (emsg)
parse_error(filename, lno, pigp,
_("`%s' field, reference to `%.255s': "
"error in version: %.255s"), fip->name, depname, emsg);
p++; while (isspace(*p)) p++;
} else {
dop->verrel= dvr_none;
blankversion(&dop->version);
}
if (!*p || *p == ',') break;
if (*p != '|')
parse_error(filename, lno, pigp,
_("`%s' field, syntax error after reference to package `%.255s'"),
fip->name, dop->ed->name);
if (fip->integer == dep_conflicts ||
fip->integer == dep_breaks ||
fip->integer == dep_provides ||
fip->integer == dep_replaces)
parse_error(filename, lno, pigp,
_("alternatives (`|') not allowed in %s field"), fip->name);
p++; while (isspace(*p)) p++;
}
if (!*p) break;
p++; while (isspace(*p)) p++;
}
}
static const char *
scan_word(const char **valp)
{
static char *buf;
static int avail;
int l;
const char *p, *start, *end;
p = *valp;
for (;;) {
if (!*p) {
*valp = p;
return NULL;
}
if (cisspace(*p)) {
p++;
continue;
}
start = p;
break;
}
for (;;) {
if (*p && !cisspace(*p)) {
p++;
continue;
}
end = p;
break;
}
l = end - start;
if (l >= avail) {
avail = l * 2 + 4;
buf = m_realloc(buf, avail);
}
memcpy(buf, start, l);
buf[l] = 0;
*valp = p;
return buf;
}
void
f_trigpend(struct pkginfo *pend, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip)
{
const char *word, *emsg;
if (flags & pdb_rejectstatus)
parse_error(filename, lno, pend,
_("value for `triggers-pending' field not allowed in "
"this context"));
while ((word = scan_word(&value))) {
emsg = illegal_triggername(word);
if (emsg)
parse_error(filename, lno, pend,
_("illegal pending trigger name `%.255s': %s"), word, emsg);
if (!trig_note_pend_core(pend, nfstrsave(word)))
parse_error(filename, lno, pend,
_("duplicate pending trigger `%.255s'"), word);
}
}
void
f_trigaw(struct pkginfo *aw, struct pkginfoperfile *pifp,
enum parsedbflags flags,
const char *filename, int lno, FILE *warnto, int *warncount,
const char *value, const struct fieldinfo *fip)
{
const char *word, *emsg;
struct pkginfo *pend;
if (flags & pdb_rejectstatus)
parse_error(filename, lno, aw,
_("value for `triggers-awaited' field not allowed in "
"this context"));
while ((word = scan_word(&value))) {
emsg = illegal_packagename(word, NULL);
if (emsg)
parse_error(filename, lno, aw,
_("illegal package name in awaited trigger `%.255s': %s"),
word, emsg);
pend = findpackage(word);
if (!trig_note_aw(pend, aw))
parse_error(filename, lno, aw,
_("duplicate awaited trigger package `%.255s'"), word);
}
}
|