432fa2
diff -up lockdev-scm-2011-10-07/src/lockdev.c.access lockdev-scm-2011-10-07/src/lockdev.c
432fa2
--- lockdev-scm-2011-10-07/src/lockdev.c.access	2011-07-22 09:37:10.000000000 +0200
432fa2
+++ lockdev-scm-2011-10-07/src/lockdev.c	2013-12-05 11:56:57.836961642 +0100
432fa2
@@ -95,6 +95,10 @@
432fa2
  *
432fa2
  */
432fa2
 
432fa2
+#ifndef _GNU_SOURCE
432fa2
+   #define _GNU_SOURCE
432fa2
+#endif
432fa2
+
432fa2
 #include <errno.h>
432fa2
 #include <signal.h>
432fa2
 #include <stdio.h>
432fa2
@@ -125,6 +125,10 @@
432fa2
 #include "lockdev.h"
432fa2
 #include "ttylock.h"
432fa2
 
432fa2
+#ifndef LOCKDEV_ACCESS
432fa2
+#define LOCKDEV_ACCESS  euidaccess
432fa2
+#endif
432fa2
+
432fa2
 #define	LOCKDEV_PATH	SBINDIR "/lockdev"
432fa2
 
432fa2
 /*
432fa2
@@ -616,7 +620,10 @@ dev_lock (const char *devname)
432fa2
 	if ( stat( device, &statbuf) == -1 ) {
432fa2
 		close_n_return(-errno);
432fa2
 	}
432fa2
-	if ( access( device, W_OK ) == -1 ) {
432fa2
+	/* check that the caller has write permission to the device
432fa2
+	 * to prevent denial-of-service attack by unauthorized users
432fa2
+	 */
432fa2
+	if ( LOCKDEV_ACCESS( device, W_OK ) == -1 ) {
432fa2
 		close_n_return(-errno);
432fa2
 	}
432fa2
 
432fa2
@@ -780,7 +787,10 @@ dev_relock (const char  *devname,
432fa2
 	if ( stat( device, &statbuf) == -1 ) {
432fa2
 		close_n_return(-errno);
432fa2
 	}
432fa2
-	if ( access( device, W_OK ) == -1 ) {
432fa2
+	/* check that the caller has write permission to the device
432fa2
+	 * to prevent denial-of-service attack by unauthorized users
432fa2
+	 */
432fa2
+	if ( LOCKDEV_ACCESS( device, W_OK ) == -1 ) {
432fa2
 		close_n_return(-errno);
432fa2
 	}
432fa2
 
432fa2
@@ -870,7 +880,10 @@ dev_unlock (const char *devname,
432fa2
 	if ( stat( device, &statbuf) == -1 ) {
432fa2
 		close_n_return(-errno);
432fa2
 	}
432fa2
-	if ( access( device, W_OK ) == -1 ) {
432fa2
+	/* check that the caller has write permission to the device
432fa2
+	 * to prevent denial-of-service attack by unauthorized users
432fa2
+	 */
432fa2
+	if ( LOCKDEV_ACCESS( device, W_OK ) == -1 ) {
432fa2
 		close_n_return(-errno);
432fa2
 	}
432fa2
 
432fa2
diff -ru lockdev-save/src/Makefile.am lockdev-scm-2011-10-07/src/Makefile.am
432fa2
--- lockdev-save/src/Makefile.am	2014-09-18 13:42:00.363741658 +0200
432fa2
+++ lockdev-scm-2011-10-07/src/Makefile.am	2014-09-18 13:52:10.307868154 +0200
432fa2
@@ -6,7 +6,6 @@
432fa2
 AM_CPPFLAGS = -include $(top_builddir)/config.h -DSBINDIR=\"$(sbindir)\"
432fa2
 
432fa2
 lockdev_SOURCES = sample.c
432fa2
-lockdev_LDADD = liblockdev.la
432fa2
 
432fa2
 baudboy_SOURCES = baudboy_test.c
432fa2
 baudboy_LDADD = liblockdev.la
432fa2
Solo in lockdev-scm-2011-10-07/src: Makefile.in
432fa2
diff -ru lockdev-save/src/sample.c lockdev-scm-2011-10-07/src/sample.c
432fa2
--- lockdev-save/src/sample.c	2014-09-18 13:42:00.363741658 +0200
432fa2
+++ lockdev-scm-2011-10-07/src/sample.c	2014-09-18 14:06:03.769023380 +0200
432fa2
@@ -6,6 +6,13 @@
432fa2
 #include <fcntl.h>
432fa2
 #include "lockdev.h"
432fa2
 
432fa2
+/* ttylock functions swap the real/effective uid/gid for us, so
432fa2
+ * use access instead of euidaccess.
432fa2
+ */
432fa2
+#define LOCKDEV_ACCESS access
432fa2
+#undef TTYLOCK_USE_HELPER
432fa2
+#include "lockdev.c"
432fa2
+
432fa2
 void
432fa2
 usage (void)
432fa2
 {
432fa2
Solo in lockdev-scm-2011-10-07: VERSION