Skip to content

Conversation

bakanovskii
Copy link

@bakanovskii bakanovskii commented Aug 22, 2025

No features added or removed, mostly lint changes from clippy
I might add a few modules for slapi_r_plugin later on, so as a first step to get familiar with your workflow and contrubiton I opened this PR

I used https://www.port389.org/docs/389ds/contributing.html for reference, sorry if i did something wrong

Summary by Sourcery

Apply lint and style improvements across Rust plugins, modernizing FFI declarations, pointer handling, and general Rust idioms while maintaining existing functionality.

Enhancements:

  • Modernize FFI declarations to unsafe extern "C" and simplify pointer casts with .cast(), const fn constructors, and explicit type annotations
  • Refine Rust idioms by using Self in enum matches, range syntax for validation, let Ok(...) patterns, vec![] and vec![0; len], and format string interpolation in log messages
  • Improve const correctness by marking constructors and pointer-returning methods as const and deriving Eq for FilterType

Build:

  • Modernize build.rs scripts with inline variable interpolation for cargo directives and file paths

Tests:

  • Update PBKDF2 tests to remove Result wrappers, simplify assertions, and adjust get_pbkdf2_rounds return type

@bakanovskii bakanovskii marked this pull request as ready for review August 22, 2025 18:07
Copy link
Member

@vashirov vashirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entryuuid and pwdchan related tests are failing with this PR.

@bakanovskii bakanovskii marked this pull request as draft August 25, 2025 12:01
@bakanovskii
Copy link
Author

entryuuid and pwdchan related tests are failing with this PR.

Hello! Could you please help me with local testing
So according to contribution guide after changing the code I used:

make check
sudo make install
sudo make lib389-install

and then i run tests like this:

sudo py.test -s dirsrvtests/tests/suites/entryuuid/
sudo py.test -s dirsrvtests/tests/suites/password/

but the test doesn't seem to "see" my changes, I even added errors in code on purpose to see if something changes but it doesn't

perhaps I'm missing something? thank you in advance

@vashirov
Copy link
Member

Do you have any other versions of 389-ds-base installed?
If you're testing this on rpm-based distro, I recommend to do

make -f rpm.mk download-cargo-dependencies rpms

And then install the resulting rpms from dist/rpms/

@bakanovskii
Copy link
Author

Do you have any other versions of 389-ds-base installed? If you're testing this on rpm-based distro, I recommend to do

make -f rpm.mk download-cargo-dependencies rpms

And then install the resulting rpms from dist/rpms/

I recently updated to debian 13, maybe I'll try to use repo from salsa and build debs from it
Thanks

@vashirov
Copy link
Member

In this case ensure that you don't have 389-ds packages installed from the distro, and use binaries installed in the prefix.

@bakanovskii bakanovskii force-pushed the lint-rust-plugins branch 3 times, most recently from 0c556be to ccf8ece Compare September 4, 2025 16:25
@bakanovskii
Copy link
Author

In this case ensure that you don't have 389-ds packages installed from the distro, and use binaries installed in the prefix.

Hello! Are tests run automatically or manually? Locally issue seems to be solved but I want to double check with CI

@vashirov
Copy link
Member

vashirov commented Sep 5, 2025

Hello! Are tests run automatically or manually? Locally issue seems to be solved but I want to double check with CI

For the first-time contributors CI run needs to be approved. I've kicked off the tests.

@bakanovskii
Copy link
Author

Hello! Are tests run automatically or manually? Locally issue seems to be solved but I want to double check with CI

For the first-time contributors CI run needs to be approved. I've kicked off the tests.

Got it, thanks

@bakanovskii
Copy link
Author

@vashirov can you please push the tests again?

@bakanovskii bakanovskii marked this pull request as ready for review September 6, 2025 10:10
Copy link

sourcery-ai bot commented Sep 6, 2025

Reviewer's Guide

This PR applies Clippy-driven lint and style updates across the Rust plugin crates, improving safety annotations, const-correctness, pointer handling, formatting, and match patterns without altering any functional behavior.

Class diagram for updated pointer and const usage in plugin types

classDiagram
    class Pblock {
        +raw_pb: *const libc::c_void
        +new() Self
    }
    class PblockRef {
        +raw_pb: *const libc::c_void
        +new(raw_pb: *const libc::c_void) Self
        +as_ptr() *const libc::c_void
    }
    Pblock --> PblockRef

    class EntryRef {
        +raw_e: *const libc::c_void
        +new(raw_e: *const libc::c_void) Self
        +get_sdnref() SdnRef
    }

    class SdnRef {
        +raw_sdn: *const libc::c_void
        +new(raw_sdn: *const libc::c_void) Self
        +as_ptr() *const libc::c_void
    }
    EntryRef --> SdnRef

    class ValueArrayRef {
        +raw_slapi_val: *const *const slapi_value
        +new(raw_slapi_val: *const libc::c_void) Self
        +iter() ValueArrayRefIter
    }

    class ValueArrayRefIter {
        +idx: usize
        +va_ref: &ValueArrayRef
    }
    ValueArrayRef --> ValueArrayRefIter

    class ValueRef {
        +raw_slapi_val: *const slapi_value
        +new(raw_slapi_val: *const libc::c_void) Self
        +as_ptr() *const slapi_value
    }
    ValueArrayRefIter --> ValueRef

    class Value {
        +value: ValueRef
        +take_ownership() *mut slapi_value
    }
    Value --> ValueRef

    class SlapiMods {
        +inner: *const libc::c_void
        +vas: Vec<ValueArray>
        +new() Self
        +append(modtype, attrtype, values)
    }

    class Modify {
        +pb: Pblock
        +mods: SlapiMods
        +new(dn: &SdnRef, mods: SlapiMods, plugin_id: &PluginIdRef) Result<Self, PluginError>
        +execute() Result<ModifyResult, LDAPError>
    }
    Modify --> SlapiMods
    Modify --> Pblock

    class PluginIdRef {
        +raw_pid: *const libc::c_void
    }
    Modify --> PluginIdRef

    class Search {
        +pb: Pblock
        +filter: Option<CString>
        +stype: SearchType
        +new_map_entry(basedn: &SdnRef, scope: SearchScope, filter: &str, plugin_id: &PluginIdRef, cbdata: &T, mapfn) Result<Self, PluginError>
        +execute() Result<SearchResult, LDAPError>
    }
    Search --> Pblock
    Search --> PluginIdRef
    Search --> SdnRef

    class BackendRef {
        +raw_be: *const libc::c_void
        +new(dn: &SdnRef) Result<Self, ()>
        +as_ptr() *const libc::c_void
    }
    BackendRef --> SdnRef

    class BackendRefTxn {
        +pb: Pblock
        +committed: bool
    }
    BackendRefTxn --> Pblock
    BackendRefTxn --> BackendRef
Loading

File-Level Changes

Change Details Files
Added unsafe qualifiers to extern C declarations
  • Converted all extern "C" blocks to unsafe extern "C"
  • Marked imported C functions as unsafe fn
src/slapi_r_plugin/src/pblock.rs
src/slapi_r_plugin/src/modify.rs
src/slapi_r_plugin/src/search.rs
src/slapi_r_plugin/src/task.rs
src/slapi_r_plugin/src/entry.rs
src/slapi_r_plugin/src/backend.rs
src/slapi_r_plugin/src/plugin.rs
src/slapi_r_plugin/src/syntax_plugin.rs
src/slapi_r_plugin/src/ber.rs
src/slapi_r_plugin/src/log.rs
Introduced const functions for constructors and pointer getters
  • Replaced pub fn new and iter with pub const fn where safe
  • Added const fn for as_ptr and similar methods
src/slapi_r_plugin/src/value.rs
src/slapi_r_plugin/src/dn.rs
src/slapi_r_plugin/src/entry.rs
src/slapi_r_plugin/src/pblock.rs
src/slapi_r_plugin/src/backend.rs
src/slapi_r_plugin/src/ber.rs
Improved pointer casting and null-check patterns
  • Swapped manual as *const/as *mut casts for .cast() calls
  • Used ptr::null_mut() and is_null() for null tests
src/slapi_r_plugin/src/value.rs
src/slapi_r_plugin/src/entry.rs
src/slapi_r_plugin/src/pblock.rs
src/slapi_r_plugin/src/backend.rs
Refactored logging and string formatting
  • Updated log_error! invocations to use inline {var} formatting
  • Simplified CString::new error handling with let Ok(x) = ... else {}
src/plugins/pwdchan/src/lib.rs
src/slapi_r_plugin/src/pblock.rs
src/slapi_r_plugin/src/plugin.rs
src/slapi_r_plugin/src/log.rs
Simplified enum match patterns
  • Replaced explicit enum paths with Self::Variant in matches
  • Mapped error arms to Self::Error instead of named type
src/slapi_r_plugin/src/constants.rs
src/slapi_r_plugin/src/error.rs
src/slapi_r_plugin/src/constants.rs
Added explicit type annotations and modern parsers
  • Annotated local let bindings with concrete types
  • Replaced from_str_radix with .parse::<T>()
src/plugins/pwdchan/src/lib.rs
src/slapi_r_plugin/src/task.rs
Streamlined collection usages
  • Replaced Vec::new() with vec![]
  • Used iterator chaining with once() and chain()
src/slapi_r_plugin/src/value.rs
src/slapi_r_plugin/src/charray.rs

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/plugins/entryuuid/src/lib.rs:47` </location>
<code_context>
+    let config_sdn: Sdn = Sdn::try_from("cn=config").expect("Invalid static dn");
+    let schema_sdn: Sdn = Sdn::try_from("cn=schema").expect("Invalid static dn");

-    if sdn.is_below_suffix(&*config_sdn) || sdn.is_below_suffix(&*schema_sdn) {
+    if sdn.is_below_suffix(&config_sdn) || sdn.is_below_suffix(&schema_sdn) {
         // We don't need to assign to these suffixes.
         log_error!(
</code_context>

<issue_to_address>
Removing dereference of Sdn is a good simplification.

Please verify that all usages of `Sdn` now match the expected type and do not require dereferencing elsewhere.

Suggested implementation:

```rust
    let config_sdn: Sdn = Sdn::try_from("cn=config").expect("Invalid static dn");
    let schema_sdn: Sdn = Sdn::try_from("cn=schema").expect("Invalid static dn");

    // Ensure all usages of Sdn are passed as references, matching method expectations.
    if sdn.is_below_suffix(&config_sdn) || sdn.is_below_suffix(&schema_sdn) {
        // We don't need to assign to these suffixes.
        log_error!(
            ErrorLevel::Plugin,
            sdn.to_dn_string()
        );

```

If there are other usages of `config_sdn` or `schema_sdn` elsewhere in the file or project, ensure they are also passed as references (`&config_sdn`, `&schema_sdn`) where required by method signatures. Remove any remaining dereferencing (`&*config_sdn`, etc.) to maintain consistency.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


if sdn.is_below_suffix(&*config_sdn) || sdn.is_below_suffix(&*schema_sdn) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Removing dereference of Sdn is a good simplification.

Please verify that all usages of Sdn now match the expected type and do not require dereferencing elsewhere.

Suggested implementation:

    let config_sdn: Sdn = Sdn::try_from("cn=config").expect("Invalid static dn");
    let schema_sdn: Sdn = Sdn::try_from("cn=schema").expect("Invalid static dn");

    // Ensure all usages of Sdn are passed as references, matching method expectations.
    if sdn.is_below_suffix(&config_sdn) || sdn.is_below_suffix(&schema_sdn) {
        // We don't need to assign to these suffixes.
        log_error!(
            ErrorLevel::Plugin,
            sdn.to_dn_string()
        );

If there are other usages of config_sdn or schema_sdn elsewhere in the file or project, ensure they are also passed as references (&config_sdn, &schema_sdn) where required by method signatures. Remove any remaining dereferencing (&*config_sdn, etc.) to maintain consistency.

@bakanovskii
Copy link
Author

@vashirov, hello!

I checked other PR's and they share the same failing tests, are these okayish to fail?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants