From 621d9e5c413e561293d7484b93882d985b3fe15f Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Sat, 24 Mar 2012 02:27:47 -0500 Subject: Removed unnecessary pki folder. Previously the source code was located inside a pki folder. This folder was created during svn migration and is no longer needed. This folder has now been removed and the contents have been moved up one level. Ticket #131 --- base/deploy/CMakeLists.txt | 137 +++++++++++ base/deploy/LICENSE | 291 +++++++++++++++++++++++ base/deploy/config/pkideployment.cfg | 28 +++ base/deploy/src/pkidestroy | 151 ++++++++++++ base/deploy/src/pkispawn | 174 ++++++++++++++ base/deploy/src/scriptlets/instance.py | 105 ++++++++ base/deploy/src/scriptlets/pkiconfig.py | 96 ++++++++ base/deploy/src/scriptlets/pkihelper.py | 222 +++++++++++++++++ base/deploy/src/scriptlets/pkilogging.py | 46 ++++ base/deploy/src/scriptlets/pkimessages.py | 86 +++++++ base/deploy/src/scriptlets/pkiscriptlet.py | 47 ++++ base/deploy/src/scriptlets/security_databases.py | 78 ++++++ 12 files changed, 1461 insertions(+) create mode 100644 base/deploy/CMakeLists.txt create mode 100644 base/deploy/LICENSE create mode 100644 base/deploy/config/pkideployment.cfg create mode 100755 base/deploy/src/pkidestroy create mode 100755 base/deploy/src/pkispawn create mode 100644 base/deploy/src/scriptlets/instance.py create mode 100644 base/deploy/src/scriptlets/pkiconfig.py create mode 100644 base/deploy/src/scriptlets/pkihelper.py create mode 100644 base/deploy/src/scriptlets/pkilogging.py create mode 100644 base/deploy/src/scriptlets/pkimessages.py create mode 100644 base/deploy/src/scriptlets/pkiscriptlet.py create mode 100644 base/deploy/src/scriptlets/security_databases.py (limited to 'base/deploy') diff --git a/base/deploy/CMakeLists.txt b/base/deploy/CMakeLists.txt new file mode 100644 index 000000000..11d70c55d --- /dev/null +++ b/base/deploy/CMakeLists.txt @@ -0,0 +1,137 @@ +project(deploy) + +install( + FILES + src/pkispawn + src/pkidestroy + DESTINATION + ${BIN_INSTALL_DIR} + PERMISSIONS + OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ +) + +install( + FILES + config/pkideployment.cfg + DESTINATION + ${DATA_INSTALL_DIR}/deployment/config + PERMISSIONS + OWNER_WRITE OWNER_READ + GROUP_READ + WORLD_READ +) + +find_package(PythonInterp REQUIRED) +execute_process( + COMMAND + ${PYTHON_EXECUTABLE} -c + "from distutils.sysconfig import get_python_lib; print get_python_lib()" + OUTPUT_VARIABLE + PYTHON_SITE_PACKAGES + OUTPUT_STRIP_TRAILING_WHITESPACE +) +install( + FILES + src/scriptlets/instance.py + src/scriptlets/pkiconfig.py + src/scriptlets/pkihelper.py + src/scriptlets/pkimessages.py + src/scriptlets/pkilogging.py + src/scriptlets/pkiscriptlet.py + src/scriptlets/security_databases.py + DESTINATION + ${PYTHON_SITE_PACKAGES}/pki/deployment + PERMISSIONS + OWNER_WRITE OWNER_READ + GROUP_READ + WORLD_READ +) +install( + CODE + "execute_process( + COMMAND + ${CMAKE_COMMAND} -E touch + \"\$ENV{DESTDIR}${PYTHON_SITE_PACKAGES}/pki/__init__.py\")" +) +install( + CODE + "execute_process( + COMMAND + ${CMAKE_COMMAND} -E touch + \"\$ENV{DESTDIR}${PYTHON_SITE_PACKAGES}/pki/deployment/__init__.py\")" +) + +#install( +# FILES +# jars/resteasy-jettison-provider-2.3-RC1.jar +# DESTINATION +# ${JAVA_JAR_INSTALL_DIR} +# PERMISSIONS +# OWNER_EXECUTE OWNER_WRITE OWNER_READ +# GROUP_EXECUTE GROUP_READ +# WORLD_EXECUTE WORLD_READ +#) + +# install empty directories +#install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${VAR_INSTALL_DIR}/lock/pki)") +#install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${VAR_INSTALL_DIR}/run/pki)") + +# install subsystem directories for pkispawn +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/ca)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/kra)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/ocsp)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/ra)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/tks)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/tps)") + +# install subsystem directories for pkidestroy +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/ca)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/kra)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/ocsp)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/ra)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/tks)") +install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/tps)") + +# generate and install symbolic links for pkispawn CA +install( + CODE + "execute_process( + COMMAND + ${CMAKE_COMMAND} -E create_symlink + \"${PYTHON_SITE_PACKAGES}/pki/deployment/instance.py\" + \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/ca/0010_instance\")" +) +install( + CODE + "execute_process( + COMMAND + ${CMAKE_COMMAND} -E create_symlink + \"${PYTHON_SITE_PACKAGES}/pki/deployment/security_databases.py\" + \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/ca/0020_security_databases\")" +) + +# generate and install symbolic links for pkispawn KRA + +# generate and install symbolic links for pkispawn OCSP + +# generate and install symbolic links for pkispawn RA + +# generate and install symbolic links for pkispawn TKS + +# generate and install symbolic links for pkispawn TPS + + +# generate and install symbolic links for pkidestroy CA + +# generate and install symbolic links for pkidestroy KRA + +# generate and install symbolic links for pkidestroy OCSP + +# generate and install symbolic links for pkidestroy RA + +# generate and install symbolic links for pkidestroy TKS + +# generate and install symbolic links for pkidestroy TPS + diff --git a/base/deploy/LICENSE b/base/deploy/LICENSE new file mode 100644 index 000000000..e281f4362 --- /dev/null +++ b/base/deploy/LICENSE @@ -0,0 +1,291 @@ +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. diff --git a/base/deploy/config/pkideployment.cfg b/base/deploy/config/pkideployment.cfg new file mode 100644 index 000000000..db9ce54dd --- /dev/null +++ b/base/deploy/config/pkideployment.cfg @@ -0,0 +1,28 @@ +[Common] +pki_instance_root=/var/lib/pki +pki_instance_name=instance +pki_user=pkiuser +pki_group=pkiuser +pki_audit_group=pkiaudit +[Apache] +pki_web_server=Apache +pki_http_port=80 +pki_https_port=443 +[Tomcat] +pki_web_server=Tomcat +pki_http_port=8080 +pki_https_port=8443 +pki_ajp_port=8009 +pki_security_manager=true +[CA] +pki_subsystem=CA +[KRA] +pki_subsystem=KRA +[OCSP] +pki_subsystem=OCSP +[RA] +pki_subsystem=RA +[TKS] +pki_subsystem=TKS +[TPS] +pki_subsystem=TPS diff --git a/base/deploy/src/pkidestroy b/base/deploy/src/pkidestroy new file mode 100755 index 000000000..a762e143a --- /dev/null +++ b/base/deploy/src/pkidestroy @@ -0,0 +1,151 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# System Imports +import sys +if not hasattr(sys, "hexversion") or sys.hexversion < 0x020700f0: + print "Python version %s.%s.%s is too old." % sys.version_info[:3] + print "Please upgrade to at least Python 2.7.0." + sys.exit(1) +try: + import argparse + import logging + import os + import pprint + from pki.deployment import pkiconfig as config + from pki.deployment import pkihelper + from pki.deployment import pkilogging + from pki.deployment import pkimessages as log +except ImportError: + print >> sys.stderr, """\ +There was a problem importing one of the required Python modules. The +error was: + + %s +""" % sys.exc_value + sys.exit(1) + + +# PKI Deployment Functions +def main(argv): + "main entry point" + + # Only run this program as "root". + if not os.geteuid() == 0: + sys.exit("'%s' must be run as root!" % argv[0]) + + # Initialize 'pretty print' for objects + pp = pprint.PrettyPrinter(indent=4) + + # Read and process command-line arguments. + pkihelper.process_command_line_arguments(argv) + + # Enable 'pkidestroy' logging. + config.pki_log_dir = config.pki_root_prefix +\ + config.PKIDESTROY_LOG_PATH + config.pki_log_name = config.PKIDESTROY_LOG_PREFIX +\ + config.pki_subsystem.lower() +\ + config.PKIDESTROY_LOG_SUFFIX + rv = pkilogging.enable_pki_logger(config.pki_log_dir, + config.pki_log_name, + config.pki_log_level, + config.pki_console_log_level, + config.PKIDESTROY_LOGGER) + if rv != OSError: + config.pki_log = rv + else: + print log.PKI_UNABLE_TO_CREATE_LOG_DIRECTORY_1 % config.pki_log_dir + sys.exit(1) + + # Read the specified PKI configuration file. + rv = pkihelper.read_pki_configuration_file() + if rv != 0: + config.pki_log.error(PKI_UNABLE_TO_PARSE_1, rv) + sys.exit(1) + else: + config.pki_log.debug(log.PKI_DICTIONARY_COMMON) + config.pki_log.debug(pp.pformat(config.pki_common_dict)) + config.pki_log.debug(log.PKI_DICTIONARY_WEB_SERVER) + config.pki_log.debug(pp.pformat(config.pki_web_server_dict)) + config.pki_log.debug(log.PKI_DICTIONARY_SUBSYSTEM) + config.pki_log.debug(pp.pformat(config.pki_subsystem_dict)) + + # Override PKI configuration file values with 'custom' command-line values. + if not config.pki_instance_name is None: + config.pki_common_dict['pki_instance_name'] =\ + config.pki_instance_name + if not config.pki_http_port is None: + config.pki_web_server_dict['pki_http_port'] =\ + config.pki_http_port + if not config.pki_https_port is None: + config.pki_web_server_dict['pki_https_port'] =\ + config.pki_https_port + if not config.pki_ajp_port is None: + config.pki_web_server_dict['pki_ajp_port'] =\ + config.pki_ajp_port + config.pki_log.debug(log.PKI_DICTIONARY_COMMON) + config.pki_log.debug(pp.pformat(config.pki_common_dict)) + config.pki_log.debug(log.PKI_DICTIONARY_WEB_SERVER) + config.pki_log.debug(pp.pformat(config.pki_web_server_dict)) + config.pki_log.debug(log.PKI_DICTIONARY_SUBSYSTEM) + config.pki_log.debug(pp.pformat(config.pki_subsystem_dict)) + + # Combine the various sectional dictionaries into a PKI master dictionary + pkihelper.create_pki_master_dictionary() + config.pki_log.debug(log.PKI_DICTIONARY_MASTER) + config.pki_log.debug(pp.pformat(config.pki_master_dict)) + + # Remove the specified PKI subsystem. + pki_scriptlets_path = config.pki_root_prefix +\ + config.PKIDESTROY_PATH +\ + "/" + config.pki_subsystem.lower() + if not os.path.exists(pki_scriptlets_path) or\ + not os.path.isdir(pki_scriptlets_path): + config.pki_log.error(log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1, + pki_scriptlets_path) + sys.exit(1) + pki_subsystem_scriptlets = os.listdir(pki_scriptlets_path) + pki_subsystem_scriptlets.sort() + + # Process the various "scriptlets" for the specified PKI subsystem. + rv = 0 + config.pki_log.info(log.PKIDESTROY_BEGIN_MESSAGE_2, + config.pki_subsystem, + config.pki_master_dict['pki_instance_name']) + for pki_scriptlet in pki_subsystem_scriptlets: + scriptlet = __import__(config.PKI_DEPLOYMENT_SCRIPTLETS_MODULE +\ + '.' + pki_scriptlet[5:], + fromlist = [pki_scriptlet[5:]]) + instance = scriptlet.PkiScriptlet() + rv = instance.destroy() + if rv != 0: + sys.exit(1) + config.pki_log.info(log.PKIDESTROY_END_MESSAGE_2, + config.pki_subsystem, + config.pki_master_dict['pki_instance_name']) + config.pki_log.debug(log.PKI_DICTIONARY_MASTER) + config.pki_log.debug(pp.pformat(config.pki_master_dict)) + + +# PKI Deployment Entry Point +if __name__ == "__main__": + main(sys.argv) + diff --git a/base/deploy/src/pkispawn b/base/deploy/src/pkispawn new file mode 100755 index 000000000..a48a4753c --- /dev/null +++ b/base/deploy/src/pkispawn @@ -0,0 +1,174 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# System Imports +import sys +if not hasattr(sys, "hexversion") or sys.hexversion < 0x020700f0: + print "Python version %s.%s.%s is too old." % sys.version_info[:3] + print "Please upgrade to at least Python 2.7.0." + sys.exit(1) +try: + import argparse + import logging + import os + import pprint + from pki.deployment import pkiconfig as config + from pki.deployment import pkihelper + from pki.deployment import pkilogging + from pki.deployment import pkimessages as log +except ImportError: + print >> sys.stderr, """\ +There was a problem importing one of the required Python modules. The +error was: + + %s +""" % sys.exc_value + sys.exit(1) + + +# PKI Deployment Functions +def main(argv): + "main entry point" + + # Only run this program as "root". + if not os.geteuid() == 0: + sys.exit("'%s' must be run as root!" % argv[0]) + + # Set the umask + os.umask(config.PKI_DEPLOYMENT_DEFAULT_UMASK) + + # Initialize 'pretty print' for objects + pp = pprint.PrettyPrinter(indent=4) + + # Read and process command-line arguments. + pkihelper.process_command_line_arguments(argv) + + # Enable 'pkispawn' logging. + rv = 0 + if not config.pki_update_flag: + pki_deployment_begin = log.PKISPAWN_BEGIN_MESSAGE_2 + pki_deployment_end = log.PKISPAWN_END_MESSAGE_2 + config.pki_log_dir = config.pki_root_prefix +\ + config.PKISPAWN_LOG_PATH + config.pki_log_name = config.PKISPAWN_LOG_PREFIX +\ + config.pki_subsystem.lower() +\ + config.PKISPAWN_LOG_SUFFIX + rv = pkilogging.enable_pki_logger(config.pki_log_dir, + config.pki_log_name, + config.pki_log_level, + config.pki_console_log_level, + config.PKISPAWN_LOGGER) + else: + pki_deployment_begin = log.PKIRESPAWN_BEGIN_MESSAGE_2 + pki_deployment_end = log.PKIRESPAWN_END_MESSAGE_2 + config.pki_log_dir = config.pki_root_prefix +\ + config.PKIRESPAWN_LOG_PATH + config.pki_log_name = config.PKIRESPAWN_LOG_PREFIX +\ + config.pki_subsystem.lower() +\ + config.PKIRESPAWN_LOG_SUFFIX + rv = pkilogging.enable_pki_logger(config.pki_log_dir, + config.pki_log_name, + config.pki_log_level, + config.pki_console_log_level, + config.PKIRESPAWN_LOGGER) + if rv != OSError: + config.pki_log = rv + else: + print log.PKI_UNABLE_TO_CREATE_LOG_DIRECTORY_1 % config.pki_log_dir + sys.exit(1) + + # Read the specified PKI configuration file. + rv = pkihelper.read_pki_configuration_file() + if rv != 0: + config.pki_log.error(PKI_UNABLE_TO_PARSE_1, rv) + sys.exit(1) + else: + config.pki_log.debug(log.PKI_DICTIONARY_COMMON) + config.pki_log.debug(pp.pformat(config.pki_common_dict)) + config.pki_log.debug(log.PKI_DICTIONARY_WEB_SERVER) + config.pki_log.debug(pp.pformat(config.pki_web_server_dict)) + config.pki_log.debug(log.PKI_DICTIONARY_SUBSYSTEM) + config.pki_log.debug(pp.pformat(config.pki_subsystem_dict)) + + # Override PKI configuration file values with 'custom' command-line values. + if not config.pki_instance_name is None: + config.pki_common_dict['pki_instance_name'] =\ + config.pki_instance_name + if not config.pki_http_port is None: + config.pki_web_server_dict['pki_http_port'] =\ + config.pki_http_port + if not config.pki_https_port is None: + config.pki_web_server_dict['pki_https_port'] =\ + config.pki_https_port + if not config.pki_ajp_port is None: + config.pki_web_server_dict['pki_ajp_port'] =\ + config.pki_ajp_port + config.pki_log.debug(log.PKI_DICTIONARY_COMMON) + config.pki_log.debug(pp.pformat(config.pki_common_dict)) + config.pki_log.debug(log.PKI_DICTIONARY_WEB_SERVER) + config.pki_log.debug(pp.pformat(config.pki_web_server_dict)) + config.pki_log.debug(log.PKI_DICTIONARY_SUBSYSTEM) + config.pki_log.debug(pp.pformat(config.pki_subsystem_dict)) + + # Combine the various sectional dictionaries into a PKI master dictionary + pkihelper.create_pki_master_dictionary() + config.pki_log.debug(log.PKI_DICTIONARY_MASTER) + config.pki_log.debug(pp.pformat(config.pki_master_dict)) + + # Install and configure the specified PKI subsystem. + pki_scriptlets_path = config.pki_root_prefix +\ + config.PKISPAWN_PATH +\ + "/" + config.pki_subsystem.lower() + if not os.path.exists(pki_scriptlets_path) or\ + not os.path.isdir(pki_scriptlets_path): + config.pki_log.error(log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1, + pki_scriptlets_path) + sys.exit(1) + pki_subsystem_scriptlets = os.listdir(pki_scriptlets_path) + pki_subsystem_scriptlets.sort() + + # Process the various "scriptlets" for the specified PKI subsystem. + rv = 0 + config.pki_log.info(pki_deployment_begin, + config.pki_subsystem, + config.pki_master_dict['pki_instance_name']) + for pki_scriptlet in pki_subsystem_scriptlets: + scriptlet = __import__(config.PKI_DEPLOYMENT_SCRIPTLETS_MODULE +\ + '.' + pki_scriptlet[5:], + fromlist = [pki_scriptlet[5:]]) + instance = scriptlet.PkiScriptlet() + if not config.pki_update_flag: + rv = instance.spawn() + else: + rv = instance.respawn() + if rv != 0: + sys.exit(1) + config.pki_log.info(pki_deployment_end, + config.pki_subsystem, + config.pki_master_dict['pki_instance_name']) + config.pki_log.debug(log.PKI_DICTIONARY_MASTER) + config.pki_log.debug(pp.pformat(config.pki_master_dict)) + + +# PKI Deployment Entry Point +if __name__ == "__main__": + main(sys.argv) + diff --git a/base/deploy/src/scriptlets/instance.py b/base/deploy/src/scriptlets/instance.py new file mode 100644 index 000000000..a7ca35c69 --- /dev/null +++ b/base/deploy/src/scriptlets/instance.py @@ -0,0 +1,105 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# System Imports +import os +import grp +import pwd + +# PKI Deployment Imports +import pkiconfig as config +import pkimessages as log +import pkiscriptlet + + +# PKI Deployment Instance Population Classes +class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): + rv = 0 + pki_path = config.pki_root_prefix +\ + config.pki_master_dict['pki_instance_root'] + pki_instance_path = pki_path + "/" +\ + config.pki_master_dict['pki_instance_name'] + pki_subsystem_path = pki_instance_path + "/" +\ + config.pki_master_dict['pki_subsystem'].lower() + + def spawn(self): + if not os.path.exists(self.pki_subsystem_path): + config.pki_log.info(log.INSTANCE_SPAWN_1, __name__) + config.pki_log.info(log.INSTANCE_SPAWN_MKDIR_1, + self.pki_subsystem_path) + if not config.pki_dry_run_flag: + try: + pki_gid = grp.getgrnam( + config.pki_master_dict['pki_group'])[2] + pki_uid = pwd.getpwnam( + config.pki_master_dict['pki_user'])[2] + os.mkdir(self.pki_path, + config.PKI_DEPLOYMENT_DEFAULT_DIR_PERMISSIONS) + os.chown(self.pki_path, + pki_uid, + pki_gid) + os.mkdir(self.pki_instance_path, + config.PKI_DEPLOYMENT_DEFAULT_DIR_PERMISSIONS) + os.chown(self.pki_instance_path, + pki_uid, + pki_gid) + os.mkdir(self.pki_subsystem_path, + config.PKI_DEPLOYMENT_DEFAULT_DIR_PERMISSIONS) + os.chown(self.pki_subsystem_path, + pki_uid, + pki_gid) + except KeyError: + self.rv = KeyError + except OSError: + self.rv = OSError + elif not os.path.isdir(self.pki_subsystem_path): + config.pki_log.error( + log.PKI_DIRECTORY_ALREADY_EXISTS_NOT_A_DIRECTORY_1, + self.pki_subsystem_path) + self.rv = -1 + else: + config.pki_log.error(log.PKI_DIRECTORY_ALREADY_EXISTS_1, + self.pki_subsystem_path) + self.rv = -1 + return self.rv + + def respawn(self): + if not os.path.exists(self.pki_subsystem_path) or\ + not os.path.isdir(self.pki_subsystem_path): + config.pki_log.error( + log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1, + self.pki_subsystem_path) + self.rv = -1 + else: + config.pki_log.info(log.INSTANCE_RESPAWN_1, __name__) + return self.rv + + def destroy(self): + if not os.path.exists(self.pki_subsystem_path) or\ + not os.path.isdir(self.pki_subsystem_path): + config.pki_log.error( + log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1, + self.pki_subsystem_path) + self.rv = -1 + else: + config.pki_log.info(log.INSTANCE_DESTROY_1, __name__) + return self.rv + diff --git a/base/deploy/src/scriptlets/pkiconfig.py b/base/deploy/src/scriptlets/pkiconfig.py new file mode 100644 index 000000000..7d676c00d --- /dev/null +++ b/base/deploy/src/scriptlets/pkiconfig.py @@ -0,0 +1,96 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# System Imports +import logging + + +# PKI Deployment Constants +PKI_DEPLOYMENT_PATH = "/usr/share/pki/deployment" +PKI_DEPLOYMENT_CONFIG_PATH = PKI_DEPLOYMENT_PATH + "/" + "config" +PKI_DEPLOYMENT_SCRIPTLETS_MODULE = "pki.deployment" +PKI_DEPLOYMENT_VERBOSITY=\ +"VERBOSITY FLAGS CONSOLE MESSAGE LEVEL LOG MESSAGE LEVEL\n"\ +"=======================================================================\n"\ +" NONE error|warning error|warning|info\n"\ +" -v error|warning|info error|warning|info\n"\ +" -vv error|warning|info error|warning|info|debug\n"\ +" -vvv error|warning|info|debug error|warning|info|debug\n"\ +" " +PKI_DEPLOYMENT_DEFAULT_DIR_PERMISSIONS = 00770 +PKI_DEPLOYMENT_DEFAULT_EXE_PERMISSIONS = 00770 +PKI_DEPLOYMENT_DEFAULT_FILE_PERMISSIONS = 00660 +PKI_DEPLOYMENT_DEFAULT_UMASK = 00002 + +PKIDESTROY_PATH = PKI_DEPLOYMENT_PATH + "/" + "destroy" +PKIDESTROY_LOG_PATH = "/var/log" +PKIDESTROY_LOG_PREFIX = "pki-" +PKIDESTROY_LOG_SUFFIX = "-destroy.log" +PKIDESTROY_LOGGER = "pkidestroy" + +PKIRESPAWN_PATH = PKI_DEPLOYMENT_PATH + "/" + "spawn" +PKIRESPAWN_LOG_PATH = "/var/log" +PKIRESPAWN_LOG_PREFIX = "pki-" +PKIRESPAWN_LOG_SUFFIX = "-respawn.log" +PKIRESPAWN_LOGGER = "pkirespawn" + +PKISPAWN_PATH = PKI_DEPLOYMENT_PATH + "/" + "spawn" +PKISPAWN_LOG_PATH = "/var/log" +PKISPAWN_LOG_PREFIX = "pki-" +PKISPAWN_LOG_SUFFIX = "-spawn.log" +PKISPAWN_LOGGER = "pkispawn" + +PKI_SECURITY_DATABASE_DIR = "alias" +PKI_SUBSYSTEMS = ["CA","KRA","OCSP","RA","TKS","TPS"] +PKI_APACHE_SUBSYSTEMS = ["RA","TPS"] +PKI_TOMCAT_SUBSYSTEMS = ["CA","KRA","OCSP","TKS"] + + +# PKI Deployment "Mandatory" Command-Line Variables +pki_subsystem = None + +# PKI Deployment "Optional" Command-Line Variables +pkideployment_cfg = PKI_DEPLOYMENT_CONFIG_PATH + "/" + "pkideployment.cfg" +pki_dry_run_flag = False +pki_root_prefix = None +pki_update_flag = False + +# PKI Deployment "Custom" Command-Line Variables +pki_instance_name = None +pki_http_port = None +pki_https_port = None +pki_ajp_port = None + + +# PKI Deployment Logger Variables +pki_log = None +pki_log_dir = None +pki_log_name = None +pki_log_level = logging.INFO +pki_console_log_level = logging.WARNING + + +# PKI Deployment Global Dictionaries +pki_common_dict = None +pki_web_server_dict = None +pki_subsystem_dict = None +pki_master_dict = None + diff --git a/base/deploy/src/scriptlets/pkihelper.py b/base/deploy/src/scriptlets/pkihelper.py new file mode 100644 index 000000000..ee2bdd249 --- /dev/null +++ b/base/deploy/src/scriptlets/pkihelper.py @@ -0,0 +1,222 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# System Imports +import ConfigParser +import argparse +import logging +import os + + +# PKI Deployment Imports +import pkiconfig as config +import pkimessages as log + + +# PKI Deployment Helper Functions +def process_command_line_arguments(argv): + "Read and process command-line options" + description = None + if os.path.basename(argv[0]) == 'pkispawn': + description = 'PKI Instance Installation and Configuration' + elif os.path.basename(argv[0]) == 'pkidestroy': + description = 'PKI Instance Removal' + parser = argparse.ArgumentParser( + description=description, + add_help=False, + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=config.PKI_DEPLOYMENT_VERBOSITY) + mandatory = parser.add_argument_group('mandatory arguments') + mandatory.add_argument('-s', + dest='pki_subsystem', action='store', + nargs=1, choices=config.PKI_SUBSYSTEMS, + required=True, metavar='', + help='where is ' + 'CA, KRA, OCSP, RA, TKS, or TPS') + optional = parser.add_argument_group('optional arguments') + optional.add_argument('--dry_run', + dest='pki_dry_run_flag', action='store_true', + help='do not actually perform any actions') + optional.add_argument('-f', + dest='pkideployment_cfg', action='store', + nargs=1, metavar='', + help='overrides default configuration filename') + optional.add_argument('-h', '--help', + dest='help', action='help', + help='show this help message and exit') + optional.add_argument('-p', + dest='pki_root_prefix', action='store', + nargs=1, metavar='', + help='directory prefix to specify local directory') + if os.path.basename(argv[0]) == 'pkispawn': + optional.add_argument('-u', + dest='pki_update_flag', action='store_true', + help='update instance of specified subsystem') + optional.add_argument('-v', + dest='pki_verbosity', action='count', + help='display verbose information (details below)') + custom = parser.add_argument_group('custom arguments ' + '(OVERRIDES configuration file values)') + custom.add_argument('-i', + dest='pki_instance_name', action='store', + nargs=1, metavar='', + help='PKI instance name (MUST specify REQUIRED ports)') + custom.add_argument('--http_port', + dest='pki_http_port', action='store', + nargs=1, metavar='', + help='HTTP port (CA, KRA, OCSP, RA, TKS, TPS)') + custom.add_argument('--https_port', + dest='pki_https_port', action='store', + nargs=1, metavar='', + help='HTTPS port (CA, KRA, OCSP, RA, TKS, TPS)') + custom.add_argument('--ajp_port', + dest='pki_ajp_port', action='store', + nargs=1, metavar='', + help='AJP port (CA, KRA, OCSP, TKS)') + args = parser.parse_args() + + config.pki_subsystem = str(args.pki_subsystem).strip('[\']') + if args.pki_dry_run_flag: + config.pki_dry_run_flag = args.pki_dry_run_flag + if not args.pkideployment_cfg is None: + config.pkideployment_cfg = str(args.pkideployment_cfg).strip('[\']') + if not os.path.exists(config.pkideployment_cfg) or\ + not os.path.isfile(config.pkideployment_cfg): + print "ERROR: " +\ + log.PKI_FILE_MISSING_OR_NOT_A_FILE_1 %\ + config.pkideployment_cfg + print + parser.print_help() + parser.exit(-1); + if not args.pki_root_prefix is None: + config.pki_root_prefix = str(args.pki_root_prefix).strip('[\']') + if config.pki_root_prefix is None or\ + len(config.pki_root_prefix) == 0: + config.pki_root_prefix = "" + elif not os.path.exists(config.pki_root_prefix) or\ + not os.path.isdir(config.pki_root_prefix): + print "ERROR: " +\ + log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1 %\ + config.pki_root_prefix + print + parser.print_help() + parser.exit(-1); + if os.path.basename(argv[0]) == 'pkispawn': + if args.pki_update_flag: + config.pki_update_flag = args.pki_update_flag + if args.pki_verbosity == 1: + config.pki_console_log_level = logging.INFO + config.pki_log_level = logging.INFO + elif args.pki_verbosity == 2: + config.pki_console_log_level = logging.INFO + config.pki_log_level = logging.DEBUG + elif args.pki_verbosity == 3: + config.pki_console_log_level = logging.DEBUG + config.pki_log_level = logging.DEBUG + elif args.pki_verbosity > 3: + print "ERROR: " + log.PKI_VERBOSITY_LEVELS_MESSAGE + print + parser.print_help() + parser.exit(-1); + if not args.pki_instance_name is None: + config.pki_instance_name = str(args.pki_instance_name).strip('[\']') + if not args.pki_http_port is None: + config.pki_http_port = str(args.pki_http_port).strip('[\']') + if not args.pki_https_port is None: + config.pki_https_port = str(args.pki_https_port).strip('[\']') + if not args.pki_ajp_port is None: + if config.pki_subsystem in config.PKI_TOMCAT_SUBSYSTEMS: + config.pki_ajp_port = str(args.pki_ajp_port).strip('[\']') + else: + print "ERROR: " +\ + log.PKI_CUSTOM_TOMCAT_AJP_PORT_1 %\ + config.pki_subsystem + print + parser.print_help() + parser.exit(-1); + if not args.pki_instance_name is None or\ + not args.pki_http_port is None or\ + not args.pki_https_port is None or\ + not args.pki_ajp_port is None: + if config.pki_subsystem in config.PKI_APACHE_SUBSYSTEMS: + if args.pki_instance_name is None or\ + args.pki_http_port is None or\ + args.pki_https_port is None: + print "ERROR: " + log.PKI_CUSTOM_APACHE_INSTANCE_1 %\ + config.pki_subsystem + print + parser.print_help() + parser.exit(-1); + elif config.pki_subsystem in config.PKI_TOMCAT_SUBSYSTEMS: + if args.pki_instance_name is None or\ + args.pki_http_port is None or\ + args.pki_https_port is None or\ + args.pki_ajp_port is None: + print "ERROR: " + log.PKI_CUSTOM_TOMCAT_INSTANCE_1 %\ + config.pki_subsystem + print + parser.print_help() + parser.exit(-1); + + +def read_pki_configuration_file(): + "Read configuration file sections into dictionaries" + rv = 0 + try: + parser = ConfigParser.ConfigParser() + parser.read(config.pkideployment_cfg) + config.pki_common_dict = dict(parser._sections['Common']) + if config.pki_subsystem == "CA": + config.pki_web_server_dict = dict(parser._sections['Tomcat']) + config.pki_subsystem_dict = dict(parser._sections['CA']) + elif config.pki_subsystem == "KRA": + config.pki_web_server_dict = dict(parser._sections['Tomcat']) + config.pki_subsystem_dict = dict(parser._sections['KRA']) + elif config.pki_subsystem == "OCSP": + config.pki_web_server_dict = dict(parser._sections['Tomcat']) + config.pki_subsystem_dict = dict(parser._sections['OCSP']) + elif config.pki_subsystem == "RA": + config.pki_web_server_dict = dict(parser._sections['Apache']) + config.pki_subsystem_dict = dict(parser._sections['RA']) + elif config.pki_subsystem == "TKS": + config.pki_web_server_dict = dict(parser._sections['Tomcat']) + config.pki_subsystem_dict = dict(parser._sections['TKS']) + elif config.pki_subsystem == "TPS": + config.pki_web_server_dict = dict(parser._sections['Apache']) + config.pki_subsystem_dict = dict(parser._sections['TPS']) + # Insert empty record into dictionaries for "pretty print" statements + config.pki_common_dict[0] = None + config.pki_web_server_dict[0] = None + config.pki_subsystem_dict[0] = None + except ConfigParser.ParsingError, err: + rv = err + return rv + + +def create_pki_master_dictionary(): + "Create a single master PKI dictionary from the sectional dictionaries" + config.pki_master_dict = dict() + config.pki_master_dict.update(config.pki_common_dict) + config.pki_master_dict.update(config.pki_web_server_dict) + config.pki_master_dict.update(config.pki_subsystem_dict) + config.pki_master_dict.update(__name__="PKI Master Dictionary") + return + diff --git a/base/deploy/src/scriptlets/pkilogging.py b/base/deploy/src/scriptlets/pkilogging.py new file mode 100644 index 000000000..776677cfd --- /dev/null +++ b/base/deploy/src/scriptlets/pkilogging.py @@ -0,0 +1,46 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# System Imports +import logging +import os + + +# PKI Deployment Logging Functions +def enable_pki_logger(log_dir, log_name, log_level, console_log_level, logger): + if not os.path.isdir(log_dir): + try: + os.makedirs(log_dir) + except OSError: + return OSError + logging.basicConfig(level=log_level, + format='%(asctime)s %(name)-12s ' +\ + '%(levelname)-8s %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', + filename=log_dir + "/" + log_name, + filemode='w') + console = logging.StreamHandler() + console.setLevel(console_log_level) + formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') + console.setFormatter(formatter) + logging.getLogger('').addHandler(console) + return logging.getLogger(logger) + diff --git a/base/deploy/src/scriptlets/pkimessages.py b/base/deploy/src/scriptlets/pkimessages.py new file mode 100644 index 000000000..e6a9f95aa --- /dev/null +++ b/base/deploy/src/scriptlets/pkimessages.py @@ -0,0 +1,86 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# PKI Deployment Engine Messages +PKI_CUSTOM_APACHE_INSTANCE_1 = "When a custom '%s' subsystem is being "\ + "deployed, the 'instance', 'http_port', and "\ + "'https_port' must ALL be specified!" +PKI_CUSTOM_TOMCAT_INSTANCE_1 = "When a custom '%s' subsystem is being "\ + "deployed, the 'instance', 'http_port', "\ + "'https_port', and 'ajp_port' must ALL be "\ + "specified!" +PKI_CUSTOM_TOMCAT_AJP_PORT_1 = "When a custom '%s' subsystem is being "\ + "deployed, ONLY the 'instance', "\ + "'http_port', and 'https_port' MUST be "\ + "specified; NO 'ajp_port' should be requested!" +PKI_DICTIONARY_COMMON ="\n"\ +"=====================================================\n"\ +" DISPLAY CONTENTS OF PKI COMMON DICTIONARY\n"\ +"=====================================================" +PKI_DICTIONARY_MASTER="\n"\ +"=====================================================\n"\ +" DISPLAY CONTENTS OF PKI MASTER DICTIONARY\n"\ +"=====================================================" +PKI_DICTIONARY_SUBSYSTEM="\n"\ +"=====================================================\n"\ +" DISPLAY CONTENTS OF PKI SUBSYSTEM DICTIONARY\n"\ +"=====================================================" +PKI_DICTIONARY_WEB_SERVER="\n"\ +"=====================================================\n"\ +" DISPLAY CONTENTS OF PKI WEB SERVER DICTIONARY\n"\ +"=====================================================" +PKI_DIRECTORY_ALREADY_EXISTS_1 = "Directory '%s' already exists!" +PKI_DIRECTORY_ALREADY_EXISTS_NOT_A_DIRECTORY_1 = "Directory '%s' already "\ + "exists BUT it is NOT a "\ + "directory!" +PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1 = "Directory '%s' is either "\ + "missing or is NOT a directory!" +PKI_FILE_MISSING_OR_NOT_A_FILE_1 = "File '%s' is either missing "\ + "or is NOT a regular file!" +PKI_UNABLE_TO_PARSE_1 = "'Could not parse: '%s'" +PKI_UNABLE_TO_CREATE_LOG_DIRECTORY_1 = "Could not create log directory '%s'!" +PKI_VERBOSITY_LEVELS_MESSAGE = "Only up to 3 levels of verbosity are supported!" + + +# PKI Deployment 'pkispawn' and 'pkidestroy' Messages +PKIDESTROY_BEGIN_MESSAGE_2 = "BEGIN destroying subsystem '%s' of "\ + "instance '%s' . . ." +PKIDESTROY_END_MESSAGE_2 = "END destroying subsystem '%s' of "\ + "instance '%s'." +PKIRESPAWN_BEGIN_MESSAGE_2 = "BEGIN respawning subsystem '%s' of "\ + "instance '%s' . . ." +PKIRESPAWN_END_MESSAGE_2 = "END respawning subsystem '%s' of "\ + "instance '%s'." +PKISPAWN_BEGIN_MESSAGE_2 = "BEGIN spawning subsystem '%s' of "\ + "instance '%s' . . ." +PKISPAWN_END_MESSAGE_2 = "END spawning subsystem '%s' of "\ + "instance '%s'." + + +# PKI Deployment "Scriptlet" Messages +INSTANCE_DESTROY_1 = " depopulating '%s'" +INSTANCE_RESPAWN_1 = " repopulating '%s'" +INSTANCE_SPAWN_1 = " populating '%s'" +INSTANCE_SPAWN_MKDIR_1 = " mkdir '%s'" +SECURITY_DATABASES_DESTROY_1 = " removing '%s'" +SECURITY_DATABASES_RESPAWN_1 = " regenerating '%s'" +SECURITY_DATABASES_SPAWN_1 = " generating '%s'" + diff --git a/base/deploy/src/scriptlets/pkiscriptlet.py b/base/deploy/src/scriptlets/pkiscriptlet.py new file mode 100644 index 000000000..5befd993a --- /dev/null +++ b/base/deploy/src/scriptlets/pkiscriptlet.py @@ -0,0 +1,47 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# System Imports +import abc + + +# PKI Deployment Classes +class AbstractBasePkiScriptlet(object): + __metaclass__ = abc.ABCMeta + + @abc.abstractmethod + def spawn(self): + """Retrieve data from the specified PKI dictionary and + use it to install a new PKI instance.""" + return + + @abc.abstractmethod + def respawn(self): + """Retrieve data from the specified PKI dictionary and + use it to update an existing PKI instance.""" + return + + @abc.abstractmethod + def destroy(self): + """Retrieve data from the specified PKI dictionary and + use it to destroy an existing PKI instance.""" + return + diff --git a/base/deploy/src/scriptlets/security_databases.py b/base/deploy/src/scriptlets/security_databases.py new file mode 100644 index 000000000..af47cbd5d --- /dev/null +++ b/base/deploy/src/scriptlets/security_databases.py @@ -0,0 +1,78 @@ +#!/usr/bin/python -t +# Authors: +# Matthew Harmsen +# +# 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. +# +# Copyright (C) 2011 Red Hat, Inc. +# All rights reserved. +# + +# System Imports +import os + +# PKI Deployment Imports +import pkiconfig as config +import pkimessages as log +import pkiscriptlet + + +# PKI Deployment Security Database Classes +class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): + rv = 0 + pki_path = config.pki_root_prefix +\ + config.pki_master_dict['pki_instance_root'] + pki_instance_path = pki_path + "/" +\ + config.pki_master_dict['pki_instance_name'] + pki_subsystem_path = pki_instance_path + "/" +\ + config.pki_master_dict['pki_subsystem'].lower() + pki_database_path = pki_subsystem_path + "/" +\ + config.PKI_SECURITY_DATABASE_DIR + + def spawn(self): + if not os.path.exists(self.pki_database_path): + config.pki_log.info(log.SECURITY_DATABASES_SPAWN_1, __name__) + elif not os.path.isdir(self.pki_database_path): + config.pki_log.error( + log.PKI_DIRECTORY_ALREADY_EXISTS_NOT_A_DIRECTORY_1, + self.pki_database_path) + self.rv = -1 + else: + config.pki_log.error(log.PKI_DIRECTORY_ALREADY_EXISTS_1, + self.pki_database_path) + self.rv = -1 + return self.rv + + def respawn(self): + if not os.path.exists(self.pki_database_path) or\ + not os.path.isdir(self.pki_database_path): + config.pki_log.error( + log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1, + self.pki_database_path) + self.rv = -1 + else: + config.pki_log.info(log.SECURITY_DATABASES_RESPAWN_1, __name__) + return self.rv + + def destroy(self): + if not os.path.exists(self.pki_database_path) or\ + not os.path.isdir(self.pki_database_path): + config.pki_log.error( + log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1, + self.pki_database_path) + self.rv = -1 + else: + config.pki_log.info(log.SECURITY_DATABASES_DESTROY_1, __name__) + return self.rv + -- cgit