diff --git a/broadcast/broadcast b/broadcast/broadcast index 1837f52..ccc9036 100755 Binary files a/broadcast/broadcast and b/broadcast/broadcast differ diff --git a/broadcast/broadcast.c b/broadcast/broadcast.c index 0a5eaf2..e6452af 100644 --- a/broadcast/broadcast.c +++ b/broadcast/broadcast.c @@ -243,7 +243,7 @@ int main(int argc, char **argv) signal(SIGABRT, SIG_IGN); signal(SIGINT, int_handler); // now try to request new channel from hotline - fd = open_unix_socket(argv[1]); + fd = open_socket(argv[1]); if (fd == -1) { M_ERROR(MODULE_NAME, "Unable to open the hotline: %s", argv[1]); @@ -262,7 +262,7 @@ int main(int argc, char **argv) (void)close(fd); return -1; } - M_DEBUG(MODULE_NAME, "Wait for comfirm creation of %s", argv[2]); + M_DEBUG(MODULE_NAME, "Wait for confirm creation of %s", argv[2]); // now wait for message if (msg_read(fd, &response) == -1) { diff --git a/runner.c b/runner.c index 39529e8..af37ab2 100644 --- a/runner.c +++ b/runner.c @@ -42,6 +42,7 @@ static void execute_command(list_t *plist) ASSERT(pid != -1, "Unable to fork: %s", strerror(errno)); if (pid == 0) { + M_LOG(MODULE_NAME, "Running %s", cmd.params[0]); execve(cmd.params[0], &cmd.params[0], &cmd.envs[0]); // Nothing below this line should be executed by child process. If so, // it means that the execl function wasn't successfull, so lets exit: diff --git a/runner.ini b/runner.ini index 32641cf..c459a0a 100644 --- a/runner.ini +++ b/runner.ini @@ -1,21 +1,27 @@ [vterm] exec = /opt/www/bin/vterm -param = /opt/www/tmp/channels/antd_hotline.sock +param = unix:/opt/www/tmp/antd_hotline.sock debug = 0 -[notification_fifo] +# [notification_fifo] +# exec = /opt/www/bin/wfifo +# param = unix:/opt/www/tmp/antd_hotline.sock +# param = notification +# param = /var/wfifo_notification +# param = r +# debug = 1 + +# [broadcast] +# exec = /opt/www/bin/broadcast +# param = unix:/opt/www/tmp/antd_hotline.sock +# param = broadcast +# debug = 1 + +# used only by tunnel to authentificate user +[tunnel_keychain] exec = /opt/www/bin/wfifo -param = /opt/www/tmp/channels/antd_hotline.sock -param = notification -param = /var/wfifo_notification +param = unix:/opt/www/tmp/antd_hotline.sock +param = keychain +param = /opt/www/tmp/antunnel_keychain param = r debug = 1 - -[broadcast] -exec = /opt/www/bin/broadcast -param = /opt/www/tmp/channels/antd_hotline.sock -param = broadcast -debug = 1 - -;service=/opt/www/bin/wfifo /opt/www/tmp/channels/antd_hotline.sock server_to_client /var/wfifo_s2c r -;service=/opt/www/bin/wfifo /opt/www/tmp/channels/antd_hotline.sock client_to_server /var/wfifo_c2s w \ No newline at end of file diff --git a/syslog/syslog.c b/syslog/syslog.c index 65d6dfa..6a0c06e 100644 --- a/syslog/syslog.c +++ b/syslog/syslog.c @@ -95,7 +95,7 @@ int main(int argc, char **argv) M_LOG(MODULE_NAME, "Unix domain socket: %s created", argv[3]); M_LOG(MODULE_NAME, "Hotline is: %s", argv[1]); // now try to request new channel from hotline - fd = open_unix_socket(argv[1]); + fd = open_socket(argv[1]); if (fd == -1) { M_ERROR(MODULE_NAME, "Unable to open the hotline: %s", argv[1]); diff --git a/tunnel.c b/tunnel.c index 2a6506d..13753cd 100644 --- a/tunnel.c +++ b/tunnel.c @@ -5,11 +5,16 @@ #include #include #include +#include #include #include "tunnel.h" #define MODULE_NAME "api" +#ifdef MAX_PATH_LEN +#undef MAX_PATH_LEN +#endif +#define MAX_PATH_LEN 108 static int guard_read(int fd, void* buffer, size_t size) { @@ -126,7 +131,7 @@ static uint8_t* msg_read_payload(int fd, uint32_t* size) } -int open_unix_socket(char* path) +static int open_unix_socket(char* path) { struct sockaddr_un address; address.sun_family = AF_UNIX; @@ -147,6 +152,69 @@ int open_unix_socket(char* path) return fd; } +static int open_tcp_socket(char * address, int port) +{ + struct sockaddr_in servaddr; + int fd = socket(AF_INET, SOCK_STREAM, 0); + if (fd == -1) + { + M_ERROR(MODULE_NAME, "Cannot create TCP socket %s:%d: %s",address, port, strerror(errno)); + return -1; + } + + bzero(&servaddr, sizeof(servaddr)); + + // assign IP, PORT + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr(address); + servaddr.sin_port = htons(port); + + // connect the client socket to server socket + if (connect(fd, (struct sockaddr*)&servaddr, sizeof(servaddr))!= 0) { + M_ERROR(MODULE_NAME, "Unable to connect to socket '%s:%d': %s", address, port, strerror(errno)); + close(fd); + return -1; + } + M_LOG(MODULE_NAME, "Connected to server: %s:%d at [%d]", address, port, fd); + return fd; +} + +int open_socket( char *path) +{ + regmatch_t regex_matches[3]; + if(strncmp(path,"unix:", 5) == 0) + { + if(strlen(path + 5) > MAX_PATH_LEN - 1) + { + M_ERROR(MODULE_NAME, "socket configuration is too long: %s", path); + return -1; + } + M_LOG(MODULE_NAME, "Found Unix domain socket configuration: %s", path + 5); + return open_unix_socket(path + 5); + } + else if(regex_match("^([a-zA-Z0-9\\-_\\.]+):([0-9]+)$", path,3, regex_matches)) + { + if(regex_matches[1].rm_eo - regex_matches[1].rm_so > MAX_PATH_LEN - 1) + { + M_ERROR(MODULE_NAME, "socket configuration is too long: %s", path); + return -1; + } + char address[MAX_PATH_LEN]; + memcpy(address, path + regex_matches[2].rm_so, regex_matches[2].rm_eo - regex_matches[2].rm_so); + int port = atoi(address); + (void*) memset(address, 0, MAX_PATH_LEN); + memcpy(address, path + regex_matches[1].rm_so, regex_matches[1].rm_eo - regex_matches[1].rm_so); + M_LOG(MODULE_NAME, "Found TCP socket configuration: %s:%d", address, port); + return open_tcp_socket(address, port); + } + else + { + M_ERROR(MODULE_NAME, "Unknown socket configuration: %s", path); + return -1; + } + return 0; +} + int msg_read(int fd, tunnel_msg_t* msg) { @@ -248,4 +316,41 @@ int msg_write(int fd, tunnel_msg_t* msg) return -1; } return 0; +} + + +int regex_match(const char* expr,const char* search, int msize, regmatch_t* matches) +{ + regex_t regex; + int reti; + char msgbuf[100]; + int ret; + /* Compile regular expression */ + reti = regcomp(®ex, expr, REG_ICASE | REG_EXTENDED); + if( reti ){ + //ERROR("Could not compile regex: %s",expr); + regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); + M_ERROR(MODULE_NAME, "Regex match failed: %s", msgbuf); + //return 0; + } + + /* Execute regular expression */ + reti = regexec(®ex, search, msize, matches, 0); + if( !reti ){ + //LOG("Match"); + ret = 1; + } + else if( reti == REG_NOMATCH ){ + //LOG("No match"); + ret = 0; + } + else{ + regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); + //ERROR("Regex match failed: %s\n", msgbuf); + ret = 0; + } + + + regfree(®ex); + return ret; } \ No newline at end of file diff --git a/tunnel.h b/tunnel.h index 416ae86..ede31f1 100644 --- a/tunnel.h +++ b/tunnel.h @@ -2,6 +2,7 @@ #define TUNNEL_H #include #include +#include #include "log.h" #define MAX_CHANNEL_PATH 108 @@ -31,10 +32,9 @@ typedef struct{ uint8_t* data; } tunnel_msg_t; -int open_unix_socket(char* path); +int open_socket(char* path); int msg_write(int fd, tunnel_msg_t* msg); int msg_read(int fd, tunnel_msg_t* msg); - - +int regex_match(const char* expr,const char* search, int msize, regmatch_t* matches); #endif \ No newline at end of file diff --git a/v4l2cam/v4l2cam.c b/v4l2cam/v4l2cam.c index eda3f0d..c02e608 100644 --- a/v4l2cam/v4l2cam.c +++ b/v4l2cam/v4l2cam.c @@ -449,7 +449,7 @@ int main(const int argc, const char **argv) { exit(1); } - sock = open_unix_socket((char *)argv[1]); + sock = open_socket((char *)argv[1]); if (sock == -1) { M_ERROR(MODULE_NAME, "Unable to open the hotline: %s", argv[1]); diff --git a/vterm/vterm.c b/vterm/vterm.c index acda558..55c0c24 100644 --- a/vterm/vterm.c +++ b/vterm/vterm.c @@ -336,7 +336,7 @@ int main(int argc, char **argv) signal(SIGINT, int_handler); M_LOG(MODULE_NAME, "Hotline is: %s", argv[1]); // now try to request new channel from hotline - fd = open_unix_socket(argv[1]); + fd = open_socket(argv[1]); if (fd == -1) { M_ERROR(MODULE_NAME, "Unable to open the hotline: %s", argv[1]); diff --git a/wfifo/wfifo.c b/wfifo/wfifo.c index 0c9ed6b..3167fee 100644 --- a/wfifo/wfifo.c +++ b/wfifo/wfifo.c @@ -213,6 +213,7 @@ int main(int argc, char **argv) if (argc != 5) { + M_LOG(MODULE_NAME, "Usage: %s path/to/hotline/socket channel_name input_file r/w\n", argv[0]); printf("Usage: %s path/to/hotline/socket channel_name input_file r/w\n", argv[0]); return -1; } @@ -221,7 +222,7 @@ int main(int argc, char **argv) signal(SIGINT, int_handler); // now try to request new channel from hotline - fd = open_unix_socket(argv[1]); + fd = open_socket(argv[1]); if (fd == -1) { M_ERROR(MODULE_NAME, "Unable to open the hotline: %s", argv[1]); @@ -240,7 +241,7 @@ int main(int argc, char **argv) (void)close(fd); return -1; } - M_LOG(MODULE_NAME, "Wait for comfirm creation of %s", argv[2]); + M_LOG(MODULE_NAME, "Wait for confirm creation of %s", argv[2]); // now wait for message if (msg_read(fd, &msg) == -1) {