[PATCH v3] libqmi-glib, proxy: Change ownership of QMI devices to the configured user.
Aleksander Morgado
aleksander at aleksander.es
Fri Dec 19 12:07:25 PST 2014
On Fri, Dec 19, 2014 at 7:22 PM, Roshan Pius <rpius at chromium.org> wrote:
> Adding a udev rule to change ownership of all QMI devices to the
> configured user specified at compile time using --enable-qmi-username
> flag.
>
Pushed v3, and then another follow up commit to also include the .in
file when the --enable-qmi-username option is not used during make
dist/distcheck.
Thinking of this a bit further, I wonder if there is some easy way to
instead of changing ownership, change group and g+rw (that is easy)
and then let qmi-proxy check if the given UID is part of the specific
group. Looking at the device lis under my /dev I see all devices owned
by root, but with specific RW groups instead.
> ---
> Makefile.am | 4 ++-
> configure.ac | 33 ++++++++++++++++------
> .../76-qmi-proxy-device-ownership.rules.in | 12 ++++++++
> src/qmi-proxy/Makefile.am | 9 ++++++
> 4 files changed, 49 insertions(+), 9 deletions(-)
> create mode 100644 src/qmi-proxy/76-qmi-proxy-device-ownership.rules.in
>
> diff --git a/Makefile.am b/Makefile.am
> index 21a6b18..7970fbe 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -3,7 +3,9 @@ SUBDIRS = . data build-aux 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 754cbae..c1ca6ef 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -81,9 +81,25 @@ GTK_DOC_CHECK(1.0)
>
> # QMI username
> AC_ARG_ENABLE(qmi-username,
> - AS_HELP_STRING([--enable-qmi-username=<username>], [user allowed to access QMI devices]),,
> - enable_qmi_username="root")
> -AC_DEFINE_UNQUOTED(QMI_USERNAME, "$enable_qmi_username", [Define the QMI username])
> + AS_HELP_STRING([--enable-qmi-username=<username>], [user allowed to access QMI devices]))
> +if test -n "$enable_qmi_username" ; then
> + QMI_USERNAME="$enable_qmi_username"
> +else
> + QMI_USERNAME="root"
> +fi
> +AM_CONDITIONAL([INSTALL_QMI_UDEV_RULES], [test "x$enable_qmi_username" = "x$QMI_USERNAME"])
> +AC_SUBST(QMI_USERNAME)
> +AC_DEFINE_UNQUOTED(QMI_USERNAME, "$QMI_USERNAME", [Define the QMI username])
> +AM_COND_IF([INSTALL_QMI_UDEV_RULES], [AC_CONFIG_FILES([src/qmi-proxy/76-qmi-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)
> @@ -116,9 +132,10 @@ echo "
> libqmi (libqmi-glib, qmicli) $VERSION
> ==============================================
>
> - compiler: ${CC}
> - cflags: ${CFLAGS}
> - Maintainer mode: ${USE_MAINTAINER_MODE}
> - Documentation: ${enable_gtk_doc}
> - QMI username: ${enable_qmi_username}
> + compiler: ${CC}
> + cflags: ${CFLAGS}
> + Maintainer mode: ${USE_MAINTAINER_MODE}
> + udev base directory: ${UDEV_BASE_DIR}
> + Documentation: ${enable_gtk_doc}
> + QMI username: ${QMI_USERNAME}
> "
> diff --git a/src/qmi-proxy/76-qmi-proxy-device-ownership.rules.in b/src/qmi-proxy/76-qmi-proxy-device-ownership.rules.in
> new file mode 100644
> index 0000000..458113d
> --- /dev/null
> +++ b/src/qmi-proxy/76-qmi-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="qmi_proxy_device_ownership_end"
> +
> +# A 'cdc-wdm' device is from a MBIM and QMI-based modems.
> +KERNEL=="cdc-wdm[0-9]", DRIVERS=="qmi_wwan", SUBSYSTEM=="usbmisc", GOTO="qmi_proxy_device_ownership_change"
> +GOTO="qmi_proxy_device_ownership_end"
> +
> +LABEL="qmi_proxy_device_ownership_change"
> +OWNER="@QMI_USERNAME@"
> +
> +LABEL="qmi_proxy_device_ownership_end"
> diff --git a/src/qmi-proxy/Makefile.am b/src/qmi-proxy/Makefile.am
> index 709f712..3eb532e 100644
> --- a/src/qmi-proxy/Makefile.am
> +++ b/src/qmi-proxy/Makefile.am
> @@ -14,3 +14,12 @@ qmi_proxy_SOURCES = qmi-proxy.c
> qmi_proxy_LDADD = \
> $(GLIB_LIBS) \
> $(top_builddir)/src/libqmi-glib/libqmi-glib.la
> +
> +#Install udev rules only if configured with --enable-qmi-username
> +if INSTALL_QMI_UDEV_RULES
> +udevrulesdir = $(UDEV_BASE_DIR)/rules.d
> +udevrules_DATA = 76-qmi-proxy-device-ownership.rules
> +
> +EXTRA_DIST = \
> + 76-qmi-proxy-device-ownership.rules.in
> +endif
> --
> 2.2.0.rc0.207.ga3a616c
>
--
Aleksander
https://aleksander.es
More information about the libqmi-devel
mailing list