aboutsummaryrefslogtreecommitdiff
path: root/crypt.c
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 /crypt.c
parentInitial commit (diff)
downloadcrypt-b14d27c7118b0c7e1b4cf1e0b62f8ac544e4f7cd.tar.gz
crypt-b14d27c7118b0c7e1b4cf1e0b62f8ac544e4f7cd.zip
First commit
Diffstat (limited to 'crypt.c')
-rw-r--r--crypt.c51
1 files changed, 51 insertions, 0 deletions
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);
+}
+