Skip to content

Fix macOS's package inventory not parsing info correctly#3035

Merged
chemamartinez merged 4 commits into3.9from
fix_mac_package_inventory
Apr 10, 2019
Merged

Fix macOS's package inventory not parsing info correctly#3035
chemamartinez merged 4 commits into3.9from
fix_mac_package_inventory

Conversation

@yasma-cif
Copy link
Copy Markdown
Contributor

This PR is aimed at solving issue #2922.

Description

  • Previously, syscollector couldn't parse Info.plist files with a different internal format, and it produced data that was empty or filled with garbage while trying. Now it can read files using both vertical and horizontal labels, and when they use a different format that it doesn't know how to parse, it at least tries to read the package's name from its folder and then empties the rest of the fields.

Use case

VirtualBox's Info.plist file por example has a format such as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundlePackageType</key>              <string>APPL</string>
    <key>CFBundleSignature</key>                <string>VBOX</string>
    <key>CFBundleDevelopmentRegion</key>        <string>English</string>
    <key>CFBundleIdentifier</key>               <string>org.virtualbox.app.VirtualBox</string>
    <key>CFBundleName</key>                     <string>VirtualBox</string>
    <key>CFBundleExecutable</key>               <string>VirtualBox</string>
    <key>CFBundleVersion</key>                  <string>6.0.4</string>
.
.
.

syscollector wasn't ready to read labels horizontally, so it resulted in wrong data being collected, like this:

1880543464|2019/04/05 10:16:16|pkg|VirtualBox||||||CFBundleGetInfoString||||CFBundleName||0

Now syscollector can read the file, producing the desired outcome:

1901203817|2019/04/05 12:05:03|pkg|VirtualBox||||||6.0.4|||applications|org.virtualbox.app.VirtualBox|/Applications/VirtualBox.app|0

If the file coulnd't be read anyways (because of it having a not supported format or it being corrupted), it would collect its name from the /Applications/VirtualBox.app and leave the remaining fields empty, like this:

115170242|2019/04/05 11:01:57|pkg|VirtualBox||||||||||||0

Testing

The previous changes have been tested with the previously problematic package VirtualBox.

@yasma-cif yasma-cif requested a review from chemamartinez April 5, 2019 10:52
#if defined(__MACH__)

char* sys_parse_pkg(const char * app_folder, const char * timestamp, int random_id);
char* sys_parse_pkg(const char * app_folder, const char * folder_name, const char * timestamp, int random_id);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yo don't need to pass to sys_parse_pkg the folder name, it is included in the app_folder variable.

int void_file=1;
while(fgets(read_buff, OS_MAXSTR - 1, fp) != NULL) {


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this new line here?

}
}
}
if(void_file==0){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can specify the location and the source of the package even though the parse of the rest of the fields failed.

cJSON_AddItemToObject(object, "program", package);
cJSON_AddStringToObject(package, "format", "pkg");

int void_file=1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here we should check if the Info.plist file is valid to be parsed, not when looking for the name program inside the file.

}
cJSON_AddStringToObject(package, "location", app_folder);
}
else{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is better to not include version, group and description when the file cannot be parsed because we cannot control what contain these fields.

@chemamartinez chemamartinez merged commit 0125f9e into 3.9 Apr 10, 2019
@chemamartinez chemamartinez deleted the fix_mac_package_inventory branch April 10, 2019 16:55
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.

2 participants