diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-04-19 22:48:07 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-04-19 22:48:07 +1200 |
commit | b14d27c7118b0c7e1b4cf1e0b62f8ac544e4f7cd (patch) | |
tree | 768cde8edab68f5d6333cfb02cada99ee30b0d66 | |
parent | Initial commit (diff) | |
download | crypt-b14d27c7118b0c7e1b4cf1e0b62f8ac544e4f7cd.tar.gz crypt-b14d27c7118b0c7e1b4cf1e0b62f8ac544e4f7cd.zip |
First commit
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | README.markdown | 9 | ||||
-rw-r--r-- | crypt.1 | 21 | ||||
-rw-r--r-- | crypt.c | 51 | ||||
-rw-r--r-- | crypt.h | 11 |
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 + @@ -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> + @@ -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); +} + @@ -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 + |