battleship

Safe HaskellUnsafe

UnsafeSys

Contents

Description

This trusted module is Unsafe, and so may only be used by Unsafe or Trustworthy modules. It provides a function for creating a privilege from a principal, exports the ExitCode type and constructors, defines functions for specializing the standard input and output handles to a given label, exports several network types and constructors, defines the LIO versions of some network functions, and defines a function for running a DC-based main function.

Synopsis

Creating Privilege from Principal

privOfPrin :: Principal -> DCPriv

privOfPrin prin produces the privilege priv such that toCNF priv == toCNF prin.

Exit Codes (from System.Exit)

data ExitCode

Defines the exit codes that a program can return.

Constructors

ExitSuccess

indicates successful termination;

ExitFailure Int

indicates program failure with an exit code. The exact interpretation of the code is operating-system dependent. In particular, some values may be prohibited (e.g. 0 on a POSIX-compliant system).

Labeling Standard Input and Output

labelStdinP :: DCPriv -> DCLabel -> DC Handle

Returns (stdin) labeled with the supplied label. Raises an exception if -- modulo the supplied privilege -- this label isn't greater than or equal to the current label, or if this label isn't less than or equal to the current clearance.

labelStdoutP :: DCPriv -> DCLabel -> DC Handle

Returns (stdout) labeled with the supplied label. Raises an exception if -- modulo the supplied privilege -- this label isn't greater than or equal to the current label, or if this label isn't less than or equal to the current clearance.

TCP Types and Functions (from Network)

type HostName = String

Either a host name e.g., "haskell.org" or a numeric host address string consisting of a dotted decimal IPv4 address or an IPv6 address e.g., "192.168.0.1".

type Socket = LObj DCLabel Socket

TCP sockets as labeled objects.

sClose :: Socket -> DC ()

The LIO analogue of sClose. Will raise the current label to the sockets's label; raises an exception if this isn't possible.

sCloseP :: DCPriv -> Socket -> DC ()

The version of sClose that uses a privilege to limit the raising of the current label: the goal is for the current label and the socket's label to be equal, modulo the privilege.

listenOnP :: DCPriv -> DCLabel -> PortNumber -> DC Socket

The LIO analogue of listenOn, returning a socket whose label is the supplied label. Raises an exception when the port can't be listened on, or when -- modulo the supplied privilege -- the supplied label isn't greater than or equal to the current label, or when the supplied label isn't less than or equal to the current clearance.

acceptP :: DCPriv -> DCLabel -> Socket -> DC Handle

The LIO analogue of accept, returning a handle with the supplied label. The handle's buffering mode is set to line buffering. If necessary -- given the supplied privilege -- will raise the current label to the socket's label; raises an exception if this isn't possible. Raises an exception if -- modulo the supplied privilege -- the supplied label isn't greater than or equal to the new current label, or if the supplied label isn't less than or equal to the current clearance.

connectToP :: DCPriv -> DCLabel -> HostName -> PortNumber -> DC Handle

The LIO analogue of connectTo, returning a handle with the supplied label. The handle's buffering mode is set to line buffering. Raises an exception if the supplied label -- modulo the supplied privilege -- isn't greater than or equal to the current label, or if the supplied label isn't less than or equal to the current clearance.

Running a Program

runProg :: (String -> [String] -> DC ExitCode) -> IO ()

Turn a DC main function, main, into an IO action that, when run, will:

  • make the standard output be line-buffered;
  • cause PIPE signals to be ignored (so that writing to a closed TCP connection doesn't result in program termination);
  • call main with the name by which the program was invoked and its command line arguments, and run the resulting DC action with label dcPublic and clearance cFalse %% cTrue;
  • exit with the exit status yielded by running the DC action.