12 #define _RPMEVR_INTERNAL
31 char *perms =
xstrdup(
"----------");
35 else if (S_ISDIR(mode))
39 else if (S_ISFIFO(mode))
45 else if (S_ISCHR(mode))
47 else if (S_ISBLK(mode))
52 if (mode & S_IRUSR) perms[1] =
'r';
53 if (mode & S_IWUSR) perms[2] =
'w';
54 if (mode & S_IXUSR) perms[3] =
'x';
56 if (mode & S_IRGRP) perms[4] =
'r';
57 if (mode & S_IWGRP) perms[5] =
'w';
58 if (mode & S_IXGRP) perms[6] =
'x';
60 if (mode & S_IROTH) perms[7] =
'r';
61 if (mode & S_IWOTH) perms[8] =
'w';
62 if (mode & S_IXOTH) perms[9] =
'x';
65 perms[3] = ((mode & S_IXUSR) ?
's' :
'S');
68 perms[6] = ((mode & S_IXGRP) ?
's' :
'S');
71 perms[9] = ((mode & S_IXOTH) ?
't' :
'T');
85 int ix = (he->
ix > 0 ? he->
ix : 0);
92 int anint = data.
i64p[ix];
93 if (anint & RPMSENSE_TRIGGERPREIN)
95 else if (anint & RPMSENSE_TRIGGERIN)
97 else if (anint & RPMSENSE_TRIGGERUN)
99 else if (anint & RPMSENSE_TRIGGERPOSTUN)
115 int ix = (he->
ix > 0 ? he->
ix : 0);
138 int ix = (he->
ix >= 0 ? he->
ix : 0);
146 unsigned anint = data.
i64p[ix];
181 int ix = (he->
ix > 0 ? he->
ix : 0);
183 const unsigned char * s;
203 if (b64decode(enc, (
void **)&s, &ns))
216 return xstrdup(
_(
"(invalid type)"));
237 int ix = (he->
ix > 0 ? he->
ix : 0);
248 size_t nt = ((ns + 2) / 3) * 4;
252 if (b64encode_chars_per_line > 0 && b64encode_eolstr != NULL) {
253 lc = (nt + b64encode_chars_per_line - 1) / b64encode_chars_per_line;
254 if (((nt + b64encode_chars_per_line - 1) % b64encode_chars_per_line) != 0)
256 nt += lc * strlen(b64encode_eolstr);
264 {
unsigned char * _data =
xcalloc(1, ns+1);
265 memcpy(_data, data.
ptr, ns);
267 if ((enc = b64encode(_data, ns)) != NULL) {
272 _data =
_free(_data);
292 while ((c = *s++) !=
'\0')
296 case '>': len +=
sizeof(
"<") - 1;
break;
297 case '&': len +=
sizeof(
"&") - 1;
break;
298 default: len += 1;
break;
316 while ((c = *s++) !=
'\0') {
318 case '<': te =
stpcpy(te,
"<");
break;
319 case '>': te =
stpcpy(te,
">");
break;
320 case '&': te =
stpcpy(te,
"&");
break;
321 default: *te++ = c;
break;
334 #if defined(HAVE_ICONV)
335 char *fromcode = NULL;
344 #ifdef HAVE_LANGINFO_H
346 fromcode = nl_langinfo (CODESET);
350 if (fromcode != NULL && strcmp(tocode, fromcode) != 0
351 && (fd = iconv_open(tocode, fromcode)) != (iconv_t)-1)
353 const char *pin = buffer;
355 size_t ib, ob, dest_size;
359 const char *shift_pin = NULL;
362 err = iconv(fd, NULL, &ib, &pout, &ob);
363 dest_size = ob = ib = strlen(buffer);
364 dest_str = pout = malloc((dest_size + 1) *
sizeof(*dest_str));
369 while (done == 0 && is_error == 0) {
370 err = iconv(fd, (
char **)&pin, &ib, &pout, &ob);
372 if (err == (
size_t)-1) {
378 {
size_t used = (size_t)(pout - dest_str);
380 dest_str = realloc(dest_str, (dest_size + 1) *
sizeof(*dest_str));
381 if (dest_str == NULL) {
385 pout = dest_str + used;
386 ob = dest_size - used;
396 if (shift_pin == NULL) {
405 xx = iconv_close(fd);
408 if (dest_str != NULL)
413 dest_str =
xstrdup((buffer ? buffer :
""));
428 int ix = (he->
ix > 0 ? he->
ix : 0);
459 int ix = (he->
ix > 0 ? he->
ix : 0);
484 int ix = (he->
ix > 0 ? he->
ix : 0);
485 const char * xtag = NULL;
488 const char * s = NULL;
490 unsigned long long anint = 0;
518 {
int cpl = b64encode_chars_per_line;
519 b64encode_chars_per_line = 0;
523 b64encode_chars_per_line = cpl;
530 anint = data.
i8p[ix];
533 anint = data.
ui16p[ix];
536 anint = data.
i32p[ix];
539 anint = data.
i64p[ix];
543 return xstrdup(
_(
"(invalid xml type)"));
549 t = memset(
alloca(tlen+1), 0, tlen+1);
552 xx =
snprintf(t, tlen,
"%llu", anint);
560 nb += strlen(xtag) +
sizeof(
"\t</>");
564 nb += 2 * strlen(xtag) +
sizeof(
"\t<></>");
593 while ((c = (
int) *s++) != (int)
'\0')
620 while ((c = (
int) *s++) != (int)
'\0') {
623 for (i = 0; i < lvl; i++) {
646 int element = he->
ix;
647 int ix = (he->
ix > 0 ? he->
ix : 0);
648 const char * xtag = NULL;
651 const char * s = NULL;
653 unsigned long long anint = 0;
667 if (strchr(
"[", s[0]))
670 while ((c = (
int) *s++) != (int)
'\0') {
679 if (s[0] !=
' ' && s[0] !=
'\0' && s[1] !=
'"')
693 if (he->
ix < 0) lvl++;
696 xtag = (element >= 0 ?
"- " : NULL);
708 {
int cpl = b64encode_chars_per_line;
709 b64encode_chars_per_line = 0;
714 b64encode_chars_per_line = cpl;
721 anint = he->
p.
ui8p[ix];
734 return xstrdup(
_(
"(invalid yaml type)"));
740 t = memset(
alloca(tlen+1), 0, tlen+1);
742 xx =
snprintf(t, tlen,
"%llu", (
unsigned long long)anint);
745 xtag = (element >= 0 ?
"- " : NULL);
751 nb +=
sizeof(
" ") - 1;
752 nb +=
sizeof(
"- ~") - 1;
760 nb +=
sizeof(
" ") - 1;
793 int ix = (he->
ix > 0 ? he->
ix : 0);
800 unsigned char * pkt = (
byte *) data.
ptr;
801 unsigned int pktlen = 0;
802 unsigned int v = *pkt;
805 unsigned int hlen = 0;
810 plen =
pgpLen(pkt+1, &hlen);
812 tag = (v >> 2) & 0xf;
813 plen = (1 << (v & 0x3));
817 pktlen = 1 + plen + hlen;
821 val =
xstrdup(
_(
"(not an OpenPGP signature)"));
847 if (t + 5 >= val + nb)
862 if (t + strlen (
", ") + 1 >= val + nb)
869 struct tm * tstruct = localtime(&dateint);
871 (void) strftime(t, (nb - (t - val)),
"%c", tstruct);
874 if (t + strlen (
", Key ID ") + 1 >= val + nb)
876 t =
stpcpy(t,
", Key ID ");
878 if (t + strlen (tempstr) > val + nb)
899 int ix = (he->
ix > 0 ? he->
ix : 0);;
906 int anint = data.
i64p[ix];
913 if (anint & RPMSENSE_SCRIPT_PRE)
915 else if (anint & RPMSENSE_SCRIPT_POST)
917 else if (anint & RPMSENSE_SCRIPT_PREUN)
919 else if (anint & RPMSENSE_SCRIPT_POSTUN)
920 t =
stpcpy(t,
"(postun)");
930 if (anint & RPMSENSE_SENSEMASK)
979 uint64_t uuid_time = ((uint64_t)tv->tv_sec * 10000000) +
980 (tv->tv_usec * 10) + 0x01B21DD213814000ULL;
986 if (rpmuuidMake(1, NULL, NULL, NULL, (
unsigned char *)he->
p.
ui8p)) {
992 he->
p.
ui8p[6] &= 0xf0;
993 he->
p.
ui8p[8] &= 0x3f;
994 he->
p.
ui8p[9] &= 0x00;
996 he->
p.
ui8p[3] = (uuid_time >> 0);
997 he->
p.
ui8p[2] = (uuid_time >> 8);
998 he->
p.
ui8p[1] = (uuid_time >> 16);
999 he->
p.
ui8p[0] = (uuid_time >> 24);
1000 he->
p.
ui8p[5] = (uuid_time >> 32);
1001 he->
p.
ui8p[4] = (uuid_time >> 40);
1002 he->
p.
ui8p[6] |= (uuid_time >> 56) & 0x0f;
1026 tv.tv_sec = he->
p.
ui32p[0];
1027 tv.tv_usec = (he->
c > 1 ? he->
p.
ui32p[1] : 0);
1113 static const char uuid_auth[] =
"%{?_uuid_auth}%{!?_uuid_auth:http://rpm5.org}";
1115 static const char uuid_path[] =
"%{?_uuid_path}%{!?_uuid_path:/package}";
1128 int version,
char * val)
1131 const char * ns = NULL;
1133 const char * s = NULL;
1137 if (!strcmp(
"Sigmd5", tagn))
1139 else if (!strcmp(
"Sha1header", tagn))
1161 rc = rpmuuidMake(version, ns, s, val, (
unsigned char *)he->
p.
ui8p);
1186 static const char hex[] =
"0123456789abcdef";
1192 for (i = 0; i < he->
c; i++) {
1193 *te++ = hex[ ((he->
p.
ui8p[i] >> 4) & 0x0f) ];
1194 *te++ = hex[ ((he->
p.
ui8p[i] ) & 0x0f) ];
1206 return str2uuid(he, NULL, 0, NULL);
1257 HE_t _he = memset(
alloca(
sizeof(*_he)), 0,
sizeof(*_he));
1262 int numNames, numScripts;
1263 const char ** conds;
1265 char * item, * flagsStr;
1289 he->
p.
argv = conds =
xmalloc(
sizeof(*conds) * numScripts);
1290 for (i = 0; i < numScripts; i++) {
1293 for (j = 0; j < numNames; j++) {
1294 if (indices.
i32p[j] != i)
1297 item =
xmalloc(strlen(names.
argv[j]) + strlen(versions.
argv[j]) + 20);
1301 sprintf(item,
"%s %s %s", names.
argv[j], flagsStr, versions.
argv[j]);
1302 flagsStr =
_free(flagsStr);
1304 strcpy(item, names.
argv[j]);
1306 chptr =
xrealloc(chptr, strlen(chptr) + strlen(item) + 5);
1307 if (*chptr !=
'\0') strcat(chptr,
", ");
1308 strcat(chptr, item);
1333 const char ** conds;
1336 int numScripts, numNames;
1349 he->
p.
argv = conds =
xmalloc(
sizeof(*conds) * numScripts);
1350 for (i = 0; i < numScripts; i++) {
1351 for (j = 0; j < numNames; j++) {
1352 if (indices.
i32p[j] != i)
1355 if (flags.
i32p[j] & RPMSENSE_TRIGGERPREIN)
1357 else if (flags.
i32p[j] & RPMSENSE_TRIGGERIN)
1359 else if (flags.
i32p[j] & RPMSENSE_TRIGGERUN)
1361 else if (flags.
i32p[j] & RPMSENSE_TRIGGERPOSTUN)
1375 #if defined(ENABLE_NLS)
1378 extern int _nl_msg_cat_cntr;
1405 if (dstring && *dstring) {
1407 const char * langval;
1408 const char * msgkey;
1414 size_t nb =
sizeof(
"()");
1417 if (tn) nb += strlen(tn);
1418 if (n.
str) nb += strlen(n.
str);
1420 sprintf(mk,
"%s(%s)", (n.
str ? n.
str :
""), (tn ? tn :
""));
1427 #if defined(ENABLE_NLS)
1432 for (domain = dstring; domain != NULL; domain = de) {
1433 de = strchr(domain,
':');
1434 if (de) *de++ =
'\0';
1436 if (msgid != msgkey)
break;
1444 #if defined(ENABLE_NLS)
1448 if (domain && msgid) {
1449 const char * s =
dgettext(domain, msgid) ;
1460 dstring =
_free(dstring);
1498 if (!rc || p.
ptr == NULL || c == 0) {
1513 for (i = 0; i < c; i++) {
1516 assert(p.
argv[i] != NULL);
1517 l += strlen(p.
argv[i]) + 1;
1519 argv =
xmalloc(c *
sizeof(*argv) + l);
1520 te = (
char *)&argv[c];
1521 for (i = 0; i < c; i++) {
1677 const char * origin;
1705 const char * baseurl;
1735 const char * digest;
1768 he->
p.
ui64p[0] = st->st_mtime;
1792 he->
p.
ui64p[0] = st->st_size;
1808 const char * N = NULL;
1809 const char *
V = NULL;
1810 const char * R = NULL;
1811 const char * A = NULL;
1816 if (N) nb += strlen(N);
1817 if (V) nb += strlen(V) + 1;
1818 if (R) nb += strlen(R) + 1;
1819 if (A) nb += strlen(A) + 1;
1914 HE_t vhe = memset(
alloca(
sizeof(*vhe)), 0,
sizeof(*vhe));
1915 const char ** fnames;
1944 fnames =
_free(fnames);
2077 if (!(Flags & RPMSENSE_MISSINGOK))
2082 nb +=
sizeof(*argv) + strlen(DNEVR+2) + 1;
2086 nb +=
sizeof(*argv);
2090 t = (
char *)(argv + argc);
2091 for (i = 0; i < argc; i++) {
2114 if (N.
argv[i] == NULL || *N.
argv[i] ==
'\0')
2117 && !(a=strcmp(N.
argv[i], N.
argv[i-1]))
2118 && !(b=strcmp(EVR.
argv[i], EVR.
argv[i-1]))
2119 && (F.
ui32p[i] & 0x4e) == ((F.
ui32p[i-1] & 0x4e)))
2140 if (xx == 0)
goto exit;
2146 if (xx == 0)
goto exit;
2151 if (xx == 0)
goto exit;
2154 nb =
sizeof(*he->
p.
argv);
2156 for (i = 0; i < c; i++) {
2160 nb +=
sizeof(*he->
p.
argv);
2161 nb +=
sizeof(
"<rpm:entry name=\"\"/>");
2162 if (*N.
argv[i] ==
'/')
2165 nb += strlen(N.
argv[i]);
2166 if (EVR.
argv != NULL && EVR.
argv[i] != NULL && *EVR.
argv[i] !=
'\0') {
2167 nb +=
sizeof(
" flags=\"EQ\" epoch=\"0\" ver=\"\"") - 1;
2168 nb += strlen(EVR.
argv[i]);
2169 if (strchr(EVR.
argv[i],
':') != NULL)
2171 if (strchr(EVR.
argv[i],
'-') != NULL)
2172 nb +=
sizeof(
" rel=\"\"") - 2;
2176 nb +=
sizeof(
" pre=\"1\"") - 1;
2184 t = (
char *) &he->
p.
argv[he->
c + 1];
2186 for (i = 0; i < c; i++) {
2189 he->
p.
argv[ac++] = t;
2190 t =
stpcpy(t,
"<rpm:entry");
2191 t =
stpcpy(t,
" name=\"");
2192 if (*N.
argv[i] ==
'/') {
2197 if (EVR.
argv != NULL && EVR.
argv[i] != NULL && *EVR.
argv[i] !=
'\0') {
2198 static char *Fstr[] = {
"?0",
"LT",
"GT",
"?3",
"EQ",
"LE",
"GE",
"?7" };
2199 int Fx = ((F.
ui32p[i] >> 1) & 0x7);
2200 const char *E, *
V, *R;
2203 f = (
char *) EVR.
argv[i];
2204 for (fe = f; *fe !=
'\0' && *fe >=
'0' && *fe <=
'9'; fe++);
2205 if (*fe ==
':') { *fe++ =
'\0'; E = f; f = fe; }
else E = NULL;
2207 for (fe = f; *fe !=
'\0' && *fe !=
'-'; fe++);
2208 if (*fe ==
'-') { *fe++ =
'\0'; R = fe; }
else R = NULL;
2216 t =
stpcpy(t,
" pre=\"1\"");
2221 he->
p.
argv[he->
c] = NULL;
2269 while ((c = (
int) *s++) != (
int)
'\0')
2272 case '\'': len += 1;
2273 default: len += 1;
break;
2291 while ((c = (
int) *s++) != (
int)
'\0') {
2293 case '\'': *te++ = (char) c;
2294 default: *te++ = (char) c;
break;
2310 int ix = (he->
ix > 0 ? he->
ix : 0);
2315 val =
xstrdup(
_(
"(not a string)"));
2349 if (xx == 0)
goto exit;
2355 if (xx == 0)
goto exit;
2360 if (xx == 0)
goto exit;
2364 nb =
sizeof(*he->
p.
argv);
2366 for (i = 0; i < c; i++) {
2370 nb +=
sizeof(*he->
p.
argv);
2371 nb += strlen(instance) +
sizeof(
", '', '', '', '', ''");
2373 nb +=
sizeof(
", ''") - 1;
2374 nb += strlen(N.
argv[i]);
2375 if (EVR.
argv != NULL && EVR.
argv[i] != NULL && *EVR.
argv[i] !=
'\0') {
2376 nb += strlen(EVR.
argv[i]);
2377 nb +=
sizeof(
"EQ0") - 1;
2381 nb +=
sizeof(
"1") - 1;
2389 t = (
char *) &he->
p.
argv[he->
c + 1];
2391 for (i = 0; i < c; i++) {
2394 he->
p.
argv[ac++] = t;
2397 if (EVR.
argv != NULL && EVR.
argv[i] != NULL && *EVR.
argv[i] !=
'\0') {
2398 static char *Fstr[] = {
"?0",
"LT",
"GT",
"?3",
"EQ",
"LE",
"GE",
"?7" };
2399 int Fx = ((F.
ui32p[i] >> 1) & 0x7);
2400 const char *E, *
V, *R;
2403 f = (
char *) EVR.
argv[i];
2404 for (fe = f; *fe !=
'\0' && *fe >=
'0' && *fe <=
'9'; fe++);
2405 if (*fe ==
':') { *fe++ =
'\0'; E = f; f = fe; }
else E = NULL;
2407 for (fe = f; *fe !=
'\0' && *fe !=
'-'; fe++);
2408 if (*fe ==
'-') { *fe++ =
'\0'; R = fe; }
else R = NULL;
2413 t =
stpcpy(t,
", '', '', '', ''");
2420 he->
p.
argv[he->
c] = NULL;
2461 size_t dnlen = strlen(dn);
2463 if (strstr(dn,
"bin/") != NULL)
2465 if (dnlen >=
sizeof(
"/etc/")-1 && !strncmp(dn,
"/etc/", dnlen))
2467 if (!strcmp(dn,
"/usr/lib/") && !strcmp(BN.
argv[i],
"sendmail"))
2490 if (xx == 0)
goto exit;
2496 if (xx == 0)
goto exit;
2501 if (xx == 0)
goto exit;
2506 if (xx == 0)
goto exit;
2511 if (xx == 0)
goto exit;
2514 nb =
sizeof(*he->
p.
argv);
2516 for (i = 0; i < c; i++) {
2517 if (lvl > 0 &&
FDGSkip(DN, BN, DI, i) != lvl)
2520 nb +=
sizeof(*he->
p.
argv);
2521 nb +=
sizeof(
"<file></file>");
2524 if (FFLAGS.
ui32p[i] & 0x40)
2525 nb +=
sizeof(
" type=\"ghost\"") - 1;
2526 else if (S_ISDIR(FMODES.
ui16p[i]))
2527 nb +=
sizeof(
" type=\"dir\"") - 1;
2534 t = (
char *) &he->
p.
argv[he->
c + 1];
2537 for (i = 0; i < c; i++) {
2538 if (lvl > 0 &&
FDGSkip(DN, BN, DI, i) != lvl)
2540 if (FFLAGS.
ui32p[i] & 0x40)
2542 if (S_ISDIR(FMODES.
ui16p[i]))
2544 he->
p.
argv[ac++] = t;
2548 t =
stpcpy(t,
"</file>");
2551 for (i = 0; i < c; i++) {
2552 if (lvl > 0 &&
FDGSkip(DN, BN, DI, i) != lvl)
2554 if (FFLAGS.
ui32p[i] & 0x40)
2556 if (!S_ISDIR(FMODES.
ui16p[i]))
2558 he->
p.
argv[ac++] = t;
2559 t =
stpcpy(t,
"<file type=\"dir\">");
2562 t =
stpcpy(t,
"</file>");
2565 for (i = 0; i < c; i++) {
2566 if (lvl > 0 &&
FDGSkip(DN, BN, DI, i) != lvl)
2568 if (!(FFLAGS.
ui32p[i] & 0x40))
2570 he->
p.
argv[ac++] = t;
2571 t =
stpcpy(t,
"<file type=\"ghost\">");
2574 t =
stpcpy(t,
"</file>");
2578 he->
p.
argv[he->
c] = NULL;
2620 if (xx == 0)
goto exit;
2626 if (xx == 0)
goto exit;
2631 if (xx == 0)
goto exit;
2636 if (xx == 0)
goto exit;
2641 if (xx == 0)
goto exit;
2645 nb =
sizeof(*he->
p.
argv);
2647 for (i = 0; i < c; i++) {
2648 if (lvl > 0 &&
FDGSkip(DN, BN, DI, i) != lvl)
2651 nb +=
sizeof(*he->
p.
argv);
2652 nb += strlen(instance) +
sizeof(
", '', ''");
2654 nb += strlen(BN.
argv[i]);
2655 if (FFLAGS.
ui32p[i] & 0x40)
2656 nb +=
sizeof(
"ghost") - 1;
2657 else if (S_ISDIR(FMODES.
ui16p[i]))
2658 nb +=
sizeof(
"dir") - 1;
2660 nb +=
sizeof(
"file") - 1;
2667 t = (
char *) &he->
p.
argv[he->
c + 1];
2670 for (i = 0; i < c; i++) {
2671 if (lvl > 0 &&
FDGSkip(DN, BN, DI, i) != lvl)
2673 if (FFLAGS.
ui32p[i] & 0x40)
2675 if (S_ISDIR(FMODES.
ui16p[i]))
2677 he->
p.
argv[ac++] = t;
2679 t = strcpy(t, DN.
argv[DI.
ui32p[i]]); t += strlen(t);
2680 t = strcpy(t, BN.
argv[i]); t += strlen(t);
2681 t =
stpcpy(t,
"', 'file'");
2684 for (i = 0; i < c; i++) {
2685 if (lvl > 0 &&
FDGSkip(DN, BN, DI, i) != lvl)
2687 if (FFLAGS.
ui32p[i] & 0x40)
2689 if (!S_ISDIR(FMODES.
ui16p[i]))
2691 he->
p.
argv[ac++] = t;
2693 t = strcpy(t, DN.
argv[DI.
ui32p[i]]); t += strlen(t);
2694 t = strcpy(t, BN.
argv[i]); t += strlen(t);
2695 t =
stpcpy(t,
"', 'dir'");
2698 for (i = 0; i < c; i++) {
2699 if (lvl > 0 &&
FDGSkip(DN, BN, DI, i) != lvl)
2701 if (!(FFLAGS.
ui32p[i] & 0x40))
2703 he->
p.
argv[ac++] = t;
2705 t = strcpy(t, DN.
argv[DI.
ui32p[i]]); t += strlen(t);
2706 t = strcpy(t, BN.
argv[i]); t += strlen(t);
2707 t =
stpcpy(t,
"', 'ghost'");
2711 he->
p.
argv[he->
c] = NULL;
2746 val =
xstrdup(
_(
"(not a string)"));
2754 if ((bn = strrchr(he->
p.
str,
'/')) != NULL)
2824 STAT_KEYS_FLAGS = (1U << 13),
2829 STAT_KEYS_FCONTEXT = (1U << 16),
2847 {
"fcontext", STAT_KEYS_FCONTEXT },
2848 {
"flags", STAT_KEYS_FLAGS },
2892 UUID_KEYS_STRING = (0U << 4),
2893 UUID_KEYS_SIV = (1U << 4),
2894 UUID_KEYS_BINARY = (2U << 4),
2895 UUID_KEYS_TEXT = (3U << 4),
2902 {
"binary", UUID_KEYS_BINARY },
2903 {
"siv", UUID_KEYS_SIV },
2904 {
"string", UUID_KEYS_STRING },
2905 {
"text", UUID_KEYS_TEXT },
2930 uint32_t keyval = 0;
2932 if (name && * name) {
2933 KEY needle = { .
name = name };
2934 KEY *k = (
KEY *)bsearch(&needle, keys, nkeys,
sizeof(*keys),
keyCmp);
2950 int ix = (he->
ix > 0 ? he->
ix : 0);
2957 val =
xstrdup(
_(
"(invalid type :digest)"));
2961 ns =
sizeof(he->
p.
ui64p[0]);
2964 ns = strlen(he->
p.
str);
2994 static const char *avdefault[] = {
"mode", NULL };
2995 const char * fn = NULL;
2996 struct stat sb, *st = &sb;
2997 int ix = (he->
ix > 0 ? he->
ix : 0);
3007 if (he->
c ==
sizeof(*st)) {
3008 st = (
struct stat *)he->
p.
ptr;
3013 val =
xstrdup(
_(
"(invalid type :stat)"));
3018 if (
Lstat(fn, st) == 0)
3025 if (!(av && av[0] && *av[0]))
3027 for (i = 0; av[i] != NULL; i++) {
3029 size_t nb =
sizeof(b);
3031 uint32_t keyval =
keyValue(keyStat, nkeyStat, av[i]);
3041 xx =
snprintf(b, nb,
"0x%lx", (
unsigned long)st->st_dev);
3044 xx =
snprintf(b, nb,
"0x%lx", (
unsigned long)st->st_ino);
3047 xx =
snprintf(b, nb,
"%06o", (
unsigned)st->st_mode);
3050 xx =
snprintf(b, nb,
"0x%ld", (
unsigned long)st->st_nlink);
3053 xx =
snprintf(b, nb,
"%ld", (
unsigned long)st->st_uid);
3056 xx =
snprintf(b, nb,
"%ld", (
unsigned long)st->st_gid);
3059 xx =
snprintf(b, nb,
"0x%lx", (
unsigned long)st->st_rdev);
3062 xx =
snprintf(b, nb,
"%ld", (
unsigned long)st->st_size);
3065 xx =
snprintf(b, nb,
"%ld", (
unsigned long)st->st_blksize);
3068 xx =
snprintf(b, nb,
"%ld", (
unsigned long)st->st_blocks);
3071 (void)
stpcpy(b, ctime(&st->st_atime));
3074 (void)
stpcpy(b, ctime(&st->st_ctime));
3077 (void)
stpcpy(b, ctime(&st->st_mtime));
3080 case STAT_KEYS_FLAGS:
3084 if (fn != NULL &&
S_ISLNK(st->st_mode)) {
3085 ssize_t size =
Readlink(fn, b, nb);
3087 nval =
rpmExpand(
"(Readlink:", fn,
":", strerror(
errno),
")", NULL);
3095 if (fn != NULL && S_ISREG(st->st_mode)) {
3099 if (fd == NULL ||
Ferror(fd)) {
3102 static int asAscii = 1;
3103 char buffer[16 * 1024];
3105 while (
Fread(buffer,
sizeof(buffer[0]),
sizeof(buffer), fd) > 0)
3156 static const char *avdefault[] = {
"v5", NULL };
3158 int ix = (he->
ix > 0 ? he->
ix : 0);
3165 val =
xstrdup(
_(
"(invalid type :uuid)"));
3172 if (!(av && av[0] && *av[0]))
3175 for (i = 0; av[i] != NULL; i++) {
3176 uint32_t keyval =
keyValue(keyUuids, nkeyUuids, av[i]);
3191 {
HE_t nhe = memset(
alloca(
sizeof(*nhe)), 0,
sizeof(*nhe));
3197 val =
xmalloc((128/4 + 4) + 1);
3198 xx =
str2uuid(nhe, NULL, version, val);
3218 int64_t * stack = memset(
alloca(ac*
sizeof(*stack)), 0, (ac*
sizeof(*stack)));
3226 val =
xstrdup(
_(
"(invalid type :rpn)"));
3230 stack[ix] = he->
p.
ui64p[0];
3234 stack[ix] = strtoll(he->
p.
str, &end, 0);
3236 val =
xstrdup(
_(
"(invalid string :rpn)"));
3243 for (i = 0; av[i] != NULL; i++) {
3244 const char * arg = av[i];
3245 size_t len = strlen(arg);
3250 }
else if (len > 1) {
3252 val =
xstrdup(
_(
"(expected number :rpn)"));
3256 val =
xstrdup(
_(
"(stack overflow :rpn)"));
3260 stack[ix] = strtoll(arg, &end, 0);
3262 val =
xstrdup(
_(
"(invalid number :rpn)"));
3267 val =
xstrdup(
_(
"(stack underflow :rpn)"));
3271 case '&': stack[ix] &= stack[ix+1];
break;
3272 case '|': stack[ix] |= stack[ix+1];
break;
3273 case '^': stack[ix] ^= stack[ix+1];
break;
3274 case '+': stack[ix] += stack[ix+1];
break;
3275 case '-': stack[ix] -= stack[ix+1];
break;
3276 case '*': stack[ix] *= stack[ix+1];
break;
3279 if (stack[ix+1] == 0) {
3280 val =
xstrdup(
_(
"(divide by zero :rpn)"));
3284 stack[ix] %= stack[ix+1];
3286 stack[ix] /= stack[ix+1];
3292 {
HE_t nhe = memset(
alloca(
sizeof(*nhe)), 0,
sizeof(*nhe));
3295 nhe->
p.
ui64p = (uint64_t *)&stack[ix];