Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo Windows registry-based deployment profile reading. #4148

Merged
merged 4 commits into from
Mar 10, 2023

Conversation

ericpromislow
Copy link
Contributor

Fixes #4144

To test this, you might want to create a new multi-string value in the registry.

According to stackoverflow, there are many ways to do this, running the gamut from powershell and VBS to high-grade ATL/C++. But I just added the values in the regedit textbox, one per line, and made sure that there was an empty line after all the values.

Reading the registry is a bit strange because sub-object names (keys)
live in a different namespace from sub-object named values.

But we can lump both sets of names together, and then decide, based on
the type of the value of a given name in the schema, whether it's
a value in the registry to harvest, or a sub-object key to do further
matching on.

Yeah, it's a bit hard to explain. But this is why there's only one recursive
call to `readRegistryUsingSchema`.

Signed-off-by: Eric Promislow <epromislow@suse.com>
@jandubois jandubois added this to the 1.8 milestone Mar 10, 2023
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericpromislow asked for a rush review (i.e. ignoring style and things and only checking functionality), so the blocking issues are:

  • parseMultiString won't do the correct things for non-string input
  • We need to convert the values for other types, otherwise we'll break at runtime.

/cc @jandubois (for the review quality).


if (multiSzValue) {
// Registry value can be a single-string or even a DWORD and parseMultiString will handle it.
const arrayValue = nativeReg.parseMultiString(multiSzValue as nativeReg.Value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This cast is unnecessary, multiSzValue is already a nativeReg.Value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was necessary in my IDE and when I ran the code

}
try {
regValue = readRegistryUsingSchema(schemaVal, innerKey);
if (regValue && (typeof regValue === 'object') && Object.keys(regValue).length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how regValue can be not 'object'. Inside the call, there is only one return from the end of the function, and newObject is always either null or Record<string, any>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to issue #4153

if (typeof schemaVal === 'boolean') {
if (typeof regValue === 'number') {
regValue = regValue !== 0;
} else {
console.debug(`Deployment Profile expected boolean value for ${ regPath.concat(schemaKey) }`);
console.debug(`Deployment Profile expected boolean value for key ${ k }`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leads to error messages like Deployment Profile expected boolean value for key enabled which is pretty useless for troubleshooting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because I'm not passing the current path into the recursive function, and I can't get it from the open key AFAICT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, hence we should pass the path in… otherwise the error messages are not useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to issue #4153

}
}
} else {
regValue = nativeReg.queryValue(regKey, k);
if (typeof schemaVal === 'boolean') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need more conversions for schemaVal, e.g. if the user provides hello for a number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we're doing zero type-checking when reading profiles on macos or linux

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to issue #4153

@mook-as mook-as removed their request for review March 10, 2023 19:59
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only reviewed the code; I didn't actually test it on Windows as I don't have a dev setup for it right now.

Approving as-is for the current release; the remaining feedback comments are to be addressed in a follow-up PR.

@jandubois jandubois merged commit 3b633d8 into main Mar 10, 2023
@jandubois jandubois deleted the 4144-load-windows-profile-from-reg branch March 10, 2023 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Windows registry arrays as a REG_MULTI_SZ string
3 participants