From 769de599fcbdf3cd50cd8137de4e2461c2a65d25 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Fri, 14 Feb 2020 23:05:21 -0800 Subject: [PATCH] move srm to own dir --- ke/main.c | 7 ++-- srm/LICENSE | 21 ++++++++++++ srm/Makefile.in | 54 +++++++++++++++++++++++++++++ srm/README | 36 ++++++++++++++++++++ srm/config.sh | 57 +++++++++++++++++++++++++++++++ srm/srm.1 | 84 ++++++++++++++++++++++++++++++++++++++++++++++ {src => srm}/srm.c | 3 +- 7 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 srm/LICENSE create mode 100644 srm/Makefile.in create mode 100644 srm/README create mode 100755 srm/config.sh create mode 100644 srm/srm.1 rename {src => srm}/srm.c (99%) diff --git a/ke/main.c b/ke/main.c index c722e66..da8ac65 100644 --- a/ke/main.c +++ b/ke/main.c @@ -760,7 +760,7 @@ editor_find_callback(char *query, int16_t c) lmatch = -1; dir = 1; return; - } else if (c == ARROW_RIGHT || c == ARROW_DOWN) { + } else if (c == ARROW_RIGHT || c == ARROW_DOWN || c == CTRL_KEY('s')) { dir = 1; } else if (c == ARROW_LEFT || c == ARROW_UP) { dir = -1; @@ -1038,6 +1038,9 @@ process_normal(int16_t c) case CTRL_KEY('l'): display_refresh(); break; + case CTRL_KEY('s'): + editor_find(); + break; case ESC_KEY: editor.mode = MODE_ESCAPE; break; @@ -1250,7 +1253,7 @@ draw_status_bar(struct abuf *ab) editor.filename ? editor.filename : "[no file]", editor.nrows); rlen = snprintf(rstatus, sizeof(rstatus), "L%d/%d C%d", - editor.cury+1, editor.nrows, editor.curx+1); + editor.cury+1, editor.nrows, editor.curx+1); ab_append(ab, ESCSEQ "7m", 4); ab_append(ab, status, len); diff --git a/srm/LICENSE b/srm/LICENSE new file mode 100644 index 0000000..b842e77 --- /dev/null +++ b/srm/LICENSE @@ -0,0 +1,21 @@ +CODE LICENSE +This code is released under the ISC license. +-------------------------------------------------------------------------------- + +the ISC license: +Copyright (c) 2011 Kyle Isom + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +-------------------------------------------------------------------------------- + diff --git a/srm/Makefile.in b/srm/Makefile.in new file mode 100644 index 0000000..e19ea93 --- /dev/null +++ b/srm/Makefile.in @@ -0,0 +1,54 @@ +VERSION := 1.3.1 +CC := gcc +TARGET := srm +OBJS := +LIBS := + +PREFIX ?= $PREFIX +MANDIR ?= $MANDIR + +CFLAGS += -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align +CFLAGS += -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations +CFLAGS += -Wnested-externs -Winline -Wno-long-long -Wunused-variable +CFLAGS += -Wstrict-prototypes -Werror -ansi -static +CFLAGS += -D$(TARGET)_VERSION="\"$(TARGET) version $(VERSION)\"" +CFLAGS += OS_CFLAGS +all: $(TARGET) + +$(TARGET): $(TARGET).o $(OBJS) + ${CC} -o $(TARGET) ${CFLAGS} ${LDFLAGS} $(LIBS) $(OBJS) $(TARGET).o + +install: $(TARGET) + install -m 0755 $(TARGET) $(PREFIX)/bin/$(TARGET) + install -m 0755 -d $(MANDIR)/man1 + install -m 0444 $(TARGET).1 $(MANDIR)/man1/$(TARGET).1 + +uninstall: + -rm -f $(PREFIX)/bin/$(TARGET) + -rm -f $(MANDIR)/man1/$(TARGET).1 + +lint: + -mkdir security + -rats -w 3 $(TARGET).[ch] > security/rats.out + -lint -fhrs $(TARGET).c > security/lint.out + -splint +posixlib $(TARGET).[ch] > security/splint.out + +dist: clean + -mkdir $(TARGET)-$(VERSION) + -cp * $(TARGET)-$(VERSION) + -cd $(TARGET)-$(VERSION) && make distclean && cd .. + -tar czf $(TARGET)-$(VERSION).tgz $(TARGET)-$(VERSION) + +distclean: clean + -rm -f Makefile + +htmldoc: + -mandoc -Thtml $(TARGET).1 > $(TARGET).1.html + +tags: + ctags *.[ch] + +.c.o: + $(CC) -c ${CFLAGS} $? + +.PHONY: clean all install lint uninstall dist distclean htmldoc tags diff --git a/srm/README b/srm/README new file mode 100644 index 0000000..dd42197 --- /dev/null +++ b/srm/README @@ -0,0 +1,36 @@ +srm - securely wipe files +-------------------------- +srm is a utility to overwrite files with random data in one or more passes. + + +Dependencies +------------ +None. + + +Compatibility +------------- +srm has been tested on the following operating systems: + * OpenBSD (5.1-snap) + * OS X (10.8) + * Linux (Debian 6.0) + + +Installation +------------ +make build install + + +Usage +----- +srm [-v] [-n number] file list + +options: + -n : specify number of passes + (default is 3 passes) + -v: verbose mode. display list of failures and wiped files after wiping + + +Known bugs / caveats +-------------------- +srm can't recursively remove files, i.e. it can't remove directories. diff --git a/srm/config.sh b/srm/config.sh new file mode 100755 index 0000000..cd4617c --- /dev/null +++ b/srm/config.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +TARGET="$(cat Makefile.in | grep 'TARGET :=' | awk -F' ' '{ print $3; }')" +echo "configuring ${TARGET}" + +which sed 2>/dev/null 1>/dev/null +if [ $? -ne 0 ]; then + echo "cannot find sed!" 1>&2 +fi + +OPSYS=$(uname -s) + +echo "Configuring for ${OPSYS}..." +if [ "x${OPSYS}" = "xLinux" ]; then + OS_CFLAGS="-D_BSD_SOURCE -D_POSIX_SOURCE -D_XOPEN_SOURCE" +elif [ "x${OPSYS}" = "xDarwin" ]; then + OS_CFLAGS="-D_DARWIN_C_SOURCE" +else + OS_CFLAGS="" +fi + +if [ -z "${OS_CFLAGS}" ]; then + echo "${OPSYS} requires no extra build flags." +else + echo "${OPSYS} requires build flags ${OS_CFLAGS}" +fi + +if [ -z "${PREFIX}" ]; then + PREFIX="/usr/local" +fi + +if [ "${PREFIX}" = "/usr" ]; then + MANDIR="$(PREFIX)/share/man" +elif [ "${PREFIX}" = "/usr/local" ]; then + if [ "${OPSYS}" = "Darwin" ]; then + MANDIR="${PREFIX}/share/man" + else + MANDIR="${PREFIX}/man" + fi +else + MANDIR="${PREFIX}/man" +fi + +if [ "$1" = "DEBUG" ]; then + OS_CFLAGS="${OS_CFLAGS} -g -O0" +fi + +echo "prefix: ${PREFIX}" +echo "mandir: ${MANDIR}" + +echo "writing new Makefile" +cat Makefile.in | sed -e "s|OS_CFLAGS|${OS_CFLAGS}|" | \ + sed -e "s|\$PREFIX|${PREFIX}|" | \ + sed -e "s|\$MANDIR|${MANDIR}|" > Makefile + + +echo "done." diff --git a/srm/srm.1 b/srm/srm.1 new file mode 100644 index 0000000..3837af0 --- /dev/null +++ b/srm/srm.1 @@ -0,0 +1,84 @@ +.Dd $Mdocdate$ +.Dt SRM 1 +.Os +.Sh NAME +.Nm srm +.Nd securely delete files +.Sh SYNOPSIS +.Nm +.Op Fl h +.Op Fl n Ar number +.Op Fl r +.Op Fl v +.Op Fl V +.Ar files +.Sh DESCRIPTION +.Nm +is a simple secure file deletion tool. It overwrites the file with several +passes of random data before unlinking it. If no options are specified, Nm +defaults to three passes. +.Nm +supports the following options: +.Bl -tag -width .Ds +.It Fl h +Display a brief help message. +.It Fl n Ar number +Specify the number of times to overwrite each target with random data. +.It Fl r +Recursive mode. Delete any directories and all subdirectories underneath. +.It Fl v +Verbose mode. Displays a list of both files that failed to wipe and files that +were successfully wiped. +.It Fl V +Print version information. +.El +.Sh EXIT STATUS +.Ex -std +The exit values are standard +.Xr sysexits 3 +values. +.Sh EXAMPLES +Wipe files +.Pa foo +and +.Pa bar +with three passes: +.Dl $ srm foo bar +Wipe files +.Pa baz +and +.Pa quux +with ten passes: +.Dl $ srm -n 10 baz quux +Wipe all PGP keys, i.e. files with extension +.Pa *.asc : +.Dl $ srm *.asc +Recursive deletes aren't implemented yet. A workaround is to use +.Nm +and +.Xr find 1 , +for example to delete all +.Pa *.pgp +files: +.Dl $ find . -iname '*.pgp' -exec srm '{}' \; +.Sh DIAGNOSTICS +.Nm +uses the standard +.Xr err 3 +facilities to report any errors that occur. +.Sh SEE ALSO +The srm page on +.Lk http://www.tyrfingr.is/projects/srm/ "tyrfinger" . +.Sh STANDARDS +.Nm +conforms to +.St -ansiC . +.Sh AUTHORS +.Nm +was written by +.An "Kyle Isom" Aq Mt kyle@tyrfingr.is . +.Sh BUGS +None known. Report bugs to the author. +.Sh LICENSE +.Nm +is released under an ISC license. diff --git a/src/srm.c b/srm/srm.c similarity index 99% rename from src/srm.c rename to srm/srm.c index ac0fb1f..98cc49b 100644 --- a/src/srm.c +++ b/srm/srm.c @@ -32,7 +32,6 @@ #define DEFAULT_PASSES 3 #define DEV_RANDOM "/dev/urandom" #define MAX_CHUNK 4096 -#define SRM_VERSION "1.3.1" static int do_wipe(char *, size_t, int); @@ -364,7 +363,7 @@ usage() void version() { - printf("%s\n", SRM_VERSION); + printf("%s\n", srm_VERSION); }