Lines 44-55
Link Here
|
44 |
/* Command codes for foreground -> background communication */ |
44 |
/* Command codes for foreground -> background communication */ |
45 |
#define COMMAND_RUN_SCRIPT 0 |
45 |
#define COMMAND_RUN_SCRIPT 0 |
46 |
#define COMMAND_EXIT 1 |
46 |
#define COMMAND_EXIT 1 |
|
|
47 |
#define COMMAND_PING 2 |
47 |
|
48 |
|
48 |
/* Response codes for background -> foreground communication */ |
49 |
/* Response codes for background -> foreground communication */ |
49 |
#define RESPONSE_INIT_SUCCEEDED 10 |
50 |
#define RESPONSE_INIT_SUCCEEDED 10 |
50 |
#define RESPONSE_INIT_FAILED 11 |
51 |
#define RESPONSE_INIT_FAILED 11 |
51 |
#define RESPONSE_SCRIPT_SUCCEEDED 12 |
52 |
#define RESPONSE_SCRIPT_SUCCEEDED 12 |
52 |
#define RESPONSE_SCRIPT_FAILED 13 |
53 |
#define RESPONSE_SCRIPT_FAILED 13 |
|
|
54 |
#define RESPONSE_PING_REQUEST 14 |
53 |
|
55 |
|
54 |
/* Background process function */ |
56 |
/* Background process function */ |
55 |
static void down_root_server (const int fd, char *command, const char *argv[], const char *envp[], const int verb); |
57 |
static void down_root_server (const int fd, char *command, const char *argv[], const char *envp[], const int verb); |
Lines 388-393
Link Here
|
388 |
return 0; /* NOTREACHED */ |
390 |
return 0; /* NOTREACHED */ |
389 |
} |
391 |
} |
390 |
} |
392 |
} |
|
|
393 |
else if (type == OPENVPN_PLUGIN_UP && context->foreground_fd >= 0) /* no need to fork a second process */ |
394 |
{ |
395 |
|
396 |
/* Check process communication */ |
397 |
|
398 |
if (send_control (context->foreground_fd, COMMAND_PING) == -1) |
399 |
{ |
400 |
fprintf (stderr, "DOWN-ROOT: Error sending ping request signal to background process\n"); |
401 |
} |
402 |
else |
403 |
{ |
404 |
const int status = recv_control (context->foreground_fd); |
405 |
if (status == RESPONSE_PING_REQUEST) |
406 |
{ |
407 |
return OPENVPN_PLUGIN_FUNC_SUCCESS; |
408 |
} |
409 |
else |
410 |
{ |
411 |
fprintf (stderr, "DOWN-ROOT: Error receiving ping reception confirmation from background process\n"); |
412 |
} |
413 |
} |
414 |
} |
391 |
else if (type == OPENVPN_PLUGIN_DOWN && context->foreground_fd >= 0) |
415 |
else if (type == OPENVPN_PLUGIN_DOWN && context->foreground_fd >= 0) |
392 |
{ |
416 |
{ |
393 |
if (send_control (context->foreground_fd, COMMAND_RUN_SCRIPT) == -1) |
417 |
if (send_control (context->foreground_fd, COMMAND_RUN_SCRIPT) == -1) |
Lines 527-532
Link Here
|
527 |
} |
551 |
} |
528 |
break; |
552 |
break; |
529 |
|
553 |
|
|
|
554 |
case COMMAND_PING: /* allows to check if process is listening */ |
555 |
|
556 |
if (send_control (fd, RESPONSE_PING_REQUEST) == -1) |
557 |
{ |
558 |
fprintf (stderr, "DOWN-ROOT: BACKGROUND: write error on response socket [4]\n"); |
559 |
goto done; |
560 |
} |
561 |
break; |
562 |
|
530 |
case COMMAND_EXIT: |
563 |
case COMMAND_EXIT: |
531 |
goto done; |
564 |
goto done; |
532 |
|
565 |
|