1
0
Fork
You've already forked pidl-rs
0
No description
  • Rust 94.1%
  • Python 3.1%
  • C 1.3%
  • Shell 0.9%
  • Makefile 0.6%
Alexander Bokovoy ba2bd91010 add tests: primitive round-trip extremes, NbtString 128-deep compression chain
Iteration 9 of autoresearch/resilience loop:
- ndr_primitive_roundtrip_extremes: encode then decode u8/u16/u32/u64/i8/i16/i32/i64/f64
 at boundary values (0, MAX, MIN, NaN, ±Inf) with both NDR32 and NDR64 syntax.
 Confirms no panic on any primitive encode/decode at extremes.
- ndr_nbtstring_max_depth_chain: build a 256-byte buffer with 128 self-referential
 compression pointer pairs that form a cycle; verifies the depth>128 guard fires
 and returns Err rather than stack-overflowing or looping infinitely.
Metric: 0 panics (24/24 tests pass).
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
2026年04月06日 19:04:10 +03:00
contrib contrib/packages: add NDR loader packages and sync Makefile from upstream 2026年03月21日 14:11:12 +02:00
docs docs: add pidl-fuzz to user documentation table and update status 2026年03月20日 19:34:22 +02:00
examples examples/krb5pac-module: regenerate after repr(C) function struct fix 2026年03月21日 12:28:24 +02:00
idl idl: add remaining 88 Samba IDL files from librpc/idl/ 2026年03月13日 14:28:08 +02:00
ndr-loading tests: improve active-crate coverage from 81% to 87% 2026年04月06日 15:03:55 +03:00
ndr-module-builder build: add release profile with LTO and full optimisation 2026年03月21日 11:28:00 +02:00
ndrdump ndrdump: gate NdrEncode behind optional validate feature 2026年04月06日 16:55:24 +03:00
pidl experiment(ndr-resilience): fix relative_base seek overflow in generated decode 2026年04月06日 18:29:26 +03:00
pidl-fuzz deps: drop unused default features from lalrpop-util and rand 2026年03月21日 12:43:36 +02:00
samba-ndr add tests: primitive round-trip extremes, NbtString 128-deep compression chain 2026年04月06日 19:04:10 +03:00
samba-pidl pidl: generate set_no_align() calls for [flag(NDR_NOALIGN)] typedefs 2026年03月19日 20:25:57 +02:00
.gitignore experiment(ndr-resilience): fix relative_base seek overflow in generated decode 2026年04月06日 18:29:26 +03:00
Cargo.lock examples/echo-module: add cdylib crate generated from echo.idl 2026年03月21日 12:27:00 +02:00
Cargo.toml deps: disable unused clap default features (color, suggestions) 2026年04月06日 16:18:12 +03:00
COPYING Add GPL-3.0 COPYING file 2026年03月13日 14:52:11 +02:00
deny.toml contrib/packages: add cargo deny support 2026年03月15日 19:02:55 +02:00
Makefile build: add Makefile for standalone builds and packaging (Phase 15) 2026年03月20日 14:35:40 +02:00
README.md README: add pidl-fuzz to workspace layout, testing section, and docs table 2026年03月20日 19:34:33 +02:00
rustfmt.toml rustfmt: drop nightly-only options from rustfmt.toml 2026年03月14日 10:30:54 +02:00

samba-pidl — Rust rewrite of the Samba PIDL compiler

samba-pidl is a Rust reimplementation of the Perl IDL compiler (pidl) used by the Samba project. It reads Interface Definition Language (IDL) files in a format compatible with Microsoft's MIDL compiler and generates C source code, NDR wire-protocol parsers, Wireshark dissectors, Python bindings, and Rust type definitions.

The goal is a drop-in replacement for the Perl pidl script with byte-identical output on the full Samba IDL corpus (librpc/idl/*.idl), better error messages, and a clean, testable architecture.

Workspace layout

samba-pidl-rust/
├── pidl/ Library crate — all pipeline logic (lexer, parser, backends)
├── samba-pidl/ Binary crate — CLI entry point, wires pipeline stages together
├── samba-ndr/ Runtime support crate for the Rust backend (NDR traits, primitives)
├── ndr-loading/ C ABI crate — dynamic module loader API (ndr_loading.h)
├── ndrdump/ Binary — decode and pretty-print NDR blobs (port of Samba's ndrdump)
├── pidl-fuzz/ Structured fuzzer for the pidl pipeline and NDR dynamic modules
├── idl/ Vendored copy of all 95 Samba IDL files (librpc/idl/)
├── examples/ Self-contained IDL examples covering every language feature
└── docs/ Design documents (architecture, AST, parser, backends, plan)

Compilation pipeline

.idl file
 │
 ▼ preprocessor.rs — invoke cpp, parse GCC line markers
 ▼ lexer.rs — tokenise preprocessed text, track source locations
 ▼ parser/ — hand-written recursive-descent IDL parser → IdlTree
 ▼ typelist.rs — register all named types into TypeRegistry
 ▼ odl.rs — ODL-to-IDL transformation (object interfaces)
 ▼ ndr/ — NDR semantic analysis → NdrTree (levels, alignment, deferred flags)
 ▼ backend/* — one or more code-generation backends

Backends

Flag Output Status
--dump-idl Regenerated IDL text Complete
--header Samba4 C header (.h) Complete
--ndr-parser NDR pull/push C source Complete
--client NDR client C source Complete
--server NDR server boilerplate Complete
--server-compat NDR server compatibility layer Complete
--tdr-parser TDR parser C source Complete
--template Samba4 server stub template Complete
--python Python binding C wrapper Complete
--samba3-ndr-client Samba3 NDR client Complete
--samba3-ndr-server Samba3 NDR server Complete
--samba3-template Samba3 server stub template Complete
--ws-parser Wireshark dissector (.c + .h) Complete
--com-header COM interface C header Complete
--dcom-proxy DCOM proxy C source Complete
--warn-compat MIDL compatibility warnings Complete
--rust Rust type definitions with NDR trait impls Complete

All complete backends produce byte-identical output to the Perl reference tool on the full 95-file Samba IDL corpus.

Building

Requires Rust 1.74 or later and a C preprocessor (cpp) on PATH.

cargo build --release

The samba-pidl binary will be at target/release/samba-pidl.

Running

# Generate NDR parser C source for an IDL file
samba-pidl --outputdir=out --ndr-parser librpc/idl/samr.idl
# Generate C header
samba-pidl --outputdir=out --header librpc/idl/samr.idl
# Generate Wireshark dissector
samba-pidl --outputdir=out --ws-parser librpc/idl/samr.idl
# Generate Rust types (against the samba-ndr runtime crate)
samba-pidl --outputdir=out --rust librpc/idl/samr.idl
# Add include directories for IDL files that #include others
samba-pidl --includedir librpc/idl --ndr-parser librpc/idl/netlogon.idl

Testing

# Run all workspace tests
cargo test --workspace
# Run only the pidl library tests (178+ unit tests + integration tests)
cargo test -p pidl
# Run ndrdump blackbox tests (14 tests decoding PAC, SAMR, NBT, NETLOGON blobs)
cargo test -p ndrdump

Fuzzing

pidl-fuzz exercises both the IDL parser pipeline and compiled NDR modules. See pidl-fuzz/README.md for the full guide.

# Deterministic: 65 curated IDL inputs
cargo run --release -p pidl-fuzz
# Random: 5 000 seeded-PRNG IDL cases
cargo run --release -p pidl-fuzz -- --count 5000 random
# Module: fuzz a compiled .so (decode → encode → free cycle)
cargo run --release -p pidl-fuzz -- --count 5000 module target/release/libndr_krb5pac.so

CI

A local CI runner mirrors the GitHub Actions pipeline:

./contrib/ci/local-ci.sh all # run all jobs: fmt, clippy, build, doc, test, examples
./contrib/ci/local-ci.sh build test # run specific jobs
./contrib/ci/local-ci.sh --list # list available jobs

Jobs run in dependency order (clippy/doc/test/examples each require a passing build). Job timing and a pass/fail summary table are printed at the end.

The examples job compiles every file in examples/ with --header, --ndr-parser, and --dump-idl, and additionally runs --client and --server on examples/full-protocol.idl.

ndrdump

ndrdump decodes NDR-encoded RPC binary blobs and prints a human-readable representation, equivalent to Samba's C ndrdump tool. It uses types generated by the Rust backend from the vendored IDL files.

cargo run --bin ndrdump -- krb5pac PAC_DATA pull test.pac

samba-ndr runtime crate

The samba-ndr crate provides the traits and primitives required by Rust-backend-generated code:

  • NdrEncode / NdrDecode — serialisation traits
  • NdrPrint — human-readable dump trait (used by ndrdump)
  • NdrBuffer — read/write cursor over a byte slice
  • Primitive implementations (u8, u16, u32, u64, i*, bool)
  • Samba-specific types: Guid, PolicyHandle, DomSid, VecSized

Documentation

Document Contents
docs/idl-format.md IDL language reference — types, attributes, syntax, examples
docs/usage.md Compiler usage guide — options, workflows, output naming, errors
docs/dynamic-modules.md NDR dynamic modules — building .so modules, C and Rust API usage
pidl-fuzz/README.md Fuzzer guide — all modes, output format, memory safety, reproducing failures
examples/README.md Runnable IDL examples — one file per feature group, index and run instructions
docs/architecture.md Crate layout, pipeline stages, data flow, CLI interface
docs/ast.md IDL AST and NDR IR type definitions
docs/parser.md Lexer, preprocessor integration, parser design
docs/backends.md Backend trait, CodeWriter, per-backend notes
docs/rust-backend.md Rust backend design and output format
docs/implementation-plan.md Phased roadmap and current status

Relationship to Samba

This project is developed alongside the Samba source tree. The Perl pidl in samba/pidl/ remains the authoritative reference during development: every backend is verified by running both tools on the same IDL input and diffing the output. Once all backends pass the regression suite, samba-pidl could be integrated into the Samba build system as a drop-in replacement.

License

GPL-3.0-or-later — same as Samba.