Class CadLoadSecurity
- Namespace
- OpenCAD2D
- Assembly
- OpenCAD2D.Core.dll
The gate in front of every file of code the presenter loads, as AutoCAD 2021's: SECURELOAD says what happens to a file
outside the trusted folders, TRUSTEDPATHS lists those folders and LEGACYCODESEARCH says whether a search for a code file
looks in the current and the drawing folder. AutoLISP's load and everything built on it asks
MayLoad(string) before it reads a file, and the app's Python does the same for PYRUN and PYLOAD.
public sealed class CadLoadSecurity
- Inheritance
-
CadLoadSecurity
- Inherited Members
Remarks
SECURELOAD 0 loads from anywhere. 1, the start value, loads from a trusted folder and asks (Ask) about a
file anywhere else: Always Load, Load Once or Do Not Load. 2 loads from a trusted folder only. The trusted folders are
the folder of the program with every folder under it, and the entries of TrustedPaths: a folder, or a
folder and every folder under it where the entry ends in \.... D:\tools trusts the files in
D:\tools and not those in D:\tools\old; D:\tools\... trusts both.
Folders are compared as Windows paths, in full and without regard to case. The instance can be used from any thread: the question itself is asked outside any lock, so it may show a window and wait.
Properties
- AlwaysLoaded
Gets or sets the files answered Always Load, each as the SHA-256 of its bytes in lower-case hexadecimal, a bar and its full path:
9f86d0...0a08|C:\work\tools\label.lsp. Such a file loads under SECURELOAD 1 with no question for as long as its bytes are the same, so a file edited since is asked about again. An entry that is not of this form is left out, and a second entry for one path replaces the first. Null is taken as empty.
- Ask
Gets or sets what asks about a file under SECURELOAD 1: it gets the full path and answers with one of CadLoadAnswer. The window shows AutoCAD's warning here. Null, as it is at the start, makes a library, a test or a console refuse the file, as AutoCAD's console does. An exception from it is a refusal and a line in the log.
- LegacyCodeSearch
Gets or sets whether a search for a file of code (
findfile,load_dialog,load) looks in the current folder and the folder of the drawing before the support folders, as AutoCAD's LEGACYCODESEARCH 1. Off at the start: a.lspfile lying beside the drawing is not found by its bare name.
- ProgramFolder
Gets the folder of the program, the one the presenter's own linetypes, hatches and Python package lie in, with no closing backslash. It is trusted with every folder under it, whatever TrustedPaths says.
- SecureLoad
Gets or sets what happens to a file of code outside the trusted folders: 0 loads it, 1 asks (Ask), 2 refuses it. Starts at 1, as AutoCAD does.
- TrustedPaths
Gets or sets the folders trusted besides the program's, as AutoCAD's TRUSTEDPATHS: entries parted by
;, an entry that ends in...trusting that folder and every folder under it and any other the folder alone, soD:\tools;D:\lisp...trustsD:\tools,D:\lispand everything belowD:\lisp. Spaces around an entry are dropped and an empty entry is skipped; a%NAME%is replaced by the environment variable when the value is set; an entry in quotes, with a wildcard or not starting at a drive or a share trusts nothing. Empty at the start; null is taken as empty, and any text is kept.
Methods
- ForgetAlwaysLoaded()
Forgets every file answered Always Load, which AutoCAD gives no way to do: each is asked about again under SECURELOAD
- A file answered Load Once in this run stays answered.
- IsCodeFile(string)
Says whether a file is one of the kinds AutoCAD keeps out of the current and the drawing folder while LEGACYCODESEARCH is 0:
.lsp .fas .vlx .mnl .scr .dcl .dll .arx .dvb .cuix, and.pyfor Python. Only the extension is read, without regard to case, solabel.LSPis one andnotes.txtandacad.linare not.
- IsTrusted(string)
Says whether a file lies in a trusted folder: the folder of the program and every folder under it, or a folder of TrustedPaths. Nothing is asked and the file need not exist.
- MayLoad(string)
Decides whether a file of code may be loaded, in this order: SECURELOAD 0 loads it; a file in a trusted folder loads; SECURELOAD 2 refuses any other, an Always Load answer given before notwithstanding; under SECURELOAD 1 a file answered Load Once in this run, or Always Load with the same bytes, loads, and any other is asked about (Ask), and refused where nothing asks. Each refusal is one line of the log at the Debug level.
Events
- Changed
Occurs when SECURELOAD, TRUSTEDPATHS, LEGACYCODESEARCH or AlwaysLoaded changes, which includes a file answered Always Load. Raised on the thread that made the change, after it; setting a value to what it is raises nothing.