Added TPQ client and server examples to build system, now compiles.
authorMargaret Wasserman <mrw@painless-security.com>
Tue, 4 Dec 2012 20:17:12 +0000 (15:17 -0500)
committerMargaret Wasserman <mrw@painless-security.com>
Tue, 4 Dec 2012 20:17:12 +0000 (15:17 -0500)
Makefile.am
include/tpq.h
tpq/example/tpqc_main.c
tpq/example/tpqs_main.c
tpq/tpq_common.c
tpq/tpqc.c
tpq/tpqs.c
tr/tr_main.c

index 7a9474d..9eadb0f 100644 (file)
@@ -1,11 +1,24 @@
-bin_PROGRAMS= tr/tr
+bin_PROGRAMS= tr/tr tpq/tpqc tpq/tpqs
 AM_CPPFLAGS=-I$(srcdir)/include
-SUBDIRS = gsscon .
+SUBDIRS = gsscon 
 
 tr_tr_SOURCES = tr/tr_main.c \
 tpq/tpqs.c \
+tpq/tpq_common.c \
 common/tr_config.c
 
 tr_tr_LDADD = gsscon/libgsscon.la
 
+tpq_tpqc_SOURCES = tpq/example/tpqc_main.c \
+tpq/tpqc.c \
+tpq/tpq_common.c
+
+tpq_tpqc_LDADD = gsscon/libgsscon.la
+
+tpq_tpqs_SOURCES = tpq/example/tpqs_main.c \
+tpq/tpqs.c \
+tpq/tpq_common.c
+
+tpq_tpqs_LDADD = gsscon/libgsscon.la
+
 
index 0f8d847..c2ec6e8 100644 (file)
@@ -45,15 +45,15 @@ typedef struct tpq_name {
 typedef struct tpq_req {
   struct tpq_req *next_req;
   int conn;
-  TPQ_NAME realm;
-  TPQ_NAME coi;
+  TPQ_NAME *realm;
+  TPQ_NAME *coi;
   void *resp_func;
   void *cookie;
 } TPQ_REQ;
 
 typedef struct tpq_resp {
-  TPQ_NAME realm;
-  TPQ_NAME coi;
+  TPQ_NAME *realm;
+  TPQ_NAME *coi;
   /* Address of AAA Server */
   /* Credentials */
   /* Trust Path Used */
@@ -65,10 +65,12 @@ typedef struct tpqc_instance {
 
 typedef struct tpqs_instance {
   int req_count;
+  void *req_handler;
+  void *cookie;
 } TPQS_INSTANCE;
 
-typedef void (*TPQC_RESP_FUNC)(TPQC_INSTANCE *, TPQ_RESP *, void *);
-typedef int (*TPQS_REQ_FUNC)(TPQS_INSTANCE *, TPQ_REQ *, TPQ_RESP *, void *);
+typedef void (TPQC_RESP_FUNC)(TPQC_INSTANCE *, TPQ_RESP *, void *);
+typedef int (TPQS_REQ_FUNC)(TPQS_INSTANCE *, TPQ_REQ *, TPQ_RESP *, void *);
 
 TPQ_NAME *tpq_dup_name (TPQ_NAME *from);
 
@@ -78,7 +80,7 @@ int tpqc_send_request (TPQC_INSTANCE *tpqc, int conn, char *realm, char *coi, TP
 void tpqc_destroy (TPQC_INSTANCE *tpqc);
 
 TPQS_INSTANCE *tpqs_create ();
-int tpqs_start (TPQS_INSTANCE *tpqs);
+int tpqs_start (TPQS_INSTANCE *tpqs, TPQS_REQ_FUNC *req_handler, void *cookie);
 void tpqs_destroy (TPQS_INSTANCE *tpqs);
 
 #endif
index cef89c3..19369dd 100644 (file)
  *
  */
 
-#include <stdio,h>
+#include <stdio.h>
+
 #include <tpq.h>
 
 static int tpqc_response_received = 0;
 
-void tpqc_print_usage (char *name)
+void tpqc_print_usage (const char *name)
 {
   printf("Usage: %s <server> <realm> <coi>\n", name);
 }
@@ -61,15 +62,16 @@ int main (int argc,
   char *coi = NULL;
   void *cookie = NULL;
   int conn = 0;
+  int rc;
 
   /* Parse command-line arguments */ 
   if (argc != 4)
     tpqc_print_usage(argv[0]);
 
   /* TBD -- validity checking, dealing with quotes, etc. */
-  server = argv[1];
-  realm = argv[2];
-  coi = argv[3];
+  server = (char *)argv[1];
+  realm = (char *)argv[2];
+  coi = (char *)argv[3];
 
   /* Create a TPQ client instance */
   tpqc = tpqc_create();
@@ -77,12 +79,12 @@ int main (int argc,
   /* Set-up TPQ connection */
   if (-1 == (conn = tpqc_open_connection(tpqc, server))) {
     /* Handle error */
-    print("Error in tpqc_open_connection.\n");
+    printf("Error in tpqc_open_connection.\n");
     return 1;
   };
 
   /* Send a TPQ request */
-  if (rc = tpqc_send_request(tpqc, conn, realm, coi, tpqc_resp_handler, NULL)) {
+  if (rc = tpqc_send_request(tpqc, conn, realm, coi, &tpqc_resp_handler, NULL)) {
     /* Handle error */
     printf("Error in tpqc_send_request, rc = &d.\n", rc);
     return 1;
@@ -92,7 +94,7 @@ int main (int argc,
   while (!tpqc_response_received);
 
   /* Clean-up the TPQ client instance, and exit */
-  tpqc_release(tpqc);
+  tpqc_destroy(tpqc);
 
   return 0;
 }
index 70784c3..f843d2c 100644 (file)
  *
  */
 
-#include <stdio,h>
+#include <stdio.h>
+
 #include <tpq.h>
 
-int tpqc_req_handler (TPQS_INSTANCE * tpqs,
+int tpqs_req_handler (TPQS_INSTANCE * tpqs,
                      TPQ_REQ *req, 
                      TPQ_RESP *resp,
-                     void *cookie);
+                     void *cookie)
 {
   printf("Request received! Realm = %s, COI = %s\n", req->realm->buf, req->coi->buf);
   if (tpqs)
@@ -64,12 +65,13 @@ int main (int argc,
     printf("Unexpected arguments, ignored.\n");
 
   /* Create a TPQ server instance */
-  tpqc = tpqc_create();
+  tpqs = tpqs_create();
 
   /* Start-up the server, won't return unless there is an error. */
+  tpqs_start(tpqs, &tpqs_req_handler , NULL);
 
   /* Clean-up the TPQ server instance */
-  tpqs_release(tpqs);
+  tpqs_destroy(tpqs);
 
   return 1;
 }
index 50fb0e4..5c78043 100644 (file)
  *
  */
 
+#include <stdlib.h>
+#include <string.h>
+
 #include <tpq.h>
 
+TPQ_NAME *tpq_new_name (char *name) 
+{
+  TPQ_NAME *new;
+
+  if (new = malloc(sizeof(TPQ_NAME))) { 
+    new->len = strlen(name);
+    if (new->buf = malloc(new->len+1)) {
+      strcpy(new->buf, name);
+    }
+  }
+  return new;
+}
+
 TPQ_NAME *tpq_dup_name (TPQ_NAME *from) 
 {
-  TPQ_NAME to;
+  TPQ_NAME *to;
 
-  to.len = from->len;
-  to.buf = malloc(to.len+1);
-  strncpy(from->buf, to.buf, to.len);
-  to.buf[to.len] = 0;          /* NULL terminate for debugging printf()s */
+  if (to = malloc(sizeof(TPQ_NAME))) {
+    to->len = from->len;
+    if (to->buf = malloc(to->len+1)) {
+      strncpy(to->buf, from->buf, to->len);
+      to->buf[to->len] = 0;    /* NULL terminate for debugging printf()s */
+    }
+  }
 
-  return &to;
+  return to;
 }
index a9be6bb..b31d78f 100644 (file)
@@ -57,7 +57,7 @@ int tpqc_open_connection (TPQC_INSTANCE *tpqc,
 
   err = gsscon_connect(server, TPQ_PORT, &conn);
   if (!err)
-    err = fsscon_active_authenticate(conn, NULL, "trustquery", &gssContext);
+    err = gsscon_active_authenticate(conn, NULL, "trustquery", &gssContext);
 
   if (!err)
     return conn;
index 1671b35..416b3b1 100644 (file)
@@ -45,7 +45,9 @@ TPQS_INSTANCE *tpqs_create ()
   return tpqs;
 }
 
-int tpqs_start (TPQS_INSTANCE *tpqs)
+int tpqs_start (TPQS_INSTANCE *tpqs, 
+               TPQS_REQ_FUNC *req_handler,
+               void *cookie)
 {
 
   return 1;
index bc57024..f539ce4 100644 (file)
 
 #include <trust_router.h>
 
+int tpqs_req_handler (TPQS_INSTANCE * tpqs,
+                     TPQ_REQ *req, 
+                     TPQ_RESP *resp,
+                     void *cookie)
+{
+  printf("Request received! Realm = %s, COI = %s\n", req->realm->buf, req->coi->buf);
+  if (tpqs)
+    tpqs->req_count++;
+
+  if ((NULL == (resp->realm = tpq_dup_name(req->realm))) ||
+      (NULL == (resp->coi = tpq_dup_name(req->coi)))) {
+    printf ("Error in tpq_dup_name, not responding.\n");
+    return 1;
+  }
+
+  return 0;
+}
+
 int main (int argc, const char *argv[])
 {
   TPQS_INSTANCE *tpqs = 0;
@@ -59,15 +77,12 @@ int main (int argc, const char *argv[])
     return 1;
   }
 
-  /* start the trust path query server, runs in its own thread */
-  if (0 != (err = tpqs_start(tpqs))) {
+  /* start the trust path query server, won't return unless there is an error. */
+  if (0 != (err = tpqs_start(tpqs, &tpqs_req_handler, NULL))) {
     printf ("Error starting Trust Path Query Server, err = %d.\n", err);
     return err;
   }
 
-  /* start the trust router protocol engine -- TBD */
-  while (1);
-
   tpqs_destroy(tpqs);
   return 0;
 }