aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-04-19 22:48:07 +1200
committerTom Ryder <tom@sanctum.geek.nz>2015-04-19 22:48:07 +1200
commitb14d27c7118b0c7e1b4cf1e0b62f8ac544e4f7cd (patch)
tree768cde8edab68f5d6333cfb02cada99ee30b0d66
parentInitial commit (diff)
downloadcrypt-b14d27c7118b0c7e1b4cf1e0b62f8ac544e4f7cd.tar.gz
crypt-b14d27c7118b0c7e1b4cf1e0b62f8ac544e4f7cd.zip
First commit
-rw-r--r--.gitignore1
-rw-r--r--Makefile13
-rw-r--r--README.markdown9
-rw-r--r--crypt.121
-rw-r--r--crypt.c51
-rw-r--r--crypt.h11
6 files changed, 106 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8155424
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+crypt
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..01552d2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+LDFLAGS = -lcrypt
+PREFIX := /usr/local
+
+all : crypt
+
+clean :
+ rm -f crypt
+
+install : crypt
+ mkdir -p "$(PREFIX)"/bin "$(PREFIX)"/share/man/man1
+ install crypt "$(PREFIX)"/bin
+ install crypt.1 "$(PREFIX)"/share/man/man1
+
diff --git a/README.markdown b/README.markdown
new file mode 100644
index 0000000..2858204
--- /dev/null
+++ b/README.markdown
@@ -0,0 +1,9 @@
+`crypt(1)`
+==========
+
+A convenience wrapper for UNIX `crypt(3)`.
+
+ $ make
+ $ make install
+ $ make install PREFIX="$HOME"/.local
+
diff --git a/crypt.1 b/crypt.1
new file mode 100644
index 0000000..d3d65df
--- /dev/null
+++ b/crypt.1
@@ -0,0 +1,21 @@
+.TH CRYPT 1 "April 2015" "Manual page for crypt(1)"
+.SH NAME
+.B crypt
+\- shell wrapper around crypt(3)
+.SH USAGE
+\fBcrypt\fR [-h|--help]
+.br
+\fBcrypt\fR \fIKEY\fR \fISALT\fR
+.SH SYNOPSIS
+\fBcrypt\fR password '$1$'
+.br
+\fBcrypt\fR password '$6$rounds=1000$sodiumchloride'
+.SH DESCRIPTION
+\fBcrypt(1)\fR just prints the output of \fBcrypt(3)\fR given the two arguments
+on the shell script. Its only purpose is so the author can play with
+\fBcrypt(3)\fR and avoid \fBmkpasswd(1)\fR.
+.SH SEE ALSO
+crypt(3)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
+
diff --git a/crypt.c b/crypt.c
new file mode 100644
index 0000000..f4d3a11
--- /dev/null
+++ b/crypt.c
@@ -0,0 +1,51 @@
+#include "crypt.h"
+
+#define OPTSTRING "h"
+#define USAGE "USAGE: crypt KEY SALT"
+
+/**
+ * crypt(1) - Simple shell script frontend to crypt(3), because I'm tired of
+ * fighting with mkpasswd(1).
+ *
+ * Author: Tom Ryder <tom@sanctum.geek.nz>
+ * Copyright: 2015
+ * License: MIT
+ */
+int main (int argc, char **argv)
+{
+ /* Assume user doesn't want help */
+ int help = 0;
+
+ /* Iterate through any options */
+ int o;
+ while ((o = getopt(argc, argv, OPTSTRING)) != -1) {
+ switch (o) {
+ case 'h':
+ help = 1;
+ break;
+ case '?':
+ fprintf(stderr, "Unknown option\n");
+ break;
+ default:
+ abort();
+ }
+ }
+
+ /* If help was asked, give it */
+ if (help) {
+ fprintf(stdout, "%s\n", USAGE);
+ exit(EXIT_SUCCESS);
+ }
+
+ /* If we don't have three arguments, bail */
+ if (argc != 3) {
+ fprintf(stderr, "%s\n", USAGE);
+ exit(EXIT_FAILURE);
+ }
+
+ /* All seems well, build the hash and print it */
+ char *hash = crypt(argv[1], argv[2]);
+ fprintf(stdout, "%s\n", hash);
+ exit(EXIT_SUCCESS);
+}
+
diff --git a/crypt.h b/crypt.h
new file mode 100644
index 0000000..7a390d7
--- /dev/null
+++ b/crypt.h
@@ -0,0 +1,11 @@
+#ifndef CRYPT_H
+#define CRYPT_H
+
+#define _XOPEN_SOURCE
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#endif
+