From 1f892c8475687874b9be03142c96b6013c76fa14 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 6 Jun 2025 10:58:39 +0200 Subject: [PATCH] unetd: cli: add helper function for getting path to temp files Signed-off-by: Felix Fietkau --- package/network/services/unetd/files/unet.uc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/package/network/services/unetd/files/unet.uc b/package/network/services/unetd/files/unet.uc index eb2c450cb6..e3eb94f227 100644 --- a/package/network/services/unetd/files/unet.uc +++ b/package/network/services/unetd/files/unet.uc @@ -51,6 +51,11 @@ function network_get_file_string(f) return str; } +function file_path(file) +{ + return "/dev/fd/" + file.fileno(); +} + function network_keygen(pw_file, args, config, out_file, extra_args) { let rounds = config.rounds; @@ -59,7 +64,7 @@ function network_keygen(pw_file, args, config, out_file, extra_args) if (!out_file) { output = mkstemp(); - out_file = "/dev/fd/" + output.fileno(); + out_file = file_path(output); } if (extra_args) @@ -70,7 +75,7 @@ function network_keygen(pw_file, args, config, out_file, extra_args) if (config.xorkey) { xorkey = network_get_string_file(config.xorkey); - args += " -x /dev/fd/" + xorkey.fileno(); + args += " -x " + file_path(xorkey); } pw_file.seek(); @@ -168,14 +173,14 @@ function network_sign_data(ctx, name, network, pw_file, upload) writefile(json_file, sprintf("%.J\n", network)); let key_file = mkstemp(); - let ret = network_keygen(pw_file, '-G', network.config, "/dev/fd/" + key_file.fileno()); + let ret = network_keygen(pw_file, '-G', network.config, file_path(key_file)); if (!ret) { if (ctx.command_failed) ctx.command_failed("Failed to generate network key"); return false; } - ret = system([ "unet-tool", "-S", "-K", "/dev/fd/" + key_file.fileno(), "-o", bin_file, json_file ]); + ret = system([ "unet-tool", "-S", "-K", file_path(key_file), "-o", bin_file, json_file ]); unlink(json_file); if (ret != 0) { if (ctx.command_failed) @@ -785,7 +790,7 @@ function network_set_password(ctx, argv, named) let key_file = network_get_string_file(key); delete config.xorkey; - config.xorkey = network_keygen(pw_file, '-G -x /dev/fd/' + key_file.fileno(), config); + config.xorkey = network_keygen(pw_file, '-G -x ' + file_path(key_file), config); key_file.close(); if (!config.xorkey) { -- 2.30.2