├── .clang-format ├── .clang-tidy ├── .cmake-format.json ├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ └── bug-report.md └── workflows │ └── docker-build.yml ├── .gitignore ├── .vscode └── extensions.json ├── CHANGELOG.md ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CPPLINT.cfg ├── DartConfiguration.tcl ├── LICENSE ├── README.md ├── SECURITY.md ├── SUPPORT.md ├── azurepipelines ├── build │ ├── README.md │ ├── docker │ │ ├── adu-debian-amd64-build.yml │ │ ├── adu-debian-arm32-build.yml │ │ └── adu-debian-arm64-build.yml │ ├── native │ │ ├── adu-ubuntu-amd64-build.yml │ │ ├── adu-ubuntu-arm64-build.yml │ │ └── adu-windows-msvc2022-amd64-build.yml │ └── templates │ │ ├── adu-docker-build-steps.yml │ │ └── adu-native-build-steps.yml └── e2e_test │ ├── README.md │ ├── e2etest.yaml │ ├── packer │ └── deltagen │ │ ├── README.md │ │ ├── deviceupdate-deltagen.pkr.hcl │ │ └── scripts │ │ ├── configure-apt-repo.sh │ │ ├── generate-delta.sh │ │ ├── install-diffgen-tool.sh │ │ ├── install-prereqs.sh │ │ └── run.sh │ ├── scenarios │ ├── test_runner │ │ ├── Bundle-update.py │ │ ├── Multi-Component-Update.py │ │ ├── add_device_to_adu_group.py │ │ ├── apt_deployment.py │ │ ├── bad_apt_deployment.py │ │ ├── delete_device.py │ │ ├── diagnostics.py │ │ ├── scenario_definitions.py │ │ └── vm_setup │ │ │ ├── create_x509_certificates.sh │ │ │ ├── sas_devicesetup.py │ │ │ ├── sas_vm_setup.sh │ │ │ ├── x509_devicesetup.py │ │ │ └── x509_vm_setup.sh │ └── testingtoolkit │ │ ├── README.md │ │ ├── __init__.py │ │ ├── _adu_test_toolkit.py │ │ ├── _version.py │ │ └── requirements.txt │ ├── scripts │ └── start_and_check_deployment.sh │ ├── templates │ ├── az_vm.template.json │ ├── e2e_test_run.yaml │ ├── e2e_test_vm_cleanup.yaml │ └── e2e_vm_setup.yaml │ └── terraform │ ├── host │ ├── DeviceUpdateHost.tf │ └── variables.tf │ └── resource_group │ ├── ResourceGroup.tf │ ├── output.tf │ └── variables.tf ├── cmake ├── FindIotHubClient.cmake ├── FindParson.cmake ├── aduc_helpers.cmake ├── agentRules.cmake ├── automate-vcpkg.cmake ├── find_curl.cmake └── find_curl_and_import_libcurl.cmake ├── daemon ├── CMakeLists.txt ├── deviceupdate-agent.service └── install.sh ├── docs ├── agent-reference │ ├── device-update-agent-extended-result-codes.md │ ├── device-update-agent-extensibility-points.md │ ├── extension-contract-versions.md │ ├── goal-state-support.md │ ├── how-to-build-agent-code.md │ ├── how-to-build-swupdate-for-swupdate-handler-unit-tests.md │ ├── how-to-implement-custom-update-handler.md │ ├── how-to-install-deb-pkg-on-rpi.md │ ├── how-to-modify-the-agent-code.md │ ├── how-to-run-agent.md │ ├── how-to-simulate-update-result.md │ ├── images │ │ ├── agent-architecture.png │ │ ├── apply-phase.png │ │ ├── download-phase.png │ │ ├── goalstate-state-diagram.png │ │ └── install-phase.png │ ├── multi-component-updating.md │ ├── registering-device-update-extensions.md │ └── update-manifest-v4-schema.md ├── how-to-troubleshoot-guide.md └── sample-artifacts │ ├── libcurl4-doc-7.58-apt-manifest.json │ ├── libcurl4-doc-apt-manifest.json │ ├── libcurl4-doc-remove-apt-manifest.json │ ├── sample-package-update-1.0.1-importManifest.json │ ├── sample-package-update-1.0.2-importManifest.json │ └── sample-package-update-2-2.0.1-importManifest.json ├── licenses └── cgmanifest.json ├── packages ├── CMakeLists.txt └── debian │ ├── copyright │ ├── postinst │ ├── postrm │ ├── preinst │ └── prerm ├── scripts ├── adu-diag.sh ├── build.ps1 ├── build.sh ├── clang-format.ps1 ├── clang-format.sh ├── cmake-format.ps1 ├── cmake-format.sh ├── config-integration.sh ├── debug_agent.ps1 ├── debug_agent.sh ├── docker │ ├── README.md │ ├── build_docker_image.sh │ ├── dbg_docker.sh │ ├── setup_docker_container.sh │ └── templates │ │ ├── Dockerfile.template │ │ ├── content_downloader.extension.template.json │ │ ├── content_handler.template.json │ │ ├── du-config.template.json │ │ ├── du-diagnostics-config.template.json │ │ └── setup_container.sh ├── error_code_generator_defs │ ├── error_code_defs_generator.py │ └── result_codes.json ├── githooks │ └── pre-commit.sh ├── install-deps.ps1 ├── install-deps.sh ├── install-du.ps1 ├── run_uts.ps1 └── sh-format.sh ├── src ├── CMakeLists.txt ├── adu-shell │ ├── CMakeLists.txt │ ├── inc │ │ ├── adushell.hpp │ │ ├── adushell_action.hpp │ │ ├── adushell_const.hpp │ │ ├── aptget_tasks.h │ │ ├── common_tasks.hpp │ │ └── script_tasks.hpp │ ├── scripts │ │ ├── CMakeLists.txt │ │ └── adu-swupdate.sh │ └── src │ │ ├── adushell_action.cpp │ │ ├── aptget_tasks.cpp │ │ ├── common_tasks.cpp │ │ ├── main.cpp │ │ └── script_tasks.cpp ├── adu_types │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ ├── adu_types.h │ │ │ └── types │ │ │ ├── adu_core.h │ │ │ ├── download.h │ │ │ ├── hash.h │ │ │ ├── update_content.h │ │ │ └── workflow.h │ └── src │ │ └── adu_types.c ├── adu_workflow │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── agent_workflow.h │ └── src │ │ └── agent_workflow.c ├── agent │ ├── CMakeLists.txt │ ├── adu_core_export_helpers │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── aduc │ │ │ │ └── adu_core_export_helpers.h │ │ └── src │ │ │ └── adu_core_export_helpers.c │ ├── adu_core_interface │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── aduc │ │ │ │ ├── adu_core_interface.h │ │ │ │ └── health_management.h │ │ ├── src │ │ │ ├── adu_core_interface.c │ │ │ ├── device_properties.c │ │ │ ├── device_properties.h │ │ │ ├── startup_msg_helper.c │ │ │ └── startup_msg_helper.h │ │ └── tests │ │ │ └── testdata │ │ │ ├── adu_core_export_helpers │ │ │ └── updateManifest.json │ │ │ ├── startupworkflowdata │ │ │ └── updateManifest.json │ │ │ └── workflow_reboot │ │ │ ├── expectedClientReportingStringAfterReboot.json │ │ │ ├── expectedPersistedReportingJson.json │ │ │ ├── expectedPersistedWorkflowData.json │ │ │ └── updateActionForActionBundle.json │ ├── command_helper │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── aduc │ │ │ │ └── command_helper.h │ │ └── src │ │ │ └── command_helper.c │ ├── device_info_interface │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── aduc │ │ │ │ └── device_info_interface.h │ │ └── src │ │ │ └── device_info_interface.c │ ├── pnp_helper │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── pnp_protocol.h │ │ ├── readme.md │ │ └── src │ │ │ └── pnp_protocol.c │ ├── shutdown_service │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── aduc │ │ │ │ └── shutdown_service.h │ │ └── src │ │ │ └── shutdown_service.c │ └── src │ │ ├── health_management.c │ │ └── main.c ├── agent_orchestration │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── agent_orchestration.h │ └── src │ │ └── agent_orchestration.c ├── communication_abstraction │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ ├── client_handle.h │ │ │ └── client_handle_helper.h │ └── src │ │ └── client_handle_helper.c ├── communication_managers │ ├── CMakeLists.txt │ └── iothub_communication_manager │ │ ├── CMakeLists.txt │ │ ├── inc │ │ └── aduc │ │ │ └── iothub_communication_manager.h │ │ └── src │ │ └── iothub_communication_manager.c ├── deps │ └── swupdate │ │ └── .config ├── diagnostics_component │ ├── CMakeLists.txt │ ├── diagnostics_async_helper │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── diagnostics_async_helper.h │ │ └── src │ │ │ └── diagnostics_async_helper.cpp │ ├── diagnostics_devicename │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── diagnostics_devicename.h │ │ └── src │ │ │ └── diagnostics_devicename.c │ ├── diagnostics_interface │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── diagnostics_interface.h │ │ └── src │ │ │ └── diagnostics_interface.c │ ├── diagnostics_workflow │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ ├── diagnostics_result.h │ │ │ └── diagnostics_workflow.h │ │ └── src │ │ │ ├── diagnostics_result.c │ │ │ └── diagnostics_workflow.c │ └── utils │ │ ├── CMakeLists.txt │ │ ├── config_utils │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── diagnostics_config_utils.h │ │ ├── src │ │ │ └── diagnostics_config_utils.c │ │ └── tests │ │ │ ├── CMakeLists.txt │ │ │ └── diagnostics_config_utils_ut.cpp │ │ ├── file_info_utils │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── file_info_utils.h │ │ ├── src │ │ │ └── file_info_utils.c │ │ └── tests │ │ │ ├── CMakeLists.txt │ │ │ └── file_info_utils_ut.cpp │ │ ├── file_upload_utils │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── file_upload_utility.h │ │ └── src │ │ │ ├── blob_storage_helper.cpp │ │ │ ├── blob_storage_helper.hpp │ │ │ └── file_upload_utility.cpp │ │ └── operation_id_utils │ │ ├── CMakeLists.txt │ │ ├── inc │ │ └── operation_id_utils.h │ │ └── src │ │ └── operation_id_utils.c ├── docs │ └── CMakeLists.txt ├── extensions │ ├── CMakeLists.txt │ ├── component_enumerators │ │ └── examples │ │ │ └── contoso_component_enumerator │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── assets │ │ │ ├── contoso-virtual-vacuum-components-diagram.svg │ │ │ └── contoso-virtual-vacuum-update-flow.svg │ │ │ ├── contoso_component_enumerator.cpp │ │ │ └── demo │ │ │ ├── README.md │ │ │ ├── demo-devices │ │ │ └── contoso-devices │ │ │ │ ├── components-inventory-with-steamers.json │ │ │ │ ├── components-inventory.json │ │ │ │ └── vacuum-1 │ │ │ │ ├── bootfs │ │ │ │ └── diskimage.json │ │ │ │ ├── cameras │ │ │ │ ├── contoso-camera-serial-00000 │ │ │ │ │ └── firmware.json │ │ │ │ └── contoso-camera-serial-00001 │ │ │ │ │ └── firmware.json │ │ │ │ ├── hostfw │ │ │ │ └── firmware.json │ │ │ │ ├── motors │ │ │ │ ├── contoso-motor-serial-00000 │ │ │ │ │ └── firmware.json │ │ │ │ ├── contoso-motor-serial-00001 │ │ │ │ │ └── firmware.json │ │ │ │ └── contoso-motor-serial-00002 │ │ │ │ │ └── firmware.json │ │ │ │ ├── rootfs │ │ │ │ └── diskimage.json │ │ │ │ └── unplugged-streamers │ │ │ │ └── contoso-steamer-serial-00000 │ │ │ │ └── firmware.json │ │ │ ├── sample-updates │ │ │ ├── AduUpdate.psm1 │ │ │ ├── CreateSampleMSOEUpdate-1.x.ps1 │ │ │ ├── CreateSampleMSOEUpdate-2.x.ps1 │ │ │ ├── CreateSampleMSOEUpdate-3.x.ps1 │ │ │ ├── CreateSampleMSOEUpdate-4.x.ps1 │ │ │ ├── CreateSampleMSOEUpdate-5.x.ps1 │ │ │ ├── CreateSampleMSOEUpdate-6.x.ps1 │ │ │ ├── CreateSampleMSOEUpdate-7.x.ps1 │ │ │ ├── data-files │ │ │ │ ├── APT │ │ │ │ │ ├── apt-manifest-1.0.json │ │ │ │ │ ├── apt-manifest-4.0.json │ │ │ │ │ ├── apt-manifest-tree-1.0.json │ │ │ │ │ └── bad-apt-manifest-1.0.json │ │ │ │ ├── camera-firmware-1.1.json │ │ │ │ ├── camera-firmware-2.1.json │ │ │ │ ├── camera-firmware-2.2.json │ │ │ │ ├── camera-firmware-3.0.json │ │ │ │ ├── contoso-vacuum-apt-1.0.json │ │ │ │ ├── host-firmware-1.1.json │ │ │ │ ├── host-firmware-1.2.json │ │ │ │ ├── host-firmware-1.3.json │ │ │ │ ├── motor-firmware-1.1.json │ │ │ │ ├── motor-firmware-1.2.json │ │ │ │ ├── motor-firmware-1.3.json │ │ │ │ ├── motor-firmware-1.4.json │ │ │ │ ├── motor-firmware-1.5.json │ │ │ │ ├── motor-firmware-3.1.json │ │ │ │ ├── steamer-firmware-1.0.json │ │ │ │ └── steamer-firmware-2.0.json │ │ │ └── scripts │ │ │ │ ├── contoso-camera-installscript.sh │ │ │ │ ├── contoso-diskimage-installscript.sh │ │ │ │ ├── contoso-firmware-installscript.sh │ │ │ │ ├── contoso-motor-installscript.sh │ │ │ │ ├── contoso-steamer-installscript.sh │ │ │ │ └── contoso-update-simulatorscript.sh │ │ │ ├── tools │ │ │ ├── add-packages-microsoft-com.sh │ │ │ └── reset-demo-components.sh │ │ │ ├── tutorial1.md │ │ │ └── tutorial1.ps1 │ ├── content_downloaders │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── curl_downloader │ │ │ ├── CMakeLists.txt │ │ │ ├── curl_content_downloader.EXPORTS.cpp │ │ │ ├── curl_content_downloader.cpp │ │ │ └── curl_content_downloader.h │ │ └── deliveryoptimization_downloader │ │ │ ├── CMakeLists.txt │ │ │ ├── deliveryoptimization_content_downloader.EXPORTS.cpp │ │ │ ├── deliveryoptimization_content_downloader.cpp │ │ │ └── deliveryoptimization_content_downloader.h │ ├── download_handlers │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── download_handler_factory │ │ │ ├── CMakeLists.txt │ │ │ ├── inc │ │ │ │ └── aduc │ │ │ │ │ ├── download_handler_factory.h │ │ │ │ │ └── download_handler_factory.hpp │ │ │ └── src │ │ │ │ └── download_handler_factory.cpp │ │ ├── download_handler_plugin │ │ │ ├── CMakeLists.txt │ │ │ ├── inc │ │ │ │ └── aduc │ │ │ │ │ ├── download_handler_plugin.h │ │ │ │ │ └── download_handler_plugin.hpp │ │ │ └── src │ │ │ │ └── download_handler_plugin.cpp │ │ └── plugin_examples │ │ │ ├── CMakeLists.txt │ │ │ └── microsoft_delta_download_handler │ │ │ ├── CMakeLists.txt │ │ │ ├── handler │ │ │ ├── CMakeLists.txt │ │ │ ├── lib │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── inc │ │ │ │ │ └── aduc │ │ │ │ │ │ └── microsoft_delta_download_handler.h │ │ │ │ └── src │ │ │ │ │ └── microsoft_delta_download_handler.c │ │ │ ├── plugin │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── src │ │ │ │ │ └── microsoft_delta_download_handler_plugin.EXPORTS.c │ │ │ └── utils │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── inc │ │ │ │ └── aduc │ │ │ │ │ └── microsoft_delta_download_handler_utils.h │ │ │ │ ├── src │ │ │ │ ├── microsoft_delta_download_handler_utils.c │ │ │ │ └── microsoft_delta_download_handler_utils.cpp │ │ │ │ └── tests │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── microsoft_delta_download_handler_utils_ut.cpp │ │ │ └── source_update_cache │ │ │ ├── CMakeLists.txt │ │ │ ├── inc │ │ │ └── aduc │ │ │ │ ├── source_update_cache.h │ │ │ │ └── source_update_cache_utils.h │ │ │ ├── src │ │ │ ├── source_update_cache.c │ │ │ ├── source_update_cache_utils.c │ │ │ └── source_update_cache_utils.cpp │ │ │ └── tests │ │ │ ├── CMakeLists.txt │ │ │ └── source_update_cache_utils_ut.cpp │ ├── extension_manager │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── aduc │ │ │ │ ├── extension_manager.h │ │ │ │ ├── extension_manager.hpp │ │ │ │ ├── extension_manager_download_options.h │ │ │ │ └── extension_manager_helper.hpp │ │ ├── src │ │ │ ├── extension_manager.cpp │ │ │ └── extension_manager_helper.cpp │ │ └── tests │ │ │ ├── CMakeLists.txt │ │ │ ├── inc │ │ │ └── extension_manager_download_test_case.hpp │ │ │ ├── src │ │ │ ├── extension_manager_download_test_case.cpp │ │ │ └── extension_manager_ut.cpp │ │ │ └── testdata │ │ │ └── extension_manager │ │ │ ├── pnpMsg.json │ │ │ └── testUpdateManifest.json │ ├── inc │ │ └── aduc │ │ │ ├── component_enumerator_extension.hpp │ │ │ ├── content_downloader_extension.hpp │ │ │ ├── content_handler.hpp │ │ │ └── exports │ │ │ ├── extension_common_export_symbols.h │ │ │ ├── extension_component_enumerator_export_symbols.h │ │ │ ├── extension_content_downloader_export_symbols.h │ │ │ ├── extension_content_handler_export_symbols.h │ │ │ ├── extension_download_handler_export_symbols.h │ │ │ └── extension_export_symbols.h │ ├── shared_lib │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ └── aduc │ │ │ │ ├── plugin_call_helper.hpp │ │ │ │ ├── plugin_exception.hpp │ │ │ │ └── shared_lib.hpp │ │ └── src │ │ │ └── shared_lib.cpp │ ├── step_handlers │ │ ├── CMakeLists.txt │ │ ├── apt_handler │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── inc │ │ │ │ └── aduc │ │ │ │ │ ├── apt_handler.hpp │ │ │ │ │ └── apt_parser.hpp │ │ │ ├── src │ │ │ │ ├── apt_handler.cpp │ │ │ │ └── apt_parser.cpp │ │ │ └── tests │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── apt_parser_ut.cpp │ │ │ │ └── sample_apt_manifest.json │ │ ├── script_handler │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── examples │ │ │ │ ├── example-installscript.ps1 │ │ │ │ └── example-installscript.sh │ │ │ ├── images │ │ │ │ └── script-handler-overview.svg │ │ │ ├── inc │ │ │ │ └── aduc │ │ │ │ │ └── script_handler.hpp │ │ │ ├── src │ │ │ │ └── script_handler.cpp │ │ │ └── tests │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── script_handler_ut.cpp │ │ │ │ └── testdata │ │ │ │ └── script_handler_test_config │ │ │ │ └── du-config.json │ │ ├── simulator_handler │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── du-simulator-data-template.jsonc │ │ │ ├── inc │ │ │ │ └── aduc │ │ │ │ │ └── simulator_handler.hpp │ │ │ ├── src │ │ │ │ └── simulator_handler.cpp │ │ │ └── tests │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── simulator_handler_unit_tests.cpp │ │ ├── swupdate_handler_v2 │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── images │ │ │ │ ├── highlevel-overview-swupdate-handler-workflow.svg │ │ │ │ └── swupdate-script-options-and-arguments.svg │ │ │ ├── inc │ │ │ │ └── aduc │ │ │ │ │ └── swupdate_handler_v2.hpp │ │ │ ├── src │ │ │ │ ├── handler_create.cpp │ │ │ │ └── swupdate_handler_v2.cpp │ │ │ └── tests │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── swupdate_handler_v2_ut.cpp │ │ │ │ └── testdata │ │ │ │ ├── adu-yocto-ab-rootfs-update │ │ │ │ ├── README.md │ │ │ │ ├── create-yocto-ab-rootfs-update-import-manifest-1.0.ps1 │ │ │ │ ├── payloads │ │ │ │ │ ├── adu-version │ │ │ │ │ ├── example-a-b-update.sh │ │ │ │ │ └── my-update.swu │ │ │ │ └── sample_swupdate_config.json │ │ │ │ ├── swupdate_filecopy │ │ │ │ ├── README.md │ │ │ │ ├── du-agent-swupdate-filecopy-test-1_1.0.swu │ │ │ │ ├── example-du-swupdate-script-2.1.sh │ │ │ │ ├── example-du-swupdate-script.sh │ │ │ │ ├── installed-criteria.txt │ │ │ │ ├── mock-update-for-file-copy-test-1.txt │ │ │ │ ├── preinst.sh │ │ │ │ └── sw-description │ │ │ │ └── swupdate_handler_v2_test_config │ │ │ │ └── du-config.json │ │ └── wim_handler │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── Wimgapi │ │ │ ├── Include │ │ │ │ └── wimgapi.h │ │ │ └── Lib │ │ │ │ ├── amd64 │ │ │ │ └── wimgapi.lib │ │ │ │ ├── arm │ │ │ │ └── wimgapi.lib │ │ │ │ ├── arm64 │ │ │ │ └── wimgapi.lib │ │ │ │ └── x86 │ │ │ │ └── wimgapi.lib │ │ │ ├── inc │ │ │ ├── aducresult.hpp │ │ │ ├── bcdedit.hpp │ │ │ ├── com_helpers.hpp │ │ │ ├── file_version.hpp │ │ │ ├── format_drive.hpp │ │ │ ├── wim_handler_1.hpp │ │ │ ├── wim_step_handler.hpp │ │ │ ├── wimg.hpp │ │ │ └── workflow_ptr.hpp │ │ │ └── src │ │ │ ├── bcdedit.cpp │ │ │ ├── file_version.cpp │ │ │ ├── format_drive.cpp │ │ │ ├── handler_create.cpp │ │ │ ├── wim_handler_1.cpp │ │ │ ├── wim_step_handler.cpp │ │ │ └── wimg.cpp │ └── update_manifest_handlers │ │ ├── CMakeLists.txt │ │ └── steps_handler │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── assets │ │ ├── steps-handler-basic-sequence-overview.mmd │ │ ├── steps-handler-basic-sequence-overview.svg │ │ ├── steps-handler-child-update-sequence-overview.mmd │ │ └── steps-handler-child-update-sequence-overview.svg │ │ ├── inc │ │ └── aduc │ │ │ └── steps_handler.hpp │ │ └── src │ │ ├── handler_create.cpp │ │ └── steps_handler.cpp ├── inc │ └── aduc │ │ ├── adu_core_exports.h │ │ ├── aduc_banned.h │ │ ├── aduc_inode.h │ │ ├── device_info_exports.h │ │ └── result.h ├── libaducpal │ ├── CMakeLists.txt │ ├── inc │ │ └── aducpal │ │ │ ├── dirent.h │ │ │ ├── dlfcn.h │ │ │ ├── ftw.h │ │ │ ├── grp.h │ │ │ ├── limits.h │ │ │ ├── pwd.h │ │ │ ├── stdio.h │ │ │ ├── stdlib.h │ │ │ ├── strings.h │ │ │ ├── sys_stat.h │ │ │ ├── sys_time.h │ │ │ ├── sys_types.h │ │ │ ├── time.h │ │ │ └── unistd.h │ └── src │ │ ├── dirent.c │ │ ├── dlfcn.c │ │ ├── ftw.c │ │ ├── grp.c │ │ ├── pwd.c │ │ ├── stdio.c │ │ ├── stdlib.c │ │ ├── strings.c │ │ ├── sys_stat.c │ │ ├── sys_time.c │ │ ├── time.c │ │ └── unistd.c ├── logging │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── logging.h │ └── zlog │ │ ├── CMakeLists.txt │ │ ├── inc │ │ ├── zlog-config.h │ │ └── zlog.h │ │ └── src │ │ ├── init.c │ │ └── zlog.c ├── platform_layers │ ├── CMakeLists.txt │ ├── linux_platform_layer │ │ ├── CMakeLists.txt │ │ ├── src │ │ │ ├── linux_adu_core_exports.cpp │ │ │ ├── linux_adu_core_impl.cpp │ │ │ ├── linux_adu_core_impl.hpp │ │ │ └── linux_device_info_exports.cpp │ │ └── tests │ │ │ ├── CMakeLists.txt │ │ │ ├── download_ut.cpp │ │ │ ├── mock_do_download.cpp │ │ │ ├── mock_do_download.hpp │ │ │ ├── mock_do_download_status.hpp │ │ │ └── mock_do_exceptions.hpp │ └── windows_platform_layer │ │ ├── CMakeLists.txt │ │ └── src │ │ ├── adu_core_exports.cpp │ │ ├── adu_core_impl.cpp │ │ ├── adu_core_impl.hpp │ │ └── device_info_exports.cpp ├── rootkey_workflow │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── rootkey_workflow.h │ ├── src │ │ └── rootkey_workflow.c │ └── tests │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ └── rootkey_workflow_ut.cpp └── utils │ ├── CMakeLists.txt │ ├── auto_utils │ ├── CMakeLists.txt │ └── inc │ │ └── aduc │ │ └── defer.hpp │ ├── c_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ ├── bit_ops.h │ │ │ ├── c_utils.h │ │ │ ├── connection_string_utils.h │ │ │ └── string_c_utils.h │ ├── src │ │ ├── bit_ops.c │ │ ├── connection_string_utils.c │ │ └── string_c_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ ├── c_utils_ut.cpp │ │ └── connection_string_utils_ut.cpp │ ├── config_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── config_utils.h │ ├── src │ │ ├── config_parsefile.c │ │ └── config_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ ├── config_utils_ut.cpp │ │ └── main.cpp │ ├── contract_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── contract_utils.h │ ├── src │ │ └── contract_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── contract_utils_ut.cpp │ ├── crypto_utils │ ├── CMakeLists.txt │ ├── inc │ │ ├── base64_utils.h │ │ ├── crypto_key.h │ │ └── crypto_lib.h │ ├── src │ │ ├── base64_utils.c │ │ └── crypto_lib.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── crypto_utils_ut.cpp │ ├── d2c_messaging │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── d2c_messaging.h │ ├── src │ │ └── d2c_messaging.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── d2c_messaging_ut.cpp │ ├── eis_utils │ ├── CMakeLists.txt │ ├── inc │ │ ├── eis_coms.h │ │ ├── eis_err.h │ │ └── eis_utils.h │ ├── src │ │ ├── eis_coms.c │ │ ├── eis_err.c │ │ └── eis_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ ├── eis_utils_ut.cpp │ │ └── main.cpp │ ├── entity_utils │ ├── CMakeLists.txt │ └── inc │ │ └── aduc │ │ └── auto_file_entity.hpp │ ├── exception_utils │ ├── CMakeLists.txt │ └── inc │ │ └── aduc │ │ ├── exception_utils.hpp │ │ └── exceptions.hpp │ ├── extension_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── extension_utils.h │ └── src │ │ └── extension_utils.c │ ├── file_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ ├── auto_opendir.hpp │ │ │ └── file_utils.hpp │ └── src │ │ ├── auto_opendir.cpp │ │ └── file_utils.cpp │ ├── hash_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── hash_utils.h │ ├── src │ │ └── hash_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── hash_utils_ut.cpp │ ├── installed_criteria_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── installed_criteria_utils.hpp │ ├── src │ │ └── installed_criteria_utils.cpp │ └── tests │ │ ├── CMakeLists.txt │ │ └── installed_criteria_utils_ut.cpp │ ├── jws_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── jws_utils.h │ ├── src │ │ └── jws_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ ├── jws_utils_ut.cpp │ │ └── testdata │ │ └── jws_utils │ │ └── testrootkeypkg.json │ ├── parser_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── parser_utils.h │ ├── src │ │ └── parser_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── parser_utils_ut.cpp │ ├── parson_json_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── parson_json_utils.h │ └── src │ │ └── parson_json_utils.c │ ├── path_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── path_utils.h │ ├── src │ │ └── path_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── path_utils_ut.cpp │ ├── permission_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── permission_utils.h │ ├── src │ │ └── permission_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── permission_utils_ut.cpp │ ├── process_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── process_utils.hpp │ ├── src │ │ └── process_utils.cpp │ ├── test_helper │ │ ├── CMakeLists.txt │ │ └── main.cpp │ └── tests │ │ ├── CMakeLists.txt │ │ └── process_utils_ut.cpp │ ├── reporting_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── reporting_utils.h │ ├── src │ │ └── reporting_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── reporting_utils_ut.cpp │ ├── retry_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── retry_utils.h │ └── src │ │ └── retry_utils.c │ ├── root_key_utils │ ├── CMakeLists.txt │ ├── inc │ │ ├── root_key_list.h │ │ ├── root_key_store.h │ │ └── root_key_util.h │ ├── src │ │ ├── root_key_list.c │ │ ├── root_key_store.c │ │ └── root_key_util.c │ └── tests │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── root_key_utils_signing_key_ut.cpp │ │ ├── root_key_utils_ut.cpp │ │ └── testdata │ │ └── root_key_utils │ │ ├── disabledRootKeyProd.json │ │ ├── disabledSigningKeyProd.json │ │ ├── invalidrootkeypackage.json │ │ └── validrootkeypackage.json │ ├── rootkeypackage_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ ├── rootkeypackage.schema.json │ │ │ ├── rootkeypackage_curl_download.h │ │ │ ├── rootkeypackage_do_download.h │ │ │ ├── rootkeypackage_download.h │ │ │ ├── rootkeypackage_json_properties.h │ │ │ ├── rootkeypackage_parse.h │ │ │ ├── rootkeypackage_types.h │ │ │ └── rootkeypackage_utils.h │ ├── src │ │ ├── rootkeypackage_curl_download.cpp │ │ ├── rootkeypackage_do_download.cpp │ │ ├── rootkeypackage_download.c │ │ ├── rootkeypackage_parse.c │ │ └── rootkeypackage_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ ├── inc │ │ └── rootkeypkgtestutils.hpp │ │ ├── scripts │ │ └── rootkeypkg │ │ │ └── rootkeyfiles │ │ │ ├── README.md │ │ │ ├── create_and_verify_signatures.sh │ │ │ ├── modulus_1.base64url.txt │ │ │ ├── modulus_2.base64url.txt │ │ │ ├── root2.sig.base64.txt │ │ │ ├── rootkey.data.json │ │ │ ├── rootkey.json │ │ │ ├── testroot1.base64.txt │ │ │ ├── testroot1.txt │ │ │ ├── testroot2.base64.txt │ │ │ └── testroot2.txt │ │ ├── src │ │ ├── rootkeypackage_download_ut.cpp │ │ └── rootkeypackage_utils_ut.cpp │ │ ├── testapp │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ └── src │ │ │ └── main.cpp │ │ └── testdata │ │ └── rootkeypackage_utils │ │ ├── rootkeypackage.json │ │ └── rootkeypackage_template.json │ ├── string_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ ├── calloc_wrapper.hpp │ │ │ ├── string_handle_wrapper.hpp │ │ │ └── string_utils.hpp │ ├── src │ │ └── string_utils.cpp │ └── tests │ │ ├── CMakeLists.txt │ │ └── string_utils_ut.cpp │ ├── system_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── system_utils.h │ ├── src │ │ └── system_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ └── system_utils_ut.cpp │ ├── test_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ ├── auto_dir.hpp │ │ │ ├── auto_workflowhandle.hpp │ │ │ └── file_test_utils.hpp │ └── src │ │ ├── auto_dir.cpp │ │ └── file_test_utils.cpp │ ├── url_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ ├── https_proxy_utils.h │ │ │ └── url_utils.h │ ├── src │ │ ├── https_proxy_utils.c │ │ └── url_utils.c │ └── tests │ │ ├── CMakeLists.txt │ │ ├── https_proxy_utils_ut.cpp │ │ └── url_utils_ut.cpp │ ├── workflow_data_utils │ ├── CMakeLists.txt │ ├── inc │ │ └── aduc │ │ │ └── workflow_data_utils.h │ └── src │ │ └── workflow_data_utils.c │ └── workflow_utils │ ├── CMakeLists.txt │ ├── inc │ └── aduc │ │ ├── workflow_internal.h │ │ └── workflow_utils.h │ ├── src │ └── workflow_utils.c │ └── tests │ ├── CMakeLists.txt │ ├── main.cpp │ ├── testdata │ └── workflow_get_update_file │ │ ├── desired_template.json │ │ ├── prod-rootkeys.json │ │ └── updateManifest_downloadhandlerid_relatedfile.json │ ├── workflow_get_update_file_ut.cpp │ └── workflow_utils_ut.cpp ├── tools ├── AduCmdlets-py │ ├── CreateSampleComplexUpdate.py │ ├── CreateSampleSimpleUpdate.py │ ├── README.md │ └── scripts │ │ └── aduupdate.py ├── AduCmdlets │ ├── .gitignore │ ├── AduAzStorageBlobHelper.psm1 │ ├── AduImportUpdate.psm1 │ ├── AduRestApi.psm1 │ ├── AduUpdate.psm1 │ ├── CreateSampleComplexUpdate.ps1 │ ├── ImportSampleComplexUpdate.ps1 │ ├── README.md │ └── create-adu-import-manifest.sh ├── download_file │ ├── CMakeLists.txt │ ├── README.md │ └── main.cpp ├── openssl_install_script │ └── install-openssl.sh ├── packer │ ├── README.md │ └── build │ │ ├── README.md │ │ └── duagent-build.pkr.hcl └── selfhost │ ├── README.md │ ├── bootstrap.py │ ├── bootstrap.sh │ ├── bootstrap_config_example.json │ └── bootstrap_config_schema.json └── vcpkg.json /.clang-tidy: -------------------------------------------------------------------------------- 1 | # Exclusion Justifications 2 | # ======================== 3 | # hicpp-signed-bitwise: 4 | # generally considered useless. See https://bugs.llvm.org/show_bug.cgi?id=36961 5 | # 6 | # llvm-header-guard: 7 | # LLVM's header guard style is too verbose. 8 | # 9 | # hicpp-deprecated-headers: 10 | # see "modernize-deprecated-headers" 11 | # 12 | # modernize-deprecated-headers: 13 | # for C++ is better than , but we have C headers being used by C and C++ code. 14 | # 15 | # modernize-pass-by-value: 16 | # It's a stylistic choice to use "const string& s" vs "string s" with "std::move(s)" in a ctor. 17 | # 18 | # modernize-use-using: 19 | # "using" is better than "typedef" for C++, but we have C headers being used by C and C++ code. 20 | 21 | Checks: '*, 22 | -android-cloexec-fopen, 23 | -cppcoreguidelines-pro-bounds-array-to-pointer-decay, 24 | -cppcoreguidelines-pro-type-vararg, 25 | -fuchsia-default-arguments, 26 | -fuchsia-overloaded-operator, 27 | -hicpp-deprecated-headers, 28 | -hicpp-no-array-decay, 29 | -hicpp-signed-bitwise, 30 | -hicpp-vararg, 31 | -llvm-header-guard, 32 | -modernize-deprecated-headers, 33 | -modernize-pass-by-value, 34 | -modernize-use-using 35 | ' 36 | -------------------------------------------------------------------------------- /.cmake-format.json: -------------------------------------------------------------------------------- 1 | { 2 | "_1": "Documentation: https://pypi.org/project/cmake_format/", 3 | "_2": "find src -name CMakeLists.txt -print0 | xargs -0 -n1 -P4 cmake-format --in-place", 4 | "_3": "Get-ChildItem -Path src -Recurse -Include 'CMakeLists.txt' | ForEach-Object { Write-Progress -Activity 'cmake-format' -Status $_; cmake-format.exe --in-place $_ }", 5 | "encode": { 6 | "emit_byteorder_mark": false, 7 | "input_encoding": "utf-8", 8 | "output_encoding": "utf-8" 9 | }, 10 | "format": { 11 | "command_case": "lower", 12 | "keyword_case": "upper", 13 | "line_ending": "windows", 14 | "line_width": 100, 15 | "max_pargs_hwrap": 6, 16 | "max_subgroups_hwrap": 2, 17 | "separate_ctrl_name_with_space": true, 18 | "separate_fn_name_with_space": true, 19 | "tab_size": 4, 20 | "use_tabchars": false 21 | }, 22 | "markup": { 23 | "enable_markup": false 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | # end_of_line = lf 7 | indent_size = 4 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | # [*.md] 13 | # trim_trailing_whitespace = false 14 | 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | # require LF ending for shell scripts 4 | *.sh text eol=lf 5 | 6 | *.png binary 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### VisualStudio Code 2 | .vscode/ 3 | 4 | ### VisualStudio 2017 5 | .vs/ 6 | 7 | ### GDB debugger 8 | .gdbinit 9 | .gdb_history 10 | 11 | ### etags, ctags, gtags (GNU global), cscope, and cquery. 12 | TAGS 13 | .TAGS 14 | !TAGS/ 15 | tags 16 | tags.lock 17 | tags.temp 18 | .tags 19 | !tags/ 20 | gtags.files 21 | GTAGS 22 | GRTAGS 23 | GPATH 24 | GSYMS 25 | .cquery 26 | compile_commands.json 27 | cscope.files 28 | cscope.out 29 | cscope.in.out 30 | cscope.po.out 31 | 32 | ### openssl output 33 | *.sig 34 | *.pem 35 | 36 | ### Python Module Files 37 | *__pycache__ 38 | *__pycache__/* 39 | 40 | ### ADU build environment 41 | out/ 42 | build/ 43 | Testing/ 44 | 45 | ### VCPKG 46 | .vcpkg/ 47 | .vcpkg-installed/ 48 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "EditorConfig.EditorConfig" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns. 10 | -------------------------------------------------------------------------------- /CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | set noparent 2 | filter=-readability/check 3 | -------------------------------------------------------------------------------- /DartConfiguration.tcl: -------------------------------------------------------------------------------- 1 | PurifyCommand: 2 | ValgrindCommand: "/usr/bin/valgrind" 3 | ValgrindCommandOptions: "--track-origins=yes --leak-check=full --show-reachable=yes --malloc-fill=F --free-fill=E --keep-stacktraces=alloc-and-free --show-mismatched-frees=yes --demangle=yes" 4 | DrMemoryCommand: 5 | DrMemoryCommandOptions: 6 | MemoryCheckType: 7 | MemoryCheckSanitizerOptions: 8 | MemoryCheckCommand: 9 | MemoryCheckCommandOptions: 10 | MemoryCheckSuppressionFile: 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | ## How to file issues and get help 4 | 5 | * Have a technical question? 6 | Ask on Stack Overflow with tag "iot-hub-device-update". 7 | 8 | * Found a bug, or want to request a new feature? 9 | You can use [GitHub Issues](https://github.com/Azure/iot-hub-device-update/issues) to track bugs and feature requests. If you feel like taking a stab at fixing the bug/adding the feature, please see the [Contribution guidance here](/CONTRIBUTING.md). 10 | 11 | * Need support? 12 | Please document your question on [GitHub Issues](https://github.com/Azure/iot-hub-device-update/issues) thoroughly, attach logs and give repro steps, so that we can help you unblock as soon as possible. 13 | 14 | * Customers with an [Azure support](https://azure.microsoft.com/support/options/) plan can open an [Azure support ticket](https://azure.microsoft.com/support/create-ticket/). 15 | We recommend this option if your problem requires immediate attention. 16 | 17 | ## Microsoft Support Policy 18 | 19 | Support for IoT Hub Device Update is limited to the resources listed above. 20 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/packer/deltagen/scripts/configure-apt-repo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Taken from the following but with sudo removed: 5 | # https://learn.microsoft.com/en-us/windows-server/administration/linux-package-repository-for-microsoft-software#examples 6 | # 7 | apt-get update || exit 1 8 | apt-get install -y curl wget sudo || exit 1 9 | 10 | # PMC APT repo config for use by .net core 6 sdk install 11 | wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb || exit 1 12 | dpkg -i packages-microsoft-prod.deb || exit 1 13 | rm packages-microsoft-prod.deb 14 | 15 | # Install repository configuration 16 | curl -sSL https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/microsoft-prod.list || exit 1 17 | 18 | # Install Microsoft GPG public key 19 | curl -sSL https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc || exit 1 20 | 21 | # Update package index files 22 | apt-get update || exit 1 23 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/packer/deltagen/scripts/install-diffgen-tool.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | unzip /tmp/linux64-diffgen-tool.zip 4 | 5 | base_dir="linux64-diffgen-tool" 6 | 7 | files=" 8 | zstd_compress_file 9 | working_folder_manager.py 10 | sign_tool.py 11 | recompress_tool.py 12 | recompress_and_sign_tool.py 13 | helpers.py 14 | dumpextfs 15 | dumpdiff 16 | compress_files.py 17 | bspatch 18 | bsdiff 19 | applydiff 20 | DiffGenTool 21 | " 22 | for x in $files; do 23 | chmod 755 "${base_dir}/$x" 24 | done 25 | 26 | cp "${base_dir}/libadudiffapi.so" /usr/local/lib/ 27 | ldconfig -v /usr/local/lib/libadudiffapi.so 28 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/packer/deltagen/scripts/install-prereqs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | apt-get install -y git 4 | apt-get install -y \ 5 | apt-utils \ 6 | curl \ 7 | openssl \ 8 | unzip \ 9 | || exit 1 10 | 11 | # Install .net core 5.0 sdk for Delta Generation Tool 12 | 13 | # First install tzdata dep non-interactively to prevent interactive blocking 14 | DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata || exit 1 15 | dpkg-reconfigure -f noninteractive tzdata || exit 1 16 | 17 | apt-get install -y dotnet-sdk-5.0 || exit 1 18 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/packer/deltagen/scripts/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # To be run from docker host after running: 5 | # packer build . 6 | # 7 | 8 | usage() { 9 | cat <<- EOS 10 | Usage: $(basename "$0") 11 | e.g. $(basename "$0") https://example.com/source.swu https://example.com/target.swu /path/to/host/outdir/for/delta/ 12 | EOS 13 | 14 | exit 1 15 | } 16 | 17 | test "$#" -eq 3 || usage 18 | 19 | docker_image=dudeltagen:latest 20 | 21 | SRC_SWU_URL="$1" 22 | TGT_SWU_URL="$2" 23 | HOST_DELTA_OUTPUT_DIR="$3" 24 | 25 | rm -rf /tmp/dockercp 26 | mkdir -p /tmp/dockercp || exit 1 27 | 28 | echo -e "\nDownloading Source .swu at $SRC_SWU_URL ..." 29 | wget -O "$HOST_DELTA_OUTPUT_DIR/src.swu" "$SRC_SWU_URL" || exit 1 30 | 31 | echo -e "\nDownloading Target .swu at $TGT_SWU_URL ..." 32 | wget -O "$HOST_DELTA_OUTPUT_DIR/tgt.swu" "$TGT_SWU_URL" || exit 1 33 | 34 | echo -e "\nRunning container with mount /deltaoutput bound to host's $HOST_DELTA_OUTPUT_DIR ..." 35 | docker run -it --rm --name deltagen \ 36 | -v "$HOST_DELTA_OUTPUT_DIR:/deltaoutput" \ 37 | ${docker_image} \ 38 | || exit 1 39 | 40 | echo -e "\nAll done!" 41 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/scenarios/testingtoolkit/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # -------------------------------------------------------------------------- 3 | # Copyright (c) Microsoft Corporation. All rights reserved. 4 | # Licensed under the MIT License. See License.txt in the project root for license information. 5 | # Code generated by Microsoft (R) AutoRest Code Generator. 6 | # Changes may cause incorrect behavior and will be lost if the code is regenerated. 7 | # -------------------------------------------------------------------------- 8 | 9 | from ._adu_test_toolkit import DeviceUpdateTestHelper,DeploymentStatusResponse,UpdateId, DuAutomatedTestConfigurationManager,DiagnosticLogCollectionStatusResponse,DiagnosticsDeviceStatus,DeploymentSubGroupStatus 10 | from ._version import VERSION 11 | 12 | __version__ = VERSION 13 | 14 | 15 | 16 | # I don't know what this is but we're keeping it for posterity in case I need it later 17 | # try: 18 | # from ._patch import patch_sdk # type: ignore 19 | # patch_sdk() 20 | # except ImportError: 21 | # pass 22 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/scenarios/testingtoolkit/_version.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # -------------------------------------------------------------------------- 3 | # Copyright (c) Microsoft Corporation. All rights reserved. 4 | # Licensed under the MIT License. See License.txt in the project root for license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | VERSION = "0.1.0" 8 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/scenarios/testingtoolkit/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-core==1.23.0 2 | azure-identity==1.16.1 3 | azure-iot-deviceupdate==1.0.0b2 4 | azure-iot-hub==2.6.0 5 | msrest==0.6.21 6 | unittest-xml-reporting==3.1.0 7 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/terraform/resource_group/ResourceGroup.tf: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | terraform { 7 | required_providers { 8 | azurerm = { 9 | source = "hashicorp/azurerm" 10 | version = "~>2.0" 11 | } 12 | } 13 | } 14 | provider "azurerm" { 15 | features {} 16 | 17 | subscription_id = var.subscription_id 18 | tenant_id = var.tenant_id 19 | 20 | # Local testing - must create a SP and plumb id/secret below using scripts/create-sp-terraform.sh 21 | client_id = var.client_id 22 | client_secret = var.client_secret 23 | } 24 | 25 | resource "random_pet" "rg-name" { 26 | prefix = var.resource_group_name_prefix 27 | } 28 | 29 | resource "azurerm_resource_group" "du-resource-group" { 30 | name = random_pet.rg-name.id 31 | location = var.resource_group_location 32 | 33 | tags = { 34 | environment = var.environment_tag 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/terraform/resource_group/output.tf: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | output "du_resource_group_name" { 7 | value = azurerm_resource_group.du-resource-group.name 8 | } 9 | -------------------------------------------------------------------------------- /azurepipelines/e2e_test/terraform/resource_group/variables.tf: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | # Local testing - must create a SP and plumb client_id/client_secret below 7 | variable "client_id" {} 8 | variable "client_secret" {} 9 | variable "subscription_id" {} 10 | variable "tenant_id" {} 11 | 12 | variable resource_group_name_prefix { 13 | default = "du-e2etest-rg" 14 | description = "Concatenated with a random two word petname to form the Resource Group name for the deployment" 15 | } 16 | 17 | 18 | variable "resource_group_location" { 19 | default = "eastus" 20 | description = "Location of the resource group." 21 | } 22 | 23 | variable "environment_tag" { 24 | default = "du-e2etest" 25 | description = "Tag used for managing generated resources for infrastructure tear down" 26 | } 27 | -------------------------------------------------------------------------------- /cmake/FindIotHubClient.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | # Find cmake module for the iothub_client library and headers 5 | # Exports IotHubClient::iothub_client target 6 | 7 | cmake_minimum_required (VERSION 3.5) 8 | 9 | include (FindPackageHandleStandardArgs) 10 | 11 | find_path ( 12 | IotHubClient_INCLUDE_DIR 13 | NAMES iothub_client.h 14 | PATH_SUFFIXES azureiot azureiot/inc) 15 | 16 | find_library (IotHubClient_LIBRARY iothub_client) 17 | 18 | find_package_handle_standard_args ( 19 | IotHubClient 20 | DEFAULT_MSG 21 | IotHubClient_INCLUDE_DIR 22 | IotHubClient_LIBRARY) 23 | 24 | if (IotHubClient_FOUND) 25 | set (IotHubClient_INCLUDE_DIRS ${IotHubClient_INCLUDE_DIR}) 26 | set (IotHubClient_LIBRARIES ${IotHubClient_LIBRARY}) 27 | 28 | if (NOT TARGET IotHubClient::iothub_client) 29 | add_library (IotHubClient::iothub_client INTERFACE IMPORTED) 30 | set_target_properties ( 31 | IotHubClient::iothub_client 32 | PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${IotHubClient_INCLUDE_DIRS}" 33 | INTERFACE_LINK_LIBRARIES "${IotHubClient_LIBRARIES}") 34 | endif () 35 | endif () 36 | -------------------------------------------------------------------------------- /cmake/find_curl.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | # Wrapper around the existing FindCURL module provided by CMake. 5 | # Adds target CURL::libcurl if it doesn't already exist. 6 | # FindCURL doesn't export targets until CMake 3.12. 7 | 8 | cmake_minimum_required (VERSION 3.5) 9 | 10 | macro (find_curl) 11 | find_package (CURL 12 | ${ARGV}) 13 | 14 | if (CURL_FOUND AND NOT TARGET CURL::libcurl) 15 | add_library (CURL::libcurl 16 | INTERFACE 17 | IMPORTED) 18 | set_target_properties (CURL::libcurl 19 | PROPERTIES INTERFACE_INCLUDE_DIRECTORIES 20 | "${CURL_INCLUDE_DIRS}" 21 | INTERFACE_LINK_LIBRARIES 22 | "${CURL_LIBRARIES}") 23 | endif () 24 | endmacro () 25 | -------------------------------------------------------------------------------- /daemon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | install ( 4 | FILES deviceupdate-agent.service 5 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/system 6 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) 7 | 8 | if (ADUC_REGISTER_DAEMON) 9 | install ( 10 | CODE "execute_process (COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install.sh ${ADUC_CONF_FOLDER} ${ADUC_CONF_FILE} ${ADUC_HOME_FOLDER} ${ADUC_LOG_FOLDER} ${ADUC_DATA_FOLDER})" 11 | ) 12 | endif () 13 | -------------------------------------------------------------------------------- /daemon/deviceupdate-agent.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Device Update Agent daemon. 3 | After=network-online.target deliveryoptimization-agent.service 4 | Wants=network-online.target deliveryoptimization-agent.service 5 | 6 | [Service] 7 | Type=simple 8 | Restart=always 9 | RestartSec=5 10 | User=adu 11 | Group=adu 12 | # systemd will try to start the ADU executable 5 times and then give up. 13 | # We can check logs with journalctl -f -u deviceupdate-agent.service 14 | # Set log verbosity level to 'Debug' and enable IoT Hub tracing. 15 | ExecStart=/usr/bin/AducIotAgent -l 0 -e 16 | 17 | [Install] 18 | WantedBy=multi-user.target 19 | -------------------------------------------------------------------------------- /docs/agent-reference/images/agent-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/docs/agent-reference/images/agent-architecture.png -------------------------------------------------------------------------------- /docs/agent-reference/images/apply-phase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/docs/agent-reference/images/apply-phase.png -------------------------------------------------------------------------------- /docs/agent-reference/images/download-phase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/docs/agent-reference/images/download-phase.png -------------------------------------------------------------------------------- /docs/agent-reference/images/goalstate-state-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/docs/agent-reference/images/goalstate-state-diagram.png -------------------------------------------------------------------------------- /docs/agent-reference/images/install-phase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/docs/agent-reference/images/install-phase.png -------------------------------------------------------------------------------- /docs/sample-artifacts/libcurl4-doc-7.58-apt-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Sample package update 2", 3 | "version": "2.0.1", 4 | "packages": [ 5 | { 6 | "name": "libcurl4-doc", 7 | "version": "7.58.0-2ubuntu3.12" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /docs/sample-artifacts/libcurl4-doc-apt-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Sample package update", 3 | "version": "1.0.1", 4 | "packages": [ 5 | { 6 | "name": "libcurl4-doc" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /docs/sample-artifacts/libcurl4-doc-remove-apt-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Sample package update", 3 | "version": "1.0.2", 4 | "packages": [ 5 | { 6 | "name": "libcurl4-doc-" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /docs/sample-artifacts/sample-package-update-1.0.1-importManifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "updateId": { 3 | "provider": "Contoso", 4 | "name": "SampleUpdate1", 5 | "version": "1.0.1" 6 | }, 7 | "updateType": "microsoft/apt:1", 8 | "installedCriteria": "Sample package update-1.0.1", 9 | "compatibility": [ 10 | { 11 | "manufacturer": "Contoso", 12 | "model": "Video" 13 | } 14 | ], 15 | "files": [ 16 | { 17 | "filename": "libcurl4-doc-apt-manifest.json", 18 | "sizeInBytes": 154, 19 | "hashes": { 20 | "sha256": "G9gVz4WqTRu/cXfRjNMbpENxEuAXqlT0E1vLOgaMICw=" 21 | } 22 | } 23 | ], 24 | "createdDateTime": "2021-02-23T04:35:22.4375560Z", 25 | "manifestVersion": "2.0" 26 | } 27 | -------------------------------------------------------------------------------- /docs/sample-artifacts/sample-package-update-1.0.2-importManifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "updateId": { 3 | "provider": "Contoso", 4 | "name": "SampleUpdate", 5 | "version": "1.0.2" 6 | }, 7 | "updateType": "microsoft/apt:1", 8 | "installedCriteria": "Sample package update-1.0.2", 9 | "compatibility": [ 10 | { 11 | "manufacturer": "Contoso", 12 | "model": "Video" 13 | } 14 | ], 15 | "files": [ 16 | { 17 | "filename": "libcurl4-doc-remove-apt-manifest.json", 18 | "sizeInBytes": 155, 19 | "hashes": { 20 | "sha256": "RL/OBnj5kQ/0VsQ1C+pb7NnUvYCpzFZEkb5buCLoJWU=" 21 | } 22 | } 23 | ], 24 | "createdDateTime": "2021-02-23T04:35:22.6533536Z", 25 | "manifestVersion": "2.0" 26 | } 27 | -------------------------------------------------------------------------------- /docs/sample-artifacts/sample-package-update-2-2.0.1-importManifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "updateId": { 3 | "provider": "Contoso", 4 | "name": "SampleUpdate2", 5 | "version": "2.0.1" 6 | }, 7 | "updateType": "microsoft/apt:1", 8 | "installedCriteria": "Sample package update 2-2.0.1", 9 | "compatibility": [ 10 | { 11 | "manufacturer": "Contoso", 12 | "model": "Video" 13 | } 14 | ], 15 | "files": [ 16 | { 17 | "filename": "libcurl4-doc-7.58-apt-manifest.json", 18 | "sizeInBytes": 202, 19 | "hashes": { 20 | "sha256": "6B0XlSRRZiUxjTgEzFImEMd76VwlERbzdRSYU3PfpHY=" 21 | } 22 | } 23 | ], 24 | "createdDateTime": "2021-02-23T04:35:22.7946429Z", 25 | "manifestVersion": "2.0" 26 | } 27 | -------------------------------------------------------------------------------- /packages/debian/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # prerm 4 | # pre-remove script for ADU Agent debian package. 5 | # Deregister deviceupdate-agent daemon. 6 | # See https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html 7 | 8 | adu_agent_service=deviceupdate-agent.service 9 | adu_agent_unit_file=/usr/lib/systemd/system/deviceupdate-agent.service 10 | 11 | deregister_daemon() 12 | { 13 | # Stop and remove deviceupdate-agent service from the failed services list. No-op if never failed earlier. 14 | systemctl stop $adu_agent_service 15 | systemctl reset-failed $adu_agent_service 16 | } 17 | 18 | case "$1" in 19 | remove) 20 | deregister_daemon 21 | ;; 22 | 23 | abort-install|upgrade|failed-upgrade|abort-upgrade|disappear) 24 | ;; 25 | 26 | *) 27 | echo "prerm called with unknown argument \`$1'" >&2 28 | exit 1 29 | ;; 30 | esac 31 | 32 | exit 0 33 | -------------------------------------------------------------------------------- /scripts/clang-format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) Microsoft Corporation. 4 | # Licensed under the MIT License. 5 | 6 | # Ensure that getopt starts from first option if ". " was used. 7 | OPTIND=1 8 | 9 | # Ensure we dont end the user's terminal session if invoked from source ("."). 10 | if [[ $0 != "${BASH_SOURCE[0]}" ]]; then 11 | ret='return' 12 | else 13 | ret='exit' 14 | fi 15 | 16 | if ! [ -x "$(command -v git)" ]; then 17 | echo 'Error: git is not installed.' >&2 18 | $ret 1 19 | fi 20 | 21 | if ! [ -x "$(command -v clang-format)" ]; then 22 | echo 'Error: clang-format is not installed. Try: apt install clang-format' >&2 23 | $ret 1 24 | fi 25 | 26 | GITROOT="$(git rev-parse --show-toplevel 2> /dev/null)" 27 | 28 | if [ -z "$GITROOT" ]; then 29 | echo 'Unable to determine git root.' >&2 30 | $ret 1 31 | fi 32 | 33 | pushd "$GITROOT" > /dev/null || $ret 34 | # diff-filter=d will exclude deleted files. 35 | IFS=$'\n' 36 | for FILE in $(git diff --diff-filter=d --relative --name-only HEAD -- "*.[CcHh]" "*.[CcHh][Pp][Pp]"); do 37 | clang-format -verbose -style=file -i "$FILE" 38 | done 39 | IFS=' ' 40 | popd > /dev/null || $ret 41 | -------------------------------------------------------------------------------- /scripts/docker/dbg_docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # e.g. $ ./dbg_docker.sh duagentaptcurlubuntu18.04stable:1.0 bash 4 | 5 | # SYS_PTRACE capability is needed to allow gdb to set breakpoints 6 | docker run --rm -it --cap-add=SYS_PTRACE --security-opt seccomp=unconfined "$@" 7 | ret_val=$? 8 | if [ $ret_val -ne 0 ]; then 9 | exit 1 10 | fi 11 | -------------------------------------------------------------------------------- /scripts/docker/setup_docker_container.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [[ $# -ne 4 ]]; then 5 | echo "USAGE: $0 /path/to/dockerimage.tar.gz " 6 | exit 1 7 | fi 8 | 9 | gunzip "$1" 10 | dir_name=$(dirname "$1") 11 | base_name=$(basename "$1" .gz) 12 | docker load < "$dir_name/$base_name" 13 | docker run -i -t --detach duagentaptcurlubuntu18.04stable:1.0 bash 14 | 15 | tmp_container_id=$(docker ps | grep duagentaptcurl | cut -f1 -d' ') 16 | # echo $tmp_container_id 17 | 18 | docker cp "$tmp_container_id:/etc/adu/du-config.json" ./du-config.template.json 19 | sed -i -e "s/CONNECTION_STRING_PLACEHOLDER/$2/g" du-config.template.json 20 | sed -i -e "s/contoso/$3/g" du-config.template.json 21 | sed -i -e "s/toaster/$4/g" du-config.template.json 22 | docker cp du-config.template.json "$tmp_container_id:/etc/adu/du-config.json" 23 | 24 | echo 25 | echo "Attaching to docker container $tmp_container_id... Ctrl + P, Ctrl + Q to detach" 26 | echo 27 | docker attach "$tmp_container_id" 28 | -------------------------------------------------------------------------------- /scripts/docker/templates/Dockerfile.template: -------------------------------------------------------------------------------- 1 | # Hardcode the base image to ubuntu:18.04 to avoid the supply chain attack. 2 | # FROM %%CONTAINER_IMAGE_BASE_IMAGE%% 3 | FROM "mcr.microsoft.com/mirror/docker/library/ubuntu:18.04" 4 | 5 | ADD ./app.tar.gz / 6 | 7 | RUN apt-get update && apt-get install -y libcurl4-gnutls-dev \ 8 | && ln -s /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4.5.0 /usr/lib/libcurl.so.4 \ 9 | && apt-get install -y libxml2 \ 10 | && apt-get install -y libboost-filesystem1.65.1 \ 11 | && ln -s /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1 /usr/lib/libboost_filesystem.so.1.65.1 \ 12 | && ln -s /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 /usr/lib/libboost_system.so.1.65.1 \ 13 | && apt-get install -y libcurl4-openssl-dev %%APT_PACKAGES_FOR_DEBUGGING%% 14 | 15 | RUN /bin/sh /usr/lib/adu/setup_container.sh 16 | 17 | LABEL version="%%CONTAINER_IMAGE_VERSION%%" 18 | LABEL description="%%CONTAINER_IMAGE_DESCRIPTION%%" 19 | 20 | CMD %%CONTAINER_IMAGE_DOCKER_CMD%% 21 | -------------------------------------------------------------------------------- /scripts/docker/templates/content_downloader.extension.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "fileName":"/var/lib/adu/extensions/sources/%%so_name%%.so", 3 | "sizeInBytes":0, 4 | "hashes": { 5 | "sha256":"%%base64digest%%" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /scripts/docker/templates/content_handler.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "fileName":"/var/lib/adu/extensions/sources/%%so_name%%.so", 3 | "sizeInBytes":0, 4 | "hashes": { 5 | "sha256":"%%base64digest%%" 6 | }, 7 | "handlerId":"%%handlerid%%" 8 | } 9 | -------------------------------------------------------------------------------- /scripts/docker/templates/du-config.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": "1.1", 3 | "aduShellTrustedUsers": [ 4 | "adu", 5 | "do" 6 | ], 7 | "compatPropertyNames": "%%DUCONFIG_COMPAT_PROPERTY_NAMES%%", 8 | "manufacturer": "%%DUCONFIG_DEVICEINFO_MANUFACTURER%%", 9 | "model": "%%DUCONFIG_DEVICEINFO_MODEL%%", 10 | "agents": [ 11 | { 12 | "name": "%%DUCONFIG_AGENT_NAME%%", 13 | "runas": "adu", 14 | "connectionSource": { 15 | "connectionType": "string", 16 | "connectionData": "%%DUCONFIG_CONNECTION_STRING%%" 17 | }, 18 | "manufacturer": "%%DUCONFIG_DEVICEPROPERTIES_MANUFACTURER%%", 19 | "model": "%%DUCONFIG_DEVICEPROPERTIES_MODEL%%" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /scripts/docker/templates/du-diagnostics-config.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "logComponents":[ 3 | { 4 | "componentName":"adu", 5 | "logPath":"/var/log/adu/" 6 | } 7 | ], 8 | "maxKilobytesToUploadPerLogPath":50 9 | } 10 | -------------------------------------------------------------------------------- /scripts/githooks/pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Ensure we dont end the user's terminal session if invoked from source ("."). 4 | if [[ $0 != "${BASH_SOURCE[0]}" ]]; then 5 | ret='return' 6 | else 7 | ret='exit' 8 | fi 9 | 10 | if ! [ -x "$(command -v git)" ]; then 11 | echo 'Error: git is not installed.' >&2 12 | $ret 1 13 | fi 14 | 15 | if ! GITROOT="$(git rev-parse --show-toplevel 2> /dev/null)"; then 16 | echo "'git rev-parse' failed with $?" 17 | $ret 1 18 | fi 19 | 20 | if [ -z "$GITROOT" ]; then 21 | echo 'Unable to determine git root.' >&2 22 | $ret 1 23 | fi 24 | 25 | # Redirect output to stderr. 26 | exec 1>&2 27 | 28 | # Run shell format first in case below scripts have issues 29 | if ! "$GITROOT/scripts/sh-format.sh" -v; then 30 | $ret 1 31 | fi 32 | 33 | # Disable for now due to arg compat across clangformat versions 34 | # if ! "$GITROOT/scripts/clang-format.sh"; then 35 | # $ret 1 36 | # fi 37 | 38 | # Unfortunately, cmake-format cannot take in piped file contents, so 39 | # not using it for pre-commit hook currently. 40 | # if ! "$GITROOT/scripts/cmake-format.sh"; then 41 | # $ret 1 42 | # fi 43 | -------------------------------------------------------------------------------- /src/adu-shell/inc/adushell_action.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file adushell_action.hpp 3 | * @brief Private header for ADU Shell Actions enum and helper functions. 4 | * @copyright Copyright (c) Microsoft Corporation. 5 | * Licensed under the MIT License. 6 | */ 7 | #ifndef ADU_SHELL_ACTION_HPP 8 | #define ADU_SHELL_ACTION_HPP 9 | 10 | enum class ADUShellAction 11 | { 12 | Unknown, 13 | Initialize, 14 | Download, 15 | Install, 16 | Remove, 17 | Apply, 18 | Cancel, 19 | Rollback, 20 | Reboot, 21 | Execute 22 | }; 23 | 24 | /** 25 | * @brief Convert string to ADUShellAction value. 26 | * @param actionString A string to convert. 27 | * 28 | * @return ADUShellAction enum value, or ADUShellAction::Unknown for unknown action string. 29 | */ 30 | ADUShellAction ADUShellActionFromString(const char* actionString); 31 | 32 | #endif // ADU_SHELL_ACTION_HPP 33 | -------------------------------------------------------------------------------- /src/adu-shell/inc/common_tasks.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file common_tasks.hpp 3 | * 4 | * @brief Implements a set of common tasks for most update type. 5 | * 6 | * @copyright Copyright (c) Microsoft Corporation. 7 | * Licensed under the MIT License. 8 | */ 9 | #ifndef ADU_SHELL_COMMON_TASKS_HPP 10 | #define ADU_SHELL_COMMON_TASKS_HPP 11 | 12 | #include 13 | 14 | namespace Adu 15 | { 16 | namespace Shell 17 | { 18 | namespace Tasks 19 | { 20 | namespace Common 21 | { 22 | /** 23 | * @brief Reboot the system. 24 | * 25 | * @param launchArgs The adu-shell launch command-line arguments that has been parsed. 26 | * @return A result from child process. 27 | */ 28 | ADUShellTaskResult Reboot(const ADUShell_LaunchArguments& launchArgs); 29 | 30 | /** 31 | * @brief Runs appropriate command based on an action and other arguments in launchArgs. 32 | * 33 | * This could resulted in one or more packaged installed or removed from the system. 34 | * 35 | * @param launchArgs The adu-shell launch command-line arguments that has been parsed. 36 | * @return A result from child process. 37 | */ 38 | ADUShellTaskResult DoCommonTask(const ADUShell_LaunchArguments& launchArgs); 39 | 40 | } // namespace Common 41 | } // namespace Tasks 42 | } // namespace Shell 43 | } // namespace Adu 44 | 45 | #endif // ADU_SHELL_COMMON_TASKS_HPP 46 | -------------------------------------------------------------------------------- /src/adu-shell/inc/script_tasks.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file script_tasks.hpp 3 | * @brief Implements functions related to microsoft/script update type. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADU_SHELL_SCRIPT_TASKS_HPP 9 | #define ADU_SHELL_SCRIPT_TASKS_HPP 10 | 11 | #include 12 | 13 | namespace Adu 14 | { 15 | namespace Shell 16 | { 17 | namespace Tasks 18 | { 19 | namespace Script 20 | { 21 | /** 22 | * @brief Runs appropriate command based on an action and other arguments in launchArgs. 23 | * 24 | * @param launchArgs An adu-shell launch arguments. 25 | * @return A result from child process. 26 | */ 27 | ADUShellTaskResult Execute(const ADUShell_LaunchArguments& launchArgs); 28 | 29 | /** 30 | * @brief Runs appropriate command based on an action and other arguments in launchArgs. 31 | * 32 | * @param launchArgs An adu-shell launch arguments. 33 | * @return A result from child process. 34 | */ 35 | ADUShellTaskResult DoScriptTask(const ADUShell_LaunchArguments& launchArgs); 36 | 37 | } // namespace Script 38 | } // namespace Tasks 39 | } // namespace Shell 40 | } // namespace Adu 41 | 42 | #endif // ADU_SHELL_SWUPDATE_TASKS_HPP 43 | -------------------------------------------------------------------------------- /src/adu-shell/scripts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | install (PROGRAMS adu-swupdate.sh DESTINATION ${CMAKE_INSTALL_BINDIR}/) 4 | -------------------------------------------------------------------------------- /src/adu_types/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name adu_types) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | 9 | add_library (${target_name} STATIC src/adu_types.c) 10 | 11 | add_library (aduc::${target_name} ALIAS ${target_name}) 12 | 13 | find_package (Parson REQUIRED) 14 | 15 | # 16 | # Turn -fPIC on, in order to use this library in another shared library. 17 | # 18 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 19 | 20 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 21 | 22 | target_link_libraries (${target_name} PUBLIC aduc::c_utils aduc::logging Parson::parson) 23 | -------------------------------------------------------------------------------- /src/adu_types/inc/aduc/types/download.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file download.h 3 | * @brief Defines types related to file download functionality. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADUC_TYPES_DOWNLOAD_H 9 | #define ADUC_TYPES_DOWNLOAD_H 10 | 11 | #include // uint64_t 12 | 13 | /** 14 | * @brief Defines download progress state for download progress callback. 15 | */ 16 | typedef enum tagADUC_DownloadProgressState 17 | { 18 | ADUC_DownloadProgressState_NotStarted = 0, 19 | ADUC_DownloadProgressState_InProgress, 20 | ADUC_DownloadProgressState_Completed, 21 | ADUC_DownloadProgressState_Cancelled, 22 | ADUC_DownloadProgressState_Error 23 | } ADUC_DownloadProgressState; 24 | 25 | /** 26 | * @brief Function signature for callback to send download progress to. 27 | */ 28 | typedef void (*ADUC_DownloadProgressCallback)( 29 | const char* workflowId, 30 | const char* fileId, 31 | ADUC_DownloadProgressState state, 32 | uint64_t bytesTransferred, 33 | uint64_t bytesTotal); 34 | 35 | #endif // ADUC_TYPES_DOWNLOAD_H 36 | -------------------------------------------------------------------------------- /src/adu_types/inc/aduc/types/hash.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hash.h 3 | * @brief Defines types related to hashing functionality. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADUC_TYPES_HASH_H 9 | #define ADUC_TYPES_HASH_H 10 | 11 | #include // for bool 12 | #include // for size_T 13 | 14 | #include "aduc/c_utils.h" 15 | 16 | 17 | EXTERN_C_BEGIN 18 | 19 | /** 20 | * @brief Encapsulates the hash and the hash type 21 | */ 22 | typedef struct tagADUC_Hash 23 | { 24 | char* value; /**< The value of the actual hash */ 25 | char* type; /**< The type of hash held in the entry*/ 26 | } ADUC_Hash; 27 | 28 | EXTERN_C_END 29 | 30 | #endif // ADUC_TYPES_HASH_H 31 | -------------------------------------------------------------------------------- /src/adu_workflow/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name agent_workflow) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC "") 8 | 9 | add_library (aduc::${target_name} ALIAS ${target_name}) 10 | 11 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 12 | 13 | target_sources (${target_name} PRIVATE src/agent_workflow.c) 14 | 15 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 16 | 17 | find_package (Parson REQUIRED) 18 | 19 | target_link_libraries ( 20 | ${target_name} 21 | PUBLIC aduc::adu_types 22 | PRIVATE aduc::adu_core_export_helpers 23 | aduc::agent_orchestration 24 | aduc::c_utils 25 | aduc::config_utils 26 | aduc::download_handler_factory 27 | aduc::download_handler_plugin 28 | aduc::logging 29 | aduc::parser_utils 30 | aduc::root_key_utils 31 | aduc::system_utils 32 | aduc::workflow_data_utils 33 | aduc::workflow_utils) 34 | 35 | target_compile_definitions (${target_name} PRIVATE ADUC_CONF_FILE_PATH="${ADUC_CONF_FILE_PATH}") 36 | 37 | target_link_libraries (${target_name} PRIVATE libaducpal) 38 | target_link_aziotsharedutil (${target_name} PRIVATE) 39 | -------------------------------------------------------------------------------- /src/agent/adu_core_export_helpers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name adu_core_export_helpers) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | find_package (Parson REQUIRED) 8 | 9 | add_library (${target_name} STATIC "") 10 | add_library (aduc::${target_name} ALIAS ${target_name}) 11 | 12 | # Turn -fPIC on, in order to use this library in a shared library. 13 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 14 | 15 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 16 | 17 | target_sources (${target_name} PRIVATE src/adu_core_export_helpers.c) 18 | 19 | target_link_libraries ( 20 | ${target_name} 21 | PUBLIC aduc::adu_types aduc::c_utils 22 | PRIVATE aduc::logging aduc::platform_layer Parson::parson) 23 | -------------------------------------------------------------------------------- /src/agent/adu_core_interface/inc/aduc/health_management.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file health_management.h 3 | * @brief Implements functions that determine whether ADU Agent can function properly. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADUC_HEALTH_MANAGEMENT_H 9 | #define ADUC_HEALTH_MANAGEMENT_H 10 | 11 | #include "aduc/adu_types.h" 12 | #include 13 | 14 | /** 15 | * @brief Performs necessary checks to determine whether ADU Agent can function properly. 16 | * 17 | * @return true if all checks passed. 18 | */ 19 | bool HealthCheck(); 20 | 21 | #endif // ADUC_HEALTH_MANAGEMENT_H 22 | -------------------------------------------------------------------------------- /src/agent/adu_core_interface/tests/testdata/workflow_reboot/expectedClientReportingStringAfterReboot.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceUpdate": { 3 | "__t": "c", 4 | "agent": { 5 | "lastInstallResult": { 6 | "resultCode": 700, 7 | "extendedResultCode": 0, 8 | "resultDetails": "" 9 | }, 10 | "state": 0, 11 | "workflow": { 12 | "action": 3, 13 | "id": "e99c69ca-3188-43a3-80af-310616c7751d" 14 | }, 15 | "installedUpdateId": "{\"provider\":\"Contoso\",\"name\":\"Virtual-Vacuum\",\"version\":\"20.0\"}" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/agent/adu_core_interface/tests/testdata/workflow_reboot/expectedPersistedReportingJson.json: -------------------------------------------------------------------------------- 1 | { 2 | "lastInstallResult": { 3 | "resultCode": 400, 4 | "extendedResultCode": 0, 5 | "resultDetails": "" 6 | }, 7 | "state": 0, 8 | "workflow": { 9 | "action": 3, 10 | "id": "e99c69ca-3188-43a3-80af-310616c7751d" 11 | }, 12 | "installedUpdateId": "{\"provider\":\"Contoso\",\"name\":\"VacuumBundleUpdate\",\"version\":\"1.0\"}" 13 | } 14 | -------------------------------------------------------------------------------- /src/agent/adu_core_interface/tests/testdata/workflow_reboot/expectedPersistedWorkflowData.json: -------------------------------------------------------------------------------- 1 | { 2 | "WorkflowStep": 4, 3 | "ResultCode": 0, 4 | "ExtendedResultCode": 0, 5 | "SystemRebootState": 2, 6 | "AgentRestartState": 0, 7 | "ExpectedUpdateID": "{\"provider\":\"Contoso\",\"name\":\"VacuumBundleUpdate\",\"version\":\"1.0\"}", 8 | "WorkflowId": "e99c69ca-3188-43a3-80af-310616c7751d", 9 | "UpdateType": "", 10 | "InstalledCriteria": "", 11 | "WorkFolder": "\/var\/lib\/adu\/downloads\/e99c69ca-3188-43a3-80af-310616c7751d", 12 | "ReportingJson": "{\"lastInstallResult\":{\"resultCode\":400,\"extendedResultCode\":0,\"resultDetails\":\"\"},\"state\":0,\"workflow\":{\"action\":3,\"id\":\"e99c69ca-3188-43a3-80af-310616c7751d\"},\"installedUpdateId\":\"{\\\"provider\\\":\\\"Contoso\\\",\\\"name\\\":\\\"VacuumBundleUpdate\\\",\\\"version\\\":\\\"1.0\\\"}\"}" 13 | } 14 | -------------------------------------------------------------------------------- /src/agent/command_helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name command_helper) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC ./src/command_helper.c) 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | target_compile_definitions ( 11 | ${target_name} PRIVATE ADUC_COMMANDS_FIFO_NAME="${ADUC_COMMANDS_FIFO_NAME}" 12 | ADUC_FILE_GROUP="${ADUC_FILE_GROUP}" ADUC_FILE_USER="${ADUC_FILE_USER}") 13 | if (WIN32) 14 | find_package (PThreads4W REQUIRED) 15 | target_link_libraries (${target_name} PRIVATE PThreads4W::PThreads4W) 16 | endif () 17 | 18 | target_include_directories ( 19 | ${target_name} 20 | PUBLIC inc 21 | PRIVATE ${ADUC_EXPORT_INCLUDES}) 22 | 23 | target_link_libraries (${target_name} PRIVATE aduc::logging aduc::permission_utils) 24 | 25 | target_link_libraries (${target_name} PRIVATE libaducpal) 26 | -------------------------------------------------------------------------------- /src/agent/device_info_interface/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name device_info_interface) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC src/device_info_interface.c) 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | target_include_directories ( 11 | ${target_name} 12 | PUBLIC inc 13 | PRIVATE ${ADUC_EXPORT_INCLUDES}) 14 | 15 | target_link_iothub_client (${target_name} PUBLIC) 16 | 17 | target_link_libraries ( 18 | ${target_name} 19 | PUBLIC aduc::c_utils aduc::communication_abstraction 20 | PRIVATE aduc::d2c_messaging 21 | aduc::logging 22 | aduc::pnp_helper 23 | IotHubClient::iothub_client) 24 | 25 | target_link_libraries (${target_name} PRIVATE libaducpal) 26 | -------------------------------------------------------------------------------- /src/agent/pnp_helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name pnp_helper) 2 | include (agentRules) 3 | 4 | compileasc99 () 5 | 6 | add_library (${target_name} STATIC ./src/pnp_protocol.c) 7 | add_library (aduc::${target_name} ALIAS ${target_name}) 8 | # 9 | # Turn -fPIC on, in order to use this library in another shared library. 10 | # 11 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 12 | 13 | target_include_directories ( 14 | ${target_name} 15 | PUBLIC inc 16 | PRIVATE ${ADUC_EXPORT_INCLUDES}) 17 | 18 | target_link_iothub_client (${target_name} PUBLIC) 19 | 20 | target_link_libraries ( 21 | ${target_name} 22 | PRIVATE IotHubClient::iothub_client 23 | aduc::communication_abstraction 24 | aduc::logging 25 | iothub_client_mqtt_transport 26 | umqtt) 27 | -------------------------------------------------------------------------------- /src/agent/shutdown_service/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name shutdown_service) 2 | 3 | include (agentRules) 4 | compileasc99 () 5 | disablertti () 6 | 7 | add_library (${target_name} STATIC) 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | target_sources (${target_name} PRIVATE src/shutdown_service.c) 11 | 12 | target_include_directories (${target_name} PUBLIC inc) 13 | 14 | target_link_aziotsharedutil (${target_name} PRIVATE) 15 | 16 | target_link_libraries (${target_name} PUBLIC aduc::c_utils) 17 | -------------------------------------------------------------------------------- /src/agent/shutdown_service/inc/aduc/shutdown_service.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file shutdown_service.h 3 | * @brief Header for agent shutdown services. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADUC_SHUTDOWN_SERVICE 9 | #define ADUC_SHUTDOWN_SERVICE 10 | 11 | #include 12 | #include 13 | 14 | EXTERN_C_BEGIN 15 | 16 | /** 17 | * @brief Requests the agent to shutdown. 18 | */ 19 | void ADUC_ShutdownService_RequestShutdown(); 20 | 21 | /** 22 | * @brief Whether agent should keep running. 23 | * 24 | * @return false if a shutdown has been requested. 25 | */ 26 | bool ADUC_ShutdownService_ShouldKeepRunning(); 27 | 28 | EXTERN_C_END 29 | 30 | #endif //ADUC_SHUTDOWN_SERVICE 31 | -------------------------------------------------------------------------------- /src/agent/shutdown_service/src/shutdown_service.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file shutdown_service.c 4 | * @brief Implementation for agent shutdown services. 5 | * 6 | * @copyright Copyright (c) Microsoft Corporation. 7 | * Licensed under the MIT License. 8 | */ 9 | 10 | #include "aduc/shutdown_service.h" 11 | 12 | static bool s_isShuttingDown = false; 13 | 14 | void ADUC_ShutdownService_RequestShutdown() 15 | { 16 | s_isShuttingDown = true; 17 | } 18 | 19 | bool ADUC_ShutdownService_ShouldKeepRunning() 20 | { 21 | return !s_isShuttingDown; 22 | } 23 | -------------------------------------------------------------------------------- /src/agent_orchestration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name agent_orchestration) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC "") 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 11 | 12 | target_sources (${target_name} PRIVATE src/agent_orchestration.c) 13 | 14 | target_link_aziotsharedutil (${target_name} PRIVATE) 15 | 16 | target_link_libraries ( 17 | ${target_name} 18 | PUBLIC aduc::adu_types 19 | PRIVATE aduc::c_utils aduc::workflow_utils) 20 | -------------------------------------------------------------------------------- /src/communication_abstraction/inc/aduc/client_handle.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file client_handle.h 3 | * @brief Declares the ClientHandle type 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef CLIENT_HANDLE_H 10 | #define CLIENT_HANDLE_H 11 | #include 12 | 13 | EXTERN_C_BEGIN 14 | 15 | typedef void* ADUC_ClientHandle; 16 | 17 | EXTERN_C_END 18 | #endif // CLIENT_HANDLE_H 19 | -------------------------------------------------------------------------------- /src/communication_managers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | add_subdirectory (iothub_communication_manager) 4 | -------------------------------------------------------------------------------- /src/diagnostics_component/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | add_subdirectory (diagnostics_async_helper) 4 | add_subdirectory (diagnostics_devicename) 5 | add_subdirectory (diagnostics_interface) 6 | add_subdirectory (diagnostics_workflow) 7 | add_subdirectory (utils) 8 | -------------------------------------------------------------------------------- /src/diagnostics_component/diagnostics_async_helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name diagnostics_async_helper) 4 | 5 | add_library (${target_name} STATIC src/diagnostics_async_helper.cpp) 6 | add_library (diagnostics_component::${target_name} ALIAS ${target_name}) 7 | 8 | target_include_directories (${target_name} PUBLIC inc) 9 | 10 | target_link_aziotsharedutil (${target_name} PRIVATE) 11 | 12 | target_link_libraries ( 13 | ${target_name} 14 | PUBLIC aduc::c_utils 15 | PRIVATE aduc::logging 16 | aduc::string_utils 17 | diagnostics_component::diagnostics_workflow 18 | diagnostic_utils::operation_id_utils) 19 | -------------------------------------------------------------------------------- /src/diagnostics_component/diagnostics_async_helper/inc/diagnostics_async_helper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file diagnostics_async_helper.h 3 | * @brief Header file for the asynchronous runner for the DiagnosticsWorkflow log upload 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #include 9 | #include 10 | 11 | #ifndef DIAGNOSTICS_ASYNC_HELPER_H 12 | # define DIAGNOSTICS_ASYNC_HELPER_H 13 | 14 | EXTERN_C_BEGIN 15 | 16 | typedef struct tagDiagnosticWorkflowData DiagnosticsWorkflowData; 17 | 18 | void DiagnosticsWorkflow_DiscoverAndUploadLogsAsync( 19 | const DiagnosticsWorkflowData* workflowData, const char* jsonString); 20 | 21 | EXTERN_C_END 22 | 23 | #endif // DIAGNOSTICS_ASYNC_HELPER_H 24 | -------------------------------------------------------------------------------- /src/diagnostics_component/diagnostics_devicename/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name diagnostics_devicename) 4 | 5 | add_library (${target_name} STATIC src/diagnostics_devicename.c) 6 | add_library (diagnostics_component::${target_name} ALIAS ${target_name}) 7 | 8 | target_include_directories (${target_name} PUBLIC inc) 9 | 10 | target_link_aziotsharedutil (${target_name} PRIVATE) 11 | 12 | target_link_libraries (${target_name} PUBLIC aduc::c_utils) 13 | -------------------------------------------------------------------------------- /src/diagnostics_component/diagnostics_interface/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name diagnostics_interface) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | 9 | add_library (${target_name} STATIC src/diagnostics_interface.c) 10 | add_library (diagnostics_component::${target_name} ALIAS ${target_name}) 11 | 12 | target_include_directories (${target_name} PUBLIC inc) 13 | 14 | target_compile_definitions (${target_name} 15 | PRIVATE DIAGNOSTICS_CONFIG_FILE_PATH="${DIAGNOSTICS_CONFIG_FILE_PATH}") 16 | 17 | target_link_iothub_client (${target_name} PUBLIC) 18 | 19 | find_package (Parson REQUIRED) 20 | 21 | target_link_libraries ( 22 | ${target_name} 23 | PUBLIC aduc::c_utils 24 | aduc::communication_abstraction 25 | diagnostics_component::diagnostics_async_helper 26 | diagnostics_component::diagnostics_workflow 27 | diagnostic_utils::diagnostics_config_utils 28 | Parson::parson 29 | PRIVATE aduc::d2c_messaging 30 | aduc::logging 31 | aduc::pnp_helper 32 | IotHubClient::iothub_client) 33 | 34 | target_link_libraries (${target_name} PRIVATE libaducpal) 35 | -------------------------------------------------------------------------------- /src/diagnostics_component/diagnostics_workflow/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name diagnostics_workflow) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | 9 | add_library (${target_name} STATIC src/diagnostics_workflow.c src/diagnostics_result.c) 10 | add_library (diagnostics_component::${target_name} ALIAS ${target_name}) 11 | 12 | target_include_directories (${target_name} PUBLIC inc) 13 | 14 | find_package (Parson REQUIRED) 15 | 16 | target_link_aziotsharedutil (${target_name} PRIVATE) 17 | 18 | if (NOT WIN32) 19 | target_link_libraries (${target_name} PRIVATE diagnostic_utils::file_upload_utility) 20 | endif () 21 | 22 | target_link_libraries ( 23 | ${target_name} 24 | PUBLIC aduc::c_utils diagnostics_component::diagnostics_async_helper 25 | diagnostic_utils::diagnostics_config_utils 26 | PRIVATE aduc::logging 27 | aduc::system_utils 28 | diagnostics_component::diagnostics_interface 29 | diagnostics_component::diagnostics_devicename 30 | diagnostic_utils::file_info_utils 31 | diagnostic_utils::operation_id_utils 32 | Parson::parson 33 | parson_json_utils) 34 | -------------------------------------------------------------------------------- /src/diagnostics_component/diagnostics_workflow/inc/diagnostics_workflow.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file diagnostics_workflow.h 3 | * @brief Header for functions handling the Diagnostics Log Upload workflow 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef DIAGNOSTICS_WORKFLOW_H 9 | #define DIAGNOSTICS_WORKFLOW_H 10 | 11 | #include 12 | #include 13 | 14 | EXTERN_C_BEGIN 15 | 16 | /** 17 | * @brief Uploads the diagnostic logs described by @p workflowData 18 | * @param workflowData the workflowData structure describing the log components 19 | * @param jsonString the string from the diagnostics_interface describing where to upload the logs 20 | */ 21 | void DiagnosticsWorkflow_DiscoverAndUploadLogs(const DiagnosticsWorkflowData* workflowData, const char* jsonString); 22 | 23 | EXTERN_C_END 24 | 25 | #endif // DIAGNOSTICS_WORKFLOW_H 26 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | add_subdirectory (config_utils) 4 | add_subdirectory (file_info_utils) 5 | add_subdirectory (file_upload_utils) 6 | add_subdirectory (operation_id_utils) 7 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/config_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name diagnostics_config_utils) 2 | 3 | add_library (${target_name} STATIC) 4 | add_library (diagnostic_utils::${target_name} ALIAS ${target_name}) 5 | 6 | target_include_directories (${target_name} PUBLIC inc) 7 | target_sources (${target_name} PRIVATE src/diagnostics_config_utils.c) 8 | 9 | find_package (Parson REQUIRED) 10 | 11 | target_link_aziotsharedutil (${target_name} PRIVATE) 12 | 13 | target_link_libraries ( 14 | ${target_name} 15 | PUBLIC aduc::c_utils Parson::parson 16 | PRIVATE aduc::parson_json_utils aduc::logging) 17 | 18 | if (ADUC_BUILD_UNIT_TESTS) 19 | add_subdirectory (tests) 20 | endif () 21 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/config_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (diagnostics_config_utils_ut) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | set (sources diagnostics_config_utils_ut.cpp) 9 | 10 | find_package (Catch2 REQUIRED) 11 | find_package (Parson REQUIRED) 12 | 13 | add_executable (${PROJECT_NAME} ${sources}) 14 | 15 | target_compile_definitions (${PROJECT_NAME} PRIVATE ADUC_LOG_FOLDER="${ADUC_LOG_FOLDER}") 16 | 17 | target_link_libraries (${PROJECT_NAME} PRIVATE diagnostic_utils::diagnostics_config_utils 18 | Catch2::Catch2WithMain Parson::parson) 19 | 20 | target_link_aziotsharedutil (${PROJECT_NAME} PRIVATE) 21 | 22 | include (CTest) 23 | include (Catch) 24 | catch_discover_tests (${PROJECT_NAME}) 25 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/file_info_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name file_info_utils) 4 | 5 | add_library (${target_name} STATIC src/file_info_utils.c) 6 | add_library (diagnostic_utils::${target_name} ALIAS ${target_name}) 7 | 8 | target_include_directories (${target_name} PUBLIC inc) 9 | 10 | find_package (Parson REQUIRED) 11 | 12 | target_link_aziotsharedutil (${target_name} PRIVATE) 13 | 14 | target_link_libraries ( 15 | ${target_name} 16 | PUBLIC aduc::c_utils 17 | PRIVATE aduc::logging) 18 | 19 | target_link_libraries (${target_name} PRIVATE libaducpal) 20 | 21 | if (ADUC_BUILD_UNIT_TESTS) 22 | # target_link_umock_c (${target_name} PRIVATE) 23 | add_subdirectory (tests) 24 | endif () 25 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/file_info_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (file_info_utils_ut) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources file_info_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${PROJECT_NAME} ${sources}) 15 | 16 | target_link_aziotsharedutil (${PROJECT_NAME} PRIVATE) 17 | 18 | # Windows needs all EXEs to have links to all potential libraries so this is included here 19 | if (WIN32) 20 | target_link_dosdk (${PROJECT_NAME} PRIVATE) 21 | endif () 22 | 23 | target_link_libraries ( 24 | ${PROJECT_NAME} PRIVATE aduc::jws_utils aduc::crypto_utils aduc::string_utils 25 | diagnostic_utils::file_info_utils Catch2::Catch2WithMain) 26 | 27 | include (CTest) 28 | include (Catch) 29 | catch_discover_tests (${PROJECT_NAME}) 30 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/file_upload_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.13) 2 | 3 | include (agentRules) 4 | 5 | set (target_name file_upload_utility) 6 | 7 | add_library (${target_name} STATIC src/file_upload_utility.cpp src/blob_storage_helper.cpp 8 | src/blob_storage_helper.hpp) 9 | add_library (diagnostic_utils::${target_name} ALIAS ${target_name}) 10 | 11 | target_link_aziotsharedutil (${target_name} PUBLIC) 12 | 13 | find_package (azure-storage-blobs-cpp CONFIG REQUIRED) 14 | 15 | include (agentRules) 16 | 17 | include (find_curl_and_import_libcurl) 18 | 19 | find_curl_and_import_libcurl () 20 | 21 | target_include_directories (${target_name} PUBLIC inc) 22 | 23 | target_link_libraries (${target_name} PRIVATE aduc::c_utils aduc::exception_utils 24 | Azure::azure-storage-blobs CURL::libcurl) 25 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/file_upload_utils/inc/file_upload_utility.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file file_upload_utility.h 3 | * @brief Defines the interface for interacting with Azure Blob Storage and uploading files 4 | * 5 | * @copyright Copyright (c) Microsoft Corp. 6 | */ 7 | #ifndef FILE_UPLOAD_UTILITY_H 8 | #define FILE_UPLOAD_UTILITY_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | EXTERN_C_BEGIN 17 | 18 | /** 19 | * @brief Struct that contains the information for uploading a set of blobs to Azure Blob Storage 20 | */ 21 | typedef struct tagBlobStorageInfo 22 | { 23 | STRING_HANDLE 24 | virtualDirectoryPath; //!< Virtual hierarchy for the blobs 25 | STRING_HANDLE storageSasCredential; //!< Combined SAS URI and SAS Token for connecting to storage 26 | } BlobStorageInfo; 27 | 28 | bool FileUploadUtility_UploadFilesToContainer( 29 | const BlobStorageInfo* blobInfo, VECTOR_HANDLE fileNames, const char* directoryPath); 30 | 31 | EXTERN_C_END 32 | 33 | #endif // FILE_UPLOAD_UTILITY_H 34 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/file_upload_utils/src/blob_storage_helper.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file blob_storage_helper.hpp 3 | * @brief Implements the interface for interacting with Azure Blob Storage 4 | * 5 | * @copyright Copyright (c) Microsoft Corp. 6 | */ 7 | #include "file_upload_utility.h" 8 | 9 | // Note: This is just the top level portion 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifndef BLOB_STORAGE_HELPER_HPP 16 | # define BLOB_STORAGE_HELPER_HPP 17 | class AzureBlobStorageHelper 18 | { 19 | private: 20 | std::unique_ptr 21 | client; // !< client connection object used for uploading files and creating containers 22 | 23 | std::string CreatePathFromFileAndDirectory(const std::string& fileName, const std::string& directoryPath); 24 | 25 | public: 26 | AzureBlobStorageHelper(const BlobStorageInfo& blobInfo); 27 | 28 | bool UploadFilesToContainer( 29 | const VECTOR_HANDLE fileNames, const std::string& directoryPath, const std::string& virtualDirectory); 30 | 31 | ~AzureBlobStorageHelper() = default; 32 | }; 33 | 34 | #endif // BLOB_STORAGE_HELPER_HPP 35 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/operation_id_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name operation_id_utils) 4 | 5 | add_library (${target_name} STATIC src/operation_id_utils.c) 6 | add_library (diagnostic_utils::${target_name} ALIAS ${target_name}) 7 | 8 | target_include_directories (${target_name} PUBLIC inc) 9 | 10 | target_compile_definitions ( 11 | ${target_name} 12 | PRIVATE DIAGNOSTICS_COMPLETED_OPERATION_FILE_PATH="${DIAGNOSTICS_COMPLETED_OPERATION_FILE_PATH}" 13 | ) 14 | 15 | find_package (Parson REQUIRED) 16 | 17 | target_link_aziotsharedutil (${target_name} PUBLIC) 18 | 19 | target_link_libraries ( 20 | ${target_name} 21 | PUBLIC aduc::c_utils Parson::parson 22 | PRIVATE aduc::logging 23 | aduc::system_utils 24 | aduc::parson_json_utils 25 | diagnostics_component::diagnostics_interface) 26 | 27 | target_link_libraries (${target_name} PRIVATE libaducpal) 28 | -------------------------------------------------------------------------------- /src/diagnostics_component/utils/operation_id_utils/inc/operation_id_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file operation_id_utils.h 3 | * @brief Header file for utilities for operations such as storing the operation id or checking if the operation has already been completed 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifndef OPERATION_ID_UTILS_H 15 | # define OPERATION_ID_UTILS_H 16 | 17 | EXTERN_C_BEGIN 18 | 19 | bool OperationIdUtils_OperationIsComplete(const char* serviceMsg); 20 | 21 | bool OperationIdUtils_StoreCompletedOperationId(const char* operationId); 22 | 23 | EXTERN_C_END 24 | 25 | #endif // OPERATION_ID_UTILS_H 26 | -------------------------------------------------------------------------------- /src/docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package (Doxygen REQUIRED) 2 | if (DOXYGEN_FOUND) 3 | set (DOXYGEN_PROJECT_NAME "Device Update for IotHub") 4 | set (DOXYGEN_PROJECT_NUMBER "1.0.2") 5 | set ( 6 | DOXYGEN_PROJECT_BRIEF 7 | "Device Update for IoTHub delivers client update from the Device Update for IotHub service." 8 | ) 9 | set (DOXYGEN_EXCLUDE_PATTERNS "*/src/deliveryoptimization/* */tests/* *.sh *.ps1 *.cpp *.c") 10 | 11 | set (DOXYGEN_GENERATE_HTML YES) 12 | set (DOXYGEN_GENERATE_MAN YES) 13 | doxygen_add_docs (doxygen_docs ${PROJECT_SOURCE_DIR} ALL COMMENT "Generating doxygen") 14 | endif () 15 | -------------------------------------------------------------------------------- /src/extensions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (content_downloaders) 2 | if (NOT WIN32) 3 | add_subdirectory (component_enumerators/examples/contoso_component_enumerator) 4 | endif () 5 | add_subdirectory (download_handlers) 6 | add_subdirectory (extension_manager) 7 | add_subdirectory (step_handlers) 8 | add_subdirectory (update_manifest_handlers) 9 | add_subdirectory (shared_lib) 10 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name contoso_component_enumerator) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} MODULE contoso_component_enumerator.cpp) 8 | 9 | find_package (Parson REQUIRED) 10 | 11 | add_library (aduc::${target_name} ALIAS ${target_name}) 12 | 13 | target_include_directories (${target_name} PUBLIC ${ADU_EXTENSION_INCLUDES} ${ADU_EXPORT_INCLUDES}) 14 | 15 | target_link_libraries (${target_name} PUBLIC Parson::parson aduc::contract_utils) 16 | 17 | install (TARGETS ${target_name} LIBRARY DESTINATION ${ADUC_EXTENSIONS_INSTALL_FOLDER}) 18 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/bootfs/diskimage.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "description": "This is a fake disk image." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/cameras/contoso-camera-serial-00000/firmware.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/cameras/contoso-camera-serial-00001/firmware.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/hostfw/firmware.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "description": "This is a fake device firmware." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/motors/contoso-motor-serial-00000/firmware.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/motors/contoso-motor-serial-00001/firmware.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/motors/contoso-motor-serial-00002/firmware.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/rootfs/diskimage.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "description": "This is a fake disk image." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/demo-devices/contoso-devices/vacuum-1/unplugged-streamers/contoso-steamer-serial-00000/firmware.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/APT/apt-manifest-1.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"apt-update-test", 3 | "version":"1.0", 4 | "packages":[ 5 | { 6 | "name":"libcurl4-doc" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/APT/apt-manifest-4.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"apt-update-test", 3 | "version":"4.0", 4 | "packages":[ 5 | { 6 | "name":"libcurl4-doc" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/APT/apt-manifest-tree-1.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"apt-update-test-tree", 3 | "version":"1.0", 4 | "packages":[ 5 | { 6 | "name":"tree" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/APT/bad-apt-manifest-1.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"apt-update-test", 3 | "version":"1.0" 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/camera-firmware-1.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/camera-firmware-2.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.1", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/camera-firmware-2.2.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.2", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/camera-firmware-3.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "3.0", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/contoso-vacuum-apt-1.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contoso-vacuum-apt", 3 | "version" : "1.0", 4 | "packages": [ 5 | { 6 | "name" : "libcurl4-doc" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/host-firmware-1.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/host-firmware-1.2.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.2", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/host-firmware-1.3.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.3", 3 | "description": "This component is generated for testing purposes." 4 | } 5 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/motor-firmware-1.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/motor-firmware-1.2.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.2", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/motor-firmware-1.3.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.3", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/motor-firmware-1.4.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.4", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/motor-firmware-1.5.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.5", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/motor-firmware-3.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "3.1", 3 | "description": "This component is generated for testing purposes.", 4 | "properties": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/steamer-firmware-1.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "manufacturer": "contoso", 3 | "model": "virtual-steamer", 4 | "version": "1.0", 5 | "description": "This component is generated for testing purposes." 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/sample-updates/data-files/steamer-firmware-2.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "manufacturer": "contoso", 3 | "model": "virtual-steamer", 4 | "version": "2.0", 5 | "description": "This component is generated for testing purposes." 6 | } 7 | -------------------------------------------------------------------------------- /src/extensions/component_enumerators/examples/contoso_component_enumerator/demo/tools/add-packages-microsoft-com.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Microsoft Corporation. 3 | # Licensed under the MIT License. 4 | 5 | curl https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb > ~/packages-microsoft-prod.deb 6 | 7 | sudo apt-get install ~/packages-microsoft-prod.deb 8 | 9 | sudo apt-get update 10 | -------------------------------------------------------------------------------- /src/extensions/content_downloaders/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | add_subdirectory (curl_downloader) 4 | add_subdirectory (deliveryoptimization_downloader) 5 | -------------------------------------------------------------------------------- /src/extensions/content_downloaders/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/src/extensions/content_downloaders/README.md -------------------------------------------------------------------------------- /src/extensions/content_downloaders/curl_downloader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name curl_content_downloader) 2 | include (agentRules) 3 | 4 | compileasc99 () 5 | 6 | add_library (${target_name} MODULE) 7 | add_library (aduc::${target_name} ALIAS ${target_name}) 8 | 9 | target_sources ( 10 | ${target_name} PRIVATE curl_content_downloader.cpp curl_content_downloader.EXPORTS.cpp 11 | curl_content_downloader.h) 12 | 13 | target_include_directories (${target_name} PUBLIC ${ADU_EXTENSION_INCLUDES} ${ADU_EXPORT_INCLUDES}) 14 | 15 | target_link_libraries ( 16 | ${target_name} 17 | PRIVATE aduc::contract_utils 18 | aduc::hash_utils 19 | aduc::logging 20 | aduc::process_utils) 21 | 22 | target_link_libraries (${target_name} PRIVATE libaducpal) 23 | 24 | install (TARGETS ${target_name} LIBRARY DESTINATION ${ADUC_EXTENSIONS_INSTALL_FOLDER}) 25 | -------------------------------------------------------------------------------- /src/extensions/content_downloaders/curl_downloader/curl_content_downloader.h: -------------------------------------------------------------------------------- 1 | 2 | #include // for ADUC_Result 3 | #include // for ADUC_DownloadProgressCallback 4 | #include // for ADUC_FileEntity 5 | 6 | ADUC_Result Download_curl( 7 | const ADUC_FileEntity* entity, 8 | const char* workflowId, 9 | const char* workFolder, 10 | unsigned int timeoutInSeconds, 11 | ADUC_DownloadProgressCallback downloadProgressCallback); 12 | -------------------------------------------------------------------------------- /src/extensions/content_downloaders/deliveryoptimization_downloader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name deliveryoptimization_content_downloader) 2 | include (agentRules) 3 | 4 | compileasc99 () 5 | 6 | add_library (${target_name} MODULE) 7 | add_library (aduc::${target_name} ALIAS ${target_name}) 8 | 9 | target_sources ( 10 | ${target_name} 11 | PRIVATE deliveryoptimization_content_downloader.cpp 12 | deliveryoptimization_content_downloader.EXPORTS.cpp 13 | deliveryoptimization_content_downloader.h) 14 | 15 | target_include_directories (${target_name} PUBLIC ${ADU_EXTENSION_INCLUDES} ${ADUC_EXPORT_INCLUDES}) 16 | 17 | target_link_aziotsharedutil (${target_name} PRIVATE) 18 | target_link_dosdk (${target_name} PRIVATE) 19 | 20 | target_link_libraries (${target_name} PRIVATE aduc::c_utils aduc::contract_utils aduc::hash_utils 21 | aduc::logging aduc::process_utils aduc::string_utils) 22 | 23 | if (WIN32) 24 | target_link_libraries (${target_name} PRIVATE libaducpal) 25 | else () 26 | target_link_libraries (${target_name} PRIVATE Microsoft::deliveryoptimization atomic) 27 | endif () 28 | 29 | install (TARGETS ${target_name} LIBRARY DESTINATION ${ADUC_EXTENSIONS_INSTALL_FOLDER}) 30 | -------------------------------------------------------------------------------- /src/extensions/content_downloaders/deliveryoptimization_downloader/deliveryoptimization_content_downloader.h: -------------------------------------------------------------------------------- 1 | #ifndef DELIVERYOPTIMIZATION_CONTENT_DOWNLOADER_HELPERS_H 2 | #define DELIVERYOPTIMIZATION_CONTENT_DOWNLOADER_HELPERS_H 3 | 4 | #include // for ADUC_Result 5 | #include // for ADUC_DownloadProgressCallback 6 | #include // for ADUC_FileEntity 7 | 8 | ADUC_Result do_download( 9 | const ADUC_FileEntity* entity, 10 | const char* workflowId, 11 | const char* workFolder, 12 | unsigned int timeoutInSeconds, 13 | ADUC_DownloadProgressCallback downloadProgressCallback); 14 | 15 | #endif // DELIVERYOPTIMIZATION_CONTENT_DOWNLOADER_HELPERS_H 16 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (download_handler_factory) 2 | add_subdirectory (download_handler_plugin) 3 | add_subdirectory (plugin_examples) 4 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/download_handler_factory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name download_handler_factory) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC "") 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | # Turn -fPIC on, in order to use this library in a shared library. 11 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 12 | 13 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 14 | 15 | target_sources (${target_name} PRIVATE src/download_handler_factory.cpp) 16 | 17 | target_link_libraries ( 18 | ${target_name} 19 | PRIVATE aduc::adu_types 20 | aduc::c_utils 21 | aduc::download_handler_plugin 22 | aduc::entity_utils 23 | aduc::extension_utils 24 | aduc::hash_utils 25 | aduc::logging 26 | aduc::parser_utils 27 | aduc::shared_lib) 28 | 29 | target_compile_definitions ( 30 | ${target_name} 31 | PRIVATE ADUC_DOWNLOAD_HANDLER_REG_FILENAME="${ADUC_DOWNLOAD_HANDLER_REG_FILENAME}") 32 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/download_handler_factory/inc/aduc/download_handler_factory.h: -------------------------------------------------------------------------------- 1 | #ifndef DOWNLOAD_HANDLER_FACTORY_H 2 | #define DOWNLOAD_HANDLER_FACTORY_H 3 | 4 | typedef void* DownloadHandlerHandle; 5 | 6 | /** 7 | * @brief Gets the plugin handle for a downloadHandlerId, which may involve loading the plugin. 8 | * 9 | * @param downloadHandlerId The download handler id from the update metadata of an update payload file. 10 | * @return DownloadHandlerHandle The opaque handle to the download handler plugin. 11 | */ 12 | DownloadHandlerHandle ADUC_DownloadHandlerFactory_LoadDownloadHandler(const char* downloadHandlerId); 13 | 14 | #endif // DOWNLOAD_HANDLER_FACTORY_H 15 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/download_handler_plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name download_handler_plugin) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC) 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | # Turn -fPIC on, in order to use this library in a shared library. 11 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 12 | 13 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES} 14 | ${ADU_EXTENSION_INCLUDES}) 15 | 16 | target_sources (${target_name} PRIVATE src/download_handler_plugin.cpp) 17 | 18 | target_link_libraries ( 19 | ${target_name} 20 | PUBLIC aduc::adu_types 21 | aduc::contract_utils 22 | aduc::logging 23 | aduc::shared_lib) 24 | 25 | target_link_libraries (${target_name} PRIVATE libaducpal) 26 | 27 | target_compile_features (${target_name} PRIVATE cxx_lambdas cxx_uniform_initialization) 28 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/download_handler_plugin/inc/aduc/download_handler_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef DOWNLOAD_HANDLER_PLUGIN_H 2 | #define DOWNLOAD_HANDLER_PLUGIN_H 3 | 4 | #include // EXTERN_C_* 5 | #include // ADUC_Result 6 | #include // ADUC_FileEntity 7 | #include // ADUC_FileEntity 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef void* DownloadHandlerHandle; 12 | 13 | /** 14 | * @brief Called when the update workflow successfully completes. 15 | * In the case of Delta download handler plugin, it moves the file at the payloadFilePath to the cache. 16 | * 17 | * @param[in] handle The handle to the download handler. 18 | * @param[in] workflowHandle The workflow handle. 19 | * @return ADUC_Result The result. 20 | */ 21 | ADUC_Result ADUC_DownloadHandlerPlugin_OnUpdateWorkflowCompleted( 22 | const DownloadHandlerHandle handle, const ADUC_WorkflowHandle workflowHandle); 23 | 24 | EXTERN_C_END 25 | 26 | #endif // DOWNLOAD_HANDLER_PLUGIN_H 27 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT WIN32) 2 | add_subdirectory (microsoft_delta_download_handler) 3 | endif () 4 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/microsoft_delta_download_handler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (handler) 2 | add_subdirectory (source_update_cache) 3 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/microsoft_delta_download_handler/handler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (lib) 2 | add_subdirectory (plugin) 3 | add_subdirectory (utils) 4 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/microsoft_delta_download_handler/handler/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name microsoft-delta-download-handler) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC) 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | # Turn -fPIC on, in order to use this library in a shared library. 11 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 12 | 13 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 14 | 15 | target_sources (${target_name} PRIVATE src/microsoft_delta_download_handler.c) 16 | 17 | target_link_libraries ( 18 | ${target_name} 19 | PUBLIC aduc::adu_types 20 | PRIVATE aduc::c_utils 21 | aduc::microsoft_delta_download_handler_utils 22 | aduc::logging 23 | aduc::source_update_cache 24 | aduc::workflow_utils) 25 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/microsoft_delta_download_handler/handler/plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name microsoft_delta_download_handler) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} MODULE) 8 | 9 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 10 | 11 | target_sources (${target_name} PRIVATE src/microsoft_delta_download_handler_plugin.EXPORTS.c) 12 | 13 | target_link_libraries (${target_name} PRIVATE aduc::adu_types aduc::contract_utils 14 | aduc::microsoft-delta-download-handler aduc::logging) 15 | 16 | install (TARGETS ${target_name} LIBRARY DESTINATION ${ADUC_EXTENSIONS_INSTALL_FOLDER}) 17 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/microsoft_delta_download_handler/handler/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name microsoft_delta_download_handler_utils) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC "") 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | # Turn -fPIC on, in order to use this library in a shared library. 11 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 12 | 13 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 14 | 15 | target_sources (${target_name} PRIVATE src/microsoft_delta_download_handler_utils.c 16 | src/microsoft_delta_download_handler_utils.cpp) 17 | 18 | target_link_aziotsharedutil (${target_name} PUBLIC) 19 | 20 | target_link_libraries ( 21 | ${target_name} 22 | PUBLIC aduc::adu_types 23 | PRIVATE aduc::c_utils 24 | aduc::extension_manager 25 | aduc::logging 26 | aduc::parser_utils 27 | aduc::shared_lib 28 | aduc::source_update_cache 29 | aduc::workflow_utils) 30 | 31 | if (ADUC_BUILD_UNIT_TESTS) 32 | add_subdirectory (tests) 33 | endif () 34 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/microsoft_delta_download_handler/handler/utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (microsoft_delta_download_handler_util_unit_tests) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | find_package (Catch2 REQUIRED) 9 | 10 | add_executable (${PROJECT_NAME} "") 11 | 12 | target_sources (${PROJECT_NAME} PRIVATE microsoft_delta_download_handler_utils_ut.cpp) 13 | 14 | target_link_libraries ( 15 | ${PROJECT_NAME} 16 | PRIVATE aduc::adu_types 17 | aduc::microsoft_delta_download_handler_utils 18 | aduc::parser_utils 19 | aduc::workflow_utils 20 | Catch2::Catch2WithMain) 21 | 22 | include (CTest) 23 | include (Catch) 24 | catch_discover_tests (${PROJECT_NAME}) 25 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/microsoft_delta_download_handler/source_update_cache/inc/aduc/source_update_cache_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file source_update_cache.c 3 | * @brief The source update cache for delta download handler update payloads. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef SOURCE_UPDATE_CACHE_UTILS_H 10 | #define SOURCE_UPDATE_CACHE_UTILS_H 11 | 12 | #include // EXTERN_C_* 13 | #include // ADUC_Result 14 | #include // ADUC_WorkflowHandle 15 | #include // STRING_HANDLE 16 | #include // off_t 17 | 18 | EXTERN_C_BEGIN 19 | 20 | STRING_HANDLE ADUC_SourceUpdateCacheUtils_CreateSourceUpdateCachePath( 21 | const char* provider, const char* hash, const char* alg, const char* updateCacheBasePath); 22 | 23 | ADUC_Result ADUC_SourceUpdateCacheUtils_MoveToUpdateCache( 24 | const ADUC_WorkflowHandle workflowHandle, const char* updateCacheBasePath); 25 | 26 | int ADUC_SourceUpdateCacheUtils_PurgeOldestFromUpdateCache( 27 | const ADUC_WorkflowHandle workflowHandle, off_t totalSize, const char* updateCacheBasePath); 28 | 29 | EXTERN_C_END 30 | 31 | #endif // SOURCE_UPDATE_CACHE_UTILS_H 32 | -------------------------------------------------------------------------------- /src/extensions/download_handlers/plugin_examples/microsoft_delta_download_handler/source_update_cache/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (source_update_cache_unit_tests) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | find_package (Catch2 REQUIRED) 9 | find_package (Parson REQUIRED) 10 | 11 | add_executable (${PROJECT_NAME} "") 12 | 13 | target_include_directories (${PROJECT_NAME} PRIVATE inc ${ADUC_EXPORT_INCLUDES}) 14 | 15 | target_sources (${PROJECT_NAME} PRIVATE source_update_cache_utils_ut.cpp) 16 | 17 | target_link_libraries ( 18 | ${PROJECT_NAME} 19 | PRIVATE aduc::file_utils 20 | aduc::source_update_cache 21 | aduc::test_utils 22 | aduc::system_utils 23 | aduc::workflow_utils 24 | Catch2::Catch2WithMain 25 | Parson::parson) 26 | 27 | target_link_libraries (${PROJECT_NAME} PRIVATE libaducpal) 28 | 29 | target_compile_definitions ( 30 | ${PROJECT_NAME} 31 | PRIVATE 32 | ADUC_DELTA_DOWNLOAD_HANDLER_SOURCE_UPDATE_CACHE_DIR="${ADUC_DELTA_DOWNLOAD_HANDLER_SOURCE_UPDATE_CACHE_DIR}" 33 | ) 34 | 35 | include (CTest) 36 | include (Catch) 37 | catch_discover_tests (${PROJECT_NAME}) 38 | -------------------------------------------------------------------------------- /src/extensions/extension_manager/inc/aduc/extension_manager_download_options.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUC_EXTENSION_MANAGER_DOWNLOAD_OPTIONS_H 2 | #define ADUC_EXTENSION_MANAGER_DOWNLOAD_OPTIONS_H 3 | 4 | #include 5 | 6 | // Default Content Downloader Download Timeout of 8 hours. 7 | #define CONTENT_DOWNLOADER_MAX_TIMEOUT_IN_MINUTES_DEFAULT (8 * 60) 8 | 9 | typedef struct tagADUC_ExtensionManager_Download_Options 10 | { 11 | unsigned int 12 | timeoutInMinutes; /**< The maximum number of minutes the content downloader should wait for the download to complete(whilst the network interface stays up). */ 13 | } ExtensionManager_Download_Options; 14 | 15 | EXTERN_C_BEGIN 16 | extern ExtensionManager_Download_Options Default_ExtensionManager_Download_Options; 17 | EXTERN_C_END 18 | 19 | #endif // #define ADUC_EXTENSION_MANAGER_DOWNLOAD_OPTIONS_H 20 | -------------------------------------------------------------------------------- /src/extensions/extension_manager/inc/aduc/extension_manager_helper.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file extension_manager_helper.hpp 3 | * @brief Headers for ExtensionManager helpers. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef ADUC_EXTENSION_MANAGER_HELPER_HPP 10 | #define ADUC_EXTENSION_MANAGER_HELPER_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | using ADUC_WorkflowHandle = void*; 18 | class DownloadHandlerPlugin; 19 | 20 | EXTERN_C_BEGIN 21 | 22 | ADUC_Result ProcessDownloadHandlerExtensibility( 23 | ADUC_WorkflowHandle workflowHandle, const ADUC_FileEntity* entity, const char* targetUpdateFilePath) noexcept; 24 | 25 | unsigned int GetDownloadTimeoutInMinutes(const ExtensionManager_Download_Options* downloadOptions) noexcept; 26 | 27 | EXTERN_C_END 28 | 29 | #endif // ADUC_EXTENSION_MANAGER_HELPER_HPP 30 | -------------------------------------------------------------------------------- /src/extensions/extension_manager/tests/testdata/extension_manager/pnpMsg.json: -------------------------------------------------------------------------------- 1 | { 2 | "workflow": { 3 | "action": 3, 4 | "id": "92d4d0d6-8211-41c2-8a1d-0ed5d81d2441" 5 | }, 6 | "updateManifest": "UPDATE_MANIFEST", 7 | "updateManifestSignature": "invalid_signature", 8 | "fileUrls": { 9 | "f722b9ffefaaac577": "dntp://example.com:1337/mock_update_payload.txt" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/extensions/extension_manager/tests/testdata/extension_manager/testUpdateManifest.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "compatibility": [ 4 | { 5 | "deviceManufacturer": "man", 6 | "deviceModel": "mod" 7 | } 8 | ], 9 | "createdDateTime": "2023-05-04T12:22:37.2627901Z", 10 | "files": { 11 | "f722b9ffefaaac577": { 12 | "fileName": "mock_update_payload.txt", 13 | "hashes": { 14 | "sha256": "LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=" 15 | }, 16 | "sizeInBytes": 5, 17 | "properties": { 18 | } 19 | } 20 | }, 21 | "instructions": { 22 | "steps": [ 23 | { 24 | "files": [ 25 | "f722b9ffefaaac577" 26 | ], 27 | "handler": "microsoft/foo:1", 28 | "handlerProperties": { 29 | "installedCriteria": "0.1" 30 | } 31 | } 32 | ] 33 | }, 34 | "manifestVersion": "5", 35 | "updateId": { 36 | "name": "update", 37 | "provider": "prov1", 38 | "version": "0.1" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/extensions/inc/aduc/content_downloader_extension.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file content_downloader_extension.hpp 3 | * @brief Defines APIs for Device Update Content Downloader. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADUC_CONTENT_DOWNLOADER_EXTENSION_HPP 9 | #define ADUC_CONTENT_DOWNLOADER_EXTENSION_HPP 10 | 11 | #include "aduc/adu_core_exports.h" 12 | 13 | EXTERN_C_BEGIN 14 | 15 | typedef ADUC_Result (*InitializeProc)(const char* initializeData); 16 | 17 | typedef ADUC_Result (*DownloadProc)( 18 | const ADUC_FileEntity* entity, 19 | const char* workflowId, 20 | const char* workFolder, 21 | unsigned int timeoutInSeconds, 22 | ADUC_DownloadProgressCallback downloadProgressCallback); 23 | 24 | EXTERN_C_END 25 | 26 | #endif // ADUC_CONTENT_DOWNLOADER_EXTENSION_HPP 27 | -------------------------------------------------------------------------------- /src/extensions/inc/aduc/exports/extension_content_handler_export_symbols.h: -------------------------------------------------------------------------------- 1 | #ifndef EXTENSION_CONTENT_HANDLER_EXPORT_SYMBOLS 2 | #define EXTENSION_CONTENT_HANDLER_EXPORT_SYMBOLS 3 | 4 | #include // for GetContractInfo__EXPORT_SYMBOL 5 | 6 | // 7 | // Step Handler Extension export V1 symbols. 8 | // These are the V1.0 symbols that must be implemented by step handlers. 9 | // 10 | 11 | /** 12 | * @brief GetContractInfo - Gets the extension contract info that the extension implements. 13 | * @param[out] contractInfo The output parameter the contract info. 14 | * @returns ADUC_Result The result of the call. 15 | * @details ADUC_Result GetContractInfo(ADUC_ExtensionContractInfo* contractInfo); 16 | */ 17 | #define CONTENT_HANDLER__GetContractInfo__EXPORT_SYMBOL GetContractInfo__EXPORT_SYMBOL 18 | 19 | /** 20 | * @brief Instantiates a Step Handler. 21 | * @return ContentHandler* The created instance. 22 | * @details ContentHandler* CreateUpdateContentHandlerExtension(ADUC_LOG_SEVERITY logLevel) 23 | */ 24 | #define CONTENT_HANDLER__CreateUpdateContentHandlerExtension__EXPORT_SYMBOL "CreateUpdateContentHandlerExtension" 25 | 26 | #endif // EXTENSION_CONTENT_HANDLER_EXPORT_SYMBOLS 27 | -------------------------------------------------------------------------------- /src/extensions/inc/aduc/exports/extension_export_symbols.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file extension_export_symbols.h 3 | * @brief The common function export symbols used by specific extension export symbols headers. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef EXTENSION_EXPORT_SYMBOLS_H 10 | #define EXTENSION_EXPORT_SYMBOLS_H 11 | 12 | #include "aduc/exports/extension_component_enumerator_export_symbols.h" 13 | #include "aduc/exports/extension_content_downloader_export_symbols.h" 14 | #include "aduc/exports/extension_content_handler_export_symbols.h" 15 | #include "aduc/exports/extension_download_handler_export_symbols.h" 16 | 17 | #endif // EXTENSION_EXPORT_SYMBOLS_H 18 | -------------------------------------------------------------------------------- /src/extensions/shared_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name shared_lib) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC "") 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | # Turn -fPIC on, in order to use this library in a shared library. 11 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 12 | 13 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 14 | 15 | target_sources (${target_name} PRIVATE src/shared_lib.cpp inc/aduc/plugin_call_helper.hpp) 16 | 17 | target_link_libraries (${target_name} PRIVATE aduc::hash_utils ${CMAKE_DL_LIBS}) 18 | 19 | target_link_libraries (${target_name} PRIVATE libaducpal) 20 | -------------------------------------------------------------------------------- /src/extensions/shared_lib/inc/aduc/plugin_exception.hpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file plugin_exception.hpp 4 | * @brief header for aduc plug exception thrown for issues with plugin/shared lib. 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | namespace aduc 13 | { 14 | class PluginException : public std::runtime_error 15 | { 16 | std::string export_symbol; 17 | 18 | public: 19 | /** 20 | * @brief default constructor for PluginException 21 | * @param msg message to set the runtime_error to 22 | * @param symbol the string representation of the exception's symbol 23 | */ 24 | PluginException(const std::string& msg, const std::string symbol) : 25 | std::runtime_error{ msg }, export_symbol{ symbol } 26 | { 27 | } 28 | 29 | /** 30 | * @brief Getter for the export_symbol member variable 31 | * @returns the string representation of the export_symbol 32 | */ 33 | const std::string& Symbol() const 34 | { 35 | return export_symbol; 36 | } 37 | }; 38 | 39 | } // namespace aduc 40 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/apt_handler/README.md: -------------------------------------------------------------------------------- 1 | # APT Update Handler 2 | 3 | The **APT Update Handler** enables the device to support the **package-based** updates. 4 | 5 | Package-based updates are targeted updates that alter only a specific component or application on the device. They use an APT manifest which provides the Device Update Agent with the information it needs to download and install the packages specified in the APT Manifest file (as well as their dependencies) from a designated repository. 6 | 7 | ## APT Manifest 8 | 9 | ### Schema 10 | 11 | ````json 12 | { 13 | "name": "", 14 | "version": "", 15 | "packages": [ 16 | { 17 | "name": "", 18 | "version": "" 19 | } 20 | ] 21 | } 22 | ```` 23 | 24 | ### Example 25 | 26 | ````json 27 | { 28 | "name":"tree-apt-manifest", 29 | "version":"1.0", 30 | "packages":[ 31 | { 32 | "name":"tree", 33 | "version":"1.7.0-5" 34 | } 35 | ] 36 | } 37 | ```` 38 | 39 | For more details, see [Device Update APT Manifest](https://docs.microsoft.com/en-us/azure/iot-hub-device-update/device-update-apt-manifest) 40 | 41 | More example APT manifest files can be found [here](../../../docs/tutorials) 42 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/apt_handler/tests/sample_apt_manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "du-agent-update", 3 | "version": "0.7.0", 4 | "packages": [ 5 | { 6 | "name": "deviceupdate-agent", 7 | "version": "0.7.0~public~preview" 8 | } 9 | ], 10 | "agentRestartRequired": true 11 | } 12 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/script_handler/tests/testdata/script_handler_test_config/du-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": "1.0", 3 | "aduShellTrustedUsers": [ 4 | "adu" 5 | ], 6 | "manufacturer": "contoso", 7 | "model": "espresso-v1", 8 | "agents": [ 9 | { 10 | "name": "main", 11 | "runas": "adu", 12 | "connectionSource": { 13 | "connectionType": "string", 14 | "connectionData": "HostName=adu-client-test-hub.azure-devices.net;DeviceId=contoso-espresso-v1-1;SharedAccessKey=000000000000000000000000000000=" 15 | }, 16 | "manufacturer": "contoso", 17 | "model": "espresso-v1" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/simulator_handler/README.md: -------------------------------------------------------------------------------- 1 | # Simulator Update Handler 2 | 3 | This handler can be use for demonstrations and testing purposes. 4 | 5 | The handler allow you specify an update result codes for any phase of the agent workflow. 6 | 7 | ## Example usages 8 | 9 | - Simulate file download success or failure. 10 | - Simulate `isInstalled()` success or failure. 11 | - Simulate overall update success or failure. 12 | 13 | See [how to simulator update result](../../../docs/agent-reference/how-to-simulate-update-result.md) for more details. 14 | 15 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/adu-yocto-ab-rootfs-update/payloads/adu-version: -------------------------------------------------------------------------------- 1 | 8.0.1.0001 2 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/adu-yocto-ab-rootfs-update/payloads/my-update.swu: -------------------------------------------------------------------------------- 1 | [PLACEHOLDER UPDATE FILE - REPLACE THIS FILE WITH YOUR OWN] 2 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/adu-yocto-ab-rootfs-update/sample_swupdate_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "--log-file" : "/adu/logs/swupdate.log", 3 | "--public-key-file" : "/adukey/pubic.pem", 4 | "--software-version-file" : "/etc/adu/adu-version" 5 | } 6 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/swupdate_filecopy/README.md: -------------------------------------------------------------------------------- 1 | # SWUpdate Test 1 2 | 3 | ## Build .SWU file 4 | 5 | To produce an image, a script like this can be used: 6 | 7 | Example of sw-description that contains preinstall script 8 | 9 | ```txt 10 | CONTAINER_VER="1.0" 11 | PRODUCT_NAME="du-agent-swupdate-filecopy-test-1" 12 | FILES="sw-description preinst.sh mock-update-for-file-copy-test-1.txt" 13 | for i in $FILES;do 14 | echo $i;done | cpio -ov -H crc > ${PRODUCT_NAME}_${CONTAINER_VER}.swu 15 | ``` 16 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/swupdate_filecopy/installed-criteria.txt: -------------------------------------------------------------------------------- 1 | This is swupdate filecopy test version 1.0 2 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/swupdate_filecopy/mock-update-for-file-copy-test-1.txt: -------------------------------------------------------------------------------- 1 | This is swupdate filecopy test version 1.0 2 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/swupdate_filecopy/preinst.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p /tmp/adu/testdata/test-device/vacuum-1/data/ 3 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/swupdate_filecopy/sw-description: -------------------------------------------------------------------------------- 1 | software= 2 | { 3 | version="0.1.0"; 4 | description="Install /tmp/adu/testdata/test-device/vacuum-1/data/mock-update-for-file-copy-test-1.txt"; 5 | hardware-compatibility: ["1.0"]; 6 | 7 | files: ( 8 | { 9 | filename="mock-update-for-file-copy-test-1.txt"; 10 | path="/tmp/adu/testdata/test-device/vacuum-1/data/mock-update-for-file-copy-test-1.txt"; 11 | } 12 | ); 13 | 14 | scripts : ( 15 | { 16 | filename = "preinst.sh"; 17 | type = "preinstall"; 18 | } 19 | ); 20 | }; 21 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/swupdate_handler_v2/tests/testdata/swupdate_handler_v2_test_config/du-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": "1.0", 3 | "aduShellTrustedUsers": [ 4 | "adu" 5 | ], 6 | "manufacturer": "contoso", 7 | "model": "espresso-v1", 8 | "agents": [ 9 | { 10 | "name": "main", 11 | "runas": "adu", 12 | "connectionSource": { 13 | "connectionType": "string", 14 | "connectionData": "HostName=adu-client-test-hub.azure-devices.net;DeviceId=contoso-espresso-v1-1;SharedAccessKey=000000000000000000000000000000=" 15 | }, 16 | "manufacturer": "contoso", 17 | "model": "espresso-v1" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/README.md: -------------------------------------------------------------------------------- 1 | # WIM Handler 2 | 3 | ## What is WIM? 4 | 5 | (TO DO) 6 | 7 | ## What is the WIM Handler? 8 | 9 | (TO DO) 10 | 11 | See [How To Implement A Custom Content Handler Extension](../../../../docs/agent-reference/how-to-implement-custom-update-handler.md) for more information. 12 | 13 | ## WIM Handler Goals 14 | 15 | (TO DO) 16 | 17 | ## Architecture 18 | 19 | (TO DO) 20 | 21 | ## How To Use WIM Handler 22 | 23 | (TO DO) 24 | 25 | ### Registering WIM Handler extension 26 | 27 | To enable WIM on the device, the handler must be registered to support **'microsoft/wim:1'**. 28 | 29 | Following command can be run manually on the device: 30 | 31 | ```PowerShell 32 | AducIotAgent.exe --update-type 'microsoft/wim:1' --register-content-handler 33 | ``` 34 | 35 | ### Setting WIM Handler Properties 36 | 37 | (TO DO) 38 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/Wimgapi/Lib/amd64/wimgapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/src/extensions/step_handlers/wim_handler/Wimgapi/Lib/amd64/wimgapi.lib -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/Wimgapi/Lib/arm/wimgapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/src/extensions/step_handlers/wim_handler/Wimgapi/Lib/arm/wimgapi.lib -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/Wimgapi/Lib/arm64/wimgapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/src/extensions/step_handlers/wim_handler/Wimgapi/Lib/arm64/wimgapi.lib -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/Wimgapi/Lib/x86/wimgapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/iot-hub-device-update/86ad3bba71f74a3eb4b5f849915cfebed2879ab6/src/extensions/step_handlers/wim_handler/Wimgapi/Lib/x86/wimgapi.lib -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/inc/bcdedit.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BCDEDIT_HPP 2 | #define BCDEDIT_HPP 3 | 4 | bool ConfigureBCD(char driveLetter, const char* identifier); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/inc/file_version.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FILE_VERSION_HPP 2 | #define FILE_VERSION_HPP 3 | 4 | #include 5 | 6 | std::string GetFileVersion(const char* path); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/inc/format_drive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FORMAT_DRIVE_HPP 2 | #define FORMAT_DRIVE_HPP 3 | 4 | #define WIN32_LEAN_AND_MEAN 5 | #include 6 | #include 7 | 8 | HRESULT FormatDrive(char driveLetter, const std::string& driveLabel); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/inc/wimg.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WIMG_HPP 2 | #define WIMG_HPP 3 | 4 | #define WIN32_LEAN_AND_MEAN 5 | #include 6 | 7 | HRESULT ApplyImage(const char* source, const char* dest, const char* temp = nullptr); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/inc/workflow_ptr.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WORKFLOW_PTR_HPP 2 | #define WORKFLOW_PTR_HPP 3 | 4 | #include // std::unique_ptr 5 | 6 | #include // workflow_free_string 7 | 8 | namespace ptr_deleters 9 | { 10 | struct workflow_string // !< wrapper for the workflow struct so we can keep free the workflow_string ptr 11 | { 12 | /** 13 | * @brief Frees the @p ptr parameter using workflow_free_string() 14 | * @param ptr the workflow string to be freed 15 | */ 16 | void operator()(char* ptr) 17 | { 18 | workflow_free_string(ptr); 19 | } 20 | }; 21 | 22 | } //namespace ptr_deleters 23 | 24 | using workflow_string_ptr = std::unique_ptr; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/extensions/step_handlers/wim_handler/src/file_version.cpp: -------------------------------------------------------------------------------- 1 | #include "file_version.hpp" 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | 6 | #include // unique_ptr 7 | #include // stringstream 8 | #include 9 | 10 | std::string GetFileVersion(const char* path) 11 | { 12 | std::string version; 13 | 14 | const DWORD size = GetFileVersionInfoSize(path, 0 /*dwHandle*/); 15 | if (size != 0) 16 | { 17 | std::unique_ptr buffer(new BYTE[size]); 18 | if (GetFileVersionInfo(path, 0 /*dwHandle*/, size, buffer.get())) 19 | { 20 | VS_FIXEDFILEINFO* pffi; 21 | UINT buflen; 22 | 23 | if (VerQueryValue(buffer.get(), "\\", reinterpret_cast(&pffi), &buflen)) 24 | { 25 | std::stringstream ss; 26 | 27 | ss << HIWORD(pffi->dwProductVersionMS) << "." << LOWORD(pffi->dwProductVersionMS) << "." 28 | << HIWORD(pffi->dwProductVersionLS) << "." << LOWORD(pffi->dwProductVersionLS); 29 | version = ss.str(); 30 | } 31 | } 32 | } 33 | 34 | return version; 35 | } 36 | -------------------------------------------------------------------------------- /src/extensions/update_manifest_handlers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (steps_handler) 2 | -------------------------------------------------------------------------------- /src/inc/aduc/aduc_banned.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file aduc_banned.h 3 | * @brief Macro definitions that cause banned functions considered to be 4 | * unsafe to result in a compilation error. 5 | * 6 | * @copyright Copyright (c) Microsoft Corporation. 7 | * Licensed under the MIT License. 8 | */ 9 | 10 | #ifndef ADUC_BANNED_H 11 | #define ADUC_BANNED_H 12 | 13 | #define DEFINE_BANNED_ALTERNATIVE(BANNED_FUNC, ALT_FUNC) BANNED_FUNC##_is_banned__Please_use_##ALT_FUNC##_instead 14 | 15 | #undef strncpy 16 | #define strncpy(dest,src,n) DEFINE_BANNED_ALTERNATIVE(strncpy, ADUC_Safe_StrCopyN) 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/inc/aduc/aduc_inode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file aduc_inode.h 3 | * @brief ADU client macro definitions related to inodes 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef ADUC_INODE_H 10 | #define ADUC_INODE_H 11 | 12 | // inode values start at 1. 0 is a sentinel inode value analogous to NULL for pointers. 13 | // When saving inode value of a file, this sentinel value is used to indicate that no 14 | // inode has been saved yet. 15 | #define ADUC_INODE_SENTINEL_VALUE 0 16 | 17 | #endif // ADUC_INODE_H 18 | -------------------------------------------------------------------------------- /src/inc/aduc/device_info_exports.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file device_info_exports.h 3 | * @brief Describes methods to be exported from platform-specific ADUC agent code for the device information interface. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADUC_DEVICE_INFO_EXPORTS_H 9 | #define ADUC_DEVICE_INFO_EXPORTS_H 10 | 11 | #include 12 | 13 | EXTERN_C_BEGIN 14 | 15 | /** 16 | * @brief Enumeration containing the device information fields that can be queried. 17 | */ 18 | typedef enum tagDI_DeviceInfoProperty 19 | { 20 | DIIP_Manufacturer, 21 | DIIP_Model, 22 | DIIP_OsName, 23 | DIIP_ProcessorArchitecture, 24 | DIIP_ProcessorManufacturer, 25 | DIIP_SoftwareVersion, 26 | DIIP_TotalMemory, 27 | DIIP_TotalStorage, 28 | } DI_DeviceInfoProperty; 29 | 30 | // 31 | // Exported methods. 32 | // 33 | 34 | /** 35 | * @brief Return a specific device information value. 36 | * 37 | * @param property Property to retrieve 38 | * @return char* Value of property allocated with malloc, or NULL on error or value not changed since last call. 39 | */ 40 | char* DI_GetDeviceInformationValue(DI_DeviceInfoProperty property); 41 | 42 | EXTERN_C_END 43 | 44 | #endif // ADUC_DEVICE_INFO_EXPORTS_H 45 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/dlfcn.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_DLFCN_H 2 | #define ADUCPAL_DLFCN_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | # define RTLD_LAZY 0 7 | 8 | # ifdef __cplusplus 9 | extern "C" 10 | { 11 | # endif 12 | 13 | void* ADUCPAL_dlopen(const char* filename, int flag); 14 | char* ADUCPAL_dlerror(); 15 | void* ADUCPAL_dlsym(void* handle, const char* symbol); 16 | int ADUCPAL_dlclose(void* handle); 17 | 18 | # ifdef __cplusplus 19 | } 20 | # endif 21 | 22 | #else 23 | 24 | # include 25 | 26 | # define ADUCPAL_dlopen dlopen 27 | # define ADUCPAL_dlerror dlerror 28 | # define ADUCPAL_dlsym dlsym 29 | # define ADUCPAL_dlclose dlclose 30 | 31 | #endif // #ifdef ADUCPAL_USE_PAL 32 | 33 | #endif // ADUCPAL_DLFCN_H 34 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/grp.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_GRP_H 2 | #define ADUCPAL_GRP_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | # include "aducpal/sys_types.h" // gid_t 7 | 8 | // This project only references gr_gid, gr_mem 9 | struct group 10 | { 11 | // char *gr_name; /* group name */ 12 | // char *gr_passwd; /* group password */ 13 | gid_t gr_gid; /* group ID */ 14 | char** gr_mem; /* group members */ 15 | }; 16 | 17 | # ifdef __cplusplus 18 | extern "C" 19 | { 20 | # endif 21 | 22 | struct group* ADUCPAL_getgrnam(const char* name); 23 | 24 | # ifdef __cplusplus 25 | } 26 | # endif 27 | 28 | #else 29 | 30 | # include 31 | 32 | # define ADUCPAL_getgrnam getgrnam 33 | 34 | #endif // #ifdef ADUCPAL_USE_PAL 35 | 36 | #endif // ADUCPAL_GRP_H 37 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/limits.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUC_PAL_LIMITS_H 2 | #define ADUC_PAL_LIMITS_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | # ifndef MAX_PATH 6 | # define MAX_PATH 260 7 | # endif 8 | 9 | # include 10 | 11 | # ifndef PATH_MAX 12 | # define PATH_MAX MAX_PATH 13 | # endif 14 | #else 15 | # include 16 | 17 | # ifndef MAX_PATH 18 | 19 | # define MAX_PATH PATH_MAX 20 | 21 | # endif 22 | #endif 23 | #endif // ADUCPAL_GRP_H 24 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/pwd.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_PWD_H 2 | #define ADUCPAL_PWD_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | # include "aducpal/sys_types.h" // uid_t 7 | 8 | // // This project only references pw_uid 9 | struct passwd 10 | { 11 | // char *pw_name; /* username */ 12 | // char *pw_passwd; /* user password */ 13 | uid_t pw_uid; /* user ID */ 14 | // gid_t pw_gid; /* group ID */ 15 | // char *pw_gecos; /* user information */ 16 | // char *pw_dir; /* home directory */ 17 | // char *pw_shell; /* shell program */ 18 | }; 19 | 20 | # ifdef __cplusplus 21 | extern "C" 22 | { 23 | # endif 24 | 25 | struct passwd* ADUCPAL_getpwnam(const char* name); 26 | 27 | # ifdef __cplusplus 28 | } 29 | # endif 30 | 31 | #else 32 | 33 | # include 34 | 35 | # define ADUCPAL_getpwnam getpwnam 36 | 37 | #endif // #ifdef ADUCPAL_USE_PAL 38 | 39 | #endif // ADUCPAL_PWD_H 40 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_STDIO_H 2 | #define ADUCPAL_STDIO_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | # include // FILE* 7 | 8 | # ifdef __cplusplus 9 | extern "C" 10 | { 11 | # endif 12 | 13 | FILE* ADUCPAL_popen(const char* command, const char* type); 14 | int ADUCPAL_pclose(FILE* stream); 15 | int ADUCPAL_remove(const char* pathname); 16 | int ADUCPAL_rename(const char* old_f, const char* new_f); 17 | 18 | # ifdef __cplusplus 19 | } 20 | # endif 21 | 22 | #else 23 | 24 | # include 25 | 26 | # define ADUCPAL_popen popen 27 | # define ADUCPAL_pclose pclose 28 | # define ADUCPAL_remove remove 29 | # define ADUCPAL_rename rename 30 | 31 | #endif // #ifdef ADUCPAL_USE_PAL 32 | 33 | #endif // ADUCPAL_STDIO_H 34 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_STDLIB_H 2 | #define ADUCPAL_STDLIB_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | # ifdef __cplusplus 7 | extern "C" 8 | { 9 | # endif 10 | 11 | int ADUCPAL_setenv(const char* name, const char* value, int overwrite); 12 | int ADUCPAL_unsetenv(const char* name); 13 | 14 | # ifdef __cplusplus 15 | } 16 | # endif 17 | 18 | #else 19 | 20 | # include 21 | 22 | # define ADUCPAL_setenv setenv 23 | # define ADUCPAL_unsetenv unsetenv 24 | 25 | #endif // #ifdef ADUCPAL_USE_PAL 26 | 27 | #endif // ADUCPAL_STDLIB_H 28 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_STRINGS_H 2 | #define ADUCPAL_STRINGS_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | # ifdef __cplusplus 7 | extern "C" 8 | { 9 | # endif 10 | 11 | int ADUCPAL_strcasecmp(const char* s1, const char* s2); 12 | 13 | # ifdef __cplusplus 14 | } 15 | # endif 16 | 17 | #else 18 | 19 | # include 20 | 21 | # define ADUCPAL_strcasecmp strcasecmp 22 | 23 | #endif // #ifdef ADUCPAL_USE_PAL 24 | 25 | #endif // ADUCPAL_STRINGS_H 26 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/sys_time.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_SYS_TIME_H 2 | #define ADUCPAL_SYS_TIME_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | # include // time_t 7 | 8 | // This project only references tv_sec 9 | struct timeval 10 | { 11 | time_t tv_sec; /* seconds */ 12 | // suseconds_t tv_usec; /* microseconds */ 13 | }; 14 | 15 | # ifdef __cplusplus 16 | extern "C" 17 | { 18 | # endif 19 | 20 | // Note: unclear if tz is "struct timezone*" or "void*". 21 | // In any case, it's unused in this project. 22 | int ADUCPAL_gettimeofday(struct timeval* tv, void* tz); 23 | 24 | # ifdef __cplusplus 25 | } 26 | # endif 27 | 28 | #else 29 | 30 | # include 31 | 32 | # define ADUCPAL_gettimeofday gettimeofday 33 | 34 | #endif // #ifdef ADUCPAL_USE_PAL 35 | 36 | #endif // ADUCPAL_SYS_TIME_H 37 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/sys_types.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_SYS_TYPES_H 2 | #define ADUCPAL_SYS_TYPES_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | typedef int gid_t; 7 | typedef int uid_t; 8 | typedef long ssize_t; 9 | typedef unsigned int mode_t; 10 | typedef int pid_t; 11 | 12 | #else 13 | 14 | # include 15 | 16 | #endif // #ifdef ADUCPAL_USE_PAL 17 | 18 | #endif // ADUCPAL_SYS_TYPES_H 19 | -------------------------------------------------------------------------------- /src/libaducpal/inc/aducpal/time.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUCPAL_TIME_H 2 | #define ADUCPAL_TIME_H 3 | 4 | #ifdef ADUCPAL_USE_PAL 5 | 6 | # include 7 | 8 | typedef unsigned int clockid_t; 9 | 10 | # define CLOCK_REALTIME 0 11 | 12 | # ifdef __cplusplus 13 | extern "C" 14 | { 15 | # endif 16 | 17 | int ADUCPAL_clock_gettime(clockid_t clockid, struct timespec* tp); 18 | struct tm* ADUCPAL_gmtime_r(const time_t* timep, struct tm* result); 19 | int ADUCPAL_nanosleep(const struct timespec* rqtp, struct timespec* rmtp); 20 | 21 | # ifdef __cplusplus 22 | } 23 | # endif 24 | 25 | #else 26 | 27 | # include 28 | 29 | # define ADUCPAL_clock_gettime clock_gettime 30 | # define ADUCPAL_gmtime_r gmtime_r 31 | # define ADUCPAL_nanosleep nanosleep 32 | 33 | #endif // #ifdef ADUCPAL_USE_PAL 34 | 35 | #endif // ADUCPAL_TIME_H 36 | -------------------------------------------------------------------------------- /src/libaducpal/src/grp.c: -------------------------------------------------------------------------------- 1 | #include "aducpal/grp.h" 2 | 3 | #include 4 | 5 | struct group* ADUCPAL_getgrnam(const char* name) 6 | { 7 | // From CMakeLists.txt 8 | #define ADUC_FILE_GROUP "adu" 9 | #define DO_FILE_GROUP "do" 10 | 11 | static char* s_gr_mem[] = { ADUC_FILE_GROUP, DO_FILE_GROUP, NULL }; 12 | 13 | // For Windows, return 0 (root) for "adu" and "do" 14 | static struct group s_g = { 0 /* gr_gid */, s_gr_mem }; 15 | 16 | if (strcmp(name, ADUC_FILE_GROUP) == 0 || strcmp(name, DO_FILE_GROUP) == 0) 17 | { 18 | return &s_g; 19 | } 20 | 21 | return NULL; 22 | } 23 | -------------------------------------------------------------------------------- /src/libaducpal/src/pwd.c: -------------------------------------------------------------------------------- 1 | #include "aducpal/pwd.h" 2 | 3 | #include 4 | 5 | struct passwd* ADUCPAL_getpwnam(const char* name) 6 | { 7 | // From CMakeLists.txt 8 | #define ADUC_FILE_USER "adu" 9 | #define DO_FILE_USER "do" 10 | 11 | // For Windows, return success on "do" and "adu". 12 | static struct passwd g_p = { 0 /* pw_uid */ }; 13 | 14 | if (strcmp(name, ADUC_FILE_USER) == 0 || strcmp(name, DO_FILE_USER) == 0) 15 | { 16 | return &g_p; 17 | } 18 | 19 | return NULL; 20 | } 21 | -------------------------------------------------------------------------------- /src/libaducpal/src/strings.c: -------------------------------------------------------------------------------- 1 | #include "aducpal/strings.h" 2 | 3 | #include // _stricmp 4 | 5 | int ADUCPAL_strcasecmp(const char* s1, const char* s2) 6 | { 7 | return _stricmp(s1, s2); 8 | } 9 | -------------------------------------------------------------------------------- /src/libaducpal/src/sys_stat.c: -------------------------------------------------------------------------------- 1 | #include "aducpal/sys_stat.h" 2 | 3 | #include // _mkdir 4 | #include // errno 5 | 6 | #ifndef UNREFERENCED_PARAMETER 7 | # define UNREFERENCED_PARAMETER(param) (void)(param) 8 | #endif 9 | 10 | int ADUCPAL_chmod(const char* path, mode_t mode) 11 | { 12 | // For Windows, do nothing with mode for now. 13 | UNREFERENCED_PARAMETER(path); 14 | UNREFERENCED_PARAMETER(mode); 15 | return 0; 16 | } 17 | 18 | int ADUCPAL_mkdir(const char* path, mode_t mode) 19 | { 20 | // For Windows, do nothing with mode for now. 21 | UNREFERENCED_PARAMETER(mode); 22 | 23 | const int ret = _mkdir(path); 24 | if (ret == -1) 25 | { 26 | // Folder existing already isn't fatal. 27 | if (errno == EEXIST) 28 | { 29 | return 0; 30 | } 31 | } 32 | return ret; 33 | } 34 | -------------------------------------------------------------------------------- /src/libaducpal/src/sys_time.c: -------------------------------------------------------------------------------- 1 | #include "aducpal/sys_time.h" 2 | #include "aducpal/time.h" // clock_gettime 3 | 4 | #include 5 | #include // memset 6 | 7 | int ADUCPAL_gettimeofday(struct timeval* tv, void* tzp) 8 | { 9 | memset(tv, 0, sizeof(*tv)); 10 | 11 | // If tzp is not a null pointer, the behavior is unspecified. 12 | if (tzp != NULL) 13 | { 14 | // No errors are defined. 15 | return ENOSYS; 16 | } 17 | 18 | struct timespec ts; 19 | ADUCPAL_clock_gettime(CLOCK_REALTIME, &ts); 20 | 21 | tv->tv_sec = ts.tv_sec; 22 | // Not used in this project. 23 | // tv->tv_usec = ts.tv_nsec / 1000; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/logging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name logging) 4 | 5 | add_library (${target_name} INTERFACE) 6 | add_library (aduc::${target_name} ALIAS ${target_name}) 7 | 8 | target_include_directories (${target_name} INTERFACE inc) 9 | 10 | set (ADUC_LOGGING_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/inc) 11 | 12 | if (ADUC_LOGGING_LIBRARY STREQUAL "xlog") 13 | # xlogging requires the azure iot shared util library. 14 | target_link_aziotsharedutil (${target_name} INTERFACE) 15 | target_compile_definitions (${target_name} INTERFACE ADUC_USE_XLOGGING=1) 16 | elseif (ADUC_LOGGING_LIBRARY STREQUAL "zlog") 17 | add_subdirectory (zlog) 18 | target_link_libraries (${target_name} INTERFACE zlog) 19 | target_compile_definitions (${target_name} INTERFACE ADUC_USE_ZLOGGING=1) 20 | else () 21 | message (FATAL_ERROR "Unknown logging library ${ADUC_LOGGING_LIBRARY} specified.") 22 | endif () 23 | -------------------------------------------------------------------------------- /src/platform_layers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name platform_layer) 4 | 5 | add_library (${target_name} INTERFACE) 6 | add_library (aduc::${target_name} ALIAS ${target_name}) 7 | 8 | # Determine which platform layer needs to be built 9 | # and add the appropriate subdirectory to the build. 10 | if (ADUC_PLATFORM_LAYER STREQUAL "linux") 11 | add_subdirectory (linux_platform_layer) 12 | target_link_libraries (${target_name} INTERFACE aduc::linux_platform_layer) 13 | elseif (ADUC_PLATFORM_LAYER STREQUAL "windows") 14 | add_subdirectory (windows_platform_layer) 15 | target_link_libraries (${target_name} INTERFACE aduc::windows_platform_layer) 16 | else () 17 | message (FATAL_ERROR "Invalid platform layer specified. ${ADUC_PLATFORM_LAYER}") 18 | endif () 19 | -------------------------------------------------------------------------------- /src/rootkey_workflow/inc/aduc/rootkey_workflow.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file diagnostics_devicename.h 3 | * @brief Header file describing the methods for setting the static global device name for use in the diagnostic component 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ROOTKEY_WORKFLOW_H 9 | #define ROOTKEY_WORKFLOW_H 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | EXTERN_C_BEGIN 16 | 17 | ADUC_Result RootKeyWorkflow_UpdateRootKeys(const char* workflowId, const char* workFolder, const char* rootKeyPkgUrl); 18 | 19 | EXTERN_C_END 20 | 21 | #endif // ROOTKEY_WORKFLOW_H 22 | -------------------------------------------------------------------------------- /src/rootkey_workflow/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name rootkey_workflow_unit_test) 2 | 3 | include (agentRules) 4 | compileasc99 () 5 | disablertti () 6 | 7 | find_package (Catch2 REQUIRED) 8 | 9 | add_executable (${target_name}) 10 | target_sources (${target_name} PRIVATE rootkey_workflow_ut.cpp) 11 | 12 | target_link_libraries ( 13 | ${target_name} 14 | PRIVATE Catch2::Catch2WithMain 15 | aduc::c_utils 16 | aduc::rootkey_workflow 17 | aduc::root_key_utils) 18 | 19 | include (CTest) 20 | include (Catch) 21 | catch_discover_tests (${target_name}) 22 | -------------------------------------------------------------------------------- /src/rootkey_workflow/tests/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @brief rootkey_workflow tests main entry point. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | // https://github.com/catchorg/Catch2/blob/master/docs/own-main.md 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | int main(int argc, char* argv[]) 15 | { 16 | int result; 17 | 18 | result = Catch::Session().run(argc, argv); 19 | if (result != 0) 20 | { 21 | std::cout << "Catch session failed, err=" << result << std::endl; 22 | } 23 | 24 | return result; 25 | } 26 | -------------------------------------------------------------------------------- /src/rootkey_workflow/tests/rootkey_workflow_ut.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rootkey_workflow_ut.cpp 3 | * @brief Unit Tests for rootkey_workflow library 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #include "aduc/rootkey_workflow.h" // RootKeyWorkflow_UpdateRootKeys 10 | #include 11 | #include 12 | #include 13 | #include // RootKeyUtility_GetReportingErc 14 | 15 | using Catch::Matchers::Equals; 16 | 17 | TEST_CASE("RootKeyWorkflow_UpdateRootKeys") 18 | { 19 | SECTION("rootkeyutil reporting erc set on failure") 20 | { 21 | ADUC_Result result = RootKeyWorkflow_UpdateRootKeys(nullptr /* workflowId */, nullptr /* workFolder */, nullptr /* rootKeyPkgUrl */); 22 | REQUIRE(IsAducResultCodeFailure(result.ResultCode)); 23 | CHECK(result.ExtendedResultCode == ADUC_ERC_INVALIDARG); 24 | 25 | ADUC_Result_t ercForReporting = RootKeyUtility_GetReportingErc(); 26 | CHECK(ercForReporting == result.ExtendedResultCode); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | add_subdirectory (auto_utils) 4 | add_subdirectory (c_utils) 5 | add_subdirectory (config_utils) 6 | add_subdirectory (contract_utils) 7 | add_subdirectory (crypto_utils) 8 | add_subdirectory (d2c_messaging) 9 | add_subdirectory (eis_utils) 10 | add_subdirectory (entity_utils) 11 | add_subdirectory (exception_utils) 12 | add_subdirectory (extension_utils) 13 | add_subdirectory (file_utils) 14 | add_subdirectory (hash_utils) 15 | add_subdirectory (installed_criteria_utils) 16 | add_subdirectory (permission_utils) 17 | add_subdirectory (parson_json_utils) 18 | add_subdirectory (jws_utils) 19 | add_subdirectory (parser_utils) 20 | add_subdirectory (path_utils) 21 | add_subdirectory (process_utils) 22 | add_subdirectory (reporting_utils) 23 | add_subdirectory (retry_utils) 24 | add_subdirectory (rootkeypackage_utils) 25 | add_subdirectory (root_key_utils) 26 | add_subdirectory (string_utils) 27 | add_subdirectory (system_utils) 28 | add_subdirectory (url_utils) 29 | add_subdirectory (workflow_data_utils) 30 | add_subdirectory (workflow_utils) 31 | 32 | if (ADUC_BUILD_UNIT_TESTS) 33 | add_subdirectory (test_utils) 34 | endif () 35 | -------------------------------------------------------------------------------- /src/utils/auto_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (target_name auto_utils) 3 | 4 | add_library (${target_name} INTERFACE) 5 | add_library (aduc::${target_name} ALIAS ${target_name}) 6 | 7 | target_include_directories (${target_name} INTERFACE inc) 8 | 9 | # 10 | # Turn -fPIC on, in order to use this library in another shared library. 11 | # 12 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 13 | -------------------------------------------------------------------------------- /src/utils/auto_utils/inc/aduc/defer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace aduc 6 | { 7 | /** 8 | * @brief Unconditionally execute a function at scope exit. 9 | * 10 | */ 11 | class Defer 12 | { 13 | std::function scope_exit_fn; 14 | 15 | public: 16 | explicit Defer(std::function&& fn) : scope_exit_fn(std::move(fn)) 17 | { 18 | } 19 | 20 | ~Defer() 21 | { 22 | scope_exit_fn(); 23 | } 24 | }; 25 | 26 | } // namespace aduc 27 | -------------------------------------------------------------------------------- /src/utils/c_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name c_utils) 4 | 5 | include (agentRules) 6 | compileasc99 () 7 | 8 | add_library (${target_name} STATIC src/bit_ops.c src/connection_string_utils.c 9 | src/string_c_utils.c) 10 | 11 | add_library (aduc::${target_name} ALIAS ${target_name}) 12 | 13 | # 14 | # Turn -fPIC on, in order to use this library in another shared library. 15 | # 16 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 17 | 18 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 19 | 20 | target_link_aziotsharedutil (${target_name} PRIVATE) 21 | 22 | target_link_libraries (${target_name} PRIVATE aduc::logging) 23 | 24 | target_link_libraries (${target_name} PRIVATE libaducpal) 25 | 26 | if (ADUC_BUILD_UNIT_TESTS) 27 | add_subdirectory (tests) 28 | endif () 29 | -------------------------------------------------------------------------------- /src/utils/c_utils/inc/aduc/bit_ops.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bit_ops.h 3 | * @brief inline functions that manipulate bits. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef __BIT_OPS_H__ 10 | #define __BIT_OPS_H__ 11 | 12 | #include // for bool 13 | #include // for size_t 14 | 15 | /* 16 | * This is using C99 extern inline model--inline definition is in header and extern declaration is in exactly one 17 | * complication unit (see bit_ops.c). 18 | */ 19 | 20 | /** 21 | * @brief Does bitwise-AND filtering on bits using the mask and ensures that all the high bits of the mask were set. 22 | * @param bits The bits to test with mask. 23 | * @param mask The bitmask to apply. 24 | * @return true when all bits are high for corresponding high bits in the mask. 25 | */ 26 | inline bool BitOps_AreAllBitsSet(size_t bits, size_t mask) 27 | { 28 | return (bits & mask) == mask; 29 | } 30 | 31 | #endif /* __BIT_OPS_H__ */ 32 | -------------------------------------------------------------------------------- /src/utils/c_utils/src/bit_ops.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bit_ops.c 3 | * @brief This file contains extern declaration for each extern inline function from the header that manipulate bits. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #include "aduc/bit_ops.h" 10 | 11 | /* 12 | * C99 extern inline model where this compilation unit has the externally visible code when not inlining (e.g. no optimizations switch enabled). 13 | * When compiler decides to inline, these become redundant declarations so we suppress that check. 14 | */ 15 | 16 | // NOLINTNEXTLINE(readability-redundant-declaration) 17 | extern /* inline */ bool BitOps_AreAllBitsSet(size_t bits, size_t mask); 18 | -------------------------------------------------------------------------------- /src/utils/c_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name c_utils_unit_tests) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources c_utils_ut.cpp connection_string_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${target_name} ${sources}) 15 | 16 | target_link_libraries (${target_name} PRIVATE aduc::c_utils aduc::string_utils aduc::system_utils 17 | Catch2::Catch2WithMain) 18 | 19 | target_link_umock_c (${target_name} PRIVATE) 20 | 21 | include (CTest) 22 | include (Catch) 23 | catch_discover_tests (${target_name}) 24 | -------------------------------------------------------------------------------- /src/utils/config_utils/src/config_parsefile.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file config_parsefile.c 4 | * @brief Implements parsing the config file 5 | * 6 | * @copyright Copyright (c) Microsoft Corporation. 7 | * Licensed under the MIT License. 8 | */ 9 | #include "aduc/config_utils.h" 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * @brief Takes in the config file path and parse it into a JSON Value with Parson 16 | * 17 | * @param configFilePath 18 | * @return JSON_Value* 19 | */ 20 | JSON_Value* Parse_JSON_File(const char* configFilePath) 21 | { 22 | return json_parse_file(configFilePath); 23 | } 24 | -------------------------------------------------------------------------------- /src/utils/config_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (config_utils_unit_test) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources main.cpp config_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${PROJECT_NAME} ${sources}) 15 | 16 | target_link_libraries (${PROJECT_NAME} PRIVATE Catch2::Catch2WithMain Parson::parson aduc::c_utils 17 | aduc::config_utils aduc::string_utils) 18 | 19 | target_link_umock_c (${PROJECT_NAME} PRIVATE) 20 | target_link_aziotsharedutil (${PROJECT_NAME} PRIVATE) 21 | 22 | target_compile_definitions ( 23 | ${PROJECT_NAME} PRIVATE ADUC_CONF_FILE_PATH="${ADUC_CONF_FILE_PATH}" 24 | ADUC_PLATFORM_LAYER="${ADUC_PLATFORM_LAYER}") 25 | 26 | include (CTest) 27 | include (Catch) 28 | catch_discover_tests (${PROJECT_NAME}) 29 | -------------------------------------------------------------------------------- /src/utils/config_utils/tests/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @brief config_utils tests main entry point. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | // https://github.com/catchorg/Catch2/blob/master/docs/own-main.md 9 | #include 10 | 11 | // https://github.com/Azure/umock-c/blob/master/doc/umock_c.md 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | int main(int argc, char* argv[]) 18 | { 19 | int result; 20 | 21 | // Global setup 22 | result = umock_c_init([](UMOCK_C_ERROR_CODE error_code) -> void { 23 | std::cerr << "*** umock_c failed, err=" << error_code << std::endl; 24 | }); 25 | if (result != 0) 26 | { 27 | std::cerr << "umock_c_init_failed, err=" << result << std::endl; 28 | return result; 29 | } 30 | 31 | result = Catch::Session().run(argc, argv); 32 | 33 | // Global cleanup. 34 | umock_c_deinit(); 35 | 36 | return result; 37 | } 38 | -------------------------------------------------------------------------------- /src/utils/contract_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name contract_utils) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | 7 | add_library (${target_name} STATIC src/contract_utils.c) 8 | add_library (aduc::${target_name} ALIAS ${target_name}) 9 | 10 | target_include_directories ( 11 | ${target_name} 12 | PUBLIC inc ${ADUC_EXPORT_INCLUDES} 13 | PRIVATE src) 14 | 15 | target_link_libraries (${target_name} PUBLIC aduc::c_utils) 16 | 17 | target_link_libraries (${target_name} PRIVATE libaducpal) 18 | 19 | if (ADUC_BUILD_UNIT_TESTS) 20 | add_subdirectory (tests) 21 | endif () 22 | -------------------------------------------------------------------------------- /src/utils/contract_utils/inc/aduc/contract_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file contract_utils.h 3 | * @brief The header for contract utils. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef ADUC_CONTRACT_UTILS 10 | #define ADUC_CONTRACT_UTILS 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #define ADUC_V1_CONTRACT_MAJOR_VER 1 //!< The major version of the v1 contract model 17 | #define ADUC_V1_CONTRACT_MINOR_VER 0 //!< The minor version of the v1 contract model 18 | 19 | /** 20 | * @brief The Extenstion Contract Info struct that wraps the version for the contract information 21 | */ 22 | typedef struct tagADUC_ExtensionContractInfo 23 | { 24 | unsigned int majorVer; //!< The major version of the contract 25 | unsigned int minorVer; //!< The minor version of the contract 26 | } ADUC_ExtensionContractInfo; 27 | 28 | EXTERN_C_BEGIN 29 | 30 | /** 31 | * @brief Checks if @p contractInfo is a v1 contract 32 | * @param contractInfo the contractInfo to check 33 | * @returns true if a v1 contract version ; false otherwise 34 | */ 35 | bool ADUC_ContractUtils_IsV1Contract(ADUC_ExtensionContractInfo* contractInfo); 36 | 37 | EXTERN_C_END 38 | 39 | #endif // ADUC_CONTRACT_UTILS 40 | -------------------------------------------------------------------------------- /src/utils/contract_utils/src/contract_utils.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file contract_utils.c 3 | * @brief The implementation for contract utils. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #include "aduc/contract_utils.h" 10 | #include 11 | #include 12 | 13 | bool ADUC_ContractUtils_IsV1Contract(ADUC_ExtensionContractInfo* contractInfo) 14 | { 15 | // V1 contract includes extensions that have no GetContractInfo symbol (NULL contractInfo argument) 16 | // or are explicitly set to 1.0 17 | return contractInfo == NULL 18 | || (contractInfo->majorVer == ADUC_V1_CONTRACT_MAJOR_VER 19 | && contractInfo->minorVer == ADUC_V1_CONTRACT_MINOR_VER); 20 | } 21 | -------------------------------------------------------------------------------- /src/utils/contract_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (contract_utils_unit_test) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | find_package (Catch2 REQUIRED) 9 | 10 | add_executable (${PROJECT_NAME}) 11 | 12 | target_sources (${PROJECT_NAME} PRIVATE contract_utils_ut.cpp) 13 | 14 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::contract_utils Catch2::Catch2WithMain) 15 | 16 | include (CTest) 17 | include (Catch) 18 | catch_discover_tests (${PROJECT_NAME}) 19 | -------------------------------------------------------------------------------- /src/utils/crypto_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name crypto_utils) 4 | 5 | add_library (${target_name} STATIC src/crypto_lib.c src/base64_utils.c) 6 | add_library (aduc::${target_name} ALIAS ${target_name}) 7 | 8 | target_include_directories (${target_name} PUBLIC inc) 9 | 10 | find_package (OpenSSL REQUIRED) 11 | 12 | # 13 | # Turn -fPIC on, in order to use this library in another shared library. 14 | # 15 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 16 | 17 | target_link_aziotsharedutil (${target_name} PUBLIC) 18 | 19 | target_link_libraries ( 20 | ${target_name} 21 | PUBLIC aduc::c_utils 22 | PRIVATE aduc::root_key_utils OpenSSL::Crypto) 23 | 24 | target_link_libraries (${target_name} PRIVATE libaducpal) 25 | 26 | target_compile_definitions (${target_name} PRIVATE EMBED_TEST_ROOT_KEYS=${EMBED_TEST_ROOT_KEYS}) 27 | 28 | if (ADUC_BUILD_UNIT_TESTS) 29 | add_subdirectory (tests) 30 | endif () 31 | -------------------------------------------------------------------------------- /src/utils/crypto_utils/inc/base64_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file base64_utils.h 3 | * @brief Provides an implementation for Base64 encoding and decoding 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef BASE64_UTILS_H 13 | # define BASE64_UTILS_H 14 | 15 | EXTERN_C_BEGIN 16 | 17 | // 18 | // Base64 Encoding / Decoding 19 | // 20 | 21 | char* Base64URLEncode(const uint8_t* bytes, size_t len); 22 | 23 | size_t Base64URLDecode(const char* base64_encoded_blob, uint8_t** decoded_buffer); 24 | 25 | char* Base64URLDecodeToString(const char* base64_encoded_blob); 26 | 27 | EXTERN_C_END 28 | 29 | #endif // BASE64_UTILS_H 30 | -------------------------------------------------------------------------------- /src/utils/crypto_utils/inc/crypto_key.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file crypto_key.h 3 | * @brief Declares the Crypto Key Handle for the crypto_utils and jws_utils libraries 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef CRYPTO_KEY_H 10 | #define CRYPTO_KEY_H 11 | 12 | /** 13 | * @brief Opaque key for cryptographic functions. 14 | */ 15 | typedef void* CryptoKeyHandle; 16 | 17 | #endif // CRYPTO_KEY_H 18 | -------------------------------------------------------------------------------- /src/utils/crypto_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (crypto_utils_unit_test) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources crypto_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | find_package (OpenSSL REQUIRED) 14 | 15 | add_executable (${PROJECT_NAME} ${sources}) 16 | 17 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::crypto_utils aduc::root_key_utils 18 | aduc::string_utils Catch2::Catch2WithMain OpenSSL::Crypto) 19 | 20 | include (CTest) 21 | include (Catch) 22 | catch_discover_tests (${PROJECT_NAME}) 23 | -------------------------------------------------------------------------------- /src/utils/d2c_messaging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name d2c_messaging) 4 | add_library (${target_name} STATIC src/d2c_messaging.c) 5 | add_library (aduc::${target_name} ALIAS ${target_name}) 6 | 7 | target_include_directories (${target_name} PUBLIC ./inc ${ADUC_TYPES_INCLUDES} 8 | ${ADUC_EXPORT_INCLUDES}) 9 | 10 | # 11 | # Turn -fPIC on, in order to use this library in another shared library. 12 | # 13 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 14 | 15 | find_package (OpenSSL REQUIRED) 16 | target_link_libraries (${target_name} PRIVATE OpenSSL::Crypto) 17 | 18 | target_link_aziotsharedutil (${target_name} PRIVATE) 19 | 20 | target_link_libraries ( 21 | ${target_name} 22 | PUBLIC aduc::adu_types 23 | PRIVATE aduc::communication_abstraction aduc::logging aduc::retry_utils) 24 | 25 | #if (ADUC_BUILD_UNIT_TESTS) 26 | # if (${IS_ARM}) 27 | # message (STATUS "Skipping tests for utils/d2c_messaging for ARM processor...") 28 | # else () 29 | # add_subdirectory (tests) 30 | # endif () 31 | #endif () 32 | -------------------------------------------------------------------------------- /src/utils/d2c_messaging/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (d2c_messaging_unit_test) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | find_package (Catch2 REQUIRED) 9 | 10 | add_executable (${PROJECT_NAME} ${sources}) 11 | 12 | target_sources (${PROJECT_NAME} PRIVATE d2c_messaging_ut.cpp) 13 | 14 | target_include_directories (${PROJECT_NAME} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 15 | 16 | target_link_libraries ( 17 | ${PROJECT_NAME} 18 | PRIVATE aduc::communication_abstraction 19 | aduc::d2c_messaging 20 | aduc::retry_utils 21 | Catch2::Catch2WithMain) 22 | 23 | target_link_libraries (${PROJECT_NAME} PRIVATE libaducpal) 24 | 25 | include (CTest) 26 | include (Catch) 27 | #catch_discover_tests (${PROJECT_NAME}) 28 | -------------------------------------------------------------------------------- /src/utils/eis_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name eis_utils) 4 | add_library (${target_name} STATIC src/eis_utils.c src/eis_coms.c src/eis_err.c) 5 | add_library (aduc::${target_name} ALIAS ${target_name}) 6 | 7 | target_include_directories (${target_name} PUBLIC inc) 8 | 9 | find_package (Parson REQUIRED) 10 | 11 | target_link_aziotsharedutil (${target_name} PRIVATE) 12 | 13 | target_link_libraries ( 14 | ${target_name} 15 | PUBLIC aduc::c_utils 16 | PRIVATE aduc::adu_types 17 | aduc::logging 18 | Parson::parson 19 | uhttp) 20 | 21 | if (ADUC_BUILD_UNIT_TESTS) 22 | add_subdirectory (tests) 23 | endif () 24 | -------------------------------------------------------------------------------- /src/utils/eis_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (eis_utils_unit_test) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources main.cpp eis_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${PROJECT_NAME} ${sources}) 15 | 16 | target_link_libraries ( 17 | ${PROJECT_NAME} 18 | PRIVATE aduc::adu_types 19 | aduc::c_utils 20 | aduc::eis_utils 21 | aduc::string_utils 22 | Catch2::Catch2WithMain) 23 | 24 | target_link_umock_c (${PROJECT_NAME} PRIVATE) 25 | target_link_aziotsharedutil (${PROJECT_NAME} PRIVATE) 26 | 27 | include (CTest) 28 | include (Catch) 29 | catch_discover_tests (${PROJECT_NAME}) 30 | -------------------------------------------------------------------------------- /src/utils/eis_utils/tests/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @brief crypto_utils tests main entry point. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | // https://github.com/catchorg/Catch2/blob/master/docs/own-main.md 9 | #include 10 | 11 | // https://github.com/Azure/umock-c/blob/master/doc/umock_c.md 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | int main(int argc, char* argv[]) 18 | { 19 | int result; 20 | 21 | // Global setup 22 | result = umock_c_init([](UMOCK_C_ERROR_CODE error_code) -> void { 23 | std::cerr << "*** umock_c failed, err=" << error_code << std::endl; 24 | }); 25 | if (result != 0) 26 | { 27 | std::cerr << "umock_c_init_failed, err=" << result << std::endl; 28 | return result; 29 | } 30 | 31 | result = Catch::Session().run(argc, argv); 32 | 33 | // Global cleanup. 34 | umock_c_deinit(); 35 | 36 | return result; 37 | } 38 | -------------------------------------------------------------------------------- /src/utils/entity_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name entity_utils) 2 | 3 | add_library (${target_name} INTERFACE) 4 | add_library (aduc::${target_name} ALIAS ${target_name}) 5 | 6 | target_include_directories (${target_name} INTERFACE inc) 7 | target_link_aziotsharedutil (${target_name} INTERFACE) 8 | -------------------------------------------------------------------------------- /src/utils/entity_utils/inc/aduc/auto_file_entity.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file auto_file_entity.hpp 3 | * @brief Defines AutoFileEntity class that houses and manages an ADUC_FileEntity member. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef AUTO_FILE_ENTITY 10 | #define AUTO_FILE_ENTITY 11 | 12 | #include // ADUC_FileEntity_Uninit 13 | #include // ADUC_FileEntity 14 | 15 | struct AutoFileEntity : public ADUC_FileEntity 16 | { 17 | AutoFileEntity() = default; 18 | 19 | AutoFileEntity(const AutoFileEntity&) = delete; 20 | AutoFileEntity& operator=(const AutoFileEntity&) = delete; 21 | AutoFileEntity(AutoFileEntity&&) = delete; 22 | AutoFileEntity& operator=(AutoFileEntity&&) = delete; 23 | 24 | ~AutoFileEntity() 25 | { 26 | ADUC_FileEntity_Uninit(this); 27 | } 28 | }; 29 | 30 | #endif // #define AUTO_FILE_ENTITY 31 | -------------------------------------------------------------------------------- /src/utils/exception_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name exception_utils) 4 | 5 | add_library (${target_name} INTERFACE) 6 | add_library (aduc::${target_name} ALIAS ${target_name}) 7 | 8 | target_include_directories (${target_name} INTERFACE inc ${ADUC_EXPORT_INCLUDES}) 9 | 10 | target_link_libraries (${target_name} INTERFACE aduc::logging) 11 | -------------------------------------------------------------------------------- /src/utils/extension_utils/inc/aduc/extension_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file extension_utils.h 3 | * @brief Utilities for the Device Update Agent extensibility. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADUC_EXTENSION_UTILS_H 9 | #define ADUC_EXTENSION_UTILS_H 10 | 11 | #include "aduc/types/update_content.h" // ADUC_FileEntity 12 | #include "aduc/types/workflow.h" // ADUC_WorkflowHandle 13 | #include // bool 14 | 15 | EXTERN_C_BEGIN 16 | 17 | bool GetDownloadHandlerFileEntity(const char* downloadHandlerId, ADUC_FileEntity* fileEntity); 18 | 19 | bool GetExtensionFileEntity(const char* extensionRegFile, ADUC_FileEntity* fileEntity); 20 | 21 | bool RegisterUpdateContentHandler(const char* updateType, const char* handlerFilePath); 22 | 23 | bool RegisterDownloadHandler(const char* downloadHandlerId, const char* handlerFilePath); 24 | 25 | bool RegisterComponentEnumeratorExtension(const char* extensionFilePath); 26 | 27 | bool RegisterContentDownloaderExtension(const char* extensionFilePath); 28 | 29 | bool RegisterExtension(const char* extensionDir, const char* extensionFilePath); 30 | 31 | EXTERN_C_END 32 | 33 | #endif // ADUC_EXTENSION_UTILS_H 34 | -------------------------------------------------------------------------------- /src/utils/file_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name file_utils) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | add_library (${target_name} STATIC "") 9 | add_library (aduc::${target_name} ALIAS ${target_name}) 10 | 11 | # Turn -fPIC on, in order to use this library in another shared library. 12 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 13 | 14 | target_include_directories (${target_name} PUBLIC inc) 15 | 16 | target_sources (${target_name} PRIVATE src/auto_opendir.cpp src/file_utils.cpp) 17 | 18 | target_link_libraries (${target_name} PRIVATE aduc::system_utils) 19 | 20 | target_link_libraries (${target_name} PRIVATE libaducpal) 21 | -------------------------------------------------------------------------------- /src/utils/file_utils/inc/aduc/file_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file file_utils.hpp 3 | * @brief Function prototypes for file utilities. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef FILE_TEST_UTILS_HPP 10 | #define FILE_TEST_UTILS_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace aduc 16 | { 17 | void findFilesInDir(const std::string& dirPath, std::vector* outPaths); 18 | 19 | } // namespace aduc 20 | 21 | #endif // FILE_UTILS_HPP 22 | -------------------------------------------------------------------------------- /src/utils/file_utils/src/auto_opendir.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file auto_opendir.hpp 3 | * @brief implementation of some AutoOpenDir methods. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #include "aduc/auto_opendir.hpp" 10 | #include 11 | 12 | #include 13 | 14 | namespace aduc 15 | { 16 | AutoOpenDir::AutoOpenDir(const std::string& dirPath) 17 | { 18 | DIR* d = ADUCPAL_opendir(dirPath.c_str()); 19 | if (d == nullptr) 20 | { 21 | throw std::invalid_argument("opendir failed"); 22 | } 23 | 24 | dirEntry = d; 25 | } 26 | 27 | AutoOpenDir::~AutoOpenDir() 28 | { 29 | if (dirEntry != nullptr) 30 | { 31 | ADUCPAL_closedir(dirEntry); 32 | dirEntry = nullptr; 33 | } 34 | } 35 | 36 | DIR* AutoOpenDir::GetDirectoryStreamHandle() 37 | { 38 | return dirEntry; 39 | } 40 | 41 | struct dirent* AutoOpenDir::NextDirEntry() 42 | { 43 | return ADUCPAL_readdir(dirEntry); 44 | } 45 | 46 | } // namespace aduc 47 | -------------------------------------------------------------------------------- /src/utils/hash_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name hash_utils) 4 | add_library (${target_name} STATIC src/hash_utils.c) 5 | add_library (aduc::${target_name} ALIAS ${target_name}) 6 | 7 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 8 | 9 | # 10 | # Turn -fPIC on, in order to use this library in another shared library. 11 | # 12 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 13 | 14 | find_package (Parson REQUIRED) 15 | 16 | target_link_aziotsharedutil (${target_name} PUBLIC) 17 | 18 | target_link_libraries ( 19 | ${target_name} 20 | PUBLIC aduc::c_utils aduc::adu_types Parson::parson 21 | PRIVATE aduc::logging aduc::string_utils) 22 | 23 | target_link_libraries (${target_name} PRIVATE libaducpal) 24 | 25 | if (ADUC_BUILD_UNIT_TESTS) 26 | add_subdirectory (tests) 27 | endif () 28 | -------------------------------------------------------------------------------- /src/utils/hash_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (hash_utils_unit_test) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources hash_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${PROJECT_NAME} ${sources}) 15 | 16 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::hash_utils aduc::system_utils aduc::string_utils Catch2::Catch2WithMain) 17 | 18 | include (CTest) 19 | include (Catch) 20 | catch_discover_tests (${PROJECT_NAME}) 21 | -------------------------------------------------------------------------------- /src/utils/installed_criteria_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name installed_criteria_utils) 4 | add_library (${target_name} STATIC src/installed_criteria_utils.cpp) 5 | add_library (aduc::${target_name} ALIAS ${target_name}) 6 | 7 | # 8 | # Turn -fPIC on, in order to use this library in another shared library. 9 | # 10 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 11 | 12 | find_package (Parson REQUIRED) 13 | 14 | target_compile_definitions ( 15 | ${target_name} PRIVATE ADUC_INSTALLEDCRITERIA_FILE_PATH="${ADUC_INSTALLEDCRITERIA_FILE_PATH}") 16 | 17 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 18 | 19 | target_link_libraries (${target_name} PRIVATE aduc::adu_core_interface aduc::logging Parson::parson) 20 | 21 | target_link_libraries (${target_name} PRIVATE libaducpal) 22 | 23 | if (ADUC_BUILD_UNIT_TESTS) 24 | add_subdirectory (tests) 25 | endif () 26 | -------------------------------------------------------------------------------- /src/utils/installed_criteria_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (installed_criteria_utils_unit_tests) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | find_package (Catch2 REQUIRED) 11 | 12 | add_executable (${PROJECT_NAME} "") 13 | 14 | target_include_directories (${PROJECT_NAME} PRIVATE ${ADUC_EXPORT_INCLUDES}) 15 | 16 | target_sources (${PROJECT_NAME} PRIVATE installed_criteria_utils_ut.cpp) 17 | 18 | # Windows needs all EXEs to have links to all potential libraries so this is included here 19 | if (WIN32) 20 | target_link_dosdk (${PROJECT_NAME} PRIVATE) 21 | endif () 22 | 23 | target_compile_definitions ( 24 | ${PROJECT_NAME} 25 | PRIVATE ADUC_INSTALLEDCRITERIA_FILE_PATH="${ADUC_TMP_DIR_PATH}/adu-test-installedcriteria") 26 | 27 | target_link_libraries ( 28 | ${PROJECT_NAME} PRIVATE aduc::adu_core_interface aduc::installed_criteria_utils 29 | aduc::platform_layer Catch2::Catch2WithMain) 30 | 31 | # Ensure that ctest discovers catch2 tests. 32 | # Use catch_discover_tests() rather than add_test() 33 | # See https://github.com/catchorg/Catch2/blob/master/contrib/Catch.cmake 34 | include (CTest) 35 | include (Catch) 36 | catch_discover_tests (${PROJECT_NAME}) 37 | -------------------------------------------------------------------------------- /src/utils/jws_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name jws_utils) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | add_library (${target_name} STATIC src/jws_utils.c) 9 | add_library (aduc::${target_name} ALIAS ${target_name}) 10 | 11 | find_package (Parson REQUIRED) 12 | 13 | # 14 | # Turn -fPIC on, in order to use this library in another shared library. 15 | # 16 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 17 | 18 | target_include_directories (${target_name} PUBLIC inc) 19 | 20 | target_link_aziotsharedutil (${target_name} PRIVATE) 21 | 22 | target_link_libraries ( 23 | ${target_name} 24 | PUBLIC aduc::crypto_utils aduc::c_utils 25 | PRIVATE aduc::logging aduc::root_key_utils Parson::parson) 26 | 27 | if (ADUC_BUILD_UNIT_TESTS) 28 | add_subdirectory (tests) 29 | endif () 30 | -------------------------------------------------------------------------------- /src/utils/jws_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (jws_utils_unit_test) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources jws_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | find_package (OpenSSL REQUIRED) 14 | 15 | add_executable (${PROJECT_NAME} ${sources}) 16 | 17 | target_link_aziotsharedutil (${PROJECT_NAME} PRIVATE) 18 | 19 | target_compile_definitions (${PROJECT_NAME} 20 | PRIVATE ADUC_TEST_DATA_FOLDER="${ADUC_TEST_DATA_FOLDER}") 21 | 22 | target_link_libraries ( 23 | ${PROJECT_NAME} 24 | PRIVATE aduc::jws_utils 25 | aduc::crypto_utils 26 | aduc::root_key_utils 27 | aduc::rootkeypackage_utils 28 | aduc::string_utils 29 | aduc::system_utils 30 | Catch2::Catch2WithMain 31 | OpenSSL::Crypto) 32 | 33 | include (CTest) 34 | include (Catch) 35 | catch_discover_tests (${PROJECT_NAME}) 36 | -------------------------------------------------------------------------------- /src/utils/parser_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name parser_utils) 4 | add_library (${target_name} STATIC src/parser_utils.c) 5 | add_library (aduc::${target_name} ALIAS ${target_name}) 6 | 7 | target_include_directories (${target_name} PUBLIC inc ${ADUC_TYPES_INCLUDES} 8 | ${ADUC_EXPORT_INCLUDES}) 9 | 10 | # 11 | # Turn -fPIC on, in order to use this library in another shared library. 12 | # 13 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 14 | 15 | find_package (Parson REQUIRED) 16 | 17 | target_link_aziotsharedutil (${target_name} PRIVATE) 18 | 19 | target_link_libraries ( 20 | ${target_name} 21 | PUBLIC aduc::adu_types Parson::parson 22 | PRIVATE aduc::hash_utils aduc::logging aduc::parson_json_utils) 23 | 24 | if (ADUC_BUILD_UNIT_TESTS) 25 | add_subdirectory (tests) 26 | endif () 27 | -------------------------------------------------------------------------------- /src/utils/parser_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (parser_utils_unit_test) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | find_package (Catch2 REQUIRED) 9 | find_package (Parson REQUIRED) 10 | 11 | add_executable (${PROJECT_NAME} ${sources} "") 12 | 13 | target_sources (${PROJECT_NAME} PRIVATE parser_utils_ut.cpp) 14 | 15 | target_include_directories (${PROJECT_NAME} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 16 | 17 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::hash_utils aduc::parser_utils aduc::string_utils Catch2::Catch2WithMain) 18 | 19 | target_compile_definitions (${PROJECT_NAME} 20 | PRIVATE ADUC_TEST_DATA_FOLDER="${ADUC_TEST_DATA_FOLDER}") 21 | 22 | include (CTest) 23 | include (Catch) 24 | catch_discover_tests (${PROJECT_NAME}) 25 | -------------------------------------------------------------------------------- /src/utils/parson_json_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name parson_json_utils) 4 | add_library (${target_name} STATIC src/parson_json_utils.c) 5 | add_library (aduc::${target_name} ALIAS ${target_name}) 6 | target_include_directories (${target_name} PUBLIC inc) 7 | 8 | # 9 | # Turn -fPIC on, in order to use this library in another shared library. 10 | # 11 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 12 | 13 | find_package (Parson REQUIRED) 14 | 15 | target_link_libraries ( 16 | ${target_name} 17 | PUBLIC aduc::c_utils Parson::parson 18 | PRIVATE aduc::logging) 19 | 20 | target_link_aziotsharedutil (${target_name} PRIVATE) 21 | target_link_umock_c (${target_name} PRIVATE) 22 | -------------------------------------------------------------------------------- /src/utils/path_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name path_utils) 2 | 3 | add_library (${target_name} STATIC "") 4 | add_library (aduc::${target_name} ALIAS ${target_name}) 5 | 6 | target_sources (${target_name} PRIVATE src/path_utils.c) 7 | 8 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 9 | 10 | # 11 | # Turn -fPIC on, in order to use this library in another shared library. 12 | # 13 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 14 | 15 | target_link_libraries ( 16 | ${target_name} 17 | PUBLIC aduc::c_utils 18 | PRIVATE libaducpal) 19 | 20 | target_link_aziotsharedutil (${target_name} PRIVATE) 21 | 22 | if (ADUC_BUILD_UNIT_TESTS) 23 | add_subdirectory (tests) 24 | endif () 25 | -------------------------------------------------------------------------------- /src/utils/path_utils/inc/aduc/path_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file path_utils.h 3 | * @brief Utilities for working with paths. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef ADUC_PATH_UTILS_H 9 | #define ADUC_PATH_UTILS_H 10 | 11 | #include // EXTERN_C_BEGIN, EXTERN_C_END 12 | #include // STRING_HANDLE 13 | 14 | EXTERN_C_BEGIN 15 | 16 | STRING_HANDLE PathUtils_SanitizePathSegment(const char* unsanitized); 17 | 18 | char* PathUtils_ConcatenateDirAndFolderPaths(const char* dirPath, const char* folderName); 19 | 20 | EXTERN_C_END 21 | 22 | #endif // ADUC_PATH_UTILS_H 23 | -------------------------------------------------------------------------------- /src/utils/path_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (path_utils_unit_tests) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | find_package (Catch2 REQUIRED) 11 | 12 | add_executable (${PROJECT_NAME} "") 13 | 14 | target_sources (${PROJECT_NAME} PRIVATE path_utils_ut.cpp) 15 | 16 | target_link_aziotsharedutil (${PROJECT_NAME} PRIVATE) 17 | 18 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::path_utils aduc::string_utils Catch2::Catch2WithMain) 19 | 20 | include (CTest) 21 | include (Catch) 22 | catch_discover_tests (${PROJECT_NAME}) 23 | -------------------------------------------------------------------------------- /src/utils/permission_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name permission_utils) 4 | 5 | include (agentRules) 6 | compileasc99 () 7 | 8 | add_library (${target_name} STATIC src/permission_utils.c) 9 | add_library (aduc::${target_name} ALIAS ${target_name}) 10 | 11 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 12 | 13 | # 14 | # Turn -fPIC on, in order to use this library in another shared library. 15 | # 16 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 17 | 18 | target_link_libraries (${target_name} PUBLIC aduc::c_utils) 19 | 20 | target_link_libraries (${target_name} PRIVATE libaducpal) 21 | 22 | if (ADUC_BUILD_UNIT_TESTS) 23 | add_subdirectory (tests) 24 | endif () 25 | -------------------------------------------------------------------------------- /src/utils/permission_utils/inc/aduc/permission_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file permission_utils.h 3 | * @brief Utilities for working with user, group, and file permissions. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #ifndef _PERMISSION_UTILS_H_ 9 | #define _PERMISSION_UTILS_H_ 10 | 11 | #include // for EXTERN_C_* 12 | #include // for bool 13 | 14 | #include // uid_t, gid_t, mode_t 15 | 16 | EXTERN_C_BEGIN 17 | 18 | bool PermissionUtils_VerifyFilemodeExact(const char* path, mode_t expectedPermissions); 19 | bool PermissionUtils_VerifyFilemodeBitmask(const char* path, mode_t bitmask); 20 | bool PermissionUtils_UserExists(const char* user); 21 | bool PermissionUtils_GroupExists(const char* group); 22 | bool PermissionUtils_UserInSupplementaryGroup(const char* user, const char* group); 23 | bool PermissionUtils_CheckOwnership(const char* path, const char* user, const char* group); 24 | bool PermissionUtils_CheckOwnerUid(const char* path, uid_t uid); 25 | bool PermissionUtils_CheckOwnerGid(const char* path, gid_t gid); 26 | bool PermissionUtils_SetProcessEffectiveUID(const char* name); 27 | bool PermissionUtils_SetProcessEffectiveGID(const char* name); 28 | 29 | EXTERN_C_END 30 | 31 | #endif // PERMISSION_UTILS_H 32 | -------------------------------------------------------------------------------- /src/utils/permission_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (permission_utils_unit_test) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources permission_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${PROJECT_NAME} ${sources}) 15 | 16 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::permission_utils aduc::system_utils 17 | Catch2::Catch2WithMain) 18 | 19 | target_link_libraries (${PROJECT_NAME} PRIVATE libaducpal) 20 | 21 | include (CTest) 22 | include (Catch) 23 | catch_discover_tests (${PROJECT_NAME}) 24 | -------------------------------------------------------------------------------- /src/utils/process_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name process_utils) 4 | add_library (${target_name} STATIC src/process_utils.cpp) 5 | add_library (aduc::${target_name} ALIAS ${target_name}) 6 | 7 | # 8 | # Turn -fPIC on, in order to use this library in another shared library. 9 | # 10 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 11 | 12 | target_include_directories (${target_name} PUBLIC inc) 13 | 14 | target_link_libraries (${target_name} PRIVATE aduc::logging aduc::c_utils aduc::config_utils 15 | aduc::string_utils) 16 | 17 | target_link_aziotsharedutil (${target_name} PUBLIC) 18 | target_link_libraries (${target_name} PUBLIC libaducpal) 19 | 20 | if (WIN32) 21 | target_compile_definitions (${target_name} PRIVATE WIN32="${WIN32}") 22 | endif () 23 | 24 | if (ADUC_BUILD_UNIT_TESTS) 25 | add_subdirectory (tests) 26 | add_subdirectory (test_helper) 27 | endif () 28 | -------------------------------------------------------------------------------- /src/utils/process_utils/test_helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (process_utils_tests_helper) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources main.cpp) 11 | 12 | add_executable (${PROJECT_NAME} ${sources}) 13 | 14 | if (WIN32) 15 | find_package(unofficial-getopt-win32 REQUIRED) 16 | target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::getopt-win32::getopt) 17 | endif () 18 | 19 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::process_utils) 20 | -------------------------------------------------------------------------------- /src/utils/process_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (process_utils_unit_tests) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources process_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${PROJECT_NAME} ${sources}) 15 | 16 | target_link_aziotsharedutil (${PROJECT_NAME} PRIVATE) 17 | 18 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::process_utils Catch2::Catch2WithMain) 19 | 20 | include (CTest) 21 | include (Catch) 22 | catch_discover_tests (${PROJECT_NAME}) 23 | -------------------------------------------------------------------------------- /src/utils/reporting_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name reporting_utils) 2 | 3 | include (agentRules) 4 | compileasc99 () 5 | 6 | add_library (${target_name} STATIC src/reporting_utils.c) 7 | add_library (aduc::${target_name} ALIAS ${target_name}) 8 | 9 | target_link_aziotsharedutil (${target_name} PUBLIC) 10 | 11 | target_include_directories (${target_name} PUBLIC inc) 12 | 13 | target_link_libraries ( 14 | ${target_name} 15 | PUBLIC aduc::c_utils 16 | PRIVATE aduc::logging) 17 | 18 | if (ADUC_BUILD_UNIT_TESTS) 19 | add_subdirectory (tests) 20 | endif () 21 | -------------------------------------------------------------------------------- /src/utils/reporting_utils/inc/aduc/reporting_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef ADUC_REPORTING_UTILS_H 2 | #define ADUC_REPORTING_UTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | EXTERN_C_BEGIN 11 | 12 | STRING_HANDLE ADUC_ReportingUtils_CreateReportingErcHexStr(const int32_t erc, bool is_first); 13 | STRING_HANDLE ADUC_ReportingUtils_StringHandleFromVectorInt32(VECTOR_HANDLE vec, size_t max); 14 | 15 | EXTERN_C_END 16 | 17 | #endif // ADUC_REPORTING_UTILS_H 18 | -------------------------------------------------------------------------------- /src/utils/reporting_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (reporting_utils_unit_tests) 2 | 3 | include (agentRules) 4 | compileasc99 () 5 | disablertti () 6 | 7 | find_package (Catch2 REQUIRED) 8 | 9 | add_executable (${PROJECT_NAME}) 10 | target_sources (${PROJECT_NAME} PRIVATE reporting_utils_ut.cpp) 11 | 12 | target_link_aziotsharedutil (${PROJECT_NAME} PRIVATE) 13 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::c_utils aduc::reporting_utils 14 | aduc::string_utils Catch2::Catch2WithMain) 15 | 16 | include (CTest) 17 | include (Catch) 18 | catch_discover_tests (${PROJECT_NAME}) 19 | -------------------------------------------------------------------------------- /src/utils/retry_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | include (agentRules) 4 | 5 | set (target_name retry_utils) 6 | add_library (${target_name} STATIC src/retry_utils.c) 7 | add_library (aduc::${target_name} ALIAS ${target_name}) 8 | 9 | target_include_directories (${target_name} PUBLIC ./inc ${ADUC_TYPES_INCLUDES} 10 | ${ADUC_EXPORT_INCLUDES}) 11 | 12 | # 13 | # Turn -fPIC on, in order to use this library in another shared library. 14 | # 15 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 16 | 17 | target_link_aziotsharedutil (${target_name} PRIVATE) 18 | 19 | target_link_libraries ( 20 | ${target_name} 21 | PUBLIC aduc::adu_types 22 | PRIVATE aduc::communication_abstraction aduc::logging) 23 | 24 | target_link_libraries (${target_name} PUBLIC libaducpal) 25 | -------------------------------------------------------------------------------- /src/utils/root_key_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name root_key_utils) 4 | 5 | include (agentRules) 6 | compileasc99 () 7 | 8 | add_library (${target_name} STATIC) 9 | add_library (aduc::${target_name} ALIAS ${target_name}) 10 | 11 | target_sources (${target_name} PRIVATE src/root_key_util.c src/root_key_list.c src/root_key_store.c) 12 | 13 | target_include_directories (${target_name} PUBLIC inc) 14 | 15 | target_link_aziotsharedutil (${target_name} PUBLIC) 16 | find_package (umock_c REQUIRED CONFIG) 17 | 18 | # 19 | # Turn -fPIC on, in order to use this library in another shared library. 20 | # 21 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 22 | 23 | target_link_libraries ( 24 | ${target_name} 25 | PUBLIC aduc::c_utils aduc::crypto_utils aduc::rootkeypackage_utils umock_c 26 | PRIVATE aduc::logging aduc::system_utils libaducpal) 27 | 28 | target_compile_definitions ( 29 | ${target_name} PRIVATE ADUC_ROOTKEY_STORE_PACKAGE_PATH="${ADUC_ROOTKEY_STORE_PACKAGE_PATH}" 30 | EMBED_TEST_ROOT_KEYS=${EMBED_TEST_ROOT_KEYS}) 31 | 32 | if (ADUC_BUILD_UNIT_TESTS) 33 | add_subdirectory (tests) 34 | endif () 35 | -------------------------------------------------------------------------------- /src/utils/root_key_utils/inc/root_key_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file root_key_list.h 3 | * @brief Defines functions for getting the hardcoded root keys 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #include "aduc/c_utils.h" 9 | #include 10 | 11 | #ifndef ROOT_KEY_LIST_H 12 | # define ROOT_KEY_LIST_H 13 | 14 | EXTERN_C_BEGIN 15 | 16 | typedef struct tagRSARootKey 17 | { 18 | const char* kid; 19 | const char* N; 20 | const unsigned int e; 21 | } RSARootKey; 22 | 23 | MOCKABLE_FUNCTION(, const RSARootKey*, RootKeyList_GetHardcodedRsaRootKeys, ) 24 | 25 | MOCKABLE_FUNCTION(, size_t, RootKeyList_numHardcodedKeys, ) 26 | 27 | EXTERN_C_END 28 | 29 | #endif // ROOT_KEY_LIST_H 30 | -------------------------------------------------------------------------------- /src/utils/root_key_utils/inc/root_key_store.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file root_key_store.h 3 | * @brief Defines the function for returning the path to the local store of the root key package 4 | * @details Functions are mockable for testing purposes 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #include "aduc/c_utils.h" 10 | #include 11 | #ifndef ROOT_KEY_STORE_H 12 | # define ROOT_KEY_STORE_H 13 | 14 | EXTERN_C_BEGIN 15 | 16 | MOCKABLE_FUNCTION(, const char*, RootKeyStore_GetRootKeyStorePath, ); 17 | 18 | EXTERN_C_END 19 | #endif // ROOT_KEY_STORE_H 20 | -------------------------------------------------------------------------------- /src/utils/root_key_utils/src/root_key_store.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file root_key_utility.c 3 | * @brief Implements a static list of root keys used to verify keys and messages within crypto_lib and it's callers. 4 | * these have exponents and parameters that have been extracted from their certs 5 | * to ease the computation process but remain the same as the ones issued by the Authority 6 | * 7 | * @copyright Copyright (c) Microsoft Corporation. 8 | * Licensed under the MIT License. 9 | */ 10 | #include "root_key_store.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | // 17 | // Surfaces the hardcoded package path for the root key package 18 | // 19 | 20 | #ifndef ADUC_ROOTKEY_STORE_PACKAGE_PATH 21 | # error "ADUC_ROOTKEY_STORE_PACKAGE_PATH must be defined" 22 | #endif 23 | 24 | const char* RootKeyStore_GetRootKeyStorePath() 25 | { 26 | return ADUC_ROOTKEY_STORE_PACKAGE_PATH; 27 | } 28 | -------------------------------------------------------------------------------- /src/utils/root_key_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (root_key_utils_ut) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | find_package (Catch2 REQUIRED) 11 | find_package (umock_c REQUIRED CONFIG) 12 | 13 | set (sources main.cpp root_key_utils_ut.cpp) 14 | 15 | add_executable (${PROJECT_NAME}) 16 | 17 | target_sources (${PROJECT_NAME} PRIVATE main.cpp root_key_utils_ut.cpp) 18 | 19 | target_compile_definitions (${PROJECT_NAME} 20 | PRIVATE ADUC_TEST_DATA_FOLDER="${ADUC_TEST_DATA_FOLDER}") 21 | 22 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::root_key_utils aduc::rootkeypackage_utils 23 | aduc::string_utils Catch2::Catch2WithMain umock_c) 24 | 25 | include (CTest) 26 | include (Catch) 27 | catch_discover_tests (${PROJECT_NAME}) 28 | -------------------------------------------------------------------------------- /src/utils/root_key_utils/tests/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @brief crypto_utils tests main entry point. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #include 9 | 10 | // https://github.com/Azure/umock-c/blob/master/doc/umock_c.md 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | int result; 19 | 20 | // Global setup 21 | result = umock_c_init([](UMOCK_C_ERROR_CODE error_code) -> void { 22 | std::cout << "*** umock_c failed, err=" << error_code << std::endl; 23 | }); 24 | if (result != 0) 25 | { 26 | std::cout << "umock_c_init_failed, err=" << result << std::endl; 27 | return result; 28 | } 29 | 30 | result = Catch::Session().run(argc, argv); 31 | if (result != 0) 32 | { 33 | std::cout << "Catch session failed, err=" << result << std::endl; 34 | } 35 | 36 | // Global cleanup. 37 | umock_c_deinit(); 38 | 39 | return result; 40 | } 41 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/inc/aduc/rootkeypackage_curl_download.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file rootkeypackage_curl_download.h 4 | * @brief The root key package curl download header. 5 | * 6 | * @copyright Copyright (c) Microsoft Corporation. 7 | * Licensed under the MIT License. 8 | */ 9 | 10 | #ifndef ROOTKEYPACKAGE_CURL_DOWNLOAD_H 11 | #define ROOTKEYPACKAGE_CURL_DOWNLOAD_H 12 | 13 | #include 14 | #include 15 | 16 | EXTERN_C_BEGIN 17 | 18 | ADUC_Result DownloadRootKeyPkg_Curl(const char* url, const char* targetFilePath); 19 | 20 | EXTERN_C_END 21 | 22 | #endif // ROOTKEYPACKAGE_CURL_DOWNLOAD_H 23 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/inc/aduc/rootkeypackage_do_download.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file rootkeypackage_do_download.h 4 | * @brief The root key package delivery optimization download header. 5 | * 6 | * @copyright Copyright (c) Microsoft Corporation. 7 | * Licensed under the MIT License. 8 | */ 9 | 10 | #ifndef ROOTKEYPACKAGE_DO_DOWNLOAD_H 11 | #define ROOTKEYPACKAGE_DO_DOWNLOAD_H 12 | 13 | #include 14 | #include 15 | 16 | EXTERN_C_BEGIN 17 | 18 | ADUC_Result DownloadRootKeyPkg_DO(const char* url, const char* targetFilePath); 19 | 20 | EXTERN_C_END 21 | 22 | #endif // ROOTKEYPACKAGE_DO_DOWNLOAD_H 23 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/inc/aduc/rootkeypackage_download.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file rootkeypackage_download.h 4 | * @brief The root key package download header. 5 | * 6 | * @copyright Copyright (c) Microsoft Corporation. 7 | * Licensed under the MIT License. 8 | */ 9 | 10 | #ifndef ROOTKEYPACKAGE_DOWNLOAD_H 11 | #define ROOTKEYPACKAGE_DOWNLOAD_H 12 | 13 | #include 14 | 15 | typedef ADUC_Result (*RootKeyPkgDownloadFunc)(const char* rootKeyPkgUrl, const char* targetFilePath); 16 | 17 | /** 18 | * @brief Root key package downloader info. 19 | * 20 | */ 21 | typedef struct tagADUC_RootKeyPkgDownloaderInfo 22 | { 23 | const char* name; /**< The name of the package downloader. */ 24 | RootKeyPkgDownloadFunc downloadFn; /**< The downloader function. */ 25 | const char* 26 | downloadBaseDir; /**< The base directory under which to create a download sandbox dir for the file download. */ 27 | } ADUC_RootKeyPkgDownloaderInfo; 28 | 29 | #endif // ROOTKEYPACKAGE_DOWNLOAD_H 30 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name rootkeypackage_utils_unit_test) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | find_package (Catch2 REQUIRED) 9 | find_package (Parson REQUIRED) 10 | 11 | add_executable (${target_name}) 12 | target_sources (${target_name} PRIVATE src/rootkeypackage_utils_ut.cpp 13 | src/rootkeypackage_download_ut.cpp) 14 | 15 | target_link_aziotsharedutil (${target_name} PRIVATE) 16 | target_include_directories (${target_name} PRIVATE inc) 17 | 18 | target_link_libraries ( 19 | ${target_name} 20 | PRIVATE aduc::rootkeypackage_utils 21 | aduc::test_utils 22 | aduc::crypto_utils 23 | aduc::c_utils 24 | aduc::hash_utils 25 | aduc::system_utils 26 | Catch2::Catch2WithMain 27 | Parson::parson) 28 | 29 | target_compile_definitions (${target_name} PRIVATE ADUC_TEST_DATA_FOLDER="${ADUC_TEST_DATA_FOLDER}") 30 | 31 | include (CTest) 32 | include (Catch) 33 | catch_discover_tests (${target_name}) 34 | 35 | add_subdirectory (testapp) 36 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/tests/scripts/rootkeypkg/rootkeyfiles/README.md: -------------------------------------------------------------------------------- 1 | # Test Data for rootkeypackage_utils 2 | 3 | ## Root Key Package 4 | 5 | The root key package is rootkey.json file. 6 | 7 | ## create_and_verify_signatures.sh 8 | 9 | create_and_verify_signatures.sh will: 10 | 11 | - Generate private and public keys, 12 | - Create rootkey.data.json.testrootX.(base64 | binary).sig, 13 | - and verify the signatures against rootkey.data.json data that was signed. 14 | 15 | ## Key pairs 16 | 17 | Regenerate the key by doing: 18 | 19 | ```bash 20 | openssl genrsa 2048 | openssl base64 > testrootX.base64.txt 21 | ``` 22 | 23 | ## Modulus and Exponent 24 | 25 | Get the RSA modulus and exponent by doing: 26 | 27 | ```bash 28 | openssl rsa -pubin -inform PEM -text -noout < pubX.pem 29 | ``` 30 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/tests/scripts/rootkeypkg/rootkeyfiles/modulus_1.base64url.txt: -------------------------------------------------------------------------------- 1 | AK0s6dGfMRRbOn90osTP4hZ4vhxuRn3bH45u3yjUp0R5guueqGs1k6VIAtBgq87PMWMCEaE8hWyEGQEH-HCaQNhClSJFsT7JR7l1JghkRRraDqfpv2BIGdk9-jRtHWxTrszwxi51MNhMMmaz2aizyiMLFj-qh4CNBUVskexUKBn2Ko4yrG0tl7dqBZA7fNdtVymK8SyFnt4GIFLLcKgnc0_NqwLc6S7zFQ--EbXuah32_Fw9rp7ZZpp6RPYzMoc2DnTarFGLhk8tzQQCTYOToAFQCDVq3KBSWkjY5QWbh2LZO-NeKNg0pG6aSOZlopf5ebuK0mEFoyB1oc6ne3HSem8 2 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/tests/scripts/rootkeypkg/rootkeyfiles/modulus_2.base64url.txt: -------------------------------------------------------------------------------- 1 | AMmbcWZ5Aa5mcxRexjQPV2FBWgUpdTKnCxIKhlvT1MkuPCyua-zwVwwpxeHubtOFXCidjyjyx8Eb_f2RmEHnlSWFaASKJhDiEl11xyn_dD8GCrMBalyC8wfQGmFL37YKdprm31Y_eBIquRirxcK-8qmN2Ko-rUkljYunlfhSbeMqbYeAiKcmT664sZ7yNNoFDkhdV8MJPD1YDNmv_RSln5RUmHje6fezkZHV5wPNl3mF_YdkRzKJrWTAgrTaY1poqC4FF8kHkukKtUNsHwDzmavmph2sqvw8cuXW_SmyHtdwHWxL9gQqEJci9XykgUFokRoZEsT8KyrrHi6fdI9cY4U 2 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/tests/scripts/rootkeypkg/rootkeyfiles/root2.sig.base64.txt: -------------------------------------------------------------------------------- 1 | qUtUfzf1k3QyIx70SObEB30b1LcIGu38kvFGEu5J9eTVcUgE+QSJ0R/LndIk/q1P 2 | Bqlk3KjbqWQKn6HERYR4r+/vG8PmHb0VEzA9mC5IO/4so2NxiGbJSVTHrznEw4EG 3 | D+Qb5L6RGcl5BBK2v3czWbi3Tv5+wu9v6Nzj1F4+ZYCYgMd4PJP0czfFN8//d2Zf 4 | EarxekrjbIi3pQ3V8qE6Abo7r4nEU65nK8ksB2rfXOcPYHCaOdNM+m1viXhf4Bay 5 | GG4HCLj8WqxLs/hFp196ki0GztKblvC9CnuPBk5YOnbmlT2j9I6FtXuzEhefQ0K3 6 | rut4jR3k5CtdoachHCrLAw== 7 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/tests/scripts/rootkeypkg/rootkeyfiles/rootkey.data.json: -------------------------------------------------------------------------------- 1 | {"isTest":false,"version":1,"published":1667343602,"disabledRootKeys":["rootkey2"],"disabledSigningKeys":[{"alg":"SHA256","hash":"sVMpGd8aPo17piBBc-f1Bki0iCJPZmKvA43GG3SsG1E"}],"rootKeys":{"rootkey1":{"keyType":"RSA","n":"AK0s6dGfMRRbOn90osTP4hZ4vhxuRn3bH45u3yjUp0R5guueqGs1k6VIAtBgq87PMWMCEaE8hWyEGQEH-HCaQNhClSJFsT7JR7l1JghkRRraDqfpv2BIGdk9-jRtHWxTrszwxi51MNhMMmaz2aizyiMLFj-qh4CNBUVskexUKBn2Ko4yrG0tl7dqBZA7fNdtVymK8SyFnt4GIFLLcKgnc0_NqwLc6S7zFQ--EbXuah32_Fw9rp7ZZpp6RPYzMoc2DnTarFGLhk8tzQQCTYOToAFQCDVq3KBSWkjY5QWbh2LZO-NeKNg0pG6aSOZlopf5ebuK0mEFoyB1oc6ne3HSem8","e":65537},"rootkey2":{"keyType":"RSA","n":"AMmbcWZ5Aa5mcxRexjQPV2FBWgUpdTKnCxIKhlvT1MkuPCyua-zwVwwpxeHubtOFXCidjyjyx8Eb_f2RmEHnlSWFaASKJhDiEl11xyn_dD8GCrMBalyC8wfQGmFL37YKdprm31Y_eBIquRirxcK-8qmN2Ko-rUkljYunlfhSbeMqbYeAiKcmT664sZ7yNNoFDkhdV8MJPD1YDNmv_RSln5RUmHje6fezkZHV5wPNl3mF_YdkRzKJrWTAgrTaY1poqC4FF8kHkukKtUNsHwDzmavmph2sqvw8cuXW_SmyHtdwHWxL9gQqEJci9XykgUFokRoZEsT8KyrrHi6fdI9cY4U","e":65537}}} 2 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/tests/testapp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name rootkeypackage_test_app) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | add_executable (${target_name}) 9 | target_sources (${target_name} PRIVATE src/main.cpp) 10 | 11 | target_link_aziotsharedutil (${target_name} INTERFACE) 12 | target_link_libraries (${target_name} PRIVATE aduc::rootkeypackage_utils aduc::test_utils) 13 | 14 | if (ROOTKEY_PKG_DOWNLOAD_USE_CURL) 15 | target_compile_definitions (${target_name} PRIVATE ROOTKEY_PKG_DOWNLOAD_USE_CURL=1) 16 | else () 17 | target_compile_definitions (${target_name} PRIVATE ROOTKEY_PKG_DOWNLOAD_USE_CURL=0) 18 | endif () 19 | -------------------------------------------------------------------------------- /src/utils/rootkeypackage_utils/tests/testapp/README.md: -------------------------------------------------------------------------------- 1 | 2 | # rootkeypackage test app 3 | 4 | ## Setup and run python http server 5 | 6 | - Ensure deliveryoptimization-agent is installed and running 7 | - Ensure `adu` user is in `do` group and `do` user is in `do` and `adu` groups 8 | - Run following steps: 9 | 10 | ```sh 11 | sudo rm -rf /tmp/deviceupdate/rootkey_download_test_app 12 | mkdir /tmp/htdocs 13 | cp src/utils/rootkeypackage_utils/tests/scripts/rootkeypkg/rootkeyfiles/rootkey.json /tmp/htdocs/ 14 | pushd /tmp/htdocs 15 | python3 -m http.server 8083 & 16 | popd 17 | ``` 18 | 19 | ## Run as adu user 20 | 21 | ```sh 22 | sudo -u adu ./out/bin/rootkeypackage_test_app 23 | ``` 24 | -------------------------------------------------------------------------------- /src/utils/string_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name string_utils) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | 9 | add_library (${target_name} STATIC src/string_utils.cpp) 10 | add_library (aduc::${target_name} ALIAS ${target_name}) 11 | 12 | target_include_directories (${target_name} PUBLIC inc) 13 | 14 | # 15 | # Turn -fPIC on, in order to use this library in another shared library. 16 | # 17 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 18 | 19 | if (ADUC_BUILD_UNIT_TESTS) 20 | add_subdirectory (tests) 21 | endif () 22 | -------------------------------------------------------------------------------- /src/utils/string_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (string_utils_unit_tests) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources string_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${PROJECT_NAME} ${sources}) 15 | 16 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::string_utils Catch2::Catch2WithMain) 17 | 18 | include (CTest) 19 | include (Catch) 20 | catch_discover_tests (${PROJECT_NAME}) 21 | -------------------------------------------------------------------------------- /src/utils/system_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name system_utils) 4 | include (agentRules) 5 | 6 | compileasc99 () 7 | 8 | add_library (${target_name} STATIC src/system_utils.c) 9 | add_library (aduc::${target_name} ALIAS ${target_name}) 10 | 11 | target_include_directories (${target_name} PUBLIC inc) 12 | 13 | # 14 | # Turn -fPIC on, in order to use this library in another shared library. 15 | # 16 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 17 | 18 | target_link_aziotsharedutil (${target_name} PUBLIC) 19 | 20 | target_link_libraries ( 21 | ${target_name} 22 | PUBLIC aduc::c_utils 23 | PRIVATE aduc::logging) 24 | 25 | target_link_libraries (${target_name} PUBLIC libaducpal) 26 | 27 | target_compile_definitions (${target_name} PRIVATE ADUC_FILE_GROUP="${ADUC_FILE_GROUP}" 28 | ADUC_FILE_USER="${ADUC_FILE_USER}") 29 | 30 | if (ADUC_BUILD_UNIT_TESTS) 31 | add_subdirectory (tests) 32 | endif () 33 | -------------------------------------------------------------------------------- /src/utils/system_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | project (system_utils_unit_tests) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | set (sources system_utils_ut.cpp) 11 | 12 | find_package (Catch2 REQUIRED) 13 | 14 | add_executable (${PROJECT_NAME} ${sources}) 15 | 16 | target_link_libraries (${PROJECT_NAME} PRIVATE aduc::file_utils aduc::string_utils 17 | aduc::system_utils Catch2::Catch2WithMain) 18 | 19 | target_link_libraries (${PROJECT_NAME} PRIVATE libaducpal) 20 | 21 | include (CTest) 22 | include (Catch) 23 | catch_discover_tests (${PROJECT_NAME}) 24 | -------------------------------------------------------------------------------- /src/utils/test_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name test_utils) 2 | 3 | include (agentRules) 4 | 5 | compileasc99 () 6 | disablertti () 7 | 8 | add_library (${target_name} STATIC "") 9 | add_library (aduc::${target_name} ALIAS ${target_name}) 10 | 11 | target_include_directories (${target_name} PUBLIC inc) 12 | 13 | target_sources (${target_name} PRIVATE src/auto_dir.cpp src/file_test_utils.cpp) 14 | 15 | target_link_libraries ( 16 | ${target_name} 17 | PRIVATE aduc::system_utils 18 | PUBLIC aduc::workflow_utils) 19 | 20 | target_link_libraries (${target_name} PRIVATE libaducpal) 21 | -------------------------------------------------------------------------------- /src/utils/test_utils/inc/aduc/file_test_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file file_test_utils.hpp 3 | * @brief Function prototypes for file test utilities. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef FILE_TEST_UTILS_HPP 10 | #define FILE_TEST_UTILS_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace aduc 16 | { 17 | std::string FileTestUtils_slurpFile(const std::string& path); 18 | 19 | std::string FileTestUtils_applyTemplateParam( 20 | const std::string& templateStr, const char* parameterName, const char* parameterValue); 21 | 22 | } // namespace aduc 23 | 24 | #endif // FILE_TEST_UTILS_HPP 25 | -------------------------------------------------------------------------------- /src/utils/test_utils/src/auto_dir.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file audo_dir.hpp 3 | * @brief implementation of some AutoDir methods. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #include "aduc/auto_dir.hpp" 10 | #include // [ADUC_]SystemUtils_* 11 | 12 | namespace aduc 13 | { 14 | AutoDir::~AutoDir() 15 | { 16 | if (SystemUtils_IsDir(dir.c_str(), nullptr)) 17 | { 18 | ADUC_SystemUtils_RmDirRecursive(dir.c_str()); 19 | } 20 | } 21 | 22 | bool AutoDir::RemoveDir() const 23 | { 24 | if (SystemUtils_IsDir(dir.c_str(), nullptr)) 25 | { 26 | return 0 == ADUC_SystemUtils_RmDirRecursive(dir.c_str()); 27 | } 28 | 29 | return true; 30 | } 31 | 32 | bool AutoDir::CreateDir() const 33 | { 34 | if (SystemUtils_IsDir(dir.c_str(), nullptr)) 35 | { 36 | return false; 37 | } 38 | 39 | return 0 == ADUC_SystemUtils_MkDirRecursiveDefault(dir.c_str()); 40 | } 41 | 42 | } // namespace aduc 43 | -------------------------------------------------------------------------------- /src/utils/test_utils/src/file_test_utils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file file_test_utils.cpp 3 | * @brief The implementation of file test utilities. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #include "aduc/file_test_utils.hpp" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace aduc 16 | { 17 | std::string FileTestUtils_slurpFile(const std::string& path) 18 | { 19 | std::ifstream file_stream{ path }; 20 | std::stringstream buffer; 21 | buffer << file_stream.rdbuf(); 22 | return buffer.str(); 23 | } 24 | 25 | std::string 26 | FileTestUtils_applyTemplateParam(const std::string& templateStr, const char* parameterName, const char* parameterValue) 27 | { 28 | std::stringstream ss; 29 | ss << "\\{\\{" << parameterName << "\\}\\}"; 30 | std::string placeholder{ ss.str() }; 31 | return std::regex_replace(templateStr, std::regex(placeholder.c_str()), parameterValue); 32 | } 33 | 34 | } // namespace aduc 35 | -------------------------------------------------------------------------------- /src/utils/url_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name url_utils) 2 | 3 | add_library (${target_name} STATIC) 4 | add_library (aduc::${target_name} ALIAS ${target_name}) 5 | 6 | target_link_aziotsharedutil (${target_name} PUBLIC) 7 | 8 | target_sources (${target_name} PRIVATE src/https_proxy_utils.c src/url_utils.c) 9 | target_include_directories (${target_name} PUBLIC inc ${ADUC_EXPORT_INCLUDES}) 10 | target_link_libraries ( 11 | ${target_name} 12 | PUBLIC aduc::c_utils 13 | PRIVATE aduc::logging) 14 | 15 | if (ADUC_BUILD_UNIT_TESTS) 16 | add_subdirectory (tests) 17 | endif () 18 | -------------------------------------------------------------------------------- /src/utils/url_utils/inc/aduc/url_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file url_utils.h 3 | * @brief Utilities for working with urls. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | 9 | #ifndef ADUC_URL_UTILS_H 10 | #define ADUC_URL_UTILS_H 11 | 12 | #include "aduc/c_utils.h" 13 | #include "aduc/result.h" 14 | #include "azure_c_shared_utility/strings.h" 15 | 16 | EXTERN_C_BEGIN 17 | 18 | ADUC_Result ADUC_UrlUtils_GetPathFileName(const char* url, STRING_HANDLE* outFileName); 19 | 20 | EXTERN_C_END 21 | 22 | #endif // ADUC_URL_UTILS_H 23 | -------------------------------------------------------------------------------- /src/utils/url_utils/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (target_name url_utils_unit_test) 2 | 3 | project (url_utils_unit_test) 4 | 5 | include (agentRules) 6 | 7 | compileasc99 () 8 | disablertti () 9 | 10 | find_package (Catch2 REQUIRED) 11 | 12 | add_executable (${target_name}) 13 | target_sources (${target_name} PRIVATE https_proxy_utils_ut.cpp url_utils_ut.cpp) 14 | 15 | target_link_libraries (${target_name} PRIVATE aduc::url_utils Catch2::Catch2WithMain) 16 | target_link_libraries (${target_name} PRIVATE libaducpal) 17 | 18 | include (CTest) 19 | include (Catch) 20 | catch_discover_tests (${target_name}) 21 | -------------------------------------------------------------------------------- /src/utils/workflow_data_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.5) 2 | 3 | set (target_name workflow_data_utils) 4 | include (agentRules) 5 | 6 | compileasc99 () 7 | 8 | add_library (${target_name} STATIC src/workflow_data_utils.c) 9 | add_library (aduc::${target_name} ALIAS ${target_name}) 10 | 11 | target_include_directories ( 12 | ${target_name} 13 | PUBLIC inc ${ADUC_EXPORT_INCLUDES} 14 | PRIVATE src) 15 | 16 | # 17 | # Turn -fPIC on, in order to use this library in another shared library. 18 | # 19 | set_property (TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE ON) 20 | 21 | target_link_libraries ( 22 | ${target_name} 23 | PRIVATE aduc::adu_core_export_helpers 24 | aduc::adu_types 25 | aduc::c_utils 26 | aduc::workflow_utils) 27 | 28 | target_link_aziotsharedutil (${target_name} PRIVATE) 29 | -------------------------------------------------------------------------------- /src/utils/workflow_utils/tests/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @brief workflow_utils tests main entry point. 4 | * 5 | * @copyright Copyright (c) Microsoft Corporation. 6 | * Licensed under the MIT License. 7 | */ 8 | #include 9 | 10 | // https://github.com/Azure/umock-c/blob/master/doc/umock_c.md 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | int result; 19 | 20 | // Global setup 21 | result = umock_c_init([](UMOCK_C_ERROR_CODE error_code) -> void { 22 | std::cout << "*** umock_c failed, err=" << error_code << std::endl; 23 | }); 24 | if (result != 0) 25 | { 26 | std::cout << "umock_c_init_failed, err=" << result << std::endl; 27 | return result; 28 | } 29 | 30 | result = Catch::Session().run(argc, argv); 31 | if (result != 0) 32 | { 33 | std::cout << "Catch session failed, err=" << result << std::endl; 34 | } 35 | 36 | // Global cleanup. 37 | umock_c_deinit(); 38 | 39 | return result; 40 | } 41 | -------------------------------------------------------------------------------- /src/utils/workflow_utils/tests/testdata/workflow_get_update_file/desired_template.json: -------------------------------------------------------------------------------- 1 | { 2 | "workflow": { 3 | "action": 3, 4 | "id": "8ea4b58c-98b2-447b-8675-c6c1a45f785e" 5 | }, 6 | "updateManifest": "UPDATE_MANIFEST", 7 | "updateManifestSignature": "UPDATE_MANIFEST_SIGNATURE", 8 | "fileUrls": { 9 | "TARGET_UPDATE_FILE_ID": "gopher://buck.t33th/0/target_update-0.2.swu", 10 | "DELTA_UPDATE_FILE_ID": "DELTA_UPDATE_FILE_URL" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tools/AduCmdlets-py/README.md: -------------------------------------------------------------------------------- 1 | # Device Update for IoT Hub - Scripts 2 | 3 | This directory contains sample Python scripts for creating an import manifest for Device Update for IoT Hub. 4 | 5 | ## Creating import manifest 6 | 7 | ### Simple example 8 | 9 | To create a simple update, refer to the Python sample [CreateSampleSimpleUpdate.py](CreateSampleSimpleUpdate.py) for usage. Modify the script as necessary, and run it as follows: 10 | 11 | ```shell 12 | python ./CreateSampleSimpleUpdate.py --path './output' --update-version '1.1' 13 | ``` 14 | 15 | ### Complex example 16 | 17 | To create a more complex update that references one or more child updates, refer to the Python sample [CreateSampleComplexUpdate.py](CreateSampleComplexUpdate.py) for usage. Modify the script as necessary, and run it as follows: 18 | 19 | ```shell 20 | python ./CreateSampleComplexUpdate.py --path './output' --update-version '1.1' 21 | ``` 22 | 23 | ## References 24 | 25 | - [Import Manifest JSON Schema version 4.0](https://docs.microsoft.com/en-us/azure/iot-hub-device-update/import-schema) 26 | - [Import concepts](https://docs.microsoft.com/en-us/azure/iot-hub-device-update/import-concepts) 27 | -------------------------------------------------------------------------------- /tools/AduCmdlets/.gitignore: -------------------------------------------------------------------------------- 1 | ### ADU cmdlets. 2 | /bin 3 | -------------------------------------------------------------------------------- /tools/download_file/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | 3 | set(target_name download_file) 4 | 5 | add_executable (${target_name}) 6 | target_sources (${target_name} PRIVATE main.cpp) 7 | target_include_directories (${target_name} PUBLIC ../../src/inc) 8 | 9 | find_package (deliveryoptimization_sdk CONFIG REQUIRED) 10 | target_link_libraries (${target_name} PRIVATE Microsoft::deliveryoptimization) 11 | -------------------------------------------------------------------------------- /tools/packer/README.md: -------------------------------------------------------------------------------- 1 | # Packer Tooling 2 | 3 | This dir is for HCL configs used by [Hashicorp packer](https://www.packer.io/) for building VM and Docker images for various purposes. 4 | 5 | ## build dir 6 | 7 | The `build` dir contains HCL for building docker images that will contain the build artifacts of building DU Agent, Unit tests, and .deb package during image creation time. 8 | See README.md in `build` dir for more details. 9 | -------------------------------------------------------------------------------- /tools/packer/build/duagent-build.pkr.hcl: -------------------------------------------------------------------------------- 1 | packer { 2 | required_plugins { 3 | docker = { 4 | version = ">= 0.0.7" 5 | source = "github.com/hashicorp/docker" 6 | } 7 | } 8 | } 9 | 10 | source "docker" "debian_arm64" { 11 | image = "arm64v8/debian:11" 12 | commit = true 13 | platform = "linux/arm64" 14 | } 15 | 16 | source "docker" "debian_amd64" { 17 | image = "amd64/debian:11" 18 | commit = true 19 | platform = "linux/amd64" 20 | } 21 | 22 | build { 23 | name = "duagent" 24 | sources = [ 25 | "source.docker.debian_arm64", 26 | "source.docker.debian_amd64" 27 | ] 28 | 29 | provisioner "shell" { 30 | inline = [ 31 | "apt-get update && apt-get --yes install apt-utils git", 32 | "git clone https://github.com/azure/iot-hub-device-update --branch develop", 33 | "cd iot-hub-device-update && ./scripts/install-deps.sh -a && ./scripts/build.sh -c -u --build-packages" 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tools/selfhost/README.md: -------------------------------------------------------------------------------- 1 | # selfhost scripts 2 | 3 | This dir contains scripts for use in bootstrapping devices (real or virtual) to run the agent and including additional functionality/convenience for self-hosting scenarios. 4 | 5 | ## bootstrap.sh 6 | 7 | - Installs python3 and any PyPi pip modules needed 8 | - It does not validate arguments but passes through to bootstrap.py 9 | - Calls bootstrap.py with arguments passed. 10 | 11 | ## bootstrap.py 12 | 13 | Runs in 2 modes 14 | 15 | - Bundle creation mode (bundler role) 16 | - Bootstrap device mode (self-hoster role) 17 | 18 | ### Bundle Creation Mode 19 | 20 | - `./bootstrap.sh --bundle-name selfhost_1 --config /path/to/bootstrap_selfhost_1.json --out-dir /path/to/out_dir --work-dir /path/to/work-dir` 21 | 22 | ### Bootstrap Device Mode 23 | 24 | - `./bootstrap.sh --install [--verbose]` 25 | - or `./bootstrap.sh -i [-v]` 26 | -------------------------------------------------------------------------------- /tools/selfhost/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (c) Microsoft Corporation. 4 | # Licensed under the MIT License. 5 | 6 | # The absolute path to the dir where this script is located 7 | script_dir='' 8 | 9 | # 10 | # MAIN 11 | # 12 | 13 | # When calling this with arguments (creating bundle not applying bootstrap), then not as root/sudo, caller must call: 14 | # 15 | # sudo apt-get install python3 python3-pip 16 | # 17 | # and 18 | # 19 | # pip3 install jsonschema 20 | # pip3 install requests 21 | 22 | if [[ $(whoami) != 'root' ]]; then 23 | echo "This needs to be run as root. Try: sudo $0" 24 | exit 1 25 | fi 26 | 27 | # Get the abs path to the dir where script is located 28 | pushd "$(dirname "$0")" > /dev/null || exit 29 | script_dir="$(pwd)" 30 | popd > /dev/null || exit 31 | 32 | # Pass-thru args to bootstrap.py 33 | "${script_dir}/bootstrap.py" "$@" 34 | -------------------------------------------------------------------------------- /tools/selfhost/bootstrap_config_example.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceupdate_agent": { 3 | "package_path": "/tmp/adu/boot/du_agent_pkg.deb", 4 | "dependencies": { 5 | "ubuntu18.04_x64": { 6 | "delivery_optimization_tarball_url": "https://github.com/microsoft/do-client/releases/download/v1.0.0/ubuntu1804_x64-packages.tar" 7 | }, 8 | "ubuntu20.04_x64": { 9 | "delivery_optimization_tarball_url": "https://github.com/microsoft/do-client/releases/download/v1.0.0/ubuntu2004_x64-packages.tar" 10 | } 11 | } 12 | }, 13 | "features": { 14 | "delta_update": { 15 | "deltaupdate_files": "/tmp/adu/boot/deltaupdate_files.zip", 16 | "deltaupdate_swupdate_files": "/tmp/adu/boot/delta_swupdate_files.tar.gz" 17 | } 18 | } 19 | } 20 | --------------------------------------------------------------------------------