Skip to content

Commit 57826a3

Browse files
committed
incorporate feedback comments
1 parent ff58f38 commit 57826a3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/system/audit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::{CStr, CString};
22
use std::fs::{DirBuilder, File, Metadata, OpenOptions};
33
use std::io::{self, Error, ErrorKind};
4-
use std::os::fd::{AsRawFd, FromRawFd};
4+
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd};
55
use std::os::unix::{
66
ffi::OsStrExt,
77
fs::{DirBuilderExt, MetadataExt, PermissionsExt},
@@ -115,7 +115,7 @@ fn secure_open_impl(
115115
}
116116

117117
#[cfg_attr(not(feature = "sudoedit"), allow(dead_code))]
118-
fn open_at(parent: &File, file_name: &CStr, create: bool) -> io::Result<File> {
118+
fn open_at(parent: BorrowedFd, file_name: &CStr, create: bool) -> io::Result<OwnedFd> {
119119
let flags = if create {
120120
libc::O_NOFOLLOW | libc::O_RDWR | libc::O_CREAT
121121
} else {
@@ -135,14 +135,14 @@ fn open_at(parent: &File, file_name: &CStr, create: bool) -> io::Result<File> {
135135
mode,
136136
))?;
137137

138-
Ok(File::from_raw_fd(fd))
138+
Ok(OwnedFd::from_raw_fd(fd))
139139
}
140140
}
141141

142-
#[cfg_attr(not(feature = "sudoedit"), allow(dead_code))]
143142
/// This opens a file making sure that
144143
/// - no directory leading up to the file is editable by the user
145144
/// - no components are a symbolic link
145+
#[cfg_attr(not(feature = "sudoedit"), allow(dead_code))]
146146
fn traversed_secure_open(path: impl AsRef<Path>, user: &User) -> io::Result<File> {
147147
let path = path.as_ref();
148148

@@ -191,11 +191,11 @@ fn traversed_secure_open(path: impl AsRef<Path>, user: &User) -> io::Result<File
191191
}
192192
};
193193

194-
cur = open_at(&cur, &dir, false)?;
194+
cur = open_at(cur.as_fd(), &dir, false)?.into();
195195
user_cannot_write(&cur)?;
196196
}
197197

198-
cur = open_at(&cur, &CString::new(file_name.as_bytes())?, true)?;
198+
cur = open_at(cur.as_fd(), &CString::new(file_name.as_bytes())?, true)?.into();
199199
user_cannot_write(&cur)?;
200200

201201
Ok(cur)

0 commit comments

Comments
 (0)