Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
e1d773b000
!25 [sync] PR-18: fix scrub stopped working for links pointing to a block device
From: @openeuler-sync-bot 
Reviewed-by: @wk333 
Signed-off-by: @wk333
2024-03-22 01:41:22 +00:00
cenhuilin
a8edcf8fa3 fix scrub stopped working for links pointing to a block device
(cherry picked from commit bd0c59a4f47e8883a25cf0560b82d45fd6a73d7c)
2024-03-22 09:08:05 +08:00
openeuler-ci-bot
7b42b9ddbd
!16 [sync] PR-11: Fix exit with status code 0 for --help
From: @openeuler-sync-bot 
Reviewed-by: @starlet-dx 
Signed-off-by: @starlet-dx
2024-01-30 08:24:00 +00:00
starlet-dx
a36945b514 Fix exit with status code 0 for --help
(cherry picked from commit 3deed882e1717f82aa351800b16f01ad0bec4bb2)
2024-01-30 15:41:47 +08:00
openeuler-ci-bot
50b13eb3d3 !9 add buildrequire gettext and gcc
From: @zhouwenpei
Reviewed-by: @small_leek
Signed-off-by: @small_leek
2021-06-29 13:15:04 +00:00
zhouwenpei
8e5c34cd88 add buildrequire gettext and gcc 2021-06-29 17:56:27 +08:00
openeuler-ci-bot
675bd9fce5 !6 scrub升级到2.6.1
From: @yizhongxuanlv
Reviewed-by: @miao_kaibo
Signed-off-by: @miao_kaibo
2020-10-16 14:08:36 +08:00
root
05a83ac7e8 update to 2.6.1 2020-10-12 15:53:02 +08:00
openeuler-ci-bot
43f0e4121d !3 Modify source0 and replace tar package
From: @baizg1107
Reviewed-by: @yanzh_h
Signed-off-by: @yanzh_h
2020-09-15 14:47:08 +08:00
baizg1107
2d13f7c540 Modify source0 and replace tar package 2020-09-09 16:58:40 +08:00
6 changed files with 277 additions and 3 deletions

Binary file not shown.

BIN
scrub-2.6.1.tar.gz Normal file

Binary file not shown.

View File

@ -1,10 +1,18 @@
Name: scrub
Version: 2.5.2
Release: 14
Version: 2.6.1
Release: 4
Summary: A disk overwrite utility
License: GPLv2+
URL: https://github.com/chaos/scrub
Source0: http://bbgentoo.ilb.ru/distfiles/scrub-2.5.2.tar.bz2
Source0: http://github.com/chaos/scrub/releases/download/2.6.1/scrub-2.6.1.tar.gz
# https://github.com/chaos/scrub/commit/006fd942abd78d3128d427f1ede9786abe14c65f
Patch0: usage-Exit-with-status-code-0-for-help.patch
# https://github.com/chaos/scrub/commit/bd88864d8ee15a65d5ecdb3818afa4d5193d2455
Patch1: usage-Output-to-stdout-on-exit-code-0.patch
# https://github.com/chaos/scrub/commit/499a491c21b5a18be79334282dfa11fd4f408c49
Patch2: symlinks-to-block-device.patch
BuildRequires: gettext, gcc
%description
Scrub writes patterns on files or disk devices to make
@ -32,5 +40,17 @@ retrieving the data more difficult. It operates in one of three modes:
%{_mandir}/man1/scrub.1*
%changelog
* Thu Mar 21 2024 cenhuilin <cenhuilin@kylinos.cn> - 2.6.1-4
- fix scrub stopped working for links pointing to a block device
* Tue Jan 30 2024 yaoxin <yao_xin001@hoperun.com> - 2.6.1-3
- Fix exit with status code 0 for --help
* Tue Jun 29 2021 zhouwenpei <zhouwenpei1@huawei.com> - 2.6.1-2
- add buildrequire gcc and gettext.
* Mon Oct 12 2020 Zhangpeng <zhangpeng228@huawei.com> - 2.6.1-1
- update to 2.6.1
* Thu Nov 28 2019 Jiangping Hu <hujiangping@huawei.com> - 2.5.2-14
- Package init

View File

@ -0,0 +1,125 @@
From e3382e63b9d30b9c56b000fbfbb2edb2e4319ee7 Mon Sep 17 00:00:00 2001
From: Sergio Correia <scorreia@redhat.com>
Date: Thu, 21 Mar 2024 14:52:41 +0800
Subject: [PATCH] scrub should work for symlinks pointing to block devices
In [1] (add -L option to avoid scrubbing symlink target [Tim
Boronczyk]), scrub introduced a -L (--no-link) option so that it would
not scrub the target, if it was a link and this new option was set.
A side-effect of that change is that scrub stopped working for links
pointing to a block device, whereas it would still work for links
pointing to regular files -- it is not clear from the commit changelog
and the added documentation for this new option that this was an
intended change.
In this commit we fix this regression, and scrub works again for links
pointing to block devices. -L/--no-link option also works for these
links.
[1] https://github.com/chaos/scrub/commit/01915c442288b4b274261fa07e42e116fb9d6b60
---
src/scrub.c | 13 ++++++++-----
src/util.c | 13 +++++++++----
src/util.h | 2 +-
3 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/src/scrub.c b/src/scrub.c
index 08389d8..22f18d0 100644
--- a/src/scrub.c
+++ b/src/scrub.c
@@ -329,6 +329,10 @@ static int scrub_object(char *filename, const struct opt_struct *opt,
fprintf(stderr, "%s: %s already scrubbed? (-f to force)\n",
prog, filename);
errcount++;
+ } else if (is_symlink(filename) && opt->nofollow) {
+ fprintf(stderr, "%s: skipping symlink %s because --no-link (-L) option was set\n",
+ prog, filename);
+ errcount++;
} else if (!noexec) {
if (dryrun) {
printf("%s: (dryrun) scrub special file %s\n",
@@ -338,8 +342,8 @@ static int scrub_object(char *filename, const struct opt_struct *opt,
}
}
break;
- case FILE_LINK:
- if (opt->nofollow) {
+ case FILE_REGULAR:
+ if (is_symlink(filename) && opt->nofollow) {
if (opt->remove && !noexec) {
if (dryrun) {
printf("%s: (dryrun) unlink %s\n", prog, filename);
@@ -354,8 +358,7 @@ static int scrub_object(char *filename, const struct opt_struct *opt,
}
break;
}
- /* FALL THRU */
- case FILE_REGULAR:
+
if (access(filename, R_OK|W_OK) < 0) {
fprintf(stderr, "%s: no rw access to %s\n", prog, filename);
errcount++;
@@ -656,7 +659,7 @@ scrub_file(char *path, const struct opt_struct *opt)
filetype_t ftype = filetype(path);
off_t size = opt->devsize;
- assert(ftype == FILE_REGULAR || ftype == FILE_LINK);
+ assert(ftype == FILE_REGULAR);
if (stat(path, &sb) < 0) {
fprintf(stderr, "%s: stat %s: %s\n", prog, path, strerror(errno));
diff --git a/src/util.c b/src/util.c
index 96dd59b..fb85368 100644
--- a/src/util.c
+++ b/src/util.c
@@ -71,6 +71,15 @@ write_all(int fd, const unsigned char *buf, int count)
return n;
}
+/* Indicates whether the file represented by 'path' is a symlink.
+ */
+int
+is_symlink(char *path)
+{
+ struct stat sb;
+ return lstat(path, &sb) == 0 && S_ISLNK(sb.st_mode);
+}
+
/* Return the type of file represented by 'path'.
*/
filetype_t
@@ -80,10 +89,6 @@ filetype(char *path)
filetype_t res = FILE_NOEXIST;
- if (lstat(path, &sb) == 0 && S_ISLNK(sb.st_mode)) {
- return FILE_LINK;
- }
-
if (stat(path, &sb) == 0) {
if (S_ISREG(sb.st_mode))
res = FILE_REGULAR;
diff --git a/src/util.h b/src/util.h
index a409f2b..7beff4d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -9,7 +9,6 @@ typedef enum {
FILE_REGULAR,
FILE_CHAR,
FILE_BLOCK,
- FILE_LINK,
FILE_OTHER,
} filetype_t;
@@ -17,6 +16,7 @@ typedef enum { UP, DOWN } round_t;
int read_all(int fd, unsigned char *buf, int count);
int write_all(int fd, const unsigned char *buf, int count);
+int is_symlink(char *path);
filetype_t filetype(char *path);
off_t blkalign(off_t offset, int blocksize, round_t rtype);
void * alloc_buffer(int bufsize);
--
2.27.0

View File

@ -0,0 +1,48 @@
From 006fd942abd78d3128d427f1ede9786abe14c65f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi>
Date: Thu, 12 Apr 2018 08:07:29 +0300
Subject: [PATCH] usage: Exit with status code 0 for --help
---
src/scrub.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/scrub.c b/src/scrub.c
index 0a325cb..fceb639 100644
--- a/src/scrub.c
+++ b/src/scrub.c
@@ -110,7 +110,7 @@ static struct option longopts[] = {
char *prog;
static void
-usage(void)
+usage(int rc)
{
fprintf(stderr,
"Usage: %s [OPTIONS] file [file...]\n"
@@ -132,7 +132,7 @@ usage(void)
fprintf(stderr, "Available patterns are:\n");
seq_list ();
- exit(1);
+ exit(rc);
}
int
@@ -225,12 +225,14 @@ main(int argc, char *argv[])
nopt = true;
break;
case 'h': /* --help */
+ usage(0);
+ break;
default:
- usage();
+ usage(1);
}
}
if (argc == optind)
- usage();
+ usage(1);
if (Xopt && argc - optind > 1) {
fprintf(stderr, "%s: -X only takes one directory name\n", prog);
exit(1);

View File

@ -0,0 +1,81 @@
From bd88864d8ee15a65d5ecdb3818afa4d5193d2455 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi>
Date: Thu, 12 Apr 2018 08:39:20 +0300
Subject: [PATCH] usage: Output to stdout on exit code 0
---
src/pattern.c | 6 +++---
src/pattern.h | 4 +++-
src/scrub.c | 7 ++++---
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/pattern.c b/src/pattern.c
index 10430f9..6c0eedc 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -420,7 +420,7 @@ seq2str(const sequence_t *sp, char *buf, int len)
}
void
-seq_list(void)
+seq_list(FILE *fp)
{
const int len = seq_count();
char buf[80];
@@ -428,10 +428,10 @@ seq_list(void)
for (i = 0; i < len; i++) {
seq2str(sequences[i], buf, sizeof(buf));
- fprintf(stderr, "%s\n", buf);
+ fprintf(fp, "%s\n", buf);
}
seq2str(&custom_seq, buf, sizeof(buf));
- fprintf(stderr, "%s\n", buf);
+ fprintf(fp, "%s\n", buf);
}
/*
diff --git a/src/pattern.h b/src/pattern.h
index bcf5374..e1d0144 100644
--- a/src/pattern.h
+++ b/src/pattern.h
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
#define MAXPATBYTES 16
#define MAXSEQPATTERNS 35
typedef enum {
@@ -19,7 +21,7 @@ typedef struct {
} sequence_t;
const sequence_t *seq_lookup(char *name);
-void seq_list(void);
+void seq_list(FILE *fp);
char *pat2str(pattern_t p);
void memset_pat(void *s, pattern_t p, size_t n);
diff --git a/src/scrub.c b/src/scrub.c
index fceb639..6671ed5 100644
--- a/src/scrub.c
+++ b/src/scrub.c
@@ -112,7 +112,8 @@ char *prog;
static void
usage(int rc)
{
- fprintf(stderr,
+ FILE *fp = rc ? stderr : stdout;
+ fprintf(fp,
"Usage: %s [OPTIONS] file [file...]\n"
" -v, --version display scrub version and exit\n"
" -p, --pattern pat select scrub pattern sequence\n"
@@ -130,8 +131,8 @@ usage(int rc)
" -h, --help display this help message\n"
, prog);
- fprintf(stderr, "Available patterns are:\n");
- seq_list ();
+ fprintf(fp, "Available patterns are:\n");
+ seq_list (fp);
exit(rc);
}