Browse Source

get the received arguments from the socket before getting the credentials of the sender.

master
Aitor 9 months ago
parent
commit
4d04d476dd
  1. 59
      src/main.c

59
src/main.c

@ -63,9 +63,9 @@
#include "sigact.h"
#include "start_periodic.h"
#define BUFFER_SIZE 128
#define MAX_SIZE 1024
//#define BUFFER_SIZE 128 /* already defined in simple-netaid/entry.h */
//#define PROTOCOL 0 /* already defined in simple-netaid/entry.h */
#define ACTIVE_WIFIS_SOCKET "/tmp/snetaid_active_wifis.socket"
#define WHITELIST "/etc/simple-netaid/whitelist"
@ -982,8 +982,8 @@ void read_arguments()
int sz, rc = -1;
char *arr_pid = NULL;
char buffer[BUFFER_SIZE] = {0};
const char *device;
int option;
const char *device, *essid, *passwd, *filename = NULL, *dname;
// Reference: https://man7.org/tlpi/code/online/dist/sockets/scm_cred_recv.c.html
@ -1026,7 +1026,32 @@ void read_arguments()
option = atoi(read_buffer(dfData, buffer));
num_messages = atoi(read_buffer(dfData, buffer));
device = read_buffer(dfData, buffer);
device = read_buffer(dfData, buffer);
switch(option) {
case 4:
essid = read_buffer(dfData, buffer);
passwd = read_buffer(dfData, buffer);
break;
case 5:
essid = read_buffer(dfData, buffer);
passwd = read_buffer(dfData, buffer);
filename = read_buffer(dfData, buffer);
break;
case 6:
filename = read_buffer(dfData, buffer);
break;
case 7:
filename = read_buffer(dfData, buffer);
dname = dirname(buffer);
break;
default:
break;
}
/* We must set the SO_PASSCRED socket option in order to receive
credentials */
@ -1152,26 +1177,16 @@ void read_arguments()
break;
case 4:
{
const char *essid = read_buffer(dfData, buffer);
const char *passwd = read_buffer(dfData, buffer);
wireless_connection(device, essid, passwd, NULL);
}
wireless_connection(device, essid, passwd, NULL);
break;
case 5:
{
const char *essid = read_buffer(dfData, buffer);
const char *passwd = read_buffer(dfData, buffer);
const char *filename = read_buffer(dfData, buffer);
wireless_connection(device, essid, passwd, filename);
}
wireless_connection(device, essid, passwd, filename);
break;
case 6:
{
struct sbuf cmd;
const char *filename = read_buffer(dfData, buffer);
kill_all_processes();
ipaddr_flush(device);
interface_down(device);
@ -1187,16 +1202,12 @@ void read_arguments()
break;
case 7:
{
const char *filename = read_buffer(dfData, buffer);
const char *dname = dirname(buffer);
if(!strcmp(dname, WIFI_DIR)) {
remove(filename);
if(!file_exists(filename)) {
log_error("Error deleting %s file.\n", filename);
}
if(!strcmp(dname, WIFI_DIR)) {
remove(filename);
if(!file_exists(filename)) {
log_error("Error deleting %s file.\n", filename);
}
}
}
break;
default:

Loading…
Cancel
Save