From 611b7e15ed46ac08489edd6c477c5285dae7d1c7 Mon Sep 17 00:00:00 2001 From: Walter Doekes Date: Mon, 29 Aug 2022 18:20:57 +0200 Subject: [PATCH] Remove execute permissions from *.c and *.h files (#1651) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add permission fix (no execute bit for source files) to fbt lint|format * Remove execute bit from 59 source files using fbt format * Also list which permissions are unwanted in lint.py * Also remove exec permissions from lib/../rfal_nfc.c Co-authored-by: あく --- applications/bad_usb/views/bad_usb_view.h | 0 .../bt/bt_debug_app/views/bt_carrier_test.c | 0 applications/bt/bt_debug_app/views/bt_test.c | 0 applications/bt/bt_debug_app/views/bt_test.h | 0 .../bt/bt_hid_app/views/bt_hid_keynote.c | 0 .../bt/bt_hid_app/views/bt_hid_media.c | 0 .../bt/bt_settings_app/bt_settings_app.c | 0 .../bt/bt_settings_app/bt_settings_app.h | 0 .../scenes/bt_settings_scene_config.h | 0 .../bt_settings_scene_forget_dev_confirm.c | 0 .../bt_settings_scene_forget_dev_success.c | 0 .../scenes/bt_settings_scene_start.c | 0 applications/cli/cli_i.h | 0 applications/gpio/views/gpio_test.c | 0 applications/gpio/views/gpio_test.h | 0 applications/gpio/views/gpio_usb_uart.h | 0 applications/gui/canvas.h | 0 applications/gui/modules/dialog_ex.c | 0 applications/gui/modules/menu.h | 0 applications/gui/modules/text_box.c | 0 applications/gui/modules/text_box.h | 0 applications/gui/modules/variable_item_list.h | 0 applications/gui/modules/widget.h | 0 .../widget_elements/widget_element_frame.c | 0 .../widget_elements/widget_element_i.h | 0 .../widget_elements/widget_element_string.c | 0 applications/gui/scene_manager.c | 0 applications/gui/scene_manager.h | 0 applications/gui/scene_manager_i.h | 0 applications/gui/view_dispatcher.h | 0 applications/nfc/helpers/nfc_emv_parser.c | 0 applications/nfc/helpers/nfc_emv_parser.h | 0 applications/nfc/nfc_cli.c | 0 applications/nfc/scenes/nfc_scene.c | 0 applications/nfc/scenes/nfc_scene_config.h | 0 applications/nfc/scenes/nfc_scene_delete.c | 0 .../nfc/scenes/nfc_scene_delete_success.c | 0 .../nfc/scenes/nfc_scene_emulate_uid.c | 0 .../nfc/scenes/nfc_scene_file_select.c | 0 .../scenes/nfc_scene_mf_ultralight_emulate.c | 0 .../nfc/scenes/nfc_scene_read_card_success.c | 0 applications/nfc/scenes/nfc_scene_set_atqa.c | 0 applications/nfc/scenes/nfc_scene_set_sak.c | 0 applications/nfc/scenes/nfc_scene_set_uid.c | 0 applications/picopass/picopass_worker.h | 0 applications/picopass/scenes/picopass_scene.c | 0 .../picopass/scenes/picopass_scene_config.h | 0 .../scenes/picopass_scene_delete_success.c | 0 .../power/battery_test_app/battery_test_app.c | 0 applications/power/power_service/power_i.h | 0 .../power_settings_scene_battery_info.c | 0 .../scenes/power_settings_scene_config.h | 0 .../scenes/power_settings_scene_reboot.c | 0 .../scenes/power_settings_scene_start.c | 0 .../storage_settings_scene_formatting.c | 0 applications/system/system_settings.h | 0 lib/ST25RFAL002/source/rfal_nfc.c | 0 lib/nfc/nfc_worker.h | 0 lib/nfc/protocols/emv.h | 0 lib/nfc/protocols/nfca.c | 0 scripts/lint.py | 59 +++++++++++++------ 61 files changed, 41 insertions(+), 18 deletions(-) mode change 100755 => 100644 applications/bad_usb/views/bad_usb_view.h mode change 100755 => 100644 applications/bt/bt_debug_app/views/bt_carrier_test.c mode change 100755 => 100644 applications/bt/bt_debug_app/views/bt_test.c mode change 100755 => 100644 applications/bt/bt_debug_app/views/bt_test.h mode change 100755 => 100644 applications/bt/bt_hid_app/views/bt_hid_keynote.c mode change 100755 => 100644 applications/bt/bt_hid_app/views/bt_hid_media.c mode change 100755 => 100644 applications/bt/bt_settings_app/bt_settings_app.c mode change 100755 => 100644 applications/bt/bt_settings_app/bt_settings_app.h mode change 100755 => 100644 applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h mode change 100755 => 100644 applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_confirm.c mode change 100755 => 100644 applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_success.c mode change 100755 => 100644 applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c mode change 100755 => 100644 applications/cli/cli_i.h mode change 100755 => 100644 applications/gpio/views/gpio_test.c mode change 100755 => 100644 applications/gpio/views/gpio_test.h mode change 100755 => 100644 applications/gpio/views/gpio_usb_uart.h mode change 100755 => 100644 applications/gui/canvas.h mode change 100755 => 100644 applications/gui/modules/dialog_ex.c mode change 100755 => 100644 applications/gui/modules/menu.h mode change 100755 => 100644 applications/gui/modules/text_box.c mode change 100755 => 100644 applications/gui/modules/text_box.h mode change 100755 => 100644 applications/gui/modules/variable_item_list.h mode change 100755 => 100644 applications/gui/modules/widget.h mode change 100755 => 100644 applications/gui/modules/widget_elements/widget_element_frame.c mode change 100755 => 100644 applications/gui/modules/widget_elements/widget_element_i.h mode change 100755 => 100644 applications/gui/modules/widget_elements/widget_element_string.c mode change 100755 => 100644 applications/gui/scene_manager.c mode change 100755 => 100644 applications/gui/scene_manager.h mode change 100755 => 100644 applications/gui/scene_manager_i.h mode change 100755 => 100644 applications/gui/view_dispatcher.h mode change 100755 => 100644 applications/nfc/helpers/nfc_emv_parser.c mode change 100755 => 100644 applications/nfc/helpers/nfc_emv_parser.h mode change 100755 => 100644 applications/nfc/nfc_cli.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_config.h mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_delete.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_delete_success.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_emulate_uid.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_file_select.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_mf_ultralight_emulate.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_read_card_success.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_set_atqa.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_set_sak.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_set_uid.c mode change 100755 => 100644 applications/picopass/picopass_worker.h mode change 100755 => 100644 applications/picopass/scenes/picopass_scene.c mode change 100755 => 100644 applications/picopass/scenes/picopass_scene_config.h mode change 100755 => 100644 applications/picopass/scenes/picopass_scene_delete_success.c mode change 100755 => 100644 applications/power/battery_test_app/battery_test_app.c mode change 100755 => 100644 applications/power/power_service/power_i.h mode change 100755 => 100644 applications/power/power_settings_app/scenes/power_settings_scene_battery_info.c mode change 100755 => 100644 applications/power/power_settings_app/scenes/power_settings_scene_config.h mode change 100755 => 100644 applications/power/power_settings_app/scenes/power_settings_scene_reboot.c mode change 100755 => 100644 applications/power/power_settings_app/scenes/power_settings_scene_start.c mode change 100755 => 100644 applications/storage_settings/scenes/storage_settings_scene_formatting.c mode change 100755 => 100644 applications/system/system_settings.h mode change 100755 => 100644 lib/ST25RFAL002/source/rfal_nfc.c mode change 100755 => 100644 lib/nfc/nfc_worker.h mode change 100755 => 100644 lib/nfc/protocols/emv.h mode change 100755 => 100644 lib/nfc/protocols/nfca.c diff --git a/applications/bad_usb/views/bad_usb_view.h b/applications/bad_usb/views/bad_usb_view.h old mode 100755 new mode 100644 diff --git a/applications/bt/bt_debug_app/views/bt_carrier_test.c b/applications/bt/bt_debug_app/views/bt_carrier_test.c old mode 100755 new mode 100644 diff --git a/applications/bt/bt_debug_app/views/bt_test.c b/applications/bt/bt_debug_app/views/bt_test.c old mode 100755 new mode 100644 diff --git a/applications/bt/bt_debug_app/views/bt_test.h b/applications/bt/bt_debug_app/views/bt_test.h old mode 100755 new mode 100644 diff --git a/applications/bt/bt_hid_app/views/bt_hid_keynote.c b/applications/bt/bt_hid_app/views/bt_hid_keynote.c old mode 100755 new mode 100644 diff --git a/applications/bt/bt_hid_app/views/bt_hid_media.c b/applications/bt/bt_hid_app/views/bt_hid_media.c old mode 100755 new mode 100644 diff --git a/applications/bt/bt_settings_app/bt_settings_app.c b/applications/bt/bt_settings_app/bt_settings_app.c old mode 100755 new mode 100644 diff --git a/applications/bt/bt_settings_app/bt_settings_app.h b/applications/bt/bt_settings_app/bt_settings_app.h old mode 100755 new mode 100644 diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h b/applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h old mode 100755 new mode 100644 diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_confirm.c b/applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_confirm.c old mode 100755 new mode 100644 diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_success.c b/applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_success.c old mode 100755 new mode 100644 diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c b/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c old mode 100755 new mode 100644 diff --git a/applications/cli/cli_i.h b/applications/cli/cli_i.h old mode 100755 new mode 100644 diff --git a/applications/gpio/views/gpio_test.c b/applications/gpio/views/gpio_test.c old mode 100755 new mode 100644 diff --git a/applications/gpio/views/gpio_test.h b/applications/gpio/views/gpio_test.h old mode 100755 new mode 100644 diff --git a/applications/gpio/views/gpio_usb_uart.h b/applications/gpio/views/gpio_usb_uart.h old mode 100755 new mode 100644 diff --git a/applications/gui/canvas.h b/applications/gui/canvas.h old mode 100755 new mode 100644 diff --git a/applications/gui/modules/dialog_ex.c b/applications/gui/modules/dialog_ex.c old mode 100755 new mode 100644 diff --git a/applications/gui/modules/menu.h b/applications/gui/modules/menu.h old mode 100755 new mode 100644 diff --git a/applications/gui/modules/text_box.c b/applications/gui/modules/text_box.c old mode 100755 new mode 100644 diff --git a/applications/gui/modules/text_box.h b/applications/gui/modules/text_box.h old mode 100755 new mode 100644 diff --git a/applications/gui/modules/variable_item_list.h b/applications/gui/modules/variable_item_list.h old mode 100755 new mode 100644 diff --git a/applications/gui/modules/widget.h b/applications/gui/modules/widget.h old mode 100755 new mode 100644 diff --git a/applications/gui/modules/widget_elements/widget_element_frame.c b/applications/gui/modules/widget_elements/widget_element_frame.c old mode 100755 new mode 100644 diff --git a/applications/gui/modules/widget_elements/widget_element_i.h b/applications/gui/modules/widget_elements/widget_element_i.h old mode 100755 new mode 100644 diff --git a/applications/gui/modules/widget_elements/widget_element_string.c b/applications/gui/modules/widget_elements/widget_element_string.c old mode 100755 new mode 100644 diff --git a/applications/gui/scene_manager.c b/applications/gui/scene_manager.c old mode 100755 new mode 100644 diff --git a/applications/gui/scene_manager.h b/applications/gui/scene_manager.h old mode 100755 new mode 100644 diff --git a/applications/gui/scene_manager_i.h b/applications/gui/scene_manager_i.h old mode 100755 new mode 100644 diff --git a/applications/gui/view_dispatcher.h b/applications/gui/view_dispatcher.h old mode 100755 new mode 100644 diff --git a/applications/nfc/helpers/nfc_emv_parser.c b/applications/nfc/helpers/nfc_emv_parser.c old mode 100755 new mode 100644 diff --git a/applications/nfc/helpers/nfc_emv_parser.h b/applications/nfc/helpers/nfc_emv_parser.h old mode 100755 new mode 100644 diff --git a/applications/nfc/nfc_cli.c b/applications/nfc/nfc_cli.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene.c b/applications/nfc/scenes/nfc_scene.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_config.h b/applications/nfc/scenes/nfc_scene_config.h old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_delete.c b/applications/nfc/scenes/nfc_scene_delete.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_delete_success.c b/applications/nfc/scenes/nfc_scene_delete_success.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_emulate_uid.c b/applications/nfc/scenes/nfc_scene_emulate_uid.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_file_select.c b/applications/nfc/scenes/nfc_scene_file_select.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_mf_ultralight_emulate.c b/applications/nfc/scenes/nfc_scene_mf_ultralight_emulate.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_read_card_success.c b/applications/nfc/scenes/nfc_scene_read_card_success.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_set_atqa.c b/applications/nfc/scenes/nfc_scene_set_atqa.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_set_sak.c b/applications/nfc/scenes/nfc_scene_set_sak.c old mode 100755 new mode 100644 diff --git a/applications/nfc/scenes/nfc_scene_set_uid.c b/applications/nfc/scenes/nfc_scene_set_uid.c old mode 100755 new mode 100644 diff --git a/applications/picopass/picopass_worker.h b/applications/picopass/picopass_worker.h old mode 100755 new mode 100644 diff --git a/applications/picopass/scenes/picopass_scene.c b/applications/picopass/scenes/picopass_scene.c old mode 100755 new mode 100644 diff --git a/applications/picopass/scenes/picopass_scene_config.h b/applications/picopass/scenes/picopass_scene_config.h old mode 100755 new mode 100644 diff --git a/applications/picopass/scenes/picopass_scene_delete_success.c b/applications/picopass/scenes/picopass_scene_delete_success.c old mode 100755 new mode 100644 diff --git a/applications/power/battery_test_app/battery_test_app.c b/applications/power/battery_test_app/battery_test_app.c old mode 100755 new mode 100644 diff --git a/applications/power/power_service/power_i.h b/applications/power/power_service/power_i.h old mode 100755 new mode 100644 diff --git a/applications/power/power_settings_app/scenes/power_settings_scene_battery_info.c b/applications/power/power_settings_app/scenes/power_settings_scene_battery_info.c old mode 100755 new mode 100644 diff --git a/applications/power/power_settings_app/scenes/power_settings_scene_config.h b/applications/power/power_settings_app/scenes/power_settings_scene_config.h old mode 100755 new mode 100644 diff --git a/applications/power/power_settings_app/scenes/power_settings_scene_reboot.c b/applications/power/power_settings_app/scenes/power_settings_scene_reboot.c old mode 100755 new mode 100644 diff --git a/applications/power/power_settings_app/scenes/power_settings_scene_start.c b/applications/power/power_settings_app/scenes/power_settings_scene_start.c old mode 100755 new mode 100644 diff --git a/applications/storage_settings/scenes/storage_settings_scene_formatting.c b/applications/storage_settings/scenes/storage_settings_scene_formatting.c old mode 100755 new mode 100644 diff --git a/applications/system/system_settings.h b/applications/system/system_settings.h old mode 100755 new mode 100644 diff --git a/lib/ST25RFAL002/source/rfal_nfc.c b/lib/ST25RFAL002/source/rfal_nfc.c old mode 100755 new mode 100644 diff --git a/lib/nfc/nfc_worker.h b/lib/nfc/nfc_worker.h old mode 100755 new mode 100644 diff --git a/lib/nfc/protocols/emv.h b/lib/nfc/protocols/emv.h old mode 100755 new mode 100644 diff --git a/lib/nfc/protocols/nfca.c b/lib/nfc/protocols/nfca.c old mode 100755 new mode 100644 diff --git a/scripts/lint.py b/scripts/lint.py index b3c3e7da4..30a5699a7 100755 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -88,7 +88,7 @@ class Main(App): def _fix_filename(self, filename: str): return filename.replace("-", "_") - def _replace_occurance(self, sources: list, old: str, new: str): + def _replace_occurrence(self, sources: list, old: str, new: str): old = old.encode() new = new.encode() for source in sources: @@ -102,7 +102,7 @@ class Main(App): pattern = re.compile(SOURCE_CODE_FILE_PATTERN) good = [] bad = [] - # Check sources for invalid filesname + # Check sources for invalid filenames for source in sources: basename = os.path.basename(source) if not pattern.match(basename): @@ -113,40 +113,63 @@ class Main(App): bad.append((source, basename, new_basename)) else: good.append(source) - # Notify about errors or replace all occurances + # Notify about errors or replace all occurrences if dry_run: if len(bad) > 0: self.logger.error(f"Found {len(bad)} incorrectly named files") self.logger.info(bad) return False else: - # Replace occurances in text files + # Replace occurrences in text files for source, old, new in bad: - self._replace_occurance(sources, old, new) + self._replace_occurrence(sources, old, new) # Rename files for source, old, new in bad: shutil.move(source, source.replace(old, new)) return True - def check(self): + def _apply_file_permissions(self, sources: list, dry_run: bool = False): + execute_permissions = 0o111 + pattern = re.compile(SOURCE_CODE_FILE_PATTERN) + good = [] + bad = [] + # Check sources for unexpected execute permissions + for source in sources: + st = os.stat(source) + perms_too_many = st.st_mode & execute_permissions + if perms_too_many: + good_perms = st.st_mode & ~perms_too_many + bad.append((source, oct(perms_too_many), good_perms)) + else: + good.append(source) + # Notify or fix + if dry_run: + if len(bad) > 0: + self.logger.error(f"Found {len(bad)} incorrect permissions") + self.logger.info([record[0:2] for record in bad]) + return False + else: + for source, perms_too_many, new_perms in bad: + os.chmod(source, new_perms) + return True + + def _perform(self, dry_run: bool): result = 0 sources = self._find_sources(self.args.input) - if not self._format_sources(sources, dry_run=True): - result |= 0b01 - if not self._apply_file_naming_convention(sources, dry_run=True): - result |= 0b10 + if not self._format_sources(sources, dry_run=dry_run): + result |= 0b001 + if not self._apply_file_naming_convention(sources, dry_run=dry_run): + result |= 0b010 + if not self._apply_file_permissions(sources, dry_run=dry_run): + result |= 0b100 self._check_folders(self.args.input) return result + def check(self): + return self._perform(dry_run=True) + def format(self): - result = 0 - sources = self._find_sources(self.args.input) - if not self._format_sources(sources): - result |= 0b01 - if not self._apply_file_naming_convention(sources): - result |= 0b10 - self._check_folders(self.args.input) - return result + return self._perform(dry_run=False) if __name__ == "__main__":