1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/krb/t_expire_warn.c - Test harness for password expiry warnings */
4 * Copyright (C) 2010 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
29 static int exp_dummy, prompt_dummy;
31 static krb5_error_code
32 prompter_cb(krb5_context ctx, void *data, const char *name,
33 const char *banner, int num_prompts, krb5_prompt prompts[])
35 /* Not expecting any actual prompts, only banners. */
36 assert(num_prompts == 0);
37 assert(banner != NULL);
38 printf("Prompter: %s\n", banner);
43 expire_cb(krb5_context ctx, void *data, krb5_timestamp password_expiration,
44 krb5_timestamp account_expiration, krb5_boolean is_last_req)
46 printf("password_expiration = %ld\n", (long)password_expiration);
47 printf("account_expiration = %ld\n", (long)account_expiration);
48 printf("is_last_req = %d\n", (int)is_last_req);
52 main(int argc, char **argv)
55 krb5_get_init_creds_opt *opt;
56 char *user, *password, *service = NULL;
58 krb5_principal client;
62 fprintf(stderr, "Usage: %s username password {1|0} [service]\n",
68 use_cb = atoi(argv[3]);
72 assert(krb5_init_context(&ctx) == 0);
73 assert(krb5_get_init_creds_opt_alloc(ctx, &opt) == 0);
75 assert(krb5_get_init_creds_opt_set_expire_callback(ctx, opt, expire_cb,
78 assert(krb5_parse_name(ctx, user, &client) == 0);
79 assert(krb5_get_init_creds_password(ctx, &creds, client, password,
80 prompter_cb, &prompt_dummy, 0, service,
82 krb5_get_init_creds_opt_free(ctx, opt);
83 krb5_free_principal(ctx, client);
84 krb5_free_cred_contents(ctx, &creds);
85 krb5_free_context(ctx);