[PATCH] libmbim-glib, proxy: Change ownership of MBIM devices to the configured user.
Roshan Pius
rpius at chromium.org
Mon Dec 22 09:33:19 PST 2014
Adding a udev rule to change ownership of all MBIM devices to the
configured user specified at compile time using --enable-mbim-username
flag.
---
Makefile.am | 4 ++-
configure.ac | 34 ++++++++++++++++------
.../76-mbim-proxy-device-ownership.rules.in | 12 ++++++++
src/mbim-proxy/Makefile.am | 9 ++++++
4 files changed, 49 insertions(+), 10 deletions(-)
create mode 100644 src/mbim-proxy/76-mbim-proxy-device-ownership.rules.in
diff --git a/Makefile.am b/Makefile.am
index bdef824..aefa985 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,9 @@ SUBDIRS = . build-aux data src utils docs
ACLOCAL_AMFLAGS = -I m4
-DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
+DISTCHECK_CONFIGURE_FLAGS = \
+ --with-udev-base-dir="$$dc_install_base" \
+ --enable-gtk-doc
EXTRA_DIST = \
gtester.make \
diff --git a/configure.ac b/configure.ac
index ae04f5f..37232f2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,9 +98,25 @@ GTK_DOC_CHECK(1.0)
# MBIM username
AC_ARG_ENABLE(mbim-username,
- AS_HELP_STRING([--enable-mbim-username=<username>], [user allowed to access MBIM devices]),,
- enable_mbim_username="root")
-AC_DEFINE_UNQUOTED(MBIM_USERNAME, "$enable_mbim_username", [Define the MBIM username])
+ AS_HELP_STRING([--enable-mbim-username=<username>], [user allowed to access MBIM devices]))
+if test -n "$enable_mbim_username" ; then
+ MBIM_USERNAME="$enable_mbim_username"
+else
+ MBIM_USERNAME="root"
+fi
+AM_CONDITIONAL([INSTALL_MBIM_UDEV_RULES], [test "x$enable_mbim_username" = "x$MBIM_USERNAME"])
+AC_SUBST(MBIM_USERNAME)
+AC_DEFINE_UNQUOTED(MBIM_USERNAME, "$MBIM_USERNAME", [Define the MBIM username])
+AM_COND_IF([INSTALL_MBIM_UDEV_RULES], [AC_CONFIG_FILES([src/mbim-proxy/76-mbim-proxy-device-ownership.rules])])
+
+# udev base directory
+AC_ARG_WITH(udev-base-dir, AS_HELP_STRING([--with-udev-base-dir=DIR], [where udev base directory is]))
+if test -n "$with_udev_base_dir" ; then
+ UDEV_BASE_DIR="$with_udev_base_dir"
+else
+ UDEV_BASE_DIR="/lib/udev"
+fi
+AC_SUBST(UDEV_BASE_DIR)
dnl Man page
AC_PATH_PROG(HELP2MAN, help2man, false)
@@ -132,10 +148,10 @@ echo "
libmbim $VERSION
==============================================
- compiler: ${CC}
- cflags: ${CFLAGS}
- Maintainer mode: ${USE_MAINTAINER_MODE}
- Documentation: ${enable_gtk_doc}
- MBIM username: ${enable_mbim_username}
-
+ compiler: ${CC}
+ cflags: ${CFLAGS}
+ Maintainer mode: ${USE_MAINTAINER_MODE}
+ udev base directory: ${UDEV_BASE_DIR}
+ Documentation: ${enable_gtk_doc}
+ MBIM username: ${MBIM_USERNAME}
"
diff --git a/src/mbim-proxy/76-mbim-proxy-device-ownership.rules.in b/src/mbim-proxy/76-mbim-proxy-device-ownership.rules.in
new file mode 100644
index 0000000..9f82b96
--- /dev/null
+++ b/src/mbim-proxy/76-mbim-proxy-device-ownership.rules.in
@@ -0,0 +1,12 @@
+# do not edit this file, it will be overwritten on update
+
+ACTION!="add|change|move", GOTO="mbim_proxy_device_ownership_end"
+
+# A 'cdc-wdm' device is from a MBIM and MBIM-based modems.
+KERNEL=="cdc-wdm[0-9]", DRIVERS=="mbim_wwan", SUBSYSTEM=="usbmisc", GOTO="mbim_proxy_device_ownership_change"
+GOTO="mbim_proxy_device_ownership_end"
+
+LABEL="mbim_proxy_device_ownership_change"
+OWNER="@MBIM_USERNAME@"
+
+LABEL="mbim_proxy_device_ownership_end"
diff --git a/src/mbim-proxy/Makefile.am b/src/mbim-proxy/Makefile.am
index 83a8ce4..1558fe5 100644
--- a/src/mbim-proxy/Makefile.am
+++ b/src/mbim-proxy/Makefile.am
@@ -14,3 +14,12 @@ mbim_proxy_SOURCES = mbim-proxy.c
mbim_proxy_LDADD = \
$(MBIMPROXY_LIBS) \
$(top_builddir)/src/libmbim-glib/libmbim-glib.la
+
+#Install udev rules only if configured with --enable-mbim-username
+if INSTALL_MBIM_UDEV_RULES
+udevrulesdir = $(UDEV_BASE_DIR)/rules.d
+udevrules_DATA = 76-mbim-proxy-device-ownership.rules
+endif
+
+EXTRA_DIST = \
+ 76-mbim-proxy-device-ownership.rules.in
--
2.2.0.rc0.207.ga3a616c
More information about the libmbim-devel
mailing list