Hello all,

I have attached a patch that implements a user configurable (via
xrdp.ini) login banner to xrdp. The patch works by popping a modal
dialog over the login box immediately upon connection if xrdp is
configured to do so. The patch should apply to the git master branch
as of today, 30-DEC-13. Please review it and consider it for inclusion
in your source tree.

Thanks!
Matt
diff -rupN -x .git xrdp/xrdp/xrdp.ini xrdp-banner/xrdp/xrdp.ini
--- xrdp/xrdp/xrdp.ini  2013-12-30 11:07:35.508013092 -0500
+++ xrdp-banner/xrdp/xrdp.ini   2013-12-30 13:42:37.517667010 -0500
@@ -33,6 +33,24 @@ tcp_keepalive=yes
 #pamerrortxt=change your password according to policy at http://url
 #new_cursors=no
 
+loginbannershow=yes # if unspecified defaults to no
+# WARNING! No upper or lower bounds checking is done for any
+# loginbanner settings. Be sure to choose sane values!
+loginbannerwidth=500 # if unspecified defaults to 640
+loginbannerheight=400 # if unspecified defaults to 480
+# window title for login banner (MAX 256 chars)
+loginbannertitle=Test login banner title
+# add as many lines as you want
+#   default width (640) seems to permit for approximately 80 letters
+#   as xrdp uses a non-monospace font
+#   default height (480) permits for 24 rows of text 
+loginbannerline=Test login banner line 0
+loginbannerline=Test login banner line 1
+loginbannerline=Test login banner line 2
+loginbannerline=Test login banner line 3
+loginbannerline=Test login banner line 4
+loginbannerline=Test login banner line 5
+
 [Logging]
 LogFile=xrdp.log
 LogLevel=DEBUG
diff -rupN -x .git xrdp/xrdp/xrdp_login_wnd.c xrdp-banner/xrdp/xrdp_login_wnd.c
--- xrdp/xrdp/xrdp_login_wnd.c  2013-12-30 11:07:45.000000000 -0500
+++ xrdp-banner/xrdp/xrdp_login_wnd.c   2013-12-30 13:47:12.200567166 -0500
@@ -367,6 +367,208 @@ xrdp_wm_show_edits(struct xrdp_wm *self,
 }
 
 /*****************************************************************************/
+static int APP_CC
+xrdp_wm_login_banner_get_message(struct list *bannerlist)
+{
+    struct list *names;
+    struct list *values;
+    int fd;
+    int i;
+    char *val;
+    char cfg_file[256];
+
+    g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
+    fd = g_file_open(cfg_file); /* xrdp.ini */
+
+    if (fd < 1)
+    {
+        log_message(LOG_LEVEL_ERROR, "Could not read xrdp ini file %s",
+                     cfg_file);
+    }
+
+    names = list_create();
+    names->auto_free = 1;
+    values = list_create();
+    values->auto_free = 1;
+
+    if (file_read_section(fd, "globals", names, values) == 0)
+    {
+        for (i = 0; i < names->count; i++)
+        {
+            val = (char *)list_get_item(names, i);
+
+            if (val != 0)
+            {
+                if (g_strcasecmp(val, "loginbannerline") == 0)
+                {
+                    val = (char *)list_get_item(values, i);
+                    list_add_item(bannerlist, (tbus)g_strdup(val));
+                }
+            }
+        }
+    }
+
+    g_file_close(fd);
+    list_delete(names);
+    list_delete(values);
+    return 0;
+}
+
+/*****************************************************************************/
+static int DEFAULT_CC
+xrdp_wm_login_banner_notify(struct xrdp_bitmap *wnd,
+                            struct xrdp_bitmap *sender,
+                            int msg, long param1, long param2)
+{
+    struct xrdp_painter *p;
+    struct list *login_banner_strings;
+    int i;
+    char *string;
+
+    if (wnd == 0)
+    {
+        return 0;
+    }
+
+    if (sender == 0)
+    {
+        return 0;
+    }
+
+    if (wnd->owner == 0)
+    {
+        return 0;
+    }
+
+    if (msg == 1) /* click */
+    {
+        if (sender->id == 1) /* ok button */
+        {
+            if (sender->owner->notify != 0)
+            {
+                wnd->owner->notify(wnd->owner, wnd, 100, 1, 0); /* ok */
+            }
+        }
+        else if (sender->id == 2) /* cancel button */
+        {
+            /* call the same routine the login window uses to get
+               rid of the connection */
+            xrdp_wm_cancel_clicked(wnd);
+        }
+    }
+    else if (msg == WM_PAINT) /* 3 */
+    {
+        p = (struct xrdp_painter *)param1;
+
+        login_banner_strings = list_create();
+        xrdp_wm_login_banner_get_message(login_banner_strings);
+
+        if (p != 0)
+        {
+            p->fg_color = wnd->wm->black;
+
+            for (i = 0; i < login_banner_strings->count; i++)
+            {
+                string = list_get_item(login_banner_strings, i);
+                xrdp_painter_draw_text(p, wnd, 10, 30 + (i * 16), string);
+            }
+        }
+
+        list_delete(login_banner_strings);
+    }
+
+    return 0;
+}
+
+/*****************************************************************************/
+static int APP_CC
+xrdp_wm_login_banner(struct xrdp_bitmap *wnd)
+{
+    struct xrdp_bitmap *banner;
+    struct xrdp_bitmap *but;
+    int login_banner_width;
+    int login_banner_height;
+
+    login_banner_width = DEFAULT_WND_BANNER_W;
+
+    /* override default banner width iff set in xrdp.ini */
+    if (wnd->wm->login_banner_width > 0)
+    {
+        login_banner_width = wnd->wm->login_banner_width;
+    }
+
+    login_banner_height = DEFAULT_WND_BANNER_H;
+
+    /* override default banner height iff set in xrdp.ini */
+    if (wnd->wm->login_banner_height > 0) 
+    {
+        login_banner_height = wnd->wm->login_banner_height;
+    }
+
+    if (wnd->wm->screen->width < login_banner_width)
+    {
+        login_banner_width = wnd->wm->screen->width;
+    }
+
+    if (wnd->wm->screen->height < login_banner_height)
+    {
+        login_banner_height = wnd->wm->screen->height;
+    }
+
+    banner = xrdp_bitmap_create(login_banner_width, login_banner_height,
+                                 wnd->wm->screen->bpp, WND_TYPE_WND, wnd->wm);
+    list_insert_item(wnd->wm->screen->child_list, 0, (long)banner);
+    banner->parent = wnd->wm->screen;
+    banner->owner = wnd;
+    wnd->modal_dialog = banner;
+    banner->bg_color = wnd->wm->grey;
+    banner->left = wnd->wm->screen->width / 2 - banner->width / 2;
+    banner->top = wnd->wm->screen->height / 2 - banner->height / 2;
+    banner->notify = xrdp_wm_login_banner_notify;
+
+    if (g_strcmp(wnd->wm->login_banner_title, "") == 0)
+    {
+        set_string(&banner->caption1, "Login banner");
+    }
+    else
+    {
+        set_string(&banner->caption1, wnd->wm->login_banner_title);
+    }
+
+    /* ok button */
+    but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, 
+                             wnd->wm->screen->bpp, WND_TYPE_BUTTON, wnd->wm);
+    list_insert_item(banner->child_list, 0, (long)but);
+    but->parent = banner;
+    but->owner = banner;
+    but->left = ((login_banner_width / 2) - DEFAULT_BUTTON_W - 5); /* center */
+    but->top = login_banner_height - DEFAULT_BUTTON_H - 15;
+    but->id = 1;
+    but->tab_stop = 1;
+    set_string(&but->caption1, "OK");
+    banner->focused_control = but;
+    banner->default_button = but;
+
+    /* ok button */
+    but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, 
+                             wnd->wm->screen->bpp, WND_TYPE_BUTTON, wnd->wm);
+    list_insert_item(banner->child_list, 1, (long)but);
+    but->parent = banner;
+    but->owner = banner;
+    but->left = ((login_banner_width / 2) +  5); /* center */
+    but->top = login_banner_height - DEFAULT_BUTTON_H - 15;
+    but->id = 2;
+    but->tab_stop = 2;
+    set_string(&but->caption1, "Cancel");
+
+    /* draw it */
+    banner->esc_button = but;
+    xrdp_bitmap_invalidate(banner, 0);
+    xrdp_wm_set_focused(wnd->wm, banner);
+    return 0;
+}
+
+/*****************************************************************************/
 /* all login screen events go here */
 static int DEFAULT_CC
 xrdp_wm_login_notify(struct xrdp_bitmap *wnd,
@@ -649,5 +851,15 @@ xrdp_login_wnd_create(struct xrdp_wm *se
     /* labels and edits */
     xrdp_wm_show_edits(self, combo);
 
+    if (self->login_banner_show)
+    {
+        xrdp_wm_login_banner(self->login_window);
+    }
+
     return 0;
 }
+
+
+
+
+
diff -rupN -x .git xrdp/xrdp/xrdp_types.h xrdp-banner/xrdp/xrdp_types.h
--- xrdp/xrdp/xrdp_types.h      2013-12-30 11:07:35.511012993 -0500
+++ xrdp-banner/xrdp/xrdp_types.h       2013-12-30 13:43:17.050357425 -0500
@@ -320,6 +320,10 @@ struct xrdp_wm
   int allowedchannels[MAX_NR_CHANNELS];
   int allowedinitialized ;
   char pamerrortxt[256];
+  int login_banner_show;
+  int login_banner_width;
+  int login_banner_height;
+  char login_banner_title[256];
 };
 
 /* rdp process */
@@ -441,6 +445,8 @@ struct xrdp_bitmap
 #define DEFAULT_WND_LOG_W     400
 #define DEFAULT_WND_LOG_H     400
 #define DEFAULT_WND_SPECIAL_H 100
+#define DEFAULT_WND_BANNER_W    640
+#define DEFAULT_WND_BANNER_H    480
 
 /* font */
 struct xrdp_font
diff -rupN -x .git xrdp/xrdp/xrdp_wm.c xrdp-banner/xrdp/xrdp_wm.c
--- xrdp/xrdp/xrdp_wm.c 2013-12-30 11:07:45.000000000 -0500
+++ xrdp-banner/xrdp/xrdp_wm.c  2013-12-30 13:45:39.375642455 -0500
@@ -356,9 +356,9 @@ xrdp_wm_load_static_colors_plus(struct x
     int bindex;
     int gindex;
     int rindex;
-
     int fd;
     int index;
+
     char *val;
     struct list *names;
     struct list *values;
@@ -463,6 +463,26 @@ xrdp_wm_load_static_colors_plus(struct x
                         val = (char *)list_get_item(values, index);
                         g_strncpy(self->pamerrortxt, val, 255);
                     }
+                    else if (g_strcasecmp(val, "loginbannershow") == 0)
+                    {
+                        val = (char *)list_get_item(values, index);
+                        self->login_banner_show = text2bool(val);
+                    }
+                    else if (g_strcasecmp(val, "loginbannerwidth") == 0)
+                    {
+                        val = (char *)list_get_item(values, index);
+                        self->login_banner_width = g_atoi(val);
+                    }
+                    else if (g_strcasecmp(val, "loginbannerheight") == 0)
+                    {
+                        val = (char *)list_get_item(values, index);
+                        self->login_banner_height = g_atoi(val);
+                    }
+                    else if (g_strcasecmp(val, "loginbannertitle") == 0)
+                    {
+                        val = (char *)list_get_item(values, index);
+                        g_strncpy(self->login_banner_title, val, 255);
+                    }
                 }
             }
         }
@@ -642,9 +662,15 @@ xrdp_wm_init(struct xrdp_wm *self)
     else
     {
         xrdp_login_wnd_create(self);
+
+        /* Do not force focus on login_window if we're showing a banner */ 
+        if (!self->login_banner_show)
+        {
+            xrdp_wm_set_focused(self, self->login_window);
+        }
+
         /* clear screen */
         xrdp_bitmap_invalidate(self->screen, 0);
-        xrdp_wm_set_focused(self, self->login_window);
         xrdp_wm_set_login_mode(self, 1);
     }
 
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
xrdp-devel mailing list
xrdp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xrdp-devel

Reply via email to