5 #define _RPMIOB_INTERNAL
16 #define _KFB(n) (1U << (n))
17 #define _DFB(n) (_KFB(n) | 0x40000000)
19 #define F_ISSET(_dc, _FLAG) ((_dc)->flags & ((RPMDC_FLAGS_##_FLAG) & ~0x40000000))
59 const char * (*print) (rpmdc
dc,
int rc);
68 unsigned char buf[BUFSIZ];
97 uint32_t dalgo = 0xffffffff;
100 if (!strcmp(dname,
"sha1new"))
103 for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
104 if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)
106 if (opt->longName == NULL)
108 if (!(opt->val > 0 && opt->val < 256))
110 if (strcmp(opt->longName, dname))
112 dalgo = (uint32_t) opt->val;
123 const char * dalgoName = NULL;
125 for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
126 if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)
128 if (opt->longName == NULL)
130 if (!(opt->val > 0 && opt->val < 256))
132 if ((uint32_t)opt->val != dalgo)
134 dalgoName = opt->longName;
154 if (strcmp(dc->
fn,
"-") == 0) {
161 fprintf(stderr,
_(
"%s: Failed to open %s: %s\n"),
171 while (fgets(buf,
sizeof(buf), fp) != NULL) {
172 const char * dname, * digest, * path;
173 char *se = buf + (int)strlen(buf);
177 while (se > buf &&
xisspace((
int)se[-1]))
182 if (buf[0] ==
'\0')
continue;
184 if (buf[0] ==
'#')
continue;
187 dname = NULL; path = NULL;
188 for (digest = se = buf; (c = (int)*se) != 0; se++)
199 if (se[1] ==
' ' || se[1] ==
'*')
205 fprintf(stderr,
_(
"%s: %s line %u: No file path found.\n"),
215 if (dc->
dalgo == 0xffffffff) {
216 fprintf(stderr,
_(
"%s: %s line %u: Unknown digest name \"%s\"\n"),
230 if (dc->
fd != NULL) {
244 const char *msg = (rc ?
"FAILED" :
"OK");
249 if (rc == 0 &&
F_ISSET(dc, STATUS))
254 nb += strlen(dc->
dalgoName) +
sizeof(
":") - 1;
255 assert(dc->
digest != NULL);
258 nb +=
sizeof(
" *") - 1;
260 nb += strlen(dc->
fn);
269 if (rc || !
F_ISSET(dc, STATUS)) {
280 *te++ = (
F_ISSET(dc, BINARY) ?
'*' :
' ');
307 if (!(xx == 0 && iob != NULL)) {
308 fprintf(stderr,
_(
"%s: Failed to open %s\n"),
__progname, dc->
fn);
313 be = (
char *)(iob->b + iob->blen);
314 while (be > (
char *)iob->b && (be[-1] ==
'\n' || be[-1] ==
'\r')) {
320 be = strrchr((
char *)iob->b,
'=');
323 _(
"%s: %s: Manifest needs \"algo=digest\" as last line\n"),
330 while (be > (
char *)iob->b && !(be[-1] ==
'\n' || be[-1] ==
'\r'))
332 if (be <= (
char *)iob->b) {
333 fprintf(stderr,
_(
"%s: %s: Manifest is empty\n"),
341 fprintf(stderr,
_(
"%s: %s: Unknown digest algo name \"%s\"\n"),
354 if (strcmp(dc->
digest, digest)) {
356 _(
"%s: %s: Manifest digest check: Expected(%s) != (%s)\n"),
361 digest =
_free(digest);
366 for (f = (
char *)iob->b; *f; f = fe) {
367 static const char hexdigits[] =
"0123456789ABCDEFabcdef";
368 const char * _dn = NULL;
373 while (*fe && !(*fe ==
'\n' || *fe ==
'\r'))
375 while (*fe && (*fe ==
'\n' || *fe ==
'\r'))
387 while (*f && strchr(hexdigits, *f) != NULL)
390 fprintf(stderr,
_(
"%s: %s line %u: Malformed digest field.\n"),
399 fprintf(stderr,
_(
"%s: %s line %u: Malformed mtime field.\n"),
408 fprintf(stderr,
_(
"%s: %s line %u: Malformed size field.\n"),
415 fprintf(stderr,
_(
"%s: %s line %u: No file path.\n"),
421 if (_dn && *_dn ==
'/')
452 const struct stat * st = &dc->
sb;
456 if (rc == 0 &&
F_ISSET(dc, STATUS))
459 snprintf(_mtime,
sizeof(_mtime),
"%llu",
460 (
unsigned long long) st->st_mtime);
461 _mtime[
sizeof(_mtime)-1] =
'\0';
462 snprintf(_size,
sizeof(_size),
"%llu",
463 (
unsigned long long) st->st_size);
464 _size[
sizeof(_size)-1] =
'\0';
465 if ((_bn = strrchr(dc->
fn,
'/')) != NULL)
474 nb += 1 + strlen(_mtime);
475 nb += 1 + strlen(_size);
476 nb += 1 + strlen(_bn);
484 const char *msg = (rc ?
"FAILED" :
"OK");
485 if (rc || !
F_ISSET(dc, STATUS)) {
492 if (S_ISDIR(st->st_mode)) {
502 }
else if (S_ISREG(st->st_mode) ||
S_ISLNK(st->st_mode)) {
506 *te++ = (st->st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) ?
'X' :
'F';
527 static int asAscii = 1;
531 fprintf(stderr,
"\trpmdcPrintFile(%p) fd %p fn %s\n", dc, dc->
fd, dc->
fn);
533 assert(dc->
fd != NULL);
535 assert(dc->
digest != NULL);
546 {
const char * t = (*dc->
print) (dc, rc);
547 if (dc->
ofd && t && *t) {
548 size_t nb = strlen(t);
571 fprintf(stderr,
"\trpmdcFiniFile(%p) fn %s\n", dc, dc->
fn);
581 for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
582 if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)
586 dc->
dalgo = opt->val;
609 fprintf(stderr,
"\trpmdcCalcFile(%p) fn %s\n", dc, dc->
fn);
618 }
while (dc->
nb > 0);
628 fprintf(stderr,
"\trpmdcInitFile(%p) fn %s\n", dc, dc->
fn);
630 if (!S_ISREG(dc->
sb.st_mode)) {
637 fprintf(stderr,
_(
"open of %s failed: %s\n"), dc->
fn,
Fstrerror(dc->
fd));
652 for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
653 if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)
655 if (opt->longName == NULL)
657 if (!(opt->val > 0 && opt->val < 256))
659 dc->
dalgo = opt->val;
678 fprintf(stderr,
"*** rpmdcVisitF(%p) fn %s\n", dc, dc->
fn);
694 return strcmp((*a)->fts_name, (*b)->fts_name);
701 if (S_ISDIR((*a)->fts_statp->st_mode)) {
702 if (!S_ISDIR((*b)->fts_statp->st_mode))
704 }
else if (S_ISDIR((*b)->fts_statp->st_mode))
706 return strcmp((*a)->fts_name, (*b)->fts_name);
712 char *
const * paths = (
char *
const *) dc->
paths;
719 fprintf(stderr,
"Fts_open: %s", strerror(
errno));
743 (
void) printf(
"# %s\n", dc->
p->
fts_path);
744 (void) rpmdcVisitD(dc);
753 (void) printf(
"%*s# %s\n", indent,
"", dc->
p->
fts_path);
754 (void) printf(
"%*s..\n", indent,
"");
762 (void) fprintf(stderr,
"%s: %s: %s\n",
__progname,
784 #if !defined(POPT_ARG_ARGV)
785 static int _poptSaveString(
const char ***argvp,
unsigned int argInfo,
const char * val)
793 while ((*argvp)[argc] != NULL)
795 *argvp =
xrealloc(*argvp, (argc + 1 + 1) *
sizeof(**argvp));
796 if ((argv = *argvp) != NULL) {
806 enum poptCallbackReason reason,
807 const struct poptOption * opt,
const char * arg,
813 if (opt->arg == NULL)
822 fprintf(stderr,
_(
"%s: Unknown option -%c\n"),
__progname, opt->val);
823 poptPrintUsage(con, stderr, 0);
833 #if !defined(POPT_ARG_ARGV)
835 { NULL,
'\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
841 N_(
"Print 0install manifest"), NULL },
844 N_(
"Read in binary mode"), NULL },
846 #if !defined(POPT_ARG_ARGV)
847 {
"check",
'c', POPT_ARG_STRING, NULL,
'c',
848 N_(
"Read digests from MANIFEST file and verify (may be used more than once)"),
851 {
"check",
'c', POPT_ARG_ARGV, &_dc.
manifests, 0,
852 N_(
"Read digests from MANIFEST file and verify (may be used more than once)"),
856 N_(
"Print file tree specification to stdout"), NULL },
858 N_(
"Directories only"), NULL },
861 N_(
"read in text mode (default)"), NULL },
864 { NULL, -1, POPT_ARG_INCLUDE_TABLE, NULL, 0,
866 The following two options are useful only when verifying digests:\
871 N_(
"no output when verifying"), NULL },
873 N_(
"warn about improperly formatted checksum lines"), NULL },
876 N_(
"Available digests:"), NULL },
879 N_(
"Common options for all rpmio executables:"),
885 { NULL, -1, POPT_ARG_INCLUDE_TABLE, NULL, 0,
887 When checking, the input should be a former output of this program. The\n\
888 default mode is to print a line with digest, a character indicating type\n\
889 (`*' for binary, ` ' for text), and name for each FILE.\n\
937 av = poptGetArgs(optCon);
942 poptPrintUsage(optCon, stderr, 0);
952 for (i = 0; i < ac; i++)
962 while ((dc->
fn = *av++) != NULL) {
975 fprintf(stderr,
"%s: WARNING: %u of %u computed checksums did NOT match\n",
981 static int asAscii = 1;
984 assert(dc->
digest != NULL);
986 (void)
Fwrite(t, strlen(t),
sizeof(*t), dc->
ofd);