Commit graph

2260 commits

Author SHA1 Message Date
Matthew Wild
bca60e609d util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Not necessarily a fix, but may give us more information about failure cases.
2024-12-20 14:21:02 +00:00
Kim Alvefur
f7d0caa5ac util.prosodyctl.cert: Ensure old cert is moved out of the way
This should make it visible if the move fails
2024-08-30 17:41:40 +02:00
Kim Alvefur
bb278430cf util.xtemplate: Fix error on applying each() to zero stanzas
Backport of 1f93e4f78c53
2024-07-11 15:24:19 +02:00
Matthew Wild
655c972a7d prosodyctl check: Warn about invalid domain names in the config file
This ensures that domain names of virtual hosts and components are valid in
XMPP, and that they are encoded correctly.
2024-03-27 15:35:15 +00:00
Kim Alvefur
da3d755a15 util.prosodyctl.check: Correct modern replacement for 'disallow_s2s'
The code would have suggested adding to modules_enabled instead of
modules_disabled
2023-08-27 15:46:19 +02:00
Kim Alvefur
0fa9d6be37 util.array: Fix new() library function
Backport of ffe4adbd2af9 since new was added in the 0.12 branch
2023-07-22 16:31:05 +02:00
Kim Alvefur
683b90f871 util.prosodyctl.check: Hint about the 'external_addresses' config option 2023-07-17 14:56:57 +02:00
Kim Alvefur
43c39930c3 util.prosodyctl.check: Validate format of module list options
Should detect things like misplaced settings inside modules_enabled
2023-07-17 14:45:15 +02:00
Kim Alvefur
3f81654a66 util.prosodyctl.check: Get some config options via minimal moduleapi #896
The module API has certain coercion features that are useful.

Fixes traceback reported in #1812 and other duplicates
2023-07-17 14:03:13 +02:00
Kim Alvefur
cbed7dfdf5 util.array: Expose new() on module table
For consistency with other utils.

Consistency is good.
2023-06-10 12:14:12 +02:00
Kim Alvefur
e4d5c15396 util.prosodyctl.check: Fix error where hostname can't be turned into A label
Where gethostname or tohostname returns an invalid name, e.g. containing
underscores or something, to_ascii would reject this and return nil,
which triggers an error in the dns lookup.

Reported by prova2 in the chat, for whom tohostname returned a long name
containing underscores.
2023-05-31 14:08:19 +02:00
Kim Alvefur
57c3771614 util.error: Fix error on conversion of invalid error stanza, fix #1805
Error stanzas should have an <error> element, but if you pass a
stanza without one to util.error.from_stanza() it triggers an attempt to
index a nil value, which this patch avoids.

In the conditional, it should be safe to assume error_tag is non-nil
since condition can't have those values then.
2023-04-19 11:32:53 +02:00
Kim Alvefur
9c49ca70fd util.prosodyctl.check: Suggest 'http_cors_override' instead of older CORS settings
The cross_domain_* settings were added here prior to http_cors_override
being added back in 17d87fb2312a, so for a time there was no
replacement, but now there is.
2023-02-22 22:27:42 +01:00
Kim Alvefur
435e008568 util.startup: Close state on exit to ensure GC finalizers are called
Ensures a last round of garbage collection and that finalizers are
called. Fixes things like proper closing of SQLite3 state.

There are more calls to os.exit() but most of them exit with an error or
in a case where a final GC sweep might not matter as much.

It would be nice if this was the default.

Calling util.statup.exit() everywhere may be sensible, but would be more
involved, requiring imports everywhere.
2023-01-22 14:45:47 +01:00
Kim Alvefur
7c302e9c4c util.prosodyctl.shell: Close state on exit to fix saving shell history
This ensures a last round of garbage collection and finalizers, which
should include flushing the readline history file.

Test procedure:
```
$ ./prosodyctl shell
prosody> s2s:show() -- any command that is not the last in history
... output
prosody> bye
$ ./prosodyctl shell
prosody> ^P
```

After this, the shell prompt should contain the last command from before
the "bye". Before this patch, recent history is gone most of the time.
2023-01-22 14:42:07 +01:00
Kim Alvefur
c9fb0c2cab prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Existing such records may cause timeouts or errors in clients and
servers trying to connect, despite prosodyctl check saying all is well
2023-01-14 05:47:47 +01:00
Kim Alvefur
63fde85044 Merge 0.11->0.12 2022-12-12 07:07:13 +01:00
Kim Alvefur
4fa3808e8d util.stanza: Allow U+7F
Allowed by XML despite arguably being a control character.

Drops the part of the range meant to rule out octets invalid in UTF-8
(\247 starts a 4-byte sequence), since UTF-8 correctness is validated by
util.encodings.utf8.valid().
2022-11-22 23:56:01 +01:00
Matthew Wild
d4daf40caa util.json: Accept empty arrays with whitespace (fixes #1782) 2022-11-04 12:26:10 +00:00
Kim Alvefur
bab0635179 util.startup: Ensure import() is available in prosodyctl (thanks keyzer)
Fixes error in mod_authz_internal due to import() being unavailable as
it was only loaded in Prosody proper
2022-10-20 16:31:18 +02:00
Kim Alvefur
bca11bfc73 util.jsonschema: Use same integer/float logic on Lua 5.2 and 5.3
Fixes test case type.json:0:1 covering treatment of 1.0 as an integer
according to the JSON definition
2022-10-09 15:42:25 +02:00
Kim Alvefur
060dc12013 util.jsonschema: Fix Lua 5.2 integer compat
math.type() is unavailable before Lua 5.3 so this should use the compat
function added at the top
2022-10-09 15:38:36 +02:00
Kim Alvefur
f6727510da util.stanza: Return nil instead of nothing (fix test with luassert >=1.9)
Due to a change in luassert, a dependency luassert of the Busted test
framework, returning nothing is no longer treated as not falsy.
2022-09-15 11:05:21 +02:00
Kim Alvefur
1261dfba9f luacheck: Shut up (backports 3caff1f93520, ignores module deleted in trunk) 2022-05-30 17:34:58 +02:00
Kim Alvefur
89359b70dc util.datamapper: Improve handling of schemas with non-obvious "type"
The JSON Schema specification says that schemas are objects or booleans,
and that the 'type' property is optional and can be an array.

This module previously allowed bare type names as schemas and did not
really handle booleans.

It now handles missing 'type' properties and boolean 'true' as a schema.
Objects and arrays are guessed based on the presence of 'properties' or
'items' field.
2022-07-08 17:32:48 +02:00
Kim Alvefur
e700edc50f util.jsonschema: Fix validation to not assume presence of "type" field
MattJ reported a curious issue where validation did not work as
expected. Primarily that the "type" field was expected to be mandatory,
and thus leaving it out would result in no checks being performed.
This was likely caused by misreading during initial development.

Spent some time testing against
https://github.com/json-schema-org/JSON-Schema-Test-Suite.git and
discovered a multitude of issues, far too many to bother splitting into
separate commits.

More than half of them fail. Many because of features not implemented,
which have been marked NYI. For example, some require deep comparisons
e.g. when objects or arrays are present in enums fields.

Some because of quirks with how Lua differs from JavaScript, e.g. no
distinct array or object types. Tests involving fractional floating
point numbers. We're definitely not going to follow references to remote
resources. Or deal with UTF-16 sillyness. One test asserted that 1.0 is
an integer, where Lua 5.3+ will disagree.
2022-07-08 14:38:23 +02:00
Kim Alvefur
d5e749bc8a util.startup: Fix async waiting for last shutdown steps
Observed problem: When shutting down prosody would immediately exit
after waiting for s2s connections to close, skipping the last cleanup
events and reporting the exit reason and code.

This happens because prosody.main_thread is in a waiting state and
queuing startup.shutdown is dispatched trough the main loop via
nexttick, but since the main loop was no longer running at that point it
proceeded to the end of the prosody script and exited there.
2022-06-14 16:28:49 +02:00
Kim Alvefur
d545540ae0 util.prosodyctl.check: Remove now redundant unbound config tweak
This is now done in net.unbound itself

Turning it back on in the config may still cause the problem of entries
there masking the DNS values.
2022-05-26 13:03:58 +02:00
Kim Alvefur
6a9efa5a52 util.jsonschema: Lua <5.3 compat here too 2022-05-09 22:39:05 +02:00
Kim Alvefur
d9de9b5627 util.jsonpointer: Fix Lua <5.3 compat 2022-05-09 22:36:57 +02:00
Kim Alvefur
d05af9f2b5 util.jsonpointer: Fix off-by-one in array resolution
Fixes #1753

Not known to be used anywhere
2022-05-08 18:04:50 +02:00
Kim Alvefur
f0fc620d2a util.prosodyctl.check: turn: Report lack of TURN services as a problem #1749
Rationale: It seems unlikely that someone who has not configured any
TURN service runs 'prosodyctl check turn' expecting this to be okay.
2022-05-03 19:36:17 +02:00
Matthew Wild
93347db124 util.argparse: Revise 553c6204fe5b with a different approach
The second return value is (not insensibly) assumed to be an error. Instead of
returning a value there in the success case, copy the positional arguments
into the existing opts table.
2022-04-25 15:24:56 +01:00
Matthew Wild
0eef6dde1e util.argparse: Return final 'arg' table with positional arguments for convenience
This is the same as the input table (which is mutated during processing), but
if that table was created on the fly, such as by packing `...` it's convenient
if it also gets returned from the parse function.
2022-04-25 15:09:41 +01:00
Matthew Wild
89934124b8 util.prosodyctl: check turn: ensure a result is always returned from a check (thanks eTaurus) 2022-04-13 18:46:11 +01:00
Kim Alvefur
1e2d4026f9 util.random: Test whether util.crand works before using it (fix #1734)
util.crand can be configured at compile time to use the Linux
getrandom() system call, available from Linux 3.17, but it is still
possible to load it with an older kernel lacking that system call, where
attempting to use it throws an ENOSYS error.

By testing for this on load we can fall back to /dev/urandom in this
case.
2022-04-02 16:33:27 +02:00
Matthew Wild
fdd5f22b8a prosodyctl: check config: Report paths of loaded configuration files (fixed #1729) 2022-03-28 11:41:57 +01:00
Matthew Wild
ff2a6d764e util.startup: Show error for unrecognized arguments passed to 'prosody' (fixes #1722) 2022-03-21 10:06:48 +00:00
Matthew Wild
afbef6406b prosodyctl: check turn: Fail with error if our own address is supplied for the ping test 2022-03-19 11:09:10 +00:00
Matthew Wild
d0bd1e71d9 prosodyctl: check config: Skip bare JID components in orphan check 2022-03-19 09:28:27 +00:00
Kim Alvefur
7badf61246 mod_admin_socket: Comment on LuaSocket UNIX compat code
Ref #1717
2022-03-16 19:32:17 +01:00
Kim Alvefur
8e5fec3220 mod_admin_socket: Compat for luasocket prior to unix datagram support
The "socket.unix" module exported only a function before
aa1b8cc9bc
when datagram support was added.

Fixes #1717

Thanks rsc and lucas for reporting and testing
2022-03-15 10:48:46 +01:00
Matthew Wild
681ac46aae prosodyctl: check turn: warn about external port mismatches behind NAT
Some NATs don't preserve port numbers, which can cause the TURN server's
reported relay address to be incorrect (the TURN server has no way to predict
what the external port is, so it can't be corrected in config like an IP
mismatch can).
2022-03-11 20:33:03 +00:00
Kim Alvefur
c9e223e4f7 spelling: non-existing mistakes (thanks timeless) 2022-03-07 00:35:29 +01:00
Kim Alvefur
43351d2b54 Spelling: Fix various spelling mistakes (thanks timeless)
Words, sometimes I wonder how they even work

Maybe I missed something.
2022-03-07 00:13:56 +01:00
Matthew Wild
9a86373fd1 prosodyctl: check turn: compare correct addresses for relay mismatch detection (thanks Zash) 2022-03-05 20:47:40 +00:00
Matthew Wild
046b4085cb prosodyctl: check turn: Add check for private IP returned from STUN. 2022-03-05 20:34:58 +00:00
Matthew Wild
f7adea5040 prosodyctl: check turn: improve warning text to suggest issues 2022-03-05 20:34:24 +00:00
Matthew Wild
750f3a78d5 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
As coturn when installed out of the box on Debian (because auth isn't enabled?)
2022-03-05 20:32:47 +00:00
Matthew Wild
08777eb3d6 prosodyctl: check turn: fix formatting of multiple warnings 2022-03-05 20:31:17 +00:00