dovecotpw.c revision 034ba60e28b45896b4a26548fe3a6d0be5f6dfa0
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Copyright (C) 2004 Joshua Goodall */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenusage(const char *s)
2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224bTimo Sirainen "usage: %s [-l] [-p plaintext] [-s scheme] [-u user] [-V]\n", s);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen " -l List known password schemes",
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen " -p plaintext New password",
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen " -s scheme Password scheme",
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen " -u user Username (if scheme uses it)",
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen " -V Internally verify the hash");
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen while ((ch = getopt(argc, argv, "lp:s:u:V")) != -1) {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen unsigned int i, count;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen schemes = array_get(&password_schemes, &count);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen for (i = 0; i < count; i++)
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen plaintext = i_strdup(getpass("Enter new password: "));
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen check = i_strdup(getpass("Retype new password: "));
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen if (!password_generate_encoded(plaintext, user, scheme, &hash)) {
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen fprintf(stderr, "Unknown scheme: %s\n", scheme);
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen const unsigned char *raw_password;
2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224bTimo Sirainen if (password_decode(hash, scheme, &raw_password, &size) <= 0) {
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen fprintf(stderr, "reverse decode check failed\n");
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen "reverse password verification check failed\n");