--- a/configure.ac
+++ b/configure.ac
@@ -378,7 +378,7 @@ locales="\
  ru_RU.UTF-8  sr_CS.UTF-8 tatar-cyr   th_TH        th_TH.UTF-8  tscii-0 \
  vi_VN.tcvn   vi_VN.viscii            zh_CN        zh_CN.gb18030 \
  zh_CN.gbk    zh_CN.UTF-8 zh_HK.big5  zh_HK.big5hkscs           zh_HK.UTF-8 \
- zh_TW        zh_TW.big5  zh_TW.UTF-8"
+ zh_TW        zh_TW.big5  zh_TW.UTF-8 ibm-cp866"
 AC_SUBST(locales)
 
 XKEYSYMDB="${X11_DATADIR}/XKeysymDB"
--- a/nls/compose.dir.pre
+++ b/nls/compose.dir.pre
@@ -185,6 +185,7 @@ iso8859-10/Compose:		lg_UG.ISO8859-10
 XCOMM Remove ko/Compose, as requested in https://bugs.debian.org/89703
 XCOMM ko/Compose:			ko_KR.eucKR
 ibm-cp1133/Compose:		lo_LA.IBM-CP1133
+ibm-cp866/Compose:              ru_RU.CP866
 mulelao-1/Compose:		lo_LA.MULELAO-1
 iso8859-4/Compose:		lt_LT.ISO8859-4
 iso8859-13/Compose:		lt_LT.ISO8859-13
--- /dev/null
+++ b/nls/ibm-cp866/Compose.pre
@@ -0,0 +1 @@
+
--- /dev/null
+++ b/nls/ibm-cp866/Makefile.am
@@ -0,0 +1,3 @@
+x11thislocaledir = $(X11_LOCALEDATADIR)/ibm-cp866
+
+include $(top_srcdir)/nls/localerules.in
--- /dev/null
+++ b/nls/ibm-cp866/XI18N_OBJS
@@ -0,0 +1,7 @@
+# CATEGORY(XLC|XIM|OM) SHARED_LIBRARY_NAME     FUNCTION_NAME
+#
+#      XI18N objects table for ibm-cp866 locale
+#
+XLC    common/xlcDef   _XlcDefaultLoader       # XLC_open
+XIM    common/ximcp    _XimOpenIM _XimRegisterIMInstantiateCallback  _XimUnRegisterIMInstantiateCallback # XIM_open   XIM_register XIM_unregister
+XOM    common/xomGeneric       _XomGenericOpenOM       # XOM_open
--- /dev/null
+++ b/nls/ibm-cp866/XLC_LOCALE.pre
@@ -0,0 +1,82 @@
+XCOMM  $Xorg: ibm-cp866,v 1.3 2000/08/17 19:47:00 cpqbld Exp $
+XCOMM  XLocale Database Sample for ibm-cp866.
+XCOMM
+XCOMM
+XCOMM  $XFree86: xc/nls/XLC_LOCALE/ibm-cp866,v 3.3 2000/12/01 17:43:03 dawes Exp $
+
+XCOMM
+XCOMM  XLC_FONTSET category
+XCOMM
+XLC_FONTSET
+XCOMM  fs0 class (7 bit ASCII)
+fs0    {
+       charset {
+               name            ISO8859-1:GL
+       }
+       font    {
+               primary         CP866:GL
+               substitute      ISO8859-1:GL
+       }
+}
+XCOMM  fs1 class
+fs1    {
+       charset         CP866:GR
+       font            CP866:GR
+}
+END XLC_FONTSET
+
+XCOMM
+XCOMM  XLC_CHARSET_DEFINE category
+XCOMM
+XLC_CHARSET_DEFINE
+csd0   {
+       charset_name    CP866
+       side            GR
+       length          1
+       string_encoding False
+       sequence        \x1b%/1
+}
+END XLC_CHARSET_DEFINE
+
+XCOMM
+XCOMM  XLC_XLOCALE category
+XCOMM
+XLC_XLOCALE
+
+encoding_name           CP866
+mb_cur_max             1
+state_depend_encoding  False
+#if WCHAR32
+wc_encoding_mask       \x30000000
+wc_shift_bits          7
+#else
+wc_encoding_mask       \x00008080
+wc_shift_bits          8
+#endif
+
+#ifndef X_LOCALE
+use_stdc_env           True
+#endif
+
+XCOMM  cs0 class
+cs0    {
+       side            GL:Default
+       length          1
+       wc_encoding     \x00000000
+       ct_encoding     CP866:GL; ISO8859-1:GL
+}
+
+
+XCOMM  cs1 class
+cs1    {
+       side            GR:Default
+       length          1
+#if WCHAR32
+       wc_encoding     \x30000000
+#else
+       wc_encoding     \x00008080
+#endif
+       ct_encoding     CP866:GR
+}
+
+END XLC_XLOCALE
--- a/nls/locale.alias.pre
+++ b/nls/locale.alias.pre
@@ -988,6 +988,7 @@ ru_RU.cp1251:					ru_RU.CP1251
 ru_RU.microsoftcp1251:				ru_RU.CP1251
 ru_RU.microsoft-cp1251:				ru_RU.CP1251
 ru_RU.MICROSOFT-CP1251:				ru_RU.CP1251
+ru_RU.cp866:                                    ru_RU.CP866
 #if defined(INCLUDE_ru_SU)
 XCOMM ru_SU is redundant now
 ru_SU:						ru_RU.KOI8-R
--- a/src/xlibi18n/Makefile.am
+++ b/src/xlibi18n/Makefile.am
@@ -97,6 +97,7 @@ libi18n_la_SOURCES = \
 	lcUniConv/cp1251.h\
 	lcUniConv/cp1255.h\
 	lcUniConv/cp1256.h\
+        lcUniConv/cp866.h \
 	lcUniConv/gb2312.h\
 	lcUniConv/gbk.h\
 	lcUniConv/georgian_academy.h\
--- a/src/xlibi18n/lcUTF8.c
+++ b/src/xlibi18n/lcUTF8.c
@@ -187,6 +187,7 @@ typedef struct _Utf8ConvRec {
 #include "lcUniConv/koi8_r.h"
 #include "lcUniConv/koi8_u.h"
 #include "lcUniConv/koi8_c.h"
+#include "lcUniConv/cp866.h"
 #include "lcUniConv/armscii_8.h"
 #include "lcUniConv/cp1133.h"
 #include "lcUniConv/mulelao.h"
@@ -304,6 +305,9 @@ static Utf8ConvRec all_charsets[] = {
     { "IBM-CP1133", NULLQUARK,
 	cp1133_mbtowc, cp1133_wctomb
     },
+    { "CP866", NULLQUARK,
+       cp866_mbtowc, cp866_wctomb
+    },
     { "MULELAO-1", NULLQUARK,
 	mulelao_mbtowc, mulelao_wctomb
     },
--- /dev/null
+++ b/src/xlibi18n/lcUniConv/cp866.h
@@ -0,0 +1,113 @@
+
+/*
+ * CP866
+ */
+
+static const unsigned short cp866_2uni[128] = {
+  /* 0x80 */
+  0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
+  0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f,
+  /* 0x90 */
+  0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
+  0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f,
+  /* 0xa0 */
+  0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
+  0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f,
+  /* 0xb0 */
+  0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
+  0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
+  /* 0xc0 */
+  0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
+  0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
+  /* 0xd0 */
+  0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b,
+  0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,
+  /* 0xe0 */
+  0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
+  0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f,
+  /* 0xf0 */
+  0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040e, 0x045e,
+  0x00b0, 0x2219, 0x00b7, 0x221a, 0x2116, 0x00a4, 0x25a0, 0x00a0,
+};
+
+static int
+cp866_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
+{
+  unsigned char c = *s;
+  if (c < 0x80)
+    *pwc = (ucs4_t) c;
+  else
+    *pwc = (ucs4_t) cp866_2uni[c-0x80];
+  return 1;
+}
+
+static const unsigned char cp866_page00[24] = {
+  0xff, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
+  0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfa, /* 0xb0-0xb7 */
+};
+static const unsigned char cp866_page04[96] = {
+  0x00, 0xf0, 0x00, 0x00, 0xf2, 0x00, 0x00, 0xf4, /* 0x00-0x07 */
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0x00, /* 0x08-0x0f */
+  0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 0x10-0x17 */
+  0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, /* 0x18-0x1f */
+  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, /* 0x20-0x27 */
+  0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, /* 0x28-0x2f */
+  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, /* 0x30-0x37 */
+  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, /* 0x38-0x3f */
+  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, /* 0x40-0x47 */
+  0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, /* 0x48-0x4f */
+  0x00, 0xf1, 0x00, 0x00, 0xf3, 0x00, 0x00, 0xf5, /* 0x50-0x57 */
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7, 0x00, /* 0x58-0x5f */
+};
+static const unsigned char cp866_page22[8] = {
+  0x00, 0xf9, 0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
+};
+static const unsigned char cp866_page25[168] = {
+  0xc4, 0x00, 0xb3, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
+  0x00, 0x00, 0x00, 0x00, 0xda, 0x00, 0x00, 0x00, /* 0x08-0x0f */
+  0xbf, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, /* 0x10-0x17 */
+  0xd9, 0x00, 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, /* 0x18-0x1f */
+  0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, /* 0x20-0x27 */
+  0x00, 0x00, 0x00, 0x00, 0xc2, 0x00, 0x00, 0x00, /* 0x28-0x2f */
+  0x00, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00, 0x00, /* 0x30-0x37 */
+  0x00, 0x00, 0x00, 0x00, 0xc5, 0x00, 0x00, 0x00, /* 0x38-0x3f */
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
+  0xcd, 0xba, 0xd5, 0xd6, 0xc9, 0xb8, 0xb7, 0xbb, /* 0x50-0x57 */
+  0xd4, 0xd3, 0xc8, 0xbe, 0xbd, 0xbc, 0xc6, 0xc7, /* 0x58-0x5f */
+  0xcc, 0xb5, 0xb6, 0xb9, 0xd1, 0xd2, 0xcb, 0xcf, /* 0x60-0x67 */
+  0xd0, 0xca, 0xd8, 0xd7, 0xce, 0x00, 0x00, 0x00, /* 0x68-0x6f */
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
+  0xdf, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, /* 0x80-0x87 */
+  0xdb, 0x00, 0x00, 0x00, 0xdd, 0x00, 0x00, 0x00, /* 0x88-0x8f */
+  0xde, 0xb0, 0xb1, 0xb2, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
+  0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
+};
+
+static int
+cp866_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
+{
+  unsigned char c = 0;
+  if (wc < 0x0080) {
+    *r = wc;
+    return 1;
+  }
+  else if (wc >= 0x00a0 && wc < 0x00b8)
+    c = cp866_page00[wc-0x00a0];
+  else if (wc >= 0x0400 && wc < 0x0460)
+    c = cp866_page04[wc-0x0400];
+  else if (wc == 0x2116)
+    c = 0xfc;
+  else if (wc >= 0x2218 && wc < 0x2220)
+    c = cp866_page22[wc-0x2218];
+  else if (wc >= 0x2500 && wc < 0x25a8)
+    c = cp866_page25[wc-0x2500];
+  if (c != 0) {
+    *r = c;
+    return 1;
+  }
+  return RET_ILSEQ;
+}
--- a/nls/locale.dir.pre
+++ b/nls/locale.dir.pre
@@ -235,6 +235,7 @@ microsoft-cp1251/XLC_LOCALE: 		ru_RU.CP1
 koi8-r/XLC_LOCALE: 			ru_RU.KOI8-R
 microsoft-cp1251/XLC_LOCALE: 		ru_UA.CP1251
 koi8-u/XLC_LOCALE:			ru_UA.KOI8-U
+ibm-cp866/XLC_LOCALE:                  ru_RU.CP866
 iso8859-1/XLC_LOCALE:           rw_RW.ISO8859-1
 iso8859-2/XLC_LOCALE: 			sh_YU.ISO8859-2
 iso8859-2/XLC_LOCALE: 			sk_SK.ISO8859-2
