]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add client_clone() for connected UDP sockets
authorAlan T. DeKok <aland@freeradius.org>
Tue, 16 Jan 2018 19:23:07 +0000 (14:23 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 16 Jan 2018 20:24:44 +0000 (15:24 -0500)
src/include/clients.h
src/main/client.c

index d494461864bd71187ab58ecca5b7402bc7249dc9..41f22caa829fdf016b775f838586bbc39c81dc0d 100644 (file)
@@ -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
index c0fc93c71ebc32cdafa4ddad44a73bf09531c97d..c5538262315b704e09a6bab202ef1ea9388cedb1 100644 (file)
@@ -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;
+}