Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 49 lines (40 sloc) 0.83 kb
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 46 47 48
/*
* Copyright (c) 2010 Joyent Inc., All rights reserved.
*
* Summary:
*
* Takes plain-text password as cmdline arg and outputs a crypt() version.
*
*/

#include <crypt.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void usage()
{
    printf("Usage: cryptpass <password>\n");
    exit(1);
}

int main(int argc, char *argv[])
{
    char *salt, *enc;

    if ((argc != 2) || (strlen(argv[1]) < 1)) {
        usage();
    }

    errno=0;
    salt=crypt_gensalt(NULL, NULL);
    if (salt == NULL) {
        printf("FATAL: crypt_gensalt() errno=%d\n", errno);
        exit(1);
    }

    enc = crypt(argv[1], salt);
    if (enc == NULL) {
        printf("FATAL: crypt() errno=%d\n", errno);
        free(salt);
        exit(1);
    }

    printf("%s\n", enc);

    free(salt);
    exit(0);
}
Something went wrong with that request. Please try again.