diff options
| author | Felix Fietkau | 2025-01-29 19:12:51 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2025-01-29 19:12:53 +0000 |
| commit | aff192cda38b56180dd00e90702e46ecd5fc1465 (patch) | |
| tree | 3690590adda4ba118a87fb8e6c9e999538dbf301 | |
| parent | c293afa01c1328ee8a18fc407948d0529353d7eb (diff) | |
| download | unetd-aff192cda38b56180dd00e90702e46ecd5fc1465.tar.gz | |
ubus: hide local private key in network_get
Private key should only be written, not returned
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | network.c | 20 | ||||
| -rw-r--r-- | network.h | 1 | ||||
| -rw-r--r-- | ubus.c | 6 |
3 files changed, 21 insertions, 6 deletions
@@ -585,6 +585,21 @@ network_destroy(struct network *net) free(net); } +void network_get_config(struct network *net, struct blob_buf *buf) +{ + struct blob_attr *tb[__NETWORK_ATTR_MAX]; + + if (!net->config.data) + return; + + blobmsg_parse_attr(network_policy, __NETWORK_ATTR_MAX, tb, + net->config.data); + tb[NETWORK_ATTR_KEY] = NULL; + for (size_t i = 0; i < ARRAY_SIZE(tb); i++) + if (tb[i]) + blobmsg_add_blob(buf, tb[i]); +} + static int network_set_config(struct network *net, struct blob_attr *config) { @@ -600,9 +615,8 @@ network_set_config(struct network *net, struct blob_attr *config) memset(&net->config, 0, sizeof(net->config)); net->config.data = blob_memdup(config); - blobmsg_parse(network_policy, __NETWORK_ATTR_MAX, tb, - blobmsg_data(net->config.data), - blobmsg_len(net->config.data)); + blobmsg_parse_attr(network_policy, __NETWORK_ATTR_MAX, tb, + net->config.data); if ((cur = tb[NETWORK_ATTR_TYPE]) == NULL || !strlen(blobmsg_get_string(cur)) || @@ -102,6 +102,7 @@ static inline const char *network_name(struct network *net) return net->node.key; } +void network_get_config(struct network *net, struct blob_buf *buf); bool network_skip_endpoint_route(struct network *net, union network_endpoint *ep); void network_fill_host_addr(union network_addr *addr, uint8_t *key); int network_save_dynamic(struct network *net); @@ -58,9 +58,9 @@ __network_dump(struct blob_buf *buf, struct network *net) void *c, *p; char *str; - blobmsg_add_field(buf, BLOBMSG_TYPE_TABLE, "config", - blobmsg_data(net->config.data), - blobmsg_len(net->config.data)); + c = blobmsg_open_table(buf, "config"); + network_get_config(net, buf); + blobmsg_close_table(buf, c); if (local) blobmsg_add_string(buf, "local_host", network_host_name(local)); |