1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00
samba-mirror/lib/param
Pavel Filipenský cccf0beb9f lib/param: Don't treat a missing include file as an error in handle_include().
Same fix as in commit 09d7690

'samba-tool domain provision -d10' fails if the included file does not
exist:

lpcfg_load: refreshing parameters from /etc/samba/smb.conf
Processing section "[global]"
Can't find include file /etc/samba/usershares.conf
pm_process() returned No
ERROR: Unable to load default file
  File "/usr/lib64/python3.12/site-packages/samba/netcmd/domain/provision.py", line 183, in run
    lp = sambaopts.get_loadparm()
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/samba/getopt.py", line 282, in get_loadparm
    self._lp.load_default()

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15698

Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>

Autobuild-User(master): Martin Schwenke <martins@samba.org>
Autobuild-Date(master): Wed Aug 21 00:04:19 UTC 2024 on atb-devel-224

(cherry picked from commit ffc75c569c)

Autobuild-User(v4-20-test): Jule Anger <janger@samba.org>
Autobuild-Date(v4-20-test): Thu Aug 22 09:01:31 UTC 2024 on atb-devel-224
2024-08-22 09:01:30 +00:00
..
loadparm_server_role.c CVE-2020-25717: Add FreeIPA domain controller role 2021-11-09 19:45:33 +00:00
loadparm.c lib/param: Don't treat a missing include file as an error in handle_include(). 2024-08-22 09:01:30 +00:00
loadparm.h s4:ldap_server: add support for tls channel bindings 2024-07-09 09:54:15 +00:00
param_table.c s4:ldap_server: add support for tls channel bindings 2024-07-09 09:54:15 +00:00
param.h VERSION: move COPYRIGHT_STARTUP_MESSAGE as SAMBA_COPYRIGHT_STRING into version.h 2023-12-15 10:44:42 +00:00
README lib:param: Fix code spelling 2023-04-11 09:06:36 +00:00
s3_param.h lib:param: Set a memory context for the globals if not initialized yet 2023-10-25 22:23:37 +00:00
samba-hostconfig.pc.in lib/param move source4 param code to the top level 2011-10-11 13:41:34 +11:00
util.c lib: Avoid a tdb handle leak 2023-09-25 19:01:34 +00:00
wscript_build lib:param: Add lp(cfg)_weak_crypto() 2020-03-19 20:46:41 +00:00

libsamba-hostconfig
-------------------

This directory contains "libsamba-hostconfig". 

The libsamba-hostconfig library provides access to all host-wide configuration
such as the configured shares, default parameter values and host secret keys.


Adding a parameter
------------------

To add or change an smb.conf option, in general you only have to add
the documentation to docs-xml/smbdotconf, or change it.
In addition to that, if special defaults are needed, the functions
loadparm_init() in lib/param/loadparm.c and/or init_globals() in
source3/param/loadparm.c need to be adapted accordingly.
The rest is generated for you.

It is important to get the attributes right in the <samba:parameter ...>
tag of the xml files.  These determine the details of the generated code.

- Supported attributes are name, context, type, constant, function,
  generated_function, synonym, parm, enumlist, handler, and deprecated.
- Supported contexts are 'G' (for global) and 'S' (for share).
- Supported types are boolean, boolean-rev, boolean-auto, list,
  cmdlist, string, ustring, char, integer, bytes, octal, and enum.



Using smb.conf parameters in the code
-------------------------------------

Call the lpcfg_*() function.  To get the lp_ctx, have the caller pass
it to you.  To get a lp_ctx for the source3/param loadparm system, use:

struct loadparm_context *lp_ctx = loadparm_init_s3(tmp_ctx, loadparm_s3_helpers());

Remember to talloc_unlink(tmp_ctx, lp_ctx) the result when you are done!

To get a lp_ctx for the lib/param loadparm system, typically the
pointer is already set up by popt at startup, and is passed down from
cmdline_lp_ctx.

In pure source3/ code, you may use lp_*() functions, but are
encouraged to use the lpcfg_*() functions so that code can be made
common.


How does loadparm_init_s3() work?
---------------------------------

loadparm_s3_helpers() returns a initialised table of function
pointers, pointing at all global lp_*() functions, except for those
that return substituted strings (% macros).  The lpcfg_*() function
then calls this plugged in function, allowing the one function and
pattern to use either loadparm system.


There is a lot of generated code, here, what generates what?
------------------------------------------------------------

The regular format of the CPP macros in param_functions.c is used to
generate up the prototypes (mkproto.pl, mks3param_proto.pl), the service
and globals table (mkparamdefs.pl), the glue table (mmks3param.pl) and
the initialisation of the glue table (mks3param_ctx_table.pl).

I have tried combining some of these, but it just makes the scripts more
complex.

The CPP macros are defined in and expand in lib/param/loadparm.c and
source3/param/loadparm.c to read the values from the generated
structures.  They are CPP #included into these files so that the same
macro has two definitions, depending on the system it is loading into.


Why was this done, rather than a 'proper' fix, or just using one system or the other?
-------------------------------------------------------------------------------------

This was done to allow merging from both ends - merging more parts of
the loadparm handling, and merging code that needs to read the
smb.conf, without having to do it all at once.  Ideally
param_functions.c would be generated from param_table.c or (even
better) our XML manpage source, and the CPP macros would instead be
generated expanded as generated C files, but this is a task nobody has
taken on yet.