summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE6
-rw-r--r--Makefile.am14
-rw-r--r--client/internal.h6
-rw-r--r--portable/macros.h37
-rw-r--r--util/messages-krb5.c (renamed from client/error.c)62
-rw-r--r--util/util.h145
6 files changed, 154 insertions, 116 deletions
diff --git a/LICENSE b/LICENSE
index a04578d..36d2143 100644
--- a/LICENSE
+++ b/LICENSE
@@ -50,9 +50,9 @@ The file portable/snprintf.c is released under the following license:
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/strlcat.c,
-portable/strlcpy.c, and util/concat.c have been placed in the public
-domain by their author.
+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,
diff --git a/Makefile.am b/Makefile.am
index fe0a812..eb93a29 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,17 +33,17 @@ EXTRA_DIST = LICENSE autogen client/wallet.pod config/allow-extract \
noinst_LIBRARIES = portable/libportable.a util/libutil.a
portable_libportable_a_SOURCES = portable/dummy.c
portable_libportable_a_LIBADD = $(LIBOBJS)
-util_libutil_a_SOURCES = util/concat.c util/messages.c util/util.h \
- util/xmalloc.c
+util_libutil_a_SOURCES = util/concat.c util/messages.c util/messages-krb5.c \
+ util/util.h util/xmalloc.c
+util_libutil_a_CPPFLAGS = $(KRB5_CPPFLAGS)
bin_PROGRAMS = client/wallet
dist_sbin_SCRIPTS = server/keytab-backend server/wallet-admin \
server/wallet-backend
-client_wallet_SOURCES = client/error.c client/file.c client/internal.h \
- client/keytab.c client/krb5.c client/remctl.c client/srvtab.c \
- client/wallet.c system.h
-client_wallet_CPPFLAGS = $(REMCTL_CPPFLAGS)
-client_wallet_LDFLAGS = $(REMCTL_LDFLAGS)
+client_wallet_SOURCES = client/file.c client/internal.h client/keytab.c \
+ client/krb5.c client/remctl.c client/srvtab.c client/wallet.c system.h
+client_wallet_CPPFLAGS = $(REMCTL_CPPFLAGS) $(KRB5_CPPFLAGS)
+client_wallet_LDFLAGS = $(REMCTL_LDFLAGS) $(KRB5_LDFLAGS)
client_wallet_LDADD = util/libutil.a portable/libportable.a $(REMCTL_LIBS) \
$(KRB5_LIBS)
diff --git a/client/internal.h b/client/internal.h
index 795c58d..ba17b73 100644
--- a/client/internal.h
+++ b/client/internal.h
@@ -82,12 +82,6 @@ void write_file(const char *name, const void *data, size_t length);
void write_srvtab(krb5_context, const char *srvtab, const char *principal,
const char *keytab);
-/* Versions of die and warn that report Kerberos errors. */
-void die_krb5(krb5_context, krb5_error_code, const char *, ...)
- __attribute__((__noreturn__, __format__(printf, 3, 4)));
-void warn_krb5(krb5_context, krb5_error_code, const char *, ...)
- __attribute__((__format__(printf, 3, 4)));
-
END_DECLS
#endif /* !CLIENT_INTERNAL_H */
diff --git a/portable/macros.h b/portable/macros.h
new file mode 100644
index 0000000..dcffa59
--- /dev/null
+++ b/portable/macros.h
@@ -0,0 +1,37 @@
+/* $Id$
+ *
+ * Portability macros used in include files.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * This work is hereby placed in the public domain by its author.
+ */
+
+#ifndef PORTABLE_MACROS_H
+#define PORTABLE_MACROS_H 1
+
+/*
+ * __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
+
+#endif /* !PORTABLE_MACROS_H */
diff --git a/client/error.c b/util/messages-krb5.c
index 982c845..314f96a 100644
--- a/client/error.c
+++ b/util/messages-krb5.c
@@ -1,23 +1,20 @@
-/* $Id$
-**
-** Error handling for the wallet client.
-**
-** Provides versions of die and warn that take a Kerberos context and a
-** Kerberos error code and append the Kerberos error message to the provided
-** formatted message.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2006, 2007, 2008
-** Board of Trustees, Leland Stanford Jr. University
-**
-** See LICENSE for licensing terms.
-*/
+/* $Id$
+ *
+ * Error handling for Kerberos v5.
+ *
+ * Provides versions of die and warn that take a Kerberos context and a
+ * Kerberos error code and append the Kerberos error message to the provided
+ * formatted message.
+ *
+ * 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 <krb5.h>
-#include <stdio.h>
-#include <sys/types.h>
+#include <system.h>
#include <krb5.h>
#if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) && !defined(HAVE_KRB5_GET_ERR_TEXT)
@@ -30,20 +27,21 @@
# endif
#endif
-#include <client/internal.h>
#include <util/util.h>
-/* This string is returned for unknown error messages. We use a static
- variable so that we can be sure not to free it. */
+/*
+ * This string is returned for unknown error messages. We use a static
+ * variable so that we can be sure not to free it.
+ */
static const char error_unknown[] = "unknown error";
/*
-** Given a Kerberos error code, return the corresponding error. Prefer the
-** Kerberos interface if available since it will provide context-specific
-** error information, whereas the error_message() call will only provide a
-** fixed message.
-*/
+ * Given a Kerberos error code, return the corresponding error. Prefer the
+ * Kerberos interface if available since it will provide context-specific
+ * error information, whereas the error_message() call will only provide a
+ * fixed message.
+ */
static const char *
get_error(krb5_context ctx UNUSED, krb5_error_code code)
{
@@ -66,8 +64,8 @@ get_error(krb5_context ctx UNUSED, krb5_error_code code)
/*
-** Free an error string if necessary.
-*/
+ * Free an error string if necessary.
+ */
static void
free_error(krb5_context ctx UNUSED, const char *msg)
{
@@ -82,8 +80,8 @@ free_error(krb5_context ctx UNUSED, const char *msg)
/*
-** Report a Kerberos error and exit.
-*/
+ * Report a Kerberos error and exit.
+ */
void
die_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...)
{
@@ -101,8 +99,8 @@ die_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...)
/*
-** Report a Kerberos error.
-*/
+ * Report a Kerberos error.
+ */
void
warn_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...)
{
diff --git a/util/util.h b/util/util.h
index 7fc4c96..0a45c73 100644
--- a/util/util.h
+++ b/util/util.h
@@ -1,61 +1,51 @@
-/* $Id$
-**
-** Utility functions.
-**
-** This is a variety of utility functions that are used internally by the
-** wallet client. Many of them came originally from INN.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** Copyright 2002, 2003, 2004, 2005, 2006, 2007
-** 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
-**
-** 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$
+ *
+ * Utility functions.
+ *
+ * This is a variety of utility functions that are used internally by pieces
+ * of remctl. Many of them came originally from INN.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * Copyright 2005, 2006, 2007, 2008
+ * Board of Trustees, Leland Stanford Jr. University
+ * 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
+ *
+ * See LICENSE for licensing terms.
+ */
#ifndef UTIL_UTIL_H
#define UTIL_UTIL_H 1
#include <config.h>
-#include <system.h>
+#include <portable/macros.h>
+
+#include <krb5.h>
+#include <stdarg.h>
+#include <sys/types.h>
/* Used for unused parameters to silence gcc warnings. */
#define UNUSED __attribute__((__unused__))
BEGIN_DECLS
-/* Forward declarations to avoid includes. */
-struct addrinfo;
-struct iovec;
-struct sockaddr;
-
/* Concatenate NULL-terminated strings into a newly allocated string. */
extern char *concat(const char *first, ...);
-/* Given a base path and a file name, create a newly allocated path string.
- The name will be appended to base with a / between them. Exceptionally, if
- name begins with a slash, it will be strdup'd and returned as-is. */
+/*
+ * Given a base path and a file name, create a newly allocated path string.
+ * The name will be appended to base with a / between them. Exceptionally, if
+ * name begins with a slash, it will be strdup'd and returned as-is.
+ */
extern char *concatpath(const char *base, const char *name);
-/* The reporting functions. The ones prefaced by "sys" add a colon, a space,
- and the results of strerror(errno) to the output and are intended for
- reporting failures of system calls. */
+/*
+ * The reporting functions. The ones prefaced by "sys" add a colon, a space,
+ * and the results of strerror(errno) to the output and are intended for
+ * reporting failures of system calls.
+ */
extern void debug(const char *, ...)
__attribute__((__format__(printf, 1, 2)));
extern void notice(const char *, ...)
@@ -71,18 +61,31 @@ extern void die(const char *, ...)
extern void sysdie(const char *, ...)
__attribute__((__noreturn__, __format__(printf, 1, 2)));
-/* Set the handlers for various message functions. All of these functions
- take a count of the number of handlers and then function pointers for each
- of those handlers. These functions are not thread-safe; they set global
- variables. */
+/*
+ * The Kerberos versions of the reporting functions. These take a context and
+ * an error code to get the Kerberos error.
+ */
+void die_krb5(krb5_context, krb5_error_code, const char *, ...)
+ __attribute__((__noreturn__, __format__(printf, 3, 4)));
+void warn_krb5(krb5_context, krb5_error_code, const char *, ...)
+ __attribute__((__format__(printf, 3, 4)));
+
+/*
+ * Set the handlers for various message functions. All of these functions
+ * take a count of the number of handlers and then function pointers for each
+ * of those handlers. These functions are not thread-safe; they set global
+ * variables.
+ */
extern void message_handlers_debug(int count, ...);
extern void message_handlers_notice(int count, ...);
extern void message_handlers_warn(int count, ...);
extern void message_handlers_die(int count, ...);
-/* Some useful handlers, intended to be passed to message_handlers_*. All
- handlers take the length of the formatted message, the format, a variadic
- argument list, and the errno setting if any. */
+/*
+ * Some useful handlers, intended to be passed to message_handlers_*. All
+ * handlers take the length of the formatted message, the format, a variadic
+ * argument list, and the errno setting if any.
+ */
extern void message_log_stdout(int, const char *, va_list, int);
extern void message_log_stderr(int, const char *, va_list, int);
extern void message_log_syslog_debug(int, const char *, va_list, int);
@@ -98,13 +101,17 @@ typedef void (*message_handler_func)(int, const char *, va_list, int);
/* If non-NULL, called before exit and its return value passed to exit. */
extern int (*message_fatal_cleanup)(void);
-/* If non-NULL, prepended (followed by ": ") to all messages printed by either
- message_log_stdout or message_log_stderr. */
+/*
+ * If non-NULL, prepended (followed by ": ") to all messages printed by either
+ * message_log_stdout or message_log_stderr.
+ */
extern const char *message_program_name;
-/* The functions are actually macros so that we can pick up the file and line
- number information for debugging error messages without the user having to
- pass those in every time. */
+/*
+ * The functions are actually macros so that we can pick up the file and line
+ * number information for debugging error messages without the user having to
+ * pass those in every time.
+ */
#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__)
@@ -112,12 +119,14 @@ extern const char *message_program_name;
#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
#define xvasprintf(p, f, a) x_vasprintf((p), (f), (a), __FILE__, __LINE__)
-/* asprintf is a special case since it takes variable arguments. If we have
- support for variadic macros, we can still pass in the file and line and
- just need to put them somewhere else in the argument list than last.
- Otherwise, just call x_asprintf directly. This means that the number of
- arguments x_asprintf takes must vary depending on whether variadic macros
- are supported. */
+/*
+ * asprintf is a special case since it takes variable arguments. If we have
+ * support for variadic macros, we can still pass in the file and line and
+ * just need to put them somewhere else in the argument list than last.
+ * Otherwise, just call x_asprintf directly. This means that the number of
+ * arguments x_asprintf takes must vary depending on whether variadic macros
+ * are supported.
+ */
#ifdef HAVE_C99_VAMACROS
# define xasprintf(p, f, ...) \
x_asprintf((p), __FILE__, __LINE__, (f), __VA_ARGS__)
@@ -128,12 +137,10 @@ extern const char *message_program_name;
# define xasprintf x_asprintf
#endif
-/* Last two arguments are always file and line number. These are internal
- implementations that should not be called directly. ISO C99 says that
- identifiers beginning with _ and a lowercase letter are reserved for
- identifiers of file scope, so while the position of libraries in the
- standard isn't clear, it's probably not entirely kosher to use _xmalloc
- here. Use x_malloc instead. */
+/*
+ * Last two arguments are always file and line number. These are internal
+ * implementations that should not be called directly.
+ */
extern void *x_calloc(size_t, size_t, const char *, int);
extern void *x_malloc(size_t, const char *, int);
extern void *x_realloc(void *, size_t, const char *, int);
@@ -154,8 +161,10 @@ typedef void (*xmalloc_handler_type)(const char *, size_t, const char *, int);
/* The default error handler. */
void xmalloc_fail(const char *, size_t, const char *, int);
-/* Assign to this variable to choose a handler other than the default, which
- just calls sysdie. */
+/*
+ * Assign to this variable to choose a handler other than the default, which
+ * just calls sysdie.
+ */
extern xmalloc_handler_type xmalloc_error_handler;
END_DECLS