annotate dvdauth.c @ 1813:c68e82514f56

add filenamechanged
author pontscho
date Fri, 31 Aug 2001 21:23:55 +0000
parents 9ffe6c1a33b9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
1 /* (C)2001 by LGB (Gabor Lenart), based on example programs in libcss
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
2 lgb@lgb.hu */
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
3
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
4 /* don't do anything with this source if css support was not requested */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
5 #include "config.h"
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
6 #ifdef HAVE_LIBCSS
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
7
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
8 #include <stdio.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
9 #include <stdlib.h>
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
10 //#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
11 #include <errno.h>
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
12 #include <unistd.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
13 #include <fcntl.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
14 #include <sys/types.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
15 #include <sys/ioctl.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
16 #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
17 #include <sys/wait.h>
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
18 #include <css.h>
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
19 #if CSS_MAJOR_VERSION > 0 || (CSS_MAJOR_VERSION == 0 && CSS_MINOR_VERSION > 1)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
20 # include <dvd.h>
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
21 # undef OLD_CSS_API
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
22 #else
1177
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1163
diff changeset
23 # 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
24 # include <sys/dvdio.h>
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
25 # elif defined(__linux__)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
26 # include <linux/cdrom.h>
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
27 # elif defined(__sun)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
28 # include <sun/dvdio.h>
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
29 # else
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
30 # 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
31 # endif
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
32 # define OLD_CSS_API 1
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
33 #endif
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
34
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
35 #include "dvdauth.h"
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
36
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
37
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
38 #if OLD_CSS_API
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
39 /*
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
40 * 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
41 * 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
42 */
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
43 #define DVDHandle int
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
44 #define DVDOpenFailed (-1)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
45
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
46 #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
47 #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
48 #define DVDCloseDevice(hdl) close(hdl)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
49 #define CSSDVDisEncrypted(hdl) CSSisEncrypted(hdl)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
50 #define CSSDVDAuthDisc CSSAuthDisc
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
51 /* Arghhh! Please think before you commit! You forget to check the return
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
52 value of path_to_lba (-1 for error) in this way ... - LGB */
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
53 //#define CSSDVDAuthTitlePath(hdl,key_title,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
54 // CSSAuthTitle(hdl,key_title,path_to_lba(path))
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
55
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
56 #else /*OLD_CSS_API*/
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 DVDHandle struct dvd_device *
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
59 #define DVDOpenFailed NULL
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
60
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
61 #endif /*OLD_CSS_API*/
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
62
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
63
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
64 char *dvd_auth_device=NULL;
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
65 char *dvd_device=NULL;
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
66 char *dvd_raw_device=NULL;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
67 unsigned char key_disc[2048];
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
68 unsigned char key_title[5];
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
69 unsigned char *dvdimportkey=NULL;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
70 int descrambling=0;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
71
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
72
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
73 #if OLD_CSS_API
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
74 /*
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
75 * With the old libcss-0.1 api, we have to find out the LBA for
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
76 * a title for title authentication.
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
77 */
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
78 #ifdef __linux__
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
79 #include <linux/fs.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
80
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
81 #ifndef FIBMAP
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
82 #define FIBMAP 1
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
83 #endif
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
84
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
85 static int path_to_lba (char *path)
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
86 {
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
87 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
88 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
89 FILE *fp;
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
90
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
91 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
92 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
93 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
94 int ret;
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
95 bzero(cmd,sizeof(cmd));
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
96 fgets(cmd,99,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
97 if ((ret=pclose(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
98 fprintf(stderr,"fibmap_mplayer: %s\n",*cmd?cmd:"no error info");
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 if(WIFEXITED(ret) && !WEXITSTATUS(ret))
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 lba=atoi(cmd);
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
101 else
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 fp=NULL;
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
103 }
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
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 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
106 printf("fibmap_mplayer could not run, trying with ioctl() ...\n");
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 if ((fd = open(path, O_RDONLY)) == -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
108 fprintf(stderr, "Cannot open file %s: %s",
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 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
110 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
111 }
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
112 if (ioctl(fd, FIBMAP, &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
113 perror ("ioctl FIBMAP");
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
114 fprintf(stderr,"Hint: run mplayer as root (or better to install fibmap_mplayer as suid root)!\n");
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
115 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
116 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
117 }
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
118 close(fd);
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
119 }
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
120 printf("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
121 return lba;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
122 }
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
123
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
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 int CSSDVDAuthTitlePath(DVDHandle hdl,unsigned char *key_title,char *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
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 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
128 if (lba==-1) 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
129 return CSSAuthTitle(hdl,key_title,lba);
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 }
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
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
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
133 #else /*linux*/
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
134 static int path_to_lba (char *path)
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
135 {
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
136 #warning translating pathname to iso9660 LBA is not supported on this platform
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
137 fprintf(stderr, "Translating pathname to iso9660 LBA is not supported on this platform\n");
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
138 return -1;
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
139 }
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
140 #endif /*linux*/
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
141 #endif /*OLD_CSS_API*/
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
142
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
143
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
144 static void reset_agids ( DVDHandle dvd )
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
145 {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
146 dvd_authinfo ai;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
147 int i;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
148 for (i = 0; i < 4; i++) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
149 memset(&ai, 0, sizeof(ai));
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
150 ai.type = DVD_INVALIDATE_AGID;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
151 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
152 DVDAuth(dvd, &ai);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
153 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
154 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
155
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
156
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
157 int dvd_import_key ( unsigned char *hexkey )
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
158 {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
159 unsigned char *t=key_title;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
160 int digit=4,len;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
161 bzero(key_title,sizeof(key_title));
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
162 // printf("DVD key: %s\n",hexkey);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
163 for (len=0;len<10;len++) {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
164 // printf("-> %c\n",*hexkey);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
165 if (!*hexkey) return 1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
166 if (*hexkey>='A'&&*hexkey<='F') *t|=(*hexkey-'A'+10)<<digit;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
167 else if (*hexkey>='0'&&*hexkey<='9') *t|=(*hexkey-'0')<<digit;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
168 else return 1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
169 if (digit) digit=0; else {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
170 digit=4;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
171 t++;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
172 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
173 hexkey++;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
174 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
175 if (*hexkey) return 1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
176 printf("DVD key (requested): %02X%02X%02X%02X%02X\n",key_title[0],key_title[1],key_title[2],key_title[3],key_title[4]);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
177 descrambling=1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
178 return 0;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
179 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
180
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
181
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
182
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
183 int dvd_auth ( char *dev , char *filename )
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
184 {
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
185 DVDHandle dvd; /* DVD device handle */
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
186
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
187 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
188 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
189 dev, strerror(errno));
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
190 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
191 }
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
192
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
193 if (!CSSDVDisEncrypted(dvd)) {
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
194 printf("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
195 DVDCloseDevice(dvd);
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
196 return 0;
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
197 } else printf("DVD is encrypted, issuing authentication ...\n");
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
198
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
199 /* reset AGIDs */
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
200 reset_agids(dvd);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
201
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
202 /* authenticate disc */
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
203 if (CSSDVDAuthDisc(dvd,key_disc)) {
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
204 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
205 DVDCloseDevice(dvd);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
206 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
207 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
208
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
209 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
210 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
211 DVDCloseDevice(dvd);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
212 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
213 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
214
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
215 /* decrypting title */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
216 if (CSSDecryptTitleKey (key_title, key_disc) < 0) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
217 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
218 DVDCloseDevice(dvd);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
219 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
220 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
221
1042
b333271f4e7c Solaris 8 DVD support and other fixes by Juergen Keil <jk@tools.de>
arpi_esp
parents: 1018
diff changeset
222 DVDCloseDevice(dvd);
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
223 printf("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]);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
224 descrambling=1;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
225 return 0;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
226 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
227
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
228
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
229 #endif