about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-12-25 20:37:45 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-25 20:43:19 -0800
commit6ae7bf91b1828df915f261c25202ca4dc241bbe9 (patch)
treee0b42a9c763f36c3315ea43f9889095230558c42
parent16d949e2596fa56003cf01e3c78fa901e0614c0a (diff)
downloadteliva-6ae7bf91b1828df915f261c25202ca4dc241bbe9.tar.gz
network calls are now sandboxed
I _think_ I don't need to gate other socket calls; you can't do anything
without bind() and connect(). And they should be good places to dump
more precise details later about the kind of server or client connection
being attempted.
-rw-r--r--src/luasocket/usocket.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/luasocket/usocket.c b/src/luasocket/usocket.c
index acfe186..2fb77a1 100644
--- a/src/luasocket/usocket.c
+++ b/src/luasocket/usocket.c
@@ -7,6 +7,7 @@
 * the I/O call fail in the first place.
 \*=========================================================================*/
 #include "luasocket.h"
+#include "../teliva.h"
 
 #include "socket.h"
 #include "pierror.h"
@@ -91,7 +92,7 @@ int socket_close(void) {
 }
 
 /*-------------------------------------------------------------------------*\
-* Close and inutilize socket
+* Close and initialize socket
 \*-------------------------------------------------------------------------*/
 void socket_destroy(p_socket ps) {
     if (*ps != SOCKET_INVALID) {
@@ -131,6 +132,10 @@ int socket_create(p_socket ps, int domain, int type, int protocol) {
 \*-------------------------------------------------------------------------*/
 int socket_bind(p_socket ps, SA *addr, socklen_t len) {
     int err = IO_DONE;
+    if (!net_operations_allowed) {
+      Previous_message = "app tried to start a server; adjust its permissions (ctrl-p) if that is expected";
+      return IO_CLOSED;
+    }
     socket_setblocking(ps);
     if (bind(*ps, addr, len) < 0) err = errno;
     socket_setnonblocking(ps);
@@ -160,6 +165,10 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
     int err;
     /* avoid calling on closed sockets */
     if (*ps == SOCKET_INVALID) return IO_CLOSED;
+    if (!net_operations_allowed) {
+      Previous_message = "app tried to connect to a remote server; adjust its permissions (ctrl-p) if that is expected";
+      return IO_CLOSED;
+    }
     /* call connect until done or failed without being interrupted */
     do if (connect(*ps, addr, len) == 0) return IO_DONE;
     while ((err = errno) == EINTR);
a id='n184' href='#n184'>184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513