routines to establish authentication grouped into a single structure
authorDaniel Kouřil <kouril@ics.muni.cz>
Tue, 17 Jan 2012 20:10:21 +0000 (20:10 +0000)
committerDaniel Kouřil <kouril@ics.muni.cz>
Tue, 17 Jan 2012 20:10:21 +0000 (20:10 +0000)
emi.canl.canl-c/src/canl.c
emi.canl.canl-c/src/canl_locl.h
emi.canl.canl-c/src/canl_ssl.c

index 8fbad61..24b753f 100644 (file)
@@ -1,5 +1,9 @@
 #include "canl_locl.h"
 
+static struct canl_mech *mechs[] = {
+    &canl_mech_ssl,
+};
+
 static void io_destroy(glb_ctx *cc, io_handler *io);
 static int init_io_content(glb_ctx *cc, io_handler *io);
 static int try_connect(glb_ctx *glb_cc, io_handler *io_cc, char *addr,
@@ -14,7 +18,7 @@ canl_ctx canl_create_ctx()
     if (!ctx) 
         return NULL;
 
-    ssl_init();
+    ssl_initialize();
 
     return ctx;
 }
index d96a463..4c8d405 100644 (file)
@@ -50,7 +50,9 @@ typedef enum _CANL_ERROR_ORIGIN
 typedef enum _CANL_AUTH_MECHANISM
 {
     x509 = 0,
-    kerberos = 1, /* and others may be added*/
+    KRB5 = 1, /* and others may be added*/
+    TLS,
+    GSSAPI,
 } CANL_AUTH_MECHANISM;
 
 typedef struct _cert_key_store {
@@ -90,6 +92,37 @@ typedef struct _io_handler
     principal_int *princ_int;
 } io_handler;
 
+typedef struct canl_mech {
+    CANL_AUTH_MECHANISM mech;
+    void *context;
+
+    canl_err_code (*initialize)
+        (void);
+
+    canl_err_code (*client_init)
+        (glb_ctx *);
+
+    canl_err_code (*server_init)
+        (glb_ctx *);
+
+    canl_err_code (*connect)
+        (glb_ctx *, io_handler *, struct timeval *, const char *);
+
+    canl_err_code (*accept)
+        (glb_ctx *, io_handler *, struct timeval *);
+
+    canl_err_code (*close)
+        (glb_ctx *, io_handler *);
+
+    canl_err_code (*read)
+        (glb_ctx *, io_handler *, void *, size_t, struct timeval *);
+
+    canl_err_code (*write)
+        (glb_ctx *, io_handler *, void *, size_t, struct timeval *);
+} canl_mech;
+
+extern struct canl_mech canl_mech_ssl;
+
 void reset_error (glb_ctx *cc, unsigned long err_code);
 int set_error (glb_ctx *cc, unsigned long err_code, CANL_ERROR_ORIGIN err_orig,
         const char *err_format, ...);
@@ -107,6 +140,6 @@ int ssl_read(glb_ctx *cc, io_handler *io, void *buffer, size_t size,
 int ssl_write(glb_ctx *cc, io_handler *io, void *buffer, size_t size, 
         struct timeval *tout);
 int ssl_close(glb_ctx *cc, io_handler *io);
-int ssl_init();
+int ssl_initialize();
 
 #endif
index 7253306..f687c36 100644 (file)
@@ -11,7 +11,7 @@ static int check_hostname_cert(glb_ctx *cc, io_handler *io, const char *host);
 static void dbg_print_ssl_error(int errorcode);
 #endif
 
-int ssl_init()
+int ssl_initialize()
 {
     SSL_library_init();
     SSL_load_error_strings();
@@ -808,3 +808,16 @@ static void dbg_print_ssl_error(int errorcode)
     }
 }
 #endif
+
+struct canl_mech canl_mech_ssl = {
+    TLS,
+    NULL,
+    ssl_initialize,
+    ssl_client_init,
+    ssl_server_init,
+    ssl_connect,
+    ssl_accept,
+    ssl_close,
+    ssl_read,
+    ssl_write
+};