Skip to content

Commit 919b0fb

Browse files
security: ensure that on creation, the DB file only gives read-write permissions to the owner (#20)
* chore: bump version * security: owner only permissions on created database file
1 parent 403f887 commit 919b0fb

File tree

9 files changed

+31
-29
lines changed

9 files changed

+31
-29
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[env]
2+
LIBSQLITE3_FLAGS = "-DSQLITE_DEFAULT_FILE_PERMISSIONS=0600"

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clipvault"
33
description = "Clipboard history manager for Wayland, inspired by cliphist"
4-
version = "1.0.3"
4+
version = "1.0.4"
55
edition = "2024"
66
repository = "https://github.com/rolv-apneseth/clipvault"
77
homepage = "https://github.com/rolv-apneseth/clipvault"

src/commands/clear.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::path::PathBuf;
1+
use std::path::Path;
22

33
use miette::Result;
44

55
use crate::database::{init_db, queries::delete_all_entries};
66

77
#[tracing::instrument(skip(path_db))]
8-
pub fn execute(path_db: PathBuf) -> Result<()> {
9-
let conn = &init_db(&path_db)?;
8+
pub fn execute(path_db: &Path) -> Result<()> {
9+
let conn = &init_db(path_db)?;
1010
delete_all_entries(conn)?;
1111
Ok(())
1212
}

src/commands/delete.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
io::{Read, stdin},
3-
path::PathBuf,
3+
path::Path,
44
};
55

66
use miette::{Context, IntoDiagnostic, Result, miette};
@@ -15,7 +15,7 @@ use crate::{
1515
};
1616

1717
#[tracing::instrument(skip(path_db))]
18-
pub fn execute(path_db: PathBuf, args: GetDelArgs) -> Result<()> {
18+
pub fn execute(path_db: &Path, args: GetDelArgs) -> Result<()> {
1919
let GetDelArgs { input, index } = args;
2020

2121
assert!(
@@ -31,7 +31,7 @@ pub fn execute(path_db: PathBuf, args: GetDelArgs) -> Result<()> {
3131
}
3232
}
3333

34-
fn delete_entry(path_db: PathBuf, mut input: String) -> Result<()> {
34+
fn delete_entry(path_db: &Path, mut input: String) -> Result<()> {
3535
// Read from STDIN if no argument given
3636
if input.is_empty() {
3737
stdin()
@@ -42,12 +42,12 @@ fn delete_entry(path_db: PathBuf, mut input: String) -> Result<()> {
4242
}
4343

4444
let id = extract_id(input)?;
45-
let conn = &init_db(&path_db)?;
45+
let conn = &init_db(path_db)?;
4646
delete_entry_by_id(conn, id)
4747
}
4848

49-
fn delete_entry_rel(path_db: PathBuf, i: isize) -> Result<()> {
50-
let conn = &init_db(&path_db)?;
49+
fn delete_entry_rel(path_db: &Path, i: isize) -> Result<()> {
50+
let conn = &init_db(path_db)?;
5151

5252
let len = count_entries(conn)?;
5353
if len == 0 {

src/commands/get.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
io::{Read, Write, stdin, stdout},
3-
path::PathBuf,
3+
path::Path,
44
};
55

66
use miette::{Context, IntoDiagnostic, Result, miette};
@@ -18,7 +18,7 @@ use crate::{
1818
};
1919

2020
#[tracing::instrument(skip(path_db))]
21-
pub fn execute(path_db: PathBuf, args: GetDelArgs) -> Result<()> {
21+
pub fn execute(path_db: &Path, args: GetDelArgs) -> Result<()> {
2222
let GetDelArgs { input, index } = args;
2323

2424
assert!(
@@ -47,7 +47,7 @@ pub fn execute(path_db: PathBuf, args: GetDelArgs) -> Result<()> {
4747
Ok(())
4848
}
4949

50-
fn get_entry(path_db: PathBuf, mut input: String) -> Result<ClipboardEntry> {
50+
fn get_entry(path_db: &Path, mut input: String) -> Result<ClipboardEntry> {
5151
// Read from STDIN if no argument given
5252
if input.is_empty() {
5353
stdin()
@@ -58,12 +58,12 @@ fn get_entry(path_db: PathBuf, mut input: String) -> Result<ClipboardEntry> {
5858
}
5959

6060
let id = extract_id(input)?;
61-
let conn = init_db(&path_db)?;
61+
let conn = init_db(path_db)?;
6262
get_entry_by_id(&conn, id)
6363
}
6464

65-
fn get_entry_rel(path_db: PathBuf, i: isize) -> Result<ClipboardEntry> {
66-
let conn = &init_db(&path_db)?;
65+
fn get_entry_rel(path_db: &Path, i: isize) -> Result<ClipboardEntry> {
66+
let conn = &init_db(path_db)?;
6767

6868
let len = count_entries(conn)?;
6969
if len == 0 {

src/commands/list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
io::{Cursor, Write, stdout},
3-
path::PathBuf,
3+
path::Path,
44
};
55

66
use content_inspector::ContentType;
@@ -73,7 +73,7 @@ fn preview(id: u64, data: &[u8], width: usize) -> String {
7373
}
7474

7575
#[tracing::instrument(skip(path_db))]
76-
pub fn execute(path_db: PathBuf, args: ListArgs) -> Result<()> {
76+
pub fn execute(path_db: &Path, args: ListArgs) -> Result<()> {
7777
let ListArgs {
7878
max_preview_width,
7979
reverse,
@@ -88,7 +88,7 @@ pub fn execute(path_db: PathBuf, args: ListArgs) -> Result<()> {
8888

8989
// Database only needed to get the entries - avoid locking
9090
let entries = {
91-
let conn = init_db(&path_db)?;
91+
let conn = init_db(path_db)?;
9292
let mut entries = get_all_entries(&conn, preview_width)?;
9393
if reverse {
9494
entries.reverse();

src/commands/store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
io::{Read, stdin},
3-
path::PathBuf,
3+
path::Path,
44
};
55

66
use miette::{Context, IntoDiagnostic, Result, miette};
@@ -16,7 +16,7 @@ use crate::{
1616
};
1717

1818
#[instrument]
19-
pub fn execute(path_db: PathBuf, args: StoreArgs) -> Result<()> {
19+
pub fn execute(path_db: &Path, args: StoreArgs) -> Result<()> {
2020
let StoreArgs {
2121
max_entries,
2222
max_entry_age: max_age,
@@ -47,7 +47,7 @@ pub fn execute(path_db: PathBuf, args: StoreArgs) -> Result<()> {
4747
// As of writing, "clear" is not yet used by `wl-clipboard`.
4848
"clear" => {
4949
tracing::debug!("explicitly cleared clipboard");
50-
return delete_all_entries(&init_db(&path_db)?);
50+
return delete_all_entries(&init_db(path_db)?);
5151
}
5252
// Clipboard is empty - nothing to store
5353
"nil" => return Ok(()),
@@ -85,7 +85,7 @@ pub fn execute(path_db: PathBuf, args: StoreArgs) -> Result<()> {
8585
}
8686

8787
// Only get DB connection after parsing STDIN - avoid locking
88-
let conn = &init_db(&path_db)?;
88+
let conn = &init_db(path_db)?;
8989

9090
// Delete old entries
9191
let max_age = max_age.as_secs();

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ fn main() -> Result<()> {
2424
let path_db = args.database;
2525

2626
match args.command {
27-
Commands::List(args) => commands::list::execute(path_db, args),
28-
Commands::Store(args) => commands::store::execute(path_db, args),
29-
Commands::Get(args) => commands::get::execute(path_db, args),
30-
Commands::Delete(args) => commands::delete::execute(path_db, args),
31-
Commands::Clear => commands::clear::execute(path_db),
27+
Commands::List(args) => commands::list::execute(&path_db, args),
28+
Commands::Store(args) => commands::store::execute(&path_db, args),
29+
Commands::Get(args) => commands::get::execute(&path_db, args),
30+
Commands::Delete(args) => commands::delete::execute(&path_db, args),
31+
Commands::Clear => commands::clear::execute(&path_db),
3232
}
3333
.inspect_err(trace_err)
3434
}

0 commit comments

Comments
 (0)