Changed GCC to -std=gnu11 which is the default with GCC 5.0 but not before
authorRick van Rein <rick@openfortress.nl>
Mon, 18 Apr 2016 07:35:27 +0000 (08:35 +0100)
committerRick van Rein <rick@openfortress.nl>
Mon, 18 Apr 2016 07:35:27 +0000 (08:35 +0100)
* Made changes to accommodate the warnings that this generated on GCC 4

15 files changed:
include/tlspool/internal.h
lib/Makefile
src/Makefile
src/config.c
src/donai.c
src/donai.h
src/manage.h
src/starttls.c
tool/Makefile
tool/get_localid.c
tool/lidsel.c
tool/set_localid.c
tool/testcli.c
tool/testpeer.c
tool/testsrv.c

index 4cc415a..5f3618b 100644 (file)
@@ -99,6 +99,7 @@ void send_error (struct command *cmd, int tlserrno, char *msg);
 void send_success (struct command *cmd);
 int send_command (struct command *cmd, int passfd);
 struct command *send_callback_and_await_response (struct command *cmdresp, time_t opt_timeout);
+void register_server_socket (int srvsox);
 
 /* pinentry.c */
 void setup_pinentry (void);
@@ -106,13 +107,13 @@ void cleanup_pinentry (void);
 void register_pinentry_command (struct command *cmd);
 success_t token_callback (const char *const label, unsigned retry);
 success_t pin_callback (int attempt, const char *token_url, const char *token_label, char *pin, size_t pin_max);
+void pinentry_forget_clientfd (int fd);
 
 /* starttls.c */
 void setup_starttls (void);
 void cleanup_starttls (void);
 void starttls_pkcs11_provider (char *p11path);
-void starttls_client (struct command *cmd);
-void starttls_server (struct command *cmd);
+void starttls (struct command *cmd);
 void starttls_prng (struct command *cmd);
 
 /* config.c */
@@ -271,6 +272,22 @@ int ctlkey_register (uint8_t *ctlkey, struct ctlkeynode *ckn, enum security_laye
  */
 int ctlkey_unregister (uint8_t *ctlkey);
 
+/* Look through the ctlkey registry, to find sessions that depend on a closing
+ * control connection meaning that they cannot survive it being closed;
+ * those entries will be unregistered and deallocated ; this is used when a
+ * client socket closes its link to the TLS Pool.
+ *
+ * This implementation closes all entries whose ctlfd matches; this is needed
+ * for detached nodes that have been reattached.  Nodes that are attached
+ * will usually be removed before they hit this routine, which is also good.
+ *
+ * Note that detached keys are (by definition) protected against this cleanup
+ * procedure; however, when their TLS connection breaks down, they too will
+ * be cleaned up.  Note that detaching is not done before the TLS handshake
+ * is complete.
+ */
+void ctlkey_close_ctlfd (int clisox);
+
 /* Find a ctlkeynode based on a ctlkey.  Returns NULL if not found.
  * 
  * The value returned is the registered structure, meaning that any context
index fe17630..7da811c 100644 (file)
@@ -15,7 +15,7 @@ OBJS = $(libtlspool_OBJS)
 all: $(TARGETS)
 
 libtlspool.so: $(libtlspool_OBJS)
-       gcc -shared $(LDFLAGS) -o "$@" $(libtlspool_OBJS) $(LIBS)
+       gcc -std=gnu11 -shared $(LDFLAGS) -o "$@" $(libtlspool_OBJS) $(LIBS)
 
 libtlspool.a: $(libtlspool_OBJS)
        rm -f "$@"
@@ -28,11 +28,13 @@ tlspool.pyc: tlspool.py
        python -m compileall "$<"
 
 .c.o:
-       gcc -c $(CFLAGS) -o $@ $<
+       gcc -std=gnu11 -c $(CFLAGS) -o $@ $<
 
 clean:
        rm -f $(OBJS) *.lo *.la $(TARGETS)
 
+anew: clean all
+
 install: all
        install libtlspool.so libtlspool.a "$(PREFIX)/lib/"
        @echo #
index 88a3b17..69579f7 100644 (file)
@@ -27,14 +27,16 @@ TASN1_LIBS   = $(shell pkg-config --libs   libtasn1)
 all: $(TARGETS)
 
 tlspool: $(OBJS)
-       gcc $(LDFLAGS) -o "$@" $(OBJS) $(LIBS)
+       gcc -std=gnu11 $(LDFLAGS) -o "$@" $(OBJS) $(LIBS)
 
 .c.o:
-       gcc -c $(CFLAGS) -o "$@" "$<"
+       gcc -std=gnu11 -c $(CFLAGS) -o "$@" "$<"
 
 clean:
        rm -f $(OBJS) $(TARGETS)
 
+anew: clean all
+
 install: all
        install $(TARGETS) "$(PREFIX)/sbin/"
 
index c3b27db..8bbaf20 100644 (file)
@@ -11,6 +11,7 @@
 #include <sys/types.h>
 #include <sys/file.h>
 #include <sys/un.h>
+#include <sys/stat.h>
 
 #include <syslog.h>
 #include <fcntl.h>
index f8140ba..4f44e2a 100644 (file)
@@ -6,6 +6,8 @@
 #include <syslog.h>
 #include <errno.h>
 
+#include <arpa/inet.h>
+
 #include <tlspool/internal.h>
 
 #include "manage.h"
index c4d545c..9cd6c2d 100644 (file)
@@ -199,6 +199,11 @@ int dbcred_interpret (pool_datum_t *creddata, uint32_t *flags, char **p11priv, u
 int selector_iterate_init (selector_t *iterator, donai_t *donai);
 int selector_iterate_next (selector_t *iterator);
 
+/* Retrieve flags from the credentials structure found in dbh_localid.
+ * The function returns non-zero on success (zero indicates syntax error).
+ */
+int dbcred_flags (DBT *creddata, uint32_t *flags);
+
 /* Print a donai or iterated selector to the given text buffer.  The
  * text will be precisely the same as the originally parsed text.  An
  * iterator may deliver values that are shorter, not longer.  The value
index 56f75c2..3e52e52 100644 (file)
@@ -45,3 +45,13 @@ success_t setup_management (void);
  */
 void cleanup_management (void);
 
+
+/* Begin a database transaction, if possible; otherwise setup as NULL */
+void manage_txn_begin (DB_TXN **txn);
+
+/* Commit a database transaction, setting it to NULL.  Ignore when NULL. */
+int manage_txn_commit (DB_TXN **txn);
+
+/* Rollback a database transaction, setting it to NULL.  Ignore when NULL. */
+int manage_txn_rollback (DB_TXN **txn);
+
index 6ad40b3..a8c7117 100644 (file)
@@ -23,6 +23,8 @@
 #include <gnutls/pkcs11.h>
 #include <gnutls/abstract.h>
 
+#include <libtasn1.h>
+
 #include <tlspool/internal.h>
 
 
@@ -1357,6 +1359,7 @@ gtls_error fetch_local_credentials (struct command *cmd) {
        int gtls_errno = 0;
        int db_errno = 0;
        int found = 0;
+       gtls_error certificate_onthefly (struct command *cmd);
 
        //
        // When applicable, try to create an on-the-fly certificate
@@ -2030,7 +2033,7 @@ static void *starttls_thread (void *cmd_void) {
        if (cmd == NULL) {
                send_error (replycmd, EINVAL, "Command structure not received");
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
        }
        cmd->session_errno = 0;
        cmd->anonpre = 0;
@@ -2045,7 +2048,7 @@ static void *starttls_thread (void *cmd_void) {
                tlog (TLOG_UNIXSOCK, LOG_ERR, "No ciphertext file descriptor supplied to TLS Pool");
                send_error (replycmd, EINVAL, "No ciphertext file descriptor supplied to TLS Pool");
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
        }
 */
        cmd->session_certificate = (intptr_t) (void *) NULL;
@@ -2065,7 +2068,7 @@ fprintf (stderr, "DEBUG: Got a request to renegotiate existing TLS connection\n"
                        send_error (replycmd, EPROTO, "File handle supplied for renegotiation");
                        close (cryptfd);
                        assert (pthread_detach (pthread_self ()) == 0);
-                       return;
+                       return NULL;
                }
                //
                // First find the ctlkeynode_tls
@@ -2075,7 +2078,7 @@ fprintf (stderr, "DEBUG: Got ckn == 0x%0x\n", (intptr_t) ckn);
                        tlog (TLOG_UNIXSOCK, LOG_ERR, "Failed to find TLS connection for renegotiation by its ctlkey");
                        send_error (replycmd, ESRCH, "Cannot find TLS connection for renegotiation");
                        assert (pthread_detach (pthread_self ()) == 0);
-                       return;
+                       return NULL;
                }
                //
                // Now cancel the pthread for this process
@@ -2092,7 +2095,7 @@ fprintf (stderr, "DEBUG: pthread_join returned %d\n", errno);
                        ctlkey_unfind (&ckn->regent);
                        assert (pthread_detach (pthread_self ()) == 0);
                        // Do not free the ckn, as the other thread still runs
-                       return;
+                       return NULL;
                }
                //
                // We are in control!  Assimilate the TLS connection data.
@@ -2147,7 +2150,7 @@ printf ("DEBUG: Client-side invocation flagged as wrong; compensated error\n");
                        }
                }
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
        }
 
        //
@@ -2187,7 +2190,7 @@ printf ("DEBUG: Client-side invocation flagged as wrong; compensated error\n");
                }
                manage_txn_rollback (&cmd->txn);
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
        }
 */
        //
@@ -2207,7 +2210,7 @@ fprintf (stderr, "ctlkey_unregister under ckn=0x%x at %d\n", ckn, __LINE__);
                }
                manage_txn_rollback (&cmd->txn);
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
        }
 
        //
@@ -2278,7 +2281,7 @@ fprintf (stderr, "ctlkey_unregister under ckn=0x%x at %d\n", ckn, __LINE__);
                }
                manage_txn_rollback (&cmd->txn);
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
        }
 
        //
@@ -2457,7 +2460,7 @@ fprintf (stderr, "ctlkey_unregister under ckn=0x%x at %d\n", ckn, __LINE__);
                }
                manage_txn_rollback (&cmd->txn);
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
        }
        tlog (TLOG_UNIXSOCK | TLOG_TLS, LOG_DEBUG, "TLS handshake started over %d", cryptfd);
        do {
@@ -2662,7 +2665,7 @@ fprintf (stderr, "ctlkey_unregister under ckn=0x%x at %d\n", ckn, __LINE__);
                }
                manage_txn_rollback (&cmd->txn);
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
         } else {
                tlog (TLOG_UNIXSOCK | TLOG_TLS, LOG_INFO, "TLS handshake succeeded over %d", cryptfd);
                //TODO// extract_authenticated_remote_identity (cmd);
@@ -2698,7 +2701,7 @@ fprintf (stderr, "ctlkey_unregister under ckn=0x%x at %d\n", ckn, __LINE__);
                        }
                        manage_txn_rollback (&cmd->txn);
                        assert (pthread_detach (pthread_self ()) == 0);
-                       return;
+                       return NULL;
                }
                cmd->cmd.pio_cmd = oldcmd;
                tlog (TLOG_UNIXSOCK, LOG_DEBUG, "Processing callback response that set plainfd:=%d for lid==\"%s\" and rid==\"%s\"", cmd->passfd, cmd->cmd.pio_data.pioc_starttls.localid, cmd->cmd.pio_data.pioc_starttls.remoteid);
@@ -2726,7 +2729,7 @@ fprintf (stderr, "ctlkey_unregister under ckn=0x%x at %d\n", ckn, __LINE__);
                }
                manage_txn_rollback (&cmd->txn);
                assert (pthread_detach (pthread_self ()) == 0);
-               return;
+               return NULL;
        }
        //DEFERRED// send_command (replycmd, -1);               // app sent plainfd to us
 
@@ -2829,7 +2832,7 @@ fprintf (stderr, "gnutls_deinit (0x%x) at %d\n", session, __LINE__);
                got_session = 0;
        }
        assert (pthread_detach (pthread_self ()) == 0);
-       return;
+       return NULL;
 }
 
 
index 998da5b..67e01d6 100644 (file)
@@ -34,53 +34,55 @@ BDB_LDFLAGS = -ldb
 all: $(TARGETS)
 
 testcli: testcli.c $(tlspool_LIB)
-       gcc $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
 
 testsrv: testsrv.c $(tlspool_LIB)
-       gcc $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
 
 testpeer: testpeer.c $(tlspool_LIB)
-       gcc $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
        @echo #
        @echo # You cannot use testpeer yet
        @echo #
 
 tlstunnel: tlstunnel.c tlstunnel-chat.c $(tlspool_LIB)
-       gcc $(CFLAGS) -o "$@" tlstunnel.c tlstunnel-chat.c $(tlspool_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) -o "$@" tlstunnel.c tlstunnel-chat.c $(tlspool_LDFLAGS)
 
 pingpool: pingpool.c $(tlspool_LIB)
-       gcc $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
 
 lidsel: lidsel.c $(tlspool_LIB)
-       gcc $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
 
 pinentry: pinentry.c $(tlspool_LIB)
-       gcc $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) -o "$@" "$<" $(tlspool_LDFLAGS)
 
 get_localid: get_localid.c $(config_SRC)
-       gcc $(CFLAGS) $(config_CFLAGS) $(BDB_CFLAGS) -o "$@" "$<" $(config_SRC) $(tlspool_LDFLAGS) $(BDB_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) $(config_CFLAGS) $(BDB_CFLAGS) -o "$@" "$<" $(config_SRC) $(tlspool_LDFLAGS) $(BDB_LDFLAGS)
 
 set_localid: set_localid.c $(config_SRC)
-       gcc $(CFLAGS) $(config_CFLAGS) $(BDB_CFLAGS) -o "$@" "$<" $(config_SRC) $(tlspool_LDFLAGS) $(BDB_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) $(config_CFLAGS) $(BDB_CFLAGS) -o "$@" "$<" $(config_SRC) $(tlspool_LDFLAGS) $(BDB_LDFLAGS)
 
 get_disclose: get_disclose.c $(config_SRC) $(donai_SRC)
-       gcc $(CFLAGS) $(config_CFLAGS) $(donai_CFLAGS) $(BDB_CFLAGS) -o "$@" "$<" $(config_SRC) $(donai_SRC) $(tlspool_LDFLAGS) $(BDB_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) $(config_CFLAGS) $(donai_CFLAGS) $(BDB_CFLAGS) -o "$@" "$<" $(config_SRC) $(donai_SRC) $(tlspool_LDFLAGS) $(BDB_LDFLAGS)
 
 set_disclose: set_disclose.c $(config_SRC)
-       gcc $(CFLAGS) $(config_CFLAGS) $(BDB_CFLAGS) -o "$@" "$<" $(config_SRC) $(tlspool_LDFLAGS) $(BDB_LDFLAGS)
+       gcc -std=gnu11 $(CFLAGS) $(config_CFLAGS) $(BDB_CFLAGS) -o "$@" "$<" $(config_SRC) $(tlspool_LDFLAGS) $(BDB_LDFLAGS)
 
 pgp11_genkey: pgp11_genkey.c
-       gcc $(CFLAGS) $(pgp11genkey_CFLAGS) -o "$@" "$<" $(pgp11genkey_LIBS)
+       gcc -std=gnu11 $(CFLAGS) $(pgp11genkey_CFLAGS) -o "$@" "$<" $(pgp11genkey_LIBS)
 
 $(tlspool_LIB):
        make -C ../lib `basename $(tlspool_LIB)`
 
 .c.o:
-       gcc -c $(CFLAGS) -o "$@" "$<"
+       gcc -std=gnu11 -c $(CFLAGS) -o "$@" "$<"
 
 clean:
        rm -f $(OBJS) $(TARGETS)
 
+anew: clean all
+
 install: all
        install $(TARGETS) "$(PREFIX)/sbin/"
 
index 67ada32..e1ec5ab 100644 (file)
 
 #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>
index e204600..9534e63 100644 (file)
@@ -36,7 +36,7 @@ struct data {
  * and stores them for future reference.  It also requests entry of the
  * local identity or the index number of the database entries printed.
  */
-void lidcb (lidentry_t *entry, void *data) {
+char *lidcb (lidentry_t *entry, void *data) {
        //
        // Declare & initialise
        struct data *d = (struct data *) data;
@@ -58,7 +58,7 @@ printf ("DEBUG: lidsel.c lidcb() called with localid %s\n", entry->localid);
                }
                d->dblidctr++;
 printf ("DEBUG: lidsel.c lidcb() returns after processing database entry\n");
-               return;
+               return NULL;
        }
 
        //
@@ -103,7 +103,7 @@ printf ("DEBUG: lidsel.c lidcb() returns after processing database entry\n");
        } while (error);
        d->dblidctr = 0;
 printf ("DEBUG: lidsel.c lidcb() returns after setting localid to %s and flags to 0x%08lx\n", entry->localid, entry->flags);
-       return;
+       return NULL;
 }
 
 
index 73a16a4..647b6a4 100644 (file)
 
 #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>
index 8e1eab7..acca2ce 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <stdint.h>
 
+#include <unistd.h>
 #include <poll.h>
 #include <errno.h>
 #include <signal.h>
@@ -67,28 +68,28 @@ void runterminal (int chanio) {
                        break;
                }
                if (inout [0].revents & POLLIN) {
-                       sz = read (0, buf, sizeof (buf), MSG_DONTWAIT);
+                       sz = read (0, buf, sizeof (buf));
                        printf ("Read %d bytes, sigcont==%d (should be 0 for proper operation)\n", sz, sigcont);
                        if (sz == -1) {
                                break;
                        } else if (sz == 0) {
                                errno = 0;
                                break;
-                       } else if (write (chanio, buf, sz, MSG_DONTWAIT) != sz) {
+                       } else if (send (chanio, buf, sz, MSG_DONTWAIT) != sz) {
                                break;
                        } else {
                                printf ("Sent %d bytes\n", sz);
                        }
                }
                if (inout [1].revents & POLLIN) {
-                       sz = read (chanio, buf, sizeof (buf), MSG_DONTWAIT);
+                       sz = recv (chanio, buf, sizeof (buf), MSG_DONTWAIT);
                        printf ("Received %d bytes, sigcont==%d (should be 0 for proper operation)\n", sz, sigcont);
                        if (sz == -1) {
                                break;
                        } else if (sz == 0) {
                                errno = 0;
                                break;
-                       } else if (write (1, buf, sz, MSG_DONTWAIT) != sz) {
+                       } else if (write (1, buf, sz) != sz) {
                                break;
                        } else {
                                printf ("Printed %d bytes\n", sz);
index 0cff697..a31d9f1 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <stdint.h>
 
+#include <unistd.h>
 #include <poll.h>
 #include <errno.h>
 #include <signal.h>
@@ -66,28 +67,28 @@ void runterminal (int chanio) {
                        break;
                }
                if (inout [0].revents & POLLIN) {
-                       sz = read (0, buf, sizeof (buf), MSG_DONTWAIT);
+                       sz = read (0, buf, sizeof (buf));
                        printf ("Read %d bytes, sigcont==%d (should be 0 for proper operation)\n", sz, sigcont);
                        if (sz == -1) {
                                break;
                        } else if (sz == 0) {
                                errno = 0;
                                break;
-                       } else if (write (chanio, buf, sz, MSG_DONTWAIT) != sz) {
+                       } else if (send (chanio, buf, sz, MSG_DONTWAIT) != sz) {
                                break;
                        } else {
                                printf ("Sent %d bytes\n", sz);
                        }
                }
                if (inout [1].revents & POLLIN) {
-                       sz = read (chanio, buf, sizeof (buf), MSG_DONTWAIT);
+                       sz = recv (chanio, buf, sizeof (buf), MSG_DONTWAIT);
                        printf ("Received %d bytes, sigcont==%d (should be 0 for proper operation)\n", sz, sigcont);
                        if (sz == -1) {
                                break;
                        } else if (sz == 0) {
                                errno = 0;
                                break;
-                       } else if (write (1, buf, sz, MSG_DONTWAIT) != sz) {
+                       } else if (write (1, buf, sz) != sz) {
                                break;
                        } else {
                                printf ("Printed %d bytes\n", sz);
index 4637087..9e208a6 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <stdint.h>
 
+#include <unistd.h>
 #include <poll.h>
 #include <errno.h>
 #include <signal.h>
@@ -67,28 +68,28 @@ void runterminal (int chanio) {
                        break;
                }
                if (inout [0].revents & POLLIN) {
-                       sz = read (0, buf, sizeof (buf), MSG_DONTWAIT);
+                       sz = read (0, buf, sizeof (buf));
                        printf ("Read %d bytes, sigcont==%d (should be 0 for proper operation)\n", sz, sigcont);
                        if (sz == -1) {
                                break;
                        } else if (sz == 0) {
                                errno = 0;
                                break;
-                       } else if (write (chanio, buf, sz, MSG_DONTWAIT) != sz) {
+                       } else if (send (chanio, buf, sz, MSG_DONTWAIT) != sz) {
                                break;
                        } else {
                                printf ("Sent %d bytes\n", sz);
                        }
                }
                if (inout [1].revents & POLLIN) {
-                       sz = read (chanio, buf, sizeof (buf), MSG_DONTWAIT);
+                       sz = recv (chanio, buf, sizeof (buf), MSG_DONTWAIT);
                        printf ("Received %d bytes, sigcont==%d (should be 0 for proper operation)\n", sz, sigcont);
                        if (sz == -1) {
                                break;
                        } else if (sz == 0) {
                                errno = 0;
                                break;
-                       } else if (write (1, buf, sz, MSG_DONTWAIT) != sz) {
+                       } else if (write (1, buf, sz) != sz) {
                                break;
                        } else {
                                printf ("Printed %d bytes\n", sz);