The File Protection System is a robust C-based application designed to safeguard files within a specified directory and its subdirectories. It employs recursive file system monitoring and access control mechanisms to prevent unauthorized modifications, deletions, or moves of protected files.
- Real-time recursive file system monitoring
- Protection against file modifications, deletions, and moves in the target directory and all subdirectories
- Template-based file protection
- Password-protected system control
- Logging of all protection events and system activities
- User-friendly command-line interface
- Recursive protection and unprotection of files
- Linux-based operating system
- GCC compiler
- Make build system
- libcrypt development libraries
-
Clone the repository:
git clone https://github.com/yourusername/file-protection-system.git cd file-protection-system -
Run the installation script to set up dependencies:
sudo chmod +x install_dependencies.sh sudo ./install_dependencies.sh -
Compile the project:
make -
The executable will be installed in
/bin/file_protection
- Edit the
template.tblfile:- First line: Hashed password for system control (initially set to "password")
- Second line: Absolute path to the directory you want to protect
- Subsequent lines: File patterns to protect (e.g., *.txt, *.doc)
Example template.tbl:
018RdQ7SlKKLA
/home/user/protected_directory
*
*.txt
*.doc
*.docx
*.pdf
Run the application with root privileges:
sudo /bin/file_protection
help: Display available commandsenable: Enable file protection recursivelydisable: Disable file protection recursively (requires password)change: Change the system passwordstatus: Show current protection statusstop: Exit the program
- The system recursively monitors the specified directory and all its subdirectories using inotify.
- When a file event occurs, it checks if the file matches any protected patterns.
- For protected files, it prevents modifications by:
- Setting the immutable flag
- Changing permissions to read-only
- Blocking creation, deletion, and move operations
- The system also monitors for new subdirectories and automatically adds them to the watch list.
main.c: Entry point of the applicationfile_protection.h: Header file with function declarations and includesfile_operations.c: File-related operations and event handlinguser_interface.c: User interaction and command processingsystem_initialization.c: System setup and main loopMakefile: Compilation and installation instructionsinstall_dependencies.sh: Script to install required dependenciestemplate.tbl: Configuration file for protected directory and file patterns
The system logs all activities to file_protection.log in the same directory as the executable. This includes:
- System initialization and shutdown
- Protection enabling/disabling
- File events (create, delete, modify, move)
- User authentication attempts
- Password changes
- Recursive protection and unprotection operations
- The system requires root privileges to set file attributes and permissions.
- The password is stored as a hash in the
template.tblfile. - Ensure that the
template.tblfile has restricted read/write permissions. - The system now protects files in subdirectories, increasing the scope of protection.
The system currently only protects files in a single directory (not recursive).The system now protects files recursively in the specified directory and all its subdirectories.- It does not prevent reading of protected files, only modifications.
- Root users can still modify protected files (as the application runs with root privileges).
- Large directory structures with many files and subdirectories may impact system performance.
Contributions to improve the File Protection System are welcome. Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement) - Make your changes and commit them (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/improvement) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Linux inotify mechanism for file system monitoring
- libcrypt for password hashing
- Added recursive file protection for all subdirectories
- Improved the
disablecommand to recursively remove protection from all files - Enhanced error handling and logging for better troubleshooting
- Updated the initialization process to provide more detailed error messages