Giter Club home page Giter Club logo

Comments (4)

conqp avatar conqp commented on July 17, 2024

With the pull request above, the following beep program works with lower privileges:

use evdev::{Device, EventType, InputEvent, SoundCode};
use std::{fs::OpenOptions, thread, time};

const FILE: &str = "/dev/input/by-path/platform-pcspkr-event-spkr";

pub fn beep(hertz: u16) -> std::io::Result<()> {
    Device::try_from(OpenOptions::new().append(true).open(FILE)?)?.send_events(&[InputEvent::new(
        EventType::SOUND.0,
        SoundCode::SND_TONE.0,
        i32::from(hertz),
    )])
}

fn main() {
    beep(440).expect("could not beep");
    thread::sleep(time::Duration::from_millis(500));
    beep(880).expect("could not beep");
    thread::sleep(time::Duration::from_millis(500));
    beep(0).expect("could not beep");
}

Udev rules:

ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="PC Speaker", ENV{DEVNAME}!="", GROUP="beep", MODE="0620"

from evdev.

hendursaga avatar hendursaga commented on July 17, 2024

@conqp I know this is closed, but I was wondering what's the practical security difference between write and append, in this context?

from evdev.

conqp avatar conqp commented on July 17, 2024

Back in the day when I wrote beep-evdev, it did not work with write and the aforementioned udev rule. I haven't been working with beep-evdev and udev lately, so I don't know what precisely was the issue. Are you able to reproduce it?
Also with the append permission rather than write, a user will never be able to accidentally create the file if it does not exist in the first place, though they'd need write permission on the parent directory anyway. But better be safe than sorry.

from evdev.

hendursaga avatar hendursaga commented on July 17, 2024

@conqp no, I haven't had an issue, I just saw this and wondered what the practical security differences between append and write were.

from evdev.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.