diff options
-rw-r--r-- | Makefile.am | 5 | ||||
-rw-r--r-- | client/wallet.c | 118 | ||||
-rw-r--r-- | configure.ac | 12 |
3 files changed, 134 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 6f82c4e..26cd6dc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,10 @@ AUTOMAKE_OPTIONS = foreign subdir-objects EXTRA_DIST = doc/design-acl doc/design-api doc/design-schema doc/notes -bin_PROGRAMS = kasetkey/kasetkey +bin_PROGRAMS = client/wallet kasetkey/kasetkey +client_wallet_CPPFLAGS = @REMCTL_CPPFLAGS@ +client_wallet_LDFLAGS = @REMCTL_LDFLAGS@ +client_wallet_LDADD = -lremctl kasetkey_kasetkey_CPPFLAGS = @AFS_CPPFLAGS@ kasetkey_kasetkey_LDFLAGS = @AFS_LDFLAGS@ kasetkey_kasetkey_LDADD = -lkauth.krb -lprot -lubik -lauth -lrxkad -ldes \ diff --git a/client/wallet.c b/client/wallet.c new file mode 100644 index 0000000..6106651 --- /dev/null +++ b/client/wallet.c @@ -0,0 +1,118 @@ +/* $Id$ +** +** The client program for the wallet system. +** +** Written by Russ Allbery <rra@stanford.edu> +** Copyright 2006 Board of Trustees, Leland Stanford Jr. University +** +** See README for licensing terms. +*/ + +#include <config.h> + +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> + +#include <remctl.h> + +/* Temporary until we have some real configuration. */ +#ifndef SERVER +# define SERVER "wallet.stanford.edu" +#endif +#ifndef PORT +# define PORT 4444 +#endif + +/* Usage message. */ +static const char usage_message[] = "\ +Usage: wallet (get|show) keytab <name>\n\ +\n\ +Options:\n\ + -h Display this help\n\ + -v Display the version of remctl\n"; + + +/* +** Display the usage message for remctl. +*/ +static void +usage(int status) +{ + fprintf((status == 0) ? stdout : stderr, "%s", usage_message); + exit(status); +} + + +/* +** Main routine. Parse the arguments and then perform the desired +** operation. +*/ +int +main(int argc, char *argv[]) +{ + int option, fd; + ssize_t status; + const char *command[3]; + struct remctl_result *result; + + while ((option = getopt(argc, argv, "hv")) != EOF) { + switch (option) { + case 'h': + usage(0); + break; + case 'v': + printf("%s\n", PACKAGE_STRING); + exit(0); + break; + default: + usage(1); + break; + } + } + argc -= optind; + argv += optind; + if (argc != 3) + usage(1); + if (strcmp(argv[1], "keytab") != 0) + usage(1); + + /* Perform the desired operation based on the first argument. */ + if (strcmp(argv[0], "get") == 0) { + command[0] = "get"; + } else if (strcmp(argv[0], "show") == 0) { + command[0] = "show"; + } + command[1] = "keytab"; + command[2] = argv[2]; + result = remctl(SERVER, PORT, NULL, command); + + /* Display the results. */ + if (result->error != NULL) { + fprintf(stderr, "%s\n", result->error); + } else if (result->stderr_len > 0) { + fwrite(result->stderr_buf, 1, result->stderr_len, stderr); + } else { + fd = open("keytab", O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd < 0) { + fprintf(stderr, "open of keytab failed: %s", strerror(errno)); + exit(1); + } + status = write(fd, result->stdout_buf, result->stdout_len); + if (status < 0) { + fprintf(stderr, "write to keytab failed: %s", strerror(errno)); + exit(1); + } else if (status != result->stdout_len) { + fprintf(stderr, "write to keytab truncated"); + exit(1); + } + if (close(fd) < 0) { + fprintf(stderr, "close of keytab failed: %s", strerror(errno)); + exit(1); + } + } + exit(result->status); +} diff --git a/configure.ac b/configure.ac index c0fc28c..45fa976 100644 --- a/configure.ac +++ b/configure.ac @@ -30,6 +30,18 @@ AC_ARG_WITH([afs-libs], fi]) AC_SUBST([AFS_LDFLAGS]) +REMCTL_CPPFLAGS= +REMCTL_LDFLAGS= +AC_ARG_WITH([remctl], + AC_HELP_STRING([--with-remctl=DIR], + [Prefix for remctl headers and libraries]), + [if test x"$withval" != xno ; then + REMCTL_CPPFLAGS="-I${withval}/include" + REMCTL_LDFLAGS="-L${withval}/lib" + fi]) +AC_SUBST([REMCTL_CPPFLAGS]) +AC_SUBST([REMCTL_LDFLAGS]) + AC_PROG_CC AM_PROG_CC_C_O AC_PROG_INSTALL |