atom feed82 messages in org.freebsd.freebsd-hackersrm -I patch (Re: Protection from the ...
FromSent OnAttachments
Giorgos KeramidasOct 2, 2004 1:19 am 
Edwin GroothuisOct 2, 2004 1:33 am 
Michael ReifenbergerOct 2, 2004 1:34 am 
Giorgos KeramidasOct 2, 2004 1:39 am 
Giorgos KeramidasOct 2, 2004 1:51 am 
Ryan SommersOct 2, 2004 1:52 am 
Giorgos KeramidasOct 2, 2004 1:53 am 
Giorgos KeramidasOct 2, 2004 2:06 am 
Max LaierOct 2, 2004 2:24 am 
Giorgos KeramidasOct 2, 2004 3:19 am 
Greg BlackOct 2, 2004 3:57 am 
Ceri DaviesOct 2, 2004 4:22 am 
Ceri DaviesOct 2, 2004 4:25 am 
Max LaierOct 2, 2004 4:51 am 
Peter JeremyOct 2, 2004 5:43 am 
Dimitry AndricOct 2, 2004 7:48 am 
Simon L. NielsenOct 2, 2004 8:03 am 
Sean FarleyOct 2, 2004 8:41 am 
SamOct 2, 2004 8:54 am 
Jacques A. VidrineOct 2, 2004 9:46 am 
Tillman HodgsonOct 2, 2004 9:51 am 
Lee HarrOct 2, 2004 9:53 am 
Tillman HodgsonOct 2, 2004 9:55 am 
Giorgos KeramidasOct 2, 2004 10:10 am 
Giorgos KeramidasOct 2, 2004 10:55 am 
Giorgos KeramidasOct 2, 2004 10:56 am 
Tillman HodgsonOct 2, 2004 11:09 am 
Doug RussellOct 2, 2004 11:37 am 
David SchultzOct 2, 2004 11:50 am 
David SchultzOct 2, 2004 12:01 pm 
Michael ReifenbergerOct 2, 2004 12:16 pm 
Doug RussellOct 2, 2004 12:18 pm 
Michael ReifenbergerOct 2, 2004 12:26 pm 
Dmitry FrolovOct 2, 2004 12:37 pm 
Doug RussellOct 2, 2004 12:48 pm 
David SchultzOct 2, 2004 1:11 pm 
Michael ReifenbergerOct 2, 2004 1:49 pm 
Tillman HodgsonOct 2, 2004 2:05 pm 
Garance A DrosihnOct 2, 2004 2:22 pm 
Ceri DaviesOct 2, 2004 3:00 pm 
sor...@cydem.orgOct 2, 2004 3:11 pm 
Giorgos KeramidasOct 2, 2004 4:28 pm 
Giorgos KeramidasOct 2, 2004 4:28 pm 
David SchultzOct 2, 2004 5:19 pm 
M. Warner LoshOct 2, 2004 6:26 pm 
M. Warner LoshOct 2, 2004 6:28 pm 
M. Warner LoshOct 2, 2004 6:29 pm 
Giorgos KeramidasOct 2, 2004 6:53 pm 
Thomas David RiversOct 2, 2004 6:53 pm 
M. Warner LoshOct 2, 2004 7:07 pm 
Doug RussellOct 2, 2004 7:11 pm 
Tillman HodgsonOct 2, 2004 8:09 pm 
Tillman HodgsonOct 2, 2004 8:11 pm 
David SchultzOct 2, 2004 11:31 pm 
Sam LawranceOct 3, 2004 12:35 am 
Chris HowellsOct 3, 2004 5:07 am 
Mike MeyerOct 3, 2004 5:07 am 
Mike MeyerOct 3, 2004 5:07 am 
M. Warner LoshOct 3, 2004 10:37 am 
Greg ShenautOct 3, 2004 11:14 am 
Dmitry MorozovskyOct 3, 2004 11:28 am 
Thomas SparrevohnOct 3, 2004 11:40 am 
Dag-Erling SmørgravOct 3, 2004 1:33 pm 
Roman NeuhauserOct 3, 2004 2:59 pm 
M. Warner LoshOct 3, 2004 6:38 pm 
Mark MurrayOct 4, 2004 1:10 am 
Dmitry KarasikOct 4, 2004 3:15 am 
Dave HorsfallOct 4, 2004 3:27 am 
Giorgos KeramidasOct 4, 2004 3:49 am 
Stijn HoopOct 4, 2004 4:52 am 
Ceri DaviesOct 4, 2004 5:33 am 
Søren SchmidtOct 4, 2004 5:43 am 
Chris HowellsOct 4, 2004 6:16 pm 
Chris DillonOct 5, 2004 8:36 am 
SamOct 5, 2004 9:03 am 
Giorgos KeramidasOct 5, 2004 5:12 pm 
Giorgos KeramidasOct 5, 2004 5:42 pm 
Matthew DillonOct 5, 2004 6:30 pm 
Matthew DillonOct 5, 2004 6:56 pm 
Matthew DillonOct 5, 2004 11:39 pm 
Thomas SparrevohnOct 6, 2004 12:49 pm 
Lyndon NerenbergOct 28, 2004 5:31 am 
Subject:rm -I patch (Re: Protection from the dreaded "rm -fr /")
From:Matthew Dillon (dil@apollo.backplane.com)
Date:Oct 5, 2004 6:56:57 pm
List:org.freebsd.freebsd-hackers

I think I'll commit something like this to DragonFly (you might get patch errors w/ FreeBSD but this is the basic idea).

-Matt

Index: rm.1 =================================================================== RCS file: /cvs/src/bin/rm/rm.1,v retrieving revision 1.2 diff -u -r1.2 rm.1 --- rm.1 17 Jun 2003 04:22:50 -0000 1.2 +++ rm.1 6 Oct 2004 01:34:12 -0000 @@ -81,6 +81,11 @@ option overrides any previous .Fl f options. +.It Fl I +Request confirmation once if more then three files are being removed or if a +directory is being recursively removed. This is a less intrusive dumb-user +option then +.Fl i .It Fl P Overwrite regular files before deleting them. Files are overwritten three times, first with the byte pattern 0xff, Index: rm.c =================================================================== RCS file: /cvs/src/bin/rm/rm.c,v retrieving revision 1.3 diff -u -r1.3 rm.c --- rm.c 30 Aug 2004 19:27:21 -0000 1.3 +++ rm.c 6 Oct 2004 01:52:46 -0000 @@ -51,9 +51,11 @@ #include <unistd.h>

int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok; +int rflag, Iflag; uid_t uid;

int check(char *, char *, struct stat *); +int check2(char **); void checkdot(char **); void rm_file(char **); void rm_overwrite(char *, struct stat *); @@ -70,7 +72,7 @@ int main(int argc, char *argv[]) { - int ch, rflag; + int ch; char *p;

/* @@ -94,7 +96,7 @@ }

Pflag = rflag = 0; - while ((ch = getopt(argc, argv, "dfiPRrvW")) != -1) + while ((ch = getopt(argc, argv, "dfiIPRrvW")) != -1) switch(ch) { case 'd': dflag = 1; @@ -107,6 +109,9 @@ fflag = 0; iflag = 1; break; + case 'I': + Iflag = 1; + break; case 'P': Pflag = 1; break; @@ -138,6 +143,10 @@ if (*argv) { stdin_ok = isatty(STDIN_FILENO);

+ if (Iflag) { + if (check2(argv) == 0) + exit (1); + } if (rflag) rm_tree(argv); else @@ -442,6 +451,47 @@ return (first == 'y' || first == 'Y'); }

+int +check2(char **argv) +{ + struct stat st; + int first; + int ch; + int fcount = 0; + int dcount = 0; + int i; + + for (i = 0; argv[i]; ++i) { + if (lstat(argv[i], &st) == 0) { + if (S_ISDIR(st.st_mode)) + ++dcount; + else + ++fcount; + } + } + first = 0; + while (first != 'n' && first != 'N' && first != 'y' && first != 'Y') { + if (dcount && fcount && rflag) { + fprintf(stderr, + "recursively remove %d dirs and %d files? ", + dcount, fcount); + } else if (dcount && rflag) { + fprintf(stderr, + "recursively remove %d dirs? ", dcount); + } else if (dcount + fcount > 3) { + fprintf(stderr, "remove %d files? ", dcount + fcount); + } else { + return(1); + } + fflush(stderr); + + first = ch = getchar(); + while (ch != '\n' && ch != EOF) + ch = getchar(); + } + return (first == 'y' || first == 'Y'); +} + #define ISDOT(a) ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && !(a)[2]))) void checkdot(char **argv)