From 6d59d9651d8af52f640ac50a201802f26fa38045 Mon Sep 17 00:00:00 2001 From: df Date: Thu, 7 Oct 2021 07:59:36 +0000 Subject: [PATCH] Fix access modes --- webif/lib/system.class | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/webif/lib/system.class b/webif/lib/system.class index 1a08edc..482ad71 100644 --- a/webif/lib/system.class +++ b/webif/lib/system.class @@ -162,31 +162,34 @@ proc {system encryptionkey} {} {{key ""}} { return [system keybytestostring $bytes] } -proc {system customencryptionkey} {{key ""}} { - - proc open_keyfile {{access r}} { - return [open "/mod/boot/cryptokey" $access] - } - +proc {system customencryptionkey} {{key ""}} {{keyfile "/mod/boot/cryptokey"}} { set ck_fd {} try { - if {$key ne ""} { + if {$key eq ""} + set ck_fd [open $keyfile r] + set ck_bytes [$ck_fd read 16] + return [system keybytestostring $ck_bytes] + } elseif {[string equal -nocase $key [system encryptionkey]]} { + file delete -force $keyfile + return $key + } else { set ck_bytes [binary format H* $key] set test [system keybytestostring $ck_bytes] if {![string equal -nocase $test $key]} { throw 1 "Invalid custom key" } - # attempt not to truncate on update until written - set ck_fd [open_keyfile a] + if {[file exists $keyfile]} { + # attempt not to truncate on update until written + set mode r+ + } else { + set mode w + } + set ck_fd [open $keyfile $mode] $ck_fd seek 0 $ck_fd puts -nonewline $ck_bytes $ck_fd close set ck_fd {} return $key - } else { - set ck_fd [open_keyfile] - set ck_bytes [$ck_fd read 16] - return [system keybytestostring $ck_bytes] } } on error {msg opts} { return {}