Use entities and add overview of directories
[Samba/gebeck_regimport.git] / docs / docbook / devdoc / modules.sgml
blobc43e8a91180983c01f3544c48471bf0c0172013b
1 <chapter id="modules">
2 <chapterinfo>
3 &author.jelmer;
4 <pubdate> 19 March 2003 </pubdate>
5 </chapterinfo>
7 <title>Modules</title>
9 <sect1>
10 <title>Advantages</title>
12 <para>
13 The new modules system has the following advantages:
14 </para>
16 <simplelist>
17 <member>Transparent loading of static and shared modules (no need
18 for a subsystem to know about modules)</member>
19 <member>Simple selection between shared and static modules at configure time</member>
20 <member>"preload modules" option for increasing performance for stable modules</member>
21 <member>No nasty #define stuff anymore</member>
22 <member>All backends are available as plugin now (including pdb_ldap and pdb_tdb)</member>
23 </simplelist>
24 </sect1>
26 <sect1>
27 <title>Loading modules</title>
29 <para>
30 Some subsystems in samba use different backends. These backends can be
31 either statically linked in to samba or available as a plugin. A subsystem
32 should have a function that allows a module to register itself. For example,
33 the passdb subsystem has:
34 </para>
36 <para><programlisting>
37 BOOL smb_register_passdb(const char *name, pdb_init_function init, int version);
38 </programlisting></para>
40 <para>
41 This function will be called by the initialisation function of the module to
42 register itself.
43 </para>
45 <sect2>
46 <title>Static modules</title>
48 <para>
49 The modules system compiles a list of initialisation functions for the
50 static modules of each subsystem. This is a define. For example,
51 it is here currently (from <filename>include/config.h</filename>):
52 </para>
54 <para><programlisting>
55 /* Static init functions */
56 #define static_init_pdb { pdb_mysql_init(); pdb_ldap_init(); pdb_smbpasswd_init(); pdb_tdbsam_init(); pdb_guest_init();}
57 </programlisting></para>
59 <para>
60 These functions should be called before the subsystem is used. That
61 should be done when the subsystem is initialised or first used.
62 </para>
64 </sect2>
66 <sect2>
67 <title>Shared modules</title>
69 <para>
70 If a subsystem needs a certain backend, it should check if it has
71 already been registered. If the backend hasn't been registered already,
72 the subsystem should call smb_probe_module(char *subsystem, char *backend).
73 This function tries to load the correct module from a certain path
74 ($LIBDIR/subsystem/backend.so). If the first character in 'backend'
75 is a slash, smb_probe_module() tries to load the module from the
76 absolute path specified in 'backend'.
77 </para>
79 <para>After smb_probe_module() has been executed, the subsystem
80 should check again if the module has been registered.
81 </para>
83 </sect2>
84 </sect1>
86 <sect1>
87 <title>Writing modules</title>
89 <para>
90 Each module has an initialisation function. For modules that are
91 included with samba this name is '<replaceable>subsystem</replaceable>_<replaceable>backend</replaceable>_init'. For external modules (that will never be built-in, but only available as a module) this name is always 'init_module'. (In the case of modules included with samba, the configure system will add a #define subsystem_backend_init() init_module()).
92 The prototype for these functions is:
93 </para>
95 <para><programlisting>
96 int init_module(void);
97 </programlisting></para>
99 <para>This function should call one or more
100 registration functions. The function should return non-zero on success and zero on
101 failure.</para>
103 <para>For example, pdb_ldap_init() contains: </para>
105 <para><programlisting>
106 int pdb_ldap_init(void)
108 smb_register_passdb("ldapsam", pdb_init_ldapsam, PASSDB_INTERFACE_VERSION);
109 smb_register_passdb("ldapsam_nua", pdb_init_ldapsam_nua, PASSDB_INTERFACE_VERSION);
110 return TRUE;
112 </programlisting></para>
114 <sect2>
115 <title>Static/Shared selection in configure.in</title>
117 <para>
118 Some macros in configure.in generate the various defines and substs that
119 are necessary for the system to work correct. All modules that should
120 be built by default have to be added to the variable 'default_modules'.
121 For example, if ldap is found, pdb_ldap is added to this variable.
122 </para>
124 <para>
125 On the bottom of configure.in, SMB_MODULE() should be called
126 for each module and SMB_SUBSYSTEM() for each subsystem.
127 </para>
129 <para>Syntax:</para>
131 <para><programlisting>
132 SMB_MODULE(<replaceable>subsystem</replaceable>_<replaceable>backend</replaceable>, <replaceable>object files</replaceable>, <replaceable>plugin name</replaceable>, <replaceable>subsystem name</replaceable>, <replaceable>static_action</replaceable>, <replaceable>shared_action</replaceable>)
133 SMB_SUBSYSTEM(<replaceable>subsystem</replaceable>)
134 </programlisting></para>
136 <para>Also, make sure to add the correct directives to
137 <filename>Makefile.in</filename>. <replaceable>@SUBSYSTEM_STATIC@</replaceable>
138 will be replaced with a list of objects files of the modules that need to
139 be linked in statically. <replaceable>@SUBSYSTEM_MODULES@</replaceable> will
140 be replaced with the names of the plugins to build.
141 </para>
143 <para>You must make sure all .c files that contain defines that can
144 be changed by ./configure are rebuilded in the 'modules_clean' make target.
145 Practically, this means all c files that contain <command>static_init_subsystem;</command> calls need to be rebuilded.
146 </para>
148 </sect2>
149 </sect1>
150 </chapter>