VirtualBox

Ticket #11720 (closed defect: fixed)

Opened 12 months ago

Last modified 8 weeks ago

Solaris Autostart service can only work for 1st user in staff group => fixed in SVN

Reported by: kburtch Owned by:
Priority: major Component: other
Version: VirtualBox 4.2.12 Keywords: autostart solaris smf group
Cc: Guest type: other
Host type: Solaris

Description

First: The use of "exec" in smf-vboxautostart.sh breaks the loop through the users as it replaces the current process with the "su" process. It also prevents the immediately following exit status check from functioning.

Second: The smf-vboxautostart.sh script loops over the "staff" Unix group instead of the "vboxuser" Unix group to determine which users to look for to start autostart-enabled VMs. The use of the "vboxuser" group makes more sense than "staff" as not all companies use "staff" for their users, and the "vboxuser" group is a required group for anyone running VirtualBox anyways.

Third: Looping through "logins -g group" includes 5 columns of data (including the GECOS field), so it will be looping over UID, group, GID, first name, last name, etc. as well as the username. At a minimum, it should be piped through "cut -d' ' -f1" to strip out the irrelevant data.

        # Get all users
        for VW_USER in `logins -g staff`
        do
            exec su - "$VW_USER" -c "/opt/VirtualBox/VBoxAutostart --background --start --config \"$VW_CONFIG\" --logrotate \"$VW_ROTATE\" --logsize \"$VW_LOGSIZE\" --loginterval \"$VW_LOGINTERVAL\""

            VW_EXIT=$?
            if [ $VW_EXIT != 0 ]; then
                echo "VBoxAutostart failed with $VW_EXIT."
                VW_EXIT=1
                break
            fi
        done

I suggest changing it to the following (diff attached):

        for VW_USER in `logins -g vboxuser | cut -d' ' -f1`
        do
            su - "$VW_USER" -c "/opt/VirtualBox/VBoxAutostart --background --start --config \"$VW_CONFIG\" --logrotate \"$VW_ROTATE\" --logsize \"$VW_LOGSIZE\" --loginterval \"$VW_LOGINTERVAL\""

            VW_EXIT=$?
            if [ $VW_EXIT != 0 ]; then
                echo "VBoxAutostart failed with $VW_EXIT."
                VW_EXIT=1
                break
            fi
        done

The above fixes all three problems: autostart VMs not starting unless you're 1st in the list; users not in "staff" group not having VMs started); and attempting to su to groups, numbers, etc. (diff attached)

Note the diff also contains a clarification of error output for the top section where it checks if a file is executable, then if it exists. I reversed those and changed the error to make more sense.

--- /opt/VirtualBox/smf-vboxautostart.sh.orig   Fri Apr 12 12:19:08 2013
+++ /opt/VirtualBox/smf-vboxautostart.sh        Mon Apr 15 19:23:31 2013
@@ -24,13 +24,13 @@
 
 case $VW_OPT in
     start)
-        if [ ! -x /opt/VirtualBox/VBoxAutostart ]; then
+        if [ ! -f /opt/VirtualBox/VBoxAutostart ]; then
             echo "ERROR: /opt/VirtualBox/VBoxAutostart does not exist."
             return $SMF_EXIT_ERR_CONFIG
         fi
 
-        if [ ! -f /opt/VirtualBox/VBoxAutostart ]; then
-            echo "ERROR: /opt/VirtualBox/VBoxAutostart does not exist."
+        if [ ! -x /opt/VirtualBox/VBoxAutostart ]; then
+            echo "ERROR: /opt/VirtualBox/VBoxAutostart is not executable."
             return $SMF_EXIT_ERR_CONFIG
         fi
 
@@ -51,9 +51,9 @@
         [ -z "$VW_LOGINTERVAL" ] && VW_LOGINTERVAL=86400
 
         # Get all users
-        for VW_USER in `logins -g staff`
+        for VW_USER in `logins -g vboxuser | cut -d' ' -f1`
         do
-            exec su - "$VW_USER" -c "/opt/VirtualBox/VBoxAutostart --background --start --config \"$VW_CONFIG\" --logrotate \"$VW_ROTATE\" --logsize \"$VW_LOGSIZE\" --loginterval \"$VW_LOGINTERVAL\""
+            su - "$VW_USER" -c "/opt/VirtualBox/VBoxAutostart --background --start --config \"$VW_CONFIG\" --logrotate \"$VW_ROTATE\" --logsize \"$VW_LOGSIZE\" --loginterval \"$VW_LOGINTERVAL\""
 
             VW_EXIT=$?
             if [ $VW_EXIT != 0 ]; then

I started a forum post on this, originally thinking the problem was the use of null arguments to options when calling VBoxAutostart (before I noticed the "exec"), as VBoxAutostart fails under those conditions.  https://forums.virtualbox.org/viewtopic.php?f=11&t=55006

Attachments

smf-vboxautostart.sh.diff Download (1.4 KB) - added by kburtch 12 months ago.
diff -u output, patch for smf-vboxautostart.sh
smf-vboxautostart.sh.2.diff Download (2.0 KB) - added by kburtch 4 months ago.
Patch against smf-vboxautostart.sh from VirtualBox 4.3.4

Change History

Changed 12 months ago by kburtch

diff -u output, patch for smf-vboxautostart.sh

comment:1 Changed 12 months ago by ramshankar

Thanks for the patch.

A few notes:

The vboxuser group is not "required". It is only needed on Solaris 11 hosts for permissions for host USB support. Keep in mind that the installer only creates the "vboxuser" group when these conditions are met.

comment:2 Changed 12 months ago by kburtch

You're very welcome for the patch.

Agreed, the vboxuser group is only required for use of USB, but it is the most appropriate group for determining what accounts may have VB VMs defined (if group parsing is used for this purpose). As stated, not all companies use "staff" as a default group.

One way this could be made flexible is by adding a property (config/group?) to the virtualbox/autostart service to specify the group to parse.

A possible alternative may be parsing *all* users (getent passwd | cut -d: -f1), but that could be busy in a large environment with a very large number of users.

comment:3 Changed 12 months ago by ramshankar

I agree that the "vboxuser" group is the most appropriate. I merely wanted to put a reminder in here that the group creation is only done conditionally by the installer, and that when one of our developers gets around to fixing this, they'd notice that they might have to change the installer as well.

comment:4 follow-up: ↓ 7 Changed 9 months ago by aeichner

Hi, thanks for the patch again. Can you please put your patch under MIT license so we can include it? Regarding the default group. I think I'll go with your suggestion and make the default group configurable and leave the default to staff. The staff group was the group every user is in with a default Solaris installation as far as I can tell.

comment:5 Changed 6 months ago by darrenmoffat

In addition to all of the above you really shouldn't be using logins that way since it will scan through the entire nameservice looking for all users. There is a "-S files" option to logins that you might want to consider using to limit it to just users with local accounts.

An alternative way to do this might be to have separate instances of the SMF for each user that is allowed to have autostarting VMs, that way the hosts admin has to explicitly enable each user (which they would have to do if you are using a special group). The advantage of using a separate instance is that you then don't need to use su but instead set the method_credential for the instance so it runs as the user.

comment:6 Changed 6 months ago by darrenmoffat

Incase you need any more justification of why scanning the whole nameservice isn't nice on my desktop "logins -g staff" takes 1 minute 37 seconds.

comment:7 in reply to: ↑ 4 Changed 5 months ago by kburtch

My apologies for not responding long ago.

Replying to aeichner:

Hi, thanks for the patch again. Can you please put your patch under MIT license so we can include it?

Absolutely. I release it under the MIT license, or any license you need to be able to include it in VirtualBox (I actually didn't think there was enough to it to require a license).

Thank you very much.

Changed 4 months ago by kburtch

Patch against smf-vboxautostart.sh from VirtualBox 4.3.4

comment:8 Changed 4 months ago by kburtch

I updated the patch since there is a similar routine in the stop section of the script now (in 4.3.4, not sure when it crept in).

I also release this patch under the MIT license.

comment:9 Changed 3 months ago by aeichner

  • Summary changed from Solaris Autostart service can only work for 1st user in staff group to Solaris Autostart service can only work for 1st user in staff group => fixed in SVN

Thanks for the updated patch. It will be part of the next maintenance release. I also made the user group for autostart configurable.

@darrenmoffat: I agree that this way might not be the best one for all configurations out there but if we would change it to check only local accounts we will get complaints from other users why it was changed.

comment:10 Changed 3 months ago by kburtch

Interesting timing... I just now successfully tested the patch against 4.3.6.

Thank you very much!

comment:11 Changed 2 months ago by frank

Could you test  VBox 4.3.8 RC1?

comment:12 Changed 8 weeks ago by frank

  • Status changed from new to closed
  • Resolution set to fixed

Fix is part of VBox 4.3.8.

Note: See TracTickets for help on using tickets.

www.oracle.com
ContactPrivacy policyTerms of Use