install: add -z <max_cmp_size> option
Introduces the -z <max_cmp_size> flag, enabling users to set a custom file size limit for pre-installation change checks and avoiding future hard-coded limit modifications. Reviewed by: glebius Approved by: glebius (mentor) Obtained from: Fudo Security MFC after: 2 weeks Sponsored by: Fudo Security Differential Revision: https://reviews.freebsd.org/D57230
This commit is contained in:
@@ -11,7 +11,7 @@ MAN= install.1
|
|||||||
CFLAGS+= -I${SRCTOP}/contrib/mtree
|
CFLAGS+= -I${SRCTOP}/contrib/mtree
|
||||||
CFLAGS+= -I${SRCTOP}/lib/libnetbsd
|
CFLAGS+= -I${SRCTOP}/lib/libnetbsd
|
||||||
|
|
||||||
LIBADD= md
|
LIBADD= md util
|
||||||
CFLAGS+= -DWITH_MD5 -DWITH_RIPEMD160
|
CFLAGS+= -DWITH_MD5 -DWITH_RIPEMD160
|
||||||
|
|
||||||
.ifdef BOOTSTRAPPING
|
.ifdef BOOTSTRAPPING
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
.Nd install binaries
|
.Nd install binaries
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl bCcpSsUv
|
.Op Fl bCcpSsUvz
|
||||||
.Op Fl B Ar suffix
|
.Op Fl B Ar suffix
|
||||||
.Op Fl D Ar destdir
|
.Op Fl D Ar destdir
|
||||||
.Op Fl f Ar flags
|
.Op Fl f Ar flags
|
||||||
@@ -45,9 +45,10 @@
|
|||||||
.Op Fl N Ar dbdir
|
.Op Fl N Ar dbdir
|
||||||
.Op Fl o Ar owner
|
.Op Fl o Ar owner
|
||||||
.Op Fl T Ar tags
|
.Op Fl T Ar tags
|
||||||
|
.Op Fl z Ar size
|
||||||
.Ar file1 file2
|
.Ar file1 file2
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl bCcpSsUv
|
.Op Fl bCcpSsUvz
|
||||||
.Op Fl B Ar suffix
|
.Op Fl B Ar suffix
|
||||||
.Op Fl D Ar destdir
|
.Op Fl D Ar destdir
|
||||||
.Op Fl f Ar flags
|
.Op Fl f Ar flags
|
||||||
@@ -59,6 +60,7 @@
|
|||||||
.Op Fl N Ar dbdir
|
.Op Fl N Ar dbdir
|
||||||
.Op Fl o Ar owner
|
.Op Fl o Ar owner
|
||||||
.Op Fl T Ar tags
|
.Op Fl T Ar tags
|
||||||
|
.Op Fl z Ar size
|
||||||
.Ar file1 ... fileN directory
|
.Ar file1 ... fileN directory
|
||||||
.Nm
|
.Nm
|
||||||
.Fl d
|
.Fl d
|
||||||
@@ -264,6 +266,13 @@ Cause
|
|||||||
.Nm
|
.Nm
|
||||||
to be verbose,
|
to be verbose,
|
||||||
showing files as they are installed or backed up.
|
showing files as they are installed or backed up.
|
||||||
|
.It Fl z Ar maxsize
|
||||||
|
Limit the comparison feature of
|
||||||
|
.Fl C
|
||||||
|
to files no larger than
|
||||||
|
.Ar maxsize .
|
||||||
|
Files exceeding this limit bypass the comparison step and are directly overwritten.
|
||||||
|
The default maximum size is 128MiB.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
By default,
|
By default,
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <util.h>
|
||||||
#include <vis.h>
|
#include <vis.h>
|
||||||
|
|
||||||
#include "mtree.h"
|
#include "mtree.h"
|
||||||
@@ -137,6 +138,7 @@ static FILE *metafp;
|
|||||||
static const char *group, *owner;
|
static const char *group, *owner;
|
||||||
static const char *suffix = BACKUP_SUFFIX;
|
static const char *suffix = BACKUP_SUFFIX;
|
||||||
static char *destdir, *digest, *fflags, *metafile, *tags;
|
static char *destdir, *digest, *fflags, *metafile, *tags;
|
||||||
|
static size_t max_compare_size = MAX_CMP_SIZE;
|
||||||
|
|
||||||
static int compare(int, const char *, size_t, int, const char *, size_t,
|
static int compare(int, const char *, size_t, int, const char *, size_t,
|
||||||
char **);
|
char **);
|
||||||
@@ -168,12 +170,13 @@ main(int argc, char *argv[])
|
|||||||
u_int iflags;
|
u_int iflags;
|
||||||
char *p;
|
char *p;
|
||||||
const char *to_name;
|
const char *to_name;
|
||||||
|
uint64_t num;
|
||||||
|
|
||||||
fset = 0;
|
fset = 0;
|
||||||
iflags = 0;
|
iflags = 0;
|
||||||
set = NULL;
|
set = NULL;
|
||||||
group = owner = NULL;
|
group = owner = NULL;
|
||||||
while ((ch = getopt(argc, argv, "B:bCcD:df:g:h:l:M:m:N:o:pSsT:Uv")) !=
|
while ((ch = getopt(argc, argv, "B:bCcD:df:g:h:l:M:m:N:o:pSsT:Uvz:")) !=
|
||||||
-1)
|
-1)
|
||||||
switch((char)ch) {
|
switch((char)ch) {
|
||||||
case 'B':
|
case 'B':
|
||||||
@@ -270,6 +273,13 @@ main(int argc, char *argv[])
|
|||||||
case 'v':
|
case 'v':
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'z':
|
||||||
|
if (expand_number(optarg, &num) != 0 || num == 0) {
|
||||||
|
errx(EX_USAGE, "invalid max compare filesize:"
|
||||||
|
" %s", optarg);
|
||||||
|
}
|
||||||
|
max_compare_size = num;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@@ -1092,7 +1102,7 @@ compare(int from_fd, const char *from_name __unused, size_t from_len,
|
|||||||
|
|
||||||
do_digest = (digesttype != DIGEST_NONE && dresp != NULL &&
|
do_digest = (digesttype != DIGEST_NONE && dresp != NULL &&
|
||||||
*dresp == NULL);
|
*dresp == NULL);
|
||||||
if (from_len <= MAX_CMP_SIZE) {
|
if (from_len <= max_compare_size) {
|
||||||
static char *buf, *buf1, *buf2;
|
static char *buf, *buf1, *buf2;
|
||||||
static size_t bufsize;
|
static size_t bufsize;
|
||||||
int n1, n2;
|
int n1, n2;
|
||||||
@@ -1484,11 +1494,11 @@ usage(void)
|
|||||||
{
|
{
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"usage: install [-bCcpSsUv] [-f flags] [-g group] [-m mode] [-o owner]\n"
|
"usage: install [-bCcpSsUv] [-f flags] [-g group] [-m mode] [-o owner]\n"
|
||||||
" [-M log] [-D dest] [-h hash] [-T tags]\n"
|
" [-M log] [-D dest] [-h hash] [-T tags] [-z maxcmpsize]\n"
|
||||||
" [-B suffix] [-l linkflags] [-N dbdir]\n"
|
" [-B suffix] [-l linkflags] [-N dbdir]\n"
|
||||||
" file1 file2\n"
|
" file1 file2\n"
|
||||||
" install [-bCcpSsUv] [-f flags] [-g group] [-m mode] [-o owner]\n"
|
" install [-bCcpSsUv] [-f flags] [-g group] [-m mode] [-o owner]\n"
|
||||||
" [-M log] [-D dest] [-h hash] [-T tags]\n"
|
" [-M log] [-D dest] [-h hash] [-T tags] [-z maxcmpsize]\n"
|
||||||
" [-B suffix] [-l linkflags] [-N dbdir]\n"
|
" [-B suffix] [-l linkflags] [-N dbdir]\n"
|
||||||
" file1 ... fileN directory\n"
|
" file1 ... fileN directory\n"
|
||||||
" install -dU [-vU] [-g group] [-m mode] [-N dbdir] [-o owner]\n"
|
" install -dU [-vU] [-g group] [-m mode] [-N dbdir] [-o owner]\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user