-
Notifications
You must be signed in to change notification settings - Fork 9
Cleanup keyutils types and api.rs #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92f3e6e
Move libkeyutils-sys to keyutils-raw
josephlr 77316f1
Add KEY_TYPE_KEYRING and KEY_TYPE_BIG_KEY
josephlr 59eed51
Change keyutils-raw types and cleanup api.rs
josephlr d2458fd
Use TryFrom for DefaultKeyring
josephlr ddcb564
Silence buggy improper_ctypes warning
josephlr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[package] | ||
name = "libkeyutils-sys" | ||
version = "0.3.1" | ||
name = "keyutils-raw" | ||
version = "0.4.0" | ||
authors = ["Ben Boeckel <[email protected]>"] | ||
license = "BSD-3-Clause" | ||
description = "FFI bindings to libkeyutils." | ||
description = "Raw bindings to Linux keyring syscalls" | ||
repository = "https://github.com/mathstuf/rust-keyutils.git" | ||
homepage = "https://github.com/mathstuf/rust-keyutils" | ||
keywords = ["keyutils"] | ||
|
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2018, Ben Boeckel | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, | ||
// are permitted provided that the following conditions are met: | ||
// | ||
// * Redistributions of source code must retain the above copyright notice, | ||
// this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above copyright notice, | ||
// this list of conditions and the following disclaimer in the documentation | ||
// and/or other materials provided with the distribution. | ||
// * Neither the name of this project nor the names of its contributors | ||
// may be used to endorse or promote products derived from this software | ||
// without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
// Ignore rustfmt changes in here. The horizontal alignment is too useful to give up. | ||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
|
||
use crate::{KeyPermissions, KeyringSerial}; | ||
|
||
// TODO: change these to &CStr when const fns get unblocked. | ||
pub const KEY_TYPE_KEYRING: &str = "keyring"; | ||
pub const KEY_TYPE_USER: &str = "user"; | ||
pub const KEY_TYPE_LOGON: &str = "logon"; | ||
pub const KEY_TYPE_BIG_KEY: &str = "big_key"; | ||
|
||
pub const KEY_SPEC_THREAD_KEYRING: KeyringSerial = unsafe { KeyringSerial::new_unchecked(-1) }; | ||
pub const KEY_SPEC_PROCESS_KEYRING: KeyringSerial = unsafe { KeyringSerial::new_unchecked(-2) }; | ||
pub const KEY_SPEC_SESSION_KEYRING: KeyringSerial = unsafe { KeyringSerial::new_unchecked(-3) }; | ||
pub const KEY_SPEC_USER_KEYRING: KeyringSerial = unsafe { KeyringSerial::new_unchecked(-4) }; | ||
pub const KEY_SPEC_USER_SESSION_KEYRING: KeyringSerial = unsafe { KeyringSerial::new_unchecked(-5) }; | ||
pub const KEY_SPEC_GROUP_KEYRING: KeyringSerial = unsafe { KeyringSerial::new_unchecked(-6) }; | ||
pub const KEY_SPEC_REQKEY_AUTH_KEY: KeyringSerial = unsafe { KeyringSerial::new_unchecked(-7) }; | ||
|
||
pub const KEY_POS_VIEW: KeyPermissions = 0x0100_0000; /* possessor can view a key's attributes */ | ||
pub const KEY_POS_READ: KeyPermissions = 0x0200_0000; /* possessor can read key payload / view keyring */ | ||
pub const KEY_POS_WRITE: KeyPermissions = 0x0400_0000; /* possessor can update key payload / add link to keyring */ | ||
pub const KEY_POS_SEARCH: KeyPermissions = 0x0800_0000; /* possessor can find a key in search / search a keyring */ | ||
pub const KEY_POS_LINK: KeyPermissions = 0x1000_0000; /* possessor can create a link to a key/keyring */ | ||
pub const KEY_POS_SETATTR: KeyPermissions = 0x2000_0000; /* possessor can set key attributes */ | ||
pub const KEY_POS_ALL: KeyPermissions = 0x3f00_0000; | ||
|
||
pub const KEY_USR_VIEW: KeyPermissions = 0x0001_0000; /* user permissions... */ | ||
pub const KEY_USR_READ: KeyPermissions = 0x0002_0000; | ||
pub const KEY_USR_WRITE: KeyPermissions = 0x0004_0000; | ||
pub const KEY_USR_SEARCH: KeyPermissions = 0x0008_0000; | ||
pub const KEY_USR_LINK: KeyPermissions = 0x0010_0000; | ||
pub const KEY_USR_SETATTR: KeyPermissions = 0x0020_0000; | ||
pub const KEY_USR_ALL: KeyPermissions = 0x003f_0000; | ||
|
||
pub const KEY_GRP_VIEW: KeyPermissions = 0x0000_0100; /* group permissions... */ | ||
pub const KEY_GRP_READ: KeyPermissions = 0x0000_0200; | ||
pub const KEY_GRP_WRITE: KeyPermissions = 0x0000_0400; | ||
pub const KEY_GRP_SEARCH: KeyPermissions = 0x0000_0800; | ||
pub const KEY_GRP_LINK: KeyPermissions = 0x0000_1000; | ||
pub const KEY_GRP_SETATTR: KeyPermissions = 0x0000_2000; | ||
pub const KEY_GRP_ALL: KeyPermissions = 0x0000_3f00; | ||
|
||
pub const KEY_OTH_VIEW: KeyPermissions = 0x0000_0001; /* third party permissions... */ | ||
pub const KEY_OTH_READ: KeyPermissions = 0x0000_0002; | ||
pub const KEY_OTH_WRITE: KeyPermissions = 0x0000_0004; | ||
pub const KEY_OTH_SEARCH: KeyPermissions = 0x0000_0008; | ||
pub const KEY_OTH_LINK: KeyPermissions = 0x0000_0010; | ||
pub const KEY_OTH_SETATTR: KeyPermissions = 0x0000_0020; | ||
pub const KEY_OTH_ALL: KeyPermissions = 0x0000_003f; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2018, Ben Boeckel | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, | ||
// are permitted provided that the following conditions are met: | ||
// | ||
// * Redistributions of source code must retain the above copyright notice, | ||
// this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above copyright notice, | ||
// this list of conditions and the following disclaimer in the documentation | ||
// and/or other materials provided with the distribution. | ||
// * Neither the name of this project nor the names of its contributors | ||
// may be used to endorse or promote products derived from this software | ||
// without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
use std::convert::TryFrom; | ||
use std::num::NonZeroI32; | ||
|
||
/// Alias for the key_serial_t kernel type, representing a keyring (or key). | ||
pub type KeyringSerial = NonZeroI32; | ||
|
||
/// Alias for the key_perm_t kernel type, representing a keyring's (or key's) | ||
/// permission bits. | ||
/// | ||
/// See `Permission`. | ||
pub type KeyPermissions = u32; | ||
|
||
pub type TimeoutSeconds = libc::c_uint; | ||
|
||
/// An enumeration for the keyrings which may be set as the default. | ||
/// | ||
/// Keys which are implicitly required via syscalls and other operations are | ||
/// placed in the default keyring. | ||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum DefaultKeyring { | ||
/// Do not change the default keyring. | ||
/// | ||
/// This may be used to get the current default keyring. | ||
NoChange = -1, | ||
/// Set the thread-specific keyring as the default. | ||
ThreadKeyring = 1, | ||
/// Set the process-specific keyring as the default. | ||
ProcessKeyring = 2, | ||
/// Set the session-specific keyring as the default. | ||
SessionKeyring = 3, | ||
/// Set the user-specific keyring as the default. | ||
UserKeyring = 4, | ||
/// Set the user session-specific keyring as the default. | ||
UserSessionKeyring = 5, | ||
/// Set the user session-specific keyring as the default. | ||
GroupKeyring = 6, | ||
/// Set the default keyring to the default logic. | ||
/// | ||
/// Keys will be placed in the first available keyring of: | ||
/// | ||
/// - thread-specific | ||
/// - process-specific | ||
/// - session-specific | ||
/// - user-specific | ||
DefaultKeyring = 0, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub struct UnknownDefault(libc::c_long); | ||
|
||
impl TryFrom<libc::c_long> for DefaultKeyring { | ||
type Error = UnknownDefault; | ||
fn try_from(id: libc::c_long) -> Result<DefaultKeyring, UnknownDefault> { | ||
use self::DefaultKeyring::*; | ||
match id { | ||
x if x == NoChange as libc::c_long => Ok(NoChange), | ||
x if x == ThreadKeyring as libc::c_long => Ok(ThreadKeyring), | ||
x if x == ProcessKeyring as libc::c_long => Ok(ProcessKeyring), | ||
x if x == SessionKeyring as libc::c_long => Ok(SessionKeyring), | ||
x if x == UserKeyring as libc::c_long => Ok(UserKeyring), | ||
x if x == UserSessionKeyring as libc::c_long => Ok(UserSessionKeyring), | ||
x if x == GroupKeyring as libc::c_long => Ok(GroupKeyring), | ||
x if x == DefaultKeyring as libc::c_long => Ok(DefaultKeyring), | ||
x => Err(UnknownDefault(x)), | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.