github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/unity8.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016-2017 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package builtin
    21  
    22  import (
    23  	"strings"
    24  
    25  	"github.com/snapcore/snapd/interfaces"
    26  	"github.com/snapcore/snapd/interfaces/apparmor"
    27  	"github.com/snapcore/snapd/snap"
    28  )
    29  
    30  const unity8Summary = `allows operating as or interacting with Unity 8`
    31  
    32  const unity8BaseDeclarationPlugs = `
    33    unity8:
    34      allow-installation: false
    35  `
    36  
    37  const unity8BaseDeclarationSlots = `
    38    unity8:
    39      allow-installation:
    40        slot-snap-type:
    41          - app
    42      deny-connection: true
    43  `
    44  
    45  const unity8ConnectedPlugAppArmor = `
    46  # Description: Can access unity8 desktop services
    47  
    48  #include <abstractions/dbus-session-strict>
    49  
    50  # Fonts
    51  #include <abstractions/fonts>
    52  /var/cache/fontconfig/   r,
    53  /var/cache/fontconfig/** mr,
    54  
    55  # The snapcraft desktop part may look for schema files in various locations, so
    56  # allow reading system installed schemas.
    57  /usr/share/glib*/schemas/{,*}              r,
    58  /usr/share/gnome/glib*/schemas/{,*}        r,
    59  /usr/share/ubuntu/glib*/schemas/{,*}       r,
    60  
    61  # URL dispatcher. All apps can call this since:
    62  # a) the dispatched application is launched out of process and not
    63  #    controllable except via the specified URL
    64  # b) the list of url types is strictly controlled
    65  # c) the dispatched application will launch in the foreground over the
    66  #    confined app
    67  dbus (send)
    68       bus=session
    69       path=/com/canonical/URLDispatcher
    70       interface=com.canonical.URLDispatcher
    71       member=DispatchURL
    72       peer=(name=com.canonical.URLDispatcher,label=###SLOT_SECURITY_TAGS###),
    73  
    74  # Note: content-hub may become its own interface, but for now include it here
    75  # Pasteboard via Content Hub. Unity8 with mir has safeguards that ensure snaps
    76  # only may get/set the pasteboard with user-driven actions.
    77  dbus (send)
    78       bus=session
    79       interface=com.ubuntu.content.dbus.Service
    80       path=/
    81       member={CreatePaste,GetAllPasteIds,GetLatestPasteData,GetPasteData,GetPasteSource,PasteFormats,RequestPasteByAppId,SelectPasteForAppId,SelectPasteForAppIdCancelled}
    82       peer=(name=com.ubuntu.content.dbus.Service,label=###SLOT_SECURITY_TAGS###),
    83  dbus (receive)
    84       bus=session
    85       interface=com.ubuntu.content.dbus.Service
    86       path=/
    87       member={PasteboardChanged,PasteFormatsChanged,PasteSelected,PasteSelectionCancelled}
    88       peer=(name=com.ubuntu.content.dbus.Service,label=###SLOT_SECURITY_TAGS###),
    89  `
    90  
    91  type unity8Interface struct{}
    92  
    93  func (iface *unity8Interface) Name() string {
    94  	return "unity8"
    95  }
    96  
    97  func (iface *unity8Interface) StaticInfo() interfaces.StaticInfo {
    98  	return interfaces.StaticInfo{
    99  		Summary:              unity8Summary,
   100  		BaseDeclarationPlugs: unity8BaseDeclarationPlugs,
   101  		BaseDeclarationSlots: unity8BaseDeclarationSlots,
   102  	}
   103  }
   104  
   105  func (iface *unity8Interface) String() string {
   106  	return iface.Name()
   107  }
   108  
   109  func (iface *unity8Interface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
   110  	oldTags := "###SLOT_SECURITY_TAGS###"
   111  	newTags := slotAppLabelExpr(slot)
   112  	snippet := strings.Replace(unity8ConnectedPlugAppArmor, oldTags, newTags, -1)
   113  	spec.AddSnippet(snippet)
   114  	return nil
   115  }
   116  
   117  func (iface *unity8Interface) AutoConnect(*snap.PlugInfo, *snap.SlotInfo) bool {
   118  	// allow what declarations allowed
   119  	return true
   120  }
   121  
   122  func init() {
   123  	registerIface(&unity8Interface{})
   124  }