Skip to content

Commit

Permalink
Add SELinux window labels based on code by Ted Toth [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Nall committed Apr 12, 2013
1 parent 4e7c884 commit dd8099c
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ openbox_openbox_LDADD = \
$(SM_LIBS) \
$(GLIB_LIBS) \
$(X_LIBS) \
$(XCB_LIBS) \
$(X11_XCB_LIBS) \
-lX11-xcb -lxcb -lxcb-xselinux \
-lselinux -lpthread \
$(XCURSOR_LIBS) \
$(LIBSN_LIBS) \
$(XML_LIBS) \
Expand Down Expand Up @@ -505,7 +509,7 @@ data/autostart/openbox-autostart: $(top_srcdir)/data/autostart/openbox-autostart

%.1.in: %.1.sgml
@echo make: creating $@
@docbook-to-man $< >$@
@docbook2man $< >$@

%.1: %.1.in Makefile
@echo make: creating $@
Expand Down
19 changes: 19 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ if test "$DIRNAME" = "no"; then
AC_MSG_ERROR([The program "dirname" is not available. This program is required to build Openbox.])
fi

PKG_CHECK_MODULES(X, [x11 >= 1.1.4])
AC_SUBST(X_CFLAGS)
AC_SUBST(X_LIBS)

PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.14.0])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
Expand All @@ -115,6 +119,21 @@ PKG_CHECK_MODULES(XML, [libxml-2.0 >= 2.6.0])
AC_SUBST(XML_CFLAGS)
AC_SUBST(XML_LIBS)

PKG_CHECK_MODULES(XCB, [xcb >= 1.0])
AC_SUBST(XCB_CFLAGS)
AC_SUBST(XCB_LIBS)

PKG_CHECK_MODULES(X11_XCB, [x11-xcb >= 1.0])
AC_SUBST(X11_XCB_CFLAGS)
AC_SUBST(X11_XCB_LIBS)

PKG_CHECK_MODULES(XCB_SELINUX, [xcb-xselinux >= 1.0])
AC_SUBST(XCB_SELINUX_CFLAGS)
AC_SUBST(XCB_SELINUX_LIBS)

SELINUX_LIBS="-lselinux -lpthread"
AC_SUBST(SELINUX_LIBS)

AC_ARG_ENABLE(startup-notification,
AC_HELP_STRING(
[--disable-startup-notification],
Expand Down
35 changes: 34 additions & 1 deletion obrender/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->a_unfocused_title = RrAppearanceNew(inst, 0);
theme->a_focused_label = RrAppearanceNew(inst, 1);
theme->a_unfocused_label = RrAppearanceNew(inst, 1);
theme->a_focused_context_label = RrAppearanceNew(inst, 1);
theme->a_unfocused_context_label = RrAppearanceNew(inst, 1);
theme->a_icon = RrAppearanceNew(inst, 1);
theme->a_focused_handle = RrAppearanceNew(inst, 0);
theme->a_unfocused_handle = RrAppearanceNew(inst, 0);
Expand Down Expand Up @@ -580,6 +582,9 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
READ_APPEARANCE("menu.title.bg", theme->a_menu_title, TRUE);
READ_APPEARANCE("menu.items.active.bg", theme->a_menu_selected, TRUE);

set_default_appearance(theme->a_focused_context_label);
set_default_appearance(theme->a_unfocused_context_label);

theme->a_menu_disabled_selected =
RrAppearanceCopy(theme->a_menu_selected);

Expand Down Expand Up @@ -918,6 +923,12 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->a_menu_bullet_selected->surface.grad = RR_SURFACE_PARENTREL;

/* set up the textures */
theme->a_focused_context_label->texture[0].type = RR_TEXTURE_TEXT;
theme->a_focused_context_label->texture[0].data.text.justify = winjust;
theme->a_focused_context_label->texture[0].data.text.font=theme->win_font_focused;
theme->a_focused_context_label->texture[0].data.text.color =
RrColorParse(inst, "black")/*theme->title_focused_color*/;

theme->a_focused_label->texture[0].type = RR_TEXTURE_TEXT;
theme->a_focused_label->texture[0].data.text.justify = winjust;
theme->a_focused_label->texture[0].data.text.font=theme->win_font_focused;
Expand All @@ -935,6 +946,8 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
i = 1;
theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
theme->a_focused_context_label->texture[0].data.text.shadow_offset_x = i;
theme->a_focused_context_label->texture[0].data.text.shadow_offset_y = i;
}
if ((p = strstr(str, "shadowtint=")))
{
Expand All @@ -955,6 +968,11 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->a_focused_label->texture[0].data.text.shadow_alpha =
theme->title_focused_shadow_alpha;

theme->a_focused_context_label->texture[0].data.text.shadow_color =
theme->title_focused_shadow_color;
theme->a_focused_context_label->texture[0].data.text.shadow_alpha =
theme->title_focused_shadow_alpha;

theme->osd_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
theme->osd_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
theme->osd_hilite_label->texture[0].data.text.font =
Expand Down Expand Up @@ -1060,6 +1078,8 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
i = 1;
theme->a_unfocused_label->texture[0].data.text.shadow_offset_x = i;
theme->a_unfocused_label->texture[0].data.text.shadow_offset_y = i;
theme->a_unfocused_context_label->texture[0].data.text.shadow_offset_x = i;
theme->a_unfocused_context_label->texture[0].data.text.shadow_offset_y = i;
}
if ((p = strstr(str, "shadowtint=")))
{
Expand All @@ -1079,6 +1099,10 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->title_unfocused_shadow_color;
theme->a_unfocused_label->texture[0].data.text.shadow_alpha =
theme->title_unfocused_shadow_alpha;
theme->a_unfocused_context_label->texture[0].data.text.shadow_color =
theme->title_unfocused_shadow_color;
theme->a_unfocused_context_label->texture[0].data.text.shadow_alpha =
theme->title_unfocused_shadow_alpha;

theme->osd_unhilite_label->texture[0].type = RR_TEXTURE_TEXT;
theme->osd_unhilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
Expand All @@ -1087,6 +1111,13 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->osd_unhilite_label->texture[0].data.text.color =
theme->osd_text_inactive_color;

theme->a_unfocused_context_label->texture[0].type = RR_TEXTURE_TEXT;
theme->a_unfocused_context_label->texture[0].data.text.justify = winjust;
theme->a_unfocused_context_label->texture[0].data.text.font =
theme->win_font_unfocused;
theme->a_unfocused_context_label->texture[0].data.text.color =
theme->title_unfocused_color;

if (read_string(db, "osd.inactive.label.text.font", &str))
{
char *p;
Expand Down Expand Up @@ -1570,7 +1601,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
MAX(MAX(theme->padding * 2, ft + fb),
MAX(theme->padding * 2, ut + ub));
*/
theme->title_height = theme->label_height + theme->paddingy * 2;
theme->title_height = (theme->label_height * 2) + (theme->paddingy * 4);

RrMargins(theme->a_menu_title, &ul, &ut, &ur, &ub);
theme->menu_title_label_height = theme->menu_title_font_height+ut+ub;
Expand Down Expand Up @@ -1679,6 +1710,8 @@ void RrThemeFree(RrTheme *theme)
RrAppearanceFree(theme->a_unfocused_title);
RrAppearanceFree(theme->a_focused_label);
RrAppearanceFree(theme->a_unfocused_label);
RrAppearanceFree(theme->a_focused_context_label);
RrAppearanceFree(theme->a_unfocused_context_label);
RrAppearanceFree(theme->a_icon);
RrAppearanceFree(theme->a_focused_handle);
RrAppearanceFree(theme->a_unfocused_handle);
Expand Down
2 changes: 2 additions & 0 deletions obrender/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ struct _RrTheme {
RrAppearance *osd_pressed_button;
RrAppearance *osd_unpressed_button;
RrAppearance *osd_focused_button;
RrAppearance *a_focused_context_label;
RrAppearance *a_unfocused_context_label;

gchar *name;
};
Expand Down
2 changes: 2 additions & 0 deletions openbox/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ void client_manage(Window window, ObPrompt *prompt)

/* create the decoration frame for the client window */
self->frame = frame_new(self);
if (self->frame == NULL)
return ;

frame_grab_client(self->frame);

Expand Down
5 changes: 4 additions & 1 deletion openbox/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typedef enum
OB_CLIENT_FUNC_CLOSE = 1 << 6, /*!< Allow to be closed */
OB_CLIENT_FUNC_ABOVE = 1 << 7, /*!< Allow to be put in lower layer */
OB_CLIENT_FUNC_BELOW = 1 << 8, /*!< Allow to be put in higher layer */
OB_CLIENT_FUNC_UNDECORATE = 1 << 9 /*!< Allow to be undecorated */
OB_CLIENT_FUNC_UNDECORATE = 0 << 9 /*!< Allow to be undecorated */
} ObFunctions;

struct _ObClient
Expand Down Expand Up @@ -110,6 +110,9 @@ struct _ObClient

/*! Normal window title */
gchar *title;

gchar *context_label;

/*! Window title when iconified */
gchar *icon_title;
/*! The title as requested by the client, without any of our own changes */
Expand Down
36 changes: 35 additions & 1 deletion openbox/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
#include "obt/display.h"
#include "obt/xqueue.h"
#include "obt/prop.h"
#include <X11/Xlib-xcb.h>
#include <xcb/xselinux.h>
#include <selinux/selinux.h>
#include <selinux/context.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <stddef.h>
#include <stdint.h>


#define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
ButtonPressMask | ButtonReleaseMask | \
Expand Down Expand Up @@ -93,6 +104,22 @@ ObFrame *frame_new(ObClient *client)
self = g_slice_new0(ObFrame);
self->client = client;

if (is_selinux_enabled()) {
/* Get the window context */
xcb_generic_error_t *xcb_error;
xcb_connection_t *xcb_con = XGetXCBConnection(obt_display);
xcb_selinux_get_client_context_cookie_t client_cookie = xcb_selinux_get_client_context(xcb_con, self->client->window);
xcb_selinux_get_client_context_reply_t *client_reply = xcb_selinux_get_client_context_reply(xcb_con, client_cookie, &xcb_error);
if (client_reply != NULL) {
security_context_t context = NULL, tcon = NULL;
context = xcb_selinux_get_client_context_context(client_reply);
ob_debug("window context %s", context);
int rc = selinux_raw_to_trans_context(context, &tcon);
self->client->context_label = g_strdup(tcon);
freecon(tcon);
}
}

visual = check_32bit_client(client);

/* create the non-visible decor windows */
Expand Down Expand Up @@ -153,6 +180,7 @@ ObFrame *frame_new(ObClient *client)
self->right = createWindow(self->window, NULL, mask, &attrib);

self->label = createWindow(self->title, NULL, mask, &attrib);
self->context_label = createWindow(self->title, NULL, mask, &attrib);
self->max = createWindow(self->title, NULL, mask, &attrib);
self->close = createWindow(self->title, NULL, mask, &attrib);
self->desk = createWindow(self->title, NULL, mask, &attrib);
Expand Down Expand Up @@ -180,6 +208,7 @@ ObFrame *frame_new(ObClient *client)

/* the other stuff is shown based on decor settings */
XMapWindow(obt_display, self->label);
XMapWindow(obt_display, self->context_label);
XMapWindow(obt_display, self->backback);
XMapWindow(obt_display, self->backfront);

Expand Down Expand Up @@ -876,6 +905,8 @@ void frame_adjust_area(ObFrame *self, gboolean moved,
{
XResizeWindow(obt_display, self->label, self->label_width,
ob_rr_theme->label_height);
XResizeWindow(obt_display, self->context_label, self->width,
ob_rr_theme->label_height + ob_rr_theme->paddingy);
}
}

Expand Down Expand Up @@ -1018,6 +1049,7 @@ void frame_grab_client(ObFrame *self)
window_add(&self->innerbrr, CLIENT_AS_WINDOW(self->client));
window_add(&self->title, CLIENT_AS_WINDOW(self->client));
window_add(&self->label, CLIENT_AS_WINDOW(self->client));
window_add(&self->context_label, CLIENT_AS_WINDOW(self->client));
window_add(&self->max, CLIENT_AS_WINDOW(self->client));
window_add(&self->close, CLIENT_AS_WINDOW(self->client));
window_add(&self->desk, CLIENT_AS_WINDOW(self->client));
Expand Down Expand Up @@ -1090,6 +1122,7 @@ void frame_release_client(ObFrame *self)
window_remove(self->innerbrr);
window_remove(self->title);
window_remove(self->label);
window_remove(self->context_label);
window_remove(self->max);
window_remove(self->close);
window_remove(self->desk);
Expand Down Expand Up @@ -1285,7 +1318,7 @@ static void layout_title(ObFrame *self)
if (self->label_on && self->label_width > 0) {
XMapWindow(obt_display, self->label);
XMoveWindow(obt_display, self->label, self->label_x,
ob_rr_theme->paddingy);
3*ob_rr_theme->paddingy + ob_rr_theme->label_height);
} else
XUnmapWindow(obt_display, self->label);
}
Expand Down Expand Up @@ -1473,6 +1506,7 @@ ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)

if (win == self->window) return OB_FRAME_CONTEXT_FRAME;
if (win == self->label) return OB_FRAME_CONTEXT_TITLEBAR;
if (win == self->context_label) return OB_FRAME_CONTEXT_TITLEBAR;
if (win == self->handle) return OB_FRAME_CONTEXT_BOTTOM;
if (win == self->handletop) return OB_FRAME_CONTEXT_BOTTOM;
if (win == self->handlebottom) return OB_FRAME_CONTEXT_BOTTOM;
Expand Down
1 change: 1 addition & 0 deletions openbox/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct _ObFrame

Window title;
Window label;
Window context_label;
Window max;
Window close;
Window desk;
Expand Down
44 changes: 43 additions & 1 deletion openbox/framerender.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
#include "framerender.h"
#include "obrender/theme.h"
#include "obt/prop.h"
#include "obrender/instance.h"
#include "obrender/color.h"
#include "debug.h"
#include <selinux/selinux.h>
#include <selinux/context.h>

static void framerender_label(ObFrame *self, RrAppearance *a);
static void framerender_context_label(ObFrame *self, RrAppearance *a);
static void framerender_icon(ObFrame *self, RrAppearance *a);
static void framerender_max(ObFrame *self, RrAppearance *a);
static void framerender_iconify(ObFrame *self, RrAppearance *a);
Expand Down Expand Up @@ -140,10 +146,11 @@ void framerender_frame(ObFrame *self)
}

if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
RrAppearance *t, *l, *m, *n, *i, *d, *s, *c, *clear;
RrAppearance *t, *l, *m, *n, *i, *d, *s, *c, *clear, *cl;
if (self->focused) {
t = ob_rr_theme->a_focused_title;
l = ob_rr_theme->a_focused_label;
cl = ob_rr_theme->a_focused_context_label;
m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
ob_rr_theme->btn_max->a_disabled_focused :
(self->client->max_vert || self->client->max_horz ?
Expand Down Expand Up @@ -201,6 +208,7 @@ void framerender_frame(ObFrame *self)
} else {
t = ob_rr_theme->a_unfocused_title;
l = ob_rr_theme->a_unfocused_label;
cl = ob_rr_theme->a_unfocused_context_label;
m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
ob_rr_theme->btn_max->a_disabled_unfocused :
(self->client->max_vert || self->client->max_horz ?
Expand Down Expand Up @@ -295,6 +303,10 @@ void framerender_frame(ObFrame *self)
l->surface.parentx = self->label_x;
l->surface.parenty = ob_rr_theme->paddingy;

cl->surface.parent = t;
cl->surface.parentx = self->label_x;
cl->surface.parenty = ob_rr_theme->paddingy;

m->surface.parent = t;
m->surface.parentx = self->max_x;
m->surface.parenty = ob_rr_theme->paddingy + 1;
Expand All @@ -320,6 +332,7 @@ void framerender_frame(ObFrame *self)
c->surface.parenty = ob_rr_theme->paddingy + 1;

framerender_label(self, l);
framerender_context_label(self, cl);
framerender_max(self, m);
framerender_icon(self, n);
framerender_iconify(self, i);
Expand Down Expand Up @@ -370,6 +383,35 @@ static void framerender_label(ObFrame *self, RrAppearance *a)
RrPaint(a, self->label, self->label_width, ob_rr_theme->label_height);
}

static void framerender_context_label(ObFrame *self, RrAppearance *a)
{
if (!self->label_on) return;
/* set the texture's text! */

context_t con = context_new(self->client->context_label);
char *range = context_range_get(con);
a->texture[0].data.text.string = g_strdup(range);

security_context_t raw_context = NULL;
selinux_trans_to_raw_context(self->client->context_label,
&raw_context);
char *colors;
selinux_raw_context_to_color(raw_context,
&colors);
freecon(raw_context);
char *orig_colors = colors;
char *fg = strsep(&colors, " ");
char *bg = strsep(&colors, " ");
context_free(con);

RrColor *textcolor = RrColorParse(ob_rr_inst, fg);
a->texture[0].data.text.color = textcolor;
RrColor *rrcolor = RrColorParse(ob_rr_inst, bg);
a->surface.primary = rrcolor;
a->surface.secondary = rrcolor;
ob_debug("RrPaint: width - %d height - %d\n", self->width, ob_rr_theme->label_height); RrPaint(a, self->context_label, self->width, ob_rr_theme->label_height);
}

static void framerender_icon(ObFrame *self, RrAppearance *a)
{
RrImage *icon;
Expand Down

0 comments on commit dd8099c

Please sign in to comment.