Skip to content

Commit

Permalink
Enhancement: deny if pads can't be updated (i.e RO media) (#232)
Browse files Browse the repository at this point in the history
* Enhancement: deny if pads can't be updated (i.e RO media)

* pad.c: improve error messages
  • Loading branch information
mcdope committed Jul 6, 2024
1 parent 8e09692 commit c021bd0
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit c021bd0

Please sign in to comment.