#include <config.h>
#include <stdio.h>
#include <syslog.h>
#include <poll.h>
#include <errno.h>
#include <arpa/inet.h>
#include <radcli/radcli2.h>
static void
print_reply(radcli_ctx *ctx, const radcli_avp_list *recvd)
{
uint32_t timeout, service_type;
struct in6_addr framed_ipv6;
char buf[INET6_ADDRSTRLEN];
fprintf(stderr, "Session-Timeout: %u seconds\n", (unsigned)timeout);
inet_ntop(AF_INET6, &framed_ipv6, buf, sizeof(buf)) != NULL)
fprintf(stderr, "Framed-IPv6-Address: %s\n", buf);
fprintf(stderr, "Service-Type: %u\n", (unsigned)service_type);
}
static void
{
(void)user;
return;
}
printf("Disconnect-Request for user '%s', session '%s'\n",
user_name ? user_name : "?", session_id ? session_id : "?");
}
int
main (int argc, char **argv)
{
radcli_ctx *ctx;
radcli_avp_list *send = NULL;
radcli_request *r;
int result = 1;
openlog("my-prog-name", LOG_PID, LOG_DAEMON);
if (ctx == NULL)
return 1;
if (dae == NULL) {
fprintf(stderr, "dynamic authorization is not enabled or is "
"misconfigured (check dae-accept/dae-server/dae-secret)\n");
return 1;
}
fprintf(stderr, "cannot start the DAE listener\n");
return 1;
}
fprintf(stderr, "error constructing the Access-Request\n");
return 1;
}
if (r == NULL) {
return 1;
}
fprintf(stderr, "cannot send the Access-Request\n");
return 1;
}
for (;;) {
size_t nfds;
int timeout_ms;
int ret;
break;
if (nfds == 0)
break;
ret = poll(pfds, (nfds_t)nfds, timeout_ms);
if (ret < 0) {
if (errno == EINTR)
continue;
break;
}
if (r != NULL) {
fprintf(stderr, "\"my-username\" RADIUS Authentication OK\n");
result = 0;
} else {
fprintf(stderr, "\"my-username\" RADIUS Authentication failure\n");
}
r = NULL;
}
}
}
if (dae != NULL)
if (r != NULL)
return result;
}
void radcli_dae_free(radcli_dae *dae)
Release a listener, closing its socket if radcli_dae_start() opened one.
const char * radcli_dae_req_session_id(const radcli_dae_request *req)
Return the request's Acct-Session-Id, if it carried one.
int radcli_ctx_get_poll(radcli_ctx *ctx, struct pollfd *pfds, size_t max_pfds, size_t *nfds, int *timeout_ms)
Report what to wait for on ctx's behalf, for the caller's own event loop – radcli never calls poll()/...
void radcli_dae_set_handler(radcli_dae *dae, radcli_dae_handler cb, void *user)
Register the callback radcli_ctx_dispatch() invokes for each validated request. May be called before ...
radcli_code radcli_dae_req_code(const radcli_dae_request *req)
Return the received packet's RADIUS code.
int radcli_ctx_dispatch(radcli_ctx *ctx)
Read what is ready on ctx's descriptor(s), validate it, and invoke the registered handler for anythin...
int radcli_dae_reply(radcli_dae_request *req, int ack)
Answer a request with an ACK or NAK, selecting 41/42 or 44/45 from the request's own code,...
struct radcli_dae_st radcli_dae
const char * radcli_dae_req_user_name(const radcli_dae_request *req)
Return the request's User-Name, if it carried one.
int radcli_dae_start(radcli_dae *dae)
Start receiving: binds the socket described by dae-listen.
#define RADCLI_CTX_MAX_POLLFDS
int radcli_dae_reply_error(radcli_dae_request *req, uint32_t error_cause)
Answer a request with a NAK carrying the given Error-Cause.
radcli_dae * radcli_dae_new(radcli_ctx *ctx, unsigned flags)
Validate dae-* configuration and build a dynamic-authorization listener. Opens no socket – see radcli...
struct radcli_dae_request_st radcli_dae_request
void radcli_dae_request_free(radcli_dae_request *req)
Release a request.
int radcli_avp_list_error(const radcli_avp_list *list)
Check whether any radcli_avp_add_*()/_by_num() call on list has ever failed.
void radcli_avp_list_free(radcli_avp_list *list)
Free a list and every attribute it holds.
int radcli_avp_add_uint32_by_num(radcli_avp_list *list, const radcli_ctx *ctx, uint32_t attrid, uint32_t vendor, uint32_t value)
Look up an integer/IPv4-address/date-typed attribute by legacy numeric ID and append it.
int radcli_avp_add_str_by_num(radcli_avp_list *list, const radcli_ctx *ctx, uint32_t attrid, uint32_t vendor, const char *value)
Look up a string-typed attribute by legacy numeric ID and append it.
int radcli_avp_get_uint32_by_num(const radcli_avp_list *list, const radcli_ctx *ctx, uint32_t attrid, uint32_t vendor, uint32_t *out)
Look up an integer/IPv4-address/date-typed attribute by legacy numeric ID and read its first occurren...
radcli_avp_list * radcli_avp_list_new(void)
Create an empty attribute-value pair list.
int radcli_avp_get_ip6_by_num(const radcli_avp_list *list, const radcli_ctx *ctx, uint32_t attrid, uint32_t vendor, struct in6_addr *out, unsigned *prefix)
Look up an IPv6-address or IPv6-prefix-typed attribute by legacy numeric ID and read its first occurr...
radcli_ctx * radcli_ctx_read_config(const char *filename, unsigned flags)
Create a context by parsing a config file – the main, recommended way to configure radcli.
void radcli_ctx_free(radcli_ctx *ctx)
Release a context.
int radcli_request_perform(radcli_request *r, unsigned flags)
Send a request, optionally waiting for the reply.
const radcli_avp_list * radcli_request_attrs(const radcli_request *r)
Return the reply's decoded attributes.
int radcli_request_done(radcli_request *r)
Report r's outcome once radcli_ctx_dispatch() has resolved it – a pure state query,...
radcli_request * radcli_request_new(radcli_ctx *ctx, radcli_code code, const radcli_avp_list *send)
Create a request to send.
void radcli_request_free(radcli_request *r)
Release a request.
radcli_code radcli_request_code(const radcli_request *r)
Return the reply's RADIUS code.
@ RADCLI_OK
A validated reply was received; see radcli_request_code() for which one.
@ RADCLI_REQUEST_SENDONLY