Compare commits

..

2 Commits

60
otp.c
View File

@@ -132,12 +132,16 @@ int main(int argc, char* argv[]) {
}
int interactive_mode(void) {
// printf("\n\n\n\n=== OTP Cipher %s ===\n\n", get_version());
char input[10];
while (1) {
show_main_menu();
char input[10];
if (fgets(input, sizeof(input), stdin)) {
if (!fgets(input, sizeof(input), stdin)) {
printf("Goodbye!\n");
break;
}
char choice = toupper(input[0]);
switch (choice) {
@@ -154,19 +158,15 @@ int interactive_mode(void) {
handle_pads_menu();
break;
case 'X':
case 'Q':
printf("Goodbye!\n");
return 0;
default:
printf("Invalid option. Please select T, F, D, P, or X.\n");
continue;
printf("Invalid choice. Please try again.\n");
break;
}
} else {
printf("Error reading input. Please try again.\n");
continue;
}
printf("\n");
}
return 0;
}
int command_line_mode(int argc, char* argv[]) {
@@ -2305,14 +2305,39 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
while ((mount_entry = readdir(mount_dir)) != NULL) {
if (mount_entry->d_name[0] == '.') continue;
// Check if drive name starts with "OTP"
if (strncmp(mount_entry->d_name, "OTP", 3) != 0) continue;
char mount_path[512];
snprintf(mount_path, sizeof(mount_path), "%s/%s", mount_dirs[mount_idx], mount_entry->d_name);
// For /media, we need to go one level deeper (user directories)
if (strcmp(mount_dirs[mount_idx], "/media") == 0) {
// This is /media/[username] - look inside for drives
DIR* user_dir = opendir(mount_path);
if (!user_dir) continue;
struct dirent* user_entry;
while ((user_entry = readdir(user_dir)) != NULL) {
if (user_entry->d_name[0] == '.') continue;
// Check if drive name starts with "OTP"
if (strncmp(user_entry->d_name, "OTP", 3) != 0) continue;
char user_mount_path[512];
snprintf(user_mount_path, sizeof(user_mount_path), "%s/%s", mount_path, user_entry->d_name);
// Check if this is a readable directory
DIR* drive_dir = opendir(user_mount_path);
if (drive_dir) {
closedir(drive_dir);
strncpy(otp_drive_path, user_mount_path, path_size - 1);
otp_drive_path[path_size - 1] = '\0';
closedir(user_dir);
closedir(mount_dir);
return 1; // Found OTP drive
}
}
closedir(user_dir);
} else if (strcmp(mount_dirs[mount_idx], "/run/media") == 0) {
// For /run/media, we need to go one level deeper (skip username)
if (strcmp(mount_dirs[mount_idx], "/run/media") == 0) {
DIR* user_dir = opendir(mount_path);
if (!user_dir) continue;
@@ -2339,7 +2364,9 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
}
closedir(user_dir);
} else {
// Direct mount point (like /media/OTP_DRIVE or /mnt/OTP_DRIVE)
// Direct mount point (like /mnt/OTP_DRIVE)
// Check if drive name starts with "OTP"
if (strncmp(mount_entry->d_name, "OTP", 3) == 0) {
DIR* drive_dir = opendir(mount_path);
if (drive_dir) {
closedir(drive_dir);
@@ -2350,6 +2377,7 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
}
}
}
}
closedir(mount_dir);
}