From: Russ Allbery Date: Sat, 16 May 2020 19:26:56 +0000 (-0700) Subject: Reformat with clang-format X-Git-Tag: release/3.2~25 X-Git-Url: https://git.eyrie.org/?a=commitdiff_plain;h=657c8a6ee967108bdbaee29d3d311966b32c57c2;p=kerberos%2Fkrb5-strength.git Reformat with clang-format Import the clang-format rules and Makefile target from rra-c-util 8.2. Exclude the cracklib directory. Complete a mangled comment in the SQLite dictionary implementation. --- diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..993594c --- /dev/null +++ b/.clang-format @@ -0,0 +1,29 @@ +# 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 . +# +# Copyright 2020 Russ Allbery +# +# 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 +--- diff --git a/Makefile.am b/Makefile.am index 1636bef..454879f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,15 +1,15 @@ # Automake makefile for krb5-strength. # # Written by Russ Allbery -# Copyright 2016 Russ Allbery -# Copyright 2007, 2009, 2010, 2012, 2013, 2014 +# Copyright 2016, 2020 Russ Allbery +# 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 \ @@ -208,3 +208,11 @@ check-valgrind: $(check_PROGRAMS) tests/data/dictionary.pwd --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 diff --git a/plugin/cdb.c b/plugin/cdb.c index 92e08eb..d411917 100644 --- a/plugin/cdb.c +++ b/plugin/cdb.c @@ -21,7 +21,7 @@ #include #ifdef HAVE_CDB_H -# include +# include #endif #include #include @@ -47,8 +47,9 @@ strength_init_cdb(krb5_context ctx, krb5_pwqual_moddata data UNUSED) 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 @@ -57,21 +58,6 @@ strength_init_cdb(krb5_context ctx, krb5_pwqual_moddata data UNUSED) /* 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 @@ -130,6 +116,21 @@ strength_init_cdb(krb5_context ctx, krb5_pwqual_moddata data) } +/* + * 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, diff --git a/plugin/classes.c b/plugin/classes.c index bf9ef01..3bded46 100644 --- a/plugin/classes.c +++ b/plugin/classes.c @@ -48,10 +48,14 @@ analyze_password(const char *password, struct password_classes *classes) 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++; } diff --git a/plugin/config.c b/plugin/config.c index 0114740..147d3f6 100644 --- a/plugin/config.c +++ b/plugin/config.c @@ -187,8 +187,10 @@ parse_class(krb5_context ctx, const char *spec, struct class_rule **rule) 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; } } @@ -214,15 +216,16 @@ parse_class(krb5_context ctx, const char *spec, struct class_rule **rule) (*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; @@ -302,8 +305,7 @@ 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; diff --git a/plugin/cracklib.c b/plugin/cracklib.c index 8efa279..76d0261 100644 --- a/plugin/cracklib.c +++ b/plugin/cracklib.c @@ -24,11 +24,11 @@ /* When using the embedded CrackLib, we need to provide our own prototype. */ #ifdef HAVE_CRACKLIB -# ifdef HAVE_CRACK_H -# include -# else +# ifdef HAVE_CRACK_H +# include +# else extern const char *FascistCheck(const char *password, const char *dict); -# endif +# endif #endif @@ -49,8 +49,9 @@ strength_init_cracklib(krb5_context ctx, krb5_pwqual_moddata data UNUSED, 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 diff --git a/plugin/error.c b/plugin/error.c index ba51366..d509c05 100644 --- a/plugin/error.c +++ b/plugin/error.c @@ -50,20 +50,20 @@ set_error(krb5_context ctx, krb5_error_code code, const char *format, * 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) diff --git a/plugin/heimdal.c b/plugin/heimdal.c index 52c8197..aa0d29b 100644 --- a/plugin/heimdal.c +++ b/plugin/heimdal.c @@ -12,6 +12,7 @@ * instead. * * Written by Russ Allbery + * Copyright 2020 Russ Allbery * Copyright 2009, 2013 * The Board of Trustees of the Leland Stanford Junior University * @@ -24,7 +25,7 @@ #include #ifdef HAVE_KADM5_KADM5_PWCHECK_H -# include +# include #endif #include @@ -60,8 +61,8 @@ convert_error(krb5_context ctx, krb5_error_code code, const char *prefix, */ 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; @@ -107,9 +108,10 @@ done: } /* 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", @@ -117,5 +119,6 @@ struct kadm5_pw_policy_verifier kadm5_password_verifier = { "Russ Allbery", functions }; +/* clang-format on */ #endif /* HAVE_KRB5_REALM */ diff --git a/plugin/internal.h b/plugin/internal.h index eb58c65..1d3d4f4 100644 --- a/plugin/internal.h +++ b/plugin/internal.h @@ -18,34 +18,34 @@ #include #ifdef HAVE_CDB_H -# include +# include #endif #ifdef HAVE_SQLITE3_H -# include +# include #endif #include #ifdef HAVE_KRB5_PWQUAL_PLUGIN_H -# include +# include #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 @@ -78,17 +78,17 @@ struct vector { * 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 */ @@ -131,8 +131,8 @@ krb5_error_code strength_check_cdb(krb5_context, krb5_pwqual_moddata, 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 /* @@ -150,7 +150,7 @@ krb5_error_code strength_init_cracklib(krb5_context, krb5_pwqual_moddata, 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 /* @@ -168,8 +168,8 @@ krb5_error_code strength_check_sqlite(krb5_context, krb5_pwqual_moddata, 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. */ @@ -185,8 +185,7 @@ krb5_error_code strength_check_principal(krb5_context, krb5_pwqual_moddata, * 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 *); diff --git a/plugin/mit.c b/plugin/mit.c index d68ad57..0bacfb0 100644 --- a/plugin/mit.c +++ b/plugin/mit.c @@ -19,7 +19,7 @@ #include #ifdef HAVE_KRB5_PWQUAL_PLUGIN_H -# include +# include #endif #include diff --git a/plugin/sqlite.c b/plugin/sqlite.c index 92ceb5f..cb821ab 100644 --- a/plugin/sqlite.c +++ b/plugin/sqlite.c @@ -29,7 +29,7 @@ * * Written by Russ Allbery * Based on work by David Mazières - * Copyright 2016 Russ Allbery + * Copyright 2016, 2020 Russ Allbery * Copyright 2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -42,7 +42,7 @@ #include #ifdef HAVE_SQLITE3_H -# include +# include #endif #include @@ -54,10 +54,12 @@ * 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 */ /* @@ -76,8 +78,9 @@ strength_init_sqlite(krb5_context ctx, krb5_pwqual_moddata data UNUSED) 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 @@ -100,7 +103,7 @@ error_sqlite(krb5_context ctx, krb5_pwqual_moddata data, const char *format, ssize_t length; char *message; const char *errmsg; - + errmsg = sqlite3_errmsg(data->sqlite); va_start(args, format); length = vasprintf(&message, format, args); @@ -163,10 +166,10 @@ common_prefix_length(const char *a, const char *b) * * 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, @@ -295,8 +298,8 @@ strength_check_sqlite(krb5_context ctx, krb5_pwqual_moddata data, 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; diff --git a/plugin/vector.c b/plugin/vector.c index b7895be..d85518c 100644 --- a/plugin/vector.c +++ b/plugin/vector.c @@ -181,7 +181,7 @@ split_multi_count(const char *string, const char *seps) */ 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; @@ -206,7 +206,7 @@ strength_vector_split_multi(const char *string, const char *seps, 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++; @@ -217,7 +217,7 @@ strength_vector_split_multi(const char *string, const char *seps, /* 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++; diff --git a/portable/asprintf.c b/portable/asprintf.c index 83fdaa7..10641c6 100644 --- a/portable/asprintf.c +++ b/portable/asprintf.c @@ -29,10 +29,10 @@ * 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) diff --git a/portable/kadmin.h b/portable/kadmin.h index 6acb3a8..e3753d5 100644 --- a/portable/kadmin.h +++ b/portable/kadmin.h @@ -26,9 +26,9 @@ #include #ifdef HAVE_KADM5_KADM5_ERR_H -# include +# include #else -# include +# include #endif /* @@ -38,21 +38,21 @@ * 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 */ diff --git a/portable/krb5-extra.c b/portable/krb5-extra.c index 0199371..c36f288 100644 --- a/portable/krb5-extra.c +++ b/portable/krb5-extra.c @@ -29,17 +29,17 @@ /* 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 -# elif defined(HAVE_ET_COM_ERR_H) -# include -# elif defined(HAVE_KERBEROSV5_COM_ERR_H) -# include -# else -# include -# endif -# endif +# if !defined(HAVE_KRB5_GET_ERROR_STRING) +# if defined(HAVE_IBM_SVC_KRB5_SVC_H) +# include +# elif defined(HAVE_ET_COM_ERR_H) +# include +# elif defined(HAVE_KERBEROSV5_COM_ERR_H) +# include +# else +# include +# endif +# endif #endif /* Used for unused parameters to silence gcc warnings. */ @@ -67,15 +67,15 @@ krb5_get_error_message(krb5_context ctx UNUSED, krb5_error_code code UNUSED) { 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 @@ -98,11 +98,11 @@ krb5_free_error_message(krb5_context ctx UNUSED, const char *msg) { 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 */ diff --git a/portable/krb5.h b/portable/krb5.h index 5956272..2b82f0e 100644 --- a/portable/krb5.h +++ b/portable/krb5.h @@ -38,16 +38,16 @@ * stripped-down version of config.h with a different name. */ #ifndef CONFIG_H_INCLUDED -# include +# include #endif #include #if defined(HAVE_KRB5_H) -# include +# include #elif defined(HAVE_KERBEROSV5_KRB5_H) -# include +# include #else -# include +# include #endif #include @@ -62,7 +62,7 @@ BEGIN_DECLS * 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 /* @@ -73,16 +73,16 @@ BEGIN_DECLS * 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 /* @@ -111,16 +111,17 @@ krb5_error_code krb5_get_init_creds_opt_alloc(krb5_context, 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 /* @@ -129,7 +130,7 @@ krb5_error_code krb5_get_init_creds_opt_alloc(krb5_context, * 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 /* diff --git a/portable/macros.h b/portable/macros.h index 810a1f8..487ab5b 100644 --- a/portable/macros.h +++ b/portable/macros.h @@ -24,9 +24,9 @@ * (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 /* @@ -37,10 +37,10 @@ * 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 /* @@ -50,7 +50,7 @@ * 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 /* @@ -60,11 +60,11 @@ #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 */ diff --git a/portable/mkstemp.c b/portable/mkstemp.c index 2d42681..71bddad 100644 --- a/portable/mkstemp.c +++ b/portable/mkstemp.c @@ -24,7 +24,7 @@ #include #include #ifdef HAVE_SYS_TIME_H -# include +# include #endif #include @@ -34,8 +34,8 @@ * another name. */ #if TESTING -# undef mkstemp -# define mkstemp test_mkstemp +# undef mkstemp +# define mkstemp test_mkstemp int test_mkstemp(char *); #endif diff --git a/portable/reallocarray.c b/portable/reallocarray.c index bfa85e7..a8be45f 100644 --- a/portable/reallocarray.c +++ b/portable/reallocarray.c @@ -31,8 +31,8 @@ * 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 diff --git a/portable/stdbool.h b/portable/stdbool.h index fb317a9..278288c 100644 --- a/portable/stdbool.h +++ b/portable/stdbool.h @@ -27,28 +27,28 @@ * stripped-down version of config.h with a different name. */ #ifndef CONFIG_H_INCLUDED -# include +# include #endif #if HAVE_STDBOOL_H -# include +# include #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 -# define bool BOOL -# else +# elif _WIN32 +# include +# 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 /* @@ -56,7 +56,7 @@ typedef unsigned char _Bool; * 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 */ diff --git a/portable/strndup.c b/portable/strndup.c index 1a0c816..982e691 100644 --- a/portable/strndup.c +++ b/portable/strndup.c @@ -25,8 +25,8 @@ * 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 @@ -43,7 +43,7 @@ strndup(const char *s, size_t n) } /* 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); diff --git a/portable/system.h b/portable/system.h index a35df76..6912ade 100644 --- a/portable/system.h +++ b/portable/system.h @@ -46,28 +46,28 @@ /* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */ #if HAVE_INTTYPES_H -# include +# include #endif #include #include #include #if HAVE_STDINT_H -# include +# include #endif #include #include #include #if HAVE_STRINGS_H -# include +# include #endif #include #if HAVE_UNISTD_H -# include +# include #endif /* SCO OpenServer gets int32_t from here. */ #if HAVE_SYS_BITYPES_H -# include +# include #endif /* Get the bool type. */ @@ -75,7 +75,7 @@ /* Windows provides snprintf under a different name. */ #ifdef _WIN32 -# define snprintf _snprintf +# define snprintf _snprintf #endif /* Windows does not define ssize_t. */ @@ -88,9 +88,9 @@ typedef ptrdiff_t 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 /* @@ -98,11 +98,11 @@ typedef ptrdiff_t ssize_t; * 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 diff --git a/tests/plugin/heimdal-t.c b/tests/plugin/heimdal-t.c index d5ef80a..4146c26 100644 --- a/tests/plugin/heimdal-t.c +++ b/tests/plugin/heimdal-t.c @@ -15,7 +15,7 @@ #include #include #ifdef HAVE_KADM5_KADM5_PWCHECK_H -# include +# include #endif #include @@ -187,7 +187,7 @@ main(void) 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"; @@ -218,13 +218,13 @@ main(void) /* 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"; @@ -260,7 +260,7 @@ main(void) 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"; @@ -277,15 +277,15 @@ main(void) 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 @@ -307,13 +307,13 @@ main(void) 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); diff --git a/tests/plugin/mit-t.c b/tests/plugin/mit-t.c index e192e23..9857bb9 100644 --- a/tests/plugin/mit-t.c +++ b/tests/plugin/mit-t.c @@ -2,7 +2,7 @@ * Test for the MIT Kerberos shared module API. * * Written by Russ Allbery - * Copyright 2017 Russ Allbery + * Copyright 2017, 2020 Russ Allbery * Copyright 2010, 2013, 2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -17,7 +17,7 @@ #include #include #ifdef HAVE_KRB5_PWQUAL_PLUGIN_H -# include +# include #endif #include @@ -151,7 +151,7 @@ main(void) { 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; @@ -206,14 +206,14 @@ main(void) 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); @@ -234,7 +234,7 @@ main(void) putenv(krb5_config); free(krb5_config_empty); -#ifdef HAVE_CRACKLIB +# ifdef HAVE_CRACKLIB /* Add CrackLib configuration. */ setup_argv[3] = (char *) "password_dictionary"; @@ -284,13 +284,13 @@ main(void) 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"; @@ -359,7 +359,7 @@ main(void) 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); @@ -388,15 +388,15 @@ main(void) 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 @@ -430,13 +430,13 @@ main(void) 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); diff --git a/tests/portable/snprintf-t.c b/tests/portable/snprintf-t.c index 601579b..6efaf53 100644 --- a/tests/portable/snprintf-t.c +++ b/tests/portable/snprintf-t.c @@ -27,7 +27,7 @@ * 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 /* @@ -40,11 +40,10 @@ int test_vsnprintf(char *str, size_t count, const char *fmt, va_list args); 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", @@ -53,55 +52,48 @@ static const char *const fp_formats[] = { "%+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; @@ -123,12 +115,13 @@ main(void) 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"); @@ -155,8 +148,8 @@ main(void) 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); diff --git a/tests/runtests.c b/tests/runtests.c index ab9a4cb..ef78733 100644 --- a/tests/runtests.c +++ b/tests/runtests.c @@ -82,13 +82,13 @@ * 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 @@ -113,7 +113,7 @@ /* 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 /* @@ -122,9 +122,9 @@ * 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 /* @@ -142,58 +142,50 @@ * $(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. */ @@ -239,9 +231,9 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ -------------------------- -------------- ---- ---- ------------------------"; /* 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__) @@ -251,9 +243,9 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ * (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 /* @@ -264,11 +256,11 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ * 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 /* @@ -278,7 +270,7 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ * 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. */ @@ -386,8 +378,8 @@ x_strdup(const char *s, const char *file, int line) 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; } @@ -480,7 +472,7 @@ tv_sum(const struct timeval *tv1, const struct timeval *tv2) static const char * skip_whitespace(const char *p) { - while (isspace((unsigned char)(*p))) + while (isspace((unsigned char) (*p))) p++; return p; } @@ -714,8 +706,7 @@ test_plan(const char *line, struct testset *ts, enum test_verbose verbose) * 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; @@ -755,7 +746,7 @@ test_checkline(const char *line, struct testset *ts, 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) { @@ -806,7 +797,7 @@ test_checkline(const char *line, struct testset *ts, * 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 == '#') { @@ -829,10 +820,17 @@ test_checkline(const char *line, struct testset *ts, /* 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; @@ -1108,8 +1106,7 @@ test_fail_summary(const struct testlist *fails) 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 @@ -1177,7 +1174,7 @@ find_test(const char *name, const char *source, const char *build) 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] = "."; @@ -1443,8 +1440,7 @@ test_batch(struct testlist *tests, const char *source, const char *build, 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, @@ -1458,8 +1454,8 @@ test_batch(struct testlist *tests, const char *source, const char *build, 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); } diff --git a/tests/tap/basic.c b/tests/tap/basic.c index c244e05..0c96fce 100644 --- a/tests/tap/basic.c +++ b/tests/tap/basic.c @@ -43,9 +43,9 @@ #include #include #ifdef _WIN32 -# include +# include #else -# include +# include #endif #include #include @@ -54,8 +54,8 @@ /* 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 /* @@ -70,7 +70,7 @@ unsigned long testnum = 1; * 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 @@ -124,16 +124,16 @@ static struct diag_file *diag_files = NULL; * 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) @@ -717,7 +717,7 @@ bcalloc(size_t n, size_t size) 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; } @@ -807,9 +807,9 @@ bstrndup(const char *s, size_t n) 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); @@ -830,7 +830,7 @@ test_file_path(const char *file) { 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++) { diff --git a/tests/tap/basic.h b/tests/tap/basic.h index a4b1a61..78c04d0 100644 --- a/tests/tap/basic.h +++ b/tests/tap/basic.h @@ -31,9 +31,9 @@ #ifndef TAP_BASIC_H #define TAP_BASIC_H 1 +#include /* va_list */ +#include /* size_t */ #include -#include /* va_list */ -#include /* size_t */ /* * Used for iterating through arrays. ARRAY_SIZE returns the number of @@ -41,8 +41,8 @@ * 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 @@ -75,8 +75,7 @@ int ok(int success, const char *format, ...) __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() @@ -117,10 +116,8 @@ int sysdiag(const char *format, ...) * 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) @@ -148,8 +145,7 @@ void test_file_path_free(char *path); * 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); /* @@ -163,8 +159,7 @@ 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 diff --git a/tests/tap/kerberos.c b/tests/tap/kerberos.c index 5551fbc..8985613 100644 --- a/tests/tap/kerberos.c +++ b/tests/tap/kerberos.c @@ -39,7 +39,7 @@ #include #ifdef HAVE_KRB5 -# include +# include #endif #include @@ -56,7 +56,7 @@ * 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 @@ -155,12 +155,11 @@ kerberos_kinit(void) 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 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 #ifdef HAVE_KRB5 -# include +# include #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. */ }; /* @@ -56,11 +56,11 @@ struct kerberos_config { * 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 diff --git a/tests/tap/macros.h b/tests/tap/macros.h index 2cd1e87..faf57a1 100644 --- a/tests/tap/macros.h +++ b/tests/tap/macros.h @@ -40,9 +40,9 @@ * 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 /* @@ -53,18 +53,18 @@ * 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 /* @@ -74,7 +74,7 @@ * 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. */ @@ -87,11 +87,11 @@ #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 */ diff --git a/tests/tap/process.c b/tests/tap/process.c index 45bbe46..4211042 100644 --- a/tests/tap/process.c +++ b/tests/tap/process.c @@ -44,11 +44,11 @@ #include #include #ifdef HAVE_SYS_SELECT_H -# include +# include #endif #include #ifdef HAVE_SYS_TIME_H -# include +# include #endif #include #include @@ -59,7 +59,7 @@ /* 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. */ @@ -70,12 +70,12 @@ * 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 */ }; /* diff --git a/tests/tap/process.h b/tests/tap/process.h index 7e008be..b2637a0 100644 --- a/tests/tap/process.h +++ b/tests/tap/process.h @@ -60,8 +60,7 @@ void is_function_output(test_function_type, void *data, int status, * 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 diff --git a/tests/tap/string.h b/tests/tap/string.h index 73e34ee..cb4c791 100644 --- a/tests/tap/string.h +++ b/tests/tap/string.h @@ -34,7 +34,7 @@ #include #include -#include /* va_list */ +#include /* va_list */ BEGIN_DECLS diff --git a/tests/util/messages-krb5-t.c b/tests/util/messages-krb5-t.c index 8113198..2fc1acb 100644 --- a/tests/util/messages-krb5-t.c +++ b/tests/util/messages-krb5-t.c @@ -29,7 +29,7 @@ #include #ifdef HAVE_KRB5 -# include +# include #endif #include @@ -37,7 +37,7 @@ #include #include #ifdef HAVE_KRB5 -# include +# include #endif #include #include diff --git a/tests/util/messages-t.c b/tests/util/messages-t.c index eb4ef5f..d27d24e 100644 --- a/tests/util/messages-t.c +++ b/tests/util/messages-t.c @@ -46,45 +46,78 @@ /* * 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; @@ -93,61 +126,92 @@ static void test11(void *data UNUSED) { } 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"); @@ -218,7 +282,7 @@ main(void) 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"); diff --git a/tests/util/xmalloc.c b/tests/util/xmalloc.c index a5c0b94..8ff1a23 100644 --- a/tests/util/xmalloc.c +++ b/tests/util/xmalloc.c @@ -35,7 +35,7 @@ #include #include #ifdef HAVE_SYS_TIME_H -# include +# include #endif #include @@ -382,14 +382,22 @@ main(int argc, char *argv[]) } 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; diff --git a/tools/heimdal-strength.c b/tools/heimdal-strength.c index 775d3af..d6f292f 100644 --- a/tools/heimdal-strength.c +++ b/tools/heimdal-strength.c @@ -21,8 +21,8 @@ #include #include -#include #include +#include #include diff --git a/util/messages-krb5.c b/util/messages-krb5.c index 341ac1a..f00289a 100644 --- a/util/messages-krb5.c +++ b/util/messages-krb5.c @@ -35,8 +35,8 @@ #include #include -#include #include +#include #include diff --git a/util/messages.c b/util/messages.c index 836c4b1..cf6f837 100644 --- a/util/messages.c +++ b/util/messages.c @@ -83,17 +83,17 @@ #include #ifdef HAVE_SYSLOG_H -# include +# include #endif #ifdef _WIN32 -# include -# 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 +# 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 @@ -101,18 +101,14 @@ #include /* 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; @@ -144,15 +140,14 @@ message_handlers(message_handler_func **list, unsigned int count, va_list args) * 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) @@ -254,7 +249,7 @@ message_log_syslog(int pri, size_t len, const char *fmt, va_list args, int err) CloseEventLog(eventlog); } } -#else /* !_WIN32 */ +#else /* !_WIN32 */ if (err == 0) syslog(pri, "%s", buffer); else @@ -268,18 +263,17 @@ message_log_syslog(int pri, size_t len, const char *fmt, va_list args, int err) * 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) /* diff --git a/util/xmalloc.c b/util/xmalloc.c index 889bd1e..fc6839e 100644 --- a/util/xmalloc.c +++ b/util/xmalloc.c @@ -100,8 +100,8 @@ void 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); @@ -201,7 +201,7 @@ x_strndup(const char *s, size_t size, const char *file, int 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); @@ -261,7 +261,7 @@ x_asprintf(char **strp, const char *file, int line, const char *fmt, ...) } 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, ...) { diff --git a/util/xmalloc.h b/util/xmalloc.h index fc159b4..bdb76d9 100644 --- a/util/xmalloc.h +++ b/util/xmalloc.h @@ -41,12 +41,12 @@ * 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__) @@ -59,13 +59,13 @@ * 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