| 1 |
#ifndef _CANL_LOCL_H |
| 2 |
#define _CANL_LOCL_H |
| 3 |
|
| 4 |
#define _GNU_SOURCE |
| 5 |
#include <stdio.h> |
| 6 |
#include <errno.h> |
| 7 |
#include <ares.h> |
| 8 |
#include <ares_version.h> |
| 9 |
#include <netdb.h> |
| 10 |
#include <unistd.h> |
| 11 |
#include <fcntl.h> |
| 12 |
#include <stdlib.h> |
| 13 |
#include <stdarg.h> |
| 14 |
#include <stdarg.h> |
| 15 |
#include <sys/types.h> |
| 16 |
#include <sys/time.h> |
| 17 |
#include <arpa/inet.h> |
| 18 |
#include <sys/socket.h> |
| 19 |
#include <string.h> |
| 20 |
|
| 21 |
#include "sslutils.h" |
| 22 |
#include "canl.h" |
| 23 |
#include "canl_err.h" |
| 24 |
|
| 25 |
typedef struct canl_err_desc { |
| 26 |
canl_error code; |
| 27 |
const char *desc; |
| 28 |
unsigned long openssl_lib; |
| 29 |
unsigned long openssl_reason; |
| 30 |
} canl_err_desc; |
| 31 |
|
| 32 |
typedef enum canl_err_origin { |
| 33 |
UNKNOWN_ERROR = 0, |
| 34 |
POSIX_ERROR, |
| 35 |
SSL_ERROR, |
| 36 |
CANL_ERROR, |
| 37 |
NETDB_ERROR, |
| 38 |
} canl_err_origin; |
| 39 |
|
| 40 |
typedef enum _CANL_AUTH_MECHANISM |
| 41 |
{ |
| 42 |
AUTH_UNDEF = -1, |
| 43 |
x509 = 0, |
| 44 |
KRB5 = 1, /* and others may be added*/ |
| 45 |
TLS, |
| 46 |
GSSAPI, |
| 47 |
} CANL_AUTH_MECHANISM; |
| 48 |
|
| 49 |
typedef struct _glb_ctx |
| 50 |
{ |
| 51 |
char * err_msg; |
| 52 |
canl_err_code err_code; |
| 53 |
/* XXX Do we need to keep these two:? */ |
| 54 |
canl_err_origin err_orig; |
| 55 |
long original_err_code; |
| 56 |
void *mech_ctx; |
| 57 |
} glb_ctx; |
| 58 |
|
| 59 |
typedef struct _asyn_result { |
| 60 |
struct hostent *ent; |
| 61 |
int err; |
| 62 |
} asyn_result; |
| 63 |
|
| 64 |
typedef struct _principal_int { |
| 65 |
char *name; |
| 66 |
// CANL_AUTH_MECHANISM mech_oid; |
| 67 |
// char *raw; /* e.g. the PEM encoded cert/chain */ |
| 68 |
} principal_int; |
| 69 |
|
| 70 |
typedef struct _io_handler |
| 71 |
{ |
| 72 |
int sock; |
| 73 |
principal_int *princ_int; |
| 74 |
void *conn_ctx; //like SSL * |
| 75 |
gss_OID oid; |
| 76 |
} io_handler; |
| 77 |
|
| 78 |
typedef struct canl_mech { |
| 79 |
CANL_AUTH_MECHANISM mech; |
| 80 |
|
| 81 |
canl_err_code (*initialize) |
| 82 |
(glb_ctx *); |
| 83 |
|
| 84 |
canl_err_code (*set_flags) |
| 85 |
(glb_ctx *cc, unsigned int *mech_flags, unsigned int flags); |
| 86 |
|
| 87 |
canl_err_code (*finish) |
| 88 |
(glb_ctx *, void *); |
| 89 |
|
| 90 |
canl_err_code (*client_init) |
| 91 |
(glb_ctx *, void **); |
| 92 |
|
| 93 |
canl_err_code (*server_init) |
| 94 |
(glb_ctx *, void **); |
| 95 |
|
| 96 |
canl_err_code (*free_ctx) |
| 97 |
(glb_ctx *); |
| 98 |
|
| 99 |
canl_err_code (*connect) |
| 100 |
(glb_ctx *, io_handler *, void *, struct timeval *, const char *); |
| 101 |
|
| 102 |
canl_err_code (*accept) |
| 103 |
(glb_ctx *, io_handler *, void *, struct timeval *); |
| 104 |
|
| 105 |
canl_err_code (*close) |
| 106 |
(glb_ctx *, io_handler *, void *); |
| 107 |
|
| 108 |
size_t (*read) |
| 109 |
(glb_ctx *, io_handler *, void *, void *, size_t, struct timeval *); |
| 110 |
|
| 111 |
size_t (*write) |
| 112 |
(glb_ctx *, io_handler *, void *, void *, size_t, struct timeval *); |
| 113 |
|
| 114 |
canl_err_code (*get_peer) |
| 115 |
(glb_ctx *, io_handler *, void *, canl_principal *); |
| 116 |
|
| 117 |
} canl_mech; |
| 118 |
|
| 119 |
/* Mechanism specific */ |
| 120 |
extern canl_mech canl_mech_ssl; |
| 121 |
|
| 122 |
extern canl_err_desc canl_err_descs[]; |
| 123 |
extern int canl_err_descs_num; |
| 124 |
|
| 125 |
struct canl_mech * |
| 126 |
find_mech(gss_OID oid); |
| 127 |
|
| 128 |
|
| 129 |
void reset_error (glb_ctx *cc, unsigned long err_code); |
| 130 |
canl_err_code set_error (glb_ctx *cc, unsigned long err_code, |
| 131 |
canl_err_origin err_orig, const char *err_format, ...); |
| 132 |
canl_err_code update_error (glb_ctx *cc, unsigned long err_code, |
| 133 |
canl_err_origin err_orig, const char *err_format, ...); |
| 134 |
void free_hostent(struct hostent *h); //TODO is there some standard funcion to free hostent? |
| 135 |
int canl_asyn_getservbyname(int a_family, asyn_result *ares_result,char const *name, |
| 136 |
struct timeval *timeout); |
| 137 |
|
| 138 |
#endif |