-
Notifications
You must be signed in to change notification settings - Fork 386
/
Copy pathparsePreamble.cc
1346 lines (1215 loc) · 34 KB
/
parsePreamble.cc
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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** \ingroup rpmbuild
* \file build/parsePreamble.c
* Parse tags in global section from spec file.
*/
#include "system.h"
#include <ctype.h>
#include <errno.h>
#include <rpm/header.h>
#include <rpm/rpmlog.h>
#include <rpm/rpmurl.h>
#include <rpm/rpmfileutil.h>
#include "rpmbuild_internal.hh"
#include "rpmbuild_misc.hh"
#include "debug.h"
#define SKIPSPACE(s) { while (*(s) && risspace(*(s))) (s)++; }
#define SKIPNONSPACE(s) { while (*(s) && !risspace(*(s))) (s)++; }
#define SKIPWHITE(_x) {while (*(_x) && (risspace(*_x) || *(_x) == ',')) (_x)++;}
#define SKIPNONWHITE(_x){while (*(_x) &&!(risspace(*_x) || *(_x) == ',')) (_x)++;}
/**
*/
static const rpmTagVal copyTagsDuringParse[] = {
RPMTAG_EPOCH,
RPMTAG_VERSION,
RPMTAG_RELEASE,
RPMTAG_LICENSE,
RPMTAG_PACKAGER,
RPMTAG_DISTRIBUTION,
RPMTAG_DISTURL,
RPMTAG_VENDOR,
RPMTAG_ICON,
RPMTAG_URL,
RPMTAG_VCS,
RPMTAG_CHANGELOGTIME,
RPMTAG_CHANGELOGNAME,
RPMTAG_CHANGELOGTEXT,
RPMTAG_PREFIXES,
RPMTAG_DISTTAG,
RPMTAG_BUGURL,
RPMTAG_TRANSLATIONURL,
RPMTAG_UPSTREAMRELEASES,
RPMTAG_GROUP,
RPMTAG_MODULARITYLABEL,
0
};
/**
*/
static const rpmTagVal requiredTagsForBuild[] = {
RPMTAG_NAME,
RPMTAG_VERSION,
RPMTAG_RELEASE,
0
};
/**
*/
static const rpmTagVal requiredTags[] = {
RPMTAG_NAME,
RPMTAG_VERSION,
RPMTAG_RELEASE,
RPMTAG_SUMMARY,
RPMTAG_LICENSE,
0
};
/**
*/
static rpmRC addOrAppendListEntry(Header h, rpmTagVal tag, const char * line)
{
int xx;
int argc;
const char **argv;
if ((xx = poptParseArgvString(line, &argc, &argv))) {
rpmlog(RPMLOG_ERR, _("Error parsing tag field: %s\n"), poptStrerror(xx));
return RPMRC_FAIL;
}
if (argc)
headerPutStringArray(h, tag, argv, argc);
argv = _free(argv);
return RPMRC_OK;
}
/* Parse a simple part line that only take -n <pkg> or <pkg> */
/* <pkg> is returned in name as a pointer into a dynamic buffer */
/**
*/
static int parseSimplePart(const char *line, char **name, int *flag)
{
char *tok;
char *linebuf = xstrdup(line);
int rc;
/* Throw away the first token (the %xxxx) */
(void)strtok(linebuf, " \t\n");
*name = NULL;
if (!(tok = strtok(NULL, " \t\n"))) {
rc = 1;
goto exit;
}
if (rstreq(tok, "-n")) {
if (!(tok = strtok(NULL, " \t\n"))) {
rc = 1;
goto exit;
}
*flag = PART_NAME;
} else {
*flag = PART_SUBNAME;
}
*name = xstrdup(tok);
rc = strtok(NULL, " \t\n") ? 1 : 0;
exit:
free(linebuf);
return rc;
}
/**
*/
static inline int parseYesNo(const char * s)
{
return ((!s || (s[0] == 'n' || s[0] == 'N' || s[0] == '0') ||
!rstrcasecmp(s, "false") || !rstrcasecmp(s, "off"))
? 0 : 1);
}
static struct Source *newSource(uint32_t num, const char *path, int flags)
{
struct Source *p = new Source {};
p->num = num;
p->fullSource = xstrdup(path);
p->flags = flags;
p->source = strrchr(p->fullSource, '/');
if (p->source) {
const char *buf = strrchr(p->source,'=');
if (buf)
p->source = buf;
p->source++;
} else {
p->source = p->fullSource;
}
p->path = rpmGetPath("%{_sourcedir}/", p->source, NULL);
return p;
}
struct Source *findSource(rpmSpec spec, uint32_t num, int flag)
{
struct Source *p;
for (p = spec->sources; p != NULL; p = p->next)
if ((num == p->num) && (p->flags & flag)) return p;
return NULL;
}
static int parseNoSource(rpmSpec spec, const char * field, rpmTagVal tag)
{
const char *f, *fe;
const char *name;
int flag;
uint32_t num;
if (tag == RPMTAG_NOSOURCE) {
flag = RPMBUILD_ISSOURCE;
name = "source";
} else {
flag = RPMBUILD_ISPATCH;
name = "patch";
}
fe = field;
for (f = fe; *f != '\0'; f = fe) {
struct Source *p;
SKIPWHITE(f);
if (*f == '\0')
break;
fe = f;
SKIPNONWHITE(fe);
if (*fe != '\0') fe++;
if (parseUnsignedNum(f, &num)) {
rpmlog(RPMLOG_ERR, _("line %d: Bad number: %s\n"),
spec->lineNum, f);
return RPMRC_FAIL;
}
if (! (p = findSource(spec, num, flag))) {
rpmlog(RPMLOG_ERR, _("line %d: Bad no%s number: %u\n"),
spec->lineNum, name, num);
return RPMRC_FAIL;
}
p->flags |= RPMBUILD_ISNO;
}
return 0;
}
static int tryDownload(const struct Source *p)
{
int rc = 0;
struct stat st;
/* try to download source/patch if it's missing */
if (lstat(p->path, &st) != 0 && errno == ENOENT) {
char *url = NULL;
if (urlIsURL(p->fullSource) != URL_IS_UNKNOWN) {
url = rstrdup(p->fullSource);
} else {
url = rpmExpand("%{_default_source_url}", NULL);
rstrcat(&url, p->source);
if (*url == '%') url = _free(url);
}
if (url) {
rpmlog(RPMLOG_WARNING, _("Downloading %s to %s\n"), url, p->path);
if (urlGetFile(url, p->path) != 0) {
rpmlog(RPMLOG_ERR, _("Couldn't download %s\n"), p->fullSource);
rc = -1;
}
}
free(url);
}
return rc;
}
/*
* Parse an option number of a tag, such as in sources and patches.
* Return -1 on error, 0 if number present and 1 if no number found.
*/
static int parseTagNumber(const char *line, uint32_t *snum)
{
int rc = 0;
char *l = xstrdup(line);
char *fieldp = l;
char *nump = l;
/* We already know that a ':' exists, and that there */
/* are no spaces before it. */
/* This also now allows for spaces and tabs between */
/* the number and the ':' */
while ((*fieldp != ':') && (*fieldp != ' ') && (*fieldp != '\t')) {
fieldp++;
}
*fieldp = '\0';
SKIPSPACE(nump);
if (nump == NULL || *nump == '\0') {
rc = 1;
} else {
rc = parseUnsignedNum(l, snum);
}
free(l);
return rc;
}
int addSource(rpmSpec spec, int specline, const char *srcname, rpmTagVal tag)
{
struct Source *p;
int flag = 0;
int nonum = 1; /* assume autonumbering */
const char *name = NULL;
char *buf = NULL;
uint32_t num = 0;
int *autonum = NULL;
int nofetch = (spec->flags & RPMSPEC_FORCE) ||
rpmExpandNumeric("%{_disable_source_fetch}");
switch (tag) {
case RPMTAG_SOURCE:
flag = RPMBUILD_ISSOURCE;
name = "source";
autonum = &spec->autonum_source;
break;
case RPMTAG_PATCH:
flag = RPMBUILD_ISPATCH;
name = "patch";
autonum = &spec->autonum_patch;
break;
default:
return -1;
break;
}
if (specline) {
char * s = spec->line;
SKIPSPACE(s);
nonum = parseTagNumber(s + strlen(name), &num);
if (nonum < 0) {
rpmlog(RPMLOG_ERR, _("line %d: Bad %s number: %s\n"),
spec->lineNum, name, spec->line);
return RPMRC_FAIL;
}
}
if (nonum > 0) {
/* No number specified, use autonumbering */
(*autonum)++;
num = *autonum;
} else {
/* Autonumbering continues from last specified number */
if ((int)num > *autonum)
*autonum = num;
}
/* Check whether tags of the same number haven't already been defined */
if (findSource(spec, num, flag)) {
rpmlog(RPMLOG_ERR, _("%s %d defined multiple times\n"), name, num);
return RPMRC_FAIL;
}
/* Create the entry and link it in */
p = newSource(num, srcname, flag);
p->next = spec->sources;
spec->sources = p;
spec->numSources++;
rasprintf(&buf, "%s%d",
(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
rpmPushMacro(spec->macros, buf, NULL, p->path, RMIL_SPEC);
free(buf);
rasprintf(&buf, "%sURL%d",
(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
free(buf);
addLuaSource(p);
if (!nofetch && tryDownload(p))
return RPMRC_FAIL;
return 0;
}
typedef const struct tokenBits_s {
const char * name;
rpmsenseFlags bits;
} * tokenBits;
/**
*/
static struct tokenBits_s const installScriptBits[] = {
{ "interp", RPMSENSE_INTERP },
{ "meta", RPMSENSE_META },
{ "preun", RPMSENSE_SCRIPT_PREUN },
{ "pre", RPMSENSE_SCRIPT_PRE },
{ "postun", RPMSENSE_SCRIPT_POSTUN },
{ "post", RPMSENSE_SCRIPT_POST },
{ "rpmlib", RPMSENSE_RPMLIB },
{ "verify", RPMSENSE_SCRIPT_VERIFY },
{ "pretrans", RPMSENSE_PRETRANS },
{ "posttrans", RPMSENSE_POSTTRANS },
{ "preuntrans", RPMSENSE_PREUNTRANS },
{ "postuntrans", RPMSENSE_POSTUNTRANS },
{ NULL, 0 }
};
/**
*/
static int parseBits(const char * s, const tokenBits tokbits,
rpmsenseFlags * bp)
{
tokenBits tb = NULL;
const char * se;
rpmsenseFlags bits = RPMSENSE_ANY;
int c = 0;
int rc = RPMRC_OK;
if (s) {
for (;;) {
while ((c = *s) && risspace(c)) s++;
se = s;
while ((c = *se) && risalpha(c)) se++;
if (s == se) {
if (c || tb)
rc = RPMRC_FAIL;
break;
}
for (tb = tokbits; tb->name; tb++) {
if (tb->name != NULL &&
strlen(tb->name) == (se-s) && rstreqn(tb->name, s, (se-s)))
break;
}
if (tb->name == NULL) {
rc = RPMRC_FAIL;
break;
}
bits |= tb->bits;
while ((c = *se) && risspace(c)) se++;
if (c != ',') {
if (c)
rc = RPMRC_FAIL;
break;
}
s = ++se;
}
}
*bp |= bits;
return rc;
}
/**
*/
static inline char * findLastChar(char * s)
{
char *res = s;
while (*s != '\0') {
if (! risspace(*s))
res = s;
s++;
}
return res;
}
/**
*/
int isMemberInEntry(Header h, const char *name, rpmTagVal tag)
{
struct rpmtd_s td;
int found = 0;
const char *str;
if (!headerGet(h, tag, &td, HEADERGET_MINMEM))
return -1;
while ((str = rpmtdNextString(&td))) {
if (!rstrcasecmp(str, name)) {
found = 1;
break;
}
}
rpmtdFreeData(&td);
return found;
}
/**
*/
rpmRC checkForValidArchitectures(rpmSpec spec)
{
char *arch = rpmExpand("%{_target_cpu}", NULL);
char *os = rpmExpand("%{_target_os}", NULL);
rpmRC rc = RPMRC_FAIL; /* assume failure */
if (!strcmp(arch, "noarch")) {
free(arch);
arch = rpmExpand("%{_build_cpu}", NULL);
}
if (isMemberInEntry(spec->buildRestrictions,
arch, RPMTAG_EXCLUDEARCH) == 1) {
rpmlog(RPMLOG_ERR, _("Architecture is excluded: %s\n"), arch);
goto exit;
}
if (isMemberInEntry(spec->buildRestrictions,
arch, RPMTAG_EXCLUSIVEARCH) == 0) {
rpmlog(RPMLOG_ERR, _("Architecture is not included: %s\n"), arch);
goto exit;
}
if (isMemberInEntry(spec->buildRestrictions,
os, RPMTAG_EXCLUDEOS) == 1) {
rpmlog(RPMLOG_ERR, _("OS is excluded: %s\n"), os);
goto exit;
}
if (isMemberInEntry(spec->buildRestrictions,
os, RPMTAG_EXCLUSIVEOS) == 0) {
rpmlog(RPMLOG_ERR, _("OS is not included: %s\n"), os);
goto exit;
}
rc = RPMRC_OK;
exit:
free(arch);
free(os);
return rc;
}
/**
* Check that required tags are present in header.
* @param h header
* @param NVR package name-version-release
* @return RPMRC_OK if OK
*/
int checkForRequired(Header h)
{
int res = RPMRC_OK;
const rpmTagVal * p;
for (p = requiredTags; *p != 0; p++) {
if (!headerIsEntry(h, *p)) {
rpmlog(RPMLOG_ERR,
_("%s field must be present in package: %s\n"),
rpmTagGetName(*p), headerGetString(h, RPMTAG_NAME));
res = RPMRC_FAIL;
}
}
return res;
}
/**
* Check that required tags are present in header.
* @param h header
* @param NVR package name-version-release
* @return RPMRC_OK if OK
*/
static int checkForRequiredForBuild(Header h)
{
int res = RPMRC_OK;
const rpmTagVal * p;
for (p = requiredTagsForBuild; *p != 0; p++) {
if (!headerIsEntry(h, *p)) {
rpmlog(RPMLOG_ERR,
_("%s field must be present before build in package: %s\n"),
rpmTagGetName(*p), headerGetString(h, RPMTAG_NAME));
res = RPMRC_FAIL;
}
}
return res;
}
/**
* Check that no duplicate tags are present in header.
* @param h header
* @param NVR package name-version-release
* @return RPMRC_OK if OK
*/
int checkForDuplicates(Header h)
{
int res = RPMRC_OK;
rpmTagVal tag, lastTag = RPMTAG_NOT_FOUND;
HeaderIterator hi = headerInitIterator(h);
while ((tag = headerNextTag(hi)) != RPMTAG_NOT_FOUND) {
if (tag == lastTag) {
rpmlog(RPMLOG_ERR, _("Duplicate %s entries in package: %s\n"),
rpmTagGetName(tag), headerGetString(h, RPMTAG_NAME));
res = RPMRC_FAIL;
}
lastTag = tag;
}
headerFreeIterator(hi);
return res;
}
/**
*/
static struct optionalTag {
rpmTagVal ot_tag;
const char * ot_mac;
} const optionalTags[] = {
{ RPMTAG_VENDOR, "%{vendor}" },
{ RPMTAG_PACKAGER, "%{packager}" },
{ RPMTAG_DISTRIBUTION, "%{distribution}" },
{ RPMTAG_DISTURL, "%{disturl}" },
{ RPMTAG_DISTTAG, "%{disttag}" },
{ RPMTAG_BUGURL, "%{bugurl}" },
{ RPMTAG_TRANSLATIONURL, "%{translationurl}" },
{ RPMTAG_UPSTREAMRELEASES, "%{upstreamreleases}" },
{ RPMTAG_MODULARITYLABEL, "%{modularitylabel}"},
{ 0, NULL }
};
/**
*/
void fillOutMainPackage(Header h)
{
const struct optionalTag *ot;
for (ot = optionalTags; ot->ot_mac != NULL; ot++) {
if (!headerIsEntry(h, ot->ot_tag)) {
char *val = rpmExpand(ot->ot_mac, NULL);
if (val && *val != '%') {
headerPutString(h, ot->ot_tag, val);
}
free(val);
}
}
}
/**
*/
void copyInheritedTags(Header h, Header fromh)
{
headerCopyTags(fromh, h, (rpmTagVal *)copyTagsDuringParse);
}
/**
*/
static rpmRC addIcon(Package pkg, const char * file)
{
struct Source *p = newSource(0, file, RPMBUILD_ISICON);
char *fn = NULL;
uint8_t *icon = NULL;
FD_t fd = NULL;
rpmRC rc = RPMRC_FAIL; /* assume failure */
off_t size;
size_t nb, iconsize;
p->next = pkg->icon;
pkg->icon = p;
/* XXX use rpmGenPath(rootdir, "%{_sourcedir}/", file) for icon path. */
fn = rpmGetPath("%{_sourcedir}/", file, NULL);
fd = Fopen(fn, "r.ufdio");
if (fd == NULL) {
rpmlog(RPMLOG_ERR, _("Unable to open icon %s: %s\n"),
fn, Fstrerror(fd));
goto exit;
}
size = fdSize(fd);
iconsize = (size >= 0 ? size : (8 * BUFSIZ));
if (iconsize == 0) {
rc = RPMRC_OK; /* XXX Eh? */
goto exit;
}
icon = (uint8_t *)xmalloc(iconsize + 1);
*icon = '\0';
nb = Fread(icon, sizeof(icon[0]), iconsize, fd);
if (Ferror(fd) || (size >= 0 && nb != size)) {
rpmlog(RPMLOG_ERR, _("Unable to read icon %s: %s\n"),
fn, Fstrerror(fd));
goto exit;
}
if (rstreqn((char*)icon, "GIF", sizeof("GIF")-1)) {
headerPutBin(pkg->header, RPMTAG_GIF, icon, iconsize);
} else if (rstreqn((char*)icon, "/* XPM", sizeof("/* XPM")-1)) {
headerPutBin(pkg->header, RPMTAG_XPM, icon, iconsize);
} else {
rpmlog(RPMLOG_ERR, _("Unknown icon type: %s\n"), file);
goto exit;
}
rc = RPMRC_OK;
exit:
Fclose(fd);
free(fn);
free(icon);
return rc;
}
#define SINGLE_TOKEN_ONLY \
if (multiToken) { \
rpmlog(RPMLOG_ERR, _("line %d: Tag takes single token only: %s\n"), \
spec->lineNum, spec->line); \
return RPMRC_FAIL; \
}
static void specLog(rpmSpec spec, int lvl, const char *line, const char *msg)
{
if (spec) {
rpmlog(lvl, _("line %d: %s in: %s\n"), spec->lineNum, msg, spec->line);
} else {
rpmlog(lvl, _("%s in: %s\n"), msg, line);
}
}
/**
* Check for inappropriate characters. All alphanums are considered sane.
* @param spec spec (or NULL)
* @param field string to check
* @param allowedchars string of permitted characters
* @return RPMRC_OK if OK
*/
rpmRC rpmCharCheck(rpmSpec spec, const char *field,
const char *allowedchars,
const char *allowedfirstchars)
{
const char *ch;
char *err = NULL;
rpmRC rc = RPMRC_OK;
if (allowedfirstchars && !(risalnum(*field) ||
strchr(allowedfirstchars, *field))) {
rasprintf(&err, _("Illegal char '%c' (0x%x)"),
isprint(*field) ? *field : '?', *field);
}
for (ch=field; *ch; ch++) {
if (ch==field && allowedfirstchars) continue;
if (risalnum(*ch) || strchr(allowedchars, *ch)) continue;
rasprintf(&err, _("Illegal char '%c' (0x%x)"),
isprint(*ch) ? *ch : '?', *ch);
}
for (ch=field; *ch; ch++) {
if (strchr("%{}", *ch)) {
specLog(spec, RPMLOG_WARNING, field,
_("Possible unexpanded macro"));
break;
}
}
if (err == NULL && strstr(field, "..") != NULL) {
rasprintf(&err, _("Illegal sequence \"..\""));
}
if (err) {
specLog(spec, RPMLOG_ERR, field, err);
free(err);
rc = RPMRC_FAIL;
}
return rc;
}
static int haveLangTag(Header h, rpmTagVal tag, const char *lang)
{
int rc = 0; /* assume tag not present */
int langNum = -1;
if (lang && *lang) {
/* See if the language is in header i18n table */
struct rpmtd_s langtd;
const char *s = NULL;
headerGet(h, RPMTAG_HEADERI18NTABLE, &langtd, HEADERGET_MINMEM);
while ((s = rpmtdNextString(&langtd)) != NULL) {
if (rstreq(s, lang)) {
langNum = rpmtdGetIndex(&langtd);
break;
}
}
rpmtdFreeData(&langtd);
} else {
/* C locale */
langNum = 0;
}
/* If locale is present, check the actual tag content */
if (langNum >= 0) {
struct rpmtd_s td;
headerGet(h, tag, &td, HEADERGET_MINMEM|HEADERGET_RAW);
if (rpmtdSetIndex(&td, langNum) == langNum) {
const char *s = rpmtdGetString(&td);
/* non-empty string means a dupe */
if (s && *s)
rc = 1;
}
rpmtdFreeData(&td);
};
return rc;
}
int addLangTag(rpmSpec spec, Header h, rpmTagVal tag,
const char *field, const char *lang)
{
int skip = 0;
if (haveLangTag(h, tag, lang)) {
/* Turn this into an error eventually */
rpmlog(RPMLOG_WARNING, _("line %d: second %s\n"),
spec->lineNum, rpmTagGetName(tag));
}
if (!*lang) {
headerPutString(h, tag, field);
} else {
skip = ((spec->flags & RPMSPEC_NOLANG) &&
!rstreq(lang, RPMBUILD_DEFAULT_LANG));
if (skip)
return 0;
headerAddI18NString(h, tag, field, lang);
}
return 0;
}
static int addBuildOption(rpmSpec spec, const char *sect, const char *opt)
{
rpmRC rc = RPMRC_FAIL;
if (*sect == '\0')
sect = "conf";
const struct sectname_s *sc = getSection(sect, 0);
if (sc) {
argvAdd(&(spec->buildopts[sc->section]), opt);
rc = RPMRC_OK;
}
return rc;
}
static rpmRC handlePreambleTag(rpmSpec spec, enum parseStages stage,
Package pkg, rpmTagVal tag,
const char *macro, const char *lang)
{
char * field = spec->line;
char * end;
int multiToken = 0;
rpmsenseFlags tagflags = RPMSENSE_ANY;
rpmRC rc = RPMRC_FAIL;
if (field == NULL) /* XXX can't happen */
goto exit;
/* Find the start of the "field" and strip trailing space */
while ((*field) && (*field != ':'))
field++;
if (*field != ':') {
rpmlog(RPMLOG_ERR, _("line %d: Malformed tag: %s\n"),
spec->lineNum, spec->line);
goto exit;
}
field++;
SKIPSPACE(field);
if (!*field) {
/* Empty field */
rpmlog(RPMLOG_ERR, _("line %d: Empty tag: %s\n"),
spec->lineNum, spec->line);
goto exit;
}
end = findLastChar(field);
*(end+1) = '\0';
/* See if this is multi-token */
end = field;
SKIPNONSPACE(end);
if (*end != '\0')
multiToken = 1;
switch (tag) {
case RPMTAG_BUILDSYSTEM:
SINGLE_TOKEN_ONLY;
if (checkBuildsystem(spec, field))
goto exit;
break;
case RPMTAG_BUILDOPTION:
if (addBuildOption(spec, lang, field))
goto exit;
break;
case RPMTAG_NAME:
SINGLE_TOKEN_ONLY;
if (rpmCharCheck(spec, field,
ALLOWED_CHARS_NAME, ALLOWED_FIRSTCHARS_NAME))
goto exit;
headerPutString(pkg->header, tag, field);
/* Main pkg name is unknown at the start, populate as soon as we can */
if (pkg == spec->packages)
pkg->name = rpmstrPoolId(spec->pool, field, 1);
break;
case RPMTAG_VERSION:
case RPMTAG_RELEASE:
SINGLE_TOKEN_ONLY;
if (rpmCharCheck(spec, field, ALLOWED_CHARS_VERREL, NULL))
goto exit;
headerPutString(pkg->header, tag, field);
break;
case RPMTAG_URL:
case RPMTAG_DISTTAG:
case RPMTAG_BUGURL:
case RPMTAG_MODULARITYLABEL:
/* XXX TODO: validate format somehow */
case RPMTAG_VCS:
SINGLE_TOKEN_ONLY;
/* fallthrough */
case RPMTAG_TRANSLATIONURL:
case RPMTAG_UPSTREAMRELEASES:
headerPutString(pkg->header, tag, field);
break;
case RPMTAG_GROUP:
case RPMTAG_SUMMARY:
case RPMTAG_DISTRIBUTION:
case RPMTAG_VENDOR:
case RPMTAG_LICENSE:
case RPMTAG_PACKAGER:
if (addLangTag(spec, pkg->header, tag, field, lang))
goto exit;
break;
case RPMTAG_SOURCELICENSE:
if (addLangTag(spec, spec->sourcePackage->header,
RPMTAG_LICENSE, field, lang))
goto exit;
break;
case RPMTAG_BUILDROOT:
/* just silently ignore BuildRoot */
break;
case RPMTAG_PREFIXES: {
struct rpmtd_s td;
const char *str;
if (addOrAppendListEntry(pkg->header, tag, field))
goto exit;
headerGet(pkg->header, tag, &td, HEADERGET_MINMEM);
while ((str = rpmtdNextString(&td))) {
size_t len = strlen(str);
if (len > 1 && str[len-1] == '/') {
rpmlog(RPMLOG_ERR,
_("line %d: Prefixes must not end with \"/\": %s\n"),
spec->lineNum, spec->line);
rpmtdFreeData(&td);
goto exit;
}
}
rpmtdFreeData(&td);
break;
}
case RPMTAG_DOCDIR:
SINGLE_TOKEN_ONLY;
if (field[0] != '/') {
rpmlog(RPMLOG_ERR, _("line %d: Docdir must begin with '/': %s\n"),
spec->lineNum, spec->line);
goto exit;
}
rpmPopMacro(NULL, "_docdir");
rpmPushMacro(NULL, "_docdir", NULL, field, RMIL_SPEC);
break;
case RPMTAG_EPOCH: {
SINGLE_TOKEN_ONLY;
uint32_t epoch;
if (parseUnsignedNum(field, &epoch)) {
rpmlog(RPMLOG_ERR,
_("line %d: Epoch field must be an unsigned number: %s\n"),
spec->lineNum, spec->line);
goto exit;
}
headerPutUint32(pkg->header, tag, &epoch, 1);
break;
}
case RPMTAG_AUTOREQPROV:
pkg->autoReq = parseYesNo(field);
pkg->autoProv = pkg->autoReq;
break;
case RPMTAG_AUTOREQ:
pkg->autoReq = parseYesNo(field);
break;
case RPMTAG_AUTOPROV:
pkg->autoProv = parseYesNo(field);
break;
case RPMTAG_SOURCE:
case RPMTAG_PATCH:
if (addSource(spec, 1, field, tag))
goto exit;
break;
case RPMTAG_ICON:
SINGLE_TOKEN_ONLY;
if (addIcon(pkg, field))
goto exit;
spec->numSources++;
break;
case RPMTAG_NOSOURCE:
case RPMTAG_NOPATCH:
spec->noSource = 1;
if (parseNoSource(spec, field, tag))
goto exit;
break;
case RPMTAG_ORDERNAME:
case RPMTAG_REQUIRENAME:
case RPMTAG_RECOMMENDNAME:
case RPMTAG_SUGGESTNAME:
case RPMTAG_SUPPLEMENTNAME:
case RPMTAG_ENHANCENAME:
if (parseBits(lang, installScriptBits, &tagflags)) {
rpmlog(RPMLOG_ERR, _("line %d: Bad %s: qualifiers: %s\n"),
spec->lineNum, rpmTagGetName(tag), spec->line);
goto exit;
}
/* fallthrough */
case RPMTAG_PREREQ:
case RPMTAG_CONFLICTNAME:
case RPMTAG_OBSOLETENAME:
case RPMTAG_PROVIDENAME:
if (parseRCPOT(spec, pkg, field, tag, 0, tagflags, addReqProvPkg, NULL))
goto exit;
break;
case RPMTAG_BUILDPREREQ:
case RPMTAG_BUILDREQUIRES:
case RPMTAG_BUILDCONFLICTS:
if (parseRCPOT(spec, spec->sourcePackage, field, tag, 0, tagflags, addReqProvPkg, NULL))
goto exit;
break;
case RPMTAG_EXCLUDEARCH:
case RPMTAG_EXCLUSIVEARCH:
case RPMTAG_EXCLUDEOS:
case RPMTAG_EXCLUSIVEOS:
if (addOrAppendListEntry(spec->buildRestrictions, tag, field))
goto exit;
break;
case RPMTAG_BUILDARCHS: {
int BACount;
const char **BANames = NULL;
if (poptParseArgvString(field, &BACount, &BANames)) {
rpmlog(RPMLOG_ERR,
_("line %d: Bad BuildArchitecture format: %s\n"),