Merge branch 'tls-kdh' of https://github.com/arpa2/tlspool into tls-kdh
[tlspool] / tool / get_localid.c
index 67ada32..665a7b2 100644 (file)
@@ -1,4 +1,4 @@
-/* tool/set_localid.c -- Retrieve local identity credentials
+/* tool/get_localid.c -- Retrieve local identity credentials
  *
  * Provide a config, a NAI and see what types of credentials are available
  * in localid.db.
 
 #include <sys/types.h>
 #include <sys/stat.h>
+
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 
+#include <arpa/inet.h>
+
 #include <db.h>
 
 #include <tlspool/internal.h>
@@ -27,7 +30,7 @@ const char const *usage =
 "Usage: %s tlspool.conf [user@]fqdn type [outfile.der]\n"
 " - tlspool.conf      is the configuration file for the TLS Pool\n"
 " - user@fqdn or fqdn is a network access identifier\n"
-" - type              comma-sep: X.509|OpenPGP, client|server, noP11?, chained?\n"
+" - type              X.509,OpenPGP,Kerberos,valexp,client,server,noP11,chained\n"
 " - outfile.der       optional output file for binary encoded public data\n"
 "Since the public data is stored in a binary format, it will never be printed\n"
 "on stdout; in absense of outfile.der the value is simply not output.\n";
@@ -41,6 +44,9 @@ struct typemap_t {
 struct typemap_t typemap [] = {
        { "X.509",      1 },
        { "OpenPGP",    2 },
+       { "Kerberos",   4 },
+       { "krb5",       4 },
+       { "valexp",     5 },
        { "client",     256 },
        { "server",     512 },
        { "noP11",      4096 },
@@ -148,7 +154,7 @@ int main (int argc, char *argv []) {
                        }
                        walker++;
                }
-               if (flags == 0) {
+               if (walker->name == NULL) {
                        fprintf (stderr, "Flag name %s not recognised\n", partstr);
                        exit (1);
                }
@@ -163,7 +169,7 @@ int main (int argc, char *argv []) {
                fprintf (stderr, "Failed to open cursor on localid.db\n");
                goto failure;
        }
-       bzero (&k_localid, sizeof (k_localid));
+       memset (&k_localid, 0, sizeof (k_localid));
        k_localid.data = localid;
        k_localid.size = strlen (localid);
        nomore = crs->get (crs, &k_localid, &e_value, DB_SET);
@@ -181,7 +187,7 @@ int main (int argc, char *argv []) {
                e_p11uri = (char *) & ((uint32_t *) e_value.data) [1];
                e_bindata = e_p11uri + strnlen (e_p11uri, e_value.size - 4) + 1;
                e_binlen = e_value.size - 4 - strnlen (e_p11uri, e_value.size - 4) - 1;
-               if (e_binlen <= 0) {
+               if (e_binlen < 0) {
                        fprintf (stderr, "Error retrieving binary data\n");
                        crs->close (crs);
                        goto failure;
@@ -224,7 +230,6 @@ printf ("Written %d bytes\n", e_binlen);
                goto failure;
        }
        if (txn->commit (txn, 0) != 0) {
-               txn->abort (txn);
                fprintf (stderr, "Failed to commit readonly transaction\n");
                exit (1);
        }