database_backends.dox 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. /**
  15. @page dhcpDatabaseBackends DHCP Database Back-Ends
  16. All DHCP lease data is stored in some form of database, the interface
  17. to this being through the Lease Manager.
  18. All backend classes such as isc::dhcp::MySqlLeaseMgr are derived from
  19. the abstract isc::dhcp::LeaseMgr class. This provides methods to
  20. create, retrieve, modify and delete leases in the database.
  21. There are currently two available Lease Managers, MySQL and Memfile:
  22. - The MySQL lease manager uses the freely available MySQL as its backend
  23. database. This is not included in BIND 10 DHCP by default:
  24. the \--with-dhcp-mysql switch must be supplied to "configure" for support
  25. to be compiled into the software.
  26. - Memfile is an in-memory lease database, with (currently) nothing being
  27. written to persistent storage. The long-term plans for the backend do
  28. include the ability to store this on disk, but it is currently a
  29. low-priority item.
  30. @section dhcpdb-instantiation Instantiation of Lease Managers
  31. A lease manager is instantiated through the LeaseMgrFactory class. This
  32. has three methods:
  33. - isc::dhcp::LeaseMgrFactory::create - Creates a singleton Lease
  34. Manager of the appropriate type.
  35. - isc::dhcp::LeaseMgrFactory::instance - Returns a reference to the
  36. the instance of the Lease Manager.
  37. - isc::dhcp::LeaseMgrFactory::destroy - Destroys the singleton lease manager.
  38. The selection of the Lease Manager (and thus the backend database) is
  39. controlled by the connection string passed to
  40. isc::dhcp::LeaseMgrFactory::create. This is a set of "keyword=value" pairs
  41. (no embedded spaces), each pair separated by a space from the others, e.g.
  42. \code
  43. type=mysql user=keatest password=keatest name=keatest host=localhost
  44. \endcode
  45. The following keywords are used for all backends:
  46. - <b>type</b> - specifies the type of database backend. The following values
  47. for the type keyword are supported:
  48. - <B>memfile</b> - In-memory database. Nothing is written to any
  49. external storage, so this should not be used in production.
  50. - <b>mysql</b> - Use MySQL as the database
  51. The following sections list the database-specific keywords:
  52. @subsection dhcpdb-keywords-mysql MySQL connection string keywords
  53. - <b>host</b> - host on which the selected database is running. If not
  54. supplied, "localhost" is assumed.
  55. - <b>name</b> - name of the MySQL database to access. There is no default -
  56. this must always be supplied.
  57. - <b>password</b> - password for the selected user ID (see below). If not
  58. specified, no password is used.
  59. - <b>user</b> - database user ID under which the database is accessed. If not
  60. specified, no user ID is used - the database is assumed to be open.
  61. @section dhcp-backend-unittest Running Unit Tests
  62. With the use of databases requiring separate authorisation, there are
  63. certain database-specific pre-requisites for successfully running the unit
  64. tests. These are listed in the following sections.
  65. @subsection dhcp-mysql-unittest MySQL
  66. A database called <i>keatest</i> must be created. A database user, also called
  67. <i>keatest</i> (and with a password <i>keatest</i>) must also be created and
  68. be given full privileges in that database. The unit tests create the schema
  69. in the database before each test and delete it afterwards.
  70. In detail, the steps to create the database and user are:
  71. -# Log into MySQL as root:
  72. @verbatim
  73. % mysql -u root -p
  74. Enter password:
  75. :
  76. mysql>@endverbatim\n
  77. -# Create the test database. This must be called "keatest":
  78. @verbatim
  79. mysql> CREATE DATABASE keatest;
  80. mysql>@endverbatim\n
  81. -# Create the user under which the test client will connect to the database
  82. (the apostrophes around the words <i>keatest</i> and <i>localhost</i> are
  83. required):
  84. @verbatim
  85. mysql> CREATE USER 'keatest'@'localhost' IDENTIFIED BY 'keatest';
  86. mysql>@endverbatim\n
  87. -# Grant the created user permissions to access the <i>keatest</i> database
  88. (again, the apostrophes around the words <i>keatest</i> and <i>localhost</i>
  89. are required):
  90. @verbatim
  91. mysql> GRANT ALL ON keatest.* TO 'keatest'@'localhost';
  92. mysql>@endverbatim\n
  93. -# Exit MySQL:
  94. @verbatim
  95. mysql> quit
  96. Bye
  97. %@endverbatim
  98. The unit tests are run automatically when "make check" is executed (providing
  99. that BIND 10 has been build with the \--with-dhcp-mysql switch (see the installation
  100. section in the <a href="http://bind10.isc.org/docs/bind10-guide.html">BIND 10 Guide</a>).
  101. @subsection dhcp-pgsql-unittest PostgreSQL unit-tests
  102. Conceptually, the steps required to run PostgreSQL unit-tests are the same as
  103. in MySQL. First, a database called <i>keatest</i> must be created. A database
  104. user, also called <i>keatest</i> (that will be allowed to log in using password
  105. <i>keatest</i>) must be created and given full privileges in that database. The
  106. unit tests create the schema in the database before each test and delete it
  107. afterwards.
  108. PostgreSQL set up differs from system to system. Please consult your OS-specific
  109. PostgreSQL documentation. The remainder of that section uses Ubuntu 13.10 x64 as
  110. example. On Ubuntu, after installing PostgreSQL (with <tt>sudo apt-get install
  111. postgresql</tt>), it is installed as user <i>postgres</i>. To create new databases
  112. or add new users, initial commands must be issued as user postgres:
  113. @verbatim
  114. $ sudo -u postgres psql postgres
  115. [sudo] password for thomson:
  116. psql (9.1.12)
  117. Type "help" for help.
  118. postgres=# CREATE USER keatest WITH PASSWORD 'keatest';
  119. CREATE ROLE
  120. postgres=# CREATE DATABASE keatest;
  121. CREATE DATABASE
  122. postgres=# GRANT ALL PRIVILEGES ON DATABASE keatest TO keatest;
  123. GRANT
  124. postgres=# \q
  125. @endverbatim
  126. Now we are back to our regular, unprivileged user. Try to log into the newly
  127. created database using keatest credentials:
  128. @verbatim
  129. $ psql -d keatest -U keatest
  130. $ psql keatest -U keatest -W
  131. Password for user keatest:
  132. psql (9.1.12)
  133. Type "help" for help.
  134. keatest=>
  135. @endverbatim
  136. If instead of seeing keatest=> prompt, your login will be refused with error
  137. code about failed peer or indent authentication, it means that PostgreSQL is
  138. configured to check unix username and reject login attepts if PostgreSQL names
  139. are different. To alter that, PostgreSQL configuration must be changed.
  140. Alternatively, you may set up your environment, so the tests would be run from
  141. unix account keatest. <tt>/etc/postgresql/9.1/main/pg_hba.conf</tt> config file
  142. had to betweaked. It may be in a different location in your system. The following
  143. lines:
  144. @verbatim
  145. local all all peer
  146. host all all 127.0.0.1/32 md5
  147. host all all ::1/128 md5
  148. @endverbatim
  149. were replaced with:
  150. @verbatim
  151. local all all password
  152. host all all 127.0.0.1/32 password
  153. host all all ::1/128 password
  154. @endverbatim
  155. Please consult your PostgreSQL user manual before applying those changes as
  156. those changes may expose your other databases that you run on the same system.
  157. In general case, it is a poor idea to run anything of value on a system
  158. that runs tests. Use caution!
  159. The unit tests are run automatically when "make check" is executed (providing
  160. that BIND 10 has been build with the \--with-dhcp-pgsql switch (see the installation
  161. section in the <a href="http://bind10.isc.org/docs/bind10-guide.html">BIND10 Guide</a>).
  162. */