/* ------------------------------------------------------------------- */
/* Copyright (C) 2008 by Intevation GmbH */
/* Author(s): */
/* Sascha Wilde <wilde@intevation.de> */

/* This program is free software under the GNU GPL (>=v2) */
/* Read the file COPYING coming with the software for details. */
/* ------------------------------------------------------------------- */

#define _XOPEN_SOURCE
#include <unistd.h>
#include <crypt.h>

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

void
usage ()
{
  printf ("Usage: pw-crypt PASSWD SALT\n");
}

int
main (int argc, char **argv)
{
  char passwd[80];
  char* c;
  if (argc != 3)
    usage();
  else
    {
      if ( strcmp (argv[1], "-") == 0 )
        {
          fgets (passwd, sizeof passwd, stdin);
          c = strchr (passwd, '\n');
          if ( c != NULL ) *c = 0;
          printf ("%s\n", crypt (passwd, argv[2]));
        }
      else
        printf ("%s\n", crypt (argv[1], argv[2]));
    }
  exit (0);
}
