diff --git a/libburn/drive.c b/libburn/drive.c index a96816a..a33260b 100644 --- a/libburn/drive.c +++ b/libburn/drive.c @@ -367,3 +367,46 @@ int burn_drive_get_write_speed(struct burn_drive *d) { return d->mdata->max_write_speed; } + + +/* ts A51221 */ +static char *enumeration_whitelist[BURN_DRIVE_WHITELIST_LEN]; +static int enumeration_whitelist_top = -1; + +/** Add a device to the list of permissible drives. As soon as some entry is in + the whitelist all non-listed drives are banned from enumeration. + @return 1 success, <=0 failure +*/ +int burn_drive_add_whitelist(char *device_address) +{ + char *new_item; + if(enumeration_whitelist_top+1 >= BURN_DRIVE_WHITELIST_LEN) + return 0; + enumeration_whitelist_top++; + new_item = malloc(strlen(device_address) + 1); + if (new_item == NULL) + return -1; + strcpy(new_item, device_address); + enumeration_whitelist[enumeration_whitelist_top] = new_item; + return 1; +} + +/** Remove all drives from whitelist. This enables all possible drives. */ +void burn_drive_clear_whitelist(void) +{ + int i; + for (i = 0; i <= enumeration_whitelist_top; i++) + free(enumeration_whitelist[i]); + enumeration_whitelist_top = -1; +} + +int burn_drive_is_banned(char *device_address) +{ + int i; + if(enumeration_whitelist_top<0) + return 0; + for (i = 0; i <= enumeration_whitelist_top; i++) + if (strcmp(enumeration_whitelist[i], device_address) == 0) + return 0; + return 1; +} diff --git a/libburn/libburn.h b/libburn/libburn.h index 7506ed3..fa7fb6a 100644 --- a/libburn/libburn.h +++ b/libburn/libburn.h @@ -451,6 +451,18 @@ struct burn_message* burn_get_message(void); /** Frees a burn_message structure */ void burn_message_free(struct burn_message *msg); + +/* ts A51221 */ +/** Maximum number of particularly permissible drive addresses */ +#define BURN_DRIVE_WHITELIST_LEN 255 +/** Add a device to the list of permissible drives. As soon as some entry is in + the whitelist all non-listed drives are banned from enumeration. + @return 1 success, <=0 failure +*/ +int burn_drive_add_whitelist(char *device_address); +/** Remove all drives from whitelist. This enables all possible drives. */ +void burn_drive_clear_whitelist(void); + /** Scans for drives. This function MUST be called until it returns nonzero. No drives can be in use when this is called or it will assert. All drive pointers are invalidated by using this function. Do NOT store diff --git a/libburn/sg.c b/libburn/sg.c index cbcbf1e..b9de49e 100644 --- a/libburn/sg.c +++ b/libburn/sg.c @@ -25,6 +25,9 @@ static void enumerate_common(char *fname); +/* ts A51221 */ +int burn_drive_is_banned(char *device_address); + static int sgio_test(int fd) { unsigned char test_ops[] = { 0, 0, 0, 0, 0, 0 }; @@ -50,6 +53,9 @@ void ata_enumerate(void) /* open O_RDWR so we don't think read only drives are in some way useful */ + /* ts A51221 */ + if (burn_drive_is_banned(fname)) + continue; fd = open(fname, O_RDWR | O_NONBLOCK); if (fd == -1) continue; @@ -85,6 +91,9 @@ void sg_enumerate(void) /* open RDWR so we don't accidentally think read only drives are in some way useful */ + /* ts A51221 */ + if (burn_drive_is_banned(fname)) + continue; fd = open(fname, O_RDWR); if (fd == -1) continue;