--- /dev/null
+# Configuration for clang-format automated reformatting. -*- yaml -*-
+#
+# The canonical version of this file is maintained in the rra-c-util package,
+# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
+#
+# Copyright 2020 Russ Allbery <eagle@eyrie.org>
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+#
+# SPDX-License-Identifier: FSFAP
+
+---
+Language: Cpp
+BasedOnStyle: LLVM
+AlignConsecutiveMacros: true
+AlignEscapedNewlines: Left
+AlwaysBreakAfterReturnType: AllDefinitions
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeBraces: WebKit
+ColumnLimit: 79
+IndentPPDirectives: AfterHash
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+MaxEmptyLinesToKeep: 2
+SpaceAfterCStyleCast: true
+---
# Automake makefile for krb5-strength.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2007, 2009, 2010, 2012, 2013, 2014
+# Copyright 2016, 2020 Russ Allbery <eagle@eyrie.org>
+# Copyright 2007, 2009-2010, 2012-2014
# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
ACLOCAL_AMFLAGS = -I m4
-EXTRA_DIST = .gitignore .travis.yml README.md LICENSE bootstrap \
- cracklib/HISTORY cracklib/LICENCE cracklib/README \
+EXTRA_DIST = .clang-format .gitignore .travis.yml README.md LICENSE \
+ bootstrap cracklib/HISTORY cracklib/LICENCE cracklib/README \
cracklib/genrules.pl cracklib/mkdict docs/krb5-strength.5.in \
docs/krb5-strength.pod docs/metadata tests/README tests/TESTS \
tests/data/krb5.conf tests/data/make-krb5-conf tests/data/passwords \
--suppressions=$(abs_top_srcdir)/tests/data/valgrind.supp \
--trace-children-skip="/bin/sh,*/cat,*/diff,*/expr,*/grep,*/mkdir,*/rm,*/rmdir,*/sed,*/sleep,*/true,*/wc,*/docs/*-t,*/perl/*-t,*/data/make-krb5-conf,*/tools/heimdal-history-t,*/tools/wordlist*-t" \
tests/runtests -l '$(abs_top_srcdir)/tests/TESTS'
+
+
+# Used by maintainers to reformat all source code using clang-format and
+# excluding some files.
+reformat:
+ find . -name '*.[ch]' \! -name snprintf.c \! -name krb5-profile.c \
+ \! -path './cracklib/*' -print \
+ | xargs clang-format-10 -style=file -i
#include <portable/system.h>
#ifdef HAVE_CDB_H
-# include <cdb.h>
+# include <cdb.h>
#endif
#include <errno.h>
#include <fcntl.h>
if (path == NULL)
return 0;
free(path);
- krb5_set_error_message(ctx, KADM5_BAD_SERVER_PARAMS, "CDB dictionary"
- " requested but not built with CDB support");
+ krb5_set_error_message(ctx, KADM5_BAD_SERVER_PARAMS,
+ "CDB dictionary requested but not built with CDB"
+ " support");
return KADM5_BAD_SERVER_PARAMS;
}
#endif
/* Skip the rest of this file if CDB is not available. */
#ifdef HAVE_CDB
-/*
- * Macro used to make password checks more readable. Assumes that the found
- * and fail labels are available for the abort cases of finding a password or
- * failing to look it up.
- */
-# define CHECK_PASSWORD(ctx, data, password) \
- do { \
- code = in_cdb_dictionary(ctx, data, password, &found); \
- if (code != 0) \
- goto fail; \
- if (found) \
- goto found; \
- } while (0)
-
-
/*
* Look up a password in CDB and set the found parameter to true if it is
* found, false otherwise. Returns a Kerberos status code, which will be 0 on
}
+/*
+ * Macro used to make password checks more readable. Assumes that the found
+ * and fail labels are available for the abort cases of finding a password or
+ * failing to look it up.
+ */
+# define CHECK_PASSWORD(ctx, data, password) \
+ do { \
+ code = in_cdb_dictionary(ctx, data, password, &found); \
+ if (code != 0) \
+ goto fail; \
+ if (found) \
+ goto found; \
+ } while (0)
+
+
/*
* Given a password, try the various transformations that we want to apply and
* check for each of them in the dictionary. Returns a Kerberos status code,
else
classes->symbol = true;
}
- if (classes->lower) classes->num_classes++;
- if (classes->upper) classes->num_classes++;
- if (classes->digit) classes->num_classes++;
- if (classes->symbol) classes->num_classes++;
+ if (classes->lower)
+ classes->num_classes++;
+ if (classes->upper)
+ classes->num_classes++;
+ if (classes->digit)
+ classes->num_classes++;
+ if (classes->symbol)
+ classes->num_classes++;
}
if (okay)
spec = end + 1;
else {
- code = strength_error_config(ctx, "bad character class requirement"
- " in configuration: %s", spec);
+ code = strength_error_config(ctx,
+ "bad character class requirement in"
+ " configuration: %s",
+ spec);
goto fail;
}
}
(*rule)->digit = true;
else if (strcmp(class, "symbol") == 0)
(*rule)->symbol = true;
- else if (isdigit((unsigned char) *class)) {
- okay = parse_number(class, &(*rule)->num_classes, &end);
- if (!okay || *end != '\0' || (*rule)->num_classes > MAX_CLASSES) {
- code = strength_error_config(ctx, "bad character class minimum"
- " in configuration: %s", class);
- goto fail;
- }
- }
- else {
+ else if (isdigit((unsigned char) *class)) {
+ okay = parse_number(class, &(*rule)->num_classes, &end);
+ if (!okay || *end != '\0' || (*rule)->num_classes > MAX_CLASSES) {
+ code = strength_error_config(ctx,
+ "bad character class minimum in"
+ " configuration: %s",
+ class);
+ goto fail;
+ }
+ } else {
code = strength_error_config(ctx, "unknown character class %s",
class);
goto fail;
* allocation failed while parsing or while setting the default value.
*/
krb5_error_code
-strength_config_list(krb5_context ctx, const char *opt,
- struct vector **result)
+strength_config_list(krb5_context ctx, const char *opt, struct vector **result)
{
realm_type realm;
char *value = NULL;
/* When using the embedded CrackLib, we need to provide our own prototype. */
#ifdef HAVE_CRACKLIB
-# ifdef HAVE_CRACK_H
-# include <crack.h>
-# else
+# ifdef HAVE_CRACK_H
+# include <crack.h>
+# else
extern const char *FascistCheck(const char *password, const char *dict);
-# endif
+# endif
#endif
if (path == NULL)
return 0;
free(path);
- krb5_set_error_message(ctx, KADM5_BAD_SERVER_PARAMS, "CrackLib dictionary"
- " requested but not built with CrackLib support");
+ krb5_set_error_message(ctx, KADM5_BAD_SERVER_PARAMS,
+ "CrackLib dictionary requested but not built with"
+ " CrackLib support");
return KADM5_BAD_SERVER_PARAMS;
}
#endif
* and variable arguments and set the Kerberos error code and message,
* returning the appropriate code.
*/
-#define ERROR_FUNC(name, code) \
- krb5_error_code \
- strength_error_ ## name(krb5_context ctx, const char *format, ...) \
- { \
- va_list args; \
- va_start(args, format); \
- set_error(ctx, code, format, args); \
- va_end(args); \
- return code; \
+#define ERROR_FUNC(name, code) \
+ krb5_error_code strength_error_##name(krb5_context ctx, \
+ const char *format, ...) \
+ { \
+ va_list args; \
+ va_start(args, format); \
+ set_error(ctx, code, format, args); \
+ va_end(args); \
+ return code; \
}
-ERROR_FUNC(class, KADM5_PASS_Q_CLASS)
-ERROR_FUNC(config, KADM5_MISSING_KRB5_CONF_PARAMS)
-ERROR_FUNC(dict, KADM5_PASS_Q_DICT)
-ERROR_FUNC(generic, KADM5_PASS_Q_GENERIC)
+ERROR_FUNC(class, KADM5_PASS_Q_CLASS)
+ERROR_FUNC(config, KADM5_MISSING_KRB5_CONF_PARAMS)
+ERROR_FUNC(dict, KADM5_PASS_Q_DICT)
+ERROR_FUNC(generic, KADM5_PASS_Q_GENERIC)
ERROR_FUNC(tooshort, KADM5_PASS_Q_TOOSHORT)
* instead.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2020 Russ Allbery <eagle@eyrie.org>
* Copyright 2009, 2013
* The Board of Trustees of the Leland Stanford Junior University
*
#include <errno.h>
#ifdef HAVE_KADM5_KADM5_PWCHECK_H
-# include <kadm5/kadm5-pwcheck.h>
+# include <kadm5/kadm5-pwcheck.h>
#endif
#include <plugin/internal.h>
*/
static int
heimdal_pwcheck(krb5_context ctx, krb5_principal principal,
- krb5_data *password, const char *tuning UNUSED,
- char *message, size_t length)
+ krb5_data *password, const char *tuning UNUSED, char *message,
+ size_t length)
{
krb5_pwqual_moddata data = NULL;
char *pastring = NULL;
}
/* The public symbol that Heimdal looks for. */
+/* clang-format off */
static struct kadm5_pw_policy_check_func functions[] = {
- { "krb5-strength", heimdal_pwcheck },
- { NULL, NULL }
+ {"krb5-strength", heimdal_pwcheck},
+ {NULL, NULL}
};
struct kadm5_pw_policy_verifier kadm5_password_verifier = {
"krb5-strength",
"Russ Allbery",
functions
};
+/* clang-format on */
#endif /* HAVE_KRB5_REALM */
#include <portable/macros.h>
#ifdef HAVE_CDB_H
-# include <cdb.h>
+# include <cdb.h>
#endif
#ifdef HAVE_SQLITE3_H
-# include <sqlite3.h>
+# include <sqlite3.h>
#endif
#include <stddef.h>
#ifdef HAVE_KRB5_PWQUAL_PLUGIN_H
-# include <krb5/pwqual_plugin.h>
+# include <krb5/pwqual_plugin.h>
#else
typedef struct krb5_pwqual_moddata_st *krb5_pwqual_moddata;
#endif
/* Error strings returned (and displayed to the user) for various failures. */
-#define ERROR_ASCII "Password contains non-ASCII or control characters"
-#define ERROR_CLASS_LOWER "Password must contain a lowercase letter"
-#define ERROR_CLASS_UPPER "Password must contain an uppercase letter"
-#define ERROR_CLASS_DIGIT "Password must contain a number"
+#define ERROR_ASCII "Password contains non-ASCII or control characters"
+#define ERROR_CLASS_LOWER "Password must contain a lowercase letter"
+#define ERROR_CLASS_UPPER "Password must contain an uppercase letter"
+#define ERROR_CLASS_DIGIT "Password must contain a number"
#define ERROR_CLASS_SYMBOL \
"Password must contain a space or punctuation character"
-#define ERROR_CLASS_MIN \
+#define ERROR_CLASS_MIN \
"Password must contain %lu types of characters (lowercase, uppercase," \
" numbers, symbols)"
-#define ERROR_DICT "Password found in list of common passwords"
-#define ERROR_LETTER "Password is only letters and spaces"
-#define ERROR_MINDIFF "Password does not contain enough unique characters"
-#define ERROR_SHORT "Password is too short"
-#define ERROR_USERNAME "Password based on username or principal"
+#define ERROR_DICT "Password found in list of common passwords"
+#define ERROR_LETTER "Password is only letters and spaces"
+#define ERROR_MINDIFF "Password does not contain enough unique characters"
+#define ERROR_SHORT "Password is too short"
+#define ERROR_USERNAME "Password based on username or principal"
/*
* A character class rule, which consists of a minimum length to which the
* checking for at least the MIT plugin.
*/
struct krb5_pwqual_moddata_st {
- long minimum_different; /* Minimum number of different characters */
- long minimum_length; /* Minimum password length */
- bool ascii; /* Whether to require printable ASCII */
- bool nonletter; /* Whether to require a non-letter */
- struct class_rule *rules; /* Linked list of character class rules */
- char *dictionary; /* Base path to CrackLib dictionary */
- long cracklib_maxlen; /* Longer passwords skip CrackLib checks */
- bool have_cdb; /* Whether we have a CDB dictionary */
- int cdb_fd; /* File descriptor of CDB dictionary */
+ long minimum_different; /* Minimum number of different characters */
+ long minimum_length; /* Minimum password length */
+ bool ascii; /* Whether to require printable ASCII */
+ bool nonletter; /* Whether to require a non-letter */
+ struct class_rule *rules; /* Linked list of character class rules */
+ char *dictionary; /* Base path to CrackLib dictionary */
+ long cracklib_maxlen; /* Longer passwords skip CrackLib checks */
+ bool have_cdb; /* Whether we have a CDB dictionary */
+ int cdb_fd; /* File descriptor of CDB dictionary */
#ifdef HAVE_CDB_H
- struct cdb cdb; /* Open CDB dictionary data */
+ struct cdb cdb; /* Open CDB dictionary data */
#endif
#ifdef HAVE_SQLITE3_H
sqlite3 *sqlite; /* Open SQLite database handle */
const char *password);
void strength_close_cdb(krb5_context, krb5_pwqual_moddata);
#else
-# define strength_check_cdb(c, d, p) 0
-# define strength_close_cdb(c, d) /* empty */
+# define strength_check_cdb(c, d, p) 0
+# define strength_close_cdb(c, d) /* empty */
#endif
/*
krb5_error_code strength_check_cracklib(krb5_context, krb5_pwqual_moddata,
const char *password);
#else
-# define strength_check_cracklib(c, d, p) 0
+# define strength_check_cracklib(c, d, p) 0
#endif
/*
const char *password);
void strength_close_sqlite(krb5_context, krb5_pwqual_moddata);
#else
-# define strength_check_sqlite(c, d, p) 0
-# define strength_close_sqlite(c, d) /* empty */
+# define strength_check_sqlite(c, d, p) 0
+# define strength_close_sqlite(c, d) /* empty */
#endif
/* Check whether the password statisfies character class requirements. */
* Manage vectors, which are counted lists of strings. The functions that
* return a boolean return false if memory allocation fails.
*/
-struct vector *strength_vector_new(void)
- __attribute__((__malloc__));
+struct vector *strength_vector_new(void) __attribute__((__malloc__));
bool strength_vector_add(struct vector *, const char *string)
__attribute__((__nonnull__));
void strength_vector_free(struct vector *);
#include <errno.h>
#ifdef HAVE_KRB5_PWQUAL_PLUGIN_H
-# include <krb5/pwqual_plugin.h>
+# include <krb5/pwqual_plugin.h>
#endif
#include <plugin/internal.h>
*
* Written by Russ Allbery <eagle@eyrie.org>
* Based on work by David Mazières
- * Copyright 2016 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2016, 2020 Russ Allbery <eagle@eyrie.org>
* Copyright 2014
* The Board of Trustees of the Leland Stanford Junior University
*
#include <portable/system.h>
#ifdef HAVE_SQLITE3_H
-# include <sqlite3.h>
+# include <sqlite3.h>
#endif
#include <plugin/internal.h>
* prefix and the prefix with the last character incremented; the suffix query
* gets the same, but the suffix should be reversed.
*/
+/* clang-format off */
#define PREFIX_QUERY \
"SELECT password, drowssap FROM passwords WHERE password BETWEEN ? AND ?;"
#define SUFFIX_QUERY \
"SELECT password, drowssap FROM passwords WHERE drowssap BETWEEN ? AND ?;"
+/* clang-format on */
/*
if (path == NULL)
return 0;
free(path);
- krb5_set_error_message(ctx, KADM5_BAD_SERVER_PARAMS, "SQLite dictionary"
- " requested but not built with SQLite support");
+ krb5_set_error_message(ctx, KADM5_BAD_SERVER_PARAMS,
+ "SQLite dictionary requested but not built with"
+ " SQLite support");
return KADM5_BAD_SERVER_PARAMS;
}
#endif
ssize_t length;
char *message;
const char *errmsg;
-
+
errmsg = sqlite3_errmsg(data->sqlite);
va_start(args, format);
length = vasprintf(&message, format, args);
*
* To see why the sum of the prefix and suffix length can be longer than the
* length of the password when the password doesn't match the word, consider
- * the password "aaaa" and the word "aaaaaaaaa"
- * (The prefix length plus the
+ * the password "aaaa" and the word "aaaaaaaaa". The prefix length plus the
* suffix length may be greater than the length of the password if the
- * password is an exact match for the word or
+ * password is an exact match for the word or an initial or final substring of
+ * the word.
*/
static bool
match(size_t length, const char *password, const char *drowssap,
goto fail;
}
prefix[prefix_length - 1]++;
- status = sqlite3_bind_text(data->prefix_query, 2, prefix, prefix_length,
- NULL);
+ status =
+ sqlite3_bind_text(data->prefix_query, 2, prefix, prefix_length, NULL);
if (status != SQLITE_OK) {
code = error_sqlite(ctx, data, "cannot bind prefix end");
goto fail;
*/
struct vector *
strength_vector_split_multi(const char *string, const char *seps,
- struct vector *vector)
+ struct vector *vector)
{
const char *p, *start;
size_t i, count;
for (start = string, p = string, i = 0; *p != '\0'; p++)
if (strchr(seps, *p) != NULL) {
if (start != p) {
- vector->strings[i] = strndup(start, (size_t) (p - start));
+ vector->strings[i] = strndup(start, (size_t)(p - start));
if (vector->strings[i] == NULL)
goto fail;
i++;
/* If there is anything left in the string, we have one more component. */
if (start != p) {
- vector->strings[i] = strndup(start, (size_t) (p - start));
+ vector->strings[i] = strndup(start, (size_t)(p - start));
if (vector->strings[i] == NULL)
goto fail;
vector->count++;
* with the system versions.
*/
#if TESTING
-# undef asprintf
-# undef vasprintf
-# define asprintf test_asprintf
-# define vasprintf test_vasprintf
+# undef asprintf
+# undef vasprintf
+# define asprintf test_asprintf
+# define vasprintf test_vasprintf
int test_asprintf(char **, const char *, ...)
__attribute__((__format__(printf, 2, 3)));
int test_vasprintf(char **, const char *, va_list)
#include <kadm5/admin.h>
#ifdef HAVE_KADM5_KADM5_ERR_H
-# include <kadm5/kadm5_err.h>
+# include <kadm5/kadm5_err.h>
#else
-# include <kadm5/kadm_err.h>
+# include <kadm5/kadm_err.h>
#endif
/*
* general just in case.)
*/
#ifndef KADM5_API_VERSION
-# ifdef KADM5_API_VERSION_3
-# define KADM5_API_VERSION KADM5_API_VERSION_3
-# else
-# define KADM5_API_VERSION KADM5_API_VERSION_2
-# endif
+# ifdef KADM5_API_VERSION_3
+# define KADM5_API_VERSION KADM5_API_VERSION_3
+# else
+# define KADM5_API_VERSION KADM5_API_VERSION_2
+# endif
#endif
/* Heimdal doesn't define KADM5_PASS_Q_GENERIC. */
#ifndef KADM5_PASS_Q_GENERIC
-# define KADM5_PASS_Q_GENERIC KADM5_PASS_Q_DICT
+# define KADM5_PASS_Q_GENERIC KADM5_PASS_Q_DICT
#endif
/* Heimdal doesn't define KADM5_MISSING_KRB5_CONF_PARAMS. */
#ifndef KADM5_MISSING_KRB5_CONF_PARAMS
-# define KADM5_MISSING_KRB5_CONF_PARAMS KADM5_MISSING_CONF_PARAMS
+# define KADM5_MISSING_KRB5_CONF_PARAMS KADM5_MISSING_CONF_PARAMS
#endif
#endif /* !PORTABLE_KADMIN_H */
/* Figure out what header files to include for error reporting. */
#if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) && !defined(HAVE_KRB5_GET_ERR_TEXT)
-# if !defined(HAVE_KRB5_GET_ERROR_STRING)
-# if defined(HAVE_IBM_SVC_KRB5_SVC_H)
-# include <ibm_svc/krb5_svc.h>
-# elif defined(HAVE_ET_COM_ERR_H)
-# include <et/com_err.h>
-# elif defined(HAVE_KERBEROSV5_COM_ERR_H)
-# include <kerberosv5/com_err.h>
-# else
-# include <com_err.h>
-# endif
-# endif
+# if !defined(HAVE_KRB5_GET_ERROR_STRING)
+# if defined(HAVE_IBM_SVC_KRB5_SVC_H)
+# include <ibm_svc/krb5_svc.h>
+# elif defined(HAVE_ET_COM_ERR_H)
+# include <et/com_err.h>
+# elif defined(HAVE_KERBEROSV5_COM_ERR_H)
+# include <kerberosv5/com_err.h>
+# else
+# include <com_err.h>
+# endif
+# endif
#endif
/* Used for unused parameters to silence gcc warnings. */
{
const char *msg = NULL;
-# if defined(HAVE_KRB5_GET_ERROR_STRING)
+# if defined(HAVE_KRB5_GET_ERROR_STRING)
msg = krb5_get_error_string(ctx);
-# elif defined(HAVE_KRB5_GET_ERR_TEXT)
+# elif defined(HAVE_KRB5_GET_ERR_TEXT)
msg = krb5_get_err_text(ctx, code);
-# elif defined(HAVE_KRB5_SVC_GET_MSG)
+# elif defined(HAVE_KRB5_SVC_GET_MSG)
krb5_svc_get_msg(code, (char **) &msg);
-# else
+# else
msg = error_message(code);
-# endif
+# endif
if (msg == NULL)
return error_unknown;
else
{
if (msg == error_unknown)
return;
-# if defined(HAVE_KRB5_GET_ERROR_STRING)
+# if defined(HAVE_KRB5_GET_ERROR_STRING)
krb5_free_error_string(ctx, (char *) msg);
-# elif defined(HAVE_KRB5_SVC_GET_MSG)
+# elif defined(HAVE_KRB5_SVC_GET_MSG)
krb5_free_string(ctx, (char *) msg);
-# endif
+# endif
}
#endif /* !HAVE_KRB5_FREE_ERROR_MESSAGE */
* stripped-down version of config.h with a different name.
*/
#ifndef CONFIG_H_INCLUDED
-# include <config.h>
+# include <config.h>
#endif
#include <portable/macros.h>
#if defined(HAVE_KRB5_H)
-# include <krb5.h>
+# include <krb5.h>
#elif defined(HAVE_KERBEROSV5_KRB5_H)
-# include <kerberosv5/krb5.h>
+# include <kerberosv5/krb5.h>
#else
-# include <krb5/krb5.h>
+# include <krb5/krb5.h>
#endif
#include <stdlib.h>
* Kerberos library. Use krb5_xfree instead.
*/
#ifndef HAVE_KRB5_FREE_DEFAULT_REALM
-# define krb5_free_default_realm(c, r) krb5_xfree(r)
+# define krb5_free_default_realm(c, r) krb5_xfree(r)
#endif
/*
* really do about it.
*/
#ifndef HAVE_KRB5_FREE_STRING
-# ifdef HAVE_KRB5_XFREE
-# define krb5_free_string(c, s) krb5_xfree(s)
-# else
-# define krb5_free_string(c, s) free(s)
-# endif
+# ifdef HAVE_KRB5_XFREE
+# define krb5_free_string(c, s) krb5_xfree(s)
+# else
+# define krb5_free_string(c, s) free(s)
+# endif
#endif
/* Heimdal: krb5_xfree, MIT: krb5_free_unparsed_name. */
#ifdef HAVE_KRB5_XFREE
-# define krb5_free_unparsed_name(c, p) krb5_xfree(p)
+# define krb5_free_unparsed_name(c, p) krb5_xfree(p)
#endif
/*
krb5_get_init_creds_opt **);
#endif
#ifdef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE
-# ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS
-# define krb5_get_init_creds_opt_free(c, o) krb5_get_init_creds_opt_free(o)
-# endif
+# ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS
+# define krb5_get_init_creds_opt_free(c, o) \
+ krb5_get_init_creds_opt_free(o)
+# endif
#else
-# define krb5_get_init_creds_opt_free(c, o) free(o)
+# define krb5_get_init_creds_opt_free(c, o) free(o)
#endif
/* Heimdal-specific. */
#ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_SET_DEFAULT_FLAGS
-# define krb5_get_init_creds_opt_set_default_flags(c, p, r, o) /* empty */
+# define krb5_get_init_creds_opt_set_default_flags(c, p, r, o) /* empty */
#endif
/*
* present in older MIT Kerberos libraries but not prototyped.
*/
#if !HAVE_DECL_KRB5_KT_FREE_ENTRY
-# define krb5_kt_free_entry(c, e) krb5_free_keytab_entry_contents((c), (e))
+# define krb5_kt_free_entry(c, e) krb5_free_keytab_entry_contents((c), (e))
#endif
/*
* (to avoid confusion with other macros).
*/
#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(spec) /* empty */
-# endif
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __attribute__(spec) /* empty */
+# endif
#endif
/*
* variadic macro support.
*/
#if !defined(__attribute__) && !defined(__alloc_size__)
-# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \
- && !defined(__clang__)
-# define __alloc_size__(spec, args...) /* empty */
-# endif
+# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \
+ && !defined(__clang__)
+# define __alloc_size__(spec, args...) /* empty */
+# endif
#endif
/*
* compilation context, but there's no push and pop available.
*/
#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
-# pragma GCC diagnostic ignored "-Wattributes"
+# pragma GCC diagnostic ignored "-Wattributes"
#endif
/*
#undef BEGIN_DECLS
#undef END_DECLS
#ifdef __cplusplus
-# define BEGIN_DECLS extern "C" {
-# define END_DECLS }
+# define BEGIN_DECLS extern "C" {
+# define END_DECLS }
#else
-# define BEGIN_DECLS /* empty */
-# define END_DECLS /* empty */
+# define BEGIN_DECLS /* empty */
+# define END_DECLS /* empty */
#endif
#endif /* !PORTABLE_MACROS_H */
#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
+# include <sys/time.h>
#endif
#include <time.h>
* another name.
*/
#if TESTING
-# undef mkstemp
-# define mkstemp test_mkstemp
+# undef mkstemp
+# define mkstemp test_mkstemp
int test_mkstemp(char *);
#endif
* it to another name.
*/
#if TESTING
-# undef reallocarray
-# define reallocarray test_reallocarray
+# undef reallocarray
+# define reallocarray test_reallocarray
void *test_reallocarray(void *, size_t, size_t);
#endif
* stripped-down version of config.h with a different name.
*/
#ifndef CONFIG_H_INCLUDED
-# include <config.h>
+# include <config.h>
#endif
#if HAVE_STDBOOL_H
-# include <stdbool.h>
+# include <stdbool.h>
#else
-# if HAVE__BOOL
-# define bool _Bool
-# else
-# ifdef __cplusplus
+# if HAVE__BOOL
+# define bool _Bool
+# else
+# ifdef __cplusplus
typedef bool _Bool;
-# elif _WIN32
-# include <windef.h>
-# define bool BOOL
-# else
+# elif _WIN32
+# include <windef.h>
+# define bool BOOL
+# else
typedef unsigned char _Bool;
-# define bool _Bool
-# endif
-# endif
-# define false 0
-# define true 1
-# define __bool_true_false_are_defined 1
+# define bool _Bool
+# endif
+# endif
+# define false 0
+# define true 1
+# define __bool_true_false_are_defined 1
#endif
/*
* fail. Only of interest for programs that also include Perl headers.
*/
#ifndef HAS_BOOL
-# define HAS_BOOL 1
+# define HAS_BOOL 1
#endif
#endif /* !PORTABLE_STDBOOL_H */
* with the system versions.
*/
#if TESTING
-# undef strndup
-# define strndup test_strndup
+# undef strndup
+# define strndup test_strndup
char *test_strndup(const char *, size_t);
#endif
}
/* Don't assume that the source string is nul-terminated. */
- for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
+ for (p = s; (size_t)(p - s) < n && *p != '\0'; p++)
;
length = p - s;
copy = malloc(length + 1);
/* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */
#if HAVE_INTTYPES_H
-# include <inttypes.h>
+# include <inttypes.h>
#endif
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
#if HAVE_STDINT_H
-# include <stdint.h>
+# include <stdint.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_STRINGS_H
-# include <strings.h>
+# include <strings.h>
#endif
#include <sys/types.h>
#if HAVE_UNISTD_H
-# include <unistd.h>
+# include <unistd.h>
#endif
/* SCO OpenServer gets int32_t from here. */
#if HAVE_SYS_BITYPES_H
-# include <sys/bitypes.h>
+# include <sys/bitypes.h>
#endif
/* Get the bool type. */
/* Windows provides snprintf under a different name. */
#ifdef _WIN32
-# define snprintf _snprintf
+# define snprintf _snprintf
#endif
/* Windows does not define ssize_t. */
* been defined, all the rest almost certainly have.
*/
#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
-# define STDOUT_FILENO 1
-# define STDERR_FILENO 2
+# define STDIN_FILENO 0
+# define STDOUT_FILENO 1
+# define STDERR_FILENO 2
#endif
/*
* Autoconf manual, memcpy is a generally portable fallback.
*/
#ifndef va_copy
-# ifdef __va_copy
-# define va_copy(d, s) __va_copy((d), (s))
-# else
-# define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
-# endif
+# ifdef __va_copy
+# define va_copy(d, s) __va_copy((d), (s))
+# else
+# define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
+# endif
#endif
BEGIN_DECLS
#include <dlfcn.h>
#include <errno.h>
#ifdef HAVE_KADM5_KADM5_PWCHECK_H
-# include <kadm5/kadm5-pwcheck.h>
+# include <kadm5/kadm5-pwcheck.h>
#endif
#include <tests/tap/basic.h>
for (i = 0; i < ARRAY_SIZE(principal_tests); i++)
is_password_test(verifier, &principal_tests[i]);
-#ifdef HAVE_CRACKLIB
+# ifdef HAVE_CRACKLIB
/* Add CrackLib tests. */
setup_argv[3] = (char *) "password_dictionary";
/* Free the memory allocated for the CrackLib test. */
free(setup_argv[4]);
-#else
+# else
/* Otherwise, mark the CrackLib tests as skipped. */
count = ARRAY_SIZE(cracklib_tests) + ARRAY_SIZE(length_tests);
skip_block(count * 2, "not built with CDB support");
-#endif /* !HAVE_CRACKLIB */
+# endif /* !HAVE_CRACKLIB */
/* Add simple character class restrictions. */
setup_argv[3] = (char *) "minimum_different";
for (i = 0; i < ARRAY_SIZE(length_tests); i++)
is_password_test(verifier, &length_tests[i]);
-#ifdef HAVE_CDB
+# ifdef HAVE_CDB
/* If built with CDB, set up krb5.conf to use a CDB dictionary instead. */
setup_argv[3] = (char *) "password_dictionary_cdb";
for (i = 0; i < ARRAY_SIZE(principal_tests); i++)
is_password_test(verifier, &principal_tests[i]);
-#else /* !HAVE_CDB */
+# else /* !HAVE_CDB */
/* Otherwise, mark the CDB tests as skipped. */
count = ARRAY_SIZE(cdb_tests) + ARRAY_SIZE(principal_tests);
skip_block(count * 2, "not built with CDB support");
-#endif /* !HAVE_CDB */
+# endif /* !HAVE_CDB */
-#ifdef HAVE_SQLITE
+# ifdef HAVE_SQLITE
/*
* If built with SQLite, set up krb5.conf to use a SQLite dictionary
for (i = 0; i < ARRAY_SIZE(principal_tests); i++)
is_password_test(verifier, &principal_tests[i]);
-#else /* !HAVE_SQLITE */
+# else /* !HAVE_SQLITE */
/* Otherwise, mark the SQLite tests as skipped. */
count = ARRAY_SIZE(sqlite_tests) + ARRAY_SIZE(principal_tests);
skip_block(count * 2, "not built with SQLite support");
-#endif /* !HAVE_SQLITE */
+# endif /* !HAVE_SQLITE */
/* Manually clean up after the results of make-krb5-conf. */
basprintf(&path, "%s/krb5.conf", tmpdir);
* Test for the MIT Kerberos shared module API.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2017, 2020 Russ Allbery <eagle@eyrie.org>
* Copyright 2010, 2013, 2014
* The Board of Trustees of the Leland Stanford Junior University
*
#include <dlfcn.h>
#include <errno.h>
#ifdef HAVE_KRB5_PWQUAL_PLUGIN_H
-# include <krb5/pwqual_plugin.h>
+# include <krb5/pwqual_plugin.h>
#endif
#include <tests/tap/basic.h>
{
char *path, *dictionary, *krb5_config, *krb5_config_empty, *tmpdir;
char *setup_argv[12];
- const char*build;
+ const char *build;
size_t i, count;
krb5_context ctx;
krb5_pwqual_vtable vtable;
for (i = 0; i < ARRAY_SIZE(principal_tests); i++)
is_password_test(ctx, vtable, data, &principal_tests[i]);
+# ifdef HAVE_CRACKLIB
/* Run the CrackLib tests if CrackLib is available, otherwise skip them. */
-#ifdef HAVE_CRACKLIB
for (i = 0; i < ARRAY_SIZE(cracklib_tests); i++)
is_password_test(ctx, vtable, data, &cracklib_tests[i]);
-#else
+# else
count = ARRAY_SIZE(cracklib_tests);
skip_block(count * 2, "not built with CrackLib support");
-#endif
+# endif
/* Close that initialization of the plugin and destroy that context. */
vtable->close(ctx, data);
putenv(krb5_config);
free(krb5_config_empty);
-#ifdef HAVE_CRACKLIB
+# ifdef HAVE_CRACKLIB
/* Add CrackLib configuration. */
setup_argv[3] = (char *) "password_dictionary";
is_password_test(ctx, vtable, data, &length_tests[i]);
vtable->close(ctx, data);
-#else
+# else
/* Otherwise mark the CrackLib tests as skipped. */
count = ARRAY_SIZE(cracklib_tests) + ARRAY_SIZE(length_tests);
skip_block(count * 2 + 1, "not built with CrackLib support");
-#endif /* !HAVE_CRACKLIB */
+# endif /* !HAVE_CRACKLIB */
/* Switch to simple character class configuration in krb5.conf. */
setup_argv[3] = (char *) "minimum_different";
is_password_test(ctx, vtable, data, &length_tests[i]);
vtable->close(ctx, data);
-#ifdef HAVE_CDB
+# ifdef HAVE_CDB
/* If built with CDB, set up krb5.conf to use a CDB dictionary instead. */
test_file_path_free(dictionary);
is_password_test(ctx, vtable, data, &principal_tests[i]);
vtable->close(ctx, data);
-#else /* !HAVE_CDB */
+# else /* !HAVE_CDB */
/* Otherwise, mark the CDB tests as skipped. */
count = ARRAY_SIZE(cdb_tests) + ARRAY_SIZE(principal_tests);
skip_block(count * 2 + 1, "not built with CDB support");
-#endif /* !HAVE_CDB */
+# endif /* !HAVE_CDB */
-#ifdef HAVE_SQLITE
+# ifdef HAVE_SQLITE
/*
* If built with SQLite, set up krb5.conf to use a SQLite dictionary
is_password_test(ctx, vtable, data, &principal_tests[i]);
vtable->close(ctx, data);
-#else /* !HAVE_SQLITE */
+# else /* !HAVE_SQLITE */
/* Otherwise, mark the SQLite tests as skipped. */
count = ARRAY_SIZE(sqlite_tests) + ARRAY_SIZE(principal_tests);
skip_block(count * 2 + 1, "not built with SQLite support");
-#endif /* !HAVE_SQLITE */
+# endif /* !HAVE_SQLITE */
/* Manually clean up after the results of make-krb5-conf. */
basprintf(&path, "%s/krb5.conf", tmpdir);
* formats for easy testing.
*/
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2) || defined(__clang__)
-# pragma GCC diagnostic ignored "-Wformat-nonliteral"
+# pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
/*
static const char string[] = "abcdefghijklmnopqrstuvwxyz0123456789";
static const char *const fp_formats[] = {
- "%-1.5f", "%1.5f", "%31.9f", "%10.5f", "% 10.5f", "%+22.9f",
- "%+4.9f", "%01.3f", "%3.1f", "%3.2f", "%.0f", "%.1f",
- "%f",
+ "%-1.5f", "%1.5f", "%31.9f", "%10.5f", "% 10.5f", "%+22.9f", "%+4.9f",
+ "%01.3f", "%3.1f", "%3.2f", "%.0f", "%.1f", "%f",
- /* %e and %g formats aren't really implemented yet. */
+/* %e and %g formats aren't really implemented yet. */
#if 0
"%-1.5e", "%1.5e", "%31.9e", "%10.5e", "% 10.5e", "%+22.9e",
"%+4.9e", "%01.3e", "%3.1e", "%3.2e", "%.0e", "%.1e",
"%+4.9g", "%01.3g", "%3.1g", "%3.2g", "%.0g", "%.1g",
"%g",
#endif
- NULL
-};
+ NULL};
static const char *const int_formats[] = {
- "%-1.5d", "%1.5d", "%31.9d", "%5.5d", "%10.5d", "% 10.5d",
- "%+22.30d", "%01.3d", "%4d", "%d", "%ld", NULL
-};
+ "%-1.5d", "%1.5d", "%31.9d", "%5.5d", "%10.5d", "% 10.5d",
+ "%+22.30d", "%01.3d", "%4d", "%d", "%ld", NULL};
static const char *const uint_formats[] = {
- "%-1.5lu", "%1.5lu", "%31.9lu", "%5.5lu", "%10.5lu", "% 10.5lu",
- "%+6.30lu", "%01.3lu", "%4lu", "%lu", "%4lx", "%4lX",
- "%01.3lx", "%1lo", NULL
-};
+ "%-1.5lu", "%1.5lu", "%31.9lu", "%5.5lu", "%10.5lu",
+ "% 10.5lu", "%+6.30lu", "%01.3lu", "%4lu", "%lu",
+ "%4lx", "%4lX", "%01.3lx", "%1lo", NULL};
static const char *const llong_formats[] = {
- "%lld", "%-1.5lld", "%1.5lld", "%123.9lld", "%5.5lld",
- "%10.5lld", "% 10.5lld", "%+22.33lld", "%01.3lld", "%4lld",
- NULL
-};
+ "%lld", "%-1.5lld", "%1.5lld", "%123.9lld", "%5.5lld", "%10.5lld",
+ "% 10.5lld", "%+22.33lld", "%01.3lld", "%4lld", NULL};
static const char *const ullong_formats[] = {
- "%llu", "%-1.5llu", "%1.5llu", "%123.9llu", "%5.5llu",
- "%10.5llu", "% 10.5llu", "%+22.33llu", "%01.3llu", "%4llu",
- "%llx", "%llo", NULL
-};
-
-static const double fp_nums[] = {
- -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996, 0.9996, 1.996,
- 4.136, 0.1, 0.01, 0.001, 10.1, 0
-};
-static long int_nums[] = {
- -1, 134, 91340, 341, 0203, 0
-};
+ "%llu", "%-1.5llu", "%1.5llu", "%123.9llu", "%5.5llu",
+ "%10.5llu", "% 10.5llu", "%+22.33llu", "%01.3llu", "%4llu",
+ "%llx", "%llo", NULL};
+
+static const double fp_nums[] = {-1.5, 134.21, 91340.2, 341.1234, 0203.9,
+ 0.96, 0.996, 0.9996, 1.996, 4.136,
+ 0.1, 0.01, 0.001, 10.1, 0};
+static long int_nums[] = {-1, 134, 91340, 341, 0203, 0};
static unsigned long uint_nums[] = {
- (unsigned long) -1, 134, 91340, 341, 0203, 0
-};
-static long long llong_nums[] = {
- ~(long long) 0, /* All-1 bit pattern. */
- (~(unsigned long long) 0) >> 1, /* Largest signed long long. */
- -150, 134, 91340, 341,
- 0
-};
+ (unsigned long) -1, 134, 91340, 341, 0203, 0};
+static long long llong_nums[] = {~(long long) 0, /* All-1 bit pattern. */
+ (~(unsigned long long) 0)
+ >> 1, /* Largest signed long long. */
+ -150,
+ 134,
+ 91340,
+ 341,
+ 0};
static unsigned long long ullong_nums[] = {
- ~(unsigned long long) 0, /* All-1 bit pattern. */
- (~(unsigned long long) 0) >> 1, /* Largest signed long long. */
- 134, 91340, 341,
- 0
-};
+ ~(unsigned long long) 0, /* All-1 bit pattern. */
+ (~(unsigned long long) 0) >> 1, /* Largest signed long long. */
+ 134,
+ 91340,
+ 341,
+ 0};
static void
-test_format(bool trunc, const char *expected, int count,
- const char *format, ...)
+test_format(bool trunc, const char *expected, int count, const char *format,
+ ...)
{
char buf[128];
int result;
long lcount;
char lgbuf[128];
- plan(8 +
- (18 + (ARRAY_SIZE(fp_formats) - 1) * ARRAY_SIZE(fp_nums)
- + (ARRAY_SIZE(int_formats) - 1) * ARRAY_SIZE(int_nums)
- + (ARRAY_SIZE(uint_formats) - 1) * ARRAY_SIZE(uint_nums)
- + (ARRAY_SIZE(llong_formats) - 1) * ARRAY_SIZE(llong_nums)
- + (ARRAY_SIZE(ullong_formats) - 1) * ARRAY_SIZE(ullong_nums)) * 2);
+ plan(8
+ + (18 + (ARRAY_SIZE(fp_formats) - 1) * ARRAY_SIZE(fp_nums)
+ + (ARRAY_SIZE(int_formats) - 1) * ARRAY_SIZE(int_nums)
+ + (ARRAY_SIZE(uint_formats) - 1) * ARRAY_SIZE(uint_nums)
+ + (ARRAY_SIZE(llong_formats) - 1) * ARRAY_SIZE(llong_nums)
+ + (ARRAY_SIZE(ullong_formats) - 1) * ARRAY_SIZE(ullong_nums))
+ * 2);
is_int(4, test_snprintf(NULL, 0, "%s", "abcd"), "simple string length");
is_int(2, test_snprintf(NULL, 0, "%d", 20), "number length");
string, -2.5);
test_format(true, "abcdefghij4444", 14, "%.10s%n%d", string, &count, 4444);
is_int(10, count, "correct output from %%n");
- test_format(true, "abcdefghijklmnopqrstuvwxyz01234", 36, "%n%s%ln",
- &count, string, &lcount);
+ test_format(true, "abcdefghijklmnopqrstuvwxyz01234", 36, "%n%s%ln", &count,
+ string, &lcount);
is_int(0, count, "correct output from two %%n");
is_int(31, lcount, "correct output from long %%ln");
test_format(true, "(null)", 6, "%s", NULL);
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
-*/
+ */
/* Required for fdopen(), getopt(), and putenv(). */
#if defined(__STRICT_ANSI__) || defined(PEDANTIC)
-# ifndef _XOPEN_SOURCE
-# define _XOPEN_SOURCE 500
-# endif
+# ifndef _XOPEN_SOURCE
+# define _XOPEN_SOURCE 500
+# endif
#endif
#include <ctype.h>
/* AIX 6.1 (and possibly later) doesn't have WCOREDUMP. */
#ifndef WCOREDUMP
-# define WCOREDUMP(status) ((unsigned)(status) & 0x80)
+# define WCOREDUMP(status) ((unsigned) (status) &0x80)
#endif
/*
* have.
*/
#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
-# define STDOUT_FILENO 1
-# define STDERR_FILENO 2
+# define STDIN_FILENO 0
+# define STDOUT_FILENO 1
+# define STDERR_FILENO 2
#endif
/*
* $(abs_top_builddir) respectively.
*/
#ifndef C_TAP_SOURCE
-# define C_TAP_SOURCE NULL
+# define C_TAP_SOURCE NULL
#endif
#ifndef C_TAP_BUILD
-# define C_TAP_BUILD NULL
+# define C_TAP_BUILD NULL
#endif
/* Test status codes. */
-enum test_status {
- TEST_FAIL,
- TEST_PASS,
- TEST_SKIP,
- TEST_INVALID
-};
+enum test_status { TEST_FAIL, TEST_PASS, TEST_SKIP, TEST_INVALID };
/* Really, just a boolean, but this is more self-documenting. */
-enum test_verbose {
- CONCISE = 0,
- VERBOSE = 1
-};
+enum test_verbose { CONCISE = 0, VERBOSE = 1 };
/* Indicates the state of our plan. */
enum plan_status {
- PLAN_INIT, /* Nothing seen yet. */
- PLAN_FIRST, /* Plan seen before any tests. */
- PLAN_PENDING, /* Test seen and no plan yet. */
- PLAN_FINAL /* Plan seen after some tests. */
+ PLAN_INIT, /* Nothing seen yet. */
+ PLAN_FIRST, /* Plan seen before any tests. */
+ PLAN_PENDING, /* Test seen and no plan yet. */
+ PLAN_FINAL /* Plan seen after some tests. */
};
/* Error exit statuses for test processes. */
-#define CHILDERR_DUP 100 /* Couldn't redirect stderr or stdout. */
-#define CHILDERR_EXEC 101 /* Couldn't exec child process. */
-#define CHILDERR_STDIN 102 /* Couldn't open stdin file. */
-#define CHILDERR_STDERR 103 /* Couldn't open stderr file. */
+#define CHILDERR_DUP 100 /* Couldn't redirect stderr or stdout. */
+#define CHILDERR_EXEC 101 /* Couldn't exec child process. */
+#define CHILDERR_STDIN 102 /* Couldn't open stdin file. */
+#define CHILDERR_STDERR 103 /* Couldn't open stderr file. */
/* Structure to hold data for a set of tests. */
struct testset {
- char *file; /* The file name of the test. */
- char *path; /* The path to the test program. */
- enum plan_status plan; /* The status of our plan. */
- unsigned long count; /* Expected count of tests. */
- unsigned long current; /* The last seen test number. */
- unsigned int length; /* The length of the last status message. */
- unsigned long passed; /* Count of passing tests. */
- unsigned long failed; /* Count of failing lists. */
- unsigned long skipped; /* Count of skipped tests (passed). */
- unsigned long allocated; /* The size of the results table. */
- enum test_status *results; /* Table of results by test number. */
- unsigned int aborted; /* Whether the set was aborted. */
- int reported; /* Whether the results were reported. */
- int status; /* The exit status of the test. */
- unsigned int all_skipped; /* Whether all tests were skipped. */
- char *reason; /* Why all tests were skipped. */
+ char *file; /* The file name of the test. */
+ char *path; /* The path to the test program. */
+ enum plan_status plan; /* The status of our plan. */
+ unsigned long count; /* Expected count of tests. */
+ unsigned long current; /* The last seen test number. */
+ unsigned int length; /* The length of the last status message. */
+ unsigned long passed; /* Count of passing tests. */
+ unsigned long failed; /* Count of failing lists. */
+ unsigned long skipped; /* Count of skipped tests (passed). */
+ unsigned long allocated; /* The size of the results table. */
+ enum test_status *results; /* Table of results by test number. */
+ unsigned int aborted; /* Whether the set was aborted. */
+ int reported; /* Whether the results were reported. */
+ int status; /* The exit status of the test. */
+ unsigned int all_skipped; /* Whether all tests were skipped. */
+ char *reason; /* Why all tests were skipped. */
};
/* Structure to hold a linked list of test sets. */
-------------------------- -------------- ---- ---- ------------------------";
/* Include the file name and line number in malloc failures. */
-#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
-#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
+#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
+#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
+#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
#define xreallocarray(p, n, size) \
x_reallocarray((p), (n), (size), __FILE__, __LINE__)
* (to avoid confusion with other macros).
*/
#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(spec) /* empty */
-# endif
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __attribute__(spec) /* empty */
+# endif
#endif
/*
* variadic macro support.
*/
#if !defined(__attribute__) && !defined(__alloc_size__)
-# if defined(__GNUC__) && !defined(__clang__)
-# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
-# define __alloc_size__(spec, args...) /* empty */
-# endif
-# endif
+# if defined(__GNUC__) && !defined(__clang__)
+# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
+# define __alloc_size__(spec, args...) /* empty */
+# endif
+# endif
#endif
/*
* compilation context, but there's no push and pop available.
*/
#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
-# pragma GCC diagnostic ignored "-Wattributes"
+# pragma GCC diagnostic ignored "-Wattributes"
#endif
/* Declare internal functions that benefit from compiler attributes. */
len = strlen(s) + 1;
p = malloc(len);
if (p == NULL)
- sysdie("failed to strdup %lu bytes at %s line %d",
- (unsigned long) len, file, line);
+ sysdie("failed to strdup %lu bytes at %s line %d", (unsigned long) len,
+ file, line);
memcpy(p, s, len);
return p;
}
static const char *
skip_whitespace(const char *p)
{
- while (isspace((unsigned char)(*p)))
+ while (isspace((unsigned char) (*p)))
p++;
return p;
}
* reported status.
*/
static void
-test_checkline(const char *line, struct testset *ts,
- enum test_verbose verbose)
+test_checkline(const char *line, struct testset *ts, enum test_verbose verbose)
{
enum test_status status = TEST_PASS;
const char *bail;
return;
/* If we haven't yet seen a plan, look for one. */
- if (ts->plan == PLAN_INIT && isdigit((unsigned char)(*line))) {
+ if (ts->plan == PLAN_INIT && isdigit((unsigned char) (*line))) {
if (!test_plan(line, ts, verbose))
return;
} else if (strncmp(line, "1..", 3) == 0) {
* Handle directives. We should probably do something more interesting
* with unexpected passes of todo tests.
*/
- while (isdigit((unsigned char)(*line)))
+ while (isdigit((unsigned char) (*line)))
line++;
line = skip_whitespace(line);
if (*line == '#') {
/* Good results. Increment our various counters. */
switch (status) {
- case TEST_PASS: ts->passed++; break;
- case TEST_FAIL: ts->failed++; break;
- case TEST_SKIP: ts->skipped++; break;
- case TEST_INVALID: break;
+ case TEST_PASS:
+ ts->passed++;
+ break;
+ case TEST_FAIL:
+ ts->failed++;
+ break;
+ case TEST_SKIP:
+ ts->skipped++;
+ break;
+ case TEST_INVALID:
+ break;
}
ts->current = current;
ts->results[current - 1] = status;
ts = fails->ts;
total = ts->count - ts->skipped;
printf("%-26.26s %4lu/%-4lu %3.0f%% %4lu ", ts->file, ts->failed,
- total, total ? (ts->failed * 100.0) / total : 0,
- ts->skipped);
+ total, total ? (ts->failed * 100.0) / total : 0, ts->skipped);
if (WIFEXITED(ts->status))
printf("%4d ", WEXITSTATUS(ts->status));
else
char *path = NULL;
const char *bases[3], *suffix, *base;
unsigned int i, j;
- const char *suffixes[3] = { "-t", ".t", "" };
+ const char *suffixes[3] = {"-t", ".t", ""};
/* Possible base directories. */
bases[0] = ".";
else
printf("Aborted %lu test sets", aborted);
printf(", passed %lu/%lu tests", passed, total);
- }
- else if (failed == 0)
+ } else if (failed == 0)
fputs("All tests successful", stdout);
else
printf("Failed %lu/%lu tests, %.2f%% okay", failed, total,
puts(".");
printf("Files=%u, Tests=%lu", count, total);
printf(", %.2f seconds", tv_diff(&end, &start));
- printf(" (%.2f usr + %.2f sys = %.2f CPU)\n",
- tv_seconds(&stats.ru_utime), tv_seconds(&stats.ru_stime),
+ printf(" (%.2f usr + %.2f sys = %.2f CPU)\n", tv_seconds(&stats.ru_utime),
+ tv_seconds(&stats.ru_stime),
tv_sum(&stats.ru_utime, &stats.ru_stime));
return (failed == 0 && aborted == 0);
}
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
-# include <direct.h>
+# include <direct.h>
#else
-# include <sys/stat.h>
+# include <sys/stat.h>
#endif
#include <sys/types.h>
#include <unistd.h>
/* Windows provides mkdir and rmdir under different names. */
#ifdef _WIN32
-# define mkdir(p, m) _mkdir(p)
-# define rmdir(p) _rmdir(p)
+# define mkdir(p, m) _mkdir(p)
+# define rmdir(p) _rmdir(p)
#endif
/*
* We can get the highest test count from testnum.
*/
static unsigned long _planned = 0;
-static unsigned long _failed = 0;
+static unsigned long _failed = 0;
/*
* Store the PID of the process that called plan() and only summarize
* print_desc, which has to be done in a macro. Assumes that format is the
* argument immediately before the variadic arguments.
*/
-#define PRINT_DESC(prefix, format) \
- do { \
- if (format != NULL) { \
- va_list args; \
- if (prefix != NULL) \
- printf("%s", prefix); \
- va_start(args, format); \
- vprintf(format, args); \
- va_end(args); \
- } \
+#define PRINT_DESC(prefix, format) \
+ do { \
+ if (format != NULL) { \
+ va_list args; \
+ if (prefix != NULL) \
+ printf("%s", prefix); \
+ va_start(args, format); \
+ vprintf(format, args); \
+ va_end(args); \
+ } \
} while (0)
p = calloc(n, size);
if (p == NULL)
- sysbail("failed to calloc %lu", (unsigned long)(n * size));
+ sysbail("failed to calloc %lu", (unsigned long) (n * size));
return p;
}
size_t length;
/* Don't assume that the source string is nul-terminated. */
- for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
+ for (p = s; (size_t)(p - s) < n && *p != '\0'; p++)
;
- length = (size_t) (p - s);
+ length = (size_t)(p - s);
copy = malloc(length + 1);
if (p == NULL)
sysbail("failed to strndup %lu bytes", (unsigned long) length);
{
char *base;
char *path = NULL;
- const char *envs[] = { "C_TAP_BUILD", "C_TAP_SOURCE", NULL };
+ const char *envs[] = {"C_TAP_BUILD", "C_TAP_SOURCE", NULL};
int i;
for (i = 0; envs[i] != NULL; i++) {
#ifndef TAP_BASIC_H
#define TAP_BASIC_H 1
+#include <stdarg.h> /* va_list */
+#include <stddef.h> /* size_t */
#include <tests/tap/macros.h>
-#include <stdarg.h> /* va_list */
-#include <stddef.h> /* size_t */
/*
* Used for iterating through arrays. ARRAY_SIZE returns the number of
* ARRAY_END returns a pointer to the element past the end (ISO C99 makes it
* legal to refer to such a pointer as long as it's never dereferenced).
*/
-#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
-#define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)])
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+#define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)])
BEGIN_DECLS
__attribute__((__format__(printf, 2, 3)));
int okv(int success, const char *format, va_list args)
__attribute__((__format__(printf, 2, 0)));
-void skip(const char *reason, ...)
- __attribute__((__format__(printf, 1, 2)));
+void skip(const char *reason, ...) __attribute__((__format__(printf, 1, 2)));
/*
* Report the same status on, or skip, the next count tests. ok_block()
* diag(). Nul characters are not supported in these files and will result in
* truncated output.
*/
-void diag_file_add(const char *file)
- __attribute__((__nonnull__));
-void diag_file_remove(const char *file)
- __attribute__((__nonnull__));
+void diag_file_add(const char *file) __attribute__((__nonnull__));
+void diag_file_remove(const char *file) __attribute__((__nonnull__));
/* Allocate memory, reporting a fatal error with bail on failure. */
void *bcalloc(size_t, size_t)
* Create a temporary directory relative to C_TAP_BUILD and return the path.
* The returned path should be freed with test_tmpdir_free().
*/
-char *test_tmpdir(void)
- __attribute__((__malloc__, __warn_unused_result__));
+char *test_tmpdir(void) __attribute__((__malloc__, __warn_unused_result__));
void test_tmpdir_free(char *path);
/*
* (the one that called plan or plan_lazy) and false otherwise.
*/
typedef void (*test_cleanup_func)(int, int);
-void test_cleanup_register(test_cleanup_func)
- __attribute__((__nonnull__));
+void test_cleanup_register(test_cleanup_func) __attribute__((__nonnull__));
END_DECLS
#include <config.h>
#ifdef HAVE_KRB5
-# include <portable/krb5.h>
+# include <portable/krb5.h>
#endif
#include <portable/system.h>
* to handle the possible patterns for kinit commands as an array.
*/
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2) || defined(__clang__)
-# pragma GCC diagnostic ignored "-Wformat-nonliteral"
+# pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
static void
kerberos_kinit(void)
{
- static const char * const format[] = {
+ static const char *const format[] = {
"kinit --no-afslog -k -t %s %s >/dev/null 2>&1 </dev/null",
"kinit -k -t %s %s >/dev/null 2>&1 </dev/null",
"kinit -t %s %s >/dev/null 2>&1 </dev/null",
- "kinit -k -K %s %s >/dev/null 2>&1 </dev/null"
- };
+ "kinit -k -K %s %s >/dev/null 2>&1 </dev/null"};
FILE *file;
char *path;
char principal[BUFSIZ], *command;
#include <tests/tap/macros.h>
#ifdef HAVE_KRB5
-# include <portable/krb5.h>
+# include <portable/krb5.h>
#endif
/* Holds the information parsed from the Kerberos test configuration. */
struct kerberos_config {
- char *keytab; /* Path to the keytab. */
- char *principal; /* Principal whose keys are in the keytab. */
- char *cache; /* Path to the Kerberos ticket cache. */
- char *userprinc; /* The fully-qualified principal. */
- char *username; /* The local (non-realm) part of principal. */
- char *realm; /* The realm part of the principal. */
- char *password; /* The password. */
- char *pkinit_principal; /* Principal for PKINIT authentication. */
- char *pkinit_cert; /* Path to certificates for PKINIT. */
+ char *keytab; /* Path to the keytab. */
+ char *principal; /* Principal whose keys are in the keytab. */
+ char *cache; /* Path to the Kerberos ticket cache. */
+ char *userprinc; /* The fully-qualified principal. */
+ char *username; /* The local (non-realm) part of principal. */
+ char *realm; /* The realm part of the principal. */
+ char *password; /* The password. */
+ char *pkinit_principal; /* Principal for PKINIT authentication. */
+ char *pkinit_cert; /* Path to certificates for PKINIT. */
};
/*
* tests require both keytab and password, but PKINIT is not required.
*/
enum kerberos_needs {
- TAP_KRB_NEEDS_NONE = 0x00,
- TAP_KRB_NEEDS_KEYTAB = 0x01,
+ TAP_KRB_NEEDS_NONE = 0x00,
+ TAP_KRB_NEEDS_KEYTAB = 0x01,
TAP_KRB_NEEDS_PASSWORD = 0x02,
- TAP_KRB_NEEDS_BOTH = 0x01 | 0x02,
- TAP_KRB_NEEDS_PKINIT = 0x04
+ TAP_KRB_NEEDS_BOTH = 0x01 | 0x02,
+ TAP_KRB_NEEDS_PKINIT = 0x04
};
BEGIN_DECLS
* the other attributes to work with GCC versions between 2.7 and 2.96.
*/
#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
-# define __attribute__(spec) /* empty */
-# endif
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
+# define __attribute__(spec) /* empty */
+# endif
#endif
/*
* variadic macro support.
*/
#if !defined(__attribute__) && !defined(__alloc_size__)
-# if defined(__GNUC__) && !defined(__clang__)
-# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
-# define __alloc_size__(spec, args...) /* empty */
-# endif
-# endif
+# if defined(__GNUC__) && !defined(__clang__)
+# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
+# define __alloc_size__(spec, args...) /* empty */
+# endif
+# endif
#endif
/* Suppress __warn_unused_result__ if gcc is too old. */
#if !defined(__attribute__) && !defined(__warn_unused_result__)
-# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
-# define __warn_unused_result__ /* empty */
-# endif
+# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
+# define __warn_unused_result__ /* empty */
+# endif
#endif
/*
* compilation context, but there's no push and pop available.
*/
#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
-# pragma GCC diagnostic ignored "-Wattributes"
+# pragma GCC diagnostic ignored "-Wattributes"
#endif
/* Used for unused parameters to silence gcc warnings. */
#undef BEGIN_DECLS
#undef END_DECLS
#ifdef __cplusplus
-# define BEGIN_DECLS extern "C" {
-# define END_DECLS }
+# define BEGIN_DECLS extern "C" {
+# define END_DECLS }
#else
-# define BEGIN_DECLS /* empty */
-# define END_DECLS /* empty */
+# define BEGIN_DECLS /* empty */
+# define END_DECLS /* empty */
#endif
#endif /* TAP_MACROS_H */
#include <fcntl.h>
#include <signal.h>
#ifdef HAVE_SYS_SELECT_H
-# include <sys/select.h>
+# include <sys/select.h>
#endif
#include <sys/stat.h>
#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
+# include <sys/time.h>
#endif
#include <sys/wait.h>
#include <time.h>
/* May be defined by the build system. */
#ifndef PATH_FAKEROOT
-# define PATH_FAKEROOT ""
+# define PATH_FAKEROOT ""
#endif
/* How long to wait for the process to start in seconds. */
* everything required to stop the process and clean up after it.
*/
struct process {
- pid_t pid; /* PID of child process */
- char *pidfile; /* PID file to delete on process stop */
- char *tmpdir; /* Temporary directory for log file */
- char *logfile; /* Log file of process output */
- bool is_child; /* Whether we can waitpid for process */
- struct process *next; /* Next process in global list */
+ pid_t pid; /* PID of child process */
+ char *pidfile; /* PID file to delete on process stop */
+ char *tmpdir; /* Temporary directory for log file */
+ char *logfile; /* Log file of process output */
+ bool is_child; /* Whether we can waitpid for process */
+ struct process *next; /* Next process in global list */
};
/*
* successfully, call bail, with the error message being the output from the
* program.
*/
-void run_setup(const char *const argv[])
- __attribute__((__nonnull__));
+void run_setup(const char *const argv[]) __attribute__((__nonnull__));
/*
* process_start starts a process in the background, returning an opaque data
#include <config.h>
#include <tests/tap/macros.h>
-#include <stdarg.h> /* va_list */
+#include <stdarg.h> /* va_list */
BEGIN_DECLS
#include <config.h>
#ifdef HAVE_KRB5
-# include <portable/krb5.h>
+# include <portable/krb5.h>
#endif
#include <portable/system.h>
#include <tests/tap/process.h>
#include <util/macros.h>
#ifdef HAVE_KRB5
-# include <util/messages-krb5.h>
+# include <util/messages-krb5.h>
#endif
#include <util/messages.h>
#include <util/xmalloc.h>
/*
* Test functions.
*/
-static void test1(void *data UNUSED) { warn("warning"); }
-static void test2(void *data UNUSED) { die("fatal"); }
-static void test3(void *data UNUSED) { errno = EPERM; syswarn("permissions"); }
-static void test4(void *data UNUSED) {
+static void
+test1(void *data UNUSED)
+{
+ warn("warning");
+}
+static void
+test2(void *data UNUSED)
+{
+ die("fatal");
+}
+static void
+test3(void *data UNUSED)
+{
+ errno = EPERM;
+ syswarn("permissions");
+}
+static void
+test4(void *data UNUSED)
+{
errno = EACCES;
sysdie("fatal access");
}
-static void test5(void *data UNUSED) {
+static void
+test5(void *data UNUSED)
+{
message_program_name = "test5";
warn("warning");
}
-static void test6(void *data UNUSED) {
+static void
+test6(void *data UNUSED)
+{
message_program_name = "test6";
die("fatal");
}
-static void test7(void *data UNUSED) {
+static void
+test7(void *data UNUSED)
+{
message_program_name = "test7";
errno = EPERM;
syswarn("perms %d", 7);
}
-static void test8(void *data UNUSED) {
+static void
+test8(void *data UNUSED)
+{
message_program_name = "test8";
errno = EACCES;
sysdie("%st%s", "fa", "al");
}
-static int return10(void) { return 10; }
+static int
+return10(void)
+{
+ return 10;
+}
-static void test9(void *data UNUSED) {
+static void
+test9(void *data UNUSED)
+{
message_fatal_cleanup = return10;
die("fatal");
}
-static void test10(void *data UNUSED) {
+static void
+test10(void *data UNUSED)
+{
message_program_name = 0;
message_fatal_cleanup = return10;
errno = EPERM;
sysdie("fatal perm");
}
-static void test11(void *data UNUSED) {
+static void
+test11(void *data UNUSED)
+{
message_program_name = "test11";
message_fatal_cleanup = return10;
errno = EPERM;
}
static void __attribute__((__format__(printf, 2, 0)))
-log_msg(size_t len, const char *format, va_list args, int error) {
+log_msg(size_t len, const char *format, va_list args, int error)
+{
fprintf(stderr, "%lu %d ", (unsigned long) len, error);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
}
-static void test12(void *data UNUSED) {
+static void
+test12(void *data UNUSED)
+{
message_handlers_warn(1, log_msg);
warn("warning");
}
-static void test13(void *data UNUSED) {
+static void
+test13(void *data UNUSED)
+{
message_handlers_die(1, log_msg);
die("fatal");
}
-static void test14(void *data UNUSED) {
+static void
+test14(void *data UNUSED)
+{
message_handlers_warn(2, log_msg, log_msg);
errno = EPERM;
syswarn("warning");
}
-static void test15(void *data UNUSED) {
+static void
+test15(void *data UNUSED)
+{
message_handlers_die(2, log_msg, log_msg);
message_fatal_cleanup = return10;
errno = EPERM;
sysdie("fatal");
}
-static void test16(void *data UNUSED) {
+static void
+test16(void *data UNUSED)
+{
message_handlers_warn(2, message_log_stderr, log_msg);
message_program_name = "test16";
errno = EPERM;
syswarn("warning");
}
-static void test17(void *data UNUSED) { notice("notice"); }
-static void test18(void *data UNUSED) {
+static void
+test17(void *data UNUSED)
+{
+ notice("notice");
+}
+static void
+test18(void *data UNUSED)
+{
message_program_name = "test18";
notice("notice");
}
-static void test19(void *data UNUSED) { debug("debug"); }
-static void test20(void *data UNUSED) {
+static void
+test19(void *data UNUSED)
+{
+ debug("debug");
+}
+static void
+test20(void *data UNUSED)
+{
message_handlers_notice(1, log_msg);
notice("foo");
}
-static void test21(void *data UNUSED) {
+static void
+test21(void *data UNUSED)
+{
message_handlers_debug(1, message_log_stdout);
message_program_name = "test23";
debug("baz");
}
-static void test22(void *data UNUSED) {
+static void
+test22(void *data UNUSED)
+{
message_handlers_die(0);
die("hi mom!");
}
-static void test23(void *data UNUSED) {
+static void
+test23(void *data UNUSED)
+{
message_handlers_warn(0);
warn("this is a test");
}
-static void test24(void *data UNUSED) {
+static void
+test24(void *data UNUSED)
+{
notice("first");
message_handlers_notice(0);
notice("second");
is_function_output(test20, NULL, 0, "3 0 foo\n", "test20");
is_function_output(test21, NULL, 0, "test23: baz\n", "test21");
- /* Make sure that it's possible to turn off a message type entirely. */
+ /* Make sure that it's possible to turn off a message type entirely. */
is_function_output(test22, NULL, 1, "", "test22");
is_function_output(test23, NULL, 0, "", "test23");
is_function_output(test24, NULL, 0, "first\nthird\n", "test24");
#include <ctype.h>
#include <errno.h>
#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
+# include <sys/time.h>
#endif
#include <time.h>
}
switch (code) {
- case 'c': exit(test_calloc(size) ? willfail : 1);
- case 'm': exit(test_malloc(size) ? willfail : 1);
- case 'r': exit(test_realloc(size) ? willfail : 1);
- case 'y': exit(test_reallocarray(4, size / 4) ? willfail : 1);
- case 's': exit(test_strdup(size) ? willfail : 1);
- case 'n': exit(test_strndup(size) ? willfail : 1);
- case 'a': exit(test_asprintf(size) ? willfail : 1);
- case 'v': exit(test_vasprintf(size) ? willfail : 1);
+ case 'c':
+ exit(test_calloc(size) ? willfail : 1);
+ case 'm':
+ exit(test_malloc(size) ? willfail : 1);
+ case 'r':
+ exit(test_realloc(size) ? willfail : 1);
+ case 'y':
+ exit(test_reallocarray(4, size / 4) ? willfail : 1);
+ case 's':
+ exit(test_strdup(size) ? willfail : 1);
+ case 'n':
+ exit(test_strndup(size) ? willfail : 1);
+ case 'a':
+ exit(test_asprintf(size) ? willfail : 1);
+ case 'v':
+ exit(test_vasprintf(size) ? willfail : 1);
default:
die("Unknown mode %c", argv[1][0]);
break;
#include <plugin/internal.h>
#include <util/macros.h>
-#include <util/messages.h>
#include <util/messages-krb5.h>
+#include <util/messages.h>
#include <util/xmalloc.h>
#include <portable/krb5.h>
#include <portable/system.h>
-#include <util/messages.h>
#include <util/messages-krb5.h>
+#include <util/messages.h>
#include <util/xmalloc.h>
#include <errno.h>
#ifdef HAVE_SYSLOG_H
-# include <syslog.h>
+# include <syslog.h>
#endif
#ifdef _WIN32
-# include <windows.h>
-# define LOG_DEBUG EVENTLOG_SUCCESS
-# define LOG_INFO EVENTLOG_INFORMATION_TYPE
-# define LOG_NOTICE EVENTLOG_INFORMATION_TYPE
-# define LOG_WARNING EVENTLOG_WARNING_TYPE
-# define LOG_ERR EVENTLOG_ERROR_TYPE
-# define LOG_CRIT EVENTLOG_ERROR_TYPE
+# include <windows.h>
+# define LOG_DEBUG EVENTLOG_SUCCESS
+# define LOG_INFO EVENTLOG_INFORMATION_TYPE
+# define LOG_NOTICE EVENTLOG_INFORMATION_TYPE
+# define LOG_WARNING EVENTLOG_WARNING_TYPE
+# define LOG_ERR EVENTLOG_ERROR_TYPE
+# define LOG_CRIT EVENTLOG_ERROR_TYPE
#endif
#include <util/macros.h>
#include <util/xmalloc.h>
/* The default handler lists. */
-static message_handler_func stdout_handlers[2] = {
- message_log_stdout, NULL
-};
-static message_handler_func stderr_handlers[2] = {
- message_log_stderr, NULL
-};
+static message_handler_func stdout_handlers[2] = {message_log_stdout, NULL};
+static message_handler_func stderr_handlers[2] = {message_log_stderr, NULL};
/* The list of logging functions currently in effect. */
-static message_handler_func *debug_handlers = NULL;
+static message_handler_func *debug_handlers = NULL;
static message_handler_func *notice_handlers = stdout_handlers;
-static message_handler_func *warn_handlers = stderr_handlers;
-static message_handler_func *die_handlers = stderr_handlers;
+static message_handler_func *warn_handlers = stderr_handlers;
+static message_handler_func *die_handlers = stderr_handlers;
/* If non-NULL, called before exit and its return value passed to exit. */
int (*message_fatal_cleanup)(void) = NULL;
* duplication since we can't assume variadic macros, but I can at least make
* it easier to write and keep them consistent.
*/
-#define HANDLER_FUNCTION(type) \
- void \
- message_handlers_ ## type(unsigned int count, ...) \
- { \
- va_list args; \
- \
- va_start(args, count); \
- message_handlers(& type ## _handlers, count, args); \
- va_end(args); \
+#define HANDLER_FUNCTION(type) \
+ void message_handlers_##type(unsigned int count, ...) \
+ { \
+ va_list args; \
+ \
+ va_start(args, count); \
+ message_handlers(&type##_handlers, count, args); \
+ va_end(args); \
}
HANDLER_FUNCTION(debug)
HANDLER_FUNCTION(notice)
CloseEventLog(eventlog);
}
}
-#else /* !_WIN32 */
+#else /* !_WIN32 */
if (err == 0)
syslog(pri, "%s", buffer);
else
* Do the same sort of wrapper to generate all of the separate syslog logging
* functions.
*/
-#define SYSLOG_FUNCTION(name, type) \
- void \
- message_log_syslog_ ## name(size_t l, const char *f, va_list a, int e) \
- { \
- message_log_syslog(LOG_ ## type, l, f, a, e); \
+#define SYSLOG_FUNCTION(name, type) \
+ void message_log_syslog_##name(size_t l, const char *f, va_list a, int e) \
+ { \
+ message_log_syslog(LOG_##type, l, f, a, e); \
}
-SYSLOG_FUNCTION(debug, DEBUG)
-SYSLOG_FUNCTION(info, INFO)
-SYSLOG_FUNCTION(notice, NOTICE)
+SYSLOG_FUNCTION(debug, DEBUG)
+SYSLOG_FUNCTION(info, INFO)
+SYSLOG_FUNCTION(notice, NOTICE)
SYSLOG_FUNCTION(warning, WARNING)
-SYSLOG_FUNCTION(err, ERR)
-SYSLOG_FUNCTION(crit, CRIT)
+SYSLOG_FUNCTION(err, ERR)
+SYSLOG_FUNCTION(crit, CRIT)
/*
xmalloc_fail(const char *function, size_t size, const char *file, int line)
{
if (size == 0)
- sysdie("failed to format output with %s at %s line %d", function,
- file, line);
+ sysdie("failed to format output with %s at %s line %d", function, file,
+ line);
else
sysdie("failed to %s %lu bytes at %s line %d", function,
(unsigned long) size, file, line);
char *copy;
/* Don't assume that the source string is nul-terminated. */
- for (p = s; (size_t) (p - s) < size && *p != '\0'; p++)
+ for (p = s; (size_t)(p - s) < size && *p != '\0'; p++)
;
length = p - s;
copy = malloc(length + 1);
}
va_end(args);
}
-#else /* !(HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS) */
+#else /* !(HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS) */
void
x_asprintf(char **strp, const char *fmt, ...)
{
* number information for debugging error messages without the user having to
* pass those in every time.
*/
-#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
-#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__)
-#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
-#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
-#define xvasprintf(p, f, a) x_vasprintf((p), (f), (a), __FILE__, __LINE__)
+#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
+#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
+#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__)
+#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
+#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
+#define xvasprintf(p, f, a) x_vasprintf((p), (f), (a), __FILE__, __LINE__)
#define xreallocarray(p, n, size) \
x_reallocarray((p), (n), (size), __FILE__, __LINE__)
* are supported.
*/
#ifdef HAVE_C99_VAMACROS
-# define xasprintf(p, f, ...) \
- x_asprintf((p), __FILE__, __LINE__, (f), __VA_ARGS__)
+# define xasprintf(p, f, ...) \
+ x_asprintf((p), __FILE__, __LINE__, (f), __VA_ARGS__)
#elif HAVE_GNU_VAMACROS
-# define xasprintf(p, f, args...) \
- x_asprintf((p), __FILE__, __LINE__, (f), args)
+# define xasprintf(p, f, args...) \
+ x_asprintf((p), __FILE__, __LINE__, (f), args)
#else
-# define xasprintf x_asprintf
+# define xasprintf x_asprintf
#endif
BEGIN_DECLS