|
Packit |
fd8b60 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
Packit |
fd8b60 |
/* tests/misc/test_getpw.c */
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright (C) 2012 by the Red Hat Inc.
|
|
Packit |
fd8b60 |
* All rights reserved.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Export of this software from the United States of America may
|
|
Packit |
fd8b60 |
* require a specific license from the United States Government.
|
|
Packit |
fd8b60 |
* It is the responsibility of any person or organization contemplating
|
|
Packit |
fd8b60 |
* export to obtain such a license before exporting.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
|
|
Packit |
fd8b60 |
* distribute this software and its documentation for any purpose and
|
|
Packit |
fd8b60 |
* without fee is hereby granted, provided that the above copyright
|
|
Packit |
fd8b60 |
* notice appear in all copies and that both that copyright notice and
|
|
Packit |
fd8b60 |
* this permission notice appear in supporting documentation, and that
|
|
Packit |
fd8b60 |
* the name of M.I.T. not be used in advertising or publicity pertaining
|
|
Packit |
fd8b60 |
* to distribution of the software without specific, written prior
|
|
Packit |
fd8b60 |
* permission. Furthermore if you modify this software you must label
|
|
Packit |
fd8b60 |
* your software as modified software and not distribute it in such a
|
|
Packit |
fd8b60 |
* fashion that it might be confused with the original M.I.T. software.
|
|
Packit |
fd8b60 |
* M.I.T. makes no representations about the suitability of
|
|
Packit |
fd8b60 |
* this software for any purpose. It is provided "as is" without express
|
|
Packit |
fd8b60 |
* or implied warranty.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include "autoconf.h"
|
|
Packit |
fd8b60 |
#include "krb5.h"
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include <sys/types.h>
|
|
Packit |
fd8b60 |
#include <assert.h>
|
|
Packit |
fd8b60 |
#include <locale.h>
|
|
Packit |
fd8b60 |
#include <stdio.h>
|
|
Packit |
fd8b60 |
#include <stdlib.h>
|
|
Packit |
fd8b60 |
#include <string.h>
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static krb5_data result_utf8 = {
|
|
Packit |
fd8b60 |
0, 23, "This is a valid string.",
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static krb5_data result_invalid_utf8 = {
|
|
Packit |
fd8b60 |
0, 19, "\0This is not valid.",
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static krb5_data result_ad_complex = {
|
|
Packit |
fd8b60 |
0, 30,
|
|
Packit |
fd8b60 |
"\0\0" /* zero bytes */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* min length */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* history */
|
|
Packit |
fd8b60 |
"\0\0\0\1" /* properties, complex */
|
|
Packit |
fd8b60 |
"\0\0\0\0\0\0\0\0" /* expire */
|
|
Packit |
fd8b60 |
"\0\0\0\0\0\0\0\0" /* min age */
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static krb5_data result_ad_length = {
|
|
Packit |
fd8b60 |
0, 30,
|
|
Packit |
fd8b60 |
"\0\0" /* zero bytes */
|
|
Packit |
fd8b60 |
"\0\0\0\x0d" /* min length, 13 charaters */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* history */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* properties */
|
|
Packit |
fd8b60 |
"\0\0\0\0\0\0\0\0" /* expire */
|
|
Packit |
fd8b60 |
"\0\0\0\0\0\0\0\0" /* min age */
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static krb5_data result_ad_history = {
|
|
Packit |
fd8b60 |
0, 30,
|
|
Packit |
fd8b60 |
"\0\0" /* zero bytes */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* min length */
|
|
Packit |
fd8b60 |
"\0\0\0\x09" /* history, 9 passwords */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* properties */
|
|
Packit |
fd8b60 |
"\0\0\0\0\0\0\0\0" /* expire */
|
|
Packit |
fd8b60 |
"\0\0\0\0\0\0\0\0" /* min age */
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static krb5_data result_ad_age = {
|
|
Packit |
fd8b60 |
0, 30,
|
|
Packit |
fd8b60 |
"\0\0" /* zero bytes */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* min length */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* history, 9 passwords */
|
|
Packit |
fd8b60 |
"\0\0\0\0" /* properties */
|
|
Packit |
fd8b60 |
"\0\0\0\0\0\0\0\0" /* expire */
|
|
Packit |
fd8b60 |
"\0\0\x01\x92\x54\xd3\x80\0" /* min age, 2 days */
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static krb5_data result_ad_all = {
|
|
Packit |
fd8b60 |
0, 30,
|
|
Packit |
fd8b60 |
"\0\0" /* zero bytes */
|
|
Packit |
fd8b60 |
"\0\0\0\x05" /* min length, 5 characters */
|
|
Packit |
fd8b60 |
"\0\0\0\x0D" /* history, 13 passwords */
|
|
Packit |
fd8b60 |
"\0\0\0\x01" /* properties, complex */
|
|
Packit |
fd8b60 |
"\0\0\0\0\0\0\0\0" /* expire */
|
|
Packit |
fd8b60 |
"\0\0\0\xc9\x2a\x69\xc0\0" /* min age, 1 day */
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static void
|
|
Packit |
fd8b60 |
check(krb5_error_code code)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
if (code != 0) {
|
|
Packit |
fd8b60 |
com_err("t_vfy_increds", code, "");
|
|
Packit |
fd8b60 |
abort();
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static void
|
|
Packit |
fd8b60 |
check_msg(const char *real, const char *expected)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
if (strstr(real, expected) == NULL) {
|
|
Packit |
fd8b60 |
fprintf(stderr, "Expected to see: %s\n", expected);
|
|
Packit |
fd8b60 |
abort();
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
int
|
|
Packit |
fd8b60 |
main(void)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
krb5_context context;
|
|
Packit |
fd8b60 |
char *msg;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
setlocale(LC_ALL, "C");
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
check(krb5_init_context(&context));
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Valid utf-8 data in the result should be returned as is */
|
|
Packit |
fd8b60 |
check(krb5_chpw_message(context, &result_utf8, &msg));
|
|
Packit |
fd8b60 |
printf(" UTF8 valid: %s\n", msg);
|
|
Packit |
fd8b60 |
check_msg(msg, "This is a valid string.");
|
|
Packit |
fd8b60 |
free(msg);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Invalid data should have a generic message. */
|
|
Packit |
fd8b60 |
check(krb5_chpw_message(context, &result_invalid_utf8, &msg));
|
|
Packit |
fd8b60 |
printf(" UTF8 invalid: %s\n", msg);
|
|
Packit |
fd8b60 |
check_msg(msg, "contact your administrator");
|
|
Packit |
fd8b60 |
free(msg);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* AD data with complex data requirement */
|
|
Packit |
fd8b60 |
check(krb5_chpw_message(context, &result_ad_complex, &msg));
|
|
Packit |
fd8b60 |
printf(" AD complex: %s\n", msg);
|
|
Packit |
fd8b60 |
check_msg(msg, "The password must include numbers or symbols.");
|
|
Packit |
fd8b60 |
check_msg(msg, "Don't include any part of your name in the password.");
|
|
Packit |
fd8b60 |
free(msg);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* AD data with min password length */
|
|
Packit |
fd8b60 |
check(krb5_chpw_message(context, &result_ad_length, &msg));
|
|
Packit |
fd8b60 |
printf(" AD length: %s\n", msg);
|
|
Packit |
fd8b60 |
check_msg(msg, "The password must contain at least 13 characters.");
|
|
Packit |
fd8b60 |
free(msg);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* AD data with history requirements */
|
|
Packit |
fd8b60 |
check(krb5_chpw_message(context, &result_ad_history, &msg));
|
|
Packit |
fd8b60 |
printf(" AD history: %s\n", msg);
|
|
Packit |
fd8b60 |
check_msg(msg, "The password must be different from the previous 9 "
|
|
Packit |
fd8b60 |
"passwords.");
|
|
Packit |
fd8b60 |
free(msg);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* AD data with minimum age */
|
|
Packit |
fd8b60 |
check(krb5_chpw_message(context, &result_ad_age, &msg));
|
|
Packit |
fd8b60 |
printf(" AD min age: %s\n", msg);
|
|
Packit |
fd8b60 |
check_msg(msg, "The password can only be changed every 2 days.");
|
|
Packit |
fd8b60 |
free(msg);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* AD data with all */
|
|
Packit |
fd8b60 |
check(krb5_chpw_message(context, &result_ad_all, &msg));
|
|
Packit |
fd8b60 |
printf(" AD all: %s\n", msg);
|
|
Packit |
fd8b60 |
check_msg(msg, "The password can only be changed once a day.");
|
|
Packit |
fd8b60 |
check_msg(msg, "The password must be different from the previous 13 "
|
|
Packit |
fd8b60 |
"passwords.");
|
|
Packit |
fd8b60 |
check_msg(msg, "The password must contain at least 5 characters.");
|
|
Packit |
fd8b60 |
check_msg(msg, "The password must include numbers or symbols.");
|
|
Packit |
fd8b60 |
check_msg(msg, "Don't include any part of your name in the password.");
|
|
Packit |
fd8b60 |
free(msg);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
krb5_free_context(context);
|
|
Packit |
fd8b60 |
exit(0);
|
|
Packit |
fd8b60 |
}
|