1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 /* Copyright (C) 2003, 2004 Novell, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 /* Change password test program */
31 #include "e2k-kerberos.h"
32 #include "test-utils.h"
34 const char *test_program_name = "cptest";
37 krb_error (E2kKerberosResult result, const char *failed)
40 case E2K_KERBEROS_USER_UNKNOWN:
41 fprintf (stderr, "Unknown user\n");
44 case E2K_KERBEROS_PASSWORD_INCORRECT:
45 fprintf (stderr, "Password incorrect\n");
48 case E2K_KERBEROS_PASSWORD_EXPIRED:
49 printf ("Note: password has expired\n");
52 case E2K_KERBEROS_KDC_UNREACHABLE:
53 fprintf (stderr, "KDC unreachable (network problem or no such domain)\n");
56 case E2K_KERBEROS_TIME_SKEW:
57 fprintf (stderr, "Client/server time skew is too large.\n");
60 case E2K_KERBEROS_PASSWORD_TOO_WEAK:
61 fprintf (stderr, "Server rejected new password\n");
64 case E2K_KERBEROS_FAILED:
66 fprintf (stderr, "%s\n", failed);
69 /* else fall through */
72 fprintf (stderr, "Unknown error.\n");
78 test_main (int argc, char **argv)
80 char *domain, *at, *prompt, *password;
81 char *newpass1, *newpass2;
86 fprintf (stderr, "Usage: %s [user@]domain\n", argv[0]);
91 at = strchr (domain, '@');
93 user = g_strndup (domain, at - domain);
96 user = g_get_user_name ();
98 prompt = g_strdup_printf ("Password for %s@%s", user, domain);
99 password = test_ask_password (prompt);
102 res = e2k_kerberos_check_password (user, domain, password);
103 if (res != E2K_KERBEROS_OK)
104 krb_error (res, NULL);
106 newpass1 = test_ask_password ("New password");
107 newpass2 = test_ask_password ("Confirm");
109 if (!newpass1 || !newpass2 || strcmp (newpass1, newpass2) != 0) {
110 fprintf (stderr, "Passwords do not match.\n");
114 res = e2k_kerberos_change_password (user, domain, password, newpass1);
115 if (res != E2K_KERBEROS_OK)
116 krb_error (res, "Could not change password");
118 printf ("Password changed\n");