Skip to content

Commit

Permalink
Merge 0049126 into a57028b
Browse files Browse the repository at this point in the history
  • Loading branch information
gotlougit committed Sep 15, 2023
2 parents a57028b + 0049126 commit 84446cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/ipc_server_with_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn run_webserver(db_socket_path: &str) {
// extrasafe context
SafetyContext::new()
.enable(Networking::nothing()
.allow_connect().yes_really()
.allow_running_tcp_servers()).unwrap()
.apply_to_current_thread()
.unwrap();
Expand Down Expand Up @@ -154,6 +155,8 @@ fn run_db(socket_path: &str) {
// after opening connection socket and db file, set extrasafe context
SafetyContext::new()
.enable(Networking::nothing()
.allow_connect()
.yes_really()
.allow_running_unix_servers()
).unwrap()
.enable(SystemIO::nothing()
Expand Down Expand Up @@ -230,6 +233,8 @@ fn run_client_write(msg: &str) {
// Set up extrasafe context
SafetyContext::new()
.enable(Networking::nothing()
.allow_connect()
.yes_really()
.allow_start_tcp_clients()).unwrap()
.apply_to_current_thread()
.unwrap();
Expand Down Expand Up @@ -272,6 +277,7 @@ fn run_client_read() {
SafetyContext::new()
.enable(Networking::nothing()
// Necessary for DNS
.allow_connect().yes_really()
.allow_start_udp_servers().yes_really()
.allow_start_tcp_clients()).unwrap()
// For some reason only if we make two requests with a client does it use multiple threads,
Expand Down
1 change: 1 addition & 0 deletions examples/network_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ fn main() {
thread::sleep(std::time::Duration::from_millis(50));
SafetyContext::new()
.enable(Networking::nothing()
.allow_connect().yes_really()
.allow_running_tcp_servers()
.allow_start_tcp_clients()
).unwrap()
Expand Down
2 changes: 2 additions & 0 deletions examples/server_with_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ fn run_client_write(msg: &str) {
// Set up extrasafe context
SafetyContext::new()
.enable(Networking::nothing()
.allow_connect().yes_really()
.allow_start_tcp_clients()).unwrap()
.apply_to_current_thread()
.unwrap();
Expand Down Expand Up @@ -224,6 +225,7 @@ fn run_client_read() {
// enable extrasafe context
SafetyContext::new()
.enable(Networking::nothing()
.allow_connect().yes_really()
// Necessary for DNS
.allow_start_udp_servers().yes_really()
.allow_start_tcp_clients()).unwrap()
Expand Down
9 changes: 7 additions & 2 deletions src/builtins/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ impl Networking {
YesReally::new(self)
}

/// Allow `connect` syscall
pub fn allow_connect(mut self) -> YesReally<Networking> {
self.allowed.extend(&[Sysno::connect]);
YesReally::new(self)
}

/// Allow starting new TCP clients.
///
/// # Security Notes
Expand All @@ -201,8 +207,7 @@ impl Networking {
self.custom.entry(Sysno::socket)
.or_insert_with(Vec::new)
.push(rule);

self.allowed.extend(&[Sysno::connect]);

self.allowed.extend(NET_IO_SYSCALLS);
self.allowed.extend(NET_READ_SYSCALLS);
self.allowed.extend(NET_WRITE_SYSCALLS);
Expand Down

0 comments on commit 84446cc

Please sign in to comment.