Commit Graph

4969 Commits

Author SHA1 Message Date
Ian Jackson 5f46bacbb2 fs-mistruct: switch from users to pwd-grp
users is unmaintained.  pwd-grp is the crate I have just written to
replace it. In this commit:

Change the cargo dependency and imports.

Replace the cacheing arrangements.  users has a built-in cache;
pwd-grp doesn't.  Now, instead of cashing individual lookups, we cache
the trusted user and trusted gid calculation results.
This saves on some syscalls, and is also more convenient to write.
(Mocking is still done via the dependency.)

Many systematic consequential changes of details:

 * The entrypoint names to the library are different:
   pwd-grp uses the names of the corresponding Unix functions.

 * pwd-grp's returned structs are transparent, so we don't
   call accessors for .uid(), .name(), etc.

 * pwd-grp's methods are much more often fallible
   (returning io::Result<Option<...>)

 * We're using the non-UTF-8 pwd-grp API, which means we must
   use turbofish syntax in some places.

 * The mocking API is a bit different.
2023-07-14 16:02:45 +01:00
Ian Jackson bf65b7763e fs-mistrust: Introduce tempoary PwdGrpProvider alias
This allows us to change a number of trait bounds in advance, reducing
noise in the next commit.
2023-07-14 16:02:45 +01:00
Ian Jackson a6108bb9b3 fs-mistrust: impl Hash for TrustedUser and TrustedGroup (config) 2023-07-14 16:02:45 +01:00
Ian Jackson a45eefec1a fs-mistrust: users: tests: Introduce mock_users etc.
Add some wrapper functions for convenience.

The pwd-grp crate has a richer and more faithful, but not so
convenient, way of creating dummy user/group entries.  Also the type
names are all going to change.

Doing this now reduces churn.
2023-07-14 16:02:45 +01:00
Ian Jackson cdafa2ce01 fs-mistrust: users: Make several functions fallible
The actual underlying operations here *are* fallible.
The `users` crate hides those errors in several cases.

(Failures are very rare (at least unless NIS is involved), so this is
not of much practical import, but it's going to be necessary when we
use the more careful pwd-grp crate.
2023-07-14 16:02:45 +01:00
Alexander Færøy ce64ade742 Merge branch 'unused_import' into 'main'
Move an import to resolve a warning.

See merge request tpo/core/arti!1407
2023-07-14 13:35:27 +00:00
Alexander Færøy 63a3bbc33c Merge branch 'bug638' into 'main'
Stop unconditionally marking bridges as having dir info.

Closes #638

See merge request tpo/core/arti!1408
2023-07-14 13:35:04 +00:00
Nick Mathewson b8334292fb Bridges: deduplicate addresses.
Currently we list an address for a bridge twice if it is listed both
in the bridge line and the bridge descriptor. That can't be right.
2023-07-13 16:58:12 -04:00
Nick Mathewson 3f2d4f8cec Better report for any recurrence of bug #638. 2023-07-13 15:43:57 -04:00
Nick Mathewson 7a915f5454 Stop unconditionally marking bridges as having dir info.
When we implemented bridges, we added code in 08473872ab to
conditionally mark their directory info as present or not present.
But the we didn't remove the old code to mark them present
unconditionally!

Fixes #638.
2023-07-13 15:43:42 -04:00
eta 41bb03c6cc Add country codes to relays inside a NetDir
- When the `geoip` feature flag of `tor-netdir` is enabled, perform
  GeoIP lookups for all relays added to the directory and add the
  resulting country code to the `Relay` struct.
  - The GeoIP database is provided in a new
    `PartialNetDir::new_with_geoip` constructor.
- A new trait was also added to `tor-linkspec`, `HasCountryCode`, to
  enable getting this data out from other crates.

Part of onionmasq#47.
2023-07-13 17:47:00 +01:00
Nick Mathewson ce8848f348 Move an import to resolve a warning. 2023-07-13 12:33:01 -04:00
Nick Mathewson 157d134a65 Explain better why you would use build_unmanaged_channel 2023-07-13 11:51:12 -04:00
gabi-250 56d96e4253 Resolve numerous typos in `ChanMgr::build_unmanaged_channel` code 2023-07-13 15:47:05 +00:00
Nick Mathewson 6b61eec987 chanmgr: Remove now-unused (and never usable) builder() method. 2023-07-13 09:33:06 -04:00
Nick Mathewson ed455023c2 chanmgr: Document makeup and timeout behavior of our factories
Basically, it's all ChanBuilder at some point, and ChanBuilder
has a timeout.
2023-07-13 09:33:06 -04:00
Nick Mathewson 7a38d68528 chanmgr: Add an experimental build_unmanaged_channel() method.
This method will let the user construct a channel that isn't
stored or monitored by the ChanMgr.
2023-07-13 09:31:57 -04:00
gabi-250 42115116e4 Merge branch 'keymgr-integration-test' into 'main'
CI: Add client auth integration test.

Closes #954

See merge request tpo/core/arti!1399
2023-07-12 16:35:43 +00:00
Alexander Færøy 89a3d43aa6 Merge branch 'feat' into 'main'
"Fix" CI complaints about "Conversation"

See merge request tpo/core/arti!1402
2023-07-12 15:34:45 +00:00
Gabriela Moldovan c942f02dea
arti-client: Log whether the client auth keys were retrieved. 2023-07-12 16:30:06 +01:00
Saksham Mittal 7933a93d3a
Gate builder() behind experimental-api feature 2023-07-12 20:14:12 +05:30
Ian Jackson f6d5cae574 tor-circmgr: Add two possibly-needed docsrs annotations
I don't know if these are needed because the rules are not documented
afaict.  But it seems like probably they ought to be there?
2023-07-12 15:32:26 +01:00
Ian Jackson 1fa692d63d tor-proto: Conversation: drop two otiose cfg(feature)
These fns are in a feature-gated impls on feature-gated structs.
2023-07-12 15:31:30 +01:00
Nick Mathewson 1737832164 Merge branch 'channelfactory' into 'main'
Expose channel builder in order to create channels more efficiently in external code

See merge request tpo/core/arti!1374
2023-07-12 13:40:54 +00:00
Gabriela Moldovan 674fc9d7dc
arti-client: Remove outdated TODO.
These errors aren't ignored anymore.
2023-07-11 16:49:44 +01:00
Nick Mathewson bcf574cef5 Merge branch 'explain_952_fix' into 'main'
Explain the code for the #952 fix.

See merge request tpo/core/arti!1391
2023-07-11 09:53:09 +00:00
Ian Jackson 3acc2af4f3 Merge branch 'clippy-allow' into 'main'
clippy: Allow some of our existing code patterns

See merge request tpo/core/arti!1396
2023-07-11 09:37:42 +00:00
Ian Jackson 24bec4552b rng docs: Fix two links 2023-07-10 16:08:03 +01:00
Ian Jackson a0a17e4074 rng ranges: Provide examples (doctests) 2023-07-10 16:08:03 +01:00
Ian Jackson d1ed505b61 rng ranges: Forbid use of panicky Rng::gen_range
Fixes #920
2023-07-10 16:08:03 +01:00
Ian Jackson b151237a7f rng ranges: Use gen_range_infallible() for Duration::ZERO..=T 2023-07-10 16:08:03 +01:00
Ian Jackson 09f0ecaa71 rng ranges: Introduce gen_range_infallible
There are a number of places where we generate random Durations
in a range which starts at zero.

These call sites currently (i) have to write out Duration::ZERO
or equivalent, and (ii) would have to use gen_range_checked and expect
the result, even though it can be statically proven to be OK.

To make this slightly smoother, provide `GenRangeInfallible` and
`gen_range_infallible`.
2023-07-10 16:07:18 +01:00
Ian Jackson 8ae759ef95 rng ranges: Use gen_range_checked().unwrap() in test case
Ideally we would be allowed to use vanilla gen_range() here, but there
doesn't seem to be a way to allow a specific clippy-forbidden method
using #[allow] and we probably don't want to make a blanket allow.
2023-07-10 16:07:18 +01:00
Ian Jackson 332285015f rng ranges: Use gen_range_checked().expect() in obvious cases (fmt) 2023-07-10 16:07:18 +01:00
Ian Jackson 5e10805ede rng ranges: Use gen_range_checked().expect() in obvious cases
In each of these, it is locally obvious that the range is nonempty.
2023-07-10 16:07:18 +01:00
Ian Jackson 36f998b690 tor-basic-utils: retry: Use and justify gen_range_checked
delay_bounds's implementation ensures the postcondition, so the
potential p[anic in next_delay_msec cannot happen.
2023-07-10 16:07:18 +01:00
Ian Jackson 58da20b708 rng ranges: Introduce RngExt and gen_range_checked
We will use this in many places instead of gen_range.
2023-07-10 16:07:18 +01:00
gabi-250 1510cf42b7 Merge branch 'keymgr-erased-key' into 'main'
keymgr: Use Box<dyn EncodableKey> instead of Box<dyn Any>.

Closes #937

See merge request tpo/core/arti!1398
2023-07-10 15:06:34 +00:00
Gabriela Moldovan bd4955f9ed keymgr: Add semver.md. 2023-07-10 15:38:58 +01:00
Gabriela Moldovan 9cde64c2c8 keymgr: Use Box<dyn EncodableKey> instead of Box<dyn Any>.
Prompted by https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1337#note_2917701

This will make it harder to accidentally return the wrong value from
`Keystore::get` (the returned value is now at least guaranteed to
implement `EncodableKey`).

Closes #937
2023-07-10 14:41:30 +01:00
Alexander Færøy 6be6352b98 Merge branch 'conversation' into 'main'
Overhaul send_control_message

See merge request tpo/core/arti!1367
2023-07-10 13:14:11 +00:00
Alexander Færøy 943c12739d Merge branch 'recurse' into 'main'
tor-hsclient: Mock traits: Work around an async boobytrap

See merge request tpo/core/arti!1365
2023-07-10 13:13:31 +00:00
Ian Jackson fd2e4979be clippy: tor-error: Use convert::identity for into_internal!
This launders the closure so that clippy's
clippy::redundant_closure_call can't see it.

We can't have a local #[allow] because it would be on an expression,
which isn't allowed on stable.

This avoids having to use more clumsy idioms at call sites.
2023-07-10 13:49:51 +01:00
Ian Jackson 1a8395cd11 tor-llcrypto: Add a missing instance of the standard lint block
This fixes a needless_vec lint on nightly.
2023-07-10 13:49:51 +01:00
Ian Jackson 473447a82e Run maint/add_warning to actually apply new lint allows 2023-07-10 13:49:51 +01:00
Nick Mathewson 9f3619d5c9 Merge branch 'clippy-vec' into 'main'
Fix new "useless_vec" warning from clippy +nightly

See merge request tpo/core/arti!1395
2023-07-10 12:07:31 +00:00
Nick Mathewson c2601ec896 Explain the code for the #952 fix.
Let's explain what Trinity did in its fix for #952, so that we know
why this code is here the next time we find it.
2023-07-10 08:00:08 -04:00
Ian Jackson 501454370f Fix new "useless_vec" warning from clippy +nightly
Explanation at
https://rust-lang.github.io/rust-clippy/master/index.html#/useless_vec

This is the non-tests subset of the same-named commmit in !1388,
(recreated by hand by me, and then checked against that commit;
I stole the commit message from Nick's.)

This should be uncontroversial I think.
2023-07-10 12:35:21 +01:00
Nick Mathewson 22f55b7cf8 Remove some needless into_iter() calls.
Clippy nightly now detects when you're calling into_iter() and
passing the result into something that accepts an
`impl IntoIterator`.
2023-07-10 12:33:21 +01:00
Nick Mathewson 0b6cc7ba5e Add exceptions for some cases of diverging_sub_expression
See here for documentation on the lint:
https://rust-lang.github.io/rust-clippy/master/index.html#/diverging_sub_expression

The issue here, from what I can tell, is that the lint triggers
whenever you use a diverging expression as a function body within an
2023-07-10 12:33:21 +01:00