summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2018-09-29 23:17:20 +0200
committerKali Kaneko <kali@leap.se>2018-09-29 23:17:20 +0200
commit8f826342f88cd977738d6a2937031d1bdef682d4 (patch)
tree04b80e52b405c0ad1fdecfee8bf0a0b492353b8a
parentcec99a26f50339a14d7c7314507632b7dcc4c32b (diff)
[pkg] remove osx pkg folder
-rw-r--r--pkg/osx/README3
-rw-r--r--pkg/osx/README.rst13
-rwxr-xr-xpkg/osx/bitmask-wrapper3
-rw-r--r--pkg/osx/bitmask.icnsbin47303 -> 0 bytes
-rw-r--r--pkg/osx/daemon/LICENSE15
-rw-r--r--pkg/osx/daemon/_metadata.py7
-rw-r--r--pkg/osx/daemon/daemon.py927
-rwxr-xr-xpkg/osx/makeicons.sh19
-rwxr-xr-xpkg/osx/openvpn/client.down.sh426
-rwxr-xr-xpkg/osx/openvpn/client.up.sh1521
-rwxr-xr-xpkg/osx/quickpkg557
-rwxr-xr-xpkg/osx/scripts-riseupvpn/postinstall13
-rwxr-xr-xpkg/osx/scripts-riseupvpn/preinstall12
-rw-r--r--pkg/osx/scripts-riseupvpn/se.leap.bitmask-helper.plist26
-rwxr-xr-xpkg/osx/scripts/postinstall12
-rwxr-xr-xpkg/osx/scripts/preinstall12
-rw-r--r--pkg/osx/scripts/se.leap.bitmask-helper.plist26
-rwxr-xr-xpkg/osx/uninstall.sh7
18 files changed, 3 insertions, 3596 deletions
diff --git a/pkg/osx/README b/pkg/osx/README
new file mode 100644
index 00000000..51558583
--- /dev/null
+++ b/pkg/osx/README
@@ -0,0 +1,3 @@
+Removed all osx packaging scripts for now.
+Maintenance now happens in riseup_vpn repo.
+
diff --git a/pkg/osx/README.rst b/pkg/osx/README.rst
deleted file mode 100644
index a9156e7b..00000000
--- a/pkg/osx/README.rst
+++ /dev/null
@@ -1,13 +0,0 @@
-Helper files needed for OSX
-===========================
-
-* The bitmask-helper that is run as root can be found in the source tree, in
-``src/leap/bitmask/vpn/helpers/osx``.
-* python ``daemon`` is a dependency for the bitmask-helper, here it is vendored.
-* The plist file ``se.leap.bitmask-helper.plist`` (this should be installed into
- /Library/LaunchDaemons/se.leap.bitmask-helper.plist).
-* OpenVPN up/down scripts: ``openvpn/client.down.sh`` and
- ``openvpn/client.up.sh``.
-
-
-
diff --git a/pkg/osx/bitmask-wrapper b/pkg/osx/bitmask-wrapper
deleted file mode 100755
index e1d1d909..00000000
--- a/pkg/osx/bitmask-wrapper
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
-exec $DIR/bitmask-app
diff --git a/pkg/osx/bitmask.icns b/pkg/osx/bitmask.icns
deleted file mode 100644
index 7cc3e752..00000000
--- a/pkg/osx/bitmask.icns
+++ /dev/null
Binary files differ
diff --git a/pkg/osx/daemon/LICENSE b/pkg/osx/daemon/LICENSE
deleted file mode 100644
index 5e2e41b1..00000000
--- a/pkg/osx/daemon/LICENSE
+++ /dev/null
@@ -1,15 +0,0 @@
-Copying
-=======
-
-This work, ‘python-daemon’, is free software: you may copy, modify,
-and/or distribute this work under certain conditions; see the relevant
-files for specific grant of license. No warranty expressed or implied.
-
-* Parts of this work are licensed to you under the terms of the GNU
-General Public License as published by the Free Software Foundation;
-version 3 of that license or any later version.
-See the file ‘LICENSE.GPL-3’ for details.
-
-* Parts of this work are licensed to you under the terms of the Apache
-License, version 2.0 as published by the Apache Software Foundation.
-See the file ‘LICENSE.ASF-2’ for details.
diff --git a/pkg/osx/daemon/_metadata.py b/pkg/osx/daemon/_metadata.py
deleted file mode 100644
index 24524bb0..00000000
--- a/pkg/osx/daemon/_metadata.py
+++ /dev/null
@@ -1,7 +0,0 @@
-author_name = "Ben Finney"
-author_email = "ben+python@benfinney.id.au"
-year_range = "2001-2017"
-copyright = "Copyright © {year_range} {author} and others".format(
- year_range=copyright_year_range, author=author)
-license = "Apache-2"
-url = "https://alioth.debian.org/projects/python-daemon/"
diff --git a/pkg/osx/daemon/daemon.py b/pkg/osx/daemon/daemon.py
deleted file mode 100644
index 7ca8770e..00000000
--- a/pkg/osx/daemon/daemon.py
+++ /dev/null
@@ -1,927 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# daemon/daemon.py
-# Part of ‘python-daemon’, an implementation of PEP 3143.
-#
-# Copyright © 2008–2015 Ben Finney <ben+python@benfinney.id.au>
-# Copyright © 2007–2008 Robert Niederreiter, Jens Klein
-# Copyright © 2004–2005 Chad J. Schroeder
-# Copyright © 2003 Clark Evans
-# Copyright © 2002 Noah Spurrier
-# Copyright © 2001 Jürgen Hermann
-#
-# This is free software: you may copy, modify, and/or distribute this work
-# under the terms of the Apache License, version 2.0 as published by the
-# Apache Software Foundation.
-# No warranty expressed or implied. See the file ‘LICENSE.ASF-2’ for details.
-
-""" Daemon process behaviour.
- """
-
-from __future__ import (absolute_import, unicode_literals)
-
-import os
-import sys
-import resource
-import errno
-import signal
-import socket
-import atexit
-try:
- # Python 2 has both ‘str’ (bytes) and ‘unicode’ (text).
- basestring = basestring
- unicode = unicode
-except NameError:
- # Python 3 names the Unicode data type ‘str’.
- basestring = str
- unicode = str
-
-
-class DaemonError(Exception):
- """ Base exception class for errors from this module. """
-
- def __init__(self, *args, **kwargs):
- self._chain_from_context()
-
- super(DaemonError, self).__init__(*args, **kwargs)
-
- def _chain_from_context(self):
- _chain_exception_from_existing_exception_context(self, as_cause=True)
-
-
-class DaemonOSEnvironmentError(DaemonError, OSError):
- """ Exception raised when daemon OS environment setup receives error. """
-
-
-class DaemonProcessDetachError(DaemonError, OSError):
- """ Exception raised when process detach fails. """
-
-
-class DaemonContext:
- """ Context for turning the current program into a daemon process.
-
- A `DaemonContext` instance represents the behaviour settings and
- process context for the program when it becomes a daemon. The
- behaviour and environment is customised by setting options on the
- instance, before calling the `open` method.
-
- Each option can be passed as a keyword argument to the `DaemonContext`
- constructor, or subsequently altered by assigning to an attribute on
- the instance at any time prior to calling `open`. That is, for
- options named `wibble` and `wubble`, the following invocation::
-
- foo = daemon.DaemonContext(wibble=bar, wubble=baz)
- foo.open()
-
- is equivalent to::
-
- foo = daemon.DaemonContext()
- foo.wibble = bar
- foo.wubble = baz
- foo.open()
-
- The following options are defined.
-
- `files_preserve`
- :Default: ``None``
-
- List of files that should *not* be closed when starting the
- daemon. If ``None``, all open file descriptors will be closed.
-
- Elements of the list are file descriptors (as returned by a file
- object's `fileno()` method) or Python `file` objects. Each
- specifies a file that is not to be closed during daemon start.
-
- `chroot_directory`
- :Default: ``None``
-
- Full path to a directory to set as the effective root directory of
- the process. If ``None``, specifies that the root directory is not
- to be changed.
-
- `working_directory`
- :Default: ``'/'``
-
- Full path of the working directory to which the process should
- change on daemon start.
-
- Since a filesystem cannot be unmounted if a process has its
- current working directory on that filesystem, this should either
- be left at default or set to a directory that is a sensible “home
- directory” for the daemon while it is running.
-
- `umask`
- :Default: ``0``
-
- File access creation mask (“umask”) to set for the process on
- daemon start.
-
- A daemon should not rely on the parent process's umask value,
- which is beyond its control and may prevent creating a file with
- the required access mode. So when the daemon context opens, the
- umask is set to an explicit known value.
-
- If the conventional value of 0 is too open, consider setting a
- value such as 0o022, 0o027, 0o077, or another specific value.
- Otherwise, ensure the daemon creates every file with an
- explicit access mode for the purpose.
-
- `pidfile`
- :Default: ``None``
-
- Context manager for a PID lock file. When the daemon context opens
- and closes, it enters and exits the `pidfile` context manager.
-
- `detach_process`
- :Default: ``None``
-
- If ``True``, detach the process context when opening the daemon
- context; if ``False``, do not detach.
-
- If unspecified (``None``) during initialisation of the instance,
- this will be set to ``True`` by default, and ``False`` only if
- detaching the process is determined to be redundant; for example,
- in the case when the process was started by `init`, by `initd`, or
- by `inetd`.
-
- `signal_map`
- :Default: system-dependent
-
- Mapping from operating system signals to callback actions.
-
- The mapping is used when the daemon context opens, and determines
- the action for each signal's signal handler:
-
- * A value of ``None`` will ignore the signal (by setting the
- signal action to ``signal.SIG_IGN``).
-
- * A string value will be used as the name of an attribute on the
- ``DaemonContext`` instance. The attribute's value will be used
- as the action for the signal handler.
-
- * Any other value will be used as the action for the
- signal handler. See the ``signal.signal`` documentation
- for details of the signal handler interface.
-
- The default value depends on which signals are defined on the
- running system. Each item from the list below whose signal is
- actually defined in the ``signal`` module will appear in the
- default map:
-
- * ``signal.SIGTTIN``: ``None``
-
- * ``signal.SIGTTOU``: ``None``
-
- * ``signal.SIGTSTP``: ``None``
-
- * ``signal.SIGTERM``: ``'terminate'``
-
- Depending on how the program will interact with its child
- processes, it may need to specify a signal map that
- includes the ``signal.SIGCHLD`` signal (received when a
- child process exits). See the specific operating system's
- documentation for more detail on how to determine what
- circumstances dictate the need for signal handlers.
-
- `uid`
- :Default: ``os.getuid()``
-
- `gid`
- :Default: ``os.getgid()``
-
- The user ID (“UID”) value and group ID (“GID”) value to switch
- the process to on daemon start.
-
- The default values, the real UID and GID of the process, will
- relinquish any effective privilege elevation inherited by the
- process.
-
- `prevent_core`
- :Default: ``True``
-
- If true, prevents the generation of core files, in order to avoid
- leaking sensitive information from daemons run as `root`.
-
- `stdin`
- :Default: ``None``
-
- `stdout`
- :Default: ``None``
-
- `stderr`
- :Default: ``None``
-
- Each of `stdin`, `stdout`, and `stderr` is a file-like object
- which will be used as the new file for the standard I/O stream
- `sys.stdin`, `sys.stdout`, and `sys.stderr` respectively. The file
- should therefore be open, with a minimum of mode 'r' in the case
- of `stdin`, and mimimum of mode 'w+' in the case of `stdout` and
- `stderr`.
-
- If the object has a `fileno()` method that returns a file
- descriptor, the corresponding file will be excluded from being
- closed during daemon start (that is, it will be treated as though
- it were listed in `files_preserve`).
-
- If ``None``, the corresponding system stream is re-bound to the
- file named by `os.devnull`.
-
- """
-
- __metaclass__ = type
-
- def __init__(
- self,
- chroot_directory=None,
- working_directory="/",
- umask=0,
- uid=None,
- gid=None,
- prevent_core=True,
- detach_process=None,
- files_preserve=None,
- pidfile=None,
- stdin=None,
- stdout=None,
- stderr=None,
- signal_map=None,
- ):
- """ Set up a new instance. """
- self.chroot_directory = chroot_directory
- self.working_directory = working_directory
- self.umask = umask
- self.prevent_core = prevent_core
- self.files_preserve = files_preserve
- self.pidfile = pidfile
- self.stdin = stdin
- self.stdout = stdout
- self.stderr = stderr
-
- if uid is None:
- uid = os.getuid()
- self.uid = uid
- if gid is None:
- gid = os.getgid()
- self.gid = gid
-
- if detach_process is None:
- detach_process = is_detach_process_context_required()
- self.detach_process = detach_process
-
- if signal_map is None:
- signal_map = make_default_signal_map()
- self.signal_map = signal_map
-
- self._is_open = False
-
- @property
- def is_open(self):
- """ ``True`` if the instance is currently open. """
- return self._is_open
-
- def open(self):
- """ Become a daemon process.
-
- :return: ``None``.
-
- Open the daemon context, turning the current program into a daemon
- process. This performs the following steps:
-
- * If this instance's `is_open` property is true, return
- immediately. This makes it safe to call `open` multiple times on
- an instance.
-
- * If the `prevent_core` attribute is true, set the resource limits
- for the process to prevent any core dump from the process.
-
- * If the `chroot_directory` attribute is not ``None``, set the
- effective root directory of the process to that directory (via
- `os.chroot`).
-
- This allows running the daemon process inside a “chroot gaol”
- as a means of limiting the system's exposure to rogue behaviour
- by the process. Note that the specified directory needs to
- already be set up for this purpose.
-
- * Set the process UID and GID to the `uid` and `gid` attribute
- values.
-
- * Close all open file descriptors. This excludes those listed in
- the `files_preserve` attribute, and those that correspond to the
- `stdin`, `stdout`, or `stderr` attributes.
-
- * Change current working directory to the path specified by the
- `working_directory` attribute.
-
- * Reset the file access creation mask to the value specified by
- the `umask` attribute.
-
- * If the `detach_process` option is true, detach the current
- process into its own process group, and disassociate from any
- controlling terminal.
-
- * Set signal handlers as specified by the `signal_map` attribute.
-
- * If any of the attributes `stdin`, `stdout`, `stderr` are not
- ``None``, bind the system streams `sys.stdin`, `sys.stdout`,
- and/or `sys.stderr` to the files represented by the
- corresponding attributes. Where the attribute has a file
- descriptor, the descriptor is duplicated (instead of re-binding
- the name).
-
- * If the `pidfile` attribute is not ``None``, enter its context
- manager.
-
- * Mark this instance as open (for the purpose of future `open` and
- `close` calls).
-
- * Register the `close` method to be called during Python's exit
- processing.
-
- When the function returns, the running program is a daemon
- process.
-
- """
- if self.is_open:
- return
-
- if self.chroot_directory is not None:
- change_root_directory(self.chroot_directory)
-
- if self.prevent_core:
- prevent_core_dump()
-
- change_file_creation_mask(self.umask)
- change_working_directory(self.working_directory)
- change_process_owner(self.uid, self.gid)
-
- if self.detach_process:
- detach_process_context()
-
- signal_handler_map = self._make_signal_handler_map()
- set_signal_handlers(signal_handler_map)
-
- exclude_fds = self._get_exclude_file_descriptors()
- close_all_open_files(exclude=exclude_fds)
-
- redirect_stream(sys.stdin, self.stdin)
- redirect_stream(sys.stdout, self.stdout)
- redirect_stream(sys.stderr, self.stderr)
-
- if self.pidfile is not None:
- self.pidfile.__enter__()
-
- self._is_open = True
-
- register_atexit_function(self.close)
-
- def __enter__(self):
- """ Context manager entry point. """
- self.open()
- return self
-
- def close(self):
- """ Exit the daemon process context.
-
- :return: ``None``.
-
- Close the daemon context. This performs the following steps:
-
- * If this instance's `is_open` property is false, return
- immediately. This makes it safe to call `close` multiple times
- on an instance.
-
- * If the `pidfile` attribute is not ``None``, exit its context
- manager.
-
- * Mark this instance as closed (for the purpose of future `open`
- and `close` calls).
-
- """
- if not self.is_open:
- return
-
- if self.pidfile is not None:
- # Follow the interface for telling a context manager to exit,
- # <URL:http://docs.python.org/library/stdtypes.html#typecontextmanager>.
- self.pidfile.__exit__(None, None, None)
-
- self._is_open = False
-
- def __exit__(self, exc_type, exc_value, traceback):
- """ Context manager exit point. """
- self.close()
-
- def terminate(self, signal_number, stack_frame):
- """ Signal handler for end-process signals.
-
- :param signal_number: The OS signal number received.
- :param stack_frame: The frame object at the point the
- signal was received.
- :return: ``None``.
-
- Signal handler for the ``signal.SIGTERM`` signal. Performs the
- following step:
-
- * Raise a ``SystemExit`` exception explaining the signal.
-
- """
- exception = SystemExit(
- "Terminating on signal {signal_number!r}".format(
- signal_number=signal_number))
- raise exception
-
- def _get_exclude_file_descriptors(self):
- """ Get the set of file descriptors to exclude closing.
-
- :return: A set containing the file descriptors for the
- files to be preserved.
-
- The file descriptors to be preserved are those from the
- items in `files_preserve`, and also each of `stdin`,
- `stdout`, and `stderr`. For each item:
-
- * If the item is ``None``, it is omitted from the return
- set.
-
- * If the item's ``fileno()`` method returns a value, that
- value is in the return set.
-
- * Otherwise, the item is in the return set verbatim.
-
- """
- files_preserve = self.files_preserve
- if files_preserve is None:
- files_preserve = []
- files_preserve.extend(
- item for item in [self.stdin, self.stdout, self.stderr]
- if hasattr(item, 'fileno'))
-
- exclude_descriptors = set()
- for item in files_preserve:
- if item is None:
- continue
- file_descriptor = _get_file_descriptor(item)
- if file_descriptor is not None:
- exclude_descriptors.add(file_descriptor)
- else:
- exclude_descriptors.add(item)
-
- return exclude_descriptors
-
- def _make_signal_handler(self, target):
- """ Make the signal handler for a specified target object.
-
- :param target: A specification of the target for the
- handler; see below.
- :return: The value for use by `signal.signal()`.
-
- If `target` is ``None``, return ``signal.SIG_IGN``. If `target`
- is a text string, return the attribute of this instance named
- by that string. Otherwise, return `target` itself.
-
- """
- if target is None:
- result = signal.SIG_IGN
- elif isinstance(target, unicode):
- name = target
- result = getattr(self, name)
- else:
- result = target
-
- return result
-
- def _make_signal_handler_map(self):
- """ Make the map from signals to handlers for this instance.
-
- :return: The constructed signal map for this instance.
-
- Construct a map from signal numbers to handlers for this
- context instance, suitable for passing to
- `set_signal_handlers`.
-
- """
- signal_handler_map = dict(
- (signal_number, self._make_signal_handler(target))
- for (signal_number, target) in self.signal_map.items())
- return signal_handler_map
-
-
-def _get_file_descriptor(obj):
- """ Get the file descriptor, if the object has one.
-
- :param obj: The object expected to be a file-like object.
- :return: The file descriptor iff the file supports it; otherwise
- ``None``.
-
- The object may be a non-file object. It may also be a
- file-like object with no support for a file descriptor. In
- either case, return ``None``.
-
- """
- file_descriptor = None
- if hasattr(obj, 'fileno'):
- try:
- file_descriptor = obj.fileno()
- except ValueError:
- # The item doesn't support a file descriptor.
- pass
-
- return file_descriptor
-
-
-def change_working_directory(directory):
- """ Change the working directory of this process.
-
- :param directory: The target directory path.
- :return: ``None``.
-
- """
- try:
- os.chdir(directory)
- except Exception as exc:
- error = DaemonOSEnvironmentError(
- "Unable to change working directory ({exc})".format(exc=exc))
- raise error
-
-
-def change_root_directory(directory):
- """ Change the root directory of this process.
-
- :param directory: The target directory path.
- :return: ``None``.
-
- Set the current working directory, then the process root directory,
- to the specified `directory`. Requires appropriate OS privileges
- for this process.
-
- """
- try:
- os.chdir(directory)
- os.chroot(directory)
- except Exception as exc:
- error = DaemonOSEnvironmentError(
- "Unable to change root directory ({exc})".format(exc=exc))
- raise error
-
-
-def change_file_creation_mask(mask):
- """ Change the file creation mask for this process.
-
- :param mask: The numeric file creation mask to set.
- :return: ``None``.
-
- """
- try:
- os.umask(mask)
- except Exception as exc:
- error = DaemonOSEnvironmentError(
- "Unable to change file creation mask ({exc})".format(exc=exc))
- raise error
-
-
-def change_process_owner(uid, gid):
- """ Change the owning UID and GID of this process.
-
- :param uid: The target UID for the daemon process.
- :param gid: The target GID for the daemon process.
- :return: ``None``.
-
- Set the GID then the UID of the process (in that order, to avoid
- permission errors) to the specified `gid` and `uid` values.
- Requires appropriate OS privileges for this process.
-
- """
- try:
- os.setgid(gid)
- os.setuid(uid)
- except Exception as exc:
- error = DaemonOSEnvironmentError(
- "Unable to change process owner ({exc})".format(exc=exc))
- raise error
-
-
-def prevent_core_dump():
- """ Prevent this process from generating a core dump.
-
- :return: ``None``.
-
- Set the soft and hard limits for core dump size to zero. On Unix,
- this entirely prevents the process from creating core dump.
-
- """
- core_resource = resource.RLIMIT_CORE
-
- try:
- # Ensure the resource limit exists on this platform, by requesting
- # its current value.
- core_limit_prev = resource.getrlimit(core_resource)
- except ValueError as exc:
- error = DaemonOSEnvironmentError(
- "System does not support RLIMIT_CORE resource limit"
- " ({exc})".format(exc=exc))
- raise error
-
- # Set hard and soft limits to zero, i.e. no core dump at all.
- core_limit = (0, 0)
- resource.setrlimit(core_resource, core_limit)
-
-
-def detach_process_context():
- """ Detach the process context from parent and session.
-
- :return: ``None``.
-
- Detach from the parent process and session group, allowing the
- parent to exit while this process continues running.
-
- Reference: “Advanced Programming in the Unix Environment”,
- section 13.3, by W. Richard Stevens, published 1993 by
- Addison-Wesley.
-
- """
-
- def fork_then_exit_parent(error_message):
- """ Fork a child process, then exit the parent process.
-
- :param error_message: Message for the exception in case of a
- detach failure.
- :return: ``None``.
- :raise DaemonProcessDetachError: If the fork fails.
-
- """
- try:
- pid = os.fork()
- if pid > 0:
- os._exit(0)
- except OSError as exc:
- error = DaemonProcessDetachError(
- "{message}: [{exc.errno:d}] {exc.strerror}".format(
- message=error_message, exc=exc))
- raise error
-
- fork_then_exit_parent(error_message="Failed first fork")
- os.setsid()
- fork_then_exit_parent(error_message="Failed second fork")
-
-
-def is_process_started_by_init():
- """ Determine whether the current process is started by `init`.
-
- :return: ``True`` iff the parent process is `init`; otherwise
- ``False``.
-
- The `init` process is the one with process ID of 1.
-
- """
- result = False
-
- init_pid = 1
- if os.getppid() == init_pid:
- result = True
-
- return result
-
-
-def is_socket(fd):
- """ Determine whether the file descriptor is a socket.
-
- :param fd: The file descriptor to interrogate.
- :return: ``True`` iff the file descriptor is a socket; otherwise
- ``False``.
-
- Query the socket type of `fd`. If there is no error, the file is a
- socket.
-
- """
- result = False
-
- file_socket = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW)
-
- try:
- socket_type = file_socket.getsockopt(
- socket.SOL_SOCKET, socket.SO_TYPE)
- except socket.error as exc:
- exc_errno = exc.args[0]
- if exc_errno == errno.ENOTSOCK:
- # Socket operation on non-socket.
- pass
- else:
- # Some other socket error.
- result = True
- else:
- # No error getting socket type.
- result = True
-
- return result
-
-
-def is_process_started_by_superserver():
- """ Determine whether the current process is started by the superserver.
-
- :return: ``True`` if this process was started by the internet
- superserver; otherwise ``False``.
-
- The internet superserver creates a network socket, and
- attaches it to the standard streams of the child process. If
- that is the case for this process, return ``True``, otherwise
- ``False``.
-
- """
- result = False
-
- stdin_fd = sys.__stdin__.fileno()
- if is_socket(stdin_fd):
- result = True
-
- return result
-
-
-def is_detach_process_context_required():
- """ Determine whether detaching the process context is required.
-
- :return: ``True`` iff the process is already detached; otherwise
- ``False``.
-
- The process environment is interrogated for the following:
-
- * Process was started by `init`; or
-
- * Process was started by `inetd`.
-
- If any of the above are true, the process is deemed to be already
- detached.
-
- """
- result = True
- if is_process_started_by_init() or is_process_started_by_superserver():
- result = False
-
- return result
-
-
-def close_file_descriptor_if_open(fd):
- """ Close a file descriptor if already open.
-
- :param fd: The file descriptor to close.
- :return: ``None``.
-
- Close the file descriptor `fd`, suppressing an error in the
- case the file was not open.
-
- """
- try:
- os.close(fd)
- except EnvironmentError as exc:
- if exc.errno == errno.EBADF:
- # File descriptor was not open.
- pass
- else:
- error = DaemonOSEnvironmentError(
- "Failed to close file descriptor {fd:d} ({exc})".format(
- fd=fd, exc=exc))
- raise error
-
-
-MAXFD = 2048
-
-
-def get_maximum_file_descriptors():
- """ Get the maximum number of open file descriptors for this process.
-
- :return: The number (integer) to use as the maximum number of open
- files for this process.
-
- The maximum is the process hard resource limit of maximum number of
- open file descriptors. If the limit is “infinity”, a default value
- of ``MAXFD`` is returned.
-
- """
- limits = resource.getrlimit(resource.RLIMIT_NOFILE)
- result = limits[1]
- if result == resource.RLIM_INFINITY:
- result = MAXFD
- return result
-
-
-def close_all_open_files(exclude=set()):
- """ Close all open file descriptors.
-
- :param exclude: Collection of file descriptors to skip when closing
- files.
- :return: ``None``.
-
- Closes every file descriptor (if open) of this process. If
- specified, `exclude` is a set of file descriptors to *not*
- close.
-
- """
- maxfd = get_maximum_file_descriptors()
- for fd in reversed(range(maxfd)):
- if fd not in exclude:
- close_file_descriptor_if_open(fd)
-
-
-def redirect_stream(system_stream, target_stream):
- """ Redirect a system stream to a specified file.
-
- :param standard_stream: A file object representing a standard I/O
- stream.
- :param target_stream: The target file object for the redirected
- stream, or ``None`` to specify the null device.
- :return: ``None``.
-
- `system_stream` is a standard system stream such as
- ``sys.stdout``. `target_stream` is an open file object that
- should replace the corresponding system stream object.
-
- If `target_stream` is ``None``, defaults to opening the
- operating system's null device and using its file descriptor.
-
- """
- if target_stream is None:
- target_fd = os.open(os.devnull, os.O_RDWR)
- else:
- target_fd = target_stream.fileno()
- os.dup2(target_fd, system_stream.fileno())
-
-
-def make_default_signal_map():
- """ Make the default signal map for this system.
-
- :return: A mapping from signal number to handler object.
-
- The signals available differ by system. The map will not contain
- any signals not defined on the running system.
-
- """
- name_map = {
- 'SIGTSTP': None,
- 'SIGTTIN': None,
- 'SIGTTOU': None,
- 'SIGTERM': 'terminate',
- }
- signal_map = dict(
- (getattr(signal, name), target)
- for (name, target) in name_map.items()
- if hasattr(signal, name))
-
- return signal_map
-
-
-def set_signal_handlers(signal_handler_map):
- """ Set the signal handlers as specified.
-
- :param signal_handler_map: A map from signal number to handler
- object.
- :return: ``None``.
-
- See the `signal` module for details on signal numbers and signal
- handlers.
-
- """
- for (signal_number, handler) in signal_handler_map.items():
- signal.signal(signal_number, handler)
-
-
-def register_atexit_function(func):
- """ Register a function for processing at program exit.
-
- :param func: A callable function expecting no arguments.
- :return: ``None``.
-
- The function `func` is registered for a call with no arguments
- at program exit.
-
- """
- atexit.register(func)
-
-
-def _chain_exception_from_existing_exception_context(exc, as_cause=False):
- """ Decorate the specified exception with the existing exception context.
-
- :param exc: The exception instance to decorate.
- :param as_cause: If true, the existing context is declared to be
- the cause of the exception.
- :return: ``None``.
-
- :PEP:`344` describes syntax and attributes (`__traceback__`,
- `__context__`, `__cause__`) for use in exception chaining.
-
- Python 2 does not have that syntax, so this function decorates
- the exception with values from the current exception context.
-
- """
- (existing_exc_type, existing_exc, existing_traceback) = sys.exc_info()
- if as_cause:
- exc.__cause__ = existing_exc
- else:
- exc.__context__ = existing_exc
- exc.__traceback__ = existing_traceback
-
-
-# Local variables:
-# coding: utf-8
-# mode: python
-# End:
-# vim: fileencoding=utf-8 filetype=python :
diff --git a/pkg/osx/makeicons.sh b/pkg/osx/makeicons.sh
deleted file mode 100755
index 823af826..00000000
--- a/pkg/osx/makeicons.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env bash
-sizes=(16 32 64 128 256 512)
-largfile='icon_512x512@2x.png'
-if [ ! -f "$largfile" ]; then
- convert -background none -resize 1024x1024 "$1" "$largfile"
-fi
-for s in "${sizes[@]}"; do
- echo $s
- convert -background none -resize ${s}x${s} "$largfile" "icon_${s}x$s.png"
-done
-
-cp 'icon_32x32.png' 'icon_16x16@2x.png'
-mv 'icon_64x64.png' 'icon_32x32@2x.png'
-cp 'icon_256x256.png' 'icon_128x128@2x.png'
-cp 'icon_512x512.png' 'icon_256x256@2x.png'
-
-mkdir icon.iconset
-mv icon_*x*.png icon.iconset
-iconutil -c icns icon.iconset
diff --git a/pkg/osx/openvpn/client.down.sh b/pkg/osx/openvpn/client.down.sh
deleted file mode 100755
index 1e173bba..00000000
--- a/pkg/osx/openvpn/client.down.sh
+++ /dev/null
@@ -1,426 +0,0 @@
-#!/bin/bash -e
-# Note: must be bash; uses bash-specific tricks
-#
-# ******************************************************************************************************************
-# Copyright By Tunnelblick. Redistributed with Bitmask under the GPL.
-# This Tunnelblick script does everything! It handles TUN and TAP interfaces,
-# pushed configurations and DHCP leases. :)
-#
-# This is the "Down" version of the script, executed after the connection is
-# closed.
-#
-# Created by: Nick Williams (using original code and parts of old Tblk scripts)
-#
-# ******************************************************************************************************************
-
-# @param String message - The message to log
-logMessage()
-{
- echo "${@}"
-}
-
-# @param String message - The message to log
-logDebugMessage()
-{
- echo "${@}" > /dev/null
-}
-
-trim()
-{
-echo ${@}
-}
-
-# @param String list - list of network service names, output from disable_ipv6()
-restore_ipv6() {
-
- # Undoes the actions performed by the disable_ipv6() routine in client.up.tunnelblick.sh by restoring the IPv6
- # 'automatic' setting for each network service for which that routine disabled IPv6.
- #
- # $1 must contain the output from disable_ipv6() -- the list of network services.
- #
- # This routine outputs log messages describing its activities.
-
- if [ "$1" = "" ] ; then
- exit
- fi
-
- printf %s "$1
-" | \
- while IFS= read -r ripv6_service ; do
- networksetup -setv6automatic "$ripv6_service"
- logMessage "Re-enabled IPv6 (automatic) for '$ripv6_service'"
- done
-}
-
-##########################################################################################
-flushDNSCache()
-{
- if ${ARG_FLUSH_DNS_CACHE} ; then
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
- readonly OSVER="$(sw_vers | grep 'ProductVersion:' | grep -o '10\.[0-9]*')"
- set -e # We instruct bash that it CAN again fail on errors
- if [ "${OSVER}" = "10.4" ] ; then
-
- if [ -f /usr/sbin/lookupd ] ; then
- set +e # we will catch errors from lookupd
- /usr/sbin/lookupd -flushcache
- if [ $? != 0 ] ; then
- logMessage "WARNING: Unable to flush the DNS cache via lookupd"
- else
- logMessage "Flushed the DNS cache via lookupd"
- fi
- set -e # bash should again fail on errors
- else
- logMessage "WARNING: /usr/sbin/lookupd not present. Not flushing the DNS cache"
- fi
-
- else
-
- if [ -f /usr/bin/dscacheutil ] ; then
- set +e # we will catch errors from dscacheutil
- /usr/bin/dscacheutil -flushcache
- if [ $? != 0 ] ; then
- logMessage "WARNING: Unable to flush the DNS cache via dscacheutil"
- else
- logMessage "Flushed the DNS cache via dscacheutil"
- fi
- set -e # bash should again fail on errors
- else
- logMessage "WARNING: /usr/bin/dscacheutil not present. Not flushing the DNS cache via dscacheutil"
- fi
-
- if [ -f /usr/sbin/discoveryutil ] ; then
- set +e # we will catch errors from discoveryutil
- /usr/sbin/discoveryutil udnsflushcaches
- if [ $? != 0 ] ; then
- logMessage "WARNING: Unable to flush the DNS cache via discoveryutil udnsflushcaches"
- else
- logMessage "Flushed the DNS cache via discoveryutil udnsflushcaches"
- fi
- /usr/sbin/discoveryutil mdnsflushcache
- if [ $? != 0 ] ; then
- logMessage "WARNING: Unable to flush the DNS cache via discoveryutil mdnsflushcache"
- else
- logMessage "Flushed the DNS cache via discoveryutil mdnsflushcache"
- fi
- set -e # bash should again fail on errors
- else
- logMessage "/usr/sbin/discoveryutil not present. Not flushing the DNS cache via discoveryutil"
- fi
-
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
- hands_off_ps="$( ps -ax | grep HandsOffDaemon | grep -v grep.HandsOffDaemon )"
- set -e # We instruct bash that it CAN again fail on errors
- if [ "${hands_off_ps}" = "" ] ; then
- if [ -f /usr/bin/killall ] ; then
- set +e # ignore errors if mDNSResponder isn't currently running
- /usr/bin/killall -HUP mDNSResponder
- if [ $? != 0 ] ; then
- logMessage "mDNSResponder not running. Not notifying it that the DNS cache was flushed"
- else
- logMessage "Notified mDNSResponder that the DNS cache was flushed"
- fi
- set -e # bash should again fail on errors
- else
- logMessage "WARNING: /usr/bin/killall not present. Not notifying mDNSResponder that the DNS cache was flushed"
- fi
- else
- logMessage "WARNING: Hands Off is running. Not notifying mDNSResponder that the DNS cache was flushed"
- fi
-
- fi
- fi
-}
-
-##########################################################################################
-resetPrimaryInterface()
-{
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
- WIFI_INTERFACE="$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}')"
- if [ "${WIFI_INTERFACE}" == "" ] ; then
- WIFI_INTERFACE="$(networksetup -listallhardwareports | awk '$3=="AirPort" {getline; print $2}')"
- fi
- PINTERFACE="$( scutil <<-EOF |
- open
- show State:/Network/Global/IPv4
- quit
-EOF
- grep PrimaryInterface | sed -e 's/.*PrimaryInterface : //'
- )"
- set -e # resume abort on error
-
- if [ "${PINTERFACE}" != "" ] ; then
- if [ "${PINTERFACE}" == "${WIFI_INTERFACE}" -a "${OSVER}" != "10.4" -a -f /usr/sbin/networksetup ] ; then
- if [ "${OSVER}" == "10.5" ] ; then
- logMessage "Resetting primary interface '${PINTERFACE}' via networksetup -setairportpower off/on..."
- /usr/sbin/networksetup -setairportpower off
- sleep 2
- /usr/sbin/networksetup -setairportpower on
- else
- logMessage "Resetting primary interface '${PINTERFACE}' via networksetup -setairportpower ${PINTERFACE} off/on..."
- /usr/sbin/networksetup -setairportpower "${PINTERFACE}" off
- sleep 2
- /usr/sbin/networksetup -setairportpower "${PINTERFACE}" on
- fi
- else
- if [ -f /sbin/ifconfig ] ; then
- logMessage "Resetting primary interface '${PINTERFACE}' via ifconfig ${PINTERFACE} down/up..."
- /sbin/ifconfig "${PINTERFACE}" down
- sleep 2
- /sbin/ifconfig "${PINTERFACE}" up
- else
- logMessage "WARNING: Not resetting primary interface because /sbin/ifconfig does not exist."
- fi
- fi
- else
- logMessage "WARNING: Not resetting primary interface because it cannot be found."
- fi
-}
-
-##########################################################################################
-trap "" TSTP
-trap "" HUP
-trap "" INT
-export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
-
-readonly OUR_NAME=$(basename "${0}")
-
-logMessage "**********************************************"
-logMessage "Start of output from ${OUR_NAME}"
-
-# Remove the flag file that indicates we need to run the down script
-
-if [ -e "/tmp/bitmask-downscript-needs-to-be-run.txt" ] ; then
- rm -f "/tmp/bitmask-downscript-needs-to-be-run.txt"
-fi
-
-# Test for the "-r" Bitmask option (Reset primary interface after disconnecting) because we _always_ need its value.
-# Usually we get the value for that option (and the other options) from State:/Network/OpenVPN,
-# but that key may not exist (because, for example, there were no DNS changes).
-# So we get the value from the Bitmask options passed to this script by OpenVPN.
-#
-# We do the same thing for the -f Bitmask option (Flush DNS cache after connecting or disconnecting)
-ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="false"
-ARG_FLUSH_DNS_CACHE="false"
-while [ {$#} ] ; do
- if [ "${1:0:1}" != "-" ] ; then # Bitmask arguments start with "-" and come first
- break # so if this one doesn't start with "-" we are done processing Bitmask arguments
- fi
- if [ "$1" = "-r" ] ; then
- ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="true"
- else
- if [ "$1" = "-f" ] ; then
- ARG_FLUSH_DNS_CACHE="true"
- fi
- fi
- shift # Shift arguments to examine the next option (if there is one)
-done
-
-# Quick check - is the configuration there?
-if ! scutil -w State:/Network/OpenVPN &>/dev/null -t 1 ; then
- # Configuration isn't there
- logMessage "WARNING: Not restoring DNS settings because no saved Bitmask DNS information was found."
-
- flushDNSCache
-
- if ${ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT} ; then
- resetPrimaryInterface
- fi
- logMessage "End of output from ${OUR_NAME}"
- logMessage "**********************************************"
- exit 0
-fi
-
-# Get info saved by the up script
-TUNNELBLICK_CONFIG="$( scutil <<-EOF
- open
- show State:/Network/OpenVPN
- quit
-EOF
-)"
-
-ARG_MONITOR_NETWORK_CONFIGURATION="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*MonitorNetwork :' | sed -e 's/^.*: //g')"
-LEASEWATCHER_PLIST_PATH="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*LeaseWatcherPlistPath :' | sed -e 's/^.*: //g')"
-REMOVE_LEASEWATCHER_PLIST="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RemoveLeaseWatcherPlist :' | sed -e 's/^.*: //g')"
-PSID="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*Service :' | sed -e 's/^.*: //g')"
-# Don't need: SCRIPT_LOG_FILE="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*ScriptLogFile :' | sed -e 's/^.*: //g')"
-# Don't need: ARG_RESTORE_ON_DNS_RESET="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RestoreOnDNSReset :' | sed -e 's/^.*: //g')"
-# Don't need: ARG_RESTORE_ON_WINS_RESET="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RestoreOnWINSReset :' | sed -e 's/^.*: //g')"
-# Don't need: PROCESS="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*PID :' | sed -e 's/^.*: //g')"
-# Don't need: ARG_IGNORE_OPTION_FLAGS="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*IgnoreOptionFlags :' | sed -e 's/^.*: //g')"
-ARG_TAP="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*IsTapInterface :' | sed -e 's/^.*: //g')"
-ARG_FLUSH_DNS_CACHE="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*FlushDNSCache :' | sed -e 's/^.*: //g')"
-ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*ResetPrimaryInterface :' | sed -e 's/^.*: //g')"
-bRouteGatewayIsDhcp="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RouteGatewayIsDhcp :' | sed -e 's/^.*: //g')"
-bTapDeviceHasBeenSetNone="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*TapDeviceHasBeenSetNone :' | sed -e 's/^.*: //g')"
-bAlsoUsingSetupKeys="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*bAlsoUsingSetupKeys :' | sed -e 's/^.*: //g')"
-sTunnelDevice="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*TunnelDevice :' | sed -e 's/^.*: //g')"
-
-# Note: '\n' was translated into '\t', so we translate it back (it was done because grep and sed only work with single lines)
-sRestoreIpv6Services="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RestoreIpv6Services :' | sed -e 's/^.*: //g' | tr '\t' '\n')"
-
-# Remove leasewatcher
-if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
- launchctl unload "${LEASEWATCHER_PLIST_PATH}"
- if ${REMOVE_LEASEWATCHER_PLIST} ; then
- rm -f "${LEASEWATCHER_PLIST_PATH}"
- fi
- logMessage "Cancelled monitoring of system configuration changes"
-fi
-
-if ${ARG_TAP} ; then
- if [ "$bRouteGatewayIsDhcp" == "true" ]; then
- if [ "$bTapDeviceHasBeenSetNone" == "false" ]; then
- if [ -z "$dev" ]; then
- # If $dev is not defined, then use TunnelDevice, which was set from $dev by client.up.tunnelblick.sh
- # ($def is not defined when this script is called from MenuController to clean up when exiting Bitmask)
- if [ -n "${sTunnelDevice}" ]; then
- logMessage "WARNING: \$dev not defined; using TunnelDevice: ${sTunnelDevice}"
- set +e
- ipconfig set "${sTunnelDevice}" NONE 2>/dev/null
- set -e
- logMessage "Released the DHCP lease via ipconfig set ${sTunnelDevice} NONE."
- else
- logMessage "WARNING: Cannot configure TAP interface to NONE without \$dev or State:/Network/OpenVPN/TunnelDevice being defined. Device may not have disconnected properly."
- fi
- else
- set +e
- ipconfig set "$dev" NONE 2>/dev/null
- set -e
- logMessage "Released the DHCP lease via ipconfig set $dev NONE."
- fi
- fi
- fi
-fi
-
-# Issue warning if the primary service ID has changed
-set +e # "grep" will return error status (1) if no matches are found, so don't fail if not found
-PSID_CURRENT="$( scutil <<-EOF |
- open
- show State:/Network/OpenVPN
- quit
-EOF
-grep 'Service : ' | sed -e 's/.*Service : //'
-)"
-set -e # resume abort on error
-if [ "${PSID}" != "${PSID_CURRENT}" ] ; then
- logMessage "Ignoring change of Network Primary Service from ${PSID} to ${PSID_CURRENT}"
-fi
-
-# Restore configurations
-DNS_OLD="$( scutil <<-EOF
- open
- show State:/Network/OpenVPN/OldDNS
- quit
-EOF
-)"
-SMB_OLD="$( scutil <<-EOF
- open
- show State:/Network/OpenVPN/OldSMB
- quit
-EOF
-)"
-DNS_OLD_SETUP="$( scutil <<-EOF
- open
- show State:/Network/OpenVPN/OldDNSSetup
- quit
-EOF
-)"
-TB_NO_SUCH_KEY="<dictionary> {
- BitmaskNoSuchKey : true
-}"
-
-if [ "${DNS_OLD}" = "${TB_NO_SUCH_KEY}" ] ; then
- scutil <<-EOF
- open
- remove State:/Network/Service/${PSID}/DNS
- quit
-EOF
-else
- scutil <<-EOF
- open
- get State:/Network/OpenVPN/OldDNS
- set State:/Network/Service/${PSID}/DNS
- quit
-EOF
-fi
-
-if [ "${DNS_OLD_SETUP}" = "${TB_NO_SUCH_KEY}" ] ; then
- if ${bAlsoUsingSetupKeys} ; then
- logDebugMessage "DEBUG: Removing 'Setup:' DNS key"
- scutil <<-EOF
- open
- remove Setup:/Network/Service/${PSID}/DNS
- quit
-EOF
- else
- logDebugMessage "DEBUG: Not removing 'Setup:' DNS key"
- fi
-else
- if ${bAlsoUsingSetupKeys} ; then
- logDebugMessage "DEBUG: Restoring 'Setup:' DNS key"
- scutil <<-EOF
- open
- get State:/Network/OpenVPN/OldDNSSetup
- set Setup:/Network/Service/${PSID}/DNS
- quit
-EOF
- else
- logDebugMessage "DEBUG: Not restoring 'Setup:' DNS key"
- fi
-fi
-
-if [ "${SMB_OLD}" = "${TB_NO_SUCH_KEY}" ] ; then
- scutil > /dev/null <<-EOF
- open
- remove State:/Network/Service/${PSID}/SMB
- quit
-EOF
-else
- scutil > /dev/null <<-EOF
- open
- get State:/Network/OpenVPN/OldSMB
- set State:/Network/Service/${PSID}/SMB
- quit
-EOF
-fi
-
-logMessage "Restored the DNS and SMB configurations"
-
-set +e # "grep" will return error status (1) if no matches are found, so don't fail if not found
-new_resolver_contents="$( grep -v '#' < /etc/resolv.conf )"
-set -e # resume abort on error
-logDebugMessage "DEBUG:"
-logDebugMessage "DEBUG: /etc/resolve = ${new_resolver_contents}"
-
-set +e # scutil --dns will return error status in case dns is already down, so don't fail if no dns found
-scutil_dns="$( scutil --dns)"
-set -e # resume abort on error
-logDebugMessage "DEBUG:"
-logDebugMessage "DEBUG: scutil --dns = ${scutil_dns}"
-logDebugMessage "DEBUG:"
-
-restore_ipv6 "$sRestoreIpv6Services"
-
-flushDNSCache
-
-# Remove our system configuration data
-scutil <<-EOF
- open
- remove State:/Network/OpenVPN/OldDNS
- remove State:/Network/OpenVPN/OldSMB
- remove State:/Network/OpenVPN/OldDNSSetup
- remove State:/Network/OpenVPN/DNS
- remove State:/Network/OpenVPN/SMB
- remove State:/Network/OpenVPN
- quit
-EOF
-
-if ${ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT} ; then
- resetPrimaryInterface
-fi
-
-logMessage "End of output from ${OUR_NAME}"
-logMessage "**********************************************"
-
-exit 0
diff --git a/pkg/osx/openvpn/client.up.sh b/pkg/osx/openvpn/client.up.sh
deleted file mode 100755
index a713c10e..00000000
--- a/pkg/osx/openvpn/client.up.sh
+++ /dev/null
@@ -1,1521 +0,0 @@
-#!/bin/bash -e
-# Note: must be bash; uses bash-specific tricks
-#
-# ******************************************************************************************************************
-# Copyright by Tunnelblick. Redistributed under GPL as part of Bitmask.
-# This Tunnelblick script does everything! It handles TUN and TAP interfaces,
-# pushed configurations, DHCP with DNS and SMB, and renewed DHCP leases. :)
-#
-# This is the "Up" version of the script, executed after the interface is
-# initialized.
-#
-# Created by: Nick Williams (using original code and parts of old Tblk scripts)
-# Modifed by: Jonathan K. Bullard for Mountain Lion
-# Adapted to use by Bitmask by: Kali Kaneko
-#
-# ******************************************************************************************************************
-
-
-##########################################################################################
-# @param String message - The message to log
-logMessage()
-{
- echo "${@}"
-}
-
-##########################################################################################
-# @param String message - The message to log
-logDebugMessage()
-{
- if ${ARG_EXTRA_LOGGING} ; then
- echo "${@}"
- fi
-}
-
-##########################################################################################
-# log a change to a setting
-# @param String filters - empty, or one or two '#' if not performing the change
-# @param String name of setting that is being changed
-# @param String new value
-# @param String old value
-logChange()
-{
- if [ "$1" = "" ] ; then
- if [ "$3" = "$4" ] ; then
- echo "Did not change $2 setting of '$3' (but re-set it)"
- else
- echo "Changed $2 setting from '$4' to '$3'"
- fi
- else
- echo "Did not change $2 setting of '$4'"
- fi
-}
-
-##########################################################################################
-# @param String string - Content to trim
-trim()
-{
- echo ${@}
-}
-
-##########################################################################################
-disable_ipv6() {
-
-# Disables IPv6 on each enabled (active) network service on which it is set to the OS X default "IPv6 Automatic".
-#
-# For each such service, outputs a line with the name of the service.
-# (A separate line is output for each name because a name may include spaces.)
-#
-# The 'restore_ipv6' routine in client.down.sh undoes the actions performed by this routine.
-#
-# NOTE: Done only for enabled services because some versions of OS X enable the service if this IPv6 setting is changed.
-#
-# This only works for OS X 10.5 and higher (10.4 does not implement IPv6.)
-
- if [ "$OSVER" = "10.4" ] ; then
- exit
- fi
-
- # Get list of services and remove the first line which contains a heading
- dipv6_services="$( networksetup -listallnetworkservices | sed -e '1,1d')"
-
- # Go through the list disabling IPv6 for enabled services, and outputting lines with the names of the services
- printf %s "$dipv6_services
-" | \
- while IFS= read -r dipv6_service ; do
-
- # If first character of a line is an asterisk, the service is disabled, so we skip it
- if [ "${dipv6_service:0:1}" != "*" ] ; then
- dipv6_ipv6_status="$( networksetup -getinfo "$dipv6_service" | grep 'IPv6: ' | sed -e 's/IPv6: //')"
- if [ "$dipv6_ipv6_status" = "Automatic" ] ; then
- networksetup -setv6off "$dipv6_service"
- echo "$dipv6_service"
- fi
- fi
-
- done
-}
-
-##########################################################################################
-# @param String[] dnsServers - The name servers to use
-# @param String domainName - The domain name to use
-# @param \optional String[] winsServers - The SMB servers to use
-# @param \optional String[] searchDomains - The search domains to use
-#
-# Throughout this routine:
-# MAN_ is a prefix for manually set parameters
-# DYN_ is a prefix for dynamically set parameters (by a "push", config file, or command line option)
-# CUR_ is a prefix for the current parameters (as arbitrated by OS X between manual and DHCP data)
-# FIN_ is a prefix for the parameters we want to end up with
-# SKP_ is a prefix for an empty string or a "#" used to control execution of statements that set parameters in scutil
-#
-# DNS_SA is a suffix for the ServerAddresses value in a System Configuration DNS key
-# DNS_SD is a suffix for the SearchDomains value in a System Configuration DNS key
-# DNS_DN is a suffix for the DomainName value in a System Configuration DNS key
-#
-# SMB_NN is a suffix for the NetBIOSName value in a System Configuration SMB key
-# SMB_WG is a suffix for the Workgroup value in a System Configuration SMB key
-# SMB_WA is a suffix for the WINSAddresses value in a System Configuration SMB key
-#
-# So, for example, MAN_SMB_NN is the manually set NetBIOSName value (or the empty string if not set manually)
-
-setDnsServersAndDomainName()
-{
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
-
- PSID="$( scutil <<-EOF |
- open
- show State:/Network/Global/IPv4
- quit
-EOF
-grep PrimaryService | sed -e 's/.*PrimaryService : //'
-)"
-
- set -e # resume abort on error
-
- MAN_DNS_CONFIG="$( scutil <<-EOF |
- open
- show Setup:/Network/Service/${PSID}/DNS
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
-
- MAN_SMB_CONFIG="$( scutil <<-EOF |
- open
- show Setup:/Network/Service/${PSID}/SMB
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
- CUR_DNS_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/Global/DNS
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
-
- CUR_SMB_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/Global/SMB
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
-
-# Set up the DYN_... variables to contain what is asked for (dynamically, by a 'push' directive, for example)
-
- declare -a vDNS=("${!1}")
- declare -a vSMB=("${!3}")
- declare -a vSD=("${!4}")
-
- if [ ${#vDNS[*]} -eq 0 ] ; then
- readonly DYN_DNS_SA=""
- else
- readonly DYN_DNS_SA="${!1}"
- fi
-
- if [ ${#vSMB[*]} -eq 0 ] ; then
- readonly DYN_SMB_WA=""
- else
- readonly DYN_SMB_WA="${!3}"
- fi
-
- if [ ${#vSD[*]} -eq 0 ] ; then
- readonly DYN_DNS_SD=""
- else
- readonly DYN_DNS_SD="${!4}"
- fi
-
- DYN_DNS_DN="$2"
-
- # The variables
- # DYN_SMB_WG
- # DYN_SMB_NN
- # are left empty. There isn't a way for OpenVPN to set them.
-
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: MAN_DNS_CONFIG = ${MAN_DNS_CONFIG}"
- logDebugMessage "DEBUG: MAN_SMB_CONFIG = ${MAN_SMB_CONFIG}"
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: CUR_DNS_CONFIG = ${CUR_DNS_CONFIG}"
- logDebugMessage "DEBUG: CUR_SMB_CONFIG = ${CUR_SMB_CONFIG}"
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: DYN_DNS_DN = ${DYN_DNS_DN}; DYN_DNS_SA = ${DYN_DNS_SA}; DYN_DNS_SD = ${DYN_DNS_SD}"
- logDebugMessage "DEBUG: DYN_SMB_NN = ${DYN_SMB_NN}; DYN_SMB_WG = ${DYN_SMB_WG}; DYN_SMB_WA = ${DYN_SMB_WA}"
-
-# Set up the MAN_... variables to contain manual network settings
-
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
-
- if echo "${MAN_DNS_CONFIG}" | grep -q "DomainName" ; then
- readonly MAN_DNS_DN="$( trim "$( echo "${MAN_DNS_CONFIG}" | sed -e 's/^.*DomainName[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
- else
- readonly MAN_DNS_DN="";
- fi
- if echo "${MAN_DNS_CONFIG}" | grep -q "ServerAddresses" ; then
- readonly MAN_DNS_SA="$( trim "$( echo "${MAN_DNS_CONFIG}" | sed -e 's/^.*ServerAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
- else
- readonly MAN_DNS_SA="";
- fi
- if echo "${MAN_DNS_CONFIG}" | grep -q "SearchDomains" ; then
- readonly MAN_DNS_SD="$( trim "$( echo "${MAN_DNS_CONFIG}" | sed -e 's/^.*SearchDomains[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
- else
- readonly MAN_DNS_SD="";
- fi
- if echo "${MAN_SMB_CONFIG}" | grep -q "NetBIOSName" ; then
- readonly MAN_SMB_NN="$( trim "$( echo "${MAN_SMB_CONFIG}" | sed -e 's/^.*NetBIOSName : \([^[:space:]]*\).*$/\1/g' )" )"
- else
- readonly MAN_SMB_NN="";
- fi
- if echo "${MAN_SMB_CONFIG}" | grep -q "Workgroup" ; then
- readonly MAN_SMB_WG="$( trim "$( echo "${MAN_SMB_CONFIG}" | sed -e 's/^.*Workgroup : \([^[:space:]]*\).*$/\1/g' )" )"
- else
- readonly MAN_SMB_WG="";
- fi
- if echo "${MAN_SMB_CONFIG}" | grep -q "WINSAddresses" ; then
- readonly MAN_SMB_WA="$( trim "$( echo "${MAN_SMB_CONFIG}" | sed -e 's/^.*WINSAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
- else
- readonly MAN_SMB_WA="";
- fi
-
- set -e # resume abort on error
-
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: MAN_DNS_DN = ${MAN_DNS_DN}; MAN_DNS_SA = ${MAN_DNS_SA}; MAN_DNS_SD = ${MAN_DNS_SD}"
- logDebugMessage "DEBUG: MAN_SMB_NN = ${MAN_SMB_NN}; MAN_SMB_WG = ${MAN_SMB_WG}; MAN_SMB_WA = ${MAN_SMB_WA}"
-
-# Set up the CUR_... variables to contain the current network settings (from manual or DHCP, as arbitrated by OS X
-
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
-
- if echo "${CUR_DNS_CONFIG}" | grep -q "DomainName" ; then
- readonly CUR_DNS_DN="$(trim "$( echo "${CUR_DNS_CONFIG}" | sed -e 's/^.*DomainName : \([^[:space:]]*\).*$/\1/g' )")"
- else
- readonly CUR_DNS_DN="";
- fi
- if echo "${CUR_DNS_CONFIG}" | grep -q "ServerAddresses" ; then
- readonly CUR_DNS_SA="$(trim "$( echo "${CUR_DNS_CONFIG}" | sed -e 's/^.*ServerAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )")"
- else
- readonly CUR_DNS_SA="";
- fi
- if echo "${CUR_DNS_CONFIG}" | grep -q "SearchDomains" ; then
- readonly CUR_DNS_SD="$(trim "$( echo "${CUR_DNS_CONFIG}" | sed -e 's/^.*SearchDomains[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )")"
- else
- readonly CUR_DNS_SD="";
- fi
- if echo "${CUR_SMB_CONFIG}" | grep -q "NetBIOSName" ; then
- readonly CUR_SMB_NN="$(trim "$( echo "${CUR_SMB_CONFIG}" | sed -e 's/^.*NetBIOSName : \([^[:space:]]*\).*$/\1/g' )")"
- else
- readonly CUR_SMB_NN="";
- fi
- if echo "${CUR_SMB_CONFIG}" | grep -q "Workgroup" ; then
- readonly CUR_SMB_WG="$(trim "$( echo "${CUR_SMB_CONFIG}" | sed -e 's/^.*Workgroup : \([^[:space:]]*\).*$/\1/g' )")"
- else
- readonly CUR_SMB_WG="";
- fi
- if echo "${CUR_SMB_CONFIG}" | grep -q "WINSAddresses" ; then
- readonly CUR_SMB_WA="$(trim "$( echo "${CUR_SMB_CONFIG}" | sed -e 's/^.*WINSAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )")"
- else
- readonly CUR_SMB_WA="";
- fi
-
- set -e # resume abort on error
-
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: CUR_DNS_DN = ${CUR_DNS_DN}; CUR_DNS_SA = ${CUR_DNS_SA}; CUR_DNS_SD = ${CUR_DNS_SD}"
- logDebugMessage "DEBUG: CUR_SMB_NN = ${CUR_SMB_NN}; CUR_SMB_WG = ${CUR_SMB_WG}; CUR_SMB_WA = ${CUR_SMB_WA}"
-
-# set up the FIN_... variables with what we want to set things to
-
- # Three FIN_... variables are simple -- no aggregation is done for them
-
- if [ "${DYN_DNS_DN}" != "" ] ; then
- if [ "${MAN_DNS_DN}" != "" ] ; then
- logMessage "WARNING: Ignoring DomainName '$DYN_DNS_DN' because DomainName was set manually"
- readonly FIN_DNS_DN="${MAN_DNS_DN}"
- else
- readonly FIN_DNS_DN="${DYN_DNS_DN}"
- fi
- else
- readonly FIN_DNS_DN="${CUR_DNS_DN}"
- fi
-
- if [ "${DYN_SMB_NN}" != "" ] ; then
- if [ "${MAN_SMB_NN}" != "" ] ; then
- logMessage "WARNING: Ignoring NetBIOSName '$DYN_SMB_NN' because NetBIOSName was set manually"
- readonly FIN_SMB_NN="${MAN_SMB_NN}"
- else
- readonly FIN_SMB_NN="${DYN_SMB_NN}"
- fi
- else
- readonly FIN_SMB_NN="${CUR_SMB_NN}"
- fi
-
- if [ "${DYN_SMB_WG}" != "" ] ; then
- if [ "${MAN_SMB_WG}" != "" ] ; then
- logMessage "WARNING: Ignoring Workgroup '$DYN_SMB_WG' because Workgroup was set manually"
- readonly FIN_SMB_WG="${MAN_SMB_WG}"
- else
- readonly FIN_SMB_WG="${DYN_SMB_WG}"
- fi
- else
- readonly FIN_SMB_WG="${CUR_SMB_WG}"
- fi
-
- # DNS ServerAddresses (FIN_DNS_SA) are aggregated for 10.4 and 10.5
- if [ ${#vDNS[*]} -eq 0 ] ; then
- readonly FIN_DNS_SA="${CUR_DNS_SA}"
- else
- if [ "${MAN_DNS_SA}" != "" ] ; then
- logMessage "WARNING: Ignoring ServerAddresses '$DYN_DNS_SA' because ServerAddresses was set manually"
- readonly FIN_DNS_SA="${CUR_DNS_SA}"
- else
- case "${OSVER}" in
- 10.4 | 10.5 )
- # We need to remove duplicate DNS entries, so that our reference list matches MacOSX's
- SDNS="$( echo "${DYN_DNS_SA}" | tr ' ' '\n' )"
- (( i=0 ))
- for n in "${vDNS[@]}" ; do
- if echo "${SDNS}" | grep -q "${n}" ; then
- unset vDNS[${i}]
- fi
- (( i++ ))
- done
- if [ ${#vDNS[*]} -gt 0 ] ; then
- readonly FIN_DNS_SA="$( trim "${DYN_DNS_SA}" "${vDNS[*]}" )"
- else
- readonly FIN_DNS_SA="${DYN_DNS_SA}"
- fi
- logMessage "Aggregating ServerAddresses because running on OS X 10.4 or 10.5"
- ;;
- * )
- # Do nothing - in 10.6 and higher -- we don't aggregate our configurations, apparently
- readonly FIN_DNS_SA="${DYN_DNS_SA}"
- logMessage "Not aggregating ServerAddresses because running on OS X 10.6 or higher"
- ;;
- esac
- fi
- fi
-
- # SMB WINSAddresses (FIN_SMB_WA) are aggregated for 10.4 and 10.5
- if [ ${#vSMB[*]} -eq 0 ] ; then
- readonly FIN_SMB_WA="${CUR_SMB_WA}"
- else
- if [ "${MAN_SMB_WA}" != "" ] ; then
- logMessage "WARNING: Ignoring WINSAddresses '$DYN_SMB_WA' because WINSAddresses was set manually"
- readonly FIN_SMB_WA="${MAN_SMB_WA}"
- else
- case "${OSVER}" in
- 10.4 | 10.5 )
- # We need to remove duplicate SMB entries, so that our reference list matches MacOSX's
- SSMB="$( echo "${DYN_SMB_WA}" | tr ' ' '\n' )"
- (( i=0 ))
- for n in "${vSMB[@]}" ; do
- if echo "${SSMB}" | grep -q "${n}" ; then
- unset vSMB[${i}]
- fi
- (( i++ ))
- done
- if [ ${#vSMB[*]} -gt 0 ] ; then
- readonly FIN_SMB_WA="$( trim "${DYN_SMB_WA}" "${vSMB[*]}" )"
- else
- readonly FIN_SMB_WA="${DYN_SMB_WA}"
- fi
- logMessage "Aggregating WINSAddresses because running on OS X 10.4 or 10.5"
- ;;
- * )
- # Do nothing - in 10.6 and higher -- we don't aggregate our configurations, apparently
- readonly FIN_SMB_WA="${DYN_SMB_WA}"
- logMessage "Not aggregating WINSAddresses because running on OS X 10.6 or higher"
- ;;
- esac
- fi
- fi
-
- # DNS SearchDomains (FIN_DNS_SD) is treated specially
- #
- # OLD BEHAVIOR:
- # if SearchDomains was not set manually, we set SearchDomains to the DomainName
- # else
- # In OS X 10.4-10.5, we add the DomainName to the end of any manual SearchDomains (unless it is already there)
- # In OS X 10.6+, if SearchDomains was entered manually, we ignore the DomainName
- # else we set SearchDomains to the DomainName
- #
- # NEW BEHAVIOR (done if ARG_PREPEND_DOMAIN_NAME is "true"):
- #
- # if SearchDomains was entered manually, we do nothing
- # else we PREpend new SearchDomains (if any) to the existing SearchDomains (NOT replacing them)
- # and PREpend DomainName to that
- #
- # (done if ARG_PREPEND_DOMAIN_NAME is "false" and there are new SearchDomains from DOMAIN-SEARCH):
- #
- # if SearchDomains was entered manually, we do nothing
- # else we PREpend any new SearchDomains to the existing SearchDomains (NOT replacing them)
- #
- # This behavior is meant to behave like Linux with Network Manager and Windows
-
- if "${ARG_PREPEND_DOMAIN_NAME}" ; then
- if [ "${MAN_DNS_SD}" = "" ] ; then
- if [ "${DYN_DNS_SD}" != "" ] ; then
- if ! echo "${CUR_DNS_SD}" | tr ' ' '\n' | grep -q "${DYN_DNS_SD}" ; then
- logMessage "Prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because the search domains were not set manually and 'Prepend domain name to search domains' was selected"
- readonly TMP_DNS_SD="$( trim "${DYN_DNS_SD}" "${CUR_DNS_SD}" )"
- else
- logMessage "Not prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because it is already there"
- readonly TMP_DNS_SD="${CUR_DNS_SD}"
- fi
- else
- readonly TMP_DNS_SD="${CUR_DNS_SD}"
- fi
- if [ "${FIN_DNS_DN}" != "" -a "${FIN_DNS_DN}" != "localdomain" ] ; then
- if ! echo "${TMP_DNS_SD}" | tr ' ' '\n' | grep -q "${FIN_DNS_DN}" ; then
- logMessage "Prepending '${FIN_DNS_DN}' to search domains '${TMP_DNS_SD}' because the search domains were not set manually and 'Prepend domain name to search domains' was selected"
- readonly FIN_DNS_SD="$( trim "${FIN_DNS_DN}" "${TMP_DNS_SD}" )"
- else
- logMessage "Not prepending '${FIN_DNS_DN}' to search domains '${TMP_DNS_SD}' because it is already there"
- readonly FIN_DNS_SD="${TMP_DNS_SD}"
- fi
- else
- readonly FIN_DNS_SD="${TMP_DNS_SD}"
- fi
- else
- if [ "${DYN_DNS_SD}" != "" ] ; then
- logMessage "WARNING: Not prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because the search domains were set manually"
- fi
- if [ "${FIN_DNS_DN}" != "" ] ; then
- logMessage "WARNING: Not prepending domain '${FIN_DNS_DN}' to search domains '${CUR_DNS_SD}' because the search domains were set manually"
- fi
- readonly FIN_DNS_SD="${CUR_DNS_SD}"
- fi
- else
- if [ "${DYN_DNS_SD}" != "" ] ; then
- if [ "${MAN_DNS_SD}" = "" ] ; then
- logMessage "Prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because the search domains were not set manually but were set via OpenVPN and 'Prepend domain name to search domains' was not selected"
- readonly FIN_DNS_SD="$( trim "${DYN_DNS_SD}" "${CUR_DNS_SD}" )"
- else
- logMessage "WARNING: Not prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because the search domains were set manually"
- readonly FIN_DNS_SD="${CUR_DNS_SD}"
- fi
- else
- if [ "${FIN_DNS_DN}" != "" -a "${FIN_DNS_DN}" != "localdomain" ] ; then
- case "${OSVER}" in
- 10.4 | 10.5 )
- if ! echo "${MAN_DNS_SD}" | tr ' ' '\n' | grep -q "${FIN_DNS_DN}" ; then
- logMessage "Appending '${FIN_DNS_DN}' to search domains '${CUR_DNS_SD}' that were set manually because running under OS X 10.4 or 10.5 and 'Prepend domain name to search domains' was not selected"
- readonly FIN_DNS_SD="$( trim "${MAN_DNS_SD}" "${FIN_DNS_DN}" )"
- else
- logMessage "Not appending '${FIN_DNS_DN}' to search domains '${CUR_DNS_SD}' because it is already in the search domains that were set manually and 'Prepend domain name to search domains' was not selected"
- readonly FIN_DNS_SD="${CUR_DNS_SD}"
- fi
- ;;
- * )
- if [ "${MAN_DNS_SD}" = "" ] ; then
- logMessage "Setting search domains to '${FIN_DNS_DN}' because running under OS X 10.6 or higher and the search domains were not set manually and 'Prepend domain name to search domains' was not selected"
- readonly FIN_DNS_SD="${FIN_DNS_DN}"
- else
- logMessage "Not replacing search domains '${CUR_DNS_SD}' with '${FIN_DNS_DN}' because the search domains were set manually and 'Prepend domain name to search domains' was not selected"
- readonly FIN_DNS_SD="${CUR_DNS_SD}"
- fi
- ;;
- esac
- else
- readonly FIN_DNS_SD="${CUR_DNS_SD}"
- fi
- fi
- fi
-
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: FIN_DNS_DN = ${FIN_DNS_DN}; FIN_DNS_SA = ${FIN_DNS_SA}; FIN_DNS_SD = ${FIN_DNS_SD}"
- logDebugMessage "DEBUG: FIN_SMB_NN = ${FIN_SMB_NN}; FIN_SMB_WG = ${FIN_SMB_WG}; FIN_SMB_WA = ${FIN_SMB_WA}"
-
-# Set up SKP_... variables to inhibit scutil from making some changes
-
- # SKP_DNS_... and SKP_SMB_... are used to comment out individual items that are not being set
- if [ "${FIN_DNS_DN}" = "" -o "${FIN_DNS_DN}" = "${CUR_DNS_DN}" ] ; then
- SKP_DNS_DN="#"
- else
- SKP_DNS_DN=""
- fi
- if [ "${FIN_DNS_SA}" = "" -o "${FIN_DNS_SA}" = "${CUR_DNS_SA}" ] ; then
- SKP_DNS_SA="#"
- else
- SKP_DNS_SA=""
- fi
- if [ "${FIN_DNS_SD}" = "" -o "${FIN_DNS_SD}" = "${CUR_DNS_SD}" ] ; then
- SKP_DNS_SD="#"
- else
- SKP_DNS_SD=""
- fi
- if [ "${FIN_SMB_NN}" = "" -o "${FIN_SMB_NN}" = "${CUR_SMB_NN}" ] ; then
- SKP_SMB_NN="#"
- else
- SKP_SMB_NN=""
- fi
- if [ "${FIN_SMB_WG}" = "" -o "${FIN_SMB_WG}" = "${CUR_SMB_WG}" ] ; then
- SKP_SMB_WG="#"
- else
- SKP_SMB_WG=""
- fi
- if [ "${FIN_SMB_WA}" = "" -o "${FIN_SMB_WA}" = "${CUR_SMB_WA}" ] ; then
- SKP_SMB_WA="#"
- else
- SKP_SMB_WA=""
- fi
-
- # if any DNS items should be set, set all that have values
- if [ "${SKP_DNS_DN}${SKP_DNS_SA}${SKP_DNS_SD}" = "###" ] ; then
- readonly SKP_DNS="#"
- else
- readonly SKP_DNS=""
- if [ "${FIN_DNS_DN}" != "" ] ; then
- SKP_DNS_DN=""
- fi
- if [ "${FIN_DNS_SA}" != "" ] ; then
- SKP_DNS_SA=""
- fi
- if [ "${FIN_DNS_SD}" != "" ] ; then
- SKP_DNS_SD=""
- fi
- fi
-
- # if any SMB items should be set, set all that have values
- if [ "${SKP_SMB_NN}${SKP_SMB_WG}${SKP_SMB_WA}" = "###" ] ; then
- readonly SKP_SMB="#"
- else
- readonly SKP_SMB=""
- if [ "${FIN_SMB_NN}" != "" ] ; then
- SKP_SMB_NN=""
- fi
- if [ "${FIN_SMB_WG}" != "" ] ; then
- SKP_SMB_WG=""
- fi
- if [ "${FIN_SMB_WA}" != "" ] ; then
- SKP_SMB_WA=""
- fi
- fi
-
- readonly SKP_DNS_SA SKP_DNS_SD SKP_DNS_DN
- readonly SKP_SMB_NN SKP_SMB_WG SKP_SMB_WA
-
-# special-case fiddling:
-
- # in 10.8 and higher, ServerAddresses and SearchDomains must be set via the Setup: key in addition to the State: key
- # in 10.7 if ServerAddresses or SearchDomains are manually set, ServerAddresses and SearchDomains must be similarly set with the Setup: key in addition to the State: key
- #
- # we pass a flag indicating whether we've done that to the other scripts in 'bAlsoUsingSetupKeys'
-
- case "${OSVER}" in
- 10.4 | 10.5 | 10.6 )
- logDebugMessage "DEBUG: OS X 10.4-10.6, so will modify settings using only State:"
- readonly SKP_SETUP_DNS="#"
- readonly bAlsoUsingSetupKeys="false"
- ;;
- 10.7 )
- if [ "${MAN_DNS_SA}" = "" -a "${MAN_DNS_SD}" = "" ] ; then
- logDebugMessage "DEBUG: OS X 10.7 and neither ServerAddresses nor SearchDomains were set manually, so will modify DNS settings using only State:"
- readonly SKP_SETUP_DNS="#"
- readonly bAlsoUsingSetupKeys="false"
- else
- logDebugMessage "DEBUG: OS X 10.7 and ServerAddresses or SearchDomains were set manually, so will modify DNS settings using Setup: in addition to State:"
- readonly SKP_SETUP_DNS=""
- readonly bAlsoUsingSetupKeys="true"
- fi
- ;;
- * )
- logDebugMessage "DEBUG: OS X 10.8 or higher, so will modify DNS settings using Setup: in addition to State:"
- readonly SKP_SETUP_DNS=""
- readonly bAlsoUsingSetupKeys="true"
- ;;
- esac
-
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: SKP_DNS = ${SKP_DNS}; SKP_DNS_SA = ${SKP_DNS_SA}; SKP_DNS_SD = ${SKP_DNS_SD}; SKP_DNS_DN = ${SKP_DNS_DN}"
- logDebugMessage "DEBUG: SKP_SETUP_DNS = ${SKP_SETUP_DNS}"
- logDebugMessage "DEBUG: SKP_SMB = ${SKP_SMB}; SKP_SMB_NN = ${SKP_SMB_NN}; SKP_SMB_WG = ${SKP_SMB_WG}; SKP_SMB_WA = ${SKP_SMB_WA}"
-
- set +e # "grep" will return error status (1) if no matches are found, so don't fail if not found
- original_resolver_contents="$( grep -v '#' < /etc/resolv.conf )"
- set -e # resume abort on error
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: /etc/resolve = ${original_resolver_contents}"
- logDebugMessage "DEBUG:"
-
- set +e # scutil --dns will return error status in case dns is already down, so don't fail if no dns found
- scutil_dns="$( scutil --dns)"
- set -e # resume abort on error
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: scutil --dns BEFORE CHANGES = ${scutil_dns}"
- logDebugMessage "DEBUG:"
-
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: Configuration changes:"
- logDebugMessage "DEBUG: ${SKP_DNS}${SKP_DNS_SA}ADD State: ServerAddresses ${FIN_DNS_SA}"
- logDebugMessage "DEBUG: ${SKP_DNS}${SKP_DNS_SD}ADD State: SearchDomains ${FIN_DNS_SD}"
- logDebugMessage "DEBUG: ${SKP_DNS}${SKP_DNS_DN}ADD State: DomainName ${FIN_DNS_DN}"
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_SA}ADD Setup: ServerAddresses ${FIN_DNS_SA}"
- logDebugMessage "DEBUG: ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_SD}ADD Setup: SearchDomains ${FIN_DNS_SD}"
- logDebugMessage "DEBUG: ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_DN}ADD Setup: DomainName ${FIN_DNS_DN}"
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: ${SKP_SMB}${SKP_SMB_NN}ADD State: NetBIOSName ${FIN_SMB_NN}"
- logDebugMessage "DEBUG: ${SKP_SMB}${SKP_SMB_WG}ADD State: Workgroup ${FIN_SMB_WG}"
- logDebugMessage "DEBUG: ${SKP_SMB}${SKP_SMB_WA}ADD State: WINSAddresses ${FIN_SMB_WA}"
-
- # Save the openvpn process ID and the Network Primary Service ID, leasewather.plist path, logfile path, and optional arguments from Bitmask,
- # then save old and new DNS and SMB settings
- # PPID is a script variable (defined by bash itself) that contains the process ID of the parent of the process running the script (i.e., OpenVPN's process ID)
- # config is an environmental variable set to the configuration path by OpenVPN prior to running this up script
-
- scutil <<-EOF > /dev/null
- open
-
- # Store our variables for the other scripts (leasewatch, down, etc.) to use
- d.init
- # The '#' in the next line does NOT start a comment; it indicates to scutil that a number follows it (as opposed to a string or an array)
- d.add PID # ${PPID}
- d.add Service ${PSID}
- d.add LeaseWatcherPlistPath "${LEASEWATCHER_PLIST_PATH}"
- d.add RemoveLeaseWatcherPlist "${REMOVE_LEASEWATCHER_PLIST}"
- d.add ScriptLogFile "${SCRIPT_LOG_FILE}"
- d.add MonitorNetwork "${ARG_MONITOR_NETWORK_CONFIGURATION}"
- d.add RestoreOnDNSReset "${ARG_RESTORE_ON_DNS_RESET}"
- d.add RestoreOnWINSReset "${ARG_RESTORE_ON_WINS_RESET}"
- d.add IgnoreOptionFlags "${ARG_IGNORE_OPTION_FLAGS}"
- d.add IsTapInterface "${ARG_TAP}"
- d.add FlushDNSCache "${ARG_FLUSH_DNS_CACHE}"
- d.add ResetPrimaryInterface "${ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT}"
- d.add RouteGatewayIsDhcp "${bRouteGatewayIsDhcp}"
- d.add bAlsoUsingSetupKeys "${bAlsoUsingSetupKeys}"
- d.add TapDeviceHasBeenSetNone "false"
- d.add TunnelDevice "$dev"
- d.add RestoreIpv6Services "$ipv6_disabled_services_encoded"
- set State:/Network/OpenVPN
-
- # Back up the device's current DNS and SMB configurations,
- # Indicate 'no such key' by a dictionary with a single entry: "BitmaskNoSuchKey : true"
- # If there isn't a key, "BitmaskNoSuchKey : true" won't be removed.
- # If there is a key, "BitmaskNoSuchKey : true" will be removed and the key's contents will be used
-
- d.init
- d.add BitmaskNoSuchKey true
- get State:/Network/Service/${PSID}/DNS
- set State:/Network/OpenVPN/OldDNS
-
- d.init
- d.add BitmaskNoSuchKey true
- get Setup:/Network/Service/${PSID}/DNS
- set State:/Network/OpenVPN/OldDNSSetup
-
- d.init
- d.add BitmaskNoSuchKey true
- get State:/Network/Service/${PSID}/SMB
- set State:/Network/OpenVPN/OldSMB
-
- # Initialize the new DNS map via State:
- ${SKP_DNS}d.init
- ${SKP_DNS}${SKP_DNS_SA}d.add ServerAddresses * ${FIN_DNS_SA}
- ${SKP_DNS}${SKP_DNS_SD}d.add SearchDomains * ${FIN_DNS_SD}
- ${SKP_DNS}${SKP_DNS_DN}d.add DomainName ${FIN_DNS_DN}
- ${SKP_DNS}set State:/Network/Service/${PSID}/DNS
-
- # If necessary, initialize the new DNS map via Setup: also
- ${SKP_SETUP_DNS}${SKP_DNS}d.init
- ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_SA}d.add ServerAddresses * ${FIN_DNS_SA}
- ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_SD}d.add SearchDomains * ${FIN_DNS_SD}
- ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_DN}d.add DomainName ${FIN_DNS_DN}
- ${SKP_SETUP_DNS}${SKP_DNS}set Setup:/Network/Service/${PSID}/DNS
-
- # Initialize the SMB map
- ${SKP_SMB}d.init
- ${SKP_SMB}${SKP_SMB_NN}d.add NetBIOSName ${FIN_SMB_NN}
- ${SKP_SMB}${SKP_SMB_WG}d.add Workgroup ${FIN_SMB_WG}
- ${SKP_SMB}${SKP_SMB_WA}d.add WINSAddresses * ${FIN_SMB_WA}
- ${SKP_SMB}set State:/Network/Service/${PSID}/SMB
-
- quit
-EOF
-
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: Pause for configuration changes to be propagated to State:/Network/Global/DNS and .../SMB"
- sleep 1
-
- scutil <<-EOF > /dev/null
- open
-
- # Initialize the maps that will be compared when a configuration change occurs
- d.init
- d.add BitmaskNoSuchKey true
- get State:/Network/Global/DNS
- set State:/Network/OpenVPN/DNS
-
- d.init
- d.add BitmaskNoSuchKey true
- get State:/Network/Global/SMB
- set State:/Network/OpenVPN/SMB
-
- quit
-EOF
-
- readonly NEW_DNS_SETUP_CONFIG="$( scutil <<-EOF |
- open
- show Setup:/Network/Service/${PSID}/DNS
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
- readonly NEW_SMB_SETUP_CONFIG="$( scutil <<-EOF |
- open
- show Setup:/Network/Service/${PSID}/SMB
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
- readonly NEW_DNS_STATE_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/Service/${PSID}/DNS
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
- readonly NEW_SMB_STATE_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/Service/${PSID}/SMB
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
- readonly NEW_DNS_GLOBAL_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/Global/DNS
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
- readonly NEW_SMB_GLOBAL_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/Global/SMB
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
- readonly EXPECTED_NEW_DNS_GLOBAL_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/OpenVPN/DNS
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
- readonly EXPECTED_NEW_SMB_GLOBAL_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/OpenVPN/SMB
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
-
-
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: Configurations as read back after changes:"
- logDebugMessage "DEBUG: State:/.../DNS = ${NEW_DNS_STATE_CONFIG}"
- logDebugMessage "DEBUG: State:/.../SMB = ${NEW_SMB_STATE_CONFIG}"
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: Setup:/.../DNS = ${NEW_DNS_SETUP_CONFIG}"
- logDebugMessage "DEBUG: Setup:/.../SMB = ${NEW_SMB_SETUP_CONFIG}"
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: State:/Network/Global/DNS = ${NEW_DNS_GLOBAL_CONFIG}"
- logDebugMessage "DEBUG: State:/Network/Global/SMB = ${NEW_SMB_GLOBAL_CONFIG}"
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: Expected by process-network-changes:"
- logDebugMessage "DEBUG: State:/Network/OpenVPN/DNS = ${EXPECTED_NEW_DNS_GLOBAL_CONFIG}"
- logDebugMessage "DEBUG: State:/Network/OpenVPN/SMB = ${EXPECTED_NEW_SMB_GLOBAL_CONFIG}"
-
- set +e # "grep" will return error status (1) if no matches are found, so don't fail if not found
- new_resolver_contents="$( grep -v '#' < /etc/resolv.conf )"
- set -e # resume abort on error
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: /etc/resolve = ${new_resolver_contents}"
- logDebugMessage "DEBUG:"
-
- set +e # scutil --dns will return error status in case dns is already down, so don't fail if no dns found
- scutil_dns="$( scutil --dns )"
- set -e # resume abort on error
- logDebugMessage "DEBUG:"
- logDebugMessage "DEBUG: scutil --dns AFTER CHANGES = ${scutil_dns}"
- logDebugMessage "DEBUG:"
-
- logMessage "Saved the DNS and SMB configurations so they can be restored"
-
- logChange "${SKP_DNS}${SKP_DNS_SA}" "DNS ServerAddresses" "${FIN_DNS_SA}" "${CUR_DNS_SA}"
- logChange "${SKP_DNS}${SKP_DNS_SD}" "DNS SearchDomains" "${FIN_DNS_SD}" "${CUR_DNS_SD}"
- logChange "${SKP_DNS}${SKP_DNS_DN}" "DNS DomainName" "${FIN_DNS_DN}" "${CUR_DNS_DN}"
- logChange "${SKP_SMB}${SKP_SMB_NN}" "SMB NetBIOSName" "${FIN_SMB_SA}" "${CUR_SMB_SA}"
- logChange "${SKP_SMB}${SKP_SMB_WG}" "SMB Workgroup" "${FIN_SMB_WG}" "${CUR_SMB_WG}"
- logChange "${SKP_SMB}${SKP_SMB_WA}" "SMB WINSAddresses" "${FIN_SMB_WA}" "${CUR_SMB_WA}"
-
- logDnsInfo "${MAN_DNS_SA}" "${FIN_DNS_SA}"
-
- flushDNSCache
-
- if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
- if [ "${ARG_IGNORE_OPTION_FLAGS:0:2}" = "-p" ] ; then
- logMessage "Setting up to monitor system configuration with process-network-changes"
- else
- logMessage "Setting up to monitor system configuration with leasewatch"
- fi
- if [ "${LEASEWATCHER_TEMPLATE_PATH}" != "" ] ; then
- sed -e "s|/Applications/Bitmask/.app/Contents/Resources|${TB_RESOURCES_PATH}|g" "${LEASEWATCHER_TEMPLATE_PATH}" > "${LEASEWATCHER_PLIST_PATH}"
- fi
- launchctl load "${LEASEWATCHER_PLIST_PATH}"
- fi
-}
-
-##########################################################################################
-# Used for TAP device which does DHCP
-configureDhcpDns()
-{
- # whilst ipconfig will have created the neccessary Network Service keys, the DNS
- # settings won't actually be used by OS X unless the SupplementalMatchDomains key
- # is added
- # ref. <http://lists.apple.com/archives/Macnetworkprog/2005/Jun/msg00011.html>
- # - is there a way to extract the domains from the SC dictionary and re-insert
- # as SupplementalMatchDomains? i.e. not requiring the ipconfig domain_name call?
-
- # - wait until we get a lease before extracting the DNS domain name and merging into SC
- # - despite it's name, ipconfig waitall doesn't (but maybe one day it will :-)
- logDebugMessage "DEBUG: About to 'ipconfig waitall'"
- ipconfig waitall
- logDebugMessage "DEBUG: Completed 'ipconfig waitall'"
-
- unset test_domain_name
- unset test_name_server
-
- set +e # We instruct bash NOT to exit on individual command errors, because if we need to wait longer these commands will fail
-
- # usually takes at least a few seconds to get a DHCP lease
- sleep 3
- n=0
- while [ -z "$test_domain_name" -a -z "$test_name_server" -a $n -lt 5 ]
- do
- logMessage "Sleeping for $n seconds to wait for DHCP to finish setup."
- sleep $n
- n="$( expr $n + 1 )"
-
- if [ -z "$test_domain_name" ]; then
- test_domain_name="$( ipconfig getoption "$dev" domain_name 2>/dev/null )"
- fi
-
- if [ -z "$test_name_server" ]; then
- test_name_server="$( ipconfig getoption "$dev" domain_name_server 2>/dev/null )"
- fi
- done
-
- logDebugMessage "DEBUG: Finished waiting for DHCP lease: test_domain_name = '$test_domain_name', test_name_server = '$test_name_server'"
-
- logDebugMessage "DEBUG: About to 'ipconfig getpacket $dev'"
- sGetPacketOutput="$( ipconfig getpacket "$dev" )"
- logDebugMessage "DEBUG: Completed 'ipconfig getpacket $dev'; sGetPacketOutput = $sGetPacketOutput"
-
- set -e # We instruct bash that it CAN again fail on individual errors
-
- unset aNameServers
- unset aWinsServers
- unset aSearchDomains
-
- nNameServerIndex=1
- nWinsServerIndex=1
- nSearchDomainIndex=1
-
- if [ "$sGetPacketOutput" ]; then
- sGetPacketOutput_FirstLine="$( echo "$sGetPacketOutput" | head -n 1 )"
- logDebugMessage "DEBUG: sGetPacketOutput_FirstLine = $sGetPacketOutput_FirstLine"
-
- if [ "$sGetPacketOutput_FirstLine" == "op = BOOTREPLY" ]; then
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
-
- for tNameServer in $( echo "$sGetPacketOutput" | grep "domain_name_server" | grep -Eo "\{([0-9\.]+)(, [0-9\.]+)*\}" | grep -Eo "([0-9\.]+)" ); do
- aNameServers[nNameServerIndex-1]="$( trim "$tNameServer" )"
- let nNameServerIndex++
- done
-
- for tWINSServer in $( echo "$sGetPacketOutput" | grep "nb_over_tcpip_name_server" | grep -Eo "\{([0-9\.]+)(, [0-9\.]+)*\}" | grep -Eo "([0-9\.]+)" ); do
- aWinsServers[nWinsServerIndex-1]="$( trim "$tWINSServer" )"
- let nWinsServerIndex++
- done
-
- for tSearchDomain in $( echo "$sGetPacketOutput" | grep "search_domain" | grep -Eo "\{([-A-Za-z0-9\-\.]+)(, [-A-Za-z0-9\-\.]+)*\}" | grep -Eo "([-A-Za-z0-9\-\.]+)" ); do
- aSearchDomains[nSearchDomainIndex-1]="$( trim "$tSearchDomain" )"
- let nSearchDomainIndex++
- done
-
- sDomainName="$( echo "$sGetPacketOutput" | grep "domain_name " | grep -Eo ": [-A-Za-z0-9\-\.]+" | grep -Eo "[-A-Za-z0-9\-\.]+" )"
- sDomainName="$( trim "$sDomainName" )"
-
- if [ ${#aNameServers[*]} -gt 0 -a "$sDomainName" ]; then
- logMessage "Retrieved from DHCP/BOOTP packet: name server(s) [ ${aNameServers[@]} ], domain name [ $sDomainName ], search domain(s) [ ${aSearchDomains[@]} ] and SMB server(s) [ ${aWinsServers[@]} ]"
- setDnsServersAndDomainName aNameServers[@] "$sDomainName" aWinsServers[@] aSearchDomains[@]
- return 0
- elif [ ${#aNameServers[*]} -gt 0 ]; then
- logMessage "Retrieved from DHCP/BOOTP packet: name server(s) [ ${aNameServers[@]} ], search domain(s) [ ${aSearchDomains[@]} ] and SMB server(s) [ ${aWinsServers[@]} ] and using default domain name [ $DEFAULT_DOMAIN_NAME ]"
- setDnsServersAndDomainName aNameServers[@] "$DEFAULT_DOMAIN_NAME" aWinsServers[@] aSearchDomains[@]
- return 0
- else
- # Should we return 1 here and indicate an error, or attempt the old method?
- logMessage "No useful information extracted from DHCP/BOOTP packet. Attempting legacy configuration."
- fi
-
- set -e # We instruct bash that it CAN again fail on errors
- else
- # Should we return 1 here and indicate an error, or attempt the old method?
- logMessage "No DHCP/BOOTP packet found on interface. Attempting legacy configuration."
- fi
- fi
-
- unset sDomainName
- unset sNameServer
- unset aNameServers
-
- set +e # We instruct bash NOT to exit on individual command errors, because if we need to wait longer these commands will fail
-
- logDebugMessage "DEBUG: About to 'ipconfig getoption $dev domain_name'"
- sDomainName="$( ipconfig getoption "$dev" domain_name 2>/dev/null )"
- logDebugMessage "DEBUG: Completed 'ipconfig getoption $dev domain_name'"
- logDebugMessage "DEBUG: About to 'ipconfig getoption $dev domain_name_server'"
- sNameServer="$( ipconfig getoption "$dev" domain_name_server 2>/dev/null )"
- logDebugMessage "DEBUG: Completed 'ipconfig getoption $dev domain_name_server'"
-
- set -e # We instruct bash that it CAN again fail on individual errors
-
- sDomainName="$( trim "$sDomainName" )"
- sNameServer="$( trim "$sNameServer" )"
-
- declare -a aWinsServers=( ) # Declare empty WINSServers array to avoid any useless error messages
- declare -a aSearchDomains=( ) # Declare empty SearchDomains array to avoid any useless error messages
-
- if [ "$sDomainName" -a "$sNameServer" ]; then
- aNameServers[0]=$sNameServer
- logMessage "Retrieved OpenVPN (DHCP): name server [ $sNameServer ], domain name [ $sDomainName ], and no SMB servers or search domains"
- setDnsServersAndDomainName aNameServers[@] "$sDomainName" aWinsServers[@] aSearchDomains[@]
- elif [ "$sNameServer" ]; then
- aNameServers[0]=$sNameServer
- logMessage "Retrieved OpenVPN (DHCP): name server [ $sNameServer ] and no SMB servers or search domains, and using default domain name [ $DEFAULT_DOMAIN_NAME ]"
- setDnsServersAndDomainName aNameServers[@] "$DEFAULT_DOMAIN_NAME" aWinsServers[@] aSearchDomains[@]
- elif [ "$sDomainName" ]; then
- logMessage "WARNING: Retrieved domain name [ $sDomainName ] but no name servers from OpenVPN via DHCP, which is not sufficient to make network/DNS configuration changes."
- if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
- logMessage "WARNING: Will NOT monitor for other network configuration changes."
- fi
- logDnsInfoNoChanges
- flushDNSCache
- else
- logMessage "WARNING: No DNS information received from OpenVPN via DHCP, so no network/DNS configuration changes need to be made."
- if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
- logMessage "WARNING: Will NOT monitor for other network configuration changes."
- fi
- logDnsInfoNoChanges
- flushDNSCache
- fi
-
- return 0
-}
-
-##########################################################################################
-# Configures using OpenVPN foreign_option_* instead of DHCP
-
-configureOpenVpnDns()
-{
-# Description of foreign_option_ parameters (from OpenVPN 2.3-alpha_2 man page):
-#
-# DOMAIN name -- Set Connection-specific DNS Suffix.
-#
-# DOMAIN-SEARCH name -- Set Connection-specific DNS Search Address. Repeat this option to
-# set additional search domains. (Bitmask-specific addition.)
-#
-# DNS addr -- Set primary domain name server address. Repeat this option to set
-# secondary DNS server addresses.
-#
-# WINS addr -- Set primary WINS server address (NetBIOS over TCP/IP Name Server).
-# Repeat this option to set secondary WINS server addresses.
-#
-# NBDD addr -- Set primary NBDD server address (NetBIOS over TCP/IP Datagram Distribution Server)
-# Repeat this option to set secondary NBDD server addresses.
-#
-# NTP addr -- Set primary NTP server address (Network Time Protocol). Repeat this option
-# to set secondary NTP server addresses.
-#
-# NBT type -- Set NetBIOS over TCP/IP Node type. Possible options: 1 = b-node
-# (broadcasts), 2 = p-node (point-to-point name queries to a WINS server), 4 = m-
-# node (broadcast then query name server), and 8 = h-node (query name server, then
-# broadcast).
-#
-# NBS scope-id -- Set NetBIOS over TCP/IP Scope. A NetBIOS Scope ID provides an
-# extended naming service for the NetBIOS over TCP/IP (Known as NBT) module. The
-# primary purpose of a NetBIOS scope ID is to isolate NetBIOS traffic on a single
-# network to only those nodes with the same NetBIOS scope ID. The NetBIOS scope ID
-# is a character string that is appended to the NetBIOS name. The NetBIOS scope ID
-# on two hosts must match, or the two hosts will not be able to communicate. The
-# NetBIOS Scope ID also allows computers to use the same computer name, as they have
-# different scope IDs. The Scope ID becomes a part of the NetBIOS name, making the
-# name unique. (This description of NetBIOS scopes courtesy of NeonSurge@abyss.com)
-#
-#DISABLE-NBT -- Disable Netbios-over-TCP/IP.
-
- unset vForOptions
- unset vOptions
- unset aNameServers
- unset aWinsServers
- unset aSearchDomains
-
- nOptionIndex=1
- nNameServerIndex=1
- nWinsServerIndex=1
- nSearchDomainIndex=1
-
- while vForOptions=foreign_option_$nOptionIndex; [ -n "${!vForOptions}" ]; do
- vOptions[nOptionIndex-1]=${!vForOptions}
- case ${vOptions[nOptionIndex-1]} in
- *DOMAIN-SEARCH* )
- aSearchDomains[nSearchDomainIndex-1]="$( trim "${vOptions[nOptionIndex-1]//dhcp-option DOMAIN-SEARCH /}" )"
- let nSearchDomainIndex++
- ;;
- *DOMAIN* )
- sDomainName="$( trim "${vOptions[nOptionIndex-1]//dhcp-option DOMAIN /}" )"
- ;;
- *DNS* )
- aNameServers[nNameServerIndex-1]="$( trim "${vOptions[nOptionIndex-1]//dhcp-option DNS /}" )"
- let nNameServerIndex++
- ;;
- *WINS* )
- aWinsServers[nWinsServerIndex-1]="$( trim "${vOptions[nOptionIndex-1]//dhcp-option WINS /}" )"
- let nWinsServerIndex++
- ;;
- * )
- logMessage "WARNING: 'foreign_option_${nOptionIndex}' = '${vOptions[nOptionIndex-1]}' ignored"
- ;;
- esac
- let nOptionIndex++
- done
-
- if [ ${#aNameServers[*]} -gt 0 -a "$sDomainName" ]; then
- logMessage "Retrieved from OpenVPN: name server(s) [ ${aNameServers[@]} ], domain name [ $sDomainName ], search domain(s) [ ${aSearchDomains[@]} ], and SMB server(s) [ ${aWinsServers[@]} ]"
- setDnsServersAndDomainName aNameServers[@] "$sDomainName" aWinsServers[@] aSearchDomains[@]
- elif [ ${#aNameServers[*]} -gt 0 ]; then
- logMessage "Retrieved from OpenVPN: name server(s) [ ${aNameServers[@]} ], search domain(s) [ ${aSearchDomains[@]} ] and SMB server(s) [ ${aWinsServers[@]} ] and using default domain name [ $DEFAULT_DOMAIN_NAME ]"
- setDnsServersAndDomainName aNameServers[@] "$DEFAULT_DOMAIN_NAME" aWinsServers[@] aSearchDomains[@]
- else
- logMessage "WARNING: No DNS information received from OpenVPN, so no network configuration changes need to be made."
- if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
- logMessage "WARNING: Will NOT monitor for other network configuration changes."
- fi
- logDnsInfoNoChanges
- flushDNSCache
- fi
-
- return 0
-}
-
-##########################################################################################
-flushDNSCache()
-{
- if ${ARG_FLUSH_DNS_CACHE} ; then
- if [ "${OSVER}" = "10.4" ] ; then
-
- if [ -f /usr/sbin/lookupd ] ; then
- set +e # we will catch errors from lookupd
- /usr/sbin/lookupd -flushcache
- if [ $? != 0 ] ; then
- logMessage "WARNING: Unable to flush the DNS cache via lookupd"
- else
- logMessage "Flushed the DNS cache via lookupd"
- fi
- set -e # bash should again fail on errors
- else
- logMessage "WARNING: /usr/sbin/lookupd not present. Not flushing the DNS cache"
- fi
-
- else
-
- if [ -f /usr/bin/dscacheutil ] ; then
- set +e # we will catch errors from dscacheutil
- /usr/bin/dscacheutil -flushcache
- if [ $? != 0 ] ; then
- logMessage "WARNING: Unable to flush the DNS cache via dscacheutil"
- else
- logMessage "Flushed the DNS cache via dscacheutil"
- fi
- set -e # bash should again fail on errors
- else
- logMessage "WARNING: /usr/bin/dscacheutil not present. Not flushing the DNS cache via dscacheutil"
- fi
-
- if [ -f /usr/sbin/discoveryutil ] ; then
- set +e # we will catch errors from discoveryutil
- /usr/sbin/discoveryutil udnsflushcaches
- if [ $? != 0 ] ; then
- logMessage "WARNING: Unable to flush the DNS cache via discoveryutil udnsflushcaches"
- else
- logMessage "Flushed the DNS cache via discoveryutil udnsflushcaches"
- fi
- /usr/sbin/discoveryutil mdnsflushcache
- if [ $? != 0 ] ; then
- logMessage "WARNING: Unable to flush the DNS cache via discoveryutil mdnsflushcache"
- else
- logMessage "Flushed the DNS cache via discoveryutil mdnsflushcache"
- fi
- set -e # bash should again fail on errors
- else
- logMessage "/usr/sbin/discoveryutil not present. Not flushing the DNS cache via discoveryutil"
- fi
-
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
- hands_off_ps="$( ps -ax | grep HandsOffDaemon | grep -v grep.HandsOffDaemon )"
- set -e # We instruct bash that it CAN again fail on errors
- if [ "${hands_off_ps}" = "" ] ; then
- if [ -f /usr/bin/killall ] ; then
- set +e # ignore errors if mDNSResponder isn't currently running
- /usr/bin/killall -HUP mDNSResponder
- if [ $? != 0 ] ; then
- logMessage "mDNSResponder not running. Not notifying it that the DNS cache was flushed"
- else
- logMessage "Notified mDNSResponder that the DNS cache was flushed"
- fi
- set -e # bash should again fail on errors
- else
- logMessage "WARNING: /usr/bin/killall not present. Not notifying mDNSResponder that the DNS cache was flushed"
- fi
- else
- logMessage "WARNING: Hands Off is running. Not notifying mDNSResponder that the DNS cache was flushed"
- fi
-
- fi
- fi
-}
-
-
-##########################################################################################
-# log information about the DNS settings
-# @param String Manual DNS_SA
-# @param String New DNS_SA
-logDnsInfo() {
-
- log_dns_info_manual_dns_sa="$1"
- log_dns_info_new_dns_sa="$2"
-
- if [ "${log_dns_info_manual_dns_sa}" != "" ] ; then
- logMessage "DNS servers '${log_dns_info_manual_dns_sa}' were set manually"
- if [ "${log_dns_info_manual_dns_sa}" != "${log_dns_info_new_dns_sa}" ] ; then
- logMessage "WARNING: that setting is being ignored by OS X; '${log_dns_info_new_dns_sa}' is being used."
- fi
- fi
-
- if [ "${log_dns_info_new_dns_sa}" != "" ] ; then
- logMessage "DNS servers '${log_dns_info_new_dns_sa}' will be used for DNS queries when the VPN is active"
- if [ "${log_dns_info_new_dns_sa}" == "127.0.0.1" ] ; then
- logMessage "NOTE: DNS server 127.0.0.1 often is used inside virtual machines (e.g., 'VirtualBox', 'Parallels', or 'VMWare'). The actual VPN server may be specified by the host machine. This DNS server setting may cause DNS queries to fail or be intercepted or falsified. Specify only known public DNS servers or DNS servers located on the VPN network to avoid such problems."
- else
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
- serversContainLoopback="$( echo "${log_dns_info_new_dns_sa}" | grep "127.0.0.1" )"
- set -e # We instruct bash that it CAN again fail on errors
- if [ "${serversContainLoopback}" != "" ] ; then
- logMessage "NOTE: DNS server 127.0.0.1 often is used inside virtual machines (e.g., 'VirtualBox', 'Parallels', or 'VMWare'). The actual VPN server may be specified by the host machine. If used, 127.0.0.1 may cause DNS queries to fail or be intercepted or falsified. Specify only known public DNS servers or DNS servers located on the VPN network to avoid such problems."
- else
- readonly knownPublicDnsServers="$( cat "${FREE_PUBLIC_DNS_SERVERS_LIST_PATH}" )"
- knownDnsServerNotFound="true"
- unknownDnsServerFound="false"
- for server in ${log_dns_info_new_dns_sa} ; do
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
- serverIsKnown="$( echo "${knownPublicDnsServers}" | grep "${server}" )"
- set -e # We instruct bash that it CAN again fail on errors
- if [ "${serverIsKnown}" != "" ] ; then
- knownDnsServerNotFound="false"
- else
- unknownDnsServerFound="true"
- fi
- done
- if ${knownDnsServerNotFound} ; then
- logMessage "NOTE: The DNS servers do not include any free public DNS servers known to Bitmask. This may cause DNS queries to fail or be intercepted or falsified even if they are directed through the VPN. Specify only known public DNS servers or DNS servers located on the VPN network to avoid such problems."
- else
- if ${unknownDnsServerFound} ; then
- logMessage "NOTE: The DNS servers include one or more free public DNS servers known to Bitmask and one or more DNS servers not known to Bitmask. If used, the DNS servers not known to Bitmask may cause DNS queries to fail or be intercepted or falsified even if they are directed through the VPN. Specify only known public DNS servers or DNS servers located on the VPN network to avoid such problems."
- else
- logMessage "The DNS servers include only free public DNS servers known to Bitmask."
- fi
- fi
- fi
- fi
- else
- logMessage "WARNING: There are no DNS servers in this computer's new network configuration. This computer or a DHCP server that this computer uses may be configured incorrectly."
- fi
-}
-
-logDnsInfoNoChanges() {
-# log information about DNS settings if they are not changing
-
- set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
-
- PSID="$( scutil <<-EOF |
- open
- show State:/Network/Global/IPv4
- quit
-EOF
-grep PrimaryService | sed -e 's/.*PrimaryService : //'
-)"
-
- readonly LOGDNSINFO_MAN_DNS_CONFIG="$( scutil <<-EOF |
- open
- show Setup:/Network/Service/${PSID}/DNS
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
-
- readonly LOGDNSINFO_CUR_DNS_CONFIG="$( scutil <<-EOF |
- open
- show State:/Network/Global/DNS
- quit
-EOF
-sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
-)"
-
- if echo "${LOGDNSINFO_MAN_DNS_CONFIG}" | grep -q "ServerAddresses" ; then
- readonly LOGDNSINFO_MAN_DNS_SA="$( trim "$( echo "${LOGDNSINFO_MAN_DNS_CONFIG}" | sed -e 's/^.*ServerAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
- else
- readonly LOGDNSINFO_MAN_DNS_SA="";
- fi
-
- if echo "${LOGDNSINFO_CUR_DNS_CONFIG}" | grep -q "ServerAddresses" ; then
- readonly LOGDNSINFO_CUR_DNS_SA="$( trim "$( echo "${LOGDNSINFO_CUR_DNS_CONFIG}" | sed -e 's/^.*ServerAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
- else
- readonly LOGDNSINFO_CUR_DNS_SA="";
- fi
-
- set -e # resume abort on error
-
- logDnsInfo "${LOGDNSINFO_MAN_DNS_SA}" "${LOGDNSINFO_CUR_DNS_SA}"
-}
-
-##########################################################################################
-#
-# START OF SCRIPT
-#
-##########################################################################################
-
-trap "" TSTP
-trap "" HUP
-trap "" INT
-export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
-
-readonly OUR_NAME="$( basename "${0}" )"
-
-logMessage "**********************************************"
-logMessage "Start of output from ${OUR_NAME}"
-
-# Process optional arguments (if any) for the script
-# Each one begins with a "-"
-# They come from Bitmask, and come first, before the OpenVPN arguments
-# So we set ARG_ script variables to their values and shift them out of the argument list
-# When we're done, only the OpenVPN arguments remain for the rest of the script to use
-ARG_TAP="false"
-ARG_WAIT_FOR_DHCP_IF_TAP="false"
-ARG_RESTORE_ON_DNS_RESET="false"
-ARG_FLUSH_DNS_CACHE="false"
-ARG_IGNORE_OPTION_FLAGS=""
-ARG_EXTRA_LOGGING="false"
-ARG_MONITOR_NETWORK_CONFIGURATION="false"
-ARG_DO_NO_USE_DEFAULT_DOMAIN="false"
-ARG_PREPEND_DOMAIN_NAME="false"
-ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="false"
-ARG_TB_PATH="/Applications/Bitmask.app"
-ARG_RESTORE_ON_WINS_RESET="false"
-ARG_DISABLE_IPV6_ON_TUN="false"
-ARG_ENABLE_IPV6_ON_TAP="false"
-
-# Handle the arguments we know about by setting ARG_ script variables to their values, then shift them out
-while [ {$#} ] ; do
- if [ "$1" = "-6" ] ; then # -6 = ARG_ENABLE_IPV6_ON_TAP (for TAP connections only)
- ARG_ENABLE_IPV6_ON_TAP="true"
- shift
- elif [ "$1" = "-9" ] ; then # -9 = ARG_DISABLE_IPV6_ON_TUN (for TUN connections only)
- ARG_DISABLE_IPV6_ON_TUN="true"
- shift
- elif [ "$1" = "-a" ] ; then # -a = ARG_TAP
- ARG_TAP="true"
- shift
- elif [ "$1" = "-b" ] ; then # -b = ARG_WAIT_FOR_DHCP_IF_TAP
- ARG_WAIT_FOR_DHCP_IF_TAP="true"
- shift
- elif [ "$1" = "-d" ] ; then # -d = ARG_RESTORE_ON_DNS_RESET
- ARG_RESTORE_ON_DNS_RESET="true"
- shift
- elif [ "$1" = "-f" ] ; then # -f = ARG_FLUSH_DNS_CACHE
- ARG_FLUSH_DNS_CACHE="true"
- shift
- elif [ "${1:0:2}" = "-i" ] ; then # -i arguments are for leasewatcher
- ARG_IGNORE_OPTION_FLAGS="${1}"
- shift
- elif [ "$1" = "-l" ] ; then # -l = ARG_EXTRA_LOGGING
- ARG_EXTRA_LOGGING="true"
- shift
- elif [ "$1" = "-m" ] ; then # -m = ARG_MONITOR_NETWORK_CONFIGURATION
- ARG_MONITOR_NETWORK_CONFIGURATION="true"
- shift
- elif [ "$1" = "-n" ] ; then # -n = ARG_DO_NO_USE_DEFAULT_DOMAIN
- ARG_DO_NO_USE_DEFAULT_DOMAIN="true"
- shift
- elif [ "$1" = "-p" ] ; then # -p = ARG_PREPEND_DOMAIN_NAME
- ARG_PREPEND_DOMAIN_NAME="true"
- shift
- elif [ "${1:0:2}" = "-p" ] ; then # -p arguments are for process-network-changes
- ARG_IGNORE_OPTION_FLAGS="${1}"
- shift
- elif [ "$1" = "-r" ] ; then # -r = ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT
- ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="true"
- shift
- elif [ "${1:0:2}" = "-t" ] ; then
- ARG_TB_PATH="${1:2}" # -t path of Bitmask.app
- shift
- elif [ "$1" = "-w" ] ; then # -w = ARG_RESTORE_ON_WINS_RESET
- ARG_RESTORE_ON_WINS_RESET="true"
- shift
- else
- if [ "${1:0:1}" = "-" ] ; then # Shift out Bitmask arguments (they start with "-") that we don't understand
- shift # so the rest of the script sees only the OpenVPN arguments
- else
- break
- fi
- fi
-done
-
-readonly ARG_MONITOR_NETWORK_CONFIGURATION ARG_RESTORE_ON_DNS_RESET ARG_RESTORE_ON_WINS_RESET ARG_TAP ARG_PREPEND_DOMAIN_NAME ARG_FLUSH_DNS_CACHE ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT ARG_IGNORE_OPTION_FLAGS
-
-# Note: The script log path name is constructed from the path of the regular config file, not the shadow copy
-# if the config is shadow copy, e.g. /Library/Application Support/Bitmask/Users/Jonathan/Folder/Subfolder/config.ovpn
-# then convert to regular config /Users/Jonathan/Library/Application Support/Bitmask/Configurations/Folder/Subfolder/config.ovpn
-# to get the script log path
-# Note: "/Users/..." works even if the home directory has a different path; it is used in the name of the log file, and is not used as a path to get to anything.
-readonly TBALTPREFIX="/Library/Application Support/Bitmask/Users/"
-readonly TBALTPREFIXLEN="${#TBALTPREFIX}"
-readonly TBCONFIGSTART="${config:0:$TBALTPREFIXLEN}"
-if [ "$TBCONFIGSTART" = "$TBALTPREFIX" ] ; then
- readonly TBBASE="${config:$TBALTPREFIXLEN}"
- readonly TBSUFFIX="${TBBASE#*/}"
- readonly TBUSERNAME="${TBBASE%%/*}"
- readonly TBCONFIG="/Users/$TBUSERNAME/Library/Application Support/Bitmask/Configurations/$TBSUFFIX"
-else
- readonly TBCONFIG="${config}"
-fi
-
-readonly CONFIG_PATH_DASHES_SLASHES="$( echo "${TBCONFIG}" | sed -e 's/-/--/g' | sed -e 's/\//-S/g' )"
-readonly SCRIPT_LOG_FILE="/Library/Application Support/Bitmask/Logs/${CONFIG_PATH_DASHES_SLASHES}.script.log"
-
-readonly TB_RESOURCES_PATH="${ARG_TB_PATH}/Contents/Resources"
-readonly FREE_PUBLIC_DNS_SERVERS_LIST_PATH="${TB_RESOURCES_PATH}/FreePublicDnsServersList.txt"
-
-# These scripts use a launchd .plist to set up to monitor the network configuration.
-#
-# If Bitmask.app is located in /Applications, we load the launchd .plist directly from within the .app.
-#
-# If Bitmask.app is not located in /Applications (i.e., we are debugging), we create a modified version of the launchd .plist and use
-# that modified copy in the 'launchctl load' command. (The modification is that the path to process-network-changes or leasewatch program
-# in the .plist is changed to point to the copy of the program that is inside the running Bitmask.)
-#
-# The variables involved in this are set up here:
-#
-# LEASEWATCHER_PLIST_PATH is the path of the .plist to use in the 'launchctl load' command
-# LEASEWATCHER_TEMPLATE_PATH is an empty string if we load the .plist directly from within the .app,
-# or it is the path to the original .plist inside the .app which we copy and modify
-# REMOVE_LEASEWATCHER_PLIST is "true" if a modified .plist was used and should be deleted after it is unloaded
-# or "false' if the plist was loaded directly from the .app
-#
-# LEASEWATCHER_PLIST_PATH and REMOVE_LEASEWATCHER_PLIST are passed to the other scripts via the scutil State:/Network/OpenVPN mechanism
-
-if [ "${ARG_IGNORE_OPTION_FLAGS:0:2}" = "-p" ] ; then
- readonly LEASEWATCHER_PLIST="ProcessNetworkChanges.plist"
-else
- readonly LEASEWATCHER_PLIST="LeaseWatch.plist"
-fi
-if [ "${ARG_TB_PATH}" = "/Applications/Bitmask.app" ] ; then
- readonly LEASEWATCHER_PLIST_PATH="${TB_RESOURCES_PATH}/${LEASEWATCHER_PLIST}"
- readonly LEASEWATCHER_TEMPLATE_PATH=""
- readonly REMOVE_LEASEWATCHER_PLIST="false"
-else
- readonly LEASEWATCHER_PLIST_PATH="/Library/Application Support/Bitmask/${LEASEWATCHER_PLIST}"
- readonly LEASEWATCHER_TEMPLATE_PATH="${TB_RESOURCES_PATH}/${LEASEWATCHER_PLIST}"
- readonly REMOVE_LEASEWATCHER_PLIST="true"
-fi
-
-set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
-readonly OSVER="$( sw_vers | grep 'ProductVersion:' | grep -o '10\.[0-9]*' )"
-set -e # We instruct bash that it CAN again fail on errors
-
-if ${ARG_DO_NO_USE_DEFAULT_DOMAIN} ; then
- readonly DEFAULT_DOMAIN_NAME=""
-else
- readonly DEFAULT_DOMAIN_NAME="openvpn"
-fi
-
-bRouteGatewayIsDhcp="false"
-
-# We sleep to allow time for OS X to process network settings
-sleep 2
-
-EXIT_CODE=0
-
-if ${ARG_TAP} ; then
-
- # IPv6 should be re-enabled only for TUN, not TAP
- readonly ipv6_disabled_services=""
- readonly ipv6_disabled_services_encoded=""
-
- # Still need to do: Look for route-gateway dhcp (TAP isn't always DHCP)
- bRouteGatewayIsDhcp="false"
- if [ -z "${route_vpn_gateway}" -o "$route_vpn_gateway" == "dhcp" -o "$route_vpn_gateway" == "DHCP" ]; then
- bRouteGatewayIsDhcp="true"
- fi
-
- if [ "$bRouteGatewayIsDhcp" == "true" ]; then
- logDebugMessage "DEBUG: bRouteGatewayIsDhcp is TRUE"
- if [ -z "$dev" ]; then
- logMessage "ERROR: Cannot configure TAP interface for DHCP without \$dev being defined. Exiting."
- # We don't create the "/tmp/bitmask-downscript-needs-to-be-run.txt" file, because the down script does NOT need to be run since we didn't do anything
- logMessage "End of output from ${OUR_NAME}"
- logMessage "**********************************************"
- exit 1
- fi
-
- logDebugMessage "DEBUG: About to 'ipconfig set \"$dev\" DHCP"
- ipconfig set "$dev" DHCP
- logMessage "Did 'ipconfig set \"$dev\" DHCP'"
-
- if ${ARG_ENABLE_IPV6_ON_TAP} ; then
- ipconfig set "$dev" AUTOMATIC-V6
- logMessage "Did 'ipconfig set \"$dev\" AUTOMATIC-V6'"
- fi
-
- if ${ARG_WAIT_FOR_DHCP_IF_TAP} ; then
- logMessage "Configuring tap DNS via DHCP synchronously"
- configureDhcpDns
- else
- logMessage "Configuring tap DNS via DHCP asynchronously"
- configureDhcpDns & # This must be run asynchronously; the DHCP lease will not complete until this script exits
- EXIT_CODE=0
- fi
- elif [ "$foreign_option_1" == "" ]; then
- logMessage "NOTE: No network configuration changes need to be made."
- if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
- logMessage "WARNING: Will NOT monitor for other network configuration changes."
- fi
- if ${ARG_ENABLE_IPV6_ON_TAP} ; then
- logMessage "WARNING: Will NOT set up IPv6 on TAP device because it does not use DHCP."
- fi
- logDnsInfoNoChanges
- flushDNSCache
- else
- if ${ARG_ENABLE_IPV6_ON_TAP} ; then
- logMessage "WARNING: Will NOT set up IPv6 on TAP device because it does not use DHCP."
- fi
- logMessage "Configuring tap DNS via OpenVPN"
- configureOpenVpnDns
- EXIT_CODE=$?
- fi
-else
- if [ "$foreign_option_1" == "" ]; then
- logMessage "NOTE: No network configuration changes need to be made."
- if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
- logMessage "WARNING: Will NOT monitor for other network configuration changes."
- fi
- if ${ARG_DISABLE_IPV6_ON_TUN} ; then
- logMessage "WARNING: Will NOT disable IPv6 settings."
- fi
- logDnsInfoNoChanges
- flushDNSCache
- else
-
- ipv6_disabled_services=""
- if ${ARG_DISABLE_IPV6_ON_TUN} ; then
- ipv6_disabled_services="$( disable_ipv6 )"
- if [ "$ipv6_disabled_services" != "" ] ; then
- printf %s "$ipv6_disabled_services
-" | \
- while IFS= read -r dipv6_service ; do
- logMessage "Disabled IPv6 for '$dipv6_service'"
- done
- fi
- fi
- readonly ipv6_disabled_services
- # Note '\n' is translated into '\t' so it is all on one line, because grep and sed only work with single lines
- readonly ipv6_disabled_services_encoded="$( echo "$ipv6_disabled_services" | tr '\n' '\t' )"
-
- configureOpenVpnDns
- EXIT_CODE=$?
- fi
-fi
-
-touch "/tmp/bitmask-downscript-needs-to-be-run.txt"
-
-logMessage "End of output from ${OUR_NAME}"
-logMessage "**********************************************"
-
-exit $EXIT_CODE
diff --git a/pkg/osx/quickpkg b/pkg/osx/quickpkg
deleted file mode 100755
index a8d04982..00000000
--- a/pkg/osx/quickpkg
+++ /dev/null
@@ -1,557 +0,0 @@
-#!/usr/bin/python
-
-import argparse
-import string
-import os
-import subprocess
-import tempfile
-import shutil
-import stat
-
-# includes FoundationPlist since some apps store their Info.plist
-# as binary PropertyLists
-
-# FoundationPlist:
-
-# Copyright 2009-2014 Greg Neagle.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""FoundationPlist.py -- a tool to generate and parse MacOSX .plist files.
-
-This is intended as a drop-in replacement for Python's included plistlib,
-with a few caveats:
- - readPlist() and writePlist() operate only on a filepath,
- not a file object.
- - there is no support for the deprecated functions:
- readPlistFromResource()
- writePlistToResource()
- - there is no support for the deprecated Plist class.
-
-The Property List (.plist) file format is a simple XML pickle supporting
-basic object types, like dictionaries, lists, numbers and strings.
-Usually the top level object is a dictionary.
-
-To write out a plist file, use the writePlist(rootObject, filepath)
-function. 'rootObject' is the top level object, 'filepath' is a
-filename.
-
-To parse a plist from a file, use the readPlist(filepath) function,
-with a file name. It returns the top level object (again, usually a
-dictionary).
-
-To work with plist data in strings, you can use readPlistFromString()
-and writePlistToString().
-"""
-
-from Foundation import NSData, \
- NSPropertyListSerialization, \
- NSPropertyListMutableContainersAndLeaves, \
- NSPropertyListXMLFormat_v1_0
-
-
-class FoundationPlistException(Exception):
- '''Base error for this module'''
- pass
-
-
-class NSPropertyListSerializationException(FoundationPlistException):
- '''Read error for this module'''
- pass
-
-
-class NSPropertyListWriteException(FoundationPlistException):
- '''Write error for this module'''
- pass
-
-
-# private functions
-def _dataToPlist(data):
- '''low-level function that parses a data object into a propertyList object'''
- darwin_vers = int(os.uname()[2].split('.')[0])
- if darwin_vers > 10:
- (plistObject, plistFormat, error) = (
- NSPropertyListSerialization.propertyListWithData_options_format_error_(
- data, NSPropertyListMutableContainersAndLeaves, None, None))
- else:
- # 10.5 doesn't support propertyListWithData:options:format:error:
- # 10.6's PyObjC wrapper for propertyListWithData:options:format:error:
- # is broken
- # so use the older NSPropertyListSerialization function
- (plistObject, plistFormat, error) = (
- NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
- data, NSPropertyListMutableContainersAndLeaves, None, None))
- if plistObject is None:
- if error is None:
- error = "Plist data is invalid and could not be deserialized."
- raise NSPropertyListSerializationException(error)
- else:
- return plistObject
-
-
-def _plistToData(plistObject):
- '''low-level function that creates NSData from a plist object'''
- darwin_vers = int(os.uname()[2].split('.')[0])
- if darwin_vers > 10:
- (data, error) = (
- NSPropertyListSerialization.dataWithPropertyList_format_options_error_(
- plistObject, NSPropertyListXMLFormat_v1_0, 0, None))
- else:
- # use the older NSPropertyListSerialization function on 10.6 and 10.5
- (data, error) = (
- NSPropertyListSerialization.dataFromPropertyList_format_errorDescription_(
- plistObject, NSPropertyListXMLFormat_v1_0, None))
- if data is None:
- if error is None:
- error = "Property list invalid for format."
- raise NSPropertyListSerializationException(error)
- return data
-
-
-# public functions
-def readPlist(filepath):
- '''Read a .plist file from filepath. Return the unpacked root object
- (which is usually a dictionary).'''
- try:
- data = NSData.dataWithContentsOfFile_(filepath)
- except NSPropertyListSerializationException, error:
- # insert filepath info into error message
- errmsg = (u'%s in %s' % (error, filepath))
- raise NSPropertyListSerializationException(errmsg)
- return _dataToPlist(data)
-
-
-def readPlistFromString(aString):
- '''Read a plist data from a string. Return the root object.'''
- data = buffer(aString)
- return _dataToPlist(data)
-
-
-def writePlist(plistObject, filepath):
- '''Write 'plistObject' as a plist to filepath.'''
- plistData = _plistToData(plistObject)
- if plistData.writeToFile_atomically_(filepath, True):
- return
- else:
- raise NSPropertyListWriteException(
- u"Failed to write plist data to %s" % filepath)
-
-
-def writePlistToString(plistObject):
- '''Create a plist-formatted string from plistObject.'''
- return str(_plistToData(plistObject))
-
-
-#
-# quickpkg
-#
-
-
-quickpkg_version = '0.5'
-supported_extensions = ['dmg', 'app', 'zip']
-
-
-# modeled after munkiimport but to build a pkg
-
-
-def logger(log, v=0):
- if args.verbosity >= v:
- print log
-
-
-def cmdexec(command, stdin=''):
- """Execute a command."""
- # if 'command' is a string, split the string into components
- if isinstance(command, str):
- command = command.split()
-
- proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
- (stdout, stderr) = proc.communicate(stdin)
-
- logger("cmdexec: %s, result: %s, error: %s" % (command, stdout, stderr), 3)
-
- # strip trailing whitespace, which would mess with string comparisons
- return {"return_code": proc.returncode, "stderr": stderr.rstrip(), "stdout": stdout.rstrip()}
-
-
-# from munkicommons.py
-def getFirstPlist(textString):
- """Gets the next plist from a text string that may contain one or
- more text-style plists.
- Returns a tuple - the first plist (if any) and the remaining
- string after the plist"""
- plist_header = '<?xml version'
- plist_footer = '</plist>'
- plist_start_index = textString.find(plist_header)
- if plist_start_index == -1:
- # not found
- return ("", textString)
- plist_end_index = textString.find(
- plist_footer, plist_start_index + len(plist_header))
- if plist_end_index == -1:
- # not found
- return ("", textString)
- # adjust end value
- plist_end_index = plist_end_index + len(plist_footer)
- return (textString[plist_start_index:plist_end_index],
- textString[plist_end_index:])
-
-
-def dmg_has_sla(dmgpath):
- has_sla = False
- imageinfo_cmd = ['/usr/bin/hdiutil', 'imageinfo', dmgpath, '-plist']
- result = cmdexec(imageinfo_cmd)
- if result["return_code"] != 0:
- print "error getting imageinfo! %s, %s" % (result["return_code"], result["stderr"])
- return False
- result_plist = result["stdout"]
- imageinfo_dict = readPlistFromString(result_plist)
- properties = imageinfo_dict.get('Properties')
- if properties is not None:
- has_sla = properties.get('Software License Agreement', False)
- return has_sla
-
-
-def attachdmg(dmgpath):
- global dmg_was_mounted
- info_cmd = ["hdiutil", "info", "-plist"]
- info_result = cmdexec(info_cmd)
- if info_result["return_code"] == 0:
- # parse the plist output
- (theplist, alltext) = getFirstPlist(info_result["stdout"])
- info_dict = readPlistFromString(theplist)
- volpaths = []
- if "images" in info_dict.keys():
- for y in info_dict["images"]:
- if "image-path" in y.keys():
- if os.path.samefile(y["image-path"], dmgpath):
- for x in y.get("system-entities"):
- if "mount-point" in x.keys():
- volpaths.append(x["mount-point"])
- dmg_was_mounted = True
- return volpaths
- else:
- print "error getting hdiutil info"
- print "(%d, %s)" % (info_result["returncode"], info_result["stderr"])
- cleanup_and_exit(1)
-
- attachcmd = ["/usr/bin/hdiutil",
- "attach",
- dmgpath,
- "-mountrandom",
- "/private/tmp",
- "-plist",
- "-nobrowse"]
- if dmg_has_sla(dmgpath):
- stdin = "Y\n"
- print "NOTE: Disk image %s has a license agreement!" % dmgpath
- else:
- stdin = ''
- result = cmdexec(attachcmd, stdin)
- if result["return_code"] == 0:
- # parse the plist output
- (theplist, alltext) = getFirstPlist(result["stdout"])
- resultdict = readPlistFromString(theplist)
- volpaths = []
- for x in resultdict["system-entities"]:
- if x["potentially-mountable"]:
- if x["volume-kind"] == 'hfs':
- volpaths.append(x["mount-point"])
- # return the paths to mounted volume
- return volpaths
- else:
- print "error mounting disk image"
- print "(%d, %s)" % (result["returncode"], result["stderr"])
- cleanup_and_exit(1)
-
-
-def detachpaths(volpaths):
- for x in volpaths:
- if os.path.exists(x):
- if os.path.ismount(x):
- detachcmd = ["/usr/bin/hdiutil", "detach", x]
- cmdexec(detachcmd)
-
-
-def finditemswithextension(dirpath, item_extension):
- foundapps = []
- if os.path.exists(dirpath):
- for x in os.listdir(dirpath):
- (item_basename, item_extension) = os.path.splitext(x)
- item_extension = string.lstrip(item_extension, '.')
- if item_extension == 'app':
- foundapps.append(os.path.join(dirpath, x))
- else:
- print "path %s does not exist" % dirpath
- cleanup_and_exit(1)
- return foundapps
-
-
-def appNameAndVersion(app_path):
- info_path = os.path.join(app_path, "Contents/Info.plist")
- if not os.path.exists(info_path):
- print "Application at path %s does not have Info.plist" % app_path
- # TODO: cleanup volumes here
- cleanup_and_exit(1)
- info_plist = readPlist(info_path)
- app_name = info_plist.get("CFBundleName")
- if app_name is None:
- app_name = info_plist.get("CFBundleDisplayName")
- if app_name is None:
- (app_name, app_ext) = os.path.splitext(os.path.basename(app_path))
- app_identifier = info_plist.get("CFBundleIdentifier")
- app_version = info_plist.get("CFBundleShortVersionString")
- if app_version is None:
- app_version = info_plist.get("CFBundleVersion")
- return (app_name, app_identifier, app_version)
-
-
-def cleanup_and_exit(returncode):
- global dmgvolumepaths
- global dmg_was_mounted
- global tmp_path
-
- if args.clean:
- if not dmg_was_mounted:
- detachpaths(dmgvolumepaths)
- if tmp_path is not None:
- shutil.rmtree(tmp_path)
- exit(returncode)
-
-
-if __name__ == "__main__":
-
- parser = argparse.ArgumentParser(description="""Attempts to build a pkg from the input.
- Installer item can be a dmg, zip, or app.""",
- epilog="""Example: quickpkg /path/to/installer_item""")
-
- # takes a path as input
- parser.add_argument('item_path', help="path to the installer item")
-
- scripts_group = parser.add_argument_group('Installation Scripts',
- '''These options will set the installation scripts. You pass an entire folder of scripts,
- just like the option of `pkgbuild` or you can give a file for the preinstall or postinstall
- scripts respectively. If you give both the --scripts and either one or both of --preinstall
- and --postinstall, quickpkg will attempt to merge, but throw an error if it cannot.''')
- scripts_group.add_argument('--scripts', help="path to a folder with scripts")
- scripts_group.add_argument('--preinstall', '--pre', help="path to the preinstall script")
- scripts_group.add_argument('--postinstall', '--post', help="path to the postinstall script")
-
- parser.add_argument('--ownership', choices=['recommended', 'preserve', 'preserve-other'],
- help="will be passed through to pkgbuild")
- parser.add_argument('--output', '--out', '-o',
- help='''path where the package file will be created. If you give the full filename
- then you can use '{name}', '{version}' and '{identifier}' as placeholders.
- If this is a directory, then the
- package will be created with the default filename {name}-{version}.pkg''')
-
- parser.add_argument('--clean', dest='clean', action='store_true', help="clean up temp files (DEFAULT)")
- parser.add_argument('--no-clean', dest='clean', action='store_false', help=" do NOT clean up temp files")
- parser.set_defaults(clean=True)
-
- parser.add_argument('--relocatable', dest='relocatable', action='store_true',
- help="sets BundleIsRelocatable in the PackageInfo to true")
- parser.add_argument('--no-relocatable', dest='relocatable', action='store_false',
- help="sets BundleIsRelocatable in the PackageInfo (DEFAULT is false)")
- parser.set_defaults(relocatable=False)
-
-
- parser.add_argument("-v", "--verbosity", action="count", default=0, help="controls amount of logging output (max -vvv)")
- parser.add_argument('--version', help='prints the version', action='version', version=quickpkg_version)
-
- args = parser.parse_args()
-
- # remove trailing '/' from path
- item_path = string.rstrip(args.item_path, '/')
-
- if item_path.startswith('~'):
- item_path = os.path.expanduser(item_path)
- item_path = os.path.abspath(item_path)
-
- # get file extension
- (item_basename, item_extension) = os.path.splitext(item_path)
- item_extension = string.lstrip(item_extension, '.')
-
- # is extension supported
- if item_extension not in supported_extensions:
- print ".%s is not a supported extension!" % item_extension
- exit(1)
-
- foundapps = []
-
- # if item is an app, just pass it on
- if item_extension == 'app':
- if not os.path.exists(item_path):
- print "This does not seem to be an Application!"
- exit(1)
- foundapps.append(item_path)
-
- dmgvolumepaths = []
- tmp_path = None
- dmg_was_mounted = False
- tmp_scripts_path = None
- tmp_path = tempfile.mkdtemp()
- payload_path = os.path.join(tmp_path, "payload")
- os.makedirs(payload_path)
-
- # if item is a dmg, mount it and find useful contents
- if item_extension == 'dmg':
- dmgvolumepaths = attachdmg(item_path)
- for x in dmgvolumepaths:
- moreapps = finditemswithextension(x, 'app')
- foundapps.extend(moreapps)
- if len(foundapps) == 0:
- print "Could not find an application!"
- cleanup_and_exit(1)
- elif len(foundapps) > 1:
- print "Found too many Applications! Can't decide!"
- print foundapps
- cleanup_and_exit(1)
-
- # if item is zip, unzip to tmp location and find useful contents
- if item_extension == 'zip':
- unarchive_path = os.path.join(tmp_path, "unarchive")
- unzip_cmd = ["/usr/bin/unzip", "-d", unarchive_path, item_path]
- result = cmdexec(unzip_cmd)
- if result["return_code"] != 0:
- print "An error occured while unzipping:"
- print "%d, %s" % (result["return_code"], result["stderr"])
- cleanup_and_exit(1)
- foundapps = finditemswithextension(unarchive_path, 'app')
- if len(foundapps) == 0:
- print "Could not find an application!"
- cleanup_and_exit(1)
- elif len(foundapps) > 1:
- print "Found too many Applications! Can't decide!"
- print foundapps
- cleanup_and_exit(1)
-
- logger("Found application: %s" % foundapps[0], 1)
-
- # copy found app to payload folder
- app_name = os.path.basename(foundapps[0])
- app_path = os.path.join(payload_path, app_name)
- shutil.copytree(foundapps[0], app_path)
-
- # extract version and other metadata
- (app_name, app_identifier, app_version) = appNameAndVersion(app_path)
-
- logger("Name: %s, ID: %s, Version: %s" % (app_name, app_identifier, app_version), 1)
-
- # create the component plist
- component_plist = os.path.join(tmp_path, app_identifier) + ".plist"
- analyzecmd = ["/usr/bin/pkgbuild",
- "--analyze",
- "--root", payload_path,
- "--identifier", app_identifier,
- "--version", app_version,
- "--install-location", "/Applications",
- component_plist]
- result = cmdexec(analyzecmd)
-
- logger(result["stdout"], 1)
- if result["return_code"] != 0:
- print "Error Code: %d " % result["return_code"]
- print result["stderr"]
- cleanup_and_exit(1)
-
- if not args.relocatable:
- # read and change component plist
- components = readPlist(component_plist)
- # component plist is an array of components
- for bundle in components:
- if "BundleIsRelocatable" in bundle.keys():
- bundle["BundleIsRelocatable"] = False
- writePlist(components, component_plist)
-
- pkg_name = "{name}-{version}.pkg"
- if args.output:
- if os.path.isdir(args.output):
- pkg_path = os.path.join(args.output, pkg_name)
- else:
- pkg_path = args.output
- else:
- pkg_path = pkg_name
- nospace_app_name = app_name.replace(' ', '') # remove spaces
- pkg_path = pkg_path.format(name=nospace_app_name, version=app_version, identifier=app_identifier)
-
- if not pkg_path.endswith('pkg'):
- pkg_path += '.pkg'
-
- # run pkgutil to build result
- pkgcmd = ["/usr/bin/pkgbuild",
- "--root", payload_path,
- "--component-plist", component_plist,
- "--identifier", app_identifier,
- "--version", app_version,
- "--install-location", "/Applications",
- pkg_path]
-
- if args.scripts and not os.path.exists(args.scripts):
- print "scripts folder %s does not exist!" % args.scripts
- cleanup_and_exit(1)
-
- if args.postinstall or args.preinstall:
- tmp_scripts_path = os.path.join(tmp_dir, "scripts")
- os.makedirs(tmp_scripts_path)
-
- if args.scripts:
- logger("copying %s to tmp scripts folder %s" % (args.scripts, tmp_scripts_path), 1)
- shutil.rmtree(tmp_scripts_path)
- shutil.copytree(args.scripts, tmp_scripts_path)
- if args.postinstall:
- if not os.path.exists(args.postinstall):
- print "postinstall file %s does not exist!" % args.postinstall
- cleanup_and_exit(1)
- postinstall_path = os.path.join(tmp_scripts_path, "postinstall")
- if os.path.exists(postinstall_path):
- print "postinstall script already exists in %s" % args.scripts
- cleanup_and_exit(1)
- logger("copying %s to %s" % (args.postinstall, postinstall_path), 1)
- shutil.copy2(args.postinstall, postinstall_path)
- os.chmod(postinstall_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
- stat.S_IRGRP | stat.S_IXGRP |
- stat.S_IROTH | stat.S_IXOTH)
- if args.preinstall:
- if not os.path.exists(args.preinstall):
- print "preinstall file %s does not exist!" % args.preinstall
- cleanup_and_exit(1)
- preinstall_path = os.path.join(tmp_scripts_path, "preinstall")
- if os.path.exists(preinstall_path):
- print "preinstall script already exists in %s" % args.scripts
- cleanup_and_exit(1)
- logger("copying %s to %s" % (args.preinstall, preinstall_path), 1)
- shutil.copy2(args.preinstall, preinstall_path)
- os.chmod(preinstall_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
- stat.S_IRGRP | stat.S_IXGRP |
- stat.S_IROTH | stat.S_IXOTH)
-
- if tmp_scripts_path:
- logger("scripts path: %s" % tmp_scripts_path, 1)
- pkgcmd.extend(["--scripts", tmp_scripts_path])
- elif args.scripts:
- logger("scripts path: %s" % args.scripts, 1)
- pkgcmd.extend(["--scripts", args.scripts])
-
- if args.ownership:
- pkgcmd.extend(["--ownership", args.ownership])
-
- result = cmdexec(pkgcmd)
-
- logger(result["stdout"], 1)
- if result["return_code"] != 0:
- print "Error Code: %d " % result["return_code"]
- print result["stderr"]
- else:
- print pkg_path
-
- cleanup_and_exit(0)
diff --git a/pkg/osx/scripts-riseupvpn/postinstall b/pkg/osx/scripts-riseupvpn/postinstall
deleted file mode 100755
index 93430390..00000000
--- a/pkg/osx/scripts-riseupvpn/postinstall
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-# Bitmask Post-Instalation script
-# (c) LEAP Encryption access Project
-# We copy the bitmask-helper plist to the LaunchDaemons folder, and load the bitmask-helper that runs as root.
-
-LOG=/tmp/bitmask-install.log
-
-chmod +x /Applications/RiseupVPN.app/Contents/Resources/bitmask-helper/bitmask-helper
-cp se.leap.bitmask-helper.plist /Library/LaunchDaemons/ \
- && echo `date` ":: Bitmask post-install: copied bitmask-helper Plist." >> $LOG
-launchctl load /Library/LaunchDaemons/se.leap.bitmask-helper.plist && echo `date` ":: Bitmask post-install: loaded bitmask-helper." >> $LOG
-echo `date` ":: Bitmask post-install: ok." >> $LOG
-exit 0
diff --git a/pkg/osx/scripts-riseupvpn/preinstall b/pkg/osx/scripts-riseupvpn/preinstall
deleted file mode 100755
index 1ae68f9c..00000000
--- a/pkg/osx/scripts-riseupvpn/preinstall
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-# Bitmask Pre-Instalation script
-# (c) LEAP Encryption access Project
-# We unload the bitmask-helper if it is running, because we can be installing an upgrade.
-
-LOG=/tmp/bitmask-install.log
-
-ps aux | grep [b]itmask-helper \
- && launchctl unload /Library/LaunchDaemons/se.leap.bitmask-helper.plist \
- && echo `date` ":: Bitmask pre-install: unloaded bitmask-helper." >> $LOG
-echo `date` ":: Bitmask pre-install: ok." >> $LOG
-exit 0
diff --git a/pkg/osx/scripts-riseupvpn/se.leap.bitmask-helper.plist b/pkg/osx/scripts-riseupvpn/se.leap.bitmask-helper.plist
deleted file mode 100644
index 8ebfb947..00000000
--- a/pkg/osx/scripts-riseupvpn/se.leap.bitmask-helper.plist
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>WorkingDirectory</key>
- <string>/Applications/RiseupVPN.app/Contents/Resources/bitmask-helper/</string>
- <key>StandardOutPath</key>
- <string>bitmask-helper.log</string>
- <key>StandardErrorPath</key>
- <string>bitmask-helper-err.log</string>
- <key>GroupName</key>
- <string>daemon</string>
- <key>RunAtLoad</key>
- <true/>
- <key>SessionCreate</key>
- <true/>
- <key>KeepAlive</key>
- <true/>
- <key>ThrottleInterval</key>
- <integer>5</integer>
- <key>Label</key>
- <string>se.leap.BitmaskHelper</string>
- <key>Program</key>
- <string>/Applications/RiseupVPN.app/Contents/Resources/bitmask-helper/bitmask-helper</string>
-</dict>
-</plist>
diff --git a/pkg/osx/scripts/postinstall b/pkg/osx/scripts/postinstall
deleted file mode 100755
index 393ab658..00000000
--- a/pkg/osx/scripts/postinstall
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-# Bitmask Post-Instalation script
-# (c) LEAP Encryption access Project
-# We copy the bitmask-helper plist to the LaunchDaemons folder, and load the bitmask-helper that runs as root.
-
-LOG=/tmp/bitmask-install.log
-
-cp se.leap.bitmask-helper.plist /Library/LaunchDaemons/ \
- && echo `date` ":: Bitmask post-install: copied bitmask-helper Plist." >> $LOG
-launchctl load /Library/LaunchDaemons/se.leap.bitmask-helper.plist && echo `date` ":: Bitmask post-install: loaded bitmask-helper." >> $LOG
-echo `date` ":: Bitmask post-install: ok." >> $LOG
-exit 0
diff --git a/pkg/osx/scripts/preinstall b/pkg/osx/scripts/preinstall
deleted file mode 100755
index 1ae68f9c..00000000
--- a/pkg/osx/scripts/preinstall
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-# Bitmask Pre-Instalation script
-# (c) LEAP Encryption access Project
-# We unload the bitmask-helper if it is running, because we can be installing an upgrade.
-
-LOG=/tmp/bitmask-install.log
-
-ps aux | grep [b]itmask-helper \
- && launchctl unload /Library/LaunchDaemons/se.leap.bitmask-helper.plist \
- && echo `date` ":: Bitmask pre-install: unloaded bitmask-helper." >> $LOG
-echo `date` ":: Bitmask pre-install: ok." >> $LOG
-exit 0
diff --git a/pkg/osx/scripts/se.leap.bitmask-helper.plist b/pkg/osx/scripts/se.leap.bitmask-helper.plist
deleted file mode 100644
index b5990f6e..00000000
--- a/pkg/osx/scripts/se.leap.bitmask-helper.plist
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>WorkingDirectory</key>
- <string>/Applications/Bitmask.app/Contents/Resources/bitmask-helper/</string>
- <key>StandardOutPath</key>
- <string>bitmask-helper.log</string>
- <key>StandardErrorPath</key>
- <string>bitmask-helper-err.log</string>
- <key>GroupName</key>
- <string>daemon</string>
- <key>RunAtLoad</key>
- <true/>
- <key>SessionCreate</key>
- <true/>
- <key>KeepAlive</key>
- <true/>
- <key>ThrottleInterval</key>
- <integer>5</integer>
- <key>Label</key>
- <string>se.leap.BitmaskHelper</string>
- <key>Program</key>
- <string>/Applications/Bitmask.app/Contents/Resources/bitmask-helper/bitmask-helper</string>
-</dict>
-</plist>
diff --git a/pkg/osx/uninstall.sh b/pkg/osx/uninstall.sh
deleted file mode 100755
index 1fb6ff87..00000000
--- a/pkg/osx/uninstall.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-HELPER_PLIST="/Library/LaunchDaemons/se.leap.bitmask-helper.plist"
-sudo launchctl unload $HELPER_PLIST
-sudo rm -rf /Applications/Bitmask.app
-sudo rm -rf ~/Library/Preferences/leap
-sudo rm $HELPER_PLIST
-echo "Bitmask has been uninstalled from your system!"