aboutsummaryrefslogtreecommitdiff
path: root/crypt.c
blob: 54b90ceaf5a4554332fa1c4bdb09267f1284bb9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "crypt.h"

/*
 * Main function
 */
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);
}