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
|
/** \ingroup rpmbuild
* \file build/parseReqs.c
* Parse dependency tag from spec file or from auto-dependency generator.
*/
#include "system.h"
#include <ctype.h>
#include <rpm/rpmtypes.h>
#include <rpm/rpmlog.h>
#include "build/rpmbuild_internal.h"
#include "build/rpmbuild_misc.h"
#include "debug.h"
/**
*/
static struct ReqComp {
const char * token;
rpmsenseFlags sense;
} const ReqComparisons[] = {
{ "<=", RPMSENSE_LESS | RPMSENSE_EQUAL},
{ "=<", RPMSENSE_LESS | RPMSENSE_EQUAL},
{ "<", RPMSENSE_LESS},
{ "==", RPMSENSE_EQUAL},
{ "=", RPMSENSE_EQUAL},
{ ">=", RPMSENSE_GREATER | RPMSENSE_EQUAL},
{ "=>", RPMSENSE_GREATER | RPMSENSE_EQUAL},
{ ">", RPMSENSE_GREATER},
{ NULL, 0 },
};
#define SKIPWHITE(_x) {while(*(_x) && (risspace(*_x) || *(_x) == ',')) (_x)++;}
#define SKIPNONWHITE(_x){while(*(_x) &&!(risspace(*_x) || *(_x) == ',')) (_x)++;}
rpmRC parseRCPOT(rpmSpec spec, Package pkg, const char *field, rpmTagVal tagN,
int index, rpmsenseFlags tagflags)
{
const char *r, *re, *v, *ve;
const char *emsg = NULL;
char * N = NULL, * EVR = NULL;
rpmTagVal nametag = RPMTAG_NOT_FOUND;
rpmsenseFlags Flags;
Header h = pkg->header; /* everything except buildrequires go here */
rpmRC rc = RPMRC_FAIL; /* assume failure */
switch (tagN) {
default:
case RPMTAG_REQUIREFLAGS:
nametag = RPMTAG_REQUIRENAME;
tagflags |= RPMSENSE_ANY;
break;
case RPMTAG_RECOMMENDFLAGS:
nametag = RPMTAG_RECOMMENDNAME;
break;
case RPMTAG_SUGGESTFLAGS:
nametag = RPMTAG_SUGGESTNAME;
break;
case RPMTAG_SUPPLEMENTFLAGS:
nametag = RPMTAG_SUPPLEMENTNAME;
break;
case RPMTAG_ENHANCEFLAGS:
nametag = RPMTAG_ENHANCENAME;
break;
case RPMTAG_PROVIDEFLAGS:
nametag = RPMTAG_PROVIDENAME;
break;
case RPMTAG_OBSOLETEFLAGS:
nametag = RPMTAG_OBSOLETENAME;
break;
case RPMTAG_CONFLICTFLAGS:
nametag = RPMTAG_CONFLICTNAME;
break;
case RPMTAG_ORDERFLAGS:
nametag = RPMTAG_ORDERNAME;
break;
case RPMTAG_PREREQ:
/* XXX map legacy PreReq into Requires(pre,preun) */
nametag = RPMTAG_REQUIRENAME;
tagflags |= (RPMSENSE_SCRIPT_PRE|RPMSENSE_SCRIPT_PREUN);
break;
case RPMTAG_TRIGGERPREIN:
nametag = RPMTAG_TRIGGERNAME;
tagflags |= RPMSENSE_TRIGGERPREIN;
break;
case RPMTAG_TRIGGERIN:
nametag = RPMTAG_TRIGGERNAME;
tagflags |= RPMSENSE_TRIGGERIN;
break;
case RPMTAG_TRIGGERPOSTUN:
nametag = RPMTAG_TRIGGERNAME;
tagflags |= RPMSENSE_TRIGGERPOSTUN;
break;
case RPMTAG_TRIGGERUN:
nametag = RPMTAG_TRIGGERNAME;
tagflags |= RPMSENSE_TRIGGERUN;
break;
case RPMTAG_BUILDPREREQ:
case RPMTAG_BUILDREQUIRES:
nametag = RPMTAG_REQUIRENAME;
tagflags |= RPMSENSE_ANY;
h = spec->buildRestrictions;
break;
case RPMTAG_BUILDCONFLICTS:
nametag = RPMTAG_CONFLICTNAME;
h = spec->buildRestrictions;
break;
case RPMTAG_SUGGESTSFLAGS:
nametag = RPMTAG_SUGGESTSNAME;
break;
case RPMTAG_ENHANCESFLAGS:
nametag = RPMTAG_ENHANCESNAME;
break;
case RPMTAG_BUILDSUGGESTS:
nametag = RPMTAG_SUGGESTSNAME;
h = spec->buildRestrictions;
break;
case RPMTAG_BUILDENHANCES:
nametag = RPMTAG_ENHANCESNAME;
h = spec->buildRestrictions;
break;
}
for (r = field; *r != '\0'; r = re) {
SKIPWHITE(r);
if (*r == '\0')
break;
Flags = (tagflags & ~RPMSENSE_SENSEMASK);
/*
* Tokens must begin with alphanumeric, _, or /, but we don't know
* the spec's encoding so we only check what we can: plain ascii.
*/
if (isascii(r[0]) && !(risalnum(r[0]) || r[0] == '_' || r[0] == '/')) {
emsg = _("Dependency tokens must begin with alpha-numeric, '_' or '/'");
goto exit;
}
re = r;
SKIPNONWHITE(re);
N = xmalloc((re-r) + 1);
rstrlcpy(N, r, (re-r) + 1);
/* Parse EVR */
v = re;
SKIPWHITE(v);
ve = v;
SKIPNONWHITE(ve);
re = v; /* ==> next token (if no EVR found) starts here */
/* Check for possible logical operator */
if (ve > v) {
const struct ReqComp *rc;
for (rc = ReqComparisons; rc->token != NULL; rc++) {
if ((ve-v) != strlen(rc->token) || !rstreqn(v, rc->token, (ve-v)))
continue;
if (r[0] == '/') {
emsg = _("Versioned file name not permitted");
goto exit;
}
Flags |= rc->sense;
/* now parse EVR */
v = ve;
SKIPWHITE(v);
ve = v;
SKIPNONWHITE(ve);
break;
}
}
if (Flags & RPMSENSE_SENSEMASK) {
if (*v == '\0' || ve == v) {
emsg = _("Version required");
goto exit;
}
EVR = xmalloc((ve-v) + 1);
rstrlcpy(EVR, v, (ve-v) + 1);
if (rpmCharCheck(spec, EVR, ve-v, ".-_+:%{}~")) goto exit;
re = ve; /* ==> next token after EVR string starts here */
} else
EVR = NULL;
if (addReqProv(h, nametag, N, EVR, Flags, index)) {
emsg = _("invalid dependency");
goto exit;
}
N = _free(N);
EVR = _free(EVR);
}
rc = RPMRC_OK;
exit:
if (emsg) {
/* Automatic dependencies don't relate to spec lines */
if (tagflags & (RPMSENSE_FIND_REQUIRES|RPMSENSE_FIND_PROVIDES)) {
rpmlog(RPMLOG_ERR, "%s: %s\n", emsg, r);
} else {
rpmlog(RPMLOG_ERR, _("line %d: %s: %s\n"),
spec->lineNum, emsg, spec->line);
}
}
free(N);
free(EVR);
return rc;
}
|