Commit graph

16221 commits

Author SHA1 Message Date
Colin Vidal
5b7445f507 effective config: specific check-names case
There are multiple check-names options provided in the default
configuration, and they must "complete" those provided by the user.
This is now handled when building the effective tree.
2025-10-29 13:55:04 -07:00
Colin Vidal
6643345a5b effective config: specific prefetch/trigger case
The prefetch statement can be overriden by the user, but the user might
specify the prefetch without the trigger value, which needs to be
pulled from the default configuration. Handle this case by directly
getting the default value if needed from the default configuration when
building the effective configuration tree.

Also take care of keeping the values inside their bounds, and simplify
the server configuration code which then just have to read effective
configuration values.
2025-10-29 13:55:04 -07:00
Colin Vidal
1f54a9107d effective config: specific dnssec-policy case
Default dnssec-policies are not overridden by user-provided ones. Add
this specific case to make sure those are kept, and also ensure that the
default dnssec-policy is always in the first position (which is an
implicit requirement in the existing implementation).

Also simplify the server configuration code, as it only needs to build
the list of dnssec-policy based on the effective config list.
2025-10-29 13:55:04 -07:00
Colin Vidal
27c4f68dcc effective config: specific view cases
User specified views don't override default views. In particular, the
_bind/CH view is still active. However, the order is important: if the
user defines a foo/CH view, it must be able to override _bind/CH by
matching clients first (this is how the view is documented).

The server configuration code is now simpler; it only has to build the
views based on the effective view list, and only creates the _default
view if there are no explicit views created by the user.
2025-10-29 13:55:04 -07:00
Colin Vidal
a99573d648 effective config: specific options/acl cases
Implement the specific rules of ACL inheritance when buiding the
effective configuration. As those rules are directly implemented in the
configuration tree, they are removed from `apply_configuation`.
2025-10-29 13:55:04 -07:00
Colin Vidal
9d477aa3d4 add cfg_effective_config() API
Add the entry point of the logic to merge the user and the default
configuration, called cfg_effective_config(). This function takes a user
configuration and a default configuration. It internally clones the user
configuration tree, then walks through the clauses recursively applying
default values if they are missing.

The newly built configuration tree, called the effective configuration
tree, is then returned.

Currently this is just the basic mechanism which is implemented (i.e.
enable to walk from clause to clause, goes into a nested clause, and so
on). The next commits will introduce the implementation of
clause-specific merge functions in order to preserve the existing
named.conf semantics.
2025-10-29 13:55:04 -07:00
Colin Vidal
a9a0af4359 add an optional merge method on cfg_clausedef_t
In order to handle specific cases when merging configurations (i.e.
some specific clauses which require specific handling, not just
overriding values for instance), the cfg_clausedef_t includes an
optional merge method.

The merge function is NULL by default. If it is defined for a given
clause, and this clause is defined in both the user and default
configurations, the merge function is then called with both the user and
default clause instances. It's up the the implementation of that function
do to anything needed to keep the correct named.conf semantic.
2025-10-29 13:55:04 -07:00
Colin Vidal
473bbeb54b add helper API calls to manipulate maps and lists
cfg_map_addclone() is a variant of cfg_map_add which internally clones
an object and adds it to a map. It ensures that the object is an
implicit list if the map clause has the CFG_CLAUSEFLAG_MULTI set

cfg_list_addclone() clones a list (internally cloning each individual
element) and appends or preprends it to an existing target list.

Both of these will be needed to merge the default configuration
with the user configuration.
2025-10-29 13:55:04 -07:00
Colin Vidal
35c8768fde parser firstclause/nextclause API changes
In order to make upcoming configuration tree changes easier, the
cfg_map_firstclause() and _nextclause() functions have been changed
to return the clause itself rather than only the clause name.
2025-10-29 13:55:04 -07:00
Evan Hunt
cd921cc7ef fix a "max-cache-size" configuration bug
"max-cache-size default;" is allowed, according to the documentation
and the parser, but when it's configured, named crashes due to an
INSIST that the only legal string value is "unlimited". this has
been fied.

the configuration has also been simplified. previously, we checked for
max-cache-size in view and options, then determined whether to look in
the global default options based on whether the view had recursion set.
the default value set there was only applicable to views with recursion.
now, the default is an explicit "default", which affects views with
and without recursion in different ways.

the cfg type for "max-cache-size" has been changed from
cfg_type_sizeorpercent to cfg_type_maxcachesize.
2025-10-29 18:28:12 +00:00
Mark Andrews
012a47476d Fix "shutdown system test crashed in dns_dispatchmgr_getblackhole"
While shutting down view->dispatchmgr is no longer valid.  Attach
to it and when creates a fetch context and use that pointer instead
of view->dispatchmgr.  Use dns_view_getdispatchmgr to do the attaching
as view->dispatchmgr is it managed using rcu.
2025-10-28 09:02:12 +11:00
Colin Vidal
cc91a5d1ec introduce cfg_obj_clone to clone a config tree
Introduce `cfg_obj_clone` which takes a `cfg_obj_t` node and clones it.
it allocates a new node, copies its scalar values and recursively
allocates child nodes, copying their scalar values as well and so on.

Internally, a new method `cfg_copyfunc_t` copy is added in `cfg_rep_t`,
which enables implementing a copy function specific for each
representation type a node can hold.
2025-10-27 21:33:18 +01:00
Mark Andrews
3594ad04e5 Remove unnecessary NULL checks in parser.c
In cfg_parse_buffer and cfg_parse_file 'pctx' was being checked
for being non-NULL when it was guarenteed to be non-NULL.  This
raised Coverity issues ID 637688 and ID 637689.
2025-10-28 06:28:52 +11:00
Ondřej Surý
871bce312b Fix assertion failure from arc4random_uniform with invalid limit
When the arc4random_uniform() is called on NetBSD with upper_bound that
makes no sense statistically (0 or 1), the call crashes the calling
program.  Fix this by returning 0 when upper bound is < 2 as does Linux,
FreeBSD and NetBSD.  (Hint: System CSPRNG should never crash.)
2025-10-24 22:20:43 +02:00
Evan Hunt
2877b57735 restore the former change_directory logging
change_directory() now lives in libisccfg. when it was moved,
the logging behavior changed: previously it had been logged
by named only, in the general logging category, and without the
named.conf filename and line number. it was not logged by
named-checkconf. this behavior has now been restored.
2025-10-23 13:01:31 -07:00
Colin Vidal
6b5246b3d2 ensure parser/cfg_obj log includes the line number
Since the `file` property of cfg_obj_t can now be null (instead of
"none"), cfg_obj_t would take a fallback flow where the line was not
logged. This fixes it.

Also, add the log line when parser_complain is called and `file` is null
(which might happend when parsing buffer only) to also include the line
number.
2025-10-23 13:01:11 -07:00
Evan Hunt
0db377da57 simplify and regularize cfg_* functions
- several functions that can no longer fail have been changed to
  type void, and unnecessary 'cleanup' sections were removed
- renamed cfg_create_obj() to cfg_obj_create(), and cfg_create_tuple()
  to cfg_tuple_create(), to match typical nomenclature.
- fixed a memory leak bug, in which an element could be removed
  from a list in delete_zoneconf() without being freed. this has
  been addressed by adding a cfg_list_unlink() function.
  list elements are now allocated based on the list they will
  be stored in, using the same mctx.
2025-10-23 13:01:10 -07:00
Evan Hunt
4f7f2dae59 simplify cfg_parser API
- the cfg_parser_create() and cfg_parser_destroy() calls are no
  longer used outside parser.c, so they are now static functions
- cfg_parser_attach(), cfg_parser_reset(), and cfg_parser_setflags()
  are no longer used at all, and have been removed.
- cfg_parser_mapadd() has been renamed for clarity to cfg_map_add().
2025-10-23 13:01:09 -07:00
Colin Vidal
d03f6e6fd4 cfg_parse_ functions internally handle the parser
Instead of (1) allocating a parser, (2) parsing a file/buffer then (3)
freeing the parser, the parser is now internally created/destroyed from
within the `cfg_parse_*` functions. This simplifies a lot the use cases,
especially around the error cases where the parser needs to be freed in
a cleanup goto.

The only trick was the parser callback mechanism, which would previously
have been set up between steps 1 and 2.  Since it's never been used for
any purpose other than the "directory" option, the chdir call has now
been moved inside the parser and the generic callback mechanism has been
removed, replacing CFG_CLAUSEFLAG_CALLBACK with CFG_CLAUSEFLAG_CHDIR.
2025-10-23 13:01:08 -07:00
Evan Hunt
0191ba5540 store the zone configuration object in the zone
when configuring a zone, we can now save the zone's configuration
object in the zone itself by calling dns_zone_setcfg().  this can
then be used by "rndc showzone" to print the zone's configuration,
which is simpler than searching for it using the new-zones
configuration, and allows it to work even if "allow-new-zones"
is disabled.
2025-10-23 13:01:06 -07:00
Evan Hunt
6de1d0dbc4 update cfg_obj_attach/destroy
now that cfg_obj_destroy() has been simplified, we can use the
ISC_REFCOUNT macros to declare cfg_obj_attach() and _detach().
2025-10-23 13:01:02 -07:00
Colin Vidal
7706f5acec remove parser context field from cfg_obj_t
cfg_obj_t doesn't store a pointer to its a parser context anymore,
and does not depend on the parser's lifecycle. Instead, it stores a
reference to its own memory context (and in principle, each node
could have different memory context). This also slightly simplifies
the _destroy API as there is no need to pass a context through it
anymore.
2025-10-23 12:59:58 -07:00
Colin Vidal
0d8c4044ab cfg_obj_t file is now a refcounted string
In order to reduce the lifecycle dependency of a `cfg_obj_t` on its
parser, the `file` field needs its own reference count, so it isn't
deleted when the parser is.  It is now stored as a subsidiary
`cfg_obj_t` object of type string.
2025-10-23 10:57:45 -07:00
Michał Kępień
c2a672bbae Merge tag 'v9.21.14' 2025-10-22 18:13:34 +02:00
Michal Nowak
d91e8ed575 Use SET_IF_NOT_NULL in isc__nm_base64* 2025-10-22 12:50:55 +02:00
Mark Andrews
4c5d48926a Don't log spurious error "bad key type" in findmatchingkeys 2025-10-22 09:42:44 +11:00
Aram Sargsyan
49b7ce9a54 Fix dnssec-keygen key collision checking for KEY rrtype keys
When generating a new key, dnssec-keygen checks for possible
key ID collisions with existing keys. The dnssec.c:findmatchingkeys()
function, which is supposed to get the list of the existing keys,
fails to do that for the existing KEY rrtype keys (i.e. generated
using 'dnssec-keygen -T KEY') because it doesn't pass down to the
dst_key_fromnamedfile() -> dst_key_read_public() functions the type
of the keys it's interested in. Fix the issue by introducing a new
function parameter which tells in which type of keys the caller is
currently interested in.
2025-10-22 09:42:43 +11:00
Michal Nowak
c56785659e Use clang-format-21 to update formatting 2025-10-21 09:34:29 +02:00
Evan Hunt
34314915e2 simplify dns_dumpctx API
the functions dns_dumpctx_db() and dns_dumpctx_version() are used in
only one place, to get the serial number of the version being dumped.
it's simpler to expose the serial number through its own call,
dns_dumpctx_serial(), and remove the others.
2025-10-20 17:48:18 -07:00
Colin Vidal
c50ace654d check memory context validity before mem_destory
Add a magic number check to ensure the memory context validity before
destorying it.

This check is needed now as it was done before implicitly when
isc_mem_inuse was called, but isc_mem_inuse is now called later (to be
able to dump the outstanding allocations).
2025-10-19 09:05:09 +02:00
Colin Vidal
9f4ff7dec4 mem: checkfree assertion after debug list dump
When a memory context is destroyed, if the `checkfree` property is set,
the program assert there is no remaining allocation. If there are and
assertions are enabled, the program immediately stops.

However, if memory trace/record debug is enabled, the dump of
outstanding allocation won't be printed as it is done after the
no remaining allocation assertion check.

This moves the no remaining allocation assertion check after the dump of
outstanding allocations, so it is still possible to figure out what's
still allocated by this memory context.
2025-10-19 09:05:09 +02:00
Evan Hunt
43f53b5010 report when zone reload already in progress
if a zone reload is already in progress when 'rndc reload <zone>' is
run, currently the message returned in "zone reload queued", which
is correct, but it's identical to the message returned when a reload
was *not* in progress, so the user can't easily tell what happened.
a user could reload a zone twice and not realize that only one
reload actually took place.

this has been addressed by changing the message returned to
"zone reload was already queued".

a new result code ISC_R_LOADING has been added to signal this
condition, taking the place of ISC_R_RELOAD, which was obsolete
and has been removed.
2025-10-17 20:36:18 +00:00
Ondřej Surý
7b26176c46
Fix the assertion failure in the selfsigned DNSKEY handling
The selfsigned_dnskey() function can now return all the return codes
that dns_dnssec_keyfromrdata() can return and this would cause an
assertion failure as we were not expecting new isc_result_t codes.
2025-10-17 14:39:43 +02:00
Evan Hunt
414bc3f27d Ensure correct result from check_signer()
It was possible for the result to be overwritten after a
validation failure, causing check_signer() to return success
when it should have returned an error.

Co-Authored-By: Ondřej Surý <ondrej@isc.org>
2025-10-15 22:05:52 -07:00
Mark Andrews
e5ceda617d Fix parse_rr in lib/dns/skr.c was failing to reset the comments
If dns_name_fromtext failed or the subsequent dns_name_compare
failed the lexer's comments state wasn't cleaned up.
2025-10-14 11:26:45 +11:00
Evan Hunt
a373671f5e remove "bindkeys-file" option
The bindkeys-file option was only used for testing purposes, and
has now been replaced with a "-T bindkeys=<filename>" option for
named.
2025-10-12 23:37:49 -07:00
Ondřej Surý
94b4d105e8
Apply the changes from updated set_if_not_null semantic patch 2025-10-08 17:44:50 +02:00
Colin Vidal
383f14a36f remove dns_zone_dump
Zone API `dns_zone_dump` is dead code in 9.21 (and was also dead code at
least in 9.20), removing it.
2025-10-08 08:33:33 +02:00
Michał Kępień
5d8aa1673a
Remove "tkey-domain"
Since the "tkey-domain" statement has been previously obsoleted, mark it
as ancient to make any attempts to use it a fatal error.
2025-10-06 14:14:33 +02:00
Michał Kępień
84b96df153
Remove "tkey-gssapi-credential" and related code
Since the "tkey-gssapi-credential" statement has been previously
deprecated, mark it as ancient and remove all code related to it:

  - The code processing the "tkey-gssapi-credential" statement in the
    configuration is the only user of the dst_gssapi_acquirecred() and
    dst_gssapi_releasecred() functions, so remove them along with their
    static helper functions and a backup definition of the
    GSS_KRB5_MECHANISM macro.

  - When calling gss_accept_sec_context(), pass GSS_C_NO_CREDENTIAL
    instead of the credential acquired by gss_acquire_cred().
    (Previously, NULL was passed when "tkey-gssapi-credential" was not
    specified.  Kerberos headers define GSS_C_NO_CREDENTIAL as
    (gss_cred_id_t) 0, so the logic was effectively the same, but using
    the GSS_C_NO_CREDENTIAL macro is more appropriate.)  This renders
    the 'cred' parameter for dst_gssapi_acceptctx() redundant, so remove
    it from the prototype of the latter.  (Contrary to what the
    documentation for dst_gssapi_acceptctx() claims,
    dst_gssapi_releasecred() does not need to subsequently be called to
    free the GSS-API context; a dst_gssapi_deletectx() call in
    gssapi_destroy() takes care of that when the dynamically generated
    TSIG key is destroyed.)

  - Remove the 'gsscred' member from struct dns_tkeyctx, along with its
    related dns_gss_cred_id_t typedef.

Update the relevant sections of the ARM and code comments accordingly.

This makes the "tkey-gssapi-keytab" statement the only way to set up
GSS-TSIG in named.

Remove redundant code from bin/named/tkeyconf.c while at it.
2025-10-06 13:19:50 +02:00
Ondřej Surý
4db9e5d90e
Use arc4random for CSPRNG when available
Use arc4random on platforms where available.  arc4random() provides high
quality cryptographically-secure pseudo-random numbers and is generally
recommended for application use.

The uv_random() call unfortunately uses getentropy() on platforms like
MacOS, OpenBSD or NetBSD which is not recommended for application use.
2025-10-02 13:26:07 +02:00
Ondřej Surý
cffcab9d5f
Use cryptographically-secure pseudo-random generator everywhere
It was discovered in an upcoming academic paper that a xoshiro128**
internal state can be recovered by an external 3rd party allowing to
predict UDP ports and DNS IDs in the outgoing queries.  This could lead
to an attacker spoofing the DNS answers with great efficiency and
poisoning the DNS cache.

Change the internal random generator to system CSPRNG with buffering to
avoid excessive syscalls.

Thanks Omer Ben Simhon and Amit Klein of Hebrew University of Jerusalem
for responsibly reporting this to us.  Very cool research!
2025-10-02 13:26:07 +02:00
Mark Andrews
2e40705c06
Retry lookups with unsigned DNAME over TCP
To prevent spoofed unsigned DNAME responses being accepted retry
response with unsigned DNAMEs over TCP if the response is not TSIG
signed or there isn't a good DNS CLIENT COOKIE.
2025-10-02 12:54:42 +02:00
Mark Andrews
a41054e9e6
Further restrict addresses that are cached when processing referrals
Use the owner name of the NS record as the bailwick apex name
when determining which additional records to cache, rather than
the name of the delegating zone (or a parent thereof).
2025-10-02 12:54:42 +02:00
Mark Andrews
fa153f791f
Tighten restrictions on caching NS RRsets in authority section
To prevent certain spoofing attacks, a new check has been added
to the existing rules for whether NS data can be cached: the owner
name of the NS RRset must be an ancestor of the name being queried.
2025-10-02 12:54:42 +02:00
Ondřej Surý
f00117a422
Fail the DNSSEC validation if matching but invalid DNSKEY is found
If a matching but cryptographically invalid key was encountered during
the DNSSEC validation, the key would be just skipped and not counted
towards validation failures.  Treat such DNSSEC keys as hard failures
and fail the DNSSEC validation immediatelly instead of continuing the
DNSSEC validation with the next DNSKEYs in the RRset.

Co-authored-by: Matthijs Mekking <matthijs@isc.org>
2025-10-02 12:31:26 +02:00
Colin Vidal
62002cfa9c rename ns_pluginregister_ctx_t into ns_pluginctx_t
The type `ns_pluginregister_ctx_t` was initially added to pass plugin
contextual data when the plugin is registered, but this is also now
passed into `plugin_check`. Furthermore, those various data are not
specific to the registration in particular. Rename the type into
`ns_pluginctx_t` for clarity.
2025-10-01 20:20:48 +02:00
Matthijs Mekking
4a0c829584 Minor refactor of dst code
Convert the defines to enums. Initialize the tags more explicitly and
less ugly.
2025-10-01 12:25:53 +00:00
Colin Vidal
72541880f2 Share reverse (ARPA) domain names
Names for reverse resolution are now shared and accessible from
dns/name.h header as those are used by ptr_12.c and byaddr.c files.

(Also, for consistency, move deprecated ip6.int. name in name.h, even
though it is used only by ptr_12.c).
2025-10-01 12:16:05 +02:00
Colin Vidal
b4568a85c1 add API to parse and extract IP from PTR name
Add an API to parse and extract either an IPv4 or IPv6 address from
a name using the reverse format. It takes care of family detection,
and returns a generic error in case of syntax error.
2025-10-01 12:16:05 +02:00