From: Alan T. DeKok Date: Tue, 16 Jan 2018 19:23:07 +0000 (-0500) Subject: add client_clone() for connected UDP sockets X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05a9efebd18f629d223b1085742f78bb524f8b4e;p=thirdparty%2Ffreeradius-server.git add client_clone() for connected UDP sockets --- diff --git a/src/include/clients.h b/src/include/clients.h index d494461864b..41f22caa829 100644 --- a/src/include/clients.h +++ b/src/include/clients.h @@ -156,6 +156,9 @@ RADCLIENT *client_find(RADCLIENT_LIST const *clients, fr_ipaddr_t const *ipaddr, RADCLIENT *client_findbynumber(RADCLIENT_LIST const *clients, int number); RADCLIENT *client_read(char const *filename, CONF_SECTION *server_cs, bool check_dns); + + +RADCLIENT *client_clone(TALLOC_CTX *ctx, RADCLIENT const *parent); #ifdef __cplusplus } #endif diff --git a/src/main/client.c b/src/main/client.c index c0fc93c71eb..c5538262315 100644 --- a/src/main/client.c +++ b/src/main/client.c @@ -983,3 +983,46 @@ RADCLIENT *client_read(char const *filename, CONF_SECTION *server_cs, bool check } #endif +RADCLIENT *client_clone(TALLOC_CTX *ctx, RADCLIENT const *parent) +{ + RADCLIENT *c; + + c = talloc_zero(ctx, RADCLIENT); + if (!c) return NULL; + + /* + * Do NOT set ipaddr or src_ipaddr. The caller MUST do this! + */ + +#define DUP_FIELD(_x) c->_x = talloc_strdup(c, parent->_x); if (!c->_x) goto error +#define COPY_FIELD(_x) c->_x = parent->_x + + DUP_FIELD(longname); + DUP_FIELD(shortname); + DUP_FIELD(secret); + DUP_FIELD(nas_type); + DUP_FIELD(server); + DUP_FIELD(nas_type); + + COPY_FIELD(message_authenticator); + /* dynamic MUST be false */ + COPY_FIELD(server_cs); + COPY_FIELD(cs); + COPY_FIELD(proto); + +#ifdef WITH_TLS + COPY_FIELD(tls_required); +#endif + + /* + * @todo - fill in other fields, too! + */ + + if (0) { + error: + talloc_free(c); + return NULL; + } + + return c; +}