Skip to main content

salus_agent/
lib.rs

1// Copyright (c) 2025 salus developers
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9//! salus login agent
10
11// rustc lints
12#![cfg_attr(
13    all(feature = "unstable", nightly),
14    feature(
15        multiple_supertrait_upcastable,
16        must_not_suspend,
17        non_exhaustive_omitted_patterns_lint,
18        strict_provenance_lints,
19        unqualified_local_imports,
20    )
21)]
22#![cfg_attr(nightly, allow(single_use_lifetimes))]
23#![cfg_attr(
24    nightly,
25    deny(
26        absolute_paths_not_starting_with_crate,
27        ambiguous_glob_imports,
28        ambiguous_glob_reexports,
29        ambiguous_negative_literals,
30        ambiguous_wide_pointer_comparisons,
31        anonymous_parameters,
32        array_into_iter,
33        asm_sub_register,
34        async_fn_in_trait,
35        bad_asm_style,
36        bare_trait_objects,
37        boxed_slice_into_iter,
38        break_with_label_and_loop,
39        clashing_extern_declarations,
40        closure_returning_async_block,
41        coherence_leak_check,
42        confusable_idents,
43        const_evaluatable_unchecked,
44        const_item_mutation,
45        dangling_pointers_from_temporaries,
46        dead_code,
47        dependency_on_unit_never_type_fallback,
48        deprecated,
49        deprecated_in_future,
50        deprecated_safe_2024,
51        deprecated_where_clause_location,
52        deref_into_dyn_supertrait,
53        deref_nullptr,
54        double_negations,
55        drop_bounds,
56        dropping_copy_types,
57        dropping_references,
58        duplicate_macro_attributes,
59        dyn_drop,
60        edition_2024_expr_fragment_specifier,
61        elided_lifetimes_in_paths,
62        ellipsis_inclusive_range_patterns,
63        explicit_outlives_requirements,
64        exported_private_dependencies,
65        ffi_unwind_calls,
66        forbidden_lint_groups,
67        forgetting_copy_types,
68        forgetting_references,
69        for_loops_over_fallibles,
70        function_item_references,
71        hidden_glob_reexports,
72        if_let_rescope,
73        impl_trait_overcaptures,
74        impl_trait_redundant_captures,
75        improper_ctypes,
76        improper_ctypes_definitions,
77        inline_no_sanitize,
78        internal_features,
79        invalid_from_utf8,
80        invalid_macro_export_arguments,
81        invalid_nan_comparisons,
82        invalid_value,
83        irrefutable_let_patterns,
84        keyword_idents_2018,
85        keyword_idents_2024,
86        large_assignments,
87        late_bound_lifetime_arguments,
88        legacy_derive_helpers,
89        let_underscore_drop,
90        macro_use_extern_crate,
91        map_unit_fn,
92        meta_variable_misuse,
93        mismatched_lifetime_syntaxes,
94        missing_abi,
95        missing_copy_implementations,
96        missing_debug_implementations,
97        missing_docs,
98        missing_unsafe_on_extern,
99        mixed_script_confusables,
100        named_arguments_used_positionally,
101        never_type_fallback_flowing_into_unsafe,
102        no_mangle_generic_items,
103        non_ascii_idents,
104        non_camel_case_types,
105        non_contiguous_range_endpoints,
106        non_fmt_panics,
107        non_local_definitions,
108        non_shorthand_field_patterns,
109        non_snake_case,
110        non_upper_case_globals,
111        noop_method_call,
112        opaque_hidden_inferred_bound,
113        out_of_scope_macro_calls,
114        overlapping_range_endpoints,
115        path_statements,
116        private_bounds,
117        private_interfaces,
118        ptr_to_integer_transmute_in_consts,
119        redundant_imports,
120        redundant_lifetimes,
121        redundant_semicolons,
122        refining_impl_trait_internal,
123        refining_impl_trait_reachable,
124        renamed_and_removed_lints,
125        rust_2021_incompatible_closure_captures,
126        rust_2021_incompatible_or_patterns,
127        rust_2021_prefixes_incompatible_syntax,
128        rust_2021_prelude_collisions,
129        rust_2024_guarded_string_incompatible_syntax,
130        rust_2024_incompatible_pat,
131        rust_2024_prelude_collisions,
132        self_constructor_from_outer_item,
133        semicolon_in_expressions_from_macros,
134        single_use_lifetimes,
135        special_module_name,
136        stable_features,
137        static_mut_refs,
138        suspicious_double_ref_op,
139        tail_expr_drop_order,
140        trivial_bounds,
141        trivial_casts,
142        trivial_numeric_casts,
143        type_alias_bounds,
144        tyvar_behind_raw_pointer,
145        uncommon_codepoints,
146        unconditional_recursion,
147        uncovered_param_in_projection,
148        unexpected_cfgs,
149        unfulfilled_lint_expectations,
150        ungated_async_fn_track_caller,
151        uninhabited_static,
152        unit_bindings,
153        unknown_lints,
154        unknown_or_malformed_diagnostic_attributes,
155        unnameable_test_items,
156        unnameable_types,
157        unpredictable_function_pointer_comparisons,
158        unreachable_code,
159        unreachable_patterns,
160        unreachable_pub,
161        unsafe_attr_outside_unsafe,
162        unsafe_code,
163        unsafe_op_in_unsafe_fn,
164        unstable_name_collisions,
165        unstable_syntax_pre_expansion,
166        unused_allocation,
167        unused_assignments,
168        unused_associated_type_bounds,
169        unused_attributes,
170        unused_braces,
171        unused_comparisons,
172        unused_crate_dependencies,
173        unused_doc_comments,
174        unused_extern_crates,
175        unused_features,
176        unused_import_braces,
177        unused_imports,
178        unused_labels,
179        unused_lifetimes,
180        unused_macro_rules,
181        unused_macros,
182        unused_must_use,
183        unused_mut,
184        unused_parens,
185        unused_qualifications,
186        unused_results,
187        unused_unsafe,
188        unused_variables,
189        useless_ptr_null_checks,
190        uses_power_alignment,
191        variant_size_differences,
192        while_true,
193    )
194)]
195// If nightly and unstable, allow `incomplete_features` and `unstable_features`
196#![cfg_attr(
197    all(feature = "unstable", nightly),
198    allow(incomplete_features, unstable_features)
199)]
200// If nightly and not unstable, deny `incomplete_features` and `unstable_features`
201#![cfg_attr(
202    all(not(feature = "unstable"), nightly),
203    deny(incomplete_features, unstable_features)
204)]
205// The unstable lints
206#![cfg_attr(
207    all(feature = "unstable", nightly),
208    deny(
209        fuzzy_provenance_casts,
210        lossy_provenance_casts,
211        multiple_supertrait_upcastable,
212        must_not_suspend,
213        non_exhaustive_omitted_patterns,
214        unqualified_local_imports,
215    )
216)]
217// clippy lints
218#![cfg_attr(nightly, deny(clippy::all, clippy::pedantic))]
219// rustdoc lints
220#![cfg_attr(
221    nightly,
222    deny(
223        rustdoc::bare_urls,
224        rustdoc::broken_intra_doc_links,
225        rustdoc::invalid_codeblock_attributes,
226        rustdoc::invalid_html_tags,
227        rustdoc::missing_crate_level_docs,
228        rustdoc::private_doc_tests,
229        rustdoc::private_intra_doc_links,
230    )
231)]
232#![cfg_attr(all(docsrs), feature(doc_cfg))]
233#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
234
235use crate::error::{clap_or_error, success};
236
237mod config;
238mod error;
239mod handler;
240pub mod keystore;
241mod logging;
242mod runtime;
243mod store;
244#[cfg(test)]
245mod test_keyring;
246mod utils;
247
248/// Run the salus login agent to completion, returning the process exit code.
249///
250/// Parses the command line, loads configuration, initializes tracing, loads the
251/// enrolled share sets from the OS keyring, then serves client requests over the
252/// agent IPC socket until the process is terminated. Any failure during setup is
253/// rendered to an exit code rather than propagated.
254#[must_use]
255pub async fn run_agent() -> i32 {
256    runtime::run::<Vec<&str>, &str>(None)
257        .await
258        .map_or_else(clap_or_error, success)
259}