Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/isaki-audio2]: src/sys/dev/audio Revive multiuser control.



details:   https://anonhg.NetBSD.org/src/rev/8dbb885f3b34
branches:  isaki-audio2
changeset: 451055:8dbb885f3b34
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sun May 05 02:20:36 2019 +0000

description:
Revive multiuser control.

diffstat:

 sys/dev/audio/audio.c    |  44 ++++++++++++++++++++++++++++++++++++++++----
 sys/dev/audio/audiovar.h |   8 +++++++-
 2 files changed, 47 insertions(+), 5 deletions(-)

diffs (109 lines):

diff -r fe00621f8f80 -r 8dbb885f3b34 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Sun May 05 02:01:34 2019 +0000
+++ b/sys/dev/audio/audio.c     Sun May 05 02:20:36 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.1.2.8 2019/05/04 07:41:50 isaki Exp $      */
+/*     $NetBSD: audio.c,v 1.1.2.9 2019/05/05 02:20:36 isaki Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -149,7 +149,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.1.2.8 2019/05/04 07:41:50 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.1.2.9 2019/05/05 02:20:36 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -577,6 +577,7 @@
 static void audio_mixers_get_format(struct audio_softc *, struct audio_info *);
 static int audio_sysctl_volume(SYSCTLFN_PROTO);
 static int audio_sysctl_blk_ms(SYSCTLFN_PROTO);
+static int audio_sysctl_multiuser(SYSCTLFN_PROTO);
 #if defined(AUDIO_DEBUG)
 static int audio_sysctl_debug(SYSCTLFN_PROTO);
 #endif
@@ -993,6 +994,13 @@
                    audio_sysctl_blk_ms, 0, (void *)sc, 0,
                    CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
 
+               sysctl_createv(&sc->sc_log, 0, NULL, NULL,
+                   CTLFLAG_READWRITE,
+                   CTLTYPE_BOOL, "multiuser",
+                   SYSCTL_DESCR("allow multiple user access"),
+                   audio_sysctl_multiuser, 0, (void *)sc, 0,
+                   CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
+
 #if defined(AUDIO_DEBUG)
                sysctl_createv(&sc->sc_log, 0, NULL, NULL,
                    CTLFLAG_READWRITE,
@@ -2070,9 +2078,9 @@
                                        goto bad3;
                        }
                }
-       } else /* if (sc->sc_multiuser == false) XXX not yet */ {
+       } else if (sc->sc_multiuser == false) {
                uid_t euid = kauth_cred_geteuid(kauth_cred_get());
-               if (euid != 0 && kauth_cred_geteuid(sc->sc_cred) != euid) {
+               if (euid != 0 && euid != kauth_cred_geteuid(sc->sc_cred)) {
                        error = EPERM;
                        goto bad2;
                }
@@ -7480,6 +7488,34 @@
        return error;
 }
 
+/*
+ * Get or set multiuser mode.
+ */
+static int
+audio_sysctl_multiuser(SYSCTLFN_ARGS)
+{
+       struct sysctlnode node;
+       struct audio_softc *sc;
+       int t, error;
+
+       node = *rnode;
+       sc = node.sysctl_data;
+
+       mutex_enter(sc->sc_lock);
+
+       t = sc->sc_multiuser;
+       node.sysctl_data = &t;
+       error = sysctl_lookup(SYSCTLFN_CALL(&node));
+       if (error || newp == NULL)
+               goto abort;
+
+       sc->sc_multiuser = t;
+       error = 0;
+abort:
+       mutex_exit(sc->sc_lock);
+       return error;
+}
+
 #if defined(AUDIO_DEBUG)
 /*
  * Get or set debug verbose level. (0..4)
diff -r fe00621f8f80 -r 8dbb885f3b34 sys/dev/audio/audiovar.h
--- a/sys/dev/audio/audiovar.h  Sun May 05 02:01:34 2019 +0000
+++ b/sys/dev/audio/audiovar.h  Sun May 05 02:20:36 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audiovar.h,v 1.1.2.2 2019/05/04 07:20:09 isaki Exp $   */
+/*     $NetBSD: audiovar.h,v 1.1.2.3 2019/05/05 02:20:36 isaki Exp $   */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -221,6 +221,12 @@
         */
        bool            sc_dying;
 
+       /*
+        * If multiuser is false, other users who have different euid
+        * than the first user cannot open this device.
+        * Must be protected by sc_lock.
+        */
+       bool sc_multiuser;
        kauth_cred_t sc_cred;
 
        struct sysctllog *sc_log;



Home | Main Index | Thread Index | Old Index