[Mplayer-dev-eng] [PATCH] FIBMAP as non-root

Arpi arpi at thot.banki.hu
Mon Jun 18 23:38:16 CEST 2001


Hi,

Is there someone with DVD, who tested/checked this?
It should be in the CVS if it's OK!

> I looked at the linux-kernel archive for why FIBMAP isn't allowed as
> root. The short answer is that it probably won't be changed until linux
> 2.5, so I went ahead and moved the FIBMAP ioctl into its own binary so
> it can be called from mplayer. Then I patched mplayer to support this.
> 
> The spawned command should probably be a configuration option, not
> hardcoded as "fibmap". oh well.
> 
> Here's the fibmap binary. It needs to be installed suid root. Note that
> this means that users can still mess around with FIBMAP, but at least
> the rest of mplayer won't be running as root.
> 
> ======== Makefile ========
> CFLAGS=-O2 -Wall
> PROG:=fibmap
> 
> $(PROG):
> 
> clean:
> 	rm -f $(PROG)
> 
> strip: $(PROG)
> 	strip $(PROG)
> 
> ======== fibmap.c ========
> #include <fcntl.h>
> #include <sys/ioctl.h>
> #include <limits.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
> #include <linux/fs.h>
> 
> void usage(char *name) {
> 	fprintf(stderr, "usage: %s <filename>\n", name);
> 	exit(EXIT_FAILURE);
> }
> 
> int main(int argc, char *argv[]) {
> 	int i;
> 
> 	if(geteuid() != 0) {
> 		fprintf(stderr, "must be root to call FIBMAP ioctl\n");
> 		return EXIT_FAILURE;
> 	}
> 	if(argc < 2) {
> 		usage(argv[0]);
> 	}
> 	for(i = 1; i < argc; i++) {
> 		int fd;
> 		int lba = 0;
> 
> 		if((fd = open(argv[i], O_RDONLY)) < 0) {
> 			perror(argv[i]);
> 			continue;
> 		}
> 		if(ioctl(fd, FIBMAP, &lba) < 0) {
> 			perror ("ioctl FIBMAP");
> 			close(fd);
> 			continue;
> 		}
> 		close(fd);
> 		if(fprintf(stdout, "%d\n", lba) < 0) {
> 			perror("fprintf(stdout)");
> 			return EXIT_FAILURE;
> 		}
> 	}
> 	return EXIT_SUCCESS;
> }
> 
> 
> Now, patch dvdauth.c with this (this patch is against tonight's CVS):
> 
> 
> Index: dvdauth.c
> ===================================================================
> RCS file: /cvsroot/mplayer/main/dvdauth.c,v
> retrieving revision 1.5
> diff -u -r1.5 dvdauth.c
> --- dvdauth.c	2001/06/06 21:16:21	1.5
> +++ dvdauth.c	2001/06/15 06:10:38
> @@ -13,6 +13,7 @@
>  #include <sys/types.h>
>  #include <sys/ioctl.h>
>  #include <sys/stat.h>
> +#include <sys/wait.h>
>  #include <css.h>
>  #if CSS_MAJOR_VERSION > 0 || (CSS_MAJOR_VERSION == 0 && CSS_MINOR_VERSION > 1)
>  # include <dvd.h>
> @@ -46,8 +47,6 @@
>  #define	DVDCloseDevice(hdl)	close(hdl)
>  #define	CSSDVDisEncrypted(hdl)	CSSisEncrypted(hdl)
>  #define	CSSDVDAuthDisc		CSSAuthDisc
> -#define	CSSDVDAuthTitlePath(hdl,key_title,path) \
> -		CSSAuthTitle(hdl,key_title,path_to_lba(path))
>  
>  #else	/*OLD_CSS_API*/
>  
> @@ -79,22 +78,34 @@
>  
>  static int path_to_lba (char *path)
>  {
> -    int fd, lba = 0;
> -
> +    FILE *fh;
> +    int fd;
> +    int lba = 0;
> +    char cmd[PATH_MAX+8];
> +
> +    snprintf(cmd, sizeof(cmd), "fibmap %s", path);
> +    if(NULL != (fh = popen(cmd, "r"))) {
> +	if(1 == fscanf(fh, "%d", &lba)) {
> +	    int status = pclose(fh);
> +	    if(WIFEXITED(status) && !WEXITSTATUS(status)) {
> +		return lba;
> +	    }
> +	}
> +    }
> +    perror("attempt to spawn fibmap failed");
>      if ((fd = open(path, O_RDONLY)) == -1) {
> -        fprintf(stderr, "Cannot open file %s: %s",
> +	fprintf(stderr, "Cannot open file %s: %s",
>  		path ? path : "(NULL)", strerror(errno));
> -        return -1;
> +	return -1;
>      }
>      if (ioctl(fd, FIBMAP, &lba) != 0) {
> -        perror ("ioctl FIBMAP");
> -	fprintf(stderr,"Hint: run mplayer as root!\n");
> -        close(fd);
> -        return -1;
> +	perror ("ioctl FIBMAP");
> +	fprintf(stderr,"Hint: install fibmap or run mplayer as root\n");
> +	close(fd);
> +	return -1;
>      }
>  
>      close(fd);
> -
>      return lba;
>  }
>  #else /*linux*/
> @@ -150,6 +161,7 @@
>  int dvd_auth ( char *dev , char *filename )
>  {
>      	DVDHandle dvd;  /* DVD device handle */
> +	int lba;
>  
>  	if ((dvd=DVDOpenDevice(dev)) == DVDOpenFailed) {
>  		fprintf(stderr,"DVD: cannot open DVD device \"%s\".\n",dev);
> @@ -172,7 +184,10 @@
>  		return 1;
>  	}
>  
> -        if (CSSDVDAuthTitlePath(dvd,key_title,filename)) {
> +	if((lba = path_to_lba(filename)) < 0) {
> +		return 1;
> +	}
> +        if (CSSAuthTitle(dvd,key_title,lba)) {
>  		fprintf(stderr,"DVD: CSSDVDAuthTitle() failed.\n");
>  		DVDCloseDevice(dvd);
>  		return 1;
> 
> _______________________________________________
> Mplayer-dev-eng mailing list
> Mplayer-dev-eng at lists.sourceforge.net
> http://lists.sourceforge.net/lists/listinfo/mplayer-dev-eng
> 
> 


A'rpi / Astral & ESP-team

--
mailto:arpi at thot.banki.hu
http://esp-team.scene.hu

_______________________________________________
Mplayer-dev-eng mailing list
Mplayer-dev-eng at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-dev-eng



More information about the MPlayer-dev-eng mailing list