summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2008-04-24 02:02:49 +0000
committerRuss Allbery <rra@stanford.edu>2008-04-24 02:02:49 +0000
commit92ff7f21ad0b167f8d742a9d7b5f93704a57619c (patch)
tree7adae5f227b6463e07d5cd0f1dab82b7f1c6be47
parent34c58f9471b3df4fa8b719b3c3534940ba5cfe1b (diff)
Major coding style cleanup. Updated all shared code from my other
projects. The configure option requesting AFS kaserver support (and thus building kasetkey) is now --with-kaserver instead of --with-afs. If KRB5_CONFIG was explicitly set in the environment, don't use a different krb5-config based on --with-krb4 or --with-krb5. If krb5-config isn't executable, don't use it. This allows one to force library probing by setting KRB5_CONFIG to point to a nonexistent file. Sanity-check the results of krb5-config before proceeding and error out in configure if they don't work. Stop setting Stanford-specific compile-time defaults for the wallet server and port.
-rw-r--r--LICENSE62
-rw-r--r--README11
-rw-r--r--client/file.c46
-rw-r--r--client/internal.h102
-rw-r--r--client/keytab.c44
-rw-r--r--client/krb5.c32
-rw-r--r--client/remctl.c43
-rw-r--r--client/srvtab.c41
-rw-r--r--client/wallet.c82
-rw-r--r--configure.ac7
-rw-r--r--kasetkey/kasetkey.c5
-rw-r--r--m4/gssapi.m411
-rw-r--r--m4/kaserver.m4 (renamed from m4/afs.m4)19
-rw-r--r--m4/krb4.m415
-rw-r--r--m4/krb5.m420
-rw-r--r--m4/lib-depends.m41
-rw-r--r--m4/remctl.m421
-rw-r--r--m4/snprintf.m412
-rw-r--r--m4/vamacros.m427
-rw-r--r--portable/asprintf.c28
-rw-r--r--portable/dummy.c23
-rw-r--r--portable/snprintf.c32
-rw-r--r--portable/stdbool.h43
-rw-r--r--portable/strlcat.c2
-rw-r--r--portable/strlcpy.c2
-rw-r--r--portable/system.h111
-rw-r--r--system.h95
-rw-r--r--tests/libtest.c124
-rw-r--r--tests/libtest.h80
-rw-r--r--tests/portable/asprintf-t.c26
-rw-r--r--tests/portable/snprintf-t.c50
-rw-r--r--tests/portable/strlcat-t.c2
-rw-r--r--tests/portable/strlcpy-t.c2
-rw-r--r--tests/runtests.c254
-rw-r--r--tests/util/concat-t.c55
-rw-r--r--tests/util/messages-t.c90
-rw-r--r--tests/util/xmalloc-t.in44
-rw-r--r--tests/util/xmalloc.c141
-rw-r--r--util/concat.c75
-rw-r--r--util/messages-krb5.c2
-rw-r--r--util/messages.c224
-rw-r--r--util/xmalloc.c168
42 files changed, 1287 insertions, 987 deletions
diff --git a/LICENSE b/LICENSE
index 36d2143..8eca7ad 100644
--- a/LICENSE
+++ b/LICENSE
@@ -29,8 +29,9 @@ Collected copyright notices for the entire package:
Copyright 1994, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007,
2008 Board of Trustees, Leland Stanford Jr. University
- Copyright 2000, 2001, 2004 Russ Allbery <rra@stanford.edu>
- Copyright 2004, 2005, 2006
+ Copyright 2000, 2001, 2004, 2006, 2007, 2008
+ Russ Allbery <rra@stanford.edu>
+ Copyright 2004, 2005, 2006, 2007
by Internet Systems Consortium, Inc. ("ISC")
Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003 by The Internet Software Consortium and Rich Salz
@@ -41,26 +42,18 @@ Collected copyright notices for the entire package:
Copyright 1998 Andrew Tridgell <tridge@samba.org>
Copyright 2000, 2005 Hrvoje Niksic <hniksic@xemacs.org>
Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ Free Software Foundation, Inc.
Copyright 1994 X Consortium
-The file portable/snprintf.c is released under the following license:
-
- This code is based on code written by Patrick Powell (papowell@astart.com)
- It may be used for any purpose as long as this notice remains intact
- on all source code distributions
-
-The files portable/asprintf.c, portable/dummy.c, portable/macros.h,
-portable/strlcat.c, portable/strlcpy.c, and util/concat.c have been placed
-in the public domain by their author.
-
The files tests/libtest.c, tests/libtest.h, tests/portable/snprintf-t.c,
tests/portable/strlcat-t.c, tests/portable/strlcpy-t.c,
tests/util/concat-t.c, tests/util/messages-t.c, tests/util/xmalloc-t, and
tests/util/xmalloc.c are released under the following copyright and
license:
- Copyright (c) 2004, 2005, 2006
+ Copyright 2008 Board of Trustees, Leland Stanford Jr. University
+ Copyright (c) 2004, 2005, 2006, 2007
by Internet Systems Consortium, Inc. ("ISC")
Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003 by The Internet Software Consortium and Rich Salz
@@ -80,11 +73,46 @@ license:
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+The files portable/asprintf.c, portable/dummy.c, portable/macros.h,
+portable/stdbool.h, portable/strlcat.c, portable/strlcpy.c, and
+util/concat.c have been placed in the public domain by their author.
+
+The file portable/snprintf.c is released under the following license:
+
+ This code is based on code written by Patrick Powell (papowell@astart.com)
+ It may be used for any purpose as long as this notice remains intact
+ on all source code distributions
+
+The file tests/runtests.c is released under the following copyright and
+license:
+
+ Copyright 2000, 2001, 2004, 2006, 2007, 2008
+ Russ Allbery <rra@stanford.edu>
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER 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.
+
The files Makefile.in and aclocal.m4 are generated by GNU Automake and
released under the following copyright and license:
Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
- 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This file is free software; the Free Software Foundation
gives unlimited permission to copy and/or distribute it,
with or without modifications, as long as this notice is preserved.
@@ -106,8 +134,8 @@ The files build-aux/compile, build-aux/depcomp, and build-aux/missing are
taken from GNU Automake and are released under the following copyright and
license:
- Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005
- Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
diff --git a/README b/README
index 3bc8df5..c68464b 100644
--- a/README
+++ b/README
@@ -184,11 +184,16 @@ BUILD AND INSTALLATION
./configure KRB5_CONFIG=/path/to/krb5-config
- To build with AFS kaserver synchronization support, pass --with-afs to
- configure. You may need to include the path to the AFS include files
+ To not use krb5-config and force library probing even if there is a
+ krb5-config script on your path, set KRB5_CONFIG to a nonexistent path:
+
+ ./configure KRB5_CONFIG=/nonexistent
+
+ To build with AFS kaserver synchronization support, pass --with-kaserver
+ to configure. You may need to include the path to the AFS include files
and libraries, such as:
- ./configure --with-afs=/usr/afsws
+ ./configure --with-kaserver=/usr/afsws
The AFS kaserver support also requires Kerberos v4 libraries and tries
to use krb5-config to find such libraries. If your Kerberos v4
diff --git a/client/file.c b/client/file.c
index 10304e5..7e0563e 100644
--- a/client/file.c
+++ b/client/file.c
@@ -1,15 +1,15 @@
-/* $Id$
-**
-** File handling for the wallet client.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
-**
-** See LICENSE for licensing terms.
-*/
+/* $Id$
+ *
+ * File handling for the wallet client.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
+ *
+ * See LICENSE for licensing terms.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <fcntl.h>
@@ -17,9 +17,9 @@
#include <util/util.h>
/*
-** Given a filename, some data, and a length, write that data to the given
-** file safely, but overwrite any existing file by that name.
-*/
+ * Given a filename, some data, and a length, write that data to the given
+ * file safely, but overwrite any existing file by that name.
+ */
void
overwrite_file(const char *name, const void *data, size_t length)
{
@@ -45,10 +45,10 @@ overwrite_file(const char *name, const void *data, size_t length)
/*
-** Given a filename, some data, and a length, write that data to the given
-** file safely and atomically by creating file.new, writing the data, linking
-** file to file.bak, and then renaming file.new to file.
-*/
+ * Given a filename, some data, and a length, write that data to the given
+ * file safely and atomically by creating file.new, writing the data, linking
+ * file to file.bak, and then renaming file.new to file.
+ */
void
write_file(const char *name, const void *data, size_t length)
{
@@ -72,12 +72,12 @@ write_file(const char *name, const void *data, size_t length)
/*
-** Given a remctl object, the command prefix, object type, and object name,
-** and a file (which may be NULL), send a wallet get command and write the
-** results to the provided file. If the file is NULL, write the results to
-** standard output instead. Returns 0 on success and an exit status on
-** failure.
-*/
+ * Given a remctl object, the command prefix, object type, and object name,
+ * and a file (which may be NULL), send a wallet get command and write the
+ * results to the provided file. If the file is NULL, write the results to
+ * standard output instead. Returns 0 on success and an exit status on
+ * failure.
+ */
int
get_file(struct remctl *r, const char *prefix, const char *type,
const char *name, const char *file)
diff --git a/client/internal.h b/client/internal.h
index ba17b73..64fad04 100644
--- a/client/internal.h
+++ b/client/internal.h
@@ -1,49 +1,47 @@
-/* $Id$
-**
-** Internal support functions for the wallet client.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
-**
-** See LICENSE for licensing terms.
-*/
+/* $Id$
+ *
+ * Internal support functions for the wallet client.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
+ *
+ * See LICENSE for licensing terms.
+ */
#ifndef CLIENT_INTERNAL_H
#define CLIENT_INTERNAL_H 1
+#include <portable/macros.h>
+
#include <krb5.h>
#include <sys/types.h>
-#include <util/util.h>
-
/* Forward declarations to avoid unnecessary includes. */
struct remctl;
-/* Temporary until we have some real configuration. */
-#ifndef WALLET_SERVER
-# define WALLET_SERVER "wallet.stanford.edu"
-#endif
-#ifndef WALLET_PORT
-# define WALLET_PORT 0
-#endif
-
BEGIN_DECLS
-/* Given a Kerberos context and a principal name, obtain Kerberos credentials
- for that principal and store them in a memory cache for use by later
- operations. */
+/*
+ * Given a Kerberos context and a principal name, obtain Kerberos credentials
+ * for that principal and store them in a memory cache for use by later
+ * operations.
+ */
void kinit(krb5_context, const char *principal);
-/* Given a remctl object, run a remctl command. If data is non-NULL, saves
- the standard output from the command into data with the length in length.
- Otherwise, prints it to standard output. Either way, prints standard error
- output and errors to standard error and returns the exit status or 255 for
- a remctl internal error. */
+/*
+ * Given a remctl object, run a remctl command. If data is non-NULL, saves
+ * the standard output from the command into data with the length in length.
+ * Otherwise, prints it to standard output. Either way, prints standard error
+ * output and errors to standard error and returns the exit status or 255 for
+ * a remctl internal error.
+ */
int run_command(struct remctl *, const char **command, char **data,
size_t *length);
-/* Check whether an object exists using the exists wallet interface. Returns
- true if it does, false if it doesn't, and dies on remctl errors. */
+/*
+ * Check whether an object exists using the exists wallet interface. Returns
+ * true if it does, false if it doesn't, and dies on remctl errors.
+ */
int object_exists(struct remctl *, const char *prefix, const char *type,
const char *name);
@@ -51,34 +49,44 @@ int object_exists(struct remctl *, const char *prefix, const char *type,
void object_autocreate(struct remctl *, const char *prefix, const char *type,
const char *name);
-/* Given a remctl object, the type for the wallet interface, object type,
- object name, and a file (which may be NULL), send a wallet get command and
- write the results to the provided file. If the file is NULL, write the
- results to standard output instead. Returns 0 on success and an exit
- status on failure. */
+/*
+ * Given a remctl object, the type for the wallet interface, object type,
+ * object name, and a file (which may be NULL), send a wallet get command and
+ * write the results to the provided file. If the file is NULL, write the
+ * results to standard output instead. Returns 0 on success and an exit
+ * status on failure.
+ */
int get_file(struct remctl *, const char *prefix, const char *type,
const char *name, const char *file);
-/* Given a remctl object, the Kerberos context, the type for the wallet
- interface, the name of a keytab object, and a file name, call the correct
- wallet commands to download a keytab and write it to that file. If srvtab
- is not NULL, write a srvtab based on the keytab after a successful
- download. */
+/*
+ * Given a remctl object, the Kerberos context, the type for the wallet
+ * interface, the name of a keytab object, and a file name, call the correct
+ * wallet commands to download a keytab and write it to that file. If srvtab
+ * is not NULL, write a srvtab based on the keytab after a successful
+ * download.
+ */
int get_keytab(struct remctl *, krb5_context, const char *type,
const char *name, const char *file, const char *srvtab);
-/* Given a filename, some data, and a length, write that data to the given
- file with error checking, overwriting any existing contents. */
+/*
+ * Given a filename, some data, and a length, write that data to the given
+ * file with error checking, overwriting any existing contents.
+ */
void overwrite_file(const char *name, const void *data, size_t length);
-/* Given a filename, some data, and a length, write that data to the given
- file safely and atomically by creating file.new, writing the data, linking
- file to file.bak, and then renaming file.new to file. */
+/*
+ * Given a filename, some data, and a length, write that data to the given
+ * file safely and atomically by creating file.new, writing the data, linking
+ * file to file.bak, and then renaming file.new to file.
+ */
void write_file(const char *name, const void *data, size_t length);
-/* Given a Kerberos context, a srvtab file, the Kerberos v5 principal, and the
- keytab file, write a srvtab file for the corresponding Kerberos v4
- principal. */
+/*
+ * Given a Kerberos context, a srvtab file, the Kerberos v5 principal, and the
+ * keytab file, write a srvtab file for the corresponding Kerberos v4
+ * principal.
+ */
void write_srvtab(krb5_context, const char *srvtab, const char *principal,
const char *keytab);
diff --git a/client/keytab.c b/client/keytab.c
index 872cd48..eb37ec1 100644
--- a/client/keytab.c
+++ b/client/keytab.c
@@ -1,15 +1,15 @@
-/* $Id$
-**
-** Implementation of keytab handling for the wallet client.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
-**
-** See LICENSE for licensing terms.
-*/
+/* $Id$
+ *
+ * Implementation of keytab handling for the wallet client.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
+ *
+ * See LICENSE for licensing terms.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <remctl.h>
@@ -18,11 +18,11 @@
/*
-** Given keytab data as a pointer to memory and a length and the path of a
-** second keytab, merge the keys in the memory keytab into the file keytab.
-** Currently, this doesn't do any cleanup of old kvnos and doesn't handle
-** duplicate kvnos correctly. Dies on any error.
-*/
+ * Given keytab data as a pointer to memory and a length and the path of a
+ * second keytab, merge the keys in the memory keytab into the file keytab.
+ * Currently, this doesn't do any cleanup of old kvnos and doesn't handle
+ * duplicate kvnos correctly. Dies on any error.
+ */
static void
merge_keytab(krb5_context ctx, const char *newfile, const char *file)
{
@@ -61,9 +61,9 @@ merge_keytab(krb5_context ctx, const char *newfile, const char *file)
/*
-** Configure a given keytab to be synchronized with an AFS kaserver if it
-** isn't already. Returns true on success, false on failure.
-*/
+ * Configure a given keytab to be synchronized with an AFS kaserver if it
+ * isn't already. Returns true on success, false on failure.
+ */
static int
set_sync(struct remctl *r, const char *type, const char *name)
{
@@ -94,10 +94,10 @@ set_sync(struct remctl *r, const char *type, const char *name)
/*
-** Given a remctl object, the Kerberos context, the name of a keytab object,
-** and a file name, call the correct wallet commands to download a keytab and
-** write it to that file. Returns the setatus or 255 on an internal error.
-*/
+ * Given a remctl object, the Kerberos context, the name of a keytab object,
+ * and a file name, call the correct wallet commands to download a keytab and
+ * write it to that file. Returns the setatus or 255 on an internal error.
+ */
int
get_keytab(struct remctl *r, krb5_context ctx, const char *type,
const char *name, const char *file, const char *srvtab)
diff --git a/client/krb5.c b/client/krb5.c
index 606cbb9..fd600da 100644
--- a/client/krb5.c
+++ b/client/krb5.c
@@ -1,17 +1,17 @@
-/* $Id$
-**
-** Kerberos support functions for the wallet client.
-**
-** Currently, the only function here is one to obtain a ticket cache for a
-** given principal and store it in memory for use by the rest of the wallet
-** client.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
-*/
+/* $Id$
+ *
+ * Kerberos support functions for the wallet client.
+ *
+ * Currently, the only function here is one to obtain a ticket cache for a
+ * given principal and store it in memory for use by the rest of the wallet
+ * client.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <krb5.h>
@@ -23,10 +23,10 @@
/*
-** Given a Kerberos context and a principal name, authenticate as that user
-** and store the TGT in a memory ticket cache for later use by remctl. Dies
-** on failure.
-*/
+ * Given a Kerberos context and a principal name, authenticate as that user
+ * and store the TGT in a memory ticket cache for later use by remctl. Dies
+ * on failure.
+ */
void
kinit(krb5_context ctx, const char *principal)
{
diff --git a/client/remctl.c b/client/remctl.c
index 74e2cf5..8b9702a 100644
--- a/client/remctl.c
+++ b/client/remctl.c
@@ -1,15 +1,15 @@
-/* $Id$
-**
-** remctl interface for the wallet client.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2007 Board of Trustees, Leland Stanford Jr. University
-**
-** See LICENSE for licensing terms.
-*/
+/* $Id$
+ *
+ * remctl interface for the wallet client.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2007 Board of Trustees, Leland Stanford Jr. University
+ *
+ * See LICENSE for licensing terms.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <remctl.h>
@@ -18,13 +18,12 @@
/*
-** Given a remctl connection and a command, run the command.
-**
-** If data is non-NULL, save the output in it and return the length in
-** length. Otherwise, send any output to stdout. Either way, send error
-** output to stderr, and return the exit status (or 255 if there is an
-** error).
-*/
+ * Given a remctl connection and a command, run the command.
+ *
+ * If data is non-NULL, save the output in it and return the length in length.
+ * Otherwise, send any output to stdout. Either way, send error output to
+ * stderr, and return the exit status (or 255 if there is an error).
+ */
int
run_command(struct remctl *r, const char **command, char **data,
size_t *length)
@@ -75,9 +74,9 @@ run_command(struct remctl *r, const char **command, char **data,
/*
-** Check whether an object exists using the exists wallet interface. Returns
-** true if it does, false if it doesn't, and dies on remctl errors.
-*/
+ * Check whether an object exists using the exists wallet interface. Returns
+ * true if it does, false if it doesn't, and dies on remctl errors.
+ */
int
object_exists(struct remctl *r, const char *prefix, const char *type,
const char *name)
@@ -101,8 +100,8 @@ object_exists(struct remctl *r, const char *prefix, const char *type,
/*
-** Attempt autocreation of an object. Dies if autocreation fails.
-*/
+ * Attempt autocreation of an object. Dies if autocreation fails.
+ */
void
object_autocreate(struct remctl *r, const char *prefix, const char *type,
const char *name)
diff --git a/client/srvtab.c b/client/srvtab.c
index b454720..2e4ea2d 100644
--- a/client/srvtab.c
+++ b/client/srvtab.c
@@ -1,15 +1,15 @@
-/* $Id$
-**
-** Implementation of srvtab handling for the wallet client.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
-**
-** See LICENSE for licensing terms.
-*/
+/* $Id$
+ *
+ * Implementation of srvtab handling for the wallet client.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
+ *
+ * See LICENSE for licensing terms.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <krb5.h>
@@ -24,16 +24,17 @@
/*
-** Given the Kerberos context, srvtab file name, a Kerberos principal (as a
-** string), and a keytab file name, extract the des-cbc-crc key from that
-** keytab and write it to the newly created srvtab file as a srvtab. Convert
-** the principal from Kerberos v5 form to Kerberos v4 form.
-**
-** We always force the kvno to 0 for the srvtab. This works with how the
-** wallet synchronizes keys, even though it's not particularly correct.
-**
-** On any failure, print an error message to standard error and then exit.
-*/
+ * Given the Kerberos context, srvtab file name, a Kerberos principal (as a
+ * string), and a keytab file name, extract the des-cbc-crc key from that
+ * keytab and write it to the newly created srvtab file as a srvtab. Convert
+ * the principal from Kerberos v5 form to Kerberos v4 form.
+ *
+ * We always force the kvno to 0 for the srvtab. This works with how the
+ * wallet synchronizes keys with kasetkey, even though it's not particularly
+ * correct.
+ *
+ * On any failure, print an error message to standard error and then exit.
+ */
void
write_srvtab(krb5_context ctx, const char *srvtab, const char *principal,
const char *keytab)
diff --git a/client/wallet.c b/client/wallet.c
index 2e4f755..2995cf6 100644
--- a/client/wallet.c
+++ b/client/wallet.c
@@ -1,16 +1,16 @@
-/* $Id$
-**
-** The client program for the wallet system.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2006, 2007, 2008
-** Board of Trustees, Leland Stanford Jr. University
-**
-** See LICENSE for licensing terms.
-*/
+/* $Id$
+ *
+ * The client program for the wallet system.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2006, 2007, 2008
+ * Board of Trustees, Leland Stanford Jr. University
+ *
+ * See LICENSE for licensing terms.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <errno.h>
#include <krb5.h>
@@ -19,9 +19,11 @@
#include <client/internal.h>
#include <util/util.h>
-/* Basic wallet behavior options set either on the command line or via
- krb5.conf. If set via krb5.conf, we allocate memory for the strings, but
- we never free them. */
+/*
+ * Basic wallet behavior options set either on the command line or via
+ * krb5.conf. If set via krb5.conf, we allocate memory for the strings, but
+ * we never free them.
+ */
struct options {
char *type;
char *server;
@@ -30,8 +32,10 @@ struct options {
int port;
};
-/* Allow defaults to be set for a particular site with configure options if
- people don't want to use krb5.conf for some reason. */
+/*
+ * Allow defaults to be set for a particular site with configure options if
+ * people don't want to use krb5.conf for some reason.
+ */
#ifndef WALLET_SERVER
# define WALLET_SERVER NULL
#endif
@@ -51,25 +55,26 @@ Options:\n\
-h Display this help\n\
-p <port> Port of server (default: %d, if zero, remctl default)\n\
-S <srvtab> For the get keytab command, srvtab output file\n\
- -s <server> Server hostname (default: " WALLET_SERVER ")\n\
+ -s <server> Server hostname (default: %s)\n\
-v Display the version of wallet\n";
/*
-** Display the usage message for remctl.
-*/
+ * Display the usage message for remctl.
+ */
static void
usage(int status)
{
- fprintf((status == 0) ? stdout : stderr, usage_message, WALLET_PORT);
+ fprintf((status == 0) ? stdout : stderr, usage_message, WALLET_PORT,
+ (WALLET_SERVER == NULL) ? "<none>" : WALLET_SERVER);
exit(status);
}
/*
-** Load a string option from Kerberos appdefaults. This requires an annoying
-** workaround because one cannot specify a default value of NULL.
-*/
+ * Load a string option from Kerberos appdefaults. This requires an annoying
+ * workaround because one cannot specify a default value of NULL.
+ */
static void
default_string(krb5_context ctx, const char *opt, const char *defval,
char **result)
@@ -85,9 +90,9 @@ default_string(krb5_context ctx, const char *opt, const char *defval,
/*
-** Load a number option from Kerberos appdefaults. The native interface
-** doesn't support numbers, so we actually read a string and then convert.
-*/
+ * Load a number option from Kerberos appdefaults. The native interface
+ * doesn't support numbers, so we actually read a string and then convert.
+ */
static void
default_number(krb5_context ctx, const char *opt, int defval, int *result)
{
@@ -104,10 +109,10 @@ default_number(krb5_context ctx, const char *opt, int defval, int *result)
/*
-** Set option defaults and then get krb5.conf configuration, if any, and
-** override the defaults. Later, command-line options will override those
-** defaults.
-*/
+ * Set option defaults and then get krb5.conf configuration, if any, and
+ * override the defaults. Later, command-line options will override those
+ * defaults.
+ */
static void
set_defaults(krb5_context ctx, struct options *options)
{
@@ -120,9 +125,8 @@ set_defaults(krb5_context ctx, struct options *options)
/*
-** Main routine. Parse the arguments and then perform the desired
-** operation.
-*/
+ * Main routine. Parse the arguments and then perform the desired operation.
+ */
int
main(int argc, char *argv[])
{
@@ -200,8 +204,10 @@ main(int argc, char *argv[])
die("-S option requires -f also be used");
}
- /* If no server was set at configure time and none was set on the command
- line or with krb5.conf settings, we can't continue. */
+ /*
+ * If no server was set at configure time and none was set on the command
+ * line or with krb5.conf settings, we can't continue.
+ */
if (options.server == NULL)
die("no server specified in krb5.conf or with -s");
@@ -216,8 +222,10 @@ main(int argc, char *argv[])
if (!remctl_open(r, options.server, options.port, options.principal))
die("%s", remctl_error(r));
- /* Most commands, we handle ourselves, but get and store commands are
- special and keytab get commands with -f are doubly special. */
+ /*
+ * Most commands, we handle ourselves, but get and store commands are
+ * special and keytab get commands with -f are doubly special.
+ */
if (strcmp(argv[0], "get") == 0 || strcmp(argv[0], "store") == 0) {
if (!object_exists(r, options.type, argv[1], argv[2]))
object_autocreate(r, options.type, argv[1], argv[2]);
diff --git a/configure.ac b/configure.ac
index ebff04f..83f3149 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,11 @@ AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_INSTALL
AC_PROG_RANLIB
+AC_AIX
+AC_GNU_SOURCE
+AC_HEADER_STDBOOL
+AC_CHECK_HEADERS([sys/bitypes.h syslog.h])
AC_CHECK_DECLS([snprintf, vsnprintf])
RRA_C_C99_VAMACROS
RRA_C_GNU_VAMACROS
@@ -56,9 +60,6 @@ AS_IF([test x"$REMCTLD" != x],
[AC_DEFINE_UNQUOTED([PATH_REMCTLD], ["$REMCTLD"],
[Define to the full path to remctld to run remctl tests.])])
-dnl Needed to get prototypes for functions like asprintf on Linux.
-AC_DEFINE([_GNU_SOURCE], [1], [Define to 1 on Linux to get full prototypes.])
-
AC_CONFIG_HEADER([config.h])
AC_CONFIG_FILES([Makefile perl/Makefile.PL tests/data/full.conf])
AC_CONFIG_FILES([tests/client/basic-t], [chmod +x tests/client/basic-t])
diff --git a/kasetkey/kasetkey.c b/kasetkey/kasetkey.c
index 6a8a35c..d40a9bb 100644
--- a/kasetkey/kasetkey.c
+++ b/kasetkey/kasetkey.c
@@ -16,14 +16,11 @@
*/
#include <config.h>
+#include <portable/system.h>
#include <errno.h>
#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
#ifdef HAVE_KERBEROSIV_KRB_H
# include <kerberosIV/krb.h>
diff --git a/m4/gssapi.m4 b/m4/gssapi.m4
index 2d36e43..5c0d9e7 100644
--- a/m4/gssapi.m4
+++ b/m4/gssapi.m4
@@ -97,6 +97,14 @@ AC_DEFUN([_RRA_LIB_GSSAPI_MANUAL],
[-lkrb5 -lasn1 -lroken -lcrypto -lcom_err $rra_gssapi_extra])
RRA_LIB_GSSAPI_RESTORE])
+dnl Sanity-check the results of krb5-config and be sure we can really link a
+dnl GSS-API program.
+AC_DEFUN([_RRA_LIB_GSSAPI_CHECK],
+[RRA_LIB_GSSAPI_SWITCH
+ AC_CHECK_FUNC([gss_import_name], ,
+ [AC_MSG_FAILURE([krb5-config results fail for GSS-API])])
+ RRA_LIB_GSSAPI_RESTORE])
+
dnl The main macro.
AC_DEFUN([RRA_LIB_GSSAPI],
[AC_REQUIRE([RRA_ENABLE_REDUCED_DEPENDS])
@@ -132,6 +140,7 @@ AC_DEFUN([RRA_LIB_GSSAPI],
[GSSAPI_CPPFLAGS=`"$KRB5_CONFIG" --cflags`
GSSAPI_LIBS=`"$KRB5_CONFIG" --libs`])
GSSAPI_CPPFLAGS=`echo "$GSSAPI_CPPFLAGS" \
- | sed 's%-I/usr/include ?%%'`],
+ | sed 's%-I/usr/include ?%%'`
+ _RRA_LIB_GSSAPI_CHECK],
[_RRA_LIB_GSSAPI_PATHS
_RRA_LIB_GSSAPI_MANUAL])])])
diff --git a/m4/afs.m4 b/m4/kaserver.m4
index 66a3f08..6a41bd4 100644
--- a/m4/afs.m4
+++ b/m4/kaserver.m4
@@ -1,13 +1,13 @@
-dnl afs.m4 -- Find the compiler and linker flags for OpenAFS.
+dnl kaserver.m4 -- Find the compiler and linker flags for OpenAFS kaserver.
dnl $Id$
dnl
-dnl If --with-afs is given, finds the compiler and linker flags for building
-dnl with OpenAFS libraries; sets AFS_CPPFLAGS, AFS_LDFLAGS, and AFS_LIBS as
-dnl appropriate; and defines HAVE_AFS. Provides the macro RRA_LIB_AFS, which
-dnl takes no arguments.
+dnl If --with-kaserver is given, finds the compiler and linker flags for
+dnl building with OpenAFS libraries; sets AFS_CPPFLAGS, AFS_LDFLAGS, and
+dnl AFS_LIBS as appropriate; and defines HAVE_AFS. Provides the macro
+dnl RRA_LIB_AFS, which takes no arguments.
dnl
-dnl This function also sets rra_afs to true if AFS was requested, which can be
-dnl checked to determine if further checks should be done.
+dnl This function also sets rra_kaserver to true if AFS was requested, which
+dnl can be checked to determine if further checks should be done.
dnl
dnl Also provides RRA_LIB_AFS_SET to set CPPFLAGS, LDFLAGS, and LIBS to
dnl include the AFS libraries; RRA_LIB_AFS_SWITCH to do the same but save the
@@ -19,6 +19,7 @@ dnl Based on code developed by Derrick Brashear and Ken Hornstein of Sine
dnl Nomine Associates, on behalf of Stanford University.
dnl Copyright 2006, 2007, 2008
dnl Board of Trustees, Leland Stanford Jr. University
+dnl
dnl See LICENSE for licensing terms.
dnl Set CPPFLAGS, LDFLAGS, and LIBS to values including the AFS settings.
@@ -81,8 +82,8 @@ AC_DEFUN([RRA_LIB_AFS],
AC_SUBST([AFS_CPPFLAGS])
AC_SUBST([AFS_LDFLAGS])
AC_SUBST([AFS_LIBS])
- AC_ARG_WITH([afs],
- [AC_HELP_STRING([--with-afs@<:@=DIR@:>@],
+ AC_ARG_WITH([kaserver],
+ [AC_HELP_STRING([--with-kaserver@<:@=DIR@:>@],
[Compile with AFS kaserver sync support])],
[AS_IF([test x"$withval" != xno],
[rra_afs=true
diff --git a/m4/krb4.m4 b/m4/krb4.m4
index 12b6efe..321b0bf 100644
--- a/m4/krb4.m4
+++ b/m4/krb4.m4
@@ -104,6 +104,14 @@ AC_DEFUN([_RRA_LIB_KRB4_EXTRA],
AC_CHECK_HEADERS([kerberosIV/krb.h])
RRA_LIB_KRB4_RESTORE])
+dnl Sanity-check the results of krb5-config and be sure we can really link a
+dnl Kerberos program.
+AC_DEFUN([_RRA_LIB_KRB4_CHECK],
+[RRA_LIB_KRB4_SWITCH
+ AC_CHECK_FUNC([krb_get_svc_in_tkt], ,
+ [AC_MSG_FAILURE([krb5-config results fail for Kerberos v4])])
+ RRA_LIB_KRB4_RESTORE])
+
dnl The main macro.
AC_DEFUN([RRA_LIB_KRB4],
[AC_REQUIRE([RRA_ENABLE_REDUCED_DEPENDS])
@@ -123,11 +131,11 @@ AS_IF([test x"$rra_reduced_depends" = xtrue],
[_RRA_LIB_KRB4_PATHS
_RRA_LIB_KRB4_REDUCED],
[AC_ARG_VAR([KRB5_CONFIG], [Path to krb5-config])
- AS_IF([test x"$rra_krb4_root" != x],
+ AS_IF([test x"$rra_krb4_root" != x && test -z "$KRB5_CONFIG"],
[AS_IF([test -x "${rra_krb4_root}/bin/krb5-config"],
[KRB5_CONFIG="${rra_krb4_root}/bin/krb5-config"])],
[AC_PATH_PROG([KRB5_CONFIG], [krb5-config])])
- AS_IF([test x"$KRB5_CONFIG" != x],
+ AS_IF([test x"$KRB5_CONFIG" != x && test -x "$KRB5_CONFIG"],
[AC_CACHE_CHECK([for krb4 support in krb5-config],
[rra_cv_lib_krb4_config],
[AS_IF(["$KRB5_CONFIG" | grep krb4 > /dev/null 2>&1],
@@ -138,7 +146,8 @@ AS_IF([test x"$rra_reduced_depends" = xtrue],
KRB4_LIBS=`"$KRB5_CONFIG" --libs krb4`],
[_RRA_LIB_KRB4_PATHS
_RRA_LIB_KRB4_MANUAL])
- KRB4_CPPFLAGS=`echo "$KRB5_CPPFLAGS" | sed 's%-I/usr/include ?%%'`],
+ KRB4_CPPFLAGS=`echo "$KRB5_CPPFLAGS" | sed 's%-I/usr/include ?%%'`
+ _RRA_LIB_KRB4_CHECK],
[_RRA_LIB_KRB4_PATHS
_RRA_LIB_KRB4_MANUAL])])
_RRA_LIB_KRB4_EXTRA])
diff --git a/m4/krb5.m4 b/m4/krb5.m4
index c7aa5bf..934be0c 100644
--- a/m4/krb5.m4
+++ b/m4/krb5.m4
@@ -132,6 +132,19 @@ AC_DEFUN([_RRA_LIB_KRB5_MANUAL],
[AC_CHECK_HEADERS([et/com_err.h])])])])
RRA_LIB_KRB5_RESTORE])
+dnl Sanity-check the results of krb5-config and be sure we can really link a
+dnl Kerberos program. The first option says whether to fail if Kerberos was
+dnl not found. If we shouldn't fail, clear KRB5_CPPFLAGS and KRB5_LIBS so
+dnl that we know we don't have usable flags.
+AC_DEFUN([_RRA_LIB_KRB5_CHECK],
+[RRA_LIB_KRB5_SWITCH
+ AC_CHECK_FUNC([krb5_init_context], ,
+ [AS_IF([test x"$1" = xtrue],
+ [AC_MSG_FAILURE([krb5-config results fail for Kerberos v5])])
+ KRB5_CPPFLAGS=
+ KRB5_LIBS=])
+ RRA_LIB_KRB5_RESTORE])
+
dnl The core of the library checking, shared between RRA_LIB_KRB5 and
dnl RRA_LIB_KRB5_OPTIONAL. The single argument, if "true", says to fail if
dnl Kerberos could not be found.
@@ -141,11 +154,11 @@ AC_DEFUN([_RRA_LIB_KRB5_INTERNAL],
[_RRA_LIB_KRB5_PATHS
_RRA_LIB_KRB5_REDUCED([$1])],
[AC_ARG_VAR([KRB5_CONFIG], [Path to krb5-config])
- AS_IF([test x"$rra_krb5_root" != x],
+ AS_IF([test x"$rra_krb5_root" != x && test -z "$KRB5_CONFIG"],
[AS_IF([test -x "${rra_krb5_root}/bin/krb5-config"],
[KRB5_CONFIG="${rra_krb5_root}/bin/krb5-config"])],
[AC_PATH_PROG([KRB5_CONFIG], [krb5-config])])
- AS_IF([test x"$KRB5_CONFIG" != x],
+ AS_IF([test x"$KRB5_CONFIG" != x && test -x "$KRB5_CONFIG"],
[AC_CACHE_CHECK([for krb5 support in krb5-config],
[rra_cv_lib_krb5_config],
[AS_IF(["$KRB5_CONFIG" | grep krb5 > /dev/null 2>&1],
@@ -157,6 +170,7 @@ AC_DEFUN([_RRA_LIB_KRB5_INTERNAL],
[KRB5_CPPFLAGS=`"$KRB5_CONFIG" --cflags`
KRB5_LIBS=`"$KRB5_CONFIG" --libs`])
KRB5_CPPFLAGS=`echo "$KRB5_CPPFLAGS" | sed 's%-I/usr/include ?%%'`
+ _RRA_LIB_KRB5_CHECK([$1])
RRA_LIB_KRB5_SWITCH
AC_CHECK_FUNCS([krb5_get_error_message],
[AC_CHECK_FUNCS([krb5_free_error_message])],
@@ -189,7 +203,7 @@ AC_DEFUN([RRA_LIB_KRB5],
[Location of Kerberos v5 headers and libraries])],
[AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
[rra_krb5_root="$withval"])])
- _RRA_LIB_KRB5_INTERNAL])
+ _RRA_LIB_KRB5_INTERNAL([true])])
dnl The main macro for packages with optional Kerberos support.
AC_DEFUN([RRA_LIB_KRB5_OPTIONAL],
diff --git a/m4/lib-depends.m4 b/m4/lib-depends.m4
index 54a8f43..5f4c284 100644
--- a/m4/lib-depends.m4
+++ b/m4/lib-depends.m4
@@ -13,6 +13,7 @@ dnl
dnl Written by Russ Allbery <rra@stanford.edu>
dnl Copyright 2005, 2006, 2007
dnl Board of Trustees, Leland Stanford Jr. University
+dnl
dnl See LICENSE for licensing terms.
AC_DEFUN([RRA_ENABLE_REDUCED_DEPENDS],
diff --git a/m4/remctl.m4 b/m4/remctl.m4
index 2941f19..5cebc68 100644
--- a/m4/remctl.m4
+++ b/m4/remctl.m4
@@ -13,6 +13,7 @@ dnl This macro depends on RRA_ENABLE_REDUCED_DEPENDS and RRA_LIB_GSSAPI.
dnl
dnl Written by Russ Allbery <rra@stanford.edu>
dnl Copyright 2008 Board of Trustees, Leland Stanford Jr. University
+dnl
dnl See LICENSE for licensing terms.
dnl Set CPPFLAGS, LDFLAGS, and LIBS to values including the Kerberos v5
@@ -48,20 +49,20 @@ AC_DEFUN([_RRA_LIB_REMCTL_PATHS],
dnl The main macro.
AC_DEFUN([RRA_LIB_REMCTL],
[AC_REQUIRE([RRA_ENABLE_REDUCED_DEPENDS])
-rra_remctl_root=
-REMCTL_CPPFLAGS=
-REMCTL_LDFLAGS=
-REMCTL_LIBS=
-AC_SUBST([REMCTL_CPPFLAGS])
-AC_SUBST([REMCTL_LDFLAGS])
-AC_SUBST([REMCTL_LIBS])
-AC_ARG_WITH([remctl],
+ rra_remctl_root=
+ REMCTL_CPPFLAGS=
+ REMCTL_LDFLAGS=
+ REMCTL_LIBS=
+ AC_SUBST([REMCTL_CPPFLAGS])
+ AC_SUBST([REMCTL_LDFLAGS])
+ AC_SUBST([REMCTL_LIBS])
+ AC_ARG_WITH([remctl],
[AC_HELP_STRING([--with-remctl=DIR],
[Location of remctl headers and libraries])],
[AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
[rra_remctl_root="$withval"])])
-_RRA_LIB_REMCTL_PATHS
-AS_IF([test x"$rra_reduced_depends" = xtrue],
+ _RRA_LIB_REMCTL_PATHS
+ AS_IF([test x"$rra_reduced_depends" = xtrue],
[REMCTL_LIBS="-lremctl"],
[RRA_LIB_GSSAPI
REMCTL_CPPFLAGS="$REMCTL_CPPFLAGS $GSSAPI_CPPFLAGS"
diff --git a/m4/snprintf.m4 b/m4/snprintf.m4
index 335a937..8ab3689 100644
--- a/m4/snprintf.m4
+++ b/m4/snprintf.m4
@@ -11,7 +11,7 @@ dnl Provides RRA_FUNC_SNPRINTF, which adds snprintf.o to LIBOBJS unless a
dnl fully working snprintf is found.
dnl
dnl Written by Russ Allbery <rra@stanford.edu>
-dnl Copyright 2006 Board of Trustees, Leland Stanford Jr. University
+dnl Copyright 2006, 2008 Board of Trustees, Leland Stanford Jr. University
dnl See LICENSE for licensing terms.
dnl Source used by RRA_FUNC_SNPRINTF.
@@ -47,9 +47,7 @@ AC_DEFUN([RRA_FUNC_SNPRINTF],
[rra_cv_func_snprintf_works=yes],
[rra_cv_func_snprintf_works=no],
[rra_cv_func_snprintf_works=no])])
-if test "$rra_cv_func_snprintf_works" = yes ; then
- AC_DEFINE([HAVE_SNPRINTF], 1,
- [Define if your system has a working snprintf function.])
-else
- AC_LIBOBJ([snprintf])
-fi])
+AS_IF([test "$rra_cv_func_snprintf_works" = yes],
+ [AC_DEFINE([HAVE_SNPRINTF], 1,
+ [Define if your system has a working snprintf function.])],
+ [AC_LIBOBJ([snprintf])])])
diff --git a/m4/vamacros.m4 b/m4/vamacros.m4
index c343d9f..8946d8b 100644
--- a/m4/vamacros.m4
+++ b/m4/vamacros.m4
@@ -15,7 +15,8 @@ dnl
dnl They set HAVE_C99_VAMACROS or HAVE_GNU_VAMACROS as appropriate.
dnl
dnl Written by Russ Allbery <rra@stanford.edu>
-dnl Copyright 2006 Board of Trustees, Leland Stanford Jr. University
+dnl Copyright 2006, 2008 Board of Trustees, Leland Stanford Jr. University
+dnl
dnl See LICENSE for licensing terms.
AC_DEFUN([RRA_C_C99_VAMACROS],
@@ -23,21 +24,21 @@ AC_DEFUN([RRA_C_C99_VAMACROS],
[AC_TRY_COMPILE(
[#include <stdio.h>
#define error(...) fprintf(stderr, __VA_ARGS__)],
-[error("foo"); error("foo %d", 0); return 0;],
-[rra_cv_c_c99_vamacros=yes], [rra_cv_c_c99_vamacros=no])])
-if test $rra_cv_c_c99_vamacros = yes ; then
- AC_DEFINE([HAVE_C99_VAMACROS], 1,
- [Define if the compiler supports C99 variadic macros.])
-fi])
+ [error("foo"); error("foo %d", 0); return 0;],
+ [rra_cv_c_c99_vamacros=yes],
+ [rra_cv_c_c99_vamacros=no])])
+AS_IF([test $rra_cv_c_c99_vamacros = yes],
+ [AC_DEFINE([HAVE_C99_VAMACROS], 1,
+ [Define if the compiler supports C99 variadic macros.])])])
AC_DEFUN([RRA_C_GNU_VAMACROS],
[AC_CACHE_CHECK([for GNU-style variadic macros], [rra_cv_c_gnu_vamacros],
[AC_TRY_COMPILE(
[#include <stdio.h>
#define error(args...) fprintf(stderr, args)],
-[error("foo"); error("foo %d", 0); return 0;],
-[rra_cv_c_gnu_vamacros=yes], [rra_cv_c_gnu_vamacros=no])])
-if test $rra_cv_c_gnu_vamacros = yes ; then
- AC_DEFINE([HAVE_GNU_VAMACROS], 1,
- [Define if the compiler supports GNU-style variadic macros.])
-fi])
+ [error("foo"); error("foo %d", 0); return 0;],
+ [rra_cv_c_gnu_vamacros=yes],
+ [rra_cv_c_gnu_vamacros=no])])
+AS_IF([test $rra_cv_c_gnu_vamacros = yes],
+ [AC_DEFINE([HAVE_GNU_VAMACROS], 1,
+ [Define if the compiler supports GNU-style variadic macros.])])])
diff --git a/portable/asprintf.c b/portable/asprintf.c
index 56a69c4..9cae827 100644
--- a/portable/asprintf.c
+++ b/portable/asprintf.c
@@ -1,19 +1,21 @@
-/* $Id$
-**
-** Replacement for a missing asprintf and vasprintf.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** This work is hereby placed in the public domain by its author.
-**
-** Provides the same functionality as the standard GNU library routines
-** asprintf and vasprintf for those platforms that don't have them.
-*/
+/* $Id$
+ *
+ * Replacement for a missing asprintf and vasprintf.
+ *
+ * Provides the same functionality as the standard GNU library routines
+ * asprintf and vasprintf for those platforms that don't have them.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * This work is hereby placed in the public domain by its author.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
-/* If we're running the test suite, rename the functions to avoid conflicts
- with the system versions. */
+/*
+ * If we're running the test suite, rename the functions to avoid conflicts
+ * with the system versions.
+ */
#if TESTING
# define asprintf test_asprintf
# define vasprintf test_vasprintf
diff --git a/portable/dummy.c b/portable/dummy.c
index e5a6224..66341c3 100644
--- a/portable/dummy.c
+++ b/portable/dummy.c
@@ -1,15 +1,14 @@
-/* $Id$
-**
-** Dummy symbol to prevent an empty library.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** This work is hereby placed in the public domain by its author.
-**
-** On platforms that already have all of the functions that libportable would
-** supply, Automake builds an empty library and then calls ar with
-** nonsensical arguments. Ensure that libportable always contains at least
-** one symbol.
-*/
+/* $Id$
+ *
+ * Dummy symbol to prevent an empty library.
+ *
+ * On platforms that already have all of the functions that libportable would
+ * supply, Automake builds an empty library and then calls ar with nonsensical
+ * arguments. Ensure that libportable always contains at least one symbol.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * This work is hereby placed in the public domain by its author.
+ */
/* Prototype to avoid gcc warnings. */
int portable_dummy(void);
diff --git a/portable/snprintf.c b/portable/snprintf.c
index bef3da7..3c39de8 100644
--- a/portable/snprintf.c
+++ b/portable/snprintf.c
@@ -1,18 +1,20 @@
-/* $Id$
-**
-** Replacement for a missing snprintf or vsnprintf.
-**
-** The following implementation of snprintf was taken mostly verbatim from
-** <http://www.fiction.net/~blong/programs/>; it is the version of snprintf
-** used in Mutt.
-**
-** Please do not reformat or otherwise change this file more than
-** necessary so that later merges with the original source are easy.
-** Bug fixes and improvements should be sent back to the original author.
-*/
-
-/* If we're running the test suite, rename snprintf and vsnprintf to avoid
- conflicts with the system version. */
+/* $Id$
+ *
+ * Replacement for a missing snprintf or vsnprintf.
+ *
+ * The following implementation of snprintf was taken mostly verbatim from
+ * <http://www.fiction.net/~blong/programs/>; it is the version of snprintf
+ * used in Mutt.
+ *
+ * Please do not reformat or otherwise change this file more than necessary so
+ * that later merges with the original source are easy. Bug fixes and
+ * improvements should be sent back to the original author.
+ */
+
+/*
+ * If we're running the test suite, rename snprintf and vsnprintf to avoid
+ * conflicts with the system version.
+ */
#if TESTING
# define snprintf test_snprintf
# define vsnprintf test_vsnprintf
diff --git a/portable/stdbool.h b/portable/stdbool.h
new file mode 100644
index 0000000..61dd8a1
--- /dev/null
+++ b/portable/stdbool.h
@@ -0,0 +1,43 @@
+/* $Id$
+ *
+ * Portability wrapper around <stdbool.h>.
+ *
+ * Provides the bool and _Bool types and the true and false constants,
+ * following the C99 specification, on hosts that don't have stdbool.h. This
+ * logic is based heavily on the example in the Autoconf manual.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * This work is hereby placed in the public domain by its author.
+ */
+
+#ifndef PORTABLE_STDBOOL_H
+#define PORTABLE_STDBOOL_H 1
+
+#if HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+# if !HAVE__BOOL
+# ifdef __cplusplus
+typedef bool _Bool;
+# 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
+#endif
+
+/*
+ * If we define bool and don't tell Perl, it will try to define its own and
+ * fail. Only of interest for programs that also include Perl headers.
+ */
+#ifndef HAS_BOOL
+# define HAS_BOOL 1
+#endif
+
+#endif /* !PORTABLE_STDBOOL_H */
diff --git a/portable/strlcat.c b/portable/strlcat.c
index 971a348..4816f90 100644
--- a/portable/strlcat.c
+++ b/portable/strlcat.c
@@ -15,7 +15,7 @@
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
/*
* If we're running the test suite, rename strlcat to avoid conflicts with
diff --git a/portable/strlcpy.c b/portable/strlcpy.c
index 1dd49a3..d281645 100644
--- a/portable/strlcpy.c
+++ b/portable/strlcpy.c
@@ -14,7 +14,7 @@
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
/*
* If we're running the test suite, rename strlcpy to avoid conflicts with
diff --git a/portable/system.h b/portable/system.h
new file mode 100644
index 0000000..1408ba7
--- /dev/null
+++ b/portable/system.h
@@ -0,0 +1,111 @@
+/* $Id$
+ *
+ * Declarations of routines and variables in the C library. Including this
+ * file is the equivalent of including all of the following headers, portably:
+ *
+ * #include <sys/types.h>
+ * #include <stdarg.h>
+ * #include <stdbool.h>
+ * #include <stdio.h>
+ * #include <stdlib.h>
+ * #include <stddef.h>
+ * #include <stdint.h>
+ * #include <string.h>
+ * #include <unistd.h>
+ *
+ * Missing functions are provided via #define or prototyped if available.
+ * Also provides some standard #defines.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * This work is hereby placed in the public domain by its author.
+ */
+
+#ifndef PORTABLE_SYSTEM_H
+#define PORTABLE_SYSTEM_H 1
+
+/* Make sure we have our configuration information. */
+#include <config.h>
+
+/* BEGIN_DECL and __attribute__. */
+#include <portable/macros.h>
+
+/* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+/* SCO OpenServer gets int32_t from here. */
+#if HAVE_SYS_BITYPES_H
+# include <sys/bitypes.h>
+#endif
+
+/* Get the bool type. */
+#include <portable/stdbool.h>
+
+BEGIN_DECLS
+
+/*
+ * Provide prototypes for functions not declared in system headers. Use the
+ * HAVE_DECL macros for those functions that may be prototyped but
+ * implemented incorrectly or implemented without a prototype.
+ */
+#if !HAVE_ASPRINTF
+extern int asprintf(char **, const char *, ...);
+extern int vasprintf(char **, const char *, va_list);
+#endif
+#if !HAVE_DECL_SNPRINTF
+extern int snprintf(char *, size_t, const char *, ...)
+ __attribute__((__format__(printf, 3, 4)));
+#endif
+#if !HAVE_DECL_VSNPRINTF
+extern int vsnprintf(char *, size_t, const char *, va_list);
+#endif
+#if !HAVE_STRLCAT
+extern size_t strlcat(char *, const char *, size_t);
+#endif
+#if !HAVE_STRLCPY
+extern size_t strlcpy(char *, const char *, size_t);
+#endif
+
+END_DECLS
+
+/* Windows provides snprintf under a different name. */
+#ifdef _WIN32
+# define snprintf _snprintf
+#endif
+
+/*
+ * POSIX requires that these be defined in <unistd.h>. If one of them has
+ * been defined, all the rest almost certainly have.
+ */
+#ifndef STDIN_FILENO
+# define STDIN_FILENO 0
+# define STDOUT_FILENO 1
+# define STDERR_FILENO 2
+#endif
+
+/*
+ * C99 requires va_copy. Older versions of GCC provide __va_copy. Per the
+ * 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
+#endif
+
+#endif /* !PORTABLE_SYSTEM_H */
diff --git a/system.h b/system.h
deleted file mode 100644
index 0650a2d..0000000
--- a/system.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/* $Id$
-**
-** Declarations of routines and variables in the C library. Including this
-** file is the equivalent of including all of the following headers,
-** portably:
-**
-** #include <sys/types.h>
-** #include <stdarg.h>
-** #include <stdio.h>
-** #include <stdlib.h>
-** #include <stddef.h>
-** #include <string.h>
-** #include <unistd.h>
-**
-** Missing functions are provided via #define or prototyped if available from
-** the util helper library. Also provides some standard #defines.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2006, 2007 Board of Trustees, Leland Stanford Jr. University
-**
-** See LICENSE for licensing terms.
-*/
-
-#ifndef SYSTEM_H
-#define SYSTEM_H 1
-
-/* Make sure we have our configuration information. */
-#include <config.h>
-
-/* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <string.h>
-#include <unistd.h>
-
-/* __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
- could you use the __format__ form of the attributes, which is what we use
- (to avoid confusion with other macros). */
-#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(spec) /* empty */
-# endif
-#endif
-
-/* BEGIN_DECLS is used at the beginning of declarations so that C++
- compilers don't mangle their names. END_DECLS is used at the end. */
-#undef BEGIN_DECLS
-#undef END_DECLS
-#ifdef __cplusplus
-# define BEGIN_DECLS extern "C" {
-# define END_DECLS }
-#else
-# define BEGIN_DECLS /* empty */
-# define END_DECLS /* empty */
-#endif
-
-BEGIN_DECLS
-
-/* Provide prototypes for functions not declared in system headers. Use the
- HAVE_DECL macros for those functions that may be prototyped but
- implemented incorrectly or implemented without a prototype. */
-#if !HAVE_ASPRINTF
-extern int asprintf(char **, const char *, ...);
-extern int vasprintf(char **, const char *, va_list);
-#endif
-#if !HAVE_DECL_SNPRINTF
-extern int snprintf(char *, size_t, const char *, ...)
- __attribute__((__format__(printf, 3, 4)));
-#endif
-#if !HAVE_DECL_VSNPRINTF
-extern int vsnprintf(char *, size_t, const char *, va_list);
-#endif
-#if !HAVE_STRLCAT
-extern size_t strlcat(char *, const char *, size_t);
-#endif
-#if !HAVE_STRLCPY
-extern size_t strlcpy(char *, const char *, size_t);
-#endif
-
-END_DECLS
-
-/* C99 requires va_copy. Older versions of GCC provide __va_copy. Per the
- 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
-#endif
-
-#endif /* !SYSTEM_H */
diff --git a/tests/libtest.c b/tests/libtest.c
index 10e6024..76d5207 100644
--- a/tests/libtest.c
+++ b/tests/libtest.c
@@ -1,37 +1,37 @@
-/* $Id$
-**
-** Some utility routines for writing tests.
-**
-** Herein are a variety of utility routines for writing tests. All
-** routines of the form ok*() take a test number and some number of
-** appropriate arguments, check to be sure the results match the expected
-** output using the arguments, and print out something appropriate for that
-** test number. Other utility routines help in constructing more complex
-** tests.
-**
-** Copyright (c) 2004, 2005, 2006
-** by Internet Systems Consortium, Inc. ("ISC")
-** Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-** 2002, 2003 by The Internet Software Consortium and Rich Salz
-**
-** This code is derived from software contributed to the Internet Software
-** Consortium by Rich Salz.
-**
-** Permission to use, copy, modify, and distribute this software for any
-** purpose with or without fee is hereby granted, provided that the above
-** copyright notice and this permission notice appear in all copies.
-**
-** THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-** REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
-** SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
+/* $Id$
+ *
+ * Some utility routines for writing tests.
+ *
+ * Herein are a variety of utility routines for writing tests. All routines
+ * of the form ok*() take a test number and some number of appropriate
+ * arguments, check to be sure the results match the expected output using the
+ * arguments, and print out something appropriate for that test number. Other
+ * utility routines help in constructing more complex tests.
+ *
+ * Copyright 2006, 2007 Board of Trustees, Leland Stanford Jr. University
+ * Copyright (c) 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+ * 2002, 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <sys/time.h>
#include <sys/wait.h>
@@ -44,9 +44,9 @@ char *errors = NULL;
/*
-** Initialize things. Turns on line buffering on stdout and then prints out
-** the number of tests in the test suite.
-*/
+ * Initialize things. Turns on line buffering on stdout and then prints out
+ * the number of tests in the test suite.
+ */
void
test_init(int count)
{
@@ -57,9 +57,9 @@ test_init(int count)
/*
-** Takes a boolean success value and assumes the test passes if that value
-** is true and fails if that value is false.
-*/
+ * Takes a boolean success value and assumes the test passes if that value
+ * is true and fails if that value is false.
+ */
void
ok(int n, int success)
{
@@ -68,9 +68,9 @@ ok(int n, int success)
/*
-** Takes an expected integer and a seen integer and assumes the test passes
-** if those two numbers match.
-*/
+ * Takes an expected integer and a seen integer and assumes the test passes
+ * if those two numbers match.
+ */
void
ok_int(int n, int wanted, int seen)
{
@@ -82,9 +82,9 @@ ok_int(int n, int wanted, int seen)
/*
-** Takes a string and what the string should be, and assumes the test
-** passes if those strings match (using strcmp).
-*/
+ * Takes a string and what the string should be, and assumes the test passes
+ * if those strings match (using strcmp).
+ */
void
ok_string(int n, const char *wanted, const char *seen)
{
@@ -100,9 +100,9 @@ ok_string(int n, const char *wanted, const char *seen)
/*
-** Takes an expected integer and a seen integer and assumes the test passes
-** if those two numbers match.
-*/
+ * Takes an expected integer and a seen integer and assumes the test passes if
+ * those two numbers match.
+ */
void
ok_double(int n, double wanted, double seen)
{
@@ -114,8 +114,8 @@ ok_double(int n, double wanted, double seen)
/*
-** Skip a test.
-*/
+ * Skip a test.
+ */
void
skip(int n, const char *reason)
{
@@ -127,8 +127,8 @@ skip(int n, const char *reason)
/*
-** Report the same status on the next count tests.
-*/
+ * Report the same status on the next count tests.
+ */
void
ok_block(int n, int count, int status)
{
@@ -140,8 +140,8 @@ ok_block(int n, int count, int status)
/*
-** Skip the next count tests.
-*/
+ * Skip the next count tests.
+ */
void
skip_block(int n, int count, const char *reason)
{
@@ -153,9 +153,9 @@ skip_block(int n, int count, const char *reason)
/*
-** An error handler that appends all errors to the errors global. Used by
-** error_capture.
-*/
+ * An error handler that appends all errors to the errors global. Used by
+ * error_capture.
+ */
static void
message_log_buffer(int len, const char *fmt, va_list args, int error UNUSED)
{
@@ -177,10 +177,10 @@ message_log_buffer(int len, const char *fmt, va_list args, int error UNUSED)
/*
-** Turn on the capturing of errors. Errors will be stored in the global
-** errors variable where they can be checked by the test suite. Capturing is
-** turned off with errors_uncapture.
-*/
+ * Turn on the capturing of errors. Errors will be stored in the global
+ * errors variable where they can be checked by the test suite. Capturing is
+ * turned off with errors_uncapture.
+ */
void
errors_capture(void)
{
@@ -194,8 +194,8 @@ errors_capture(void)
/*
-** Turn off the capturing of errors again.
-*/
+ * Turn off the capturing of errors again.
+ */
void
errors_uncapture(void)
{
diff --git a/tests/libtest.h b/tests/libtest.h
index 7c4aca7..ac2b083 100644
--- a/tests/libtest.h
+++ b/tests/libtest.h
@@ -1,49 +1,41 @@
-/* $Id$
-**
-** Some utility routines for writing tests.
-**
-** Copyright (c) 2004, 2005, 2006
-** by Internet Systems Consortium, Inc. ("ISC")
-** Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-** 2002, 2003 by The Internet Software Consortium and Rich Salz
-**
-** This code is derived from software contributed to the Internet Software
-** Consortium by Rich Salz.
-**
-** Permission to use, copy, modify, and distribute this software for any
-** purpose with or without fee is hereby granted, provided that the above
-** copyright notice and this permission notice appear in all copies.
-**
-** THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-** REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
-** SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
+/* $Id$
+ *
+ * Some utility routines for writing tests.
+ *
+ * Copyright 2006, 2007 Board of Trustees, Leland Stanford Jr. University
+ * Copyright (c) 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+ * 2002, 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
#ifndef LIBTEST_H
#define LIBTEST_H 1
#include <config.h>
+#include <portable/macros.h>
-/* BEGIN_DECLS is used at the beginning of declarations so that C++
- compilers don't mangle their names. END_DECLS is used at the end. */
-#undef BEGIN_DECLS
-#undef END_DECLS
-#ifdef __cplusplus
-# define BEGIN_DECLS extern "C" {
-# define END_DECLS }
-#else
-# define BEGIN_DECLS /* empty */
-# define END_DECLS /* empty */
-#endif
-
-/* Used for iterating through arrays. ARRAY_SIZE returns the number of
- elements in the array (useful for a < upper bound in a for loop) and
- 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). */
+/*
+ * Used for iterating through arrays. ARRAY_SIZE returns the number of
+ * elements in the array (useful for a < upper bound in a for loop) and
+ * 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)])
@@ -65,9 +57,11 @@ void skip_block(int n, int count, const char *reason);
/* Print out the number of tests and set standard output to line buffered. */
void test_init(int count);
-/* Turn on capturing of errors with errors_capture. Errors reported by warn
- will be stored in the global errors variable. Turn this off again with
- errors_uncapture. Caller is responsible for freeing errors when done. */
+/*
+ * Turn on capturing of errors with errors_capture. Errors reported by warn
+ * will be stored in the global errors variable. Turn this off again with
+ * errors_uncapture. Caller is responsible for freeing errors when done.
+ */
void errors_capture(void);
void errors_uncapture(void);
diff --git a/tests/portable/asprintf-t.c b/tests/portable/asprintf-t.c
index a79c7f4..d42e740 100644
--- a/tests/portable/asprintf-t.c
+++ b/tests/portable/asprintf-t.c
@@ -1,15 +1,21 @@
-/* $Id$ */
-/* asprintf and vasprintf test suite. */
-
-/* Written by Russ Allbery <rra@stanford.edu>
- Copyright 2006 Board of Trustees, Leland Stanford Jr. University
- See LICENSE for licensing terms. */
+/* $Id$
+ *
+ * asprintf and vasprintf test suite.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2006, 2008 Board of Trustees, Leland Stanford Jr. University
+ *
+ * See LICENSE for licensing terms.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <tests/libtest.h>
+int test_asprintf(char **, const char *, ...);
+int test_vasprintf(char **, const char *, va_list);
+
static int
vatest(char **result, const char *format, ...)
{
@@ -17,7 +23,7 @@ vatest(char **result, const char *format, ...)
int status;
va_start(args, format);
- status = vasprintf(result, format, args);
+ status = test_vasprintf(result, format, args);
va_end(args);
return status;
}
@@ -29,11 +35,11 @@ main(void)
test_init(12);
- ok_int(1, 7, asprintf(&result, "%s", "testing"));
+ ok_int(1, 7, test_asprintf(&result, "%s", "testing"));
ok_string(2, "testing", result);
free(result);
ok(3, 1);
- ok_int(4, 0, asprintf(&result, "%s", ""));
+ ok_int(4, 0, test_asprintf(&result, "%s", ""));
ok_string(5, "", result);
free(result);
ok(6, 1);
diff --git a/tests/portable/snprintf-t.c b/tests/portable/snprintf-t.c
index 9159fcf..c33e0e7 100644
--- a/tests/portable/snprintf-t.c
+++ b/tests/portable/snprintf-t.c
@@ -1,28 +1,30 @@
-/* $Id$ */
-/* snprintf test suite. */
-
-/* Copyright (c) 2004, 2005, 2006
- by Internet Systems Consortium, Inc. ("ISC")
- Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003 by The Internet Software Consortium and Rich Salz
-
- This code is derived from software contributed to the Internet Software
- Consortium by Rich Salz.
-
- Permission to use, copy, modify, and distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+/* $Id$
+ *
+ * snprintf test suite.
+ *
+ * Copyright (c) 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+ * 2002, 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <tests/libtest.h>
@@ -90,6 +92,7 @@ static unsigned long long ullong_nums[] = {
0
};
+
static void
test_format(int n, int truncate, const char *expected, int count,
const char *format, ...)
@@ -113,6 +116,7 @@ test_format(int n, int truncate, const char *expected, int count,
}
}
+
int
main(void)
{
diff --git a/tests/portable/strlcat-t.c b/tests/portable/strlcat-t.c
index 5ad8b6f..c860803 100644
--- a/tests/portable/strlcat-t.c
+++ b/tests/portable/strlcat-t.c
@@ -24,7 +24,7 @@
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <tests/libtest.h>
diff --git a/tests/portable/strlcpy-t.c b/tests/portable/strlcpy-t.c
index 6427374..8fb1f9c 100644
--- a/tests/portable/strlcpy-t.c
+++ b/tests/portable/strlcpy-t.c
@@ -24,7 +24,7 @@
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <tests/libtest.h>
diff --git a/tests/runtests.c b/tests/runtests.c
index d15d19c..abad3b6 100644
--- a/tests/runtests.c
+++ b/tests/runtests.c
@@ -1,52 +1,52 @@
-/* $Id$
-**
-** Run a set of tests, reporting results.
-**
-** Usage:
-**
-** runtests <test-list>
-**
-** Expects a list of executables located in the given file, one line per
-** executable. For each one, runs it as part of a test suite, reporting
-** results. Test output should start with a line containing the number of
-** tests (numbered from 1 to this number), and then each line should be in
-** the following format:
-**
-** ok <number>
-** not ok <number>
-** ok <number> # skip
-**
-** where <number> is the number of the test. ok indicates success, not ok
-** indicates failure, and "# skip" indicates the test was skipped for some
-** reason (maybe because it doesn't apply to this platform).
-**
-** Any bug reports, bug fixes, and improvements are very much welcome and
-** should be sent to the e-mail address below.
-**
-** Copyright 2000, 2001, 2004 Russ Allbery <rra@stanford.edu>
-**
-** Permission is hereby granted, free of charge, to any person obtaining a
-** copy of this software and associated documentation files (the
-** "Software"), to deal in the Software without restriction, including
-** without limitation the rights to use, copy, modify, merge, publish,
-** distribute, sublicense, and/or sell copies of the Software, and to
-** permit persons to whom the Software is furnished to do so, subject to
-** the following conditions:
-**
-** The above copyright notice and this permission notice shall be included
-** in all copies or substantial portions of the Software.
-**
-** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-** CLAIM, DAMAGES OR OTHER 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.
+/* $Id$
+ *
+ * Run a set of tests, reporting results.
+ *
+ * Usage:
+ *
+ * runtests <test-list>
+ *
+ * Expects a list of executables located in the given file, one line per
+ * executable. For each one, runs it as part of a test suite, reporting
+ * results. Test output should start with a line containing the number of
+ * tests (numbered from 1 to this number), and then each line should be in the
+ * following format:
+ *
+ * ok <number>
+ * not ok <number>
+ * ok <number> # skip
+ *
+ * where <number> is the number of the test. ok indicates success, not ok
+ * indicates failure, and "# skip" indicates the test was skipped for some
+ * reason (maybe because it doesn't apply to this platform).
+ *
+ * Any bug reports, bug fixes, and improvements are very much welcome and
+ * should be sent to the e-mail address below.
+ *
+ * Copyright 2000, 2001, 2004, 2006, 2007, 2008
+ * Russ Allbery <rra@stanford.edu>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * 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.
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <ctype.h>
#include <errno.h>
@@ -98,8 +98,10 @@ struct testlist {
struct testlist *next;
};
-/* Header used for test output. %s is replaced by the file name of the list
- of tests. */
+/*
+ * Header used for test output. %s is replaced by the file name of the list
+ * of tests.
+ */
static const char banner[] = "\n\
Running all tests listed in %s. If any tests fail, run the failing\n\
test program by hand to see more details. The test program will have the\n\
@@ -131,7 +133,9 @@ static double tv_seconds(const struct timeval *);
static double tv_sum(const struct timeval *, const struct timeval *);
-/* Report a fatal error, including the results of strerror, and exit. */
+/*
+ * Report a fatal error, including the results of strerror, and exit.
+ */
static void
sysdie(const char *format, ...)
{
@@ -149,7 +153,9 @@ sysdie(const char *format, ...)
}
-/* Allocate memory, reporting a fatal error and exiting on failure. */
+/*
+ * Allocate memory, reporting a fatal error and exiting on failure.
+ */
static void *
x_malloc(size_t size, const char *file, int line)
{
@@ -163,7 +169,9 @@ x_malloc(size_t size, const char *file, int line)
}
-/* Copy a string, reporting a fatal error and exiting on failure. */
+/*
+ * Copy a string, reporting a fatal error and exiting on failure.
+ */
static char *
x_strdup(const char *s, const char *file, int line)
{
@@ -180,22 +188,30 @@ x_strdup(const char *s, const char *file, int line)
}
-/* Given a struct timeval, return the number of seconds it represents as a
- double. Use difftime() to convert a time_t to a double. */
+/*
+ * Given a struct timeval, return the number of seconds it represents as a
+ * double. Use difftime() to convert a time_t to a double.
+ */
static double
tv_seconds(const struct timeval *tv)
{
return difftime(tv->tv_sec, 0) + tv->tv_usec * 1e-6;
}
-/* Given two struct timevals, return the difference in seconds. */
+
+/*
+ * Given two struct timevals, return the difference in seconds.
+ */
static double
tv_diff(const struct timeval *tv1, const struct timeval *tv0)
{
return tv_seconds(tv1) - tv_seconds(tv0);
}
-/* Given two struct timevals, return the sum in seconds as a double. */
+
+/*
+ * Given two struct timevals, return the sum in seconds as a double.
+ */
static double
tv_sum(const struct timeval *tv1, const struct timeval *tv2)
{
@@ -203,18 +219,22 @@ tv_sum(const struct timeval *tv1, const struct timeval *tv2)
}
-/* Read the first line of test output, which should contain the range of
- test numbers, and initialize the testset structure. Assume it was zeroed
- before being passed in. Return true if initialization succeeds, false
- otherwise. */
+/*
+ * Read the first line of test output, which should contain the range of
+ * test numbers, and initialize the testset structure. Assume it was zeroed
+ * before being passed in. Return true if initialization succeeds, false
+ * otherwise.
+ */
static int
test_init(const char *line, struct testset *ts)
{
int i;
- /* Prefer a simple number of tests, but if the count is given as a range
- such as 1..10, accept that too for compatibility with Perl's
- Test::Harness. */
+ /*
+ * Prefer a simple number of tests, but if the count is given as a range
+ * such as 1..10, accept that too for compatibility with Perl's
+ * Test::Harness.
+ */
while (isspace((unsigned char)(*line)))
line++;
if (strncmp(line, "1..", 3) == 0)
@@ -236,9 +256,11 @@ test_init(const char *line, struct testset *ts)
}
-/* Start a program, connecting its stdout to a pipe on our end and its
- stderr to /dev/null, and storing the file descriptor to read from in the
- two argument. Returns the PID of the new process. Errors are fatal. */
+/*
+ * Start a program, connecting its stdout to a pipe on our end and its stderr
+ * to /dev/null, and storing the file descriptor to read from in the two
+ * argument. Returns the PID of the new process. Errors are fatal.
+ */
static pid_t
test_start(const char *path, int *fd)
{
@@ -278,7 +300,9 @@ test_start(const char *path, int *fd)
}
-/* Back up over the output saying what test we were executing. */
+/*
+ * Back up over the output saying what test we were executing.
+ */
static void
test_backspace(struct testset *ts)
{
@@ -296,18 +320,22 @@ test_backspace(struct testset *ts)
}
-/* Given a single line of output from a test, parse it and return the
- success status of that test. Anything printed to stdout not matching the
- form /^(not )?ok \d+/ is ignored. Sets ts->current to the test number
- that just reported status. */
+/*
+ * Given a single line of output from a test, parse it and return the success
+ * status of that test. Anything printed to stdout not matching the form
+ * /^(not )?ok \d+/ is ignored. Sets ts->current to the test number that just
+ * reported status.
+ */
static void
test_checkline(const char *line, struct testset *ts)
{
enum test_status status = TEST_PASS;
int current;
- /* If the given line isn't newline-terminated, it was too big for an
- fgets(), which means ignore it. */
+ /*
+ * If the given line isn't newline-terminated, it was too big for an
+ * fgets(), which means ignore it.
+ */
if (line[strlen(line) - 1] != '\n')
return;
@@ -369,11 +397,13 @@ test_checkline(const char *line, struct testset *ts)
}
-/* Print out a range of test numbers, returning the number of characters it
- took up. Add a comma and a space before the range if chars indicates
- that something has already been printed on the line, and print
- ... instead if chars plus the space needed would go over the limit (use a
- limit of 0 to disable this. */
+/*
+ * Print out a range of test numbers, returning the number of characters it
+ * took up. Add a comma and a space before the range if chars indicates that
+ * something has already been printed on the line, and print ... instead if
+ * chars plus the space needed would go over the limit (use a limit of 0 to
+ * disable this.
+ */
static int
test_print_range(int first, int last, int chars, int limit)
{
@@ -404,10 +434,12 @@ test_print_range(int first, int last, int chars, int limit)
}
-/* Summarize a single test set. The second argument is 0 if the set exited
- cleanly, a positive integer representing the exit status if it exited
- with a non-zero status, and a negative integer representing the signal
- that terminated it if it was killed by a signal. */
+/*
+ * Summarize a single test set. The second argument is 0 if the set exited
+ * cleanly, a positive integer representing the exit status if it exited
+ * with a non-zero status, and a negative integer representing the signal
+ * that terminated it if it was killed by a signal.
+ */
static void
test_summarize(struct testset *ts, int status)
{
@@ -479,9 +511,11 @@ test_summarize(struct testset *ts, int status)
}
-/* Given a test set, analyze the results, classify the exit status, handle a
- few special error messages, and then pass it along to test_summarize()
- for the regular output. */
+/*
+ * Given a test set, analyze the results, classify the exit status, handle a
+ * few special error messages, and then pass it along to test_summarize()
+ * for the regular output.
+ */
static int
test_analyze(struct testset *ts)
{
@@ -516,9 +550,11 @@ test_analyze(struct testset *ts)
}
-/* Runs a single test set, accumulating and then reporting the results.
- Returns true if the test set was successfully run and all tests passed,
- false otherwise. */
+/*
+ * Runs a single test set, accumulating and then reporting the results.
+ * Returns true if the test set was successfully run and all tests passed,
+ * false otherwise.
+ */
static int
test_run(struct testset *ts)
{
@@ -528,8 +564,10 @@ test_run(struct testset *ts)
char buffer[BUFSIZ];
char *file;
- /* Initialize the test and our data structures, flagging this set in
- error if the initialization fails. */
+ /*
+ * Initialize the test and our data structures, flagging this set in error
+ * if the initialization fails.
+ */
file = xmalloc(strlen(ts->file) + 3);
strcpy(file, ts->file);
strcat(file, "-t");
@@ -556,8 +594,10 @@ test_run(struct testset *ts)
ts->aborted = 1;
test_backspace(ts);
- /* Close the output descriptor, retrieve the exit status, and pass that
- information to test_analyze() for eventual output. */
+ /*
+ * Close the output descriptor, retrieve the exit status, and pass that
+ * information to test_analyze() for eventual output.
+ */
fclose(output);
child = waitpid(testpid, &ts->status, 0);
if (child == (pid_t) -1) {
@@ -626,9 +666,11 @@ test_fail_summary(const struct testlist *fails)
}
-/* Run a batch of tests from a given file listing each test on a line by
- itself. The file must be rewindable. Returns true iff all tests
- passed. */
+/*
+ * Run a batch of tests from a given file listing each test on a line by
+ * itself. The file must be rewindable. Returns true iff all tests
+ * passed.
+ */
static int
test_batch(const char *testlist)
{
@@ -648,8 +690,10 @@ test_batch(const char *testlist)
int failed = 0;
int aborted = 0;
- /* Open our file of tests to run and scan it, checking for lines that
- are too long and searching for the longest line. */
+ /*
+ * Open our file of tests to run and scan it, checking for lines that
+ * are too long and searching for the longest line.
+ */
tests = fopen(testlist, "r");
if (!tests)
sysdie("can't open %s", testlist);
@@ -667,8 +711,10 @@ test_batch(const char *testlist)
if (fseek(tests, 0, SEEK_SET) == -1)
sysdie("can't rewind %s", testlist);
- /* Add two to longest and round up to the nearest tab stop. This is how
- wide the column for printing the current test name will be. */
+ /*
+ * Add two to longest and round up to the nearest tab stop. This is how
+ * wide the column for printing the current test name will be.
+ */
longest += 2;
if (longest % 8)
longest += 8 - (longest % 8);
@@ -676,8 +722,10 @@ test_batch(const char *testlist)
/* Start the wall clock timer. */
gettimeofday(&start, NULL);
- /* Now, plow through our tests again, running each one. Check line
- length again out of paranoia. */
+ /*
+ * Now, plow through our tests again, running each one. Check line
+ * length again out of paranoia.
+ */
line = 0;
while (fgets(buffer, sizeof(buffer), tests)) {
line++;
@@ -690,6 +738,8 @@ test_batch(const char *testlist)
fputs(buffer, stdout);
for (i = length; i < longest; i++)
putchar('.');
+ if (isatty(STDOUT_FILENO))
+ fflush(stdout);
memset(&ts, 0, sizeof(ts));
ts.file = xstrdup(buffer);
if (!test_run(&ts)) {
@@ -750,7 +800,9 @@ test_batch(const char *testlist)
}
-/* Main routine. Given a file listing tests, run each test listed. */
+/*
+ * Main routine. Given a file listing tests, run each test listed.
+ */
int
main(int argc, char *argv[])
{
diff --git a/tests/util/concat-t.c b/tests/util/concat-t.c
index c18cd19..2428d71 100644
--- a/tests/util/concat-t.c
+++ b/tests/util/concat-t.c
@@ -1,35 +1,40 @@
-/* $Id$ */
-/* concat test suite. */
-
-/* Copyright (c) 2004, 2005, 2006
- by Internet Systems Consortium, Inc. ("ISC")
- Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003 by The Internet Software Consortium and Rich Salz
-
- This code is derived from software contributed to the Internet Software
- Consortium by Rich Salz.
-
- Permission to use, copy, modify, and distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+/* $Id$
+ *
+ * concat test suite.
+ *
+ * Copyright 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ * 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <tests/libtest.h>
#include <util/util.h>
-#define END (char *) 0
+#define END (char *) 0
+
-/* Memory leaks everywhere! Whoo-hoo! */
+/*
+ * Memory leaks everywhere! Whoo-hoo!
+ */
int
main(void)
{
diff --git a/tests/util/messages-t.c b/tests/util/messages-t.c
index ef58737..434ef56 100644
--- a/tests/util/messages-t.c
+++ b/tests/util/messages-t.c
@@ -1,28 +1,30 @@
-/* $Id$ */
-/* Test suite for error handling routines. */
-
-/* Copyright (c) 2004, 2005, 2006
- by Internet Systems Consortium, Inc. ("ISC")
- Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003 by The Internet Software Consortium and Rich Salz
-
- This code is derived from software contributed to the Internet Software
- Consortium by Rich Salz.
-
- Permission to use, copy, modify, and distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+/* $Id$
+ *
+ * Test suite for error handling routines.
+ *
+ * Copyright 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ * 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <errno.h>
#include <fcntl.h>
@@ -32,14 +34,17 @@
#include <tests/libtest.h>
#include <util/util.h>
-#define END (char *) 0
+#define END (char *) 0
/* Test function type. */
typedef void (*test_function_t)(void);
-/* Fork and execute the provided function, connecting stdout and stderr to a
- pipe. Captures the output into the provided buffer and returns the exit
- status as a waitpid status value. */
+
+/*
+ * Fork and execute the provided function, connecting stdout and stderr to a
+ * pipe. Captures the output into the provided buffer and returns the exit
+ * status as a waitpid status value.
+ */
static int
run_test(test_function_t function, char *buf, size_t buflen)
{
@@ -70,8 +75,10 @@ run_test(test_function_t function, char *buf, size_t buflen)
fflush(stdout);
_exit(0);
} else {
- /* In the parent; close the extra file descriptor, read the output
- if any, and then collect the exit status. */
+ /*
+ * In the parent; close the extra file descriptor, read the output if
+ * any, and then collect the exit status.
+ */
close(fds[1]);
count = 0;
do {
@@ -86,7 +93,10 @@ run_test(test_function_t function, char *buf, size_t buflen)
return rval;
}
-/* Test functions. */
+
+/*
+ * Test functions.
+ */
static void test1(void) { warn("warning"); }
static void test2(void) { die("fatal"); }
static void test3(void) { errno = EPERM; syswarn("permissions"); }
@@ -192,8 +202,11 @@ static void test24(void) {
notice("third");
}
-/* Given the test number, intended exit status and message, and the function
- to run, print ok or not ok. */
+
+/*
+ * Given the test number, intended exit status and message, and the function
+ * to run, print ok or not ok.
+ */
static void
test_error(int n, int status, const char *output, test_function_t function)
{
@@ -214,9 +227,11 @@ test_error(int n, int status, const char *output, test_function_t function)
printf("%sok %d\n", succeeded ? "" : "not ", n);
}
-/* Given the test number, intended status, intended message sans the
- appended strerror output, errno, and the function to run, print ok or not
- ok. */
+
+/*
+ * Given the test number, intended status, intended message sans the appended
+ * strerror output, errno, and the function to run, print ok or not ok.
+ */
static void
test_strerror(int n, int status, const char *output, int error,
test_function_t function)
@@ -228,7 +243,10 @@ test_strerror(int n, int status, const char *output, int error,
free(full_output);
}
-/* Run the tests. */
+
+/*
+ * Run the tests.
+ */
int
main(void)
{
diff --git a/tests/util/xmalloc-t.in b/tests/util/xmalloc-t.in
index 504bbaa..f721822 100644
--- a/tests/util/xmalloc-t.in
+++ b/tests/util/xmalloc-t.in
@@ -3,18 +3,18 @@
#
# Test suite for xmalloc and friends.
#
-# Copyright (c) 2004, 2005, 2006
+# Copyright 2004, 2005, 2006
# by Internet Systems Consortium, Inc. ("ISC")
-# Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-# 2002, 2003 by The Internet Software Consortium and Rich Salz
-#
+# Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003 by The Internet Software Consortium and Rich Salz
+#
# This code is derived from software contributed to the Internet Software
# Consortium by Rich Salz.
-#
+#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
-#
+#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
@@ -39,7 +39,7 @@ runsuccess () {
printcount "ok"
else
if test $status = 2 ; then
- printcount "ok" "# skip no data limit support"
+ printcount "ok" "# skip - no data limit support"
else
printcount "not ok"
echo " $output"
@@ -59,7 +59,7 @@ runfailure () {
printcount "ok"
else
if test $status = 2 ; then
- printcount "ok" "# skip no data limit support"
+ printcount "ok" "# skip - no data limit support"
else
printcount "not ok"
echo " saw: $output"
@@ -94,28 +94,28 @@ runsuccess "v" "128000" "0"
# Now limit our memory to 120KB and then try the large ones again, all of
# which should fail.
runfailure "m" "128000" "120000" \
- "failed to malloc 128000 bytes at xmalloc.c line 54"
+ "failed to malloc 128000 bytes at xmalloc.c line 61"
runfailure "r" "128000" "120000" \
- "failed to realloc 128000 bytes at xmalloc.c line 80"
+ "failed to realloc 128000 bytes at xmalloc.c line 90"
runfailure "s" "64000" "120000" \
- "failed to strdup 64000 bytes at xmalloc.c line 109"
+ "failed to strdup 64000 bytes at xmalloc.c line 121"
runfailure "n" "64000" "120000" \
- "failed to strndup 64000 bytes at xmalloc.c line 133"
+ "failed to strndup 64000 bytes at xmalloc.c line 148"
runfailure "c" "128000" "120000" \
- "failed to calloc 128000 bytes at xmalloc.c line 155"
+ "failed to calloc 128000 bytes at xmalloc.c line 172"
runfailure "a" "64000" "120000" \
- "failed to asprintf 64000 bytes at xmalloc.c line 177"
+ "failed to asprintf 64000 bytes at xmalloc.c line 241"
runfailure "v" "64000" "120000" \
- "failed to vasprintf 64000 bytes at xmalloc.c line 196"
+ "failed to vasprintf 64000 bytes at xmalloc.c line 217"
# Check our custom error handler.
-runfailure "M" "128000" "120000" "malloc 128000 xmalloc.c 54"
-runfailure "R" "128000" "120000" "realloc 128000 xmalloc.c 80"
-runfailure "S" "64000" "120000" "strdup 64000 xmalloc.c 109"
-runfailure "N" "64000" "120000" "strndup 64000 xmalloc.c 133"
-runfailure "C" "128000" "120000" "calloc 128000 xmalloc.c 155"
-runfailure "A" "64000" "120000" "asprintf 64000 xmalloc.c 177"
-runfailure "V" "64000" "120000" "vasprintf 64000 xmalloc.c 196"
+runfailure "M" "128000" "120000" "malloc 128000 xmalloc.c 61"
+runfailure "R" "128000" "120000" "realloc 128000 xmalloc.c 90"
+runfailure "S" "64000" "120000" "strdup 64000 xmalloc.c 121"
+runfailure "N" "64000" "120000" "strndup 64000 xmalloc.c 148"
+runfailure "C" "128000" "120000" "calloc 128000 xmalloc.c 172"
+runfailure "A" "64000" "120000" "asprintf 64000 xmalloc.c 241"
+runfailure "V" "64000" "120000" "vasprintf 64000 xmalloc.c 217"
# Check the smaller ones again just for grins.
runsuccess "m" "21" "96000"
diff --git a/tests/util/xmalloc.c b/tests/util/xmalloc.c
index 4327681..699d0c4 100644
--- a/tests/util/xmalloc.c
+++ b/tests/util/xmalloc.c
@@ -1,50 +1,57 @@
-/* $Id$ */
-/* Test suite for xmalloc and family. */
-
-/* Copyright (c) 2004, 2005, 2006
- by Internet Systems Consortium, Inc. ("ISC")
- Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003 by The Internet Software Consortium and Rich Salz
-
- This code is derived from software contributed to the Internet Software
- Consortium by Rich Salz.
-
- Permission to use, copy, modify, and distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+/* $Id$
+ *
+ * Test suite for xmalloc and family.
+ *
+ * Copyright 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ * 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <ctype.h>
#include <errno.h>
#include <sys/time.h>
-#include <unistd.h>
/* Linux requires sys/time.h be included before sys/resource.h. */
#include <sys/resource.h>
#include <util/util.h>
-/* A customized error handler for checking xmalloc's support of them.
- Prints out the error message and exits with status 1. */
+
+/*
+ * A customized error handler for checking xmalloc's support of them. Prints
+ * out the error message and exits with status 1.
+ */
static void
test_handler(const char *function, size_t size, const char *file, int line)
{
die("%s %lu %s %d", function, (unsigned long) size, file, line);
}
-/* Allocate the amount of memory given and write to all of it to make sure
- we can, returning true if that succeeded and false on any sort of
- detectable error. */
+
+/*
+ * Allocate the amount of memory given and write to all of it to make sure we
+ * can, returning true if that succeeded and false on any sort of detectable
+ * error.
+ */
static int
test_malloc(size_t size)
{
@@ -63,9 +70,12 @@ test_malloc(size_t size)
return 1;
}
-/* Allocate half the memory given, write to it, then reallocate to the
- desired size, writing to the rest and then checking it all. Returns true
- on success, false on any failure. */
+
+/*
+ * Allocate half the memory given, write to it, then reallocate to the desired
+ * size, writing to the rest and then checking it all. Returns true on
+ * success, false on any failure.
+ */
static int
test_realloc(size_t size)
{
@@ -92,9 +102,11 @@ test_realloc(size_t size)
return 1;
}
-/* Generate a string of the size indicated, call xstrdup on it, and then
- ensure the result matches. Returns true on success, false on any
- failure. */
+
+/*
+ * Generate a string of the size indicated, call xstrdup on it, and then
+ * ensure the result matches. Returns true on success, false on any failure.
+ */
static int
test_strdup(size_t size)
{
@@ -115,9 +127,12 @@ test_strdup(size_t size)
return (match == 0);
}
-/* Generate a string of the size indicated plus some, call xstrndup on it, and
- then ensure the result matches. Returns true on success, false on any
- failure. */
+
+/*
+ * Generate a string of the size indicated plus some, call xstrndup on it, and
+ * then ensure the result matches. Returns true on success, false on any
+ * failure.
+ */
static int
test_strndup(size_t size)
{
@@ -140,9 +155,11 @@ test_strndup(size_t size)
return (match == 0 && toomuch != 0);
}
-/* Allocate the amount of memory given and check that it's all zeroed,
- returning true if that succeeded and false on any sort of detectable
- error. */
+
+/*
+ * Allocate the amount of memory given and check that it's all zeroed,
+ * returning true if that succeeded and false on any sort of detectable error.
+ */
static int
test_calloc(size_t size)
{
@@ -162,8 +179,11 @@ test_calloc(size_t size)
return 1;
}
-/* Test asprintf with a large string (essentially using it as strdup).
- Returns true if successful, false otherwise. */
+
+/*
+ * Test asprintf with a large string (essentially using it as strdup).
+ * Returns true if successful, false otherwise.
+ */
static int
test_asprintf(size_t size)
{
@@ -185,6 +205,7 @@ test_asprintf(size_t size)
return 1;
}
+
/* Wrapper around vasprintf to do the va_list stuff. */
static int
xvasprintf_wrapper(char **strp, const char *format, ...)
@@ -198,8 +219,11 @@ xvasprintf_wrapper(char **strp, const char *format, ...)
return status;
}
-/* Test vasprintf with a large string (essentially using it as strdup).
- Returns true if successful, false otherwise. */
+
+/*
+ * Test vasprintf with a large string (essentially using it as strdup).
+ * Returns true if successful, false otherwise.
+ */
static int
test_vasprintf(size_t size)
{
@@ -221,8 +245,11 @@ test_vasprintf(size_t size)
return 1;
}
-/* Take the amount of memory to allocate in bytes as a command-line argument
- and call test_malloc with that amount of memory. */
+
+/*
+ * Take the amount of memory to allocate in bytes as a command-line argument
+ * and call test_malloc with that amount of memory.
+ */
int
main(int argc, char *argv[])
{
@@ -243,11 +270,13 @@ main(int argc, char *argv[])
if (limit == 0 && errno != 0)
sysdie("Invalid limit");
- /* If a memory limit was given and we can set memory limits, set it.
- Otherwise, exit 2, signalling to the driver that the test should be
- skipped. We do this here rather than in the driver due to some
- pathological problems with Linux (setting ulimit in the shell caused
- the shell to die). */
+ /*
+ * If a memory limit was given and we can set memory limits, set it.
+ * Otherwise, exit 2, signalling to the driver that the test should be
+ * skipped. We do this here rather than in the driver due to some
+ * pathological problems with Linux (setting ulimit in the shell caused
+ * the shell to die).
+ */
if (limit > 0) {
#if HAVE_SETRLIMIT && defined(RLIMIT_DATA)
rl.rlim_cur = limit;
@@ -269,9 +298,11 @@ main(int argc, char *argv[])
code = tolower(code);
}
- /* Decide if the allocation should fail. If it should, set willfail to
- 2, so that if it unexpectedly succeeds, we exit with a status
- indicating that the test should be skipped. */
+ /*
+ * Decide if the allocation should fail. If it should, set willfail to 2,
+ * so that if it unexpectedly succeeds, we exit with a status indicating
+ * that the test should be skipped.
+ */
max = size;
if (code == 's' || code == 'n' || code == 'a' || code == 'v')
max *= 2;
diff --git a/util/concat.c b/util/concat.c
index 65ca04c..1d08e08 100644
--- a/util/concat.c
+++ b/util/concat.c
@@ -1,39 +1,42 @@
-/* $Id$
-**
-** Concatenate strings with dynamic memory allocation.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** This work is hereby placed in the public domain by its author.
-**
-** Usage:
-**
-** string = concat(string1, string2, ..., (char *) 0);
-** path = concatpath(base, name);
-**
-** Dynamically allocates (using xmalloc) sufficient memory to hold all of
-** the strings given and then concatenates them together into that
-** allocated memory, returning a pointer to it. Caller is responsible for
-** freeing. Assumes xmalloc is available. The last argument must be a
-** null pointer (to a char *, if you actually find a platform where it
-** matters).
-**
-** concatpath is similar, except that it only takes two arguments. If the
-** second argument begins with / or ./, a copy of it is returned;
-** otherwise, the first argument, a slash, and the second argument are
-** concatenated together and returned. This is useful for building file
-** names where names that aren't fully qualified are qualified with some
-** particular directory.
-*/
+/* $Id$
+ *
+ * Concatenate strings with dynamic memory allocation.
+ *
+ * Usage:
+ *
+ * string = concat(string1, string2, ..., (char *) 0);
+ * path = concatpath(base, name);
+ *
+ * Dynamically allocates (using xmalloc) sufficient memory to hold all of the
+ * strings given and then concatenates them together into that allocated
+ * memory, returning a pointer to it. Caller is responsible for freeing.
+ * Assumes xmalloc is available. The last argument must be a null pointer (to
+ * a char *, if you actually find a platform where it matters).
+ *
+ * concatpath is similar, except that it only takes two arguments. If the
+ * second argument begins with / or ./, a copy of it is returned; otherwise,
+ * the first argument, a slash, and the second argument are concatenated
+ * together and returned. This is useful for building file names where names
+ * that aren't fully qualified are qualified with some particular directory.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * This work is hereby placed in the public domain by its author.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <util/util.h>
/* Abbreviation for cleaner code. */
-#define VA_NEXT(var, type) ((var) = (type) va_arg(args, type))
+#define VA_NEXT(var, type) ((var) = (type) va_arg(args, type))
-/* ANSI C requires at least one named parameter. */
+
+/*
+ * Concatenate all of the arguments into a newly allocated string. ANSI C
+ * requires at least one named parameter, but it's not treated any different
+ * than the rest.
+ */
char *
concat(const char *first, ...)
{
@@ -49,10 +52,12 @@ concat(const char *first, ...)
va_end(args);
length++;
- /* Create the string. Doing the copy ourselves avoids useless string
- traversals of result, if using strcat, or string, if using strlen to
- increment a pointer into result, at the cost of losing the native
- optimization of strcat if any. */
+ /*
+ * Create the string. Doing the copy ourselves avoids useless string
+ * traversals of result, if using strcat, or string, if using strlen to
+ * increment a pointer into result, at the cost of losing the native
+ * optimization of strcat if any.
+ */
result = xmalloc(length);
p = result;
va_start(args, first);
@@ -66,6 +71,10 @@ concat(const char *first, ...)
}
+/*
+ * Concatenate name with base, unless name begins with / or ./. Return the
+ * new string in newly allocated memory.
+ */
char *
concatpath(const char *base, const char *name)
{
diff --git a/util/messages-krb5.c b/util/messages-krb5.c
index 314f96a..caf29b9 100644
--- a/util/messages-krb5.c
+++ b/util/messages-krb5.c
@@ -14,7 +14,7 @@
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <krb5.h>
#if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) && !defined(HAVE_KRB5_GET_ERR_TEXT)
diff --git a/util/messages.c b/util/messages.c
index 4a975c3..7714c2b 100644
--- a/util/messages.c
+++ b/util/messages.c
@@ -1,82 +1,95 @@
-/* $Id$
-**
-** Message and error reporting (possibly fatal).
-**
-** Usage:
-**
-** extern int cleanup(void);
-** extern void log(int, const char *, va_list, int);
-**
-** message_fatal_cleanup = cleanup;
-** message_program_name = argv[0];
-**
-** warn("Something horrible happened at %lu", time);
-** syswarn("Couldn't unlink temporary file %s", tmpfile);
-**
-** die("Something fatal happened at %lu", time);
-** sysdie("open of %s failed", filename);
-**
-** debug("Some debugging message about %s", string);
-** notice("Informational notices");
-**
-** message_handlers_warn(1, log);
-** warn("This now goes through our log function");
-**
-** These functions implement message reporting through user-configurable
-** handler functions. debug() only does something if DEBUG is defined, and
-** notice() and warn() just output messages as configured. die() similarly
-** outputs a message but then exits, normally with a status of 1.
-**
-** The sys* versions do the same, but append a colon, a space, and the
-** results of strerror(errno) to the end of the message. All functions
-** accept printf-style formatting strings and arguments.
-**
-** If message_fatal_cleanup is non-NULL, it is called before exit by die and
-** sysdie and its return value is used as the argument to exit. It is a
-** pointer to a function taking no arguments and returning an int, and can be
-** used to call cleanup functions or to exit in some alternate fashion (such
-** as by calling _exit).
-**
-** If message_program_name is non-NULL, the string it points to, followed by
-** a colon and a space, is prepended to all error messages logged through the
-** message_log_stdout and message_log_stderr message handlers (the former is
-** the default for notice, and the latter is the default for warn and die).
-**
-** Honoring error_program_name and printing to stderr is just the default
-** handler; with message_handlers_* the handlers for any message function can
-** be changed. By default, notice prints to stdout, warn and die print to
-** stderr, and the others don't do anything at all. These functions take a
-** count of handlers and then that many function pointers, each one to a
-** function that takes a message length (the number of characters snprintf
-** generates given the format and arguments), a format, an argument list as a
-** va_list, and the applicable errno value (if any).
-**
-** Copyright (c) 2004, 2005, 2006
-** by Internet Systems Consortium, Inc. ("ISC")
-** Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-** 2002, 2003 by The Internet Software Consortium and Rich Salz
-**
-** This code is derived from software contributed to the Internet Software
-** Consortium by Rich Salz.
-**
-** Permission to use, copy, modify, and distribute this software for any
-** purpose with or without fee is hereby granted, provided that the above
-** copyright notice and this permission notice appear in all copies.
-**
-** THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-** REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
-** SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+/* $Id$
+ *
+ * Message and error reporting (possibly fatal).
+ *
+ * Usage:
+ *
+ * extern int cleanup(void);
+ * extern void log(int, const char *, va_list, int);
+ *
+ * message_fatal_cleanup = cleanup;
+ * message_program_name = argv[0];
+ *
+ * warn("Something horrible happened at %lu", time);
+ * syswarn("Couldn't unlink temporary file %s", tmpfile);
+ *
+ * die("Something fatal happened at %lu", time);
+ * sysdie("open of %s failed", filename);
+ *
+ * debug("Some debugging message about %s", string);
+ * notice("Informational notices");
+ *
+ * message_handlers_warn(1, log);
+ * warn("This now goes through our log function");
+ *
+ * These functions implement message reporting through user-configurable
+ * handler functions. debug() only does something if DEBUG is defined, and
+ * notice() and warn() just output messages as configured. die() similarly
+ * outputs a message but then exits, normally with a status of 1.
+ *
+ * The sys* versions do the same, but append a colon, a space, and the results
+ * of strerror(errno) to the end of the message. All functions accept
+ * printf-style formatting strings and arguments.
+ *
+ * If message_fatal_cleanup is non-NULL, it is called before exit by die and
+ * sysdie and its return value is used as the argument to exit. It is a
+ * pointer to a function taking no arguments and returning an int, and can be
+ * used to call cleanup functions or to exit in some alternate fashion (such
+ * as by calling _exit).
+ *
+ * If message_program_name is non-NULL, the string it points to, followed by a
+ * colon and a space, is prepended to all error messages logged through the
+ * message_log_stdout and message_log_stderr message handlers (the former is
+ * the default for notice, and the latter is the default for warn and die).
+ *
+ * Honoring error_program_name and printing to stderr is just the default
+ * handler; with message_handlers_* the handlers for any message function can
+ * be changed. By default, notice prints to stdout, warn and die print to
+ * stderr, and the others don't do anything at all. These functions take a
+ * count of handlers and then that many function pointers, each one to a
+ * function that takes a message length (the number of characters snprintf
+ * generates given the format and arguments), a format, an argument list as a
+ * va_list, and the applicable errno value (if any).
+ *
+ * Copyright 2008 Board of Trustees, Leland Stanford Jr. University
+ * Copyright 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ * 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <errno.h>
-#include <syslog.h>
+#ifdef HAVE_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
+#endif
#include <util/util.h>
@@ -102,9 +115,9 @@ const char *message_program_name = NULL;
/*
-** Set the handlers for a particular message function. Takes a pointer to
-** the handler list, the count of handlers, and the argument list.
-*/
+ * Set the handlers for a particular message function. Takes a pointer to the
+ * handler list, the count of handlers, and the argument list.
+ */
static void
message_handlers(message_handler_func **list, int count, va_list args)
{
@@ -120,10 +133,10 @@ message_handlers(message_handler_func **list, int count, va_list args)
/*
-** There's no good way of writing these handlers without a bunch of code
-** duplication since we can't assume variadic macros, but I can at least make
-** it easier to write and keep them consistent.
-*/
+ * There's no good way of writing these handlers without a bunch of code
+ * 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(int count, ...) \
@@ -141,8 +154,8 @@ HANDLER_FUNCTION(die)
/*
-** Print a message to stdout, supporting message_program_name.
-*/
+ * Print a message to stdout, supporting message_program_name.
+ */
void
message_log_stdout(int len UNUSED, const char *fmt, va_list args, int err)
{
@@ -152,13 +165,14 @@ message_log_stdout(int len UNUSED, const char *fmt, va_list args, int err)
if (err)
fprintf(stdout, ": %s", strerror(err));
fprintf(stdout, "\n");
+ fflush(stdout);
}
/*
-** Print a message to stderr, supporting message_program_name. Also flush
-** stdout so that errors and regular output occur in the right order.
-*/
+ * Print a message to stderr, supporting message_program_name. Also flush
+ * stdout so that errors and regular output occur in the right order.
+ */
void
message_log_stderr(int len UNUSED, const char *fmt, va_list args, int err)
{
@@ -173,11 +187,13 @@ message_log_stderr(int len UNUSED, const char *fmt, va_list args, int err)
/*
-** Log a message to syslog. This is a helper function used to implement all
-** of the syslog message log handlers. It takes the same arguments as a
-** regular message handler function but with an additional priority
-** argument.
-*/
+ * Log a message to syslog. This is a helper function used to implement all
+ * of the syslog message log handlers. It takes the same arguments as a
+ * regular message handler function but with an additional priority argument.
+ *
+ * This needs further attention on Windows. For example, it currently doesn't
+ * log the errno information.
+ */
static void
message_log_syslog(int pri, int len, const char *fmt, va_list args, int err)
{
@@ -190,18 +206,30 @@ message_log_syslog(int pri, int len, const char *fmt, va_list args, int err)
exit(message_fatal_cleanup ? (*message_fatal_cleanup)() : 1);
}
vsnprintf(buffer, len + 1, fmt, args);
+#ifdef _WIN32
+ {
+ HANDLE eventlog;
+
+ eventlog = RegisterEventSource(NULL, message_program_name);
+ if (eventlog != NULL) {
+ ReportEvent(eventlog, pri, 0, 0, NULL, 1, 0, &buffer, NULL);
+ CloseEventLog(eventlog);
+ }
+ }
+#else /* !_WIN32 */
if (err == 0)
syslog(pri, "%s", buffer);
else
syslog(pri, "%s: %s", buffer, strerror(err));
+#endif /* !_WIN32 */
free(buffer);
}
/*
-** Do the same sort of wrapper to generate all of the separate syslog logging
-** functions.
-*/
+ * 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(int l, const char *f, va_list a, int e) \
@@ -217,10 +245,10 @@ SYSLOG_FUNCTION(crit, CRIT)
/*
-** All of the message handlers. There's a lot of code duplication here too,
-** but each one is still *slightly* different and va_start has to be called
-** multiple times, so it's hard to get rid of the duplication.
-*/
+ * All of the message handlers. There's a lot of code duplication here too,
+ * but each one is still *slightly* different and va_start has to be called
+ * multiple times, so it's hard to get rid of the duplication.
+ */
void
debug(const char *format, ...)
diff --git a/util/xmalloc.c b/util/xmalloc.c
index 635af75..927372d 100644
--- a/util/xmalloc.c
+++ b/util/xmalloc.c
@@ -1,90 +1,93 @@
/* $Id$
-**
-** malloc routines with failure handling.
-**
-** Usage:
-**
-** extern xmalloc_handler_t memory_error;
-** extern const char *string;
-** char *buffer;
-** va_list args;
-**
-** xmalloc_error_handler = memory_error;
-** buffer = xmalloc(1024);
-** xrealloc(buffer, 2048);
-** free(buffer);
-** buffer = xcalloc(1024);
-** free(buffer);
-** buffer = xstrdup(string);
-** free(buffer);
-** buffer = xstrndup(string, 25);
-** free(buffer);
-** xasprintf(&buffer, "%s", "some string");
-** free(buffer);
-** xvasprintf(&buffer, "%s", args);
-**
-** xmalloc, xcalloc, xrealloc, and xstrdup behave exactly like their C
-** library counterparts without the leading x except that they will never
-** return NULL. Instead, on error, they call xmalloc_error_handler,
-** passing it the name of the function whose memory allocation failed, the
-** amount of the allocation, and the file and line number where the
-** allocation function was invoked (from __FILE__ and __LINE__). This
-** function may do whatever it wishes, such as some action to free up
-** memory or a call to sleep to hope that system resources return. If the
-** handler returns, the interrupted memory allocation function will try its
-** allocation again (calling the handler again if it still fails).
-**
-** xstrndup behaves like xstrdup but only copies the given number of
-** characters. It allocates an additional byte over its second argument and
-** always nul-terminates the string.
-**
-** xasprintf and xvasprintf behave just like their GNU glibc library
-** implementations except that they do the same checking as described above.
-** xasprintf will only be able to provide accurate file and line information
-** on systems that support variadic macros.
-**
-** The default error handler, if none is set by the caller, prints an error
-** message to stderr and exits with exit status 1. An error handler must
-** take a const char * (function name), size_t (bytes allocated), const
-** char * (file), and int (line).
-**
-** xmalloc will return a pointer to a valid memory region on an xmalloc of 0
-** bytes, ensuring this by allocating space for one character instead of 0
-** bytes.
-**
-** The functions defined here are actually x_malloc, x_realloc, etc. The
-** header file defines macros named xmalloc, etc. that pass the file name
-** and line number to these functions.
-**
-** Copyright (c) 2004, 2005, 2006
-** by Internet Systems Consortium, Inc. ("ISC")
-** Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-** 2002, 2003 by The Internet Software Consortium and Rich Salz
-**
-** This code is derived from software contributed to the Internet Software
-** Consortium by Rich Salz.
-**
-** Permission to use, copy, modify, and distribute this software for any
-** purpose with or without fee is hereby granted, provided that the above
-** copyright notice and this permission notice appear in all copies.
-**
-** THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-** REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
-** SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
+ *
+ * malloc routines with failure handling.
+ *
+ * Usage:
+ *
+ * extern xmalloc_handler_t memory_error;
+ * extern const char *string;
+ * char *buffer;
+ * va_list args;
+ *
+ * xmalloc_error_handler = memory_error;
+ * buffer = xmalloc(1024);
+ * xrealloc(buffer, 2048);
+ * free(buffer);
+ * buffer = xcalloc(1024);
+ * free(buffer);
+ * buffer = xstrdup(string);
+ * free(buffer);
+ * buffer = xstrndup(string, 25);
+ * free(buffer);
+ * xasprintf(&buffer, "%s", "some string");
+ * free(buffer);
+ * xvasprintf(&buffer, "%s", args);
+ *
+ * xmalloc, xcalloc, xrealloc, and xstrdup behave exactly like their C library
+ * counterparts without the leading x except that they will never return NULL.
+ * Instead, on error, they call xmalloc_error_handler, passing it the name of
+ * the function whose memory allocation failed, the amount of the allocation,
+ * and the file and line number where the allocation function was invoked
+ * (from __FILE__ and __LINE__). This function may do whatever it wishes,
+ * such as some action to free up memory or a call to sleep to hope that
+ * system resources return. If the handler returns, the interrupted memory
+ * allocation function will try its allocation again (calling the handler
+ * again if it still fails).
+ *
+ * xstrndup behaves like xstrdup but only copies the given number of
+ * characters. It allocates an additional byte over its second argument and
+ * always nul-terminates the string.
+ *
+ * xasprintf and xvasprintf behave just like their GNU glibc library
+ * implementations except that they do the same checking as described above.
+ * xasprintf will only be able to provide accurate file and line information
+ * on systems that support variadic macros.
+ *
+ * The default error handler, if none is set by the caller, prints an error
+ * message to stderr and exits with exit status 1. An error handler must take
+ * a const char * (function name), size_t (bytes allocated), const char *
+ * (file), and int (line).
+ *
+ * xmalloc will return a pointer to a valid memory region on an xmalloc of 0
+ * bytes, ensuring this by allocating space for one character instead of 0
+ * bytes.
+ *
+ * The functions defined here are actually x_malloc, x_realloc, etc. The
+ * header file defines macros named xmalloc, etc. that pass the file name and
+ * line number to these functions.
+ *
+ * Copyright 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ * 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <errno.h>
#include <util/util.h>
-/* The default error handler. */
+
+/*
+ * The default error handler.
+ */
void
xmalloc_fail(const char *function, size_t size, const char *file, int line)
{
@@ -95,6 +98,7 @@ xmalloc_fail(const char *function, size_t size, const char *file, int line)
/* Assign to this variable to choose a handler other than the default. */
xmalloc_handler_type xmalloc_error_handler = xmalloc_fail;
+
void *
x_malloc(size_t size, const char *file, int line)
{
@@ -110,6 +114,7 @@ x_malloc(size_t size, const char *file, int line)
return p;
}
+
void *
x_calloc(size_t n, size_t size, const char *file, int line)
{
@@ -125,6 +130,7 @@ x_calloc(size_t n, size_t size, const char *file, int line)
return p;
}
+
void *
x_realloc(void *p, size_t size, const char *file, int line)
{
@@ -138,6 +144,7 @@ x_realloc(void *p, size_t size, const char *file, int line)
return newp;
}
+
char *
x_strdup(const char *s, const char *file, int line)
{
@@ -154,6 +161,7 @@ x_strdup(const char *s, const char *file, int line)
return p;
}
+
char *
x_strndup(const char *s, size_t size, const char *file, int line)
{
@@ -169,6 +177,7 @@ x_strndup(const char *s, size_t size, const char *file, int line)
return p;
}
+
int
x_vasprintf(char **strp, const char *fmt, va_list args, const char *file,
int line)
@@ -191,6 +200,7 @@ x_vasprintf(char **strp, const char *fmt, va_list args, const char *file,
return status;
}
+
#if HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS
int
x_asprintf(char **strp, const char *file, int line, const char *fmt, ...)