summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorAlexandra Ellwood <lxs@mit.edu>2008-07-24 21:26:14 +0000
committerAlexandra Ellwood <lxs@mit.edu>2008-07-24 21:26:14 +0000
commiteb14fbed2b11a4369b76367e5f15aa1237bc14fb (patch)
tree1d870506c71c1d95cd4901c4eeb4541c7840f04d /src/include
parent4b6f2fd2ea29a84fec63b328846bfb31bb85268e (diff)
Return extended krb5 error strings
Use krb5_get_error_message instead of error_message for detailed krb5 error strings. Also removed a few remaining instances of types ending in _t and fixed up some whitespace issues. Recommend ignoring whitespace diff. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20579 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/include')
-rw-r--r--src/include/kim/kim_options.h114
1 files changed, 57 insertions, 57 deletions
diff --git a/src/include/kim/kim_options.h b/src/include/kim/kim_options.h
index 9699501529..bf30b75b66 100644
--- a/src/include/kim/kim_options.h
+++ b/src/include/kim/kim_options.h
@@ -28,9 +28,9 @@
#ifdef __cplusplus
extern "C" {
#endif
-
+
#include <kim/kim_types.h>
-
+
/*!
* \addtogroup kim_types_reference
* @{
@@ -51,7 +51,7 @@ extern "C" {
* This value determines what type of user interface is displayed.
* See \ref kim_options_custom_prompt_callback for more information.
*/
-typedef uint32_t kim_prompt_type_t;
+typedef uint32_t kim_prompt_type;
enum kim_prompt_type_enum {
kim_prompt_type_password = 0,
@@ -62,45 +62,45 @@ enum kim_prompt_type_enum {
* The prompt callback used to display a prompt to the user.
* See \ref kim_options_custom_prompt_callback for more information.
*/
-typedef kim_error_code (*kim_prompt_callback_t) (kim_options *io_options,
- kim_prompt_type_t in_type,
- kim_string in_title,
- kim_string in_message,
- kim_string in_description,
- void **out_reply);
+typedef kim_error_code (*kim_prompt_callback) (kim_options *io_options,
+ kim_prompt_type in_type,
+ kim_string in_title,
+ kim_string in_message,
+ kim_string in_description,
+ void **out_reply);
/*!
* The default prompt callback.
* See \ref kim_options_custom_prompt_callback for more information.
*/
kim_error_code kim_prompt_callback_default (kim_options *io_options,
- kim_prompt_type_t in_type,
- kim_string in_title,
- kim_string in_message,
- kim_string in_description,
- void **out_reply);
+ kim_prompt_type in_type,
+ kim_string in_title,
+ kim_string in_message,
+ kim_string in_description,
+ void **out_reply);
/*!
* The graphical prompt callback.
* See \ref kim_options_custom_prompt_callback for more information.
*/
kim_error_code kim_prompt_callback_gui (kim_options *io_options,
- kim_prompt_type_t in_type,
- kim_string in_title,
- kim_string in_message,
- kim_string in_description,
- void **out_reply);
+ kim_prompt_type in_type,
+ kim_string in_title,
+ kim_string in_message,
+ kim_string in_description,
+ void **out_reply);
/*!
* The command line prompt callback.
* See \ref kim_options_custom_prompt_callback for more information.
*/
kim_error_code kim_prompt_callback_cli (kim_options *io_options,
- kim_prompt_type_t in_type,
- kim_string in_title,
- kim_string in_message,
- kim_string in_description,
- void **out_reply);
+ kim_prompt_type in_type,
+ kim_string in_title,
+ kim_string in_message,
+ kim_string in_description,
+ void **out_reply);
/*!
* The prompt callback which always returns an error.
@@ -109,11 +109,11 @@ kim_error_code kim_prompt_callback_cli (kim_options *io_options,
* See \ref kim_options_custom_prompt_callback for more information.
*/
kim_error_code kim_prompt_callback_none (kim_options *io_options,
- kim_prompt_type_t in_type,
- kim_string in_title,
- kim_string in_message,
- kim_string in_description,
- void **out_reply);
+ kim_prompt_type in_type,
+ kim_string in_title,
+ kim_string in_message,
+ kim_string in_description,
+ void **out_reply);
/*! @} */
@@ -305,7 +305,7 @@ kim_error kim_options_create (kim_options *out_options);
* \brief Copy options.
*/
kim_error kim_options_copy (kim_options *out_options,
- kim_options in_options);
+ kim_options in_options);
/*!
* \param io_options an options object to modify.
@@ -317,7 +317,7 @@ kim_error kim_options_copy (kim_options *out_options,
* \sa kim_options_get_prompt_callback()
*/
kim_error kim_options_set_prompt_callback (kim_options io_options,
- kim_prompt_callback_t in_prompt_callback);
+ kim_prompt_callback in_prompt_callback);
/*!
* \param in_options an options object.
@@ -331,7 +331,7 @@ kim_error kim_options_set_prompt_callback (kim_options io_options,
* \sa kim_options_set_prompt_callback()
*/
kim_error kim_options_get_prompt_callback (kim_options in_options,
- kim_prompt_callback_t *out_prompt_callback);
+ kim_prompt_callback *out_prompt_callback);
/*!
* \param io_options an options object to modify.
@@ -345,7 +345,7 @@ kim_error kim_options_get_prompt_callback (kim_options in_options,
* \sa kim_options_get_data()
*/
kim_error kim_options_set_data (kim_options io_options,
- const void *in_data);
+ const void *in_data);
/*!
* \param in_options an options object.
@@ -360,7 +360,7 @@ kim_error kim_options_set_data (kim_options io_options,
* \sa kim_options_set_data()
*/
kim_error kim_options_get_data (kim_options in_options,
- const void **out_data);
+ const void **out_data);
/*!
* \param io_options an options object to modify.
@@ -376,9 +376,9 @@ kim_error kim_options_get_data (kim_options in_options,
* NULL (no response is set by default)
* \sa kim_options_get_prompt_response()
*/
-kim_error kim_options_set_prompt_response (kim_options io_options,
- kim_prompt_type_t in_prompt_type,
- void *in_response);
+kim_error kim_options_set_prompt_response (kim_options io_options,
+ kim_prompt_type in_prompt_type,
+ void *in_response);
/*!
* \param in_options an options object.
@@ -397,8 +397,8 @@ kim_error kim_options_set_prompt_response (kim_options io_options,
* \sa kim_options_set_prompt_response()
*/
kim_error kim_options_get_prompt_response (kim_options in_options,
- kim_prompt_type_t in_prompt_type,
- void **out_response);
+ kim_prompt_type in_prompt_type,
+ void **out_response);
/*!
* \param io_options an options object to modify.
@@ -414,7 +414,7 @@ kim_error kim_options_get_prompt_response (kim_options in_options,
* \sa kim_options_get_start_time(), kim_credential_validate(), kim_ccache_validate(), kim_identity_validate()
*/
kim_error kim_options_set_start_time (kim_options io_options,
- kim_time in_start_time);
+ kim_time in_start_time);
/*!
* \param in_options an options object.
@@ -430,7 +430,7 @@ kim_error kim_options_set_start_time (kim_options io_options,
* \sa kim_options_set_start_time(), kim_credential_validate(), kim_ccache_validate(), kim_identity_validate()
*/
kim_error kim_options_get_start_time (kim_options in_options,
- kim_time *out_start_time);
+ kim_time *out_start_time);
/*!
* \param io_options an options object to modify.
@@ -445,7 +445,7 @@ kim_error kim_options_get_start_time (kim_options in_options,
* Read from the user's preferences and the Kerberos configuration. 10 hours if unspecified.
*/
kim_error kim_options_set_lifetime (kim_options io_options,
- kim_lifetime in_lifetime);
+ kim_lifetime in_lifetime);
/*!
* \param in_options an options object.
@@ -460,10 +460,10 @@ kim_error kim_options_set_lifetime (kim_options io_options,
* \sa kim_options_set_lifetime()
*/
kim_error kim_options_get_lifetime (kim_options in_options,
- kim_lifetime *out_lifetime);
+ kim_lifetime *out_lifetime);
/*!
-* \param io_options an options object to modify.
+ * \param io_options an options object to modify.
* \param in_renewable a boolean value indicating whether or not to request a renewable
* credential.
* \return On success, #KIM_NO_ERROR. On failure, an error object representing the failure.
@@ -473,10 +473,10 @@ kim_error kim_options_get_lifetime (kim_options in_options,
* \sa kim_options_get_renewable()
*/
kim_error kim_options_set_renewable (kim_options io_options,
- kim_boolean in_renewable);
+ kim_boolean in_renewable);
/*!
-* \param in_options an options object.
+ * \param in_options an options object.
* \param out_renewable on exit, a boolean value indicating whether or \a in_options will
* request a renewable credential.
* \return On success, #KIM_NO_ERROR. On failure, an error object representing the failure.
@@ -486,7 +486,7 @@ kim_error kim_options_set_renewable (kim_options io_options,
* \sa kim_options_set_renewable()
*/
kim_error kim_options_get_renewable (kim_options in_options,
- kim_boolean *out_renewable);
+ kim_boolean *out_renewable);
/*!
* \param io_options an options object to modify.
@@ -501,7 +501,7 @@ kim_error kim_options_get_renewable (kim_options in_options,
* \sa kim_options_get_renewal_lifetime(), kim_identity_renew(), kim_credential_renew(), kim_ccache_renew()
*/
kim_error kim_options_set_renewal_lifetime (kim_options io_options,
- kim_lifetime in_renewal_lifetime);
+ kim_lifetime in_renewal_lifetime);
/*!
* \param in_options an options object.
@@ -517,7 +517,7 @@ kim_error kim_options_set_renewal_lifetime (kim_options io_options,
* \sa kim_options_set_renewal_lifetime(), kim_identity_renew(), kim_credential_renew(), kim_ccache_renew()
*/
kim_error kim_options_get_renewal_lifetime (kim_options in_options,
- kim_lifetime *out_renewal_lifetime);
+ kim_lifetime *out_renewal_lifetime);
/*!
* \param io_options an options object to modify.
@@ -530,7 +530,7 @@ kim_error kim_options_get_renewal_lifetime (kim_options in_options,
* \sa kim_options_get_forwardable()
*/
kim_error kim_options_set_forwardable (kim_options io_options,
- kim_boolean in_forwardable);
+ kim_boolean in_forwardable);
/*!
* \param in_options an options object.
@@ -543,7 +543,7 @@ kim_error kim_options_set_forwardable (kim_options io_options,
* \sa kim_options_set_forwardable()
*/
kim_error kim_options_get_forwardable (kim_options in_options,
- kim_boolean *out_forwardable);
+ kim_boolean *out_forwardable);
/*!
* \param io_options an options object to modify.
@@ -556,7 +556,7 @@ kim_error kim_options_get_forwardable (kim_options in_options,
* \sa kim_options_get_proxiable()
*/
kim_error kim_options_set_proxiable (kim_options io_options,
- kim_boolean in_proxiable);
+ kim_boolean in_proxiable);
/*!
* \param in_options an options object.
@@ -569,7 +569,7 @@ kim_error kim_options_set_proxiable (kim_options io_options,
* \sa kim_options_set_proxiable()
*/
kim_error kim_options_get_proxiable (kim_options in_options,
- kim_boolean *out_proxiable);
+ kim_boolean *out_proxiable);
/*!
* \param io_options an options object to modify.
@@ -582,7 +582,7 @@ kim_error kim_options_get_proxiable (kim_options in_options,
* \sa kim_options_get_addressless()
*/
kim_error kim_options_set_addressless (kim_options io_options,
- kim_boolean in_addressless);
+ kim_boolean in_addressless);
/*!
* \param in_options an options object.
@@ -595,7 +595,7 @@ kim_error kim_options_set_addressless (kim_options io_options,
* \sa kim_options_set_addressless()
*/
kim_error kim_options_get_addressless (kim_options in_options,
- kim_boolean *out_addressless);
+ kim_boolean *out_addressless);
/*!
* \param io_options an options object to modify.
@@ -607,7 +607,7 @@ kim_error kim_options_get_addressless (kim_options in_options,
* \sa kim_options_get_service_name()
*/
kim_error kim_options_set_service_name (kim_options io_options,
- kim_string in_service_name);
+ kim_string in_service_name);
/*!
* \param in_options an options object.
@@ -620,7 +620,7 @@ kim_error kim_options_set_service_name (kim_options io_options,
* \sa kim_options_set_service_name()
*/
kim_error kim_options_get_service_name (kim_options in_options,
- kim_string *out_service_name);
+ kim_string *out_service_name);
/*!
* \param io_options the options object to be freed. Set to NULL on exit.
ref='#n576'>576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.dbs;


import java.math.BigInteger;
import java.util.*;
import java.io.*;
import java.security.*;
import java.security.cert.*;
import java.security.cert.Certificate;
import netscape.security.x509.*;
import netscape.ldap.*;
import com.netscape.certsrv.base.SessionContext;
import com.netscape.certsrv.base.*;
import com.netscape.certsrv.dbs.*;
import com.netscape.certsrv.dbs.certdb.*;
import com.netscape.certsrv.dbs.repository.*;
import com.netscape.certsrv.logging.*;
import com.netscape.certsrv.apps.*;
import com.netscape.certsrv.ca.*;

import com.netscape.cmscore.dbs.*;
import com.netscape.cmscore.util.*;
import com.netscape.cmscore.cert.*;


/**
 * A class represents a certificate repository. It
 * stores all the issued certificate.
 * <P>
 *
 * @author thomask
 * @author kanda
 * @version $Revision$, $Date$
 */
public class CertificateRepository extends Repository
    implements ICertificateRepository {

    public final String CERT_X509ATTRIBUTE = "x509signedcert";

    private IDBSubsystem mDBService;
    private String mBaseDN;
    private String mRequestBaseDN;
    private boolean mConsistencyCheck = false;
    private boolean mSkipIfInconsistent = false;

    private int mCertStatusUpdateInterval = 0;
    private Hashtable mCRLIssuingPoints = new Hashtable();

    private int mTransitMaxRecords = 1000000;
    private int mTransitRecordPageSize = 200;

    /**
     * Constructs a certificate repository.
     */
    public CertificateRepository(IDBSubsystem dbService, String certRepoBaseDN, int increment, String baseDN)
        throws EDBException {
        super(dbService, increment, baseDN);
        mBaseDN = certRepoBaseDN;
      
        mDBService = dbService;

        // registers CMS database attributes
        IDBRegistry reg = dbService.getRegistry();

        IConfigStore cfg = mDBService.getConfigStore();
    }

    public ICertRecord createCertRecord(BigInteger id, Certificate cert, MetaInfo meta) {
        return new CertRecord(id, cert, meta);
    }

    public BigInteger getLastSerialNumberInRange(BigInteger  serial_low_bound, BigInteger serial_upper_bound)
    throws EBaseException {

        CMS.debug("CertificateRepository:  in getLastSerialNumberInRange: low " + serial_low_bound + " high " + serial_upper_bound);

        if(serial_low_bound == null || serial_upper_bound == null || serial_low_bound.compareTo(serial_upper_bound) >= 0 )
        { 
            return null;

        }

        String ldapfilter = "(" + "certstatus" + "=*" + ")";

        String[] attrs = null;

        ICertRecordList recList = findCertRecordsInList(ldapfilter,attrs,serial_upper_bound.toString(10),"serialno", 5 * -1);

        int size = recList.getSize();

        CMS.debug("CertificateRepository:getLastSerialNumberInRange: recList size " + size);

        if (size <= 0) {
            CMS.debug("CertificateRepository:getLastSerialNumberInRange: index may be empty");

            BigInteger ret = new BigInteger(serial_low_bound.toString(10));

            ret = ret.add(new BigInteger("-1")); 
            CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + ret);
            return ret;
        }
        int ltSize = recList.getSizeBeforeJumpTo();

        Vector cList = new Vector(ltSize);

        CMS.debug("CertificateRepository:getLastSerialNumberInRange: ltSize " + ltSize);

        CertRecord curRec = null;

        int i;
        Object obj = null;

        for (i = 0; i < 5; i++) {
            obj = recList.getCertRecord(i);

            if (obj != null) {
                curRec = (CertRecord) obj;

                BigInteger serial = curRec.getSerialNumber();

                CMS.debug("CertificateRepository:getLastCertRecordSerialNo:  serialno  " + serial);

                if(  ((serial.compareTo(serial_low_bound) == 0) || (serial.compareTo(serial_low_bound) == 1) ) &&
                     ((serial.compareTo(serial_upper_bound) == 0) || (serial.compareTo(serial_upper_bound) == -1) ))
                {
                    CMS.debug("getLastSerialNumberInRange returning: " + serial);
                    return serial;
                }
            } else {
                CMS.debug("getLastSerialNumberInRange:found null from getCertRecord");
            }
        }
        

        BigInteger ret = new BigInteger(serial_low_bound.toString(10));

        ret = ret.add(new BigInteger("-1")); 

        CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + ret);
        return ret; 

    }

    /**
     * Removes all objects with this repository.
     */
    public void removeCertRecords(BigInteger beginS, BigInteger endS) throws EBaseException
    {
        String filter = "(" + CertRecord.ATTR_CERT_STATUS + "=*" + ")";
        ICertRecordList list =findCertRecordsInList(filter, 
                    null, "serialno", 10);
        int size = list.getSize();
        Enumeration e = list.getCertRecords(0, size - 1);
        while (e.hasMoreElements()) {
            CertRecord rec = (CertRecord) e.nextElement();
            BigInteger cur = rec.getSerialNumber();
            BigInteger max = cur.max(beginS);
            BigInteger min = cur;
            if (endS != null)
                min = cur.min(endS);
            if (cur.equals(beginS) || cur.equals(endS) || 
              (cur.equals(max) && cur.equals(min)))
                deleteCertificateRecord(cur);
        }
    }

    public void setConsistencyCheck(boolean ConsistencyCheck) {
        mConsistencyCheck = ConsistencyCheck;
    }

    public void setSkipIfInConsistent(boolean SkipIfInconsistent) {
        mSkipIfInconsistent = SkipIfInconsistent;
    }

    public void setTransitMaxRecords(int max) {
        mTransitMaxRecords = max;
    }

    public void setTransitRecordPageSize(int size) {
        mTransitRecordPageSize = size;

    }

    /**
     * register CRL Issuing Point
     */
    public void addCRLIssuingPoint(String id, ICRLIssuingPoint crlIssuingPoint) {
        mCRLIssuingPoints.put(id, crlIssuingPoint);
    }

    /**
     * interval value: (in seconds)
     *   0 - disable
     *   >0 - enable
     */
    public CertStatusUpdateThread mCertStatusUpdateThread = null;
    public RetrieveModificationsThread mRetrieveModificationsThread = null;

    public void setCertStatusUpdateInterval(IRepository requestRepo, int interval, boolean listenToCloneModifications) {
        CMS.debug("In setCertStatusUpdateInterval " + interval);
        if (interval == 0) {
            CMS.debug("In setCertStatusUpdateInterval interval = 0" + interval);
            if (mCertStatusUpdateThread != null) {
                mCertStatusUpdateThread.stop();
            }
            if (mRetrieveModificationsThread != null) {
                mRetrieveModificationsThread.stop();
            }
            return;
        }

        CMS.debug("In setCertStatusUpdateInterval  listenToCloneModifications="+listenToCloneModifications+
                  "  mRetrieveModificationsThread="+mRetrieveModificationsThread);
        if (listenToCloneModifications && mRetrieveModificationsThread == null) {
            CMS.debug("In setCertStatusUpdateInterval about to create RetrieveModificationsThread");
            mRetrieveModificationsThread = new RetrieveModificationsThread(this, "RetrieveModificationsThread");
            LDAPSearchResults mResults = null;
            try {
                mResults = startSearchForModifiedCertificateRecords();
            } catch (Exception e) {
                mResults = null;
            }
            if (mResults != null) {
                mRetrieveModificationsThread.setResults(mResults);
                mRetrieveModificationsThread.start();
            }
        }

        CMS.debug("In setCertStatusUpdateInterval  mCertStatusUpdateThread " + mCertStatusUpdateThread);
        if (mCertStatusUpdateThread == null) {
            CMS.debug("In setCertStatusUpdateInterval about to create CertStatusUpdateThread ");
            mCertStatusUpdateThread = new CertStatusUpdateThread(this, requestRepo, "CertStatusUpdateThread");
            mCertStatusUpdateThread.setInterval(interval);
            mCertStatusUpdateThread.start();
        } else {
            CMS.debug("In setCertStatusUpdateInterval it thinks the thread is up already ");
            mCertStatusUpdateThread.setInterval(interval);
            // dont do anything if we have a thread running already
        }
    }


    /**
     * Blocking method.
     */
    public void updateCertStatus() throws EBaseException {

        CMS.debug("In updateCertStatus()");

        CMS.getLogger().log(ILogger.EV_SYSTEM, ILogger.S_OTHER, 
            CMS.getLogMessage("CMSCORE_DBS_START_VALID_SEARCH"));
        transitInvalidCertificates();
        CMS.getLogger().log(ILogger.EV_SYSTEM, ILogger.S_OTHER,
            CMS.getLogMessage("CMSCORE_DBS_FINISH_VALID_SEARCH"));
        CMS.getLogger().log(ILogger.EV_SYSTEM, ILogger.S_OTHER,
            CMS.getLogMessage("CMSCORE_DBS_START_EXPIRED_SEARCH"));
        transitValidCertificates();
        CMS.getLogger().log(ILogger.EV_SYSTEM, ILogger.S_OTHER,
            CMS.getLogMessage("CMSCORE_DBS_FINISH_EXPIRED_SEARCH"));
        CMS.getLogger().log(ILogger.EV_SYSTEM, ILogger.S_OTHER,
            CMS.getLogMessage("CMSCORE_DBS_START_REVOKED_EXPIRED_SEARCH"));
        transitRevokedExpiredCertificates();
        CMS.getLogger().log(ILogger.EV_SYSTEM, ILogger.S_OTHER,
            CMS.getLogMessage("CMSCORE_DBS_FINISH_REVOKED_EXPIRED_SEARCH"));
    }

    /**
     * Retrieves DN of this repository.
     */
    public String getDN() {
        return mBaseDN;
    }

    public void setRequestDN( String requestDN )  {
        mRequestBaseDN = requestDN;
    }

    public String getRequestDN()  {
        return mRequestBaseDN;
    }
    /**
     * Retrieves backend database handle.
     */
    public IDBSubsystem getDBSubsystem() {
        return mDBService;
    }

    /**
     * Adds a certificate record to the repository. Each certificate
     * record contains four parts: certificate, meta-attributes,
     * issue information and reovcation information.
     * <P>
     *
     * @param cert X.509 certificate
     * @exception EBaseException failed to add new certificate to
     * 		the repository
     */
    public void addCertificateRecord(ICertRecord record)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();

        try {
            String name = "cn" + "=" +
                ((CertRecord) record).getSerialNumber().toString() + "," + getDN();
            SessionContext ctx = SessionContext.getContext();
            String uid = (String) ctx.get(SessionContext.USER_ID);

            if (uid == null) {
                // XXX is this right?
                record.set(CertRecord.ATTR_ISSUED_BY, "system");

                /**
                 System.out.println("XXX servlet should set USER_ID");
                 throw new EBaseException(BaseResources.UNKNOWN_PRINCIPAL_1, 
                 "null");
                 **/
            } else {
                record.set(CertRecord.ATTR_ISSUED_BY, uid);
            }

            // Check validity of this certificate. If it is not invalid, 
            // mark it so. We will have a thread to transit the status
            // from INVALID to VALID.
            X509CertImpl x509cert = (X509CertImpl) record.get(
                    CertRecord.ATTR_X509CERT);

            if (x509cert != null) {
                Date now = CMS.getCurrentDate();

                if (x509cert.getNotBefore().after(now)) {
                    // not yet valid
                    record.set(ICertRecord.ATTR_CERT_STATUS, 
                        ICertRecord.STATUS_INVALID);
                }
            }
			
            s.add(name, record);
        } finally {
            if (s != null)
                s.close();
        }
    }

    /**
     * Used by the Clone Master (CLA) to add a revoked certificate
     * record to the repository.
     * <p>
     *
     * @param record a CertRecord
     * @exception EBaseException failed to add new certificate to
     * 		the repository
     */
    public void addRevokedCertRecord(CertRecord record)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();

        try {
            String name = "cn" + "=" +
                record.getSerialNumber().toString() + "," + getDN();

            s.add(name, record);
        } finally {
            if (s != null)
                s.close();
        }
    }

    /**
     * This transits a certificate status from VALID to EXPIRED
     * if a certificate becomes expired.
     */
    public void transitValidCertificates() throws EBaseException {

        Date now = CMS.getCurrentDate();
        ICertRecordList recList = getValidCertsByNotAfterDate(now, -1 * mTransitRecordPageSize);

        int size = recList.getSize();

        if (size <= 0) {
            CMS.debug("index may be empty");
            return;
        }
        int ltSize = recList.getSizeBeforeJumpTo();

        ltSize = Math.min(ltSize, mTransitMaxRecords);

        Vector cList = new Vector(ltSize);

        CMS.debug("transidValidCertificates: list size: " + size);
        CMS.debug("transitValidCertificates: ltSize " + ltSize);

        CertRecord curRec = null;

        int i;
        Object obj = null;

        for (i = 0; i < ltSize; i++) {
            obj = recList.getCertRecord(i);

            if (obj != null) {     
                curRec = (CertRecord) obj;

                Date notAfter = curRec.getNotAfter();

                //CMS.debug("notAfter " + notAfter.toString() + " now " + now.toString());
                if (notAfter.after(now)) {
                    CMS.debug("Record does not qualify,notAfter " + notAfter.toString() + " date " + now.toString());
                    continue;
                }

                CMS.debug("transitValid: curRec: " + i + " " + curRec.toString());

                if (mConsistencyCheck) {
                    cList.add(curRec);
                } else {
                    cList.add(curRec.getSerialNumber());
                }
            } else {
                CMS.debug("found null from getCertRecord");
            }
        }

        CertRecord cRec = null;
        BigInteger serial = null;

        transitCertList(cList, CertRecord.STATUS_EXPIRED);
    }

    /**
     * This transits a certificate status from REVOKED to REVOKED_EXPIRED
     * if an revoked certificate becomes expired.
     */
    public void transitRevokedExpiredCertificates() throws EBaseException {
        Date now = CMS.getCurrentDate();
        ICertRecordList recList = getRevokedCertsByNotAfterDate(now, -1 * mTransitRecordPageSize);
   
        int size = recList.getSize();

        if (size <= 0) {
            CMS.debug("index may be empty");
            return;
        }

        int ltSize = recList.getSizeBeforeJumpTo();
        Vector cList = new Vector(ltSize);

        ltSize = Math.min(ltSize, mTransitMaxRecords);

        CMS.debug("transitRevokedExpiredCertificates: list size: " + size);
        CMS.debug("transitRevokedExpiredCertificates: ltSize " + ltSize);

        CertRecord curRec = null;
        int i;
        Object obj = null;

        for (i = 0; i < ltSize; i++) {
            obj = recList.getCertRecord(i);
            if (obj != null) {
                curRec = (CertRecord) obj;
                CMS.debug("transitRevokedExpired: curRec: " + i + " " + curRec.toString());

                Date notAfter = curRec.getNotAfter();

                // CMS.debug("notAfter " + notAfter.toString() + " now " + now.toString());
                if (notAfter.after(now)) {
                    CMS.debug("Record does not qualify,notAfter " + notAfter.toString() + " date " + now.toString());
                    continue;
                }

                if (mConsistencyCheck) {
                    cList.add(curRec);
                } else {
                    cList.add(curRec.getSerialNumber());
                }
            }  else {
                CMS.debug("found null record in getCertRecord");
            }
        }

        transitCertList(cList, CertRecord.STATUS_REVOKED_EXPIRED);

    }

    /**
     * This transits a certificate status from INVALID to VALID
     * if a certificate becomes valid.
     */
    public void transitInvalidCertificates() throws EBaseException {

        Date now = CMS.getCurrentDate();

        ICertRecordList recList = getInvalidCertsByNotBeforeDate(now, -1 * mTransitRecordPageSize);

        int size = recList.getSize();

        if (size <= 0) {
            CMS.debug("index may be empty");
            return;
        }
        int ltSize = recList.getSizeBeforeJumpTo();

        ltSize = Math.min(ltSize, mTransitMaxRecords);

        Vector cList = new Vector(ltSize);

        CMS.debug("transidInValidCertificates: list size: " + size);
        CMS.debug("transitInValidCertificates: ltSize " + ltSize);

        CertRecord curRec = null;

        int i;

        Object obj = null;

        for (i = 0; i < ltSize; i++) {
            obj = recList.getCertRecord(i);

            if (obj != null) {
                curRec = (CertRecord) obj;

                Date notBefore = curRec.getNotBefore();

                //CMS.debug("notBefore " + notBefore.toString() + " now " + now.toString());
                if (notBefore.after(now)) {
                    CMS.debug("Record does not qualify,notBefore " + notBefore.toString() + " date " + now.toString());
                    continue;

                }
                CMS.debug("transitInValid: curRec: " + i + " " + curRec.toString());

                if (mConsistencyCheck) {
                    cList.add(curRec);
                } else {
                    cList.add(curRec.getSerialNumber());
                }

            } else {
                CMS.debug("found null from getCertRecord");
            }
        }

        transitCertList(cList, CertRecord.STATUS_VALID);

    }

    private void transitCertList(Vector cList, String newCertStatus) throws EBaseException {
        CertRecord cRec = null;
        BigInteger serial = null;

        int i;

        CMS.debug("transitCertList " + newCertStatus);

        for (i = 0; i < cList.size(); i++) {
            if (mConsistencyCheck) {
                cRec = (CertRecord) cList.elementAt(i);

                if (cRec == null)
                    continue;

                serial = cRec.getSerialNumber();
            } else {
                serial = (BigInteger) cList.elementAt(i);
            }

            updateStatus(serial, newCertStatus);

            if (newCertStatus.equals(CertRecord.STATUS_REVOKED_EXPIRED)) {
                
                // inform all CRLIssuingPoints about revoked and expired certificate

                Enumeration eIPs = mCRLIssuingPoints.elements();

                while (eIPs.hasMoreElements()) {
                    ICRLIssuingPoint ip = (ICRLIssuingPoint) eIPs.nextElement();

                    if (ip != null) {
                        ip.addExpiredCert(serial);
                    }
                }

            }

            CMS.debug("transitCertList number at: " + i + " = " + serial);
        }

        cList.removeAllElements();
    }

    /**
     * Reads the certificate identified by the given serial no.
     */
    public X509CertImpl getX509Certificate(BigInteger serialNo)
        throws EBaseException {
        X509CertImpl cert = null;
        ICertRecord cr = readCertificateRecord(serialNo);

        return (cr.getCertificate());
    }

    /**
     * Deletes certificate record.
     */
    public void deleteCertificateRecord(BigInteger serialNo)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();

        try {
            String name = "cn" + "=" +
                serialNo.toString() + "," + getDN();

            s.delete(name);
        } finally {
            if (s != null) 
                s.close();
        }
    }

    /**
     * Reads certificate from repository.
     */
    public ICertRecord readCertificateRecord(BigInteger serialNo)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        CertRecord rec = null;

        try {
            String name = "cn" + "=" +
                serialNo.toString() + "," + getDN();

            rec = (CertRecord) s.read(name);
        } finally {
            if (s != null) 
                s.close();
        }
        return rec;
    }

    public synchronized void modifyCertificateRecord(BigInteger serialNo,
        ModificationSet mods) throws EBaseException {
        IDBSSession s = mDBService.createSession();

        try {
            String name = "cn" + "=" +
                serialNo.toString() + "," + getDN();

            mods.add(CertRecord.ATTR_MODIFY_TIME, Modification.MOD_REPLACE,
                CMS.getCurrentDate());
            s.modify(name, mods);
        } finally {
            if (s != null) 
                s.close();
        }
    }

    /**
     * Checks if the specified certificate is in the repository.
     */
    public boolean containsCertificate(BigInteger serialNo)
        throws EBaseException {
        try {
            ICertRecord cr = readCertificateRecord(serialNo);

            if (cr != null)
                return true;
        } catch (EBaseException e) {
        }
        return false;
    }

    /**
     * Marks certificate as revoked.
     */
    public void markAsRevoked(BigInteger id, IRevocationInfo info)
        throws EBaseException {
        ModificationSet mods = new ModificationSet();

        mods.add(CertRecord.ATTR_REVO_INFO, Modification.MOD_ADD, info);
        SessionContext ctx = SessionContext.getContext();
        String uid = (String) ctx.get(SessionContext.USER_ID);

        if (uid == null) {
            mods.add(CertRecord.ATTR_REVOKED_BY, Modification.MOD_ADD,
                "system");
        } else {
            mods.add(CertRecord.ATTR_REVOKED_BY, Modification.MOD_ADD,
                uid);
        }
        mods.add(CertRecord.ATTR_REVOKED_ON, Modification.MOD_ADD,
            CMS.getCurrentDate());
        mods.add(CertRecord.ATTR_CERT_STATUS, Modification.MOD_REPLACE,
            CertRecord.STATUS_REVOKED);
        modifyCertificateRecord(id, mods);
    }

    /**
     * Unmarks revoked certificate.
     */
    public void unmarkRevoked(BigInteger id, IRevocationInfo info,
        Date revokedOn, String revokedBy)
        throws EBaseException {
        ModificationSet mods = new ModificationSet();

        mods.add(CertRecord.ATTR_REVO_INFO, Modification.MOD_DELETE, info);
        mods.add(CertRecord.ATTR_REVOKED_BY, Modification.MOD_DELETE, revokedBy);
        mods.add(CertRecord.ATTR_REVOKED_ON, Modification.MOD_DELETE, revokedOn);
        mods.add(CertRecord.ATTR_CERT_STATUS, Modification.MOD_REPLACE,
            CertRecord.STATUS_VALID);
        modifyCertificateRecord(id, mods);
    }

    /**
     * Updates the certificiate record status to the specified.
     */
    public void updateStatus(BigInteger id, String status)
        throws EBaseException {
        CMS.debug("updateStatus: " + id + " status " + status);
        ModificationSet mods = new ModificationSet();

        mods.add(CertRecord.ATTR_CERT_STATUS, Modification.MOD_REPLACE,
            status);
        modifyCertificateRecord(id, mods);
    }

    public Enumeration searchCertificates(String filter, int maxSize)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        CMS.debug("searchCertificates filter " + filter + " maxSize " + maxSize);
        try {
            e = s.search(getDN(), filter, maxSize);
        } finally {
            if (s != null) 
                s.close();
        }
        return e;
    }

    public Enumeration searchCertificates(String filter, int maxSize, int timeLimit)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        CMS.debug("searchCertificateswith time limit filter " + filter);
        try {
            e = s.search(getDN(), filter, maxSize, timeLimit);
        } finally {
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Returns a list of X509CertImp that satisfies the filter.
     * @deprecated replaced by <code>findCertificatesInList</code>
     */
    public Enumeration findCertRecs(String filter)
        throws EBaseException {
        CMS.debug("findCertRecs " + filter);
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;
        try {
            e = s.search(getDN(), filter);
        } finally {
            if (s != null) s.close();
        }
        return e;
    }

    public Enumeration findCertRecs(String filter, String[] attrs)
        throws EBaseException {

        CMS.debug( "findCertRecs " + filter
                 + "attrs " + Arrays.toString( attrs ) );
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;
        try {
            e = s.search(getDN(), filter, attrs);
        } finally {
            if (s != null) s.close();
        }
        return e;

    }

    public Enumeration findCertificates(String filter)
        throws EBaseException {
        Enumeration e = findCertRecords(filter);
        Vector v = new Vector();

        while (e.hasMoreElements()) {
            CertRecord rec = (CertRecord) e.nextElement();

            v.addElement(rec.getCertificate());
        }
        return v.elements();
    }

    /**
     * Finds a list of certificate records that satisifies
     * the filter.
     * If you are going to process everything in the list,
     * use this.
     */
    public Enumeration findCertRecords(String filter)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            //e = s.search(getDN(), filter);
            ICertRecordList list = null;

            list = findCertRecordsInList(filter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally {
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Finds certificate records. Here is a list of filter
     * attribute can be used:
     * <pre>
     *   certRecordId
     *   certMetaInfo
     *   certStatus
     *   certCreateTime
     *   certModifyTime
     *   x509Cert.notBefore
     *   x509Cert.notAfter
     *   x509Cert.subject
     * </pre>
     * The filter should follow RFC1558 LDAP filter syntax.
     * For example,
     * <pre>
     *   (&(certRecordId=5)(x509Cert.notBefore=934398398))
     * </pre>
     */
    public ICertRecordList findCertRecordsInList(String filter, 
        String attrs[], int pageSize) throws EBaseException {
        return findCertRecordsInList(filter, attrs, CertRecord.ATTR_ID, 
                pageSize);
    }

    public ICertRecordList findCertRecordsInList(String filter, 
        String attrs[], String sortKey, int pageSize) 
        throws EBaseException {
        IDBSSession s = mDBService.createSession();

        CMS.debug("In findCertRecordsInList");
        CertRecordList list = null;

        try {
            DBVirtualList vlist = (DBVirtualList) s.createVirtualList(getDN(), filter, attrs,
                    sortKey, pageSize);

            list = new CertRecordList(vlist);
        } finally {
            if (s != null) 
                s.close();
        }
        return list;
    }

    public ICertRecordList findCertRecordsInList(String filter, 
		 String attrs[], String jumpTo, String sortKey, int pageSize)
        throws EBaseException {
	return findCertRecordsInList(filter, attrs, jumpTo, false, sortKey, pageSize);

    }

    public ICertRecordList findCertRecordsInList(String filter, 
		 String attrs[], String jumpTo, boolean hardJumpTo,
						 String sortKey, int pageSize)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        CertRecordList list = null;

        CMS.debug("In findCertRecordsInList with Jumpto " + jumpTo);
        try {
            String jumpToVal = null;

	    if (hardJumpTo) {
        CMS.debug("In findCertRecordsInList with hardJumpto ");
		jumpToVal = "99";
	    } else {
            int len = jumpTo.length();

            if (len > 9) {
                jumpToVal = Integer.toString(len) + jumpTo;
            } else {
                jumpToVal = "0" + Integer.toString(len) + jumpTo;
            }
	    }

            DBVirtualList vlist = (DBVirtualList) s.createVirtualList(getDN(), filter, 
                    attrs, jumpToVal, sortKey, pageSize);

            list = new CertRecordList(vlist);
        } finally {
            if (s != null) 
                s.close();
        }
        return list;
    }

    public ICertRecordList findCertRecordsInListRawJumpto(String filter,
        String attrs[], String jumpTo, String sortKey, int pageSize)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        CertRecordList list = null;

        CMS.debug("In findCertRecordsInListRawJumpto with Jumpto " + jumpTo);

        try {

            DBVirtualList vlist = (DBVirtualList) s.createVirtualList(getDN(), filter,
                    attrs, jumpTo, sortKey, pageSize);

            list = new CertRecordList(vlist);
        } finally {
            if (s != null)
                s.close();
        }
        return list;
    }

    /**
     * Marks certificate as renewable.
     */
    public void markCertificateAsRenewable(ICertRecord record)
        throws EBaseException {
        changeRenewalAttribute(((CertRecord) record).getSerialNumber().toString(),
            CertRecord.AUTO_RENEWAL_ENABLED);
    }

    /**
     * Marks certificate as renewable.
     */
    public void markCertificateAsNotRenewable(ICertRecord record)
        throws EBaseException {
        changeRenewalAttribute(((CertRecord) record).getSerialNumber().toString(),
            CertRecord.AUTO_RENEWAL_DISABLED);
    }

    public void markCertificateAsRenewed(String serialNo)
        throws EBaseException {
        changeRenewalAttribute(serialNo, CertRecord.AUTO_RENEWAL_DONE);
    }

    public void markCertificateAsRenewalNotified(String serialNo)
        throws EBaseException {
        changeRenewalAttribute(serialNo, CertRecord.AUTO_RENEWAL_NOTIFIED);
    }

    private void changeRenewalAttribute(String serialno, String value)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();

        try {
            String name = "cn" + "=" + serialno +
                "," + getDN();
            ModificationSet mods = new ModificationSet();

            mods.add(CertRecord.ATTR_AUTO_RENEW, Modification.MOD_REPLACE,
                value);
            s.modify(name, mods);
        } finally {
            if (s != null) 
                s.close();
        }
    }

    /**
     * temp solution...
     */
    public class RenewableCertificateCollection {
        Vector mToRenew = null;
        Vector mToNotify = null;
        public RenewableCertificateCollection() {
        }

        public Vector getRenewable() {
            return mToRenew;
        }

        public Vector getNotifiable() {
            return mToNotify;
        }

        public void addCertificate(String renewalFlag, Object o) {
            if (renewalFlag.equals(CertRecord.AUTO_RENEWAL_ENABLED)) {
                if (mToRenew == null)
                    mToRenew = new Vector();
                mToRenew.addElement(o);
            }
            if (renewalFlag.equals(CertRecord.AUTO_RENEWAL_DISABLED)) {
                if (mToNotify == null)
                    mToNotify = new Vector();
                mToNotify.addElement(o);
            }
        }
    }

    public Hashtable getRenewableCertificates(String renewalTime)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();

        Hashtable tab = null;

        try {
            String filter = "(&(" + CertRecord.ATTR_CERT_STATUS + "=" +
                CertRecord.STATUS_VALID + ")("
                + CertRecord.ATTR_X509CERT +
                "." + CertificateValidity.NOT_AFTER + "<=" + renewalTime +
                ")(!(" + CertRecord.ATTR_AUTO_RENEW + "=" +
                CertRecord.AUTO_RENEWAL_DONE +
                "))(!(" + CertRecord.ATTR_AUTO_RENEW + "=" +
                CertRecord.AUTO_RENEWAL_NOTIFIED + ")))";
            //Enumeration e = s.search(getDN(), filter);
            ICertRecordList list = null;

            list = findCertRecordsInList(filter, null, "serialno", 10);
            int size = list.getSize();
            Enumeration e = list.getCertRecords(0, size - 1);

            tab = new Hashtable();
            while (e.hasMoreElements()) {
                CertRecord rec = (CertRecord) e.nextElement();
                X509CertImpl cert = rec.getCertificate();
                String subjectDN = cert.getSubjectDN().toString();
                String renewalFlag = rec.getAutoRenew();

                // See if the subjectDN is in the table
                Object val = null;

                if ((val = tab.get(subjectDN)) == null) {
                    RenewableCertificateCollection collection =
                        new RenewableCertificateCollection();

                    collection.addCertificate(renewalFlag, cert);
                    tab.put(subjectDN, collection);
                } else {
                    ((RenewableCertificateCollection) val).addCertificate(renewalFlag, cert);
                }
            }
        } finally {
            if (s != null) 
                s.close();
        }
        return tab;
    }

    /**
     * Gets all valid and unexpired certificates pertaining
     * to a subject DN.
     *
     * @param subjectDN	The distinguished name of the subject.
     * @param validityType	The type of certificates to get.
     * @return An array of certificates.
     */

    public X509CertImpl[] getX509Certificates(String subjectDN,
        int validityType) throws EBaseException {
        IDBSSession s = mDBService.createSession();

        X509CertImpl certs[] = null;

        try {
            // XXX - not checking validityType...
            String filter = "(&(" + CertRecord.ATTR_X509CERT +
                "." + X509CertInfo.SUBJECT + "=" + subjectDN;

            if (validityType == ALL_VALID_CERTS) {
                filter += ")(" +
                        CertRecord.ATTR_CERT_STATUS + "=" +
                        CertRecord.STATUS_VALID;
            }
            if (validityType == ALL_UNREVOKED_CERTS) {
                filter += ")(|(" +
                        CertRecord.ATTR_CERT_STATUS + "=" +
                        CertRecord.STATUS_VALID + ")(" +
                        CertRecord.ATTR_CERT_STATUS + "=" +
                        CertRecord.STATUS_EXPIRED + ")";
            }
            filter += "))";

            //Enumeration e = s.search(getDN(), filter);
            ICertRecordList list = null;

            list = findCertRecordsInList(filter, null, "serialno", 10);
            int size = list.getSize();
            Enumeration e = list.getCertRecords(0, size - 1);

            Vector v = new Vector();

            while (e.hasMoreElements()) {
                CertRecord rec = (CertRecord) e.nextElement();

                v.addElement(rec.getCertificate());
            }
            if (v.size() == 0)
                return null;
            certs = new X509CertImpl[v.size()];
            v.copyInto(certs);
        } finally {
            if (s != null) 
                s.close();
        }
        return certs;
    }

    public X509CertImpl[] getX509Certificates(String filter)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();

        X509CertImpl certs[] = null;

        try {
            Enumeration e = null;

            if (filter != null && filter.length() > 0) {
                //e = s.search(getDN(), filter);
                ICertRecordList list = null;

                list = findCertRecordsInList(filter, null, "serialno", 10);
                int size = list.getSize();

                e = list.getCertRecords(0, size - 1);
            }

            Vector v = new Vector();

            while (e != null && e.hasMoreElements()) {
                CertRecord rec = (CertRecord) e.nextElement();

                v.addElement(rec.getCertificate());
            }
            if (v.size() > 0) {
                certs = new X509CertImpl[v.size()];
                v.copyInto(certs);
            }
        } finally {
            if (s != null) 
                s.close();
        }
        return certs;
    }

    /**
     * Retrives all valid certificates excluding ones already revoked.
     * @param from	The starting point of the serial number range.
     * @param to	The ending point of the serial number range.
     */
    public Enumeration getValidCertificates(String from, String to)
		throws EBaseException {
			IDBSSession s = mDBService.createSession();
			Vector v = new Vector();

			try {

				// 'from' determines 'jumpto' value
				// 'to' determines where to stop looking

				String ldapfilter = "(certstatus=VALID)";

                String fromVal = "0";
                try {
                    if (from != null) {
                      int fv = Integer.parseInt(from);
                      fromVal = from;
                    }
                } catch (Exception e1) {
                   // from is not integer
                }

				ICertRecordList list = 
					findCertRecordsInList(ldapfilter, null, fromVal, "serialno", 40);

				BigInteger toInt = null;
                if (to != null && !to.trim().equals("")) {
                  toInt = new BigInteger(to);
                }

				for (int i=0;; i++) {
					CertRecord rec = (CertRecord) list.getCertRecord(i);
					CMS.debug("processing record: "+i);
					if (rec == null) {
                         break; // no element returned
                    } else {

					     CMS.debug("processing record: "+i+" "+rec.getSerialNumber());
						// Check if we are past the 'to' marker
                        if (toInt != null) {
						  if (rec.getSerialNumber().compareTo(toInt) > 0) {
							break;
						  }
                        }
						v.addElement(rec);
					}
				}

			} finally {
				if (s != null) 
					s.close();
			}
			CMS.debug("returning "+v.size()+" elements");
			return v.elements();
		}

    /**
     * Retrives all valid certificates excluding ones already revoked.
     */
    public Enumeration getAllValidCertificates()
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            Date now = CMS.getCurrentDate();
            String ldapfilter = "(&(!(" + CertRecord.ATTR_REVO_INFO + "=*))(" +
                CertRecord.ATTR_X509CERT + "." +
                CertificateValidity.NOT_BEFORE + "<=" +
                DateMapper.dateToDB(now) + ")(" +
                CertRecord.ATTR_X509CERT + "." +
                CertificateValidity.NOT_AFTER + ">=" +
                DateMapper.dateToDB(now) + "))";
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
								 
        } finally {
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all valid not published certificates 
     * excluding ones already revoked.
     * @param from	The starting point of the serial number range.
     * @param to	The ending point of the serial number range.
     */
    public Enumeration getValidNotPublishedCertificates(String from, String to)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            Date now = CMS.getCurrentDate();
            String ldapfilter = "(&(";

            if (from != null && from.length() > 0)
                ldapfilter += CertRecord.ATTR_ID + ">=" + from + ")(";
            if (to != null && to.length() > 0)
                ldapfilter += CertRecord.ATTR_ID + "<=" + to + ")(";
            ldapfilter += "!(" + CertRecord.ATTR_REVO_INFO + "=*))(" +
                    CertRecord.ATTR_X509CERT + "." +
                    CertificateValidity.NOT_BEFORE + "<=" +
                    DateMapper.dateToDB(now) + ")(" +
                    CertRecord.ATTR_X509CERT + "." +
                    CertificateValidity.NOT_AFTER + ">=" +
                    DateMapper.dateToDB(now) + ")(!(" +
                    "certMetainfo=" +
                    CertRecord.META_LDAPPUBLISH +
                    ":true)))";
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
								 
        } finally {
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all valid not published certificates 
     * excluding ones already revoked.
     */
    public Enumeration getAllValidNotPublishedCertificates()
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            Date now = CMS.getCurrentDate();
            String ldapfilter = "(&(!(" + CertRecord.ATTR_REVO_INFO + "=*))(" +
                CertRecord.ATTR_X509CERT + "." +
                CertificateValidity.NOT_BEFORE + "<=" +
                DateMapper.dateToDB(now) + ")(" +
                CertRecord.ATTR_X509CERT + "." +
                CertificateValidity.NOT_AFTER + ">=" +
                DateMapper.dateToDB(now) + ")(!(" +
                "certMetainfo=" +
                CertRecord.META_LDAPPUBLISH +
                ":true)))";
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
								 
        } finally {
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all expired certificates.
     * @param from	The starting point of the serial number range.
     * @param to	The ending point of the serial number range.
     */
    public Enumeration getExpiredCertificates(String from, String to)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            Date now = CMS.getCurrentDate();
            String ldapfilter = "(&(";

            if (from != null && from.length() > 0)
                ldapfilter += CertRecord.ATTR_ID + ">=" + from + ")(";
            if (to != null && to.length() > 0)
                ldapfilter += CertRecord.ATTR_ID + "<=" + to + ")(";
            ldapfilter += "!(" + CertRecord.ATTR_X509CERT + "." +
                    CertificateValidity.NOT_AFTER + ">=" +
                    DateMapper.dateToDB(now) + ")))";
            //e = s.search(getDN(), ldapfilter);
								 
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally { 
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all expired certificates.
     */
    public Enumeration getAllExpiredCertificates()
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            Date now = CMS.getCurrentDate();
            String ldapfilter = "(!(" + CertRecord.ATTR_X509CERT + "." +
                CertificateValidity.NOT_AFTER + ">=" +
                DateMapper.dateToDB(now) + "))";
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
								 
        } finally { 
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all expired published certificates.
     * @param from	The starting point of the serial number range.
     * @param to	The ending point of the serial number range.
     */
    public Enumeration getExpiredPublishedCertificates(String from, String to)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            Date now = CMS.getCurrentDate();
            String ldapfilter = "(&(";

            if (from != null && from.length() > 0)
                ldapfilter += CertRecord.ATTR_ID + ">=" + from + ")(";
            if (to != null && to.length() > 0)
                ldapfilter += CertRecord.ATTR_ID + "<=" + to + ")(";
            ldapfilter += "!(" + CertRecord.ATTR_X509CERT + "." +
                    CertificateValidity.NOT_AFTER + ">=" +
                    //DateMapper.dateToDB(now) + ")))";
                    DateMapper.dateToDB(now) + "))(" +
                    "certMetainfo=" +
                    CertRecord.META_LDAPPUBLISH +
                    ":true))";
            //e = s.search(getDN(), ldapfilter);
								 
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally { 
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all expired publishedcertificates.
     */
    public Enumeration getAllExpiredPublishedCertificates()
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            Date now = CMS.getCurrentDate();
            String ldapfilter = "(&";

            ldapfilter += "(!(" + CertRecord.ATTR_X509CERT + "." +
                    CertificateValidity.NOT_AFTER + ">=" +
                    DateMapper.dateToDB(now) + "))";
            ldapfilter += "(certMetainfo=" +
                    CertRecord.META_LDAPPUBLISH +
                    ":true))";
		
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
								 
        } finally { 
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    public ICertRecordList getInvalidCertsByNotBeforeDate(Date date, int pageSize)
        throws EBaseException {

        String now = null;

        Date rightNow = CMS.getCurrentDate();

        ICertRecordList list = null;
        IDBSSession s = mDBService.createSession();

        try {
            String ldapfilter = "(" + CertRecord.ATTR_CERT_STATUS + "=" + CertRecord.STATUS_INVALID + ")";

            String[] attrs = null;

            if (mConsistencyCheck == false) {
                attrs = new String[] { "objectclass", CertRecord.ATTR_ID, CertRecord.ATTR_X509CERT};
            }

            CMS.debug("getInvalidCertificatesByNotBeforeDate filter " + ldapfilter);
            //e = s.search(getDN(), ldapfilter);
            CMS.debug("getInvalidCertificatesByNotBeforeDate: about to call findCertRecordsInList");

            list = findCertRecordsInListRawJumpto(ldapfilter, attrs,
                        DateMapper.dateToDB(date), "notBefore", pageSize);

            //e = list.getCertRecords(0, size - 1);

        } finally {
            // XXX - transaction is not done at this moment


            CMS.debug("In getInvalidCertsByNotBeforeDate finally.");

            if (s != null)
                s.close();
        }
        return list;

    }

    public ICertRecordList getValidCertsByNotAfterDate(Date date, int pageSize)
        throws EBaseException {

        String now = null;

        ICertRecordList list = null;
        IDBSSession s = mDBService.createSession();

        try {
            String ldapfilter = "(" + CertRecord.ATTR_CERT_STATUS + "=" + CertRecord.STATUS_VALID + ")";

            String[] attrs = null;

            if (mConsistencyCheck == false) {
                attrs = new String[] { "objectclass", CertRecord.ATTR_ID, CertRecord.ATTR_X509CERT};
            }

            CMS.debug("getValidCertsByNotAfterDate filter " + ldapfilter);
            //e = s.search(getDN(), ldapfilter);
            list = findCertRecordsInListRawJumpto(ldapfilter, attrs, DateMapper.dateToDB(date), "notAfter", pageSize);

        } finally {
            // XXX - transaction is not done at this moment

            if (s != null)
                s.close();
        }
        return list;
    }

    public ICertRecordList getRevokedCertsByNotAfterDate(Date date, int pageSize)
        throws EBaseException {

        ICertRecordList list = null;
        IDBSSession s = mDBService.createSession();

        try {
            String ldapfilter = "(" + CertRecord.ATTR_CERT_STATUS + "=" + CertRecord.STATUS_REVOKED + ")";

            String[] attrs = null;

            if (mConsistencyCheck == false) {
                attrs = new String[] { "objectclass", CertRecord.ATTR_REVOKED_ON, CertRecord.ATTR_ID,
                            CertRecord.ATTR_REVO_INFO, CertificateValidity.NOT_AFTER, CertRecord.ATTR_X509CERT};
            }

            CMS.debug("getRevokedCertificatesByNotAfterDate filter " + ldapfilter);
            //e = s.search(getDN(), ldapfilter);
            CMS.debug("getRevokedCertificatesByNotAfterDate: about to call findCertRecordsInList");

            list = findCertRecordsInListRawJumpto(ldapfilter, attrs,
                        DateMapper.dateToDB(date), "notafter", pageSize);

        } finally {
            // XXX - transaction is not done at this moment


            if (s != null)
                s.close();
        }
        return list;

    }
    
    /**
     * Retrieves all revoked certificates in the serial number range. 
     * @param from	The starting point of the serial number range.
     * @param to	The ending point of the serial number range.
     */
    public Enumeration getRevokedCertificates(String from, String to)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            String ldapfilter = "(&(" + CertRecord.ATTR_REVO_INFO + "=*)";

            if (from != null && from.length() > 0)
                ldapfilter += "(" + CertRecord.ATTR_ID + ">=" + from + ")";
            if (to != null && to.length() > 0)
                ldapfilter += "(" + CertRecord.ATTR_ID + "<=" + to + ")";
            ldapfilter += ")";
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally {
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all revoked certificates including ones already expired or 
     * not yet valid.
     */
    public Enumeration getAllRevokedCertificates()
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;
        String ldapfilter = "(|(" + CertRecord.ATTR_CERT_STATUS + "=" + CertRecord.STATUS_REVOKED + ")(" + CertRecord.ATTR_CERT_STATUS + "=" + CertRecord.STATUS_REVOKED_EXPIRED + "))"; // index is setup for this filter

        try {
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally {
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrieves all revoked publishedcertificates in the serial number range. 
     * @param from	The starting point of the serial number range.
     * @param to	The ending point of the serial number range.
     */
    public Enumeration getRevokedPublishedCertificates(String from, String to)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {
            String ldapfilter = "(&(" + CertRecord.ATTR_REVO_INFO + "=*)";

            if (from != null && from.length() > 0)
                ldapfilter += "(" + CertRecord.ATTR_ID + ">=" + from + ")";
            if (to != null && to.length() > 0)
                ldapfilter += "(" + CertRecord.ATTR_ID + "<=" + to + ")";
                //ldapfilter += ")";
            ldapfilter += "(certMetainfo=" +
                    CertRecord.META_LDAPPUBLISH +
                    ":true))";
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally {
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all revoked published certificates including ones 
     * already expired or not yet valid.
     */
    public Enumeration getAllRevokedPublishedCertificates()
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;
        String ldapfilter = "(&(|(" + CertRecord.ATTR_CERT_STATUS + "=" + CertRecord.STATUS_REVOKED + ")(" + CertRecord.ATTR_CERT_STATUS + "=" + CertRecord.STATUS_REVOKED_EXPIRED + "))"; // index is setup for this filter

        ldapfilter += "(certMetainfo=" +
                CertRecord.META_LDAPPUBLISH +
                ":true))";
        try {
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally {
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrieves all revoked certificates that have not expired. 
     */
    public Enumeration getRevokedCertificates(Date asOfDate)
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;

        try {

            /*e = s.search(getDN(), "(&(" +
             CertRecord.ATTR_REVO_INFO + "=*)(" + CertRecord.ATTR_X509CERT +
             "." +  CertificateValidity.NOT_AFTER + " >= " +
             DateMapper.dateToDB(asOfDate) + "))");*/
            String ldapfilter = "(&(" +
                CertRecord.ATTR_REVO_INFO + "=*)(" + CertRecord.ATTR_X509CERT +
                "." + CertificateValidity.NOT_AFTER + " >= " +
                DateMapper.dateToDB(asOfDate) + "))";
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally {
            // XXX - transaction is not done at this moment
            if (s != null) 
                s.close();
        }
        return e;
    }

    /**
     * Retrives all revoked certificates excluing ones already expired.
     */
    public Enumeration getAllRevokedNonExpiredCertificates()
        throws EBaseException {
        IDBSSession s = mDBService.createSession();
        Enumeration e = null;
        String ldapfilter = "(" + CertRecord.ATTR_CERT_STATUS + "=" + CertRecord.STATUS_REVOKED + ")"; // index is setup for this filter

        try {
            //e = s.search(getDN(), ldapfilter);
            ICertRecordList list = null;

            list = findCertRecordsInList(ldapfilter, null, "serialno", 10);
            int size = list.getSize();

            e = list.getCertRecords(0, size - 1);
        } finally {
            if (s != null) 
                s.close();
        }
        return e;
    }

    private LDAPSearchResults startSearchForModifiedCertificateRecords()
        throws EBaseException {
        CMS.debug("startSearchForModifiedCertificateRecords");
        LDAPSearchResults r = null;
        IDBSSession s = mDBService.createSession();

        String filter = "(" + CertRecord.ATTR_CERT_STATUS + "=*)";
        try {
            r = s.persistentSearch(getDN(), filter, null);
            CMS.debug("startSearchForModifiedCertificateRecords  persistentSearch started");
        } catch (Exception e) {
            CMS.debug("startSearchForModifiedCertificateRecords  persistentSearch Exception="+e);
            r = null;
            if (s != null) 
                s.close();
        }
        return r;
    }

    public void getModifications(LDAPEntry entry) {
        if (entry != null) {
            CMS.debug("getModifications  entry DN="+entry.getDN());

            LDAPAttributeSet entryAttrs = entry.getAttributeSet();
            ICertRecord certRec = null;
            try {
                certRec = (ICertRecord)mDBService.getRegistry().createObject(entryAttrs);
            } catch (Exception e) {
            }
            if (certRec != null) {
                String status = certRec.getStatus();
                CMS.debug("getModifications  serialNumber="+certRec.getSerialNumber()+
                          "  status="+status);
                if (status != null && (status.equals(ICertRecord.STATUS_VALID) ||
                    status.equals(ICertRecord.STATUS_REVOKED))) {

                    Enumeration eIPs = mCRLIssuingPoints.elements();

                    while (eIPs.hasMoreElements()) {
                        ICRLIssuingPoint ip = (ICRLIssuingPoint) eIPs.nextElement();

                        if (ip != null) {
                            if (status.equals(ICertRecord.STATUS_REVOKED)) {
                                IRevocationInfo rInfo = certRec.getRevocationInfo();
                                if (rInfo != null) {
                                    ip.addRevokedCert(certRec.getSerialNumber(),
                                        new RevokedCertImpl(certRec.getSerialNumber(),
                                                            rInfo.getRevocationDate(),
                                                            rInfo.getCRLEntryExtensions()));
                                }
                            } else {
                                ip.addUnrevokedCert(certRec.getSerialNumber());
                            }
                        }
                    }

                }
            }
        } else {
            CMS.debug("getModifications  entry == null");
        }
    }


    /**
     * Checks if the presented certificate belongs to the repository
     * and is revoked.
     *
     * @param cert	certificate to verify.
     * @return RevocationInfo if the presented certificate is revoked otherwise null.
     */
    public RevocationInfo isCertificateRevoked(X509CertImpl cert)
        throws EBaseException {
        RevocationInfo info = null;

        // 615932
        if (cert == null)
            return null;

        ICertRecord rec = readCertificateRecord(cert.getSerialNumber());

        if (rec != null) {
            if (rec.getStatus().equals(ICertRecord.STATUS_REVOKED)) {
                X500Name name = (X500Name) cert.getSubjectDN();
                X500Name repCertName = (X500Name) rec.getCertificate().getSubjectDN();

                if (name.equals(repCertName)) {
                    byte[] certEncoded = null;
                    byte[] repCertEncoded = null;

                    try {
                        certEncoded = cert.getEncoded();
                        repCertEncoded = rec.getCertificate().getEncoded();
                    } catch (Exception e) {
                    }

                    if (certEncoded != null &&
                        repCertEncoded != null &&
                        certEncoded.length == repCertEncoded.length) {
                        int i;

                        for (i = 0; i < certEncoded.length; i++) {
                            if (certEncoded[i] != repCertEncoded[i])
                                break;
                        }
                        if (i >= certEncoded.length) {
                            info = (RevocationInfo) ((CertRecord) rec).getRevocationInfo();
                        }
                    }
                }
            }
        }

        return info;
    }

    public void shutdown() {
        //if (mCertStatusUpdateThread != null) 
        //        mCertStatusUpdateThread.destroy();

        //if (mRetrieveModificationsThread != null) 
        //        mRetrieveModificationsThread.destroy();
    }
}


class CertStatusUpdateThread extends Thread {
    CertificateRepository _cr = null;
    IRepository _rr = null;
    int _interval;

    CertStatusUpdateThread(CertificateRepository cr, IRepository rr, String name) {
        super(name);
        CMS.debug("new CertStatusUpdateThread");
        //setName(name);

        _cr = cr;
        _rr = rr;
    }

    public void setInterval(int interval) {
        _interval = interval;
    }

    public void run() {
        CMS.debug("Inside run method of CertStatusUpdateThread");

        while (true) {
            try {
                // block the update while another thread
                // (such as the CRL Update) is running
                CMS.debug("About to start updateCertStatus");
                synchronized (_cr.mCertStatusUpdateThread) {
                    CMS.debug("Starting updateCertStatus (entered lock)");
                    _cr.updateCertStatus();
                    CMS.debug("updateCertStatus done");

                    CMS.debug("Starting cert checkRanges");
                    _cr.checkRanges();
                    CMS.debug("cert checkRanges done");

                    CMS.debug("Starting request checkRanges");
                    _rr.checkRanges();
                    CMS.debug("request checkRanges done");
                }

            } catch (Exception e) {
                CMS.debug("updateCertStatus done: " + e.toString());
            }
            try {
                sleep(_interval * 1000);
            } catch (InterruptedException e) {
            }
        }
    }
}


class RetrieveModificationsThread extends Thread {
    CertificateRepository _cr = null;
    LDAPSearchResults _results = null;

    RetrieveModificationsThread(CertificateRepository cr, String name) {
        super(name);
        CMS.debug("new RetrieveModificationsThread");
        //setName(name);

        _cr = cr;
    }

    public void setResults(LDAPSearchResults results) {
        _results = results;
    }

    public void run() {
        CMS.debug("Inside run method of RetrieveModificationsThread");

        if (_results != null) {
            try {
                while (_results.hasMoreElements()) {
                    LDAPEntry entry = _results.next();
                    _cr.getModifications(entry);
                }
            } catch (LDAPException e) {
                CMS.debug("LDAPException: "+e.toString());
            }
        } else {
            CMS.debug("_results are null");
        }
        CMS.debug("Done with run method of RetrieveModificationsThread");
    }
}