summaryrefslogtreecommitdiff
path: root/client
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 /client
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.
Diffstat (limited to 'client')
-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
7 files changed, 203 insertions, 187 deletions
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]);