1088N/A/*
1379N/A * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
0N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
0N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
606N/A */
0N/A
0N/A
0N/A
1088N/A#ifndef _TSOL_INFO_H
1088N/A#define _TSOL_INFO_H
0N/A
0N/A#include <sys/types.h>
0N/A
0N/A#include <tsol/label.h>
0N/A#include <sys/tsol/tndb.h>
0N/A#include <bsm/audit.h>
0N/A#include <sys/mkdev.h>
0N/A#include <ucred.h>
0N/A#include "misc.h"
0N/A#include "dixstruct.h"
1088N/A#include "selection.h"
705N/A#include "globals.h"
98N/A#include <X11/keysym.h>
0N/A
0N/A/*********************************
0N/A *
0N/A * DEBUG INFO
0N/A *
0N/A *********************************/
0N/A
639N/A/* Message verbosity levels passed to os/log.c functions
639N/A * Level 0 messages are printed by all servers to stderr.
639N/A * Xorg defaults to logging messages in 0-3 to /var/log/Xorg.<display>.log
639N/A * Ranges of messages to print to stderr can be changed with Xorg -verbose N
639N/A * and Xephyr -verbosity N
639N/A * Ranges of messages to print to log can be changed with Xorg -logverbose N
639N/A * Other servers don't support runtime configuration of log messages yet.
0N/A */
639N/A
639N/A#define TSOL_MSG_ERROR 0 /* Always printed */
1209N/A#define TSOL_MSG_WARNING 4
667N/A#define TSOL_MSG_POLICY_DENIED 5
667N/A#define TSOL_MSG_UNIMPLEMENTED 6
639N/A#define TSOL_MSG_ACCESS_TRACE 7
0N/A
639N/A#define TSOL_LOG_PREFIX TSOLNAME ": "
639N/Aextern const char *TsolDixAccessModeNameString(Mask access_mode);
639N/Aextern const char *TsolErrorNameString(int req);
639N/Aextern const char *TsolPolicyReturnString(int pr);
639N/Aextern const char *TsolRequestNameString(int req);
639N/Aextern const char *TsolResourceTypeString(RESTYPE resource);
639N/A
639N/A#define MAXNAME 64 /* 63 chars of process name stored */
0N/A
0N/A/*********************************
0N/A *
0N/A * CONSTANTS
0N/A *
0N/A *********************************/
0N/A
0N/A
0N/A/*
0N/A * X audit events start from 9101 in audit_uevents.h. The first 2 events
0N/A * are non-protocol ones viz. ClientConnect, mapped to 9101 and
0N/A * ClientDisconnect, mapped to 9102.
0N/A * The protocol events are mapped from 9103 onwards in the serial order
0N/A * of their respective protocol opcode, for eg, the protocol UngrabPointer
0N/A * which is has a protocol opcode 27 is mapped to 9129 (9102 + 27).
0N/A * All extension protocols are mapped to a single audit event AUE_XExtension
0N/A * as opcodes are assigined dynamically to these protocols. We set the
0N/A * extension protocol opcode to be 128, one more than the last standard opcode.
0N/A */
0N/A#define XAUDIT_Q_SIZE 1024 /* audit queue size for x server */
0N/A#define XAUDIT_OFFSET 9102
0N/A#define XAUDIT_EXTENSION 128
633N/A
1379N/A#define MAX_CLIENT 256
1379N/A#define MAX_SLS 256 /* used in atom */
0N/A#define MAX_POLYPROPS 128 /* used in property */
0N/A#define DEF_UID (uid_t)0 /* uid used for default objects */
0N/A#define INVALID_UID (uid_t)0xFFFF /* invalid uid */
0N/A/*
0N/A * Various flags for TsolInfoRec, TsolResRec
0N/A */
0N/A#define TSOL_IIL 0x0000001 /* iil changed for window */
0N/A#define TSOL_DOXAUDIT 0x0000002 /* write X audit rec if set */
0N/A#define TSOL_AUDITEVENT 0x0000004 /* this event mask selected for audit */
0N/A#define CONFIG_AUDITED 0x0000008 /* this priv has been asserted for */
0N/A#define DAC_READ_AUDITED 0x0000010 /* the same object before */
0N/A#define DAC_WRITE_AUDITED 0x0000020
0N/A#define MAC_READ_AUDITED 0x0000040
0N/A#define MAC_WRITE_AUDITED 0x0000080
0N/A#define TRUSTED_MASK 0x0000100 /* Window has Trusted Path */
0N/A
0N/A/*
0N/A * Polyinstantiated property/selections
0N/A */
0N/A#define POLY_SIZE 16 /* increase the list 16 at a time */
0N/A#define CONFIG_PRIV_FILE "config.privs"
0N/A#define CONFIG_EXTENSION_FILE "config.extensions"
0N/A
0N/A#define PROCVECTORSIZE (256)
0N/A
0N/Aenum tsolconfig_types {
0N/A TSOL_ATOM = 0,
0N/A TSOL_PROPERTY,
0N/A TSOL_SELECTION,
0N/A TSOL_EXTENSION,
0N/A TSOL_PRIVILEGE
0N/A};
0N/A
799N/A#define MAJOROP_CODE (client->requestBuffer != 0 ? MAJOROP : (-1))
799N/A
0N/Atypedef enum tsolconfig_types tsolconfig_t;
0N/A
0N/A/*
0N/A * Masks corresponding various types
0N/A */
0N/A#define TSOLM_ATOM 1
0N/A#define TSOLM_PROPERTY (1 << 1)
0N/A#define TSOLM_SELECTION (1 << 2)
0N/A
0N/A#define SL_SIZE blabel_size()
0N/A
0N/A/*********************************
0N/A *
0N/A * MACROS
0N/A *
0N/A *********************************/
0N/A
0N/A
0N/A#define WindowIsRoot(pWin) (pWin && (pWin->parent == NullWindow))
0N/A#define DrawableIsRoot(pDraw)\
1088N/A (pDraw && (pDraw->id == pDraw->pScreen->root->drawable.id))
0N/A
0N/A/*
0N/A * True if client is part of TrustedPath
0N/A */
0N/A#define HasTrustedPath(tsolinfo)\
0N/A (tsolinfo->trusted_path ||\
0N/A (tsolinfo->forced_trust == 1))
0N/A
606N/A#define XTSOLTrusted(pWin) \
1088N/A ((TsolWindowPrivate(pWin))->flags & TRUSTED_MASK)
0N/A
0N/A
0N/A/*********************************
0N/A *
0N/A * DATA STRUCTURES
0N/A *
0N/A *********************************/
0N/Aenum client_types {
0N/A CLIENT_LOCAL,
0N/A CLIENT_REMOTE
0N/A};
0N/A
0N/Atypedef enum client_types client_type_t;
0N/A
0N/A/*
0N/A * Extended attributes for each client.
0N/A * Most of the information comes from getpeerucred()
0N/A */
0N/Atypedef struct _TsolInfo {
0N/A uid_t uid; /* real user id */
0N/A uid_t euid; /* effective user id */
0N/A gid_t gid; /* real group id */
0N/A gid_t egid; /* effective group id */
0N/A pid_t pid; /* process id */
0N/A zoneid_t zid; /* zone id */
0N/A priv_set_t *privs; /* privileges */
0N/A bslabel_t *sl; /* sensitivity label */
1088N/A ulong_t iaddr; /* internet addr */
0N/A Bool trusted_path; /* has trusted path */
0N/A Bool priv_debug; /* do privilege debugging */
1088N/A ulong_t flags; /* various flags */
0N/A int forced_trust; /* client masked as trusted */
0N/A au_id_t auid; /* audit id */
36N/A au_mask_t amask; /* audit mask */
36N/A au_asid_t asid; /* audit session id */
0N/A client_type_t client_type; /* Local or Remote client */
36N/A int asaverd;
36N/A struct sockaddr_storage saddr; /* socket information */
639N/A char pname[MAXNAME]; /* process name for debug messages */
0N/A} TsolInfoRec, *TsolInfoPtr;
0N/A
0N/A/*
0N/A * per resource info
0N/A */
0N/Atypedef struct _TsolRes {
0N/A bslabel_t *sl; /* sensitivity label */
0N/A uid_t uid; /* user id */
1088N/A ulong_t flags; /* various flags */
0N/A pid_t pid; /* who created it */
799N/A Bool internal; /* Created internally by the server */
1088N/A Bool poly; /* Polyinstantiated or not. Applicable
1088N/A to selection or properties */
0N/A} TsolResRec, *TsolResPtr;
0N/A
0N/A/*
851N/A * per keyboard info:
851N/A * Hot Key structure caches keycode/mask for primary & alternate Hot Keys
851N/A */
851N/Atypedef struct _HotKeyRec {
851N/A int initialized;
851N/A KeyCode key; /* Primary key */
851N/A unsigned shift; /* Primary modifier/shift */
851N/A KeyCode altkey; /* Alternate key */
851N/A unsigned altshift; /* Alternate modifier/shift */
851N/A} HotKeyRec, *HotKeyPtr;
851N/A
851N/A
851N/A/*
606N/A * information stored in devPrivates
606N/A */
1088N/Aextern _X_HIDDEN DevPrivateKeyRec tsolClientPrivateKeyRec;
1088N/A#define tsolClientPrivateKey (&tsolClientPrivateKeyRec)
1088N/A
1088N/Aextern _X_HIDDEN DevPrivateKeyRec tsolPixmapPrivateKeyRec;
1088N/A#define tsolPixmapPrivateKey (&tsolPixmapPrivateKeyRec)
1088N/A
1088N/Aextern _X_HIDDEN DevPrivateKeyRec tsolWindowPrivateKeyRec;
1088N/A#define tsolWindowPrivateKey (&tsolWindowPrivateKeyRec)
1088N/A
1088N/Aextern _X_HIDDEN DevPrivateKeyRec tsolPropertyPrivateKeyRec;
1088N/A#define tsolPropertyPrivateKey (&tsolPropertyPrivateKeyRec)
606N/A
1088N/Aextern _X_HIDDEN DevPrivateKeyRec tsolSelectionPrivateKeyRec;
1088N/A#define tsolSelectionPrivateKey (&tsolSelectionPrivateKeyRec)
1088N/A
1088N/A/* Currently only used in keyboard devices */
1088N/Aextern _X_HIDDEN DevPrivateKeyRec tsolDevicePrivateKeyRec;
1088N/A#define tsolDevicePrivateKey (&tsolDevicePrivateKeyRec)
1088N/A
1088N/Astatic inline TsolInfoPtr
1088N/ATsolClientPrivate (ClientPtr pClient)
1088N/A{
1088N/A return (TsolInfoPtr) dixLookupPrivate(&(pClient->devPrivates),
1088N/A tsolClientPrivateKey);
1088N/A}
606N/A
1088N/Astatic inline TsolResPtr
1088N/ATsolPixmapPrivate (PixmapPtr pPix)
1088N/A{
1088N/A return (TsolResPtr) dixLookupPrivate(&(pPix->devPrivates),
1088N/A tsolPixmapPrivateKey);
1088N/A}
1088N/A
1088N/Astatic inline TsolResPtr
1088N/ATsolWindowPrivate (WindowPtr pWin)
1088N/A{
1088N/A return (TsolResPtr) dixLookupPrivate(&(pWin->devPrivates),
1088N/A tsolWindowPrivateKey);
1088N/A}
606N/A
1088N/Astatic inline TsolResPtr
1088N/ATsolPropertyPrivate (PropertyPtr pProp)
1088N/A{
1088N/A return (TsolResPtr) dixLookupPrivate(&(pProp->devPrivates),
1088N/A tsolPropertyPrivateKey);
1088N/A}
606N/A
1088N/Astatic inline TsolResPtr
1088N/ATsolSelectionPrivate (Selection *pSel)
1088N/A{
1088N/A return (TsolResPtr) dixLookupPrivate(&(pSel->devPrivates),
1088N/A tsolSelectionPrivateKey);
1088N/A}
1088N/A
1088N/Astatic inline HotKeyPtr
1088N/ATsolKeyboardPrivate (DeviceIntPtr pDev)
1088N/A{
1088N/A return (HotKeyPtr) dixLookupPrivate(&(pDev->devPrivates),
1088N/A tsolDevicePrivateKey);
1088N/A}
851N/A
0N/A
1379N/A#define NODE_SLSIZE 256 /* increase sl array by this amount */
0N/Atypedef struct _TsolNodeRec {
0N/A unsigned int flags;
0N/A int slcount; /* no. of SLs referenced */
0N/A int slsize; /* size of the sl array */
0N/A int IsSpecial;
0N/A bslabel_t **sl;
0N/A
0N/A} TsolNodeRec, *TsolNodePtr;
0N/A
0N/A/*
0N/A * if polyinst true, the name list is polyinstantiated
0N/A * if false, the everything except the list is polyinstantiated
0N/A * NOTE: Default for seln: polyinstantiate the list
0N/A * Default for prop: polyinstantiate everything except the list
0N/A */
0N/Atypedef struct _TsolPolyAtom {
0N/A int polyinst;
0N/A int size; /* max size of the list */
0N/A int count; /* how many are actually valid */
0N/A char **name;
0N/A} TsolPolyAtomRec, *TsolPolyAtomPtr;
0N/A
0N/A/*
0N/A * PolyInstInfo represents if a get request will match the
0N/A * client's sl,uid for this or it will use the polyinstinfo
0N/A * information to retrieve values for prop/selection
0N/A */
0N/Atypedef struct _TsolPolyInstInfo {
0N/A int enabled; /* if true use following sl, uid */
0N/A uid_t uid;
0N/A bslabel_t *sl;
0N/A} TsolPolyInstInfoRec, *TsolPolyInstInfoPtr;
0N/A
0N/A
0N/A/*********************************
0N/A *
0N/A * EXTERNS
0N/A *
0N/A *********************************/
0N/A
0N/A
0N/Aextern int PolyProperty(Atom atom, WindowPtr pWin);
0N/Aextern int PolySelection(Atom atom);
0N/Aextern TsolPolyInstInfoRec tsolpolyinstinfo;
0N/Aextern uid_t OwnerUID; /* Workstation owner uid */
36N/Aextern Bool system_audit_on;
0N/A
0N/A/*********************************
0N/A *
0N/A * FUNCTION PROTOTYPES
0N/A *
0N/A *********************************/
0N/A
0N/A
0N/Avoid TsolReadPolyAtoms(char *filename, TsolPolyAtomPtr polyatomptr);
0N/Aextern WindowPtr TopClientWin(WindowPtr pWin);
0N/Aextern WindowPtr RootWin(WindowPtr pWin);
0N/Aextern Window RootOf(WindowPtr pWin);
0N/Aextern Window RootOfClient(WindowPtr pWin);
606N/Aextern int TsolDisabledExtension(const char *extname);
633N/Aextern int MatchTsolConfig(const char *name, int len);
36N/Aextern int HasWinSelection(TsolInfoPtr tsolinfo);
36N/Aextern int same_client (ClientPtr client, XID xid);
36N/Aextern int client_private (ClientPtr client, XID xid);
606N/Aextern bslabel_t *lookupSL_low(void);
36N/Aextern bslabel_t *lookupSL(bslabel_t *slptr);
36N/Aextern BoxPtr WindowExtents(WindowPtr pWin, BoxPtr pBox);
36N/Aextern Bool ShapeOverlap(WindowPtr pWin, BoxPtr pWinBox,
36N/A WindowPtr pSib, BoxPtr pSibBox);
799N/Aextern TsolResPtr TsolDrawablePrivate(DrawablePtr pDraw, ClientPtr client);
0N/A
1088N/A#endif /* _TSOL_INFO_H */