diff options
author | Linus Nordberg <linus@nordu.net> | 2010-10-03 22:51:29 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2010-10-03 22:51:29 +0200 |
commit | 4d99bb55ec1368b42daccb29f0440bc166297a17 (patch) | |
tree | dff2f47b6555583c71ff38207e7efaedb9dd459e | |
parent | 63a5bc0182881d8f806a9acdf47b708492b8a41b (diff) |
WIP
-rw-r--r-- | lib/examples/client-blocking.c | 24 | ||||
-rw-r--r-- | lib/include/radsec/radsec-impl.h | 21 | ||||
-rw-r--r-- | lib/include/radsec/radsec.h | 9 | ||||
-rw-r--r-- | lib/radsec.c | 63 |
4 files changed, 62 insertions, 55 deletions
diff --git a/lib/examples/client-blocking.c b/lib/examples/client-blocking.c index 9a211c8..a9a4f32 100644 --- a/lib/examples/client-blocking.c +++ b/lib/examples/client-blocking.c @@ -16,7 +16,7 @@ #define USER_PW "hemligt" struct rs_error * -blocking_client (const char *srvname, int srvport) +blocking_client (const char *av1, const char *av2) { struct rs_handle *h; struct rs_connection *conn; @@ -28,13 +28,23 @@ blocking_client (const char *srvname, int srvport) if (rs_context_create (&h, "/usr/share/freeradius/dictionary")) return NULL; - if (rs_conn_create (h, &conn)) + if (rs_conn_create (h, &conn, RS_CONN_TYPE_UDP)) return rs_err_conn_pop (conn); - if (rs_conn_add_server (conn, &server, RS_CONN_TYPE_UDP, srvname, srvport)) +#if !defined (USE_CONFIG_FILE) + if (rs_server_create (conn, &server, NULL)) + return rs_err_conn_pop (conn); + if (rs_server_set_address (server, av1, atoi (av2))) return rs_err_conn_pop (conn); rs_server_set_timeout (server, 1); rs_server_set_tries (server, 3); - rs_server_set_secret (server, SECRET); + if (rs_server_set_secret (server, SECRET)) + return rs_err_conn_pop (conn); +#else + if (rs_context_config_read (h, av1)) + return rs_err_ctx_pop (h); + if (rs_server_create (conn, &server, av2)) + return rs_err_conn_pop (conn); +#endif /* USE_CONFIG_FILE */ if (rs_packet_create_acc_request (conn, &req, USER_NAME, USER_PW)) return rs_err_conn_pop (conn); @@ -71,12 +81,8 @@ int main (int argc, char *argv[]) { struct rs_error *err; - char *host; - int port; - host = strsep (argv + 1, ":"); - port = atoi (argv[1]); - err = blocking_client (host, port); + err = blocking_client (argv[1], argv[2]); if (err) { fprintf (stderr, "%s\n", rs_err_msg (err, 0)); diff --git a/lib/include/radsec/radsec-impl.h b/lib/include/radsec/radsec-impl.h index c92d9e9..4f7fa2c 100644 --- a/lib/include/radsec/radsec-impl.h +++ b/lib/include/radsec/radsec-impl.h @@ -30,25 +30,30 @@ struct rs_error { char buf[1024]; }; -struct rs_handle { - struct rs_alloc_scheme alloc_scheme; - struct rs_error *err; - fr_randctx fr_randctx; - /* TODO: dictionary? */ -}; - struct rs_peer { struct rs_connection *conn; struct evutil_addrinfo *addr; int fd; /* Socket. */ char is_connecting; /* FIXME: replace with a single state member */ - char is_connected; /* FIXME: replace */ + char is_connected; /* FIXME: replace with a single state member */ char *secret; int timeout; /* client only */ int tries; /* client only */ struct rs_peer *next; }; +struct rs_realm { + char *name; + struct rs_peer *peers; +}; + +struct rs_handle { + struct rs_realm *realms; + struct rs_alloc_scheme alloc_scheme; + struct rs_error *err; + fr_randctx fr_randctx; +}; + struct rs_connection { struct rs_handle *ctx; struct event_base *evb; diff --git a/lib/include/radsec/radsec.h b/lib/include/radsec/radsec.h index dea4109..f92da7f 100644 --- a/lib/include/radsec/radsec.h +++ b/lib/include/radsec/radsec.h @@ -73,16 +73,17 @@ struct rs_conn_callbacks { int rs_context_create(struct rs_handle **ctx, const char *dict); void rs_context_destroy(struct rs_handle *ctx); int rs_context_set_alloc_scheme(struct rs_handle *ctx, struct rs_alloc_scheme *scheme); -int rs_context_config_read(struct rs_handle *ctx, const char *config_file); +int rs_context_read_config(struct rs_handle *ctx, const char *config_file); /* Server and client configuration. */ +int rs_server_create(struct rs_connection *conn, struct rs_peer **server, const char *config); +int rs_server_set_address(struct rs_peer *server, const char *hostname, int port); +int rs_server_set_secret(struct rs_peer *server, const char *secret); void rs_server_set_timeout(struct rs_peer *server, int timeout); void rs_server_set_tries(struct rs_peer *server, int tries); -int rs_server_set_secret(struct rs_peer *server, const char *secret); /* Connection. */ -int rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn); -int rs_conn_add_server(struct rs_connection *conn, struct rs_peer **server, rs_conn_type_t type, const char *hostname, int port); +int rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn, rs_conn_type_t type); int rs_conn_add_listener(struct rs_connection *conn, rs_conn_type_t type, const char *hostname, int port); void rs_conn_destroy(struct rs_connection *conn); int rs_conn_set_eventbase(struct rs_connection *conn, struct event_base *eb); diff --git a/lib/radsec.c b/lib/radsec.c index 35e159d..6ec2b06 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -79,7 +79,9 @@ int rs_context_config_read(struct rs_handle *ctx, const char *config_file) "%s: NYI", __func__); } -int rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn) +int +rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn, + rs_conn_type_t type) { struct rs_connection *c; @@ -88,6 +90,7 @@ int rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn) { memset (c, 0, sizeof(struct rs_connection)); c->ctx = ctx; + c->type = type; } if (conn) *conn = c; @@ -132,14 +135,9 @@ _resolv (struct rs_connection *conn, const char *hostname, int port) } static struct rs_peer * -_peer_new (struct rs_connection *conn, const char *hostname, int port) +_peer_new (struct rs_connection *conn) { struct rs_peer *p; - struct evutil_addrinfo *addr; - - addr = _resolv (conn, hostname, port); - if (!addr) - return NULL; p = (struct rs_peer *) malloc (sizeof(*p)); if (p) @@ -147,7 +145,6 @@ _peer_new (struct rs_connection *conn, const char *hostname, int port) memset (p, 0, sizeof(struct rs_peer)); p->conn = conn; p->fd = -1; - p->addr = addr; p->next = conn->peers; if (conn->peers) conn->peers->next = p; @@ -155,44 +152,46 @@ _peer_new (struct rs_connection *conn, const char *hostname, int port) conn->peers = p; } else - { - evutil_freeaddrinfo (addr); - rs_err_conn_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL); - } + rs_err_conn_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL); return p; } int -rs_conn_add_server(struct rs_connection *conn, struct rs_peer **server, - rs_conn_type_t type, const char *hostname, int port) +rs_server_create (struct rs_connection *conn, struct rs_peer **server, + const char *config) { struct rs_peer *srv; - if (conn->type == RS_CONN_TYPE_NONE) - conn->type = type; - else if (conn->type != type) - return rs_err_conn_push (conn, RSE_CONN_TYPE_MISMATCH, NULL); - - srv = _peer_new (conn, hostname, port); + srv = _peer_new (conn); if (srv) { - srv->timeout = 10; + srv->timeout = 1; srv->tries = 3; } - if (*server) - *server = srv; + *server = srv; return srv ? RSE_OK : -1; } -void rs_server_set_timeout(struct rs_peer *server, int timeout) +int +rs_server_set_address (struct rs_peer *server, const char *hostname, int port) +{ + server->addr = _resolv (server->conn, hostname, port); + return server->addr ? RSE_OK : -1; +} + +void +rs_server_set_timeout (struct rs_peer *server, int timeout) { server->timeout = timeout; } -void rs_server_set_tries(struct rs_peer *server, int tries) +void +rs_server_set_tries (struct rs_peer *server, int tries) { server->tries = tries; } -int rs_server_set_secret(struct rs_peer *server, const char *secret) + +int +rs_server_set_secret (struct rs_peer *server, const char *secret) { if (server->secret) free (server->secret); @@ -203,14 +202,16 @@ int rs_server_set_secret(struct rs_peer *server, const char *secret) return RSE_OK; } -int rs_conn_add_listener(struct rs_connection *conn, rs_conn_type_t type, const char *hostname, int port) +int +rs_conn_add_listener (struct rs_connection *conn, rs_conn_type_t type, + const char *hostname, int port) { return rs_err_conn_push_fl (conn, RSE_NOSYS, __FILE__, __LINE__, "%s: NYI", __func__); } void -rs_conn_destroy(struct rs_connection *conn) +rs_conn_destroy (struct rs_connection *conn) { struct rs_peer *p; @@ -240,12 +241,6 @@ int rs_conn_set_callbacks(struct rs_connection *conn, struct rs_conn_callbacks * "%s: NYI", __func__); } -int rs_conn_set_server(struct rs_connection *conn, const char *name) -{ - return rs_err_conn_push_fl (conn, RSE_NOSYS, __FILE__, __LINE__, - "%s: NYI", __func__); -} - int rs_conn_get_current_server(struct rs_connection *conn, const char *name, size_t buflen) { return rs_err_conn_push_fl (conn, RSE_NOSYS, __FILE__, __LINE__, |