Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: deny if pads can't be updated (i.e RO media) #232

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static int pusb_pad_should_update(t_pusb_options *opts, const char *user)
return (1);
}

static void pusb_pad_update(
static int pusb_pad_update(
t_pusb_options *opts,
const char *volume,
const char *user
Expand All @@ -232,22 +232,22 @@ static void pusb_pad_update(

if (!pusb_pad_should_update(opts, user))
{
return;
return 1;
}

log_info("Regenerating new pads...\n");
if (!(f_device = pusb_pad_open_device(opts, volume, user, "w+")))
{
log_error("Unable to update pads.\n");
return;
log_error("Unable to update device pads.\n");
return 0;
}
pusb_pad_protect(user, fileno(f_device));

if (!(f_system = pusb_pad_open_system(opts, user, "w+")))
{
log_error("Unable to update pads.\n");
log_error("Unable to update system pads.\n");
fclose(f_device);
return;
return 0;
}
pusb_pad_protect(user, fileno(f_system));

Expand Down Expand Up @@ -279,6 +279,8 @@ static void pusb_pad_update(
fclose(f_system);
fclose(f_device);
log_debug("One time pads updated.\n");

return 1;
}

void generateRandom(char* output, int sizeBytes)
Expand Down Expand Up @@ -373,7 +375,10 @@ int pusb_pad_check(
retval = pusb_pad_compare(opts, volume->mount_point, user);
if (retval)
{
pusb_pad_update(opts, volume->mount_point, user);
if (pusb_pad_update(opts, volume->mount_point, user) != 1) {
log_error("Pad check succeeded, but updating failed!\n");
retval = 0;
}
}
else
{
Expand Down
Loading