libdvdcss patches

H}kan Hjort d95hjort at dtek.chalmers.se
Thu May 16 17:04:37 CEST 2002


First change the error text in CSSTest, since dvd ioctls are always
compiled in now.  Shoulw we keep the message or simply remove it all?

Second patch adds a small function that (for unix) stats the string
that we've been told to open, and trys to determin if we should bother
using the ioctls. I.e. they should only be use (tried) on actuall DVD
drives.  Images and files on normal file systems doesn't need any
authentication and if they are encrypted one needs to crack the keys
anyway.
I'm not sure exactly what to test for here though, I compromised and
check for block or char devices on all systems.  It lacks code for
widows as I don't have any clue what should be done there.
Perhaps this could/should be done as part of _dvdcss_open instead?

-- 
Håkan Hjort
d95hjort at dtek.chalmers.se
-------------- next part --------------
Index: css.c
===================================================================
RCS file: /var/cvs/videolan/libdvdcss/src/css.c,v
retrieving revision 1.7
diff -p -u -d -r1.7 css.c
--- css.c	2002/04/05 00:26:25	1.7
+++ css.c	2002/05/16 13:50:00
@@ -82,7 +82,7 @@ int CSSTest( dvdcss_handle dvdcss )
         /* Since it's the first ioctl we try to issue, we add a notice */
         _dvdcss_error( dvdcss, "css error: ioctl_ReadCopyright failed, "
                        "make sure there is a DVD in the drive, and that "
-                       "DVD ioctls were compiled in this libdvdcss version."
+                       "you have used the correct device node."
 #if defined( WIN32 )
                        "\nAlso note that if you are using Windows NT/2000/XP "
                        "you need to have administrator priviledges to be able "
-------------- next part --------------
Index: libdvdcss.c
===================================================================
RCS file: /var/cvs/videolan/libdvdcss/src/libdvdcss.c,v
retrieving revision 1.8
diff -p -u -d -r1.8 libdvdcss.c
--- libdvdcss.c	2002/05/16 12:10:29	1.8
+++ libdvdcss.c	2002/05/16 15:02:48
@@ -71,6 +71,7 @@ struct iovec
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
+static int _dvdcss_use_ioctls ( dvdcss_handle dvdcss, char *psz_target );
 static int _dvdcss_open  ( dvdcss_handle, char *psz_target );
 static int _dvdcss_close ( dvdcss_handle );
 static int _dvdcss_readv ( dvdcss_handle, struct iovec *p_iovec, int i_blocks );
@@ -219,19 +220,23 @@ extern dvdcss_handle dvdcss_open ( char 
         free( dvdcss );
         return NULL;
     }
+    
+    dvdcss->b_encrypted = 1; /* Assume the worst */
+    dvdcss->b_ioctls = _dvdcss_use_ioctls( dvdcss, psz_target );
 
-    i_ret = CSSTest( dvdcss );
-    if( i_ret < 0 )
-    {
-        _dvdcss_error( dvdcss, "CSS test failed" );
-        /* Disable the CSS ioctls and hope that it works? */
-        dvdcss->b_ioctls = 0;
-        dvdcss->b_encrypted = 1;
-    }
-    else
+    if( dvdcss->b_ioctls )
     {
-        dvdcss->b_ioctls = 1;
-        dvdcss->b_encrypted = i_ret;
+        i_ret = CSSTest( dvdcss );
+	if( i_ret < 0 )
+	{
+	    _dvdcss_error( dvdcss, "CSS test failed" );
+	    /* Disable the CSS ioctls and hope that it works? */
+	    dvdcss->b_ioctls = 0;
+	}
+	else
+	{
+	    dvdcss->b_encrypted = i_ret;
+	}
     }
 
     /* If disc is CSS protected and the ioctls work, authenticate the drive */
@@ -500,6 +505,55 @@ extern int dvdcss_close ( dvdcss_handle 
 }
 
 /* Following functions are local */
+
+static int _dvdcss_use_ioctls( dvdcss_handle dvdcss, char *psz_target )
+{
+#if defined( WIN32 )
+    /* Some one need to implement this for Windows */
+    if( WIN2K )
+    {
+	return 1;	
+    }
+    else
+    {
+	return 1;	
+    }
+#else
+    struct stat fileinfo;
+    int ret;
+
+    ret = stat( psz_target, &fileinfo );
+    if( ret < 0 )
+    {
+        _dvdcss_debug( "Can't stat %s\n", psz_target );
+	return 1;  /* What to do?  Be conservative and try to use the ioctsl */
+    }
+    
+    /* Complete this list and check that we test for the right things 
+     * (I've assumed for all OSs that 'r', (raw) device, are char devices
+     *  and those that don't contain/use an 'r' in the name are block devices)
+     *
+     * Linux    needs a block device
+     * Solaris  needs a char device
+     * Darwin   needs a char device 
+     * OpenBSD  needs a char device
+     * NetBSD   needs a char device
+     * FreeBSD  can use either the block or the char device
+     * BSD/OS   can use either the block or the char device
+     */
+    
+    /* Check if this is a block/char device */
+    if( S_ISBLK( fileinfo.st_mode ) || 
+	S_ISCHR( fileinfo.st_mode ) )
+    {
+	return 1;
+    }
+    else
+    {
+	return 0;
+    }
+#endif
+}
 
 static int _dvdcss_open ( dvdcss_handle dvdcss, char *psz_target )
 {


More information about the libdvdcss-devel mailing list