annotate libmpdemux/dvdauth.c @ 5477:fc466845b9e1

mpegpes is no longer handled by libmpeg2 - we have vd_mpegpes now
author arpi
date Wed, 03 Apr 2002 18:23:22 +0000
parents f798a7371653
children 02576893af2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
1 /* (C)2001,2002 by LGB (Gabor Lenart), based on example programs in libcss
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
2 lgb@lgb.hu
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
3
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
4 This source is part of MPlayer project. This source is copyrighted by
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
5 the author according to rules declared in GNU/GPL license.
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
6
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
7 2001 Inital version (LGB)
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
8 2001 fibmap_mplayer to avoid uid=0 mplayer need (LGB)
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
9 2001 Support for libcss with the new API (by ???)
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
10 2002/Jan/04 Use dlopen to access libcss.so to avoid conflict with
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
11 libdvdread [now with only libcss with old API (LGB)
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
12
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
13 TODO:
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
14 support for libcss libraries with new API */
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
15
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
16 /* don't do anything with this source if css support was not requested */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
17 #include "config.h"
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
18 #ifdef HAVE_LIBCSS
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
19
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
20 #warning FIXME: Dynamic loading of libcss.so with newer (ver>0.1) libcss API is not supported in this version!
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
21
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
22 #include <stdio.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
23 #include <stdlib.h>
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
24 //#include <string.h> // FIXME: conflicts with fs.h
1510
9ffe6c1a33b9 In case the open on the dvd device fails, print some hints based on errno
jkeil
parents: 1177
diff changeset
25 #include <errno.h>
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
26 #include <unistd.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
27 #include <fcntl.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
28 #include <sys/types.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
29 #include <sys/ioctl.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
30 #include <sys/stat.h>
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 ;-)
lgb
parents: 1042
diff changeset
31 #include <sys/wait.h>
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
32 // #include <css.h>
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
33
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
34 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
35 # include <sys/dvdio.h>
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
36 #elif defined(__linux__)
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
37 # include <linux/cdrom.h>
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
38 #elif defined(__sun)
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
39 # include <sun/dvdio.h>
4128
f22ecf05acea patch by Steven M. Schultz to support dvd under BSD/OS
alex
parents: 4093
diff changeset
40 #elif defined(__bsdi__)
f22ecf05acea patch by Steven M. Schultz to support dvd under BSD/OS
alex
parents: 4093
diff changeset
41 # include <dvd.h>
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
42 #else
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
43 # error "Need the DVD ioctls"
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
44 #endif
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
45
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
46 #include <dlfcn.h>
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
47 #include "dvdauth.h"
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
48
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
49
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
50 // #if OLD_CSS_API
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
51 /*
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
52 * provide some backward compatibiliy macros to compile this
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
53 * code using the old libcss-0.1
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
54 */
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
55 #define DVDHandle int
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
56 #define DVDOpenFailed (-1)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
57
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
58 #define DVDAuth(hdl, s) ioctl(hdl, DVD_AUTH, s)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
59 #define DVDOpenDevice(path) open(path, O_RDONLY)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
60 #define DVDCloseDevice(hdl) close(hdl)
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
61 // #define CSSDVDisEncrypted(hdl) CSSisEncrypted(hdl)
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
62 // #define CSSDVDAuthDisc CSSAuthDisc
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
63
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
64
1018
e5fc7ec51fa3 -dvd is renamed to -dvdauth, variable dvd_device is renamed to dvd_auth_device. These changes are needed for future DVD playback developmenting
lgb
parents: 559
diff changeset
65 char *dvd_auth_device=NULL;
4228
bcbe3359e88f Fixed bug of multiple declaration of 'dvd_device'
nick
parents: 4128
diff changeset
66 extern char *dvd_device;
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 ;-)
lgb
parents: 1042
diff changeset
67 char *dvd_raw_device=NULL;
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
68 char *css_so=NULL;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
69 unsigned char key_disc[2048];
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
70 unsigned char key_title[5];
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
71 unsigned char *dvdimportkey=NULL;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
72 int descrambling=0;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
73
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
74 static void *dlid;
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
75 static int (*dl_CSSisEncrypted)(int);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
76 static int (*dl_CSSAuthDisc)(int,char *);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
77 static int (*dl_CSSAuthTitle)(int, char *,int);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
78 static int (*dl_CSSGetASF)(int);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
79 static int (*dl_CSSDecryptTitleKey)(char *, char *);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
80 static void (*dl_CSSDescramble)(u_char *, u_char *);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
81
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
82 dvd_css_descramble ( u_char *sec , u_char *key )
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
83 {
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
84 (*dl_CSSDescramble)(sec,key);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
85 }
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
86
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
87
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
88 #ifdef __linux__
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
89 #include <linux/fs.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
90
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
91 #ifndef FIBMAP
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
92 #define FIBMAP 1
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
93 #endif
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
94
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
95
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
96 static int path_to_lba (char *path)
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
97 {
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 ;-)
lgb
parents: 1042
diff changeset
98 int lba = 0;
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 ;-)
lgb
parents: 1042
diff changeset
99 char cmd[100];
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 ;-)
lgb
parents: 1042
diff changeset
100 FILE *fp;
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
101
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 ;-)
lgb
parents: 1042
diff changeset
102 snprintf(cmd,sizeof(cmd),"fibmap_mplayer %s",path);
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 ;-)
lgb
parents: 1042
diff changeset
103 fp=popen(cmd,"r");
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 ;-)
lgb
parents: 1042
diff changeset
104 if (fp) {
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 ;-)
lgb
parents: 1042
diff changeset
105 int ret;
3700
91f801a94a59 memset is more portable than bzero ("BSD"ism)
pl
parents: 2310
diff changeset
106 memset(cmd,0,sizeof(cmd));
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 ;-)
lgb
parents: 1042
diff changeset
107 fgets(cmd,99,fp);
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
108 // printf("DVD: cmd: %s\n",cmd);
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 ;-)
lgb
parents: 1042
diff changeset
109 if ((ret=pclose(fp)))
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
110 fprintf(stderr,"DVD: fibmap_mplayer: %s\n",*cmd?cmd:"no error info");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
111 if (cmd[0]<'0'||cmd[0]>'9') fp=NULL; else {
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
112 if(WIFEXITED(ret) && !WEXITSTATUS(ret)) {
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
113 lba=atoi(cmd);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
114 printf("DVD: fibmap_mplayer is being used\n");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
115 } else
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
116 fp=NULL;
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
117 }
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
118 }
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 ;-)
lgb
parents: 1042
diff changeset
119 if (!fp) {
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 ;-)
lgb
parents: 1042
diff changeset
120 int fd;
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
121 printf("DVD: fibmap_mplayer could not run, trying with ioctl() ...\n");
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 ;-)
lgb
parents: 1042
diff changeset
122 if ((fd = open(path, O_RDONLY)) == -1) {
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
123 fprintf(stderr, "DVD: Cannot open file %s: %s",
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 ;-)
lgb
parents: 1042
diff changeset
124 path ? path : "(NULL)", strerror(errno));
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 ;-)
lgb
parents: 1042
diff changeset
125 return -1;
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 ;-)
lgb
parents: 1042
diff changeset
126 }
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 ;-)
lgb
parents: 1042
diff changeset
127 if (ioctl(fd, FIBMAP, &lba) != 0) {
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
128 perror("DVD: ioctl FIBMAP");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
129 fprintf(stderr," Hint: run mplayer as root (or better to install fibmap_mplayer as suid root)!\n");
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 ;-)
lgb
parents: 1042
diff changeset
130 close(fd);
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 ;-)
lgb
parents: 1042
diff changeset
131 return -1;
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 ;-)
lgb
parents: 1042
diff changeset
132 }
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 ;-)
lgb
parents: 1042
diff changeset
133 close(fd);
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
134 }
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
135 printf("DVD: LBA: %d\n",lba);
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
136 return lba;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
137 }
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 ;-)
lgb
parents: 1042
diff changeset
138
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
139 #else /*linux*/
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 ;-)
lgb
parents: 1042
diff changeset
140
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
141 static int path_to_lba (char *path)
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
142 {
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
143 #warning translating pathname to iso9660 LBA is not supported on this platform
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
144 fprintf(stderr, "DVD: Translating pathname to iso9660 LBA is not supported on this platform\n");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
145 return -1;
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
146 }
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
147
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
148 #endif /*linux*/
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
149
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
150
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
151 static int CSSDVDAuthTitlePath(DVDHandle hdl,unsigned char *key_title,char *path)
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 ;-)
lgb
parents: 1042
diff changeset
152 {
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 ;-)
lgb
parents: 1042
diff changeset
153 int lba=path_to_lba(path);
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 ;-)
lgb
parents: 1042
diff changeset
154 if (lba==-1) return -1;
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
155 return (*dl_CSSAuthTitle)(hdl,key_title,lba);
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 ;-)
lgb
parents: 1042
diff changeset
156 }
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 ;-)
lgb
parents: 1042
diff changeset
157
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 ;-)
lgb
parents: 1042
diff changeset
158
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
159
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
160 static void reset_agids ( DVDHandle dvd )
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
161 {
4337
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
162 #if !defined(DVD_AUTH) && defined(DVDIOCREPORTKEY)
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
163 struct dvd_authinfo ai;
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
164 int i;
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
165 for (i = 0; i < 4; i++) {
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
166 memset(&ai, 0, sizeof(ai));
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
167 ai.format = DVD_INVALIDATE_AGID;
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
168 ai.agid = i;
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
169 ioctl(dvd, DVDIOCREPORTKEY, &ai);
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
170 }
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
171 #else
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
172 dvd_authinfo ai;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
173 int i;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
174 for (i = 0; i < 4; i++) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
175 memset(&ai, 0, sizeof(ai));
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
176 ai.type = DVD_INVALIDATE_AGID;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
177 ai.lsa.agid = i;
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
178 DVDAuth(dvd, &ai);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
179 }
4337
f798a7371653 freebsd fix by bjoern fischer
atmos4
parents: 4228
diff changeset
180 #endif
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
181 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
182
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
183
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
184 int dvd_import_key ( unsigned char *hexkey )
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
185 {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
186 unsigned char *t=key_title;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
187 int digit=4,len;
3700
91f801a94a59 memset is more portable than bzero ("BSD"ism)
pl
parents: 2310
diff changeset
188 memset(key_title,0,sizeof(key_title));
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
189 // printf("DVD key: %s\n",hexkey);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
190 for (len=0;len<10;len++) {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
191 // printf("-> %c\n",*hexkey);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
192 if (!*hexkey) return 1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
193 if (*hexkey>='A'&&*hexkey<='F') *t|=(*hexkey-'A'+10)<<digit;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
194 else if (*hexkey>='0'&&*hexkey<='9') *t|=(*hexkey-'0')<<digit;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
195 else return 1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
196 if (digit) digit=0; else {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
197 digit=4;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
198 t++;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
199 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
200 hexkey++;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
201 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
202 if (*hexkey) return 1;
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
203 printf("DVD: DVD key (requested): %02X%02X%02X%02X%02X\n",key_title[0],key_title[1],key_title[2],key_title[3],key_title[4]);
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
204 descrambling=1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
205 return 0;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
206 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
207
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
208
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
209
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
210 int dvd_auth ( char *dev , char *filename )
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
211 {
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
212 DVDHandle dvd; /* DVD device handle */
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
213
4093
d197584460dc relatiev path to libcss.so - patch by Jim Radford <radford@robotics.caltech.edu>
arpi
parents: 3975
diff changeset
214 if (!css_so) css_so=strdup("libcss.so");
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
215 printf("DVD: opening libcss.so as %s ...\n",css_so);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
216 dlid=dlopen(css_so,RTLD_NOW);
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
217 if (!dlid) {
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
218 printf("DVD: dlopen: %s\n",dlerror());
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
219 return 1;
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
220 } printf("DVD: dlopen OK!\n");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
221
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
222 #define CSS_DLSYM(v,s) if (!(v=dlsym(dlid,s))) {\
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
223 fprintf(stderr,"DVD: %s\n Hint: use libcss version 0.1!\n",dlerror());\
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
224 return 1; }
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
225
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
226 CSS_DLSYM(dl_CSSisEncrypted,"CSSisEncrypted");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
227 CSS_DLSYM(dl_CSSAuthDisc,"CSSAuthDisc");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
228 CSS_DLSYM(dl_CSSAuthTitle,"CSSAuthTitle");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
229 CSS_DLSYM(dl_CSSGetASF,"CSSGetASF");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
230 CSS_DLSYM(dl_CSSDecryptTitleKey,"CSSDecryptTitleKey");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
231 CSS_DLSYM(dl_CSSDescramble,"CSSDescramble");
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
232
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
233 #undef CSS_DLSYM
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
234
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
235 if ((dvd=DVDOpenDevice(dev)) == DVDOpenFailed) {
1510
9ffe6c1a33b9 In case the open on the dvd device fails, print some hints based on errno
jkeil
parents: 1177
diff changeset
236 fprintf(stderr,"DVD: cannot open DVD device \"%s\": %s.\n",
9ffe6c1a33b9 In case the open on the dvd device fails, print some hints based on errno
jkeil
parents: 1177
diff changeset
237 dev, strerror(errno));
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
238 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
239 }
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
240
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
241 if (!(*dl_CSSisEncrypted)(dvd)) {
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
242 printf("DVD: DVD is unencrypted! Skipping authentication!\n(note: you should not use -dvd switch for unencrypted discs!)\n");
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
243 DVDCloseDevice(dvd);
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
244 return 0;
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
245 } else printf("DVD: DVD is encrypted, issuing authentication ...\n");
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
246 /* reset AGIDs */
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
247 reset_agids(dvd);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
248 /* authenticate disc */
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
249 if ((*dl_CSSAuthDisc)(dvd,key_disc)) {
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
250 fprintf(stderr,"DVD: CSSDVDAuthDisc() failed.\n");
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
251 DVDCloseDevice(dvd);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
252 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
253 }
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
254 if (CSSDVDAuthTitlePath(dvd,key_title,filename)) {
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
255 fprintf(stderr,"DVD: CSSDVDAuthTitle() failed.\n");
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
256 DVDCloseDevice(dvd);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
257 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
258 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
259
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
260 /* decrypting title */
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
261 if ((*dl_CSSDecryptTitleKey)(key_title, key_disc) < 0) {
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
262 fprintf(stderr,"DVD: CSSDecryptTitleKey() failed.\n");
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
263 DVDCloseDevice(dvd);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
264 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
265 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
266
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
267 DVDCloseDevice(dvd);
3975
04b2227ab75a Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents: 3700
diff changeset
268 printf("DVD: DVD title key is: %02X%02X%02X%02X%02X\n",key_title[0],key_title[1],key_title[2],key_title[3],key_title[4]);
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
269 descrambling=1;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
270 return 0;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
271 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
272
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
273
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
274 #endif