#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 * Copyright: 2015 * License: MIT */ int main (int argc, char **argv) { /* The hash we will produce, hopefully */ char *hash = NULL; /* 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 */ hash = crypt(argv[1], argv[2]); fprintf(stdout, "%s\n", hash); exit(EXIT_SUCCESS); }