changeset 1163:ac1341d4a2a7

According an idea, mplayer now can use external setuid root wrapper to do FIBMAP ioctl (requires root priv). Also, a serious bug was fixed in dvdauth.c made by some guy when mixing old and new style CSS API into dvdauth.c ;-)
author lgb
date Mon, 18 Jun 2001 23:56:19 +0000
parents 11e49d541f11
children 3367eba48763
files Makefile dvdauth.c
diffstat 2 files changed, 60 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Jun 18 22:11:04 2001 +0000
+++ b/Makefile	Mon Jun 18 23:56:19 2001 +0000
@@ -9,6 +9,7 @@
 PRG = mplayer
 PRG_HQ = mplayerHQ
 PRG_AVIP = aviparse
+PRG_FIBMAP = fibmap_mplayer
 PRG_TV = tvision
 PRG_CFG = codec-cfg
 
@@ -25,7 +26,7 @@
 
 # .PHONY: all clean
 
-all:	$(PRG)
+all:	$(PRG) $(PRG_FIBMAP)
 # $(PRG_AVIP)
 
 .c.o:
@@ -66,6 +67,9 @@
 $(PRG):	version.h mplayer.o $(OBJS) loader/libloader.a $(DS_DEP) libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
 	$(CC) $(CFLAGS) -o $(PRG) mplayer.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader $(DS_LIB) -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore -Llibao2 -lao2 $(VO_LIBS) $(CSS_LIB) -Lencore -lencore $(ARCH_LIBS)
 
+$(PRG_FIBMAP): fibmap_mplayer.o
+	$(CC) -o $(PRG_FIBMAP) fibmap_mplayer.o
+
 # $(PRG_HQ):	depfile mplayerHQ.o $(OBJS) loader/libloader.a libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
 # 	$(CC) $(CFLAGS) -o $(PRG_HQ) mplayerHQ.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader -ldl -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore $(VO_LIBS) -Lencore -lencore -lpthread
 
@@ -78,16 +82,21 @@
 $(PRG_CFG):        version.h codec-cfg.c codec-cfg.h
 	$(CC) $(CFLAGS) -g codec-cfg.c -o $(PRG_CFG) -DCODECS2HTML
 
-install: $(PRG)
+install: $(PRG) $(PRG_FIBMAP)
 	install -D -m 755 -s $(PRG) $(BINDIR)/$(PRG)
 	install -D -m 644 DOCS/mplayer.1 $(prefix)/man/man1/mplayer.1
+	@echo "Following task requires root privs. If it fails don't panic"
+	@echo "however it means you can't use fibmap_mplayer."
+	@echo "Without this (or without running mplayer as root) you won't be"
+	@echo "able to play DVDs."
+	install -D -o root -g root -m 4755 -s $(PRG_FIBMAP) $(BINDIR)/$(PRG_FIBMAP)
 
 clean:
 	rm -f *.o *~ $(OBJS)
 
 distclean:
 	@for a in mp3lib libac3 libmpeg2 opendivx encore libvo libao2 loader loader/DirectShow drivers drivers/syncfb ; do $(MAKE) -C $$a distclean ; done
-	rm -f *~ $(PRG) $(PRG_HQ) $(PRG_AVIP) $(PRG_TV) $(OBJS) *.o *.a .depend
+	rm -f *~ $(PRG) $(PRG_FIBMAP) $(PRG_HQ) $(PRG_AVIP) $(PRG_TV) $(OBJS) *.o *.a .depend
 
 dep:	depend
 
--- a/dvdauth.c	Mon Jun 18 22:11:04 2001 +0000
+++ b/dvdauth.c	Mon Jun 18 23:56:19 2001 +0000
@@ -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,10 @@
 #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))
+/* Arghhh! Please think before you commit! You forget to check the return
+   value of path_to_lba (-1 for error) in this way ... - LGB */
+//#define	CSSDVDAuthTitlePath(hdl,key_title,path) \
+//		CSSAuthTitle(hdl,key_title,path_to_lba(path))
 
 #else	/*OLD_CSS_API*/
 
@@ -58,6 +61,8 @@
 
 
 char *dvd_auth_device=NULL;
+char *dvd_device=NULL;
+char *dvd_raw_device=NULL;
 unsigned char key_disc[2048];
 unsigned char key_title[5];
 unsigned char *dvdimportkey=NULL;
@@ -79,24 +84,52 @@
 
 static int path_to_lba (char *path)
 {
-    int fd, lba = 0;
+    int lba = 0;
+    char cmd[100];
+    FILE *fp;
 
-    if ((fd = open(path, O_RDONLY)) == -1) {
-        fprintf(stderr, "Cannot open file %s: %s",
-		path ? path : "(NULL)", strerror(errno));
-        return -1;
+    snprintf(cmd,sizeof(cmd),"fibmap_mplayer %s",path);
+    fp=popen(cmd,"r");
+    if (fp) {
+	    int ret;
+	    bzero(cmd,sizeof(cmd));
+	    fgets(cmd,99,fp);
+	    if ((ret=pclose(fp)))
+		    fprintf(stderr,"fibmap_mplayer: %s\n",*cmd?cmd:"no error info");
+	    if(WIFEXITED(ret) && !WEXITSTATUS(ret)) 
+		lba=atoi(cmd);
+	    else
+		fp=NULL;
     }
-    if (ioctl(fd, FIBMAP, &lba) != 0) {
-        perror ("ioctl FIBMAP");
-	fprintf(stderr,"Hint: run mplayer as root!\n");
-        close(fd);
-        return -1;
+    if (!fp) {
+	int fd;
+	printf("fibmap_mplayer could not run, trying with ioctl() ...\n");
+	if ((fd = open(path, O_RDONLY)) == -1) {
+    	    fprintf(stderr, "Cannot open file %s: %s",
+	    path ? path : "(NULL)", strerror(errno));
+    	    return -1;
+	}
+        if (ioctl(fd, FIBMAP, &lba) != 0) {
+            perror ("ioctl FIBMAP");
+	    fprintf(stderr,"Hint: run mplayer as root (or better to install fibmap_mplayer as suid root)!\n");
+            close(fd);
+            return -1;
+        }
+	close(fd);
     }
-
-    close(fd);
-
+    printf("LBA: %d\n",lba);
     return lba;
 }
+
+
+int CSSDVDAuthTitlePath(DVDHandle hdl,unsigned char *key_title,char *path)
+{
+	int lba=path_to_lba(path);
+	if (lba==-1) return -1;
+	return CSSAuthTitle(hdl,key_title,lba);
+}		
+		
+
 #else /*linux*/
 static int path_to_lba (char *path)
 {