Dump some old code up in here.
This commit is contained in:
36
doc/README.kst
Normal file
36
doc/README.kst
Normal file
@@ -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 <number of passes>: 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.
|
||||
95
doc/libdirutils.3
Normal file
95
doc/libdirutils.3
Normal file
@@ -0,0 +1,95 @@
|
||||
.Dd November 20, 2012
|
||||
.Dt LIBDIRUTILS 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm libdirutils
|
||||
.Nd Python-esque file utility functions for C
|
||||
.Sh SYNOPSIS
|
||||
.In dirutils.h
|
||||
.Ft int
|
||||
.Fo makedirs
|
||||
.Fa "const char *path"
|
||||
.Fc
|
||||
.Ft EXISTS_STATUS
|
||||
.Fo path_exists
|
||||
.Fa "const char *path"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo rmdirs
|
||||
.Fa "const char *path"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo walkpath
|
||||
.Fa "const char *root"
|
||||
.Fa "dirwalk_action action"
|
||||
.Fa "unsigned char mask"
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
provides a number of convenience functions for working with files and
|
||||
directories; as the name implies, it is aimed primarily at directories.
|
||||
.Nm makedirs
|
||||
provides functionality similar to
|
||||
.Ic mkdir -p ,
|
||||
creating all the parent directories required. They are created with the
|
||||
caller's umask applied to the mode 0777.
|
||||
.Nm path_exists
|
||||
returns an EXISTS_STATUS value (described below) indicated the status
|
||||
of the file.
|
||||
.Nm rmdirs
|
||||
provides functionality similar to
|
||||
.Ic rm -r .
|
||||
.Nm walkpath
|
||||
walks through a path on disk and calls an action on a file if it
|
||||
matches the file type mask. The mask should include some of the
|
||||
file types listed in
|
||||
.Xr readdir 3 ,
|
||||
such as DT_DIR or DT_REG. The convenience definitions
|
||||
.Ic FT_ANY
|
||||
and
|
||||
.Ic FT_STD
|
||||
are provided; the former matches any file type and the latter matches
|
||||
regular files and directories. Note that this will not follow links.
|
||||
The action is defined in the dirutils.h header as
|
||||
.Ic typedef int (*dirwalk_action)(const char *) ;
|
||||
it takes a NULL-terminated path and does what it will with that path.
|
||||
It should return -1 on failure and 0 on success. Note that in the case
|
||||
where the path provided to
|
||||
.Nm walkdir
|
||||
is not a directory, but its type matches the mask, the action will
|
||||
still be run on it.
|
||||
.Sh RETURN VALUES
|
||||
.Nm makedirs
|
||||
and
|
||||
.Nm rmdirs
|
||||
return EXIT_SUCCESS on success and EXIT_FAILURE on failure. The enum
|
||||
returned by
|
||||
.Nm path_exists
|
||||
is defined in
|
||||
.Sy dirutils.h
|
||||
as:
|
||||
.Bd -literal
|
||||
enum E_EXISTS_STATUS {
|
||||
EXISTS_ERROR, /* an error occurred looking at the file */
|
||||
EXISTS_NOENT, /* the path does not exist */
|
||||
EXISTS_NOPERM, /* the process does not have appropriate permissions */
|
||||
EXISTS_DIR, /* the path exists and is a directory */
|
||||
EXISTS_FILE, /* the path exists and is a regular file */
|
||||
EXISTS_OTHER /* the path exists and is not a directory or regular */
|
||||
/* file. */
|
||||
};
|
||||
.Ed
|
||||
.Sh ERRORS
|
||||
The most common error will be a permissions error; it may be prudent to
|
||||
compare the value of
|
||||
.Nm errno
|
||||
before and after calling the function.
|
||||
.Sh HISTORY
|
||||
.Nm
|
||||
was inspired by similar functions in the Python and Go programming languages.
|
||||
The author found himself in need of such functions in several projects,
|
||||
and decided to write a utility library to handle these functions.
|
||||
.Sh AUTHORS
|
||||
The
|
||||
.Nm
|
||||
library was written by
|
||||
.An Kyle Isom Aq Mt kyle@tyrfingr.is .
|
||||
285
doc/libiniparser.3
Normal file
285
doc/libiniparser.3
Normal file
@@ -0,0 +1,285 @@
|
||||
.Dd Sep 9, 2015
|
||||
.Dt LIBINIPARSER 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm libiniparser
|
||||
.Nd simple parser for .ini files
|
||||
.Sh SYNOPSIS
|
||||
.In stdint.h
|
||||
.In iniparser/iniparser.h
|
||||
.Ft int
|
||||
.Fo iniparser_init
|
||||
.Fa void
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo iniparser_destroy
|
||||
.Fa void
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo iniparser_open
|
||||
.Fa "const char *path"
|
||||
.Fa "iniparser_file_s **file"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo iniparser_close
|
||||
.Fa "iniparser_file_s *file"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo iniparser_readline
|
||||
.Fa "iniparser_file_s *file"
|
||||
.Fa "inipaser_line_s *line"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo iniparser_line_init
|
||||
.Fa "iniparser_line_s *line"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo iniparser_line_destroy
|
||||
.Fa "iniparser_line_s *line"
|
||||
.Fc
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is a parsing library for .ini files. An ini file is of the form
|
||||
.Bd -literal
|
||||
[ section1 ]
|
||||
keyA = valueA
|
||||
keyB = valueB
|
||||
|
||||
[ section2 ]
|
||||
keyA = valueA
|
||||
keyB = valueB
|
||||
keyC =
|
||||
.Ed
|
||||
.Ss OVERVIEW
|
||||
The library is initialised with
|
||||
.Nm iniparser_init ,
|
||||
which will
|
||||
.Sy must
|
||||
be called before using the library. When no longer needed, the
|
||||
.Nm libparser_destroy
|
||||
function should be called to free resources.
|
||||
Configuration files are represented by the
|
||||
.Nm iniparser_file_s structure, which is defined as
|
||||
.Bd -literal
|
||||
typedef struct {
|
||||
FILE *source;
|
||||
char *lineptr;
|
||||
size_t linelen;
|
||||
ssize_t readlen;
|
||||
} iniparser_file_s;
|
||||
.Ed
|
||||
.Pp
|
||||
A configuration file may be opened with
|
||||
.Nm iniparser_open ,
|
||||
which if given a pointer to a NULL pointer to an
|
||||
.Nm iniparser_file_s ,
|
||||
will allocate space using
|
||||
.Xr calloc 3 .
|
||||
The caller must be sure then to free this memory when it is no longer
|
||||
needed. Callers may also explicitly set the
|
||||
.Ic source
|
||||
pointer to the appropriate source file handle, and ensure that the
|
||||
other fields are at zero values. Similarly,
|
||||
.Nm iniparser_close
|
||||
will close the source file handle and free any memory allocated inside
|
||||
the structure. Users should still ensure that the structure itself is
|
||||
freed as required.
|
||||
.Nm iniparser_readline
|
||||
will attempt to fill in the results of parsing the next line in the
|
||||
configuration file. Note that it will keep reading lines, skipping
|
||||
comments and blank lines, until it reads a valid section or key-value
|
||||
line or until it encounters an error. The
|
||||
.Nm iniparser_line_s
|
||||
structure is defined as
|
||||
.Bd -literal
|
||||
typedef struct {
|
||||
uint8_t is_section;
|
||||
uint8_t is_set;
|
||||
char *name;
|
||||
char *value;
|
||||
} iniparser_line_s;
|
||||
.Ed
|
||||
.Pp
|
||||
A line should be initialised before first use with
|
||||
.Nm iniparser_line_init ,
|
||||
and should be destroyed after last use with
|
||||
.Nm iniparser_line_destroy .
|
||||
The fields are defined as:
|
||||
.Bl -bullet -width Ds
|
||||
.It
|
||||
The is_section field will be set to 1 if the line was a new section.
|
||||
.It
|
||||
The is_set field will be set to 1 if valid data was set. This is
|
||||
useful when an EOF is reached.
|
||||
.It
|
||||
The name field contains the section name if the is_section field is 1,
|
||||
or the key if is_section is 0 and is_set is 1. It should be
|
||||
disregarded outside of these two cases.
|
||||
.It
|
||||
The value field contains the key's value if is_section is 0 and is_set
|
||||
is 1. It should be disregarded otherwise. If it is NULL, the key had
|
||||
no value.
|
||||
.El
|
||||
Both the name and value field will have leading and trailing spaces
|
||||
stripped. The line that is passed in is reset and its memory freed
|
||||
every time
|
||||
.Nm iniparser_readline
|
||||
is run. Callers should copy any relevant data from the line elsewhere.
|
||||
.Ss TYPICAL USAGE
|
||||
Processing a file
|
||||
generally follows the following steps:
|
||||
.Bl -bullet
|
||||
.It
|
||||
Call
|
||||
.Nm iniparser_open
|
||||
with the path to the ini file and a pointer to an
|
||||
.Nm iniparser_file_s
|
||||
structure that will be used to manage the file parsing.
|
||||
.It
|
||||
Prepare the line storage variable with
|
||||
.Nm iniparser_line_init .
|
||||
.It
|
||||
Call
|
||||
.Nm iniparser_readline
|
||||
to obtain successive values of the file.
|
||||
.It
|
||||
While iniparser_readline continues to succeed, keep processing the
|
||||
results.
|
||||
.It
|
||||
Clean up with the following sequence:
|
||||
.Bl -enum
|
||||
.It
|
||||
.Nm iniparser_line_destroy
|
||||
.It
|
||||
.Nm iniparser_close
|
||||
.It
|
||||
If the parser is no longer needed,
|
||||
.Nm iniparser_destroy .
|
||||
Once this is called, the library cannot be used until
|
||||
.Nm iniparser_init
|
||||
is called again.
|
||||
.El
|
||||
.El
|
||||
.Ss THE REGULAR EXPRESSIONS
|
||||
The following regular expressions are used:
|
||||
.Bl -tag -width Ds
|
||||
.It sections
|
||||
"^\\[ *([a-zA-Z0-9_-]+) *\\]$"
|
||||
.It blank lines
|
||||
"^[ \t]*$"
|
||||
.It comments
|
||||
"^[ \t]*[#;]"
|
||||
.It key-value lines
|
||||
"^[ \t]*([a-zA-Z0-9_-]+)[ \t]*=(.*)$"
|
||||
.El
|
||||
.Sh RETURN VALUES
|
||||
.Nm iniparser_init ,
|
||||
.Nm iniparser_open ,
|
||||
and
|
||||
.Nm iniparser_readline
|
||||
all return 0 on success and -1 on failure. Additionally,
|
||||
.Nm iniparser_readline
|
||||
uses 1 to signal EOF; the line value should be checked to determine if
|
||||
there is new data and the file closed.
|
||||
.Sh EXAMPLES
|
||||
The following program will parse the files specified on the command
|
||||
line and print sections and key/value pairs.
|
||||
.Bd -literal
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "iniparser/iniparser.h"
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
iniparser_file_s *file = NULL;
|
||||
iniparser_line_s line;
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
ret = iniparser_init();
|
||||
if (0 != ret) {
|
||||
fprintf(stderr, "init failed: %d\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
printf("Processing %s\n", argv[i]);
|
||||
ret = iniparser_open(argv[i], &file);
|
||||
if (0 != ret) {
|
||||
perror("_open");
|
||||
fprintf(stderr, "retval: %d\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
iniparser_line_init(&line);
|
||||
|
||||
while (1) {
|
||||
ret = iniparser_readline(file, &line);
|
||||
/* -1 is returned on error. */
|
||||
if (-1 == ret) {
|
||||
perror("_readline");
|
||||
fprintf(stderr, "retval: %d\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
/* 1 means EOF. */
|
||||
else if (1 == ret) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (line.is_section) {
|
||||
printf("Now in section '%s'\n", line.name);
|
||||
}
|
||||
else {
|
||||
printf("Read key '%s' with value '%s'\n",
|
||||
line.name, line.value);
|
||||
}
|
||||
|
||||
iniparser_line_destroy(&line);
|
||||
}
|
||||
|
||||
iniparser_close(file);
|
||||
free(file);
|
||||
file = NULL;
|
||||
iniparser_line_destroy(&line);
|
||||
}
|
||||
|
||||
exit:
|
||||
iniparser_line_destroy(&line);
|
||||
if (argc > 0) {
|
||||
iniparser_destroy();
|
||||
}
|
||||
|
||||
return ret==0;
|
||||
}
|
||||
.Ed
|
||||
.Sh ERRORS
|
||||
.Nm iniparser_open
|
||||
will fail if its
|
||||
.Ic file
|
||||
argument is NULL, the call to
|
||||
.Xr calloc 3
|
||||
fails, or the source file could not be opened. Note that in the case
|
||||
where memory is allocated by the library, it will be freed on exit.
|
||||
.Pp
|
||||
.Nm iniparser_close
|
||||
returns the exit value of the call to
|
||||
.Xr fclose 3 .
|
||||
.Pp
|
||||
.Nm iniparser_readline
|
||||
will fail if there are any improperly formatted lines; comments and
|
||||
blank lines will be skipped. It will also fail if it fails to read
|
||||
a line from the file.
|
||||
.Sh AUTHORS
|
||||
.Nm
|
||||
was written by
|
||||
.An Kyle Isom Aq Mt kyle@tyrfingr.is .
|
||||
.Sh LICENSE
|
||||
.Nm
|
||||
is released under the MIT license.
|
||||
84
doc/srm.1
Normal file
84
doc/srm.1
Normal file
@@ -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.
|
||||
Reference in New Issue
Block a user