[][src]Macro sudo_plugin::sudo_io_plugin

macro_rules! sudo_io_plugin {
    ( $name:ident : $ty:ty { $($cb:ident : $fn:ident),* $(,)* } ) => { ... };
}

Emits the boilerplate stanza for creating and initializing a custom sudo I/O plugin.

Example

use sudo_plugin::*;
use sudo_plugin::errors::*;
use std::io::Write;

sudo_io_plugin! {
    example : Example {
        close:      close,
        log_stdout: log_stdout,
    }
}

struct Example {
    plugin: &'static sudo_plugin::Plugin
}

impl Example {
    fn open(plugin: &'static sudo_plugin::Plugin) -> Result<Self> {
        plugin.stdout().write(b"example sudo plugin initialized");

        Ok(Example { plugin })
    }

    fn close(&mut self, _: i32, _: i32) {
        self.plugin.stdout().write(b"example sudo plugin exited");
    }

    fn log_stdout(&mut self, _: &[u8]) -> Result<()> {
        self.plugin.stdout().write(
            b"example sudo plugin received output on stdout"
        );

        Ok(())
    }
}

The generated plugin will have the entry point example, so to enable it, you'd copy the library to example.so in sudo's plugin directory (on macOS, /usr/local/libexec/sudo) and add the following to /etc/sudo.conf:

This example is not tested
Plugin example example.so