README.plugins.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
  5. <TITLE></TITLE>
  6. <META NAME="GENERATOR" CONTENT="OpenOffice 4.1.2 (Unix)">
  7. <META NAME="CREATED" CONTENT="20130417;16154700">
  8. <META NAME="CHANGEDBY" CONTENT="Alex Peshkoff">
  9. <META NAME="CHANGED" CONTENT="20160407;19330500">
  10. <META NAME="CHANGEDBY" CONTENT="Alex Peshkoff">
  11. <STYLE TYPE="text/css">
  12. <!--
  13. @page { margin: 0.79in }
  14. P { margin-bottom: 0.08in }
  15. -->
  16. </STYLE>
  17. </HEAD>
  18. <BODY LANG="en-US" DIR="LTR">
  19. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Firebird plugins.</FONT></P>
  20. <P STYLE="margin-bottom: 0in"><BR>
  21. </P>
  22. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Since version 3, Firebird
  23. supports plugins architecture. This means that for a number of
  24. predefined points in Firebird code, user can write his own fragment
  25. of code which will be executed when needed. Plugin is not necessarily
  26. always written by user - Firebird already has a number of plugins
  27. which are its native part. Moreover, as you will see later, some core
  28. parts of Firebird are implemented as plugins. </FONT>
  29. </P>
  30. <P STYLE="margin-bottom: 0in"><BR>
  31. </P>
  32. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>First of all a few words
  33. about the term “plugin”. Unfortunately, it's often used to define
  34. related but different things. Plugin is used to name:</FONT></P>
  35. <UL>
  36. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>dynamic library,
  37. containing code to be loaded as plugin (often called plugin module)
  38. and stored in $FIREBIRD/plugins directory;</FONT></P>
  39. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>code implementing
  40. plugin – slightly different from the library cause single dynamic
  41. library may contain code for more than one plugin;</FONT></P>
  42. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>plugin's factory - an
  43. object created by that code (pure virtual C++ class), creating
  44. plugin instances on Firebird request;</FONT></P>
  45. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>instance of plugin,
  46. created by factory.</FONT></P>
  47. </UL>
  48. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>In most cases it's clear
  49. from context what “plugin” do we talk about. If not it will be
  50. clarified explicitly.</FONT></P>
  51. <P STYLE="margin-bottom: 0in"><BR>
  52. </P>
  53. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Firebird plugin
  54. architecture supports creation of any plugin type for any purpose –
  55. but first of all this requires changes in Firebird code. Plugin can't
  56. be added at any desired point “magically”. To be able to have
  57. plugin (for example) encrypting database on the disk, Firebird code
  58. should be prepared for it – must have a point from which plugin is
  59. called. I.e. each version has a fixed set of plugins which are
  60. supported. To add one more type, first of all Firebird code should be
  61. modified. What DOES our plugin architecture – it helps to make both
  62. adding new types of plugins and writing plugin code simple and as
  63. universal between plugins as possible.</FONT></P>
  64. <P STYLE="margin-bottom: 0in"><BR>
  65. </P>
  66. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Firebird 3 has a following
  67. set of plugin types:</FONT></P>
  68. <UL>
  69. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>user authentication
  70. related: AuthServer (validates user's credentials on server when use
  71. logins), AuthClient (prepares credentials to be passed over the
  72. wire) and AuthUserManagement (maintains a list of users on a server
  73. in a form, known to AuthServer);</FONT></P>
  74. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>ExternalEngine
  75. controls use of various engines, see README.external_routines;</FONT></P>
  76. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>Trace plugin is known
  77. from Firebird 2.5, but a way how it interacts with engine was
  78. changed to match new generic rules; </FONT>
  79. </P>
  80. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>encrypting plugins
  81. are for network (WireCrypt) and disk (DbCrypt), there is also helper
  82. plugin KeyHolder, which is used to help maintaining secret key(s)
  83. for DbCrypt;</FONT></P>
  84. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>and probably the most
  85. important kind – Provider. Firebird 3 supports providers as a kind
  86. of plugins, which has nothing outstanding compared with others. See
  87. README.Providers for more information about providers. </FONT>
  88. </P>
  89. </UL>
  90. <P STYLE="margin-bottom: 0in"><BR>
  91. </P>
  92. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Plugins are using a set of
  93. special Firebird interfaces (see Using_OO_API for details). All
  94. plugin-specific interfaces are reference counted, i.e. have
  95. explicitly controlled lifetime. Interfaces are declared in
  96. Interfaces.h include file. There is an example of writing plugin
  97. module – fbSampleDbCrypt. It does not perform any actual encryption
  98. – just a sample of how to write plugin. Complete instruction of how
  99. to write plugins is out of this document's scope. Here is provided a
  100. short list of plugin features:</FONT></P>
  101. <UL>
  102. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>plugin may be written
  103. using any language, supporting function pointers in a
  104. structure/record (or at least arrays of function pointers);</FONT></P>
  105. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>currently interfaces
  106. description is available only for C++ and Pascal(Delphi), you will
  107. need to write your interfaces declarations generator for your
  108. language if you need something else;</FONT></P>
  109. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>like with UDFs you
  110. are free to add any reasonable code to your plugin, but pay
  111. attention to word “reasonable” - asking a question from plugin
  112. at server's console is hardly good idea;</FONT></P>
  113. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>it's OK to use
  114. Firebird API calls in your plugin if needed (for example, default
  115. authentication server and user manager are using Firebird database
  116. to store accounts);</FONT></P>
  117. <LI><P STYLE="margin-bottom: 0in"><FONT SIZE=4>additionally Firebird
  118. provides a set of interfaces, helping you to configure your plugins
  119. (certainly, you are not forced to use them – plugin is generic
  120. code, which may use any way of providing configuration information,
  121. but with standard tools you get common for the rest of Firebird
  122. configuration style and sooner of all save you efforts).</FONT></P>
  123. </UL>
  124. <P STYLE="margin-bottom: 0in"><BR>
  125. </P>
  126. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Configuring plugins has 2
  127. parts – first, engine should be instructed what plugins it should
  128. load, and next plugins themselves sometimes need some configuration.
  129. What plugins to be loaded is defined in main configuration file –
  130. firebird.conf for each type of plugin. Like any other value in
  131. firebird.conf the have defaults:</FONT></P>
  132. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>AuthServer = Srp</I></FONT></P>
  133. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>AuthClient = Srp,
  134. Win_Sspi, Legacy_Auth</I></FONT></P>
  135. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>UserManager = Srp</I></FONT></P>
  136. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>TracePlugin = fbtrace</I></FONT></P>
  137. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Providers =
  138. Remote,Engine14,Loopback</I></FONT></P>
  139. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>WireCryptPlugin = Arc4</I></FONT></P>
  140. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>This provides normal
  141. operation in server, client and embedded cases. If you want to add
  142. other plugins, you must mention them in firebird.conf – except
  143. other this is security measure to avoid loading unknown code. But
  144. what does for example fbtrace mean here? Is it a name of dynamic
  145. library to load? In trivial case yes, but exact answer is more
  146. complicated.</FONT></P>
  147. <P STYLE="margin-bottom: 0in"><BR>
  148. </P>
  149. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>As it was already
  150. mentioned, single plugin module may implement more than single
  151. plugin. Moreover, single plugin may have at the same time more than
  152. one configuration – and for each configuration separate plugin's
  153. factory is created. Each of this 3 objects (module – implementation
  154. – factory) has it's own name. Name of a module is a file name of
  155. dynamic library. Plugin implementation's name is one given to it by
  156. plugin developer and hard-coded inside module. Factory's name by
  157. default equals to plugin implementation's name (and it's factory name
  158. which is actually used in firebird.conf). Certainly in typical case,
  159. module contains one plugin, and that plugin works with only one
  160. configuration, and all 3 names are equal, and no more configuration
  161. is needed – for example libEngine14.so or Engine14.dll contains
  162. implementation of provider Engine14, and nothing else except record </FONT>
  163. </P>
  164. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Providers = Engine14</FONT></P>
  165. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>in firebird.conf is needed
  166. to load it. But if you have something complex – configuration file
  167. plugins.conf will help you to have such plugin factories which you
  168. really want.</FONT></P>
  169. <P STYLE="margin-bottom: 0in"><BR>
  170. </P>
  171. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>File plugins.conf has 2
  172. types of records – config and plugin. Plugin record is a set of
  173. rules for plugin's loading and activating. Plugin record has the
  174. following format:</FONT></P>
  175. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Plugin = PlugName ##
  176. this is name to be referenced in firebird.conf</I></FONT></P>
  177. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>{</I></FONT></P>
  178. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Module = LibName ##
  179. name of dynamic library</I></FONT></P>
  180. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>RegisterName = RegName
  181. ## name given to plugin by it's developer</I></FONT></P>
  182. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Config = ConfName ##
  183. name of config record to be used</I></FONT></P>
  184. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>ConfigFile = ConfFile
  185. ## name of a file, containing plugin's configuration</I></FONT></P>
  186. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>}</I></FONT></P>
  187. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>i.e. when plugin PlugName
  188. is needed Firebird loads library LibName, finds in it plugin
  189. registered with name RegName and passes it configuration from config
  190. record ConfName or config file ConfFile (config record is used if
  191. both are given). Each parameter in this record may be missing, in
  192. that case the default PlugName is used. The only exception is
  193. ConfigFile – by default, file with same name as module's dynamic
  194. library but .conf extension is used. ConfigFile is expected to have
  195. format Key=Value (like other Firebird configuration files), same
  196. format is used for plugin record:</FONT></P>
  197. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Config = ConfName</I></FONT></P>
  198. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>{</I></FONT></P>
  199. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Key1 = Value1</I></FONT></P>
  200. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Key2 = Value2</I></FONT></P>
  201. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>...</I></FONT></P>
  202. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>}</I></FONT></P>
  203. <P STYLE="margin-bottom: 0in"><BR>
  204. </P>
  205. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Let's have a sample.
  206. Suppose some clients of your server trust wire encryption from one
  207. vendor and others – from another one (and have different licenses
  208. for appropriate client parts), but each vendor calls his plugin
  209. BestCrypt. Certainly, first of all you have to rename libraries to
  210. something like Crypt1 and Crypt2 – one can't have 2 files with same
  211. name in one directory. But after it, modules stop to load
  212. automatically – they are not named BestCrypt any more. To fix it,
  213. plugins.conf should contain something like this:</FONT></P>
  214. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Plugin = Crypt1</I></FONT></P>
  215. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>{</I></FONT></P>
  216. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>RegisterName =
  217. BestCrypt</I></FONT></P>
  218. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>}</I></FONT></P>
  219. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>Plugin = Crypt2</I></FONT></P>
  220. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>{</I></FONT></P>
  221. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>RegisterName =
  222. BestCrypt</I></FONT></P>
  223. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>}</I></FONT></P>
  224. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Module names will be
  225. automatically set to Crypt1 and Crypt2 and found. Certainly you may
  226. add some configuration info for plugins if needed. Also don't forget
  227. to modify firebird.conf:</FONT></P>
  228. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>WireCryptPlugin =
  229. Crypt1, Crypt2</I></FONT></P>
  230. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>After it server will
  231. automatically select appropriate plugin to talk to client.</FONT></P>
  232. <P STYLE="margin-bottom: 0in"><BR>
  233. </P>
  234. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Another sample may be
  235. found in distributed with Firebird plugins.conf. One of standard
  236. plugins, UDR, is written to use non-default configuration. Therefore
  237. module name and one configuration parameter are given explicitly.</FONT></P>
  238. <P STYLE="margin-bottom: 0in"><BR>
  239. </P>
  240. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Questions and answers.</FONT></P>
  241. <P STYLE="margin-bottom: 0in"><BR>
  242. </P>
  243. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Q. There are plugins named
  244. Remote, Loopback, Arc4 in default configuration, but no libraries
  245. with such names. How do they work?</FONT></P>
  246. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>A. That are so-called
  247. 'built-in' plugins. They are built into fbclient library, and
  248. therefore are always present. Arrival of such plugins is due to old
  249. ability to distribute windows Firebird client as single dll. It was
  250. decided to keep such feature at least for a case when standard set of
  251. plugins is used.</FONT></P>
  252. <P STYLE="margin-bottom: 0in"><BR>
  253. </P>
  254. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Q. What do names of Srp
  255. and Arc4 plugins mean?</FONT></P>
  256. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>A. Srp implements Secure
  257. Remote Passwords protocol which is default way of authenticating
  258. users in Firebird 3. It has efficient password’s length equal to 20
  259. bytes, resistant to most of attacks (including man in the middle) and
  260. does not require exchanging any keys between client and server to
  261. work. Arc4 means Alleged RC4 - an implementation of RC4 cypher. The
  262. advantage of SRP is that it can generate unique cryptographically
  263. strong key on both client and server and it's impossible to guess it
  264. capturing data transferred over the wire during password validation
  265. by SRP. That key is used after SRP handshake by Arc4, which makes
  266. wire encryption secure without need to exchange any keys between
  267. client and server explicitly.</FONT></P>
  268. <P STYLE="margin-bottom: 0in"><BR>
  269. </P>
  270. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Q. And what do Win_Sspi
  271. and Legacy_Auth mean?</FONT></P>
  272. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>A. Windows SSPI was used
  273. since FB 2.1 for windows trusted authentication. Legacy_Auth is
  274. compatibility plugin. It's enabled by default on client to let it
  275. connect to pre-FB3 servers. (Yes – it still transfers almost plain
  276. passwords over the wire. Compatibility...) On server it works with
  277. security database from FB 2.5, and should be avoided except cases
  278. when you understand well what are you doing. To use Legacy_Auth on
  279. server you should set lower level of network traffic encryption in
  280. firebird.conf:</FONT></P>
  281. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>WireCrypt = Enabled</I></FONT></P>
  282. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>or in the worst case:</FONT></P>
  283. <P STYLE="margin-bottom: 0in"><FONT SIZE=4><I>WireCrypt = Disabled</I></FONT></P>
  284. <P STYLE="margin-bottom: 0in"><BR>
  285. </P>
  286. </BODY>
  287. </HTML>