summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHåkon Nessjøen <haakon.nessjoen@gmail.com>2010-12-24 01:52:10 +0100
committerHåkon Nessjøen <haakon.nessjoen@gmail.com>2010-12-24 01:52:10 +0100
commit2d9057c497585c4eb76e5f3ad4f623da56a2e28c (patch)
tree4f519791995a4d83bdf559a98611d104575e91ff
parentdbadc1ab26b3cca6b3697d9c07f284f582dde75d (diff)
downloadMAC-Telnet-2d9057c497585c4eb76e5f3ad4f623da56a2e28c.tar.gz
MAC-Telnet-2d9057c497585c4eb76e5f3ad4f623da56a2e28c.zip
Changed naming convention on function names
-rw-r--r--console.c8
-rw-r--r--console.h8
-rw-r--r--devices.c8
-rw-r--r--devices.h8
-rw-r--r--mactelnet.c128
-rw-r--r--mactelnetd.c140
-rw-r--r--mndp.c2
-rw-r--r--protocol.c14
-rw-r--r--protocol.h12
-rw-r--r--udp.c2
-rw-r--r--udp.h2
-rw-r--r--users.c4
-rw-r--r--users.h4
13 files changed, 170 insertions, 170 deletions
diff --git a/console.c b/console.c
index 090e11c..60c854e 100644
--- a/console.c
+++ b/console.c
@@ -26,7 +26,7 @@
struct termios origTerm;
-int rawTerm() {
+int raw_term() {
struct termios new;
if (tcgetattr(STDIN_FILENO, &origTerm) < 0) {
@@ -49,7 +49,7 @@ int rawTerm() {
return 0;
}
-int resetTerm() {
+int reset_term() {
if (tcsetattr(STDIN_FILENO, TCSANOW, &origTerm) < 0) {
perror("tcsetattr");
return -1;
@@ -57,7 +57,7 @@ int resetTerm() {
return 0;
}
-int getTerminalSize(unsigned short *width, unsigned short *height) {
+int get_terminal_size(unsigned short *width, unsigned short *height) {
struct winsize ws;
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != 0) {
@@ -71,7 +71,7 @@ int getTerminalSize(unsigned short *width, unsigned short *height) {
return 0;
}
-int setTerminalSize(int fd, unsigned short width, unsigned short height) {
+int set_terminal_size(int fd, unsigned short width, unsigned short height) {
struct winsize ws;
ws.ws_col = width;
diff --git a/console.h b/console.h
index cb55797..3fcca2c 100644
--- a/console.h
+++ b/console.h
@@ -1,4 +1,4 @@
-extern int getTerminalSize(unsigned short *width, unsigned short *height);
-extern int rawTerm();
-extern int resetTerm();
-extern int setTerminalSize(int fd, unsigned short width, unsigned short height);
+extern int get_terminal_size(unsigned short *width, unsigned short *height);
+extern int raw_term();
+extern int reset_term();
+extern int set_terminal_size(int fd, unsigned short width, unsigned short height);
diff --git a/devices.c b/devices.c
index a40ee9d..ffdc6b3 100644
--- a/devices.c
+++ b/devices.c
@@ -35,7 +35,7 @@
/* Functions using NETDEVICE api */
-int getDeviceIndex(int sockfd, char *deviceName) {
+int get_device_index(int sockfd, char *deviceName) {
struct ifreq ifr;
/* Find interface index from deviceName */
@@ -48,7 +48,7 @@ int getDeviceIndex(int sockfd, char *deviceName) {
return ifr.ifr_ifindex;
}
-int getDeviceMAC(const int sockfd, const char *deviceName, unsigned char *mac) {
+int get_device_mac(const int sockfd, const char *deviceName, unsigned char *mac) {
struct ifreq ifr;
/* Find interface hardware address from deviceName */
@@ -62,7 +62,7 @@ int getDeviceMAC(const int sockfd, const char *deviceName, unsigned char *mac) {
return 1;
}
-int getDeviceIp(const int sockfd, const char *deviceName, struct sockaddr_in *ip) {
+int get_device_ip(const int sockfd, const char *deviceName, struct sockaddr_in *ip) {
struct ifconf ifc;
struct ifreq *ifr;
int i,numDevices;
@@ -106,7 +106,7 @@ int getDeviceIp(const int sockfd, const char *deviceName, struct sockaddr_in *ip
return -1;
}
-int getIps(char *name, int nameLen, struct sockaddr_in *ip) {
+int get_ips(char *name, int nameLen, struct sockaddr_in *ip) {
static int first = 1;
static struct ifaddrs *int_addrs;
static const struct ifaddrs *int_cursor;
diff --git a/devices.h b/devices.h
index d917401..dd8abe5 100644
--- a/devices.h
+++ b/devices.h
@@ -1,4 +1,4 @@
-extern int getDeviceIndex(int sockfd, char *deviceName);
-extern int getDeviceMAC(const int sockfd, const char *deviceName, unsigned char *mac);
-extern int getDeviceIp(const int sockfd, const char *deviceName, struct sockaddr_in *ip);
-int getIps(char *name, int nameLen, struct sockaddr_in *ip);
+extern int get_device_index(int sockfd, char *deviceName);
+extern int get_device_mac(const int sockfd, const char *deviceName, unsigned char *mac);
+extern int get_device_ip(const int sockfd, const char *deviceName, struct sockaddr_in *ip);
+int get_ips(char *name, int nameLen, struct sockaddr_in *ip);
diff --git a/mactelnet.c b/mactelnet.c
index 8049ff3..54f9c96 100644
--- a/mactelnet.c
+++ b/mactelnet.c
@@ -47,7 +47,7 @@ unsigned int incounter = 0;
int sessionkey = 0;
int running = 1;
-unsigned char broadcastMode = 1;
+unsigned char broadcast_mode = 1;
unsigned char terminalMode = 0;
unsigned char srcmac[ETH_ALEN];
@@ -66,25 +66,25 @@ char password[255];
/* Protocol data direction */
unsigned char mt_direction_fromserver = 0;
-unsigned int sendSocket;
+unsigned int send_socket;
-static int sendUDP(struct mt_packet *packet) {
+static int send_udp(struct mt_packet *packet) {
- if (broadcastMode) {
+ if (broadcast_mode) {
/* Init SendTo struct */
struct sockaddr_in socket_address;
socket_address.sin_family = AF_INET;
socket_address.sin_port = htons(MT_MACTELNET_PORT);
socket_address.sin_addr.s_addr = htonl(INADDR_BROADCAST);
- return sendto(sendSocket, packet->data, packet->size, 0, (struct sockaddr*)&socket_address, sizeof(socket_address));
+ return sendto(send_socket, packet->data, packet->size, 0, (struct sockaddr*)&socket_address, sizeof(socket_address));
} else {
- return sendCustomUDP(sockfd, deviceIndex, srcmac, dstmac, &sourceip, sourceport, &destip, MT_MACTELNET_PORT, packet->data, packet->size);
+ return send_custom_udp(sockfd, deviceIndex, srcmac, dstmac, &sourceip, sourceport, &destip, MT_MACTELNET_PORT, packet->data, packet->size);
}
}
-static void sendAuthData(char *username, char *password) {
+static void send_auth(char *username, char *password) {
struct mt_packet data;
unsigned short width = 0;
unsigned short height = 0;
@@ -92,7 +92,7 @@ static void sendAuthData(char *username, char *password) {
char md5data[100];
unsigned char md5sum[17];
int result;
- int plen = 0;
+ int plen;
md5_state_t state;
/* Concat string of 0 + password + encryptionkey */
@@ -108,20 +108,20 @@ static void sendAuthData(char *username, char *password) {
md5sum[0] = 0;
/* Send combined packet to server */
- initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
- plen += addControlPacket(&data, MT_CPTYPE_PASSWORD, md5sum, 17);
- plen += addControlPacket(&data, MT_CPTYPE_USERNAME, username, strlen(username));
- plen += addControlPacket(&data, MT_CPTYPE_TERM_TYPE, terminal, strlen(terminal));
+ init_packet(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
+ plen = add_control_packet(&data, MT_CPTYPE_PASSWORD, md5sum, 17);
+ plen += add_control_packet(&data, MT_CPTYPE_USERNAME, username, strlen(username));
+ plen += add_control_packet(&data, MT_CPTYPE_TERM_TYPE, terminal, strlen(terminal));
- if (getTerminalSize(&width, &height) != -1) {
- plen += addControlPacket(&data, MT_CPTYPE_TERM_WIDTH, &width, 2);
- plen += addControlPacket(&data, MT_CPTYPE_TERM_HEIGHT, &height, 2);
+ if (get_terminal_size(&width, &height) != -1) {
+ plen += add_control_packet(&data, MT_CPTYPE_TERM_WIDTH, &width, 2);
+ plen += add_control_packet(&data, MT_CPTYPE_TERM_HEIGHT, &height, 2);
}
outcounter += plen;
/* TODO: handle result */
- result = sendUDP(&data);
+ result = send_udp(&data);
}
static void sig_winch(int sig) {
@@ -130,22 +130,22 @@ static void sig_winch(int sig) {
int result,plen;
/* terminal height/width has changed, inform server */
- if (getTerminalSize(&width, &height) != -1) {
- initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
- plen = addControlPacket(&data, MT_CPTYPE_TERM_WIDTH, &width, 2);
- plen += addControlPacket(&data, MT_CPTYPE_TERM_HEIGHT, &height, 2);
+ if (get_terminal_size(&width, &height) != -1) {
+ init_packet(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
+ plen = add_control_packet(&data, MT_CPTYPE_TERM_WIDTH, &width, 2);
+ plen += add_control_packet(&data, MT_CPTYPE_TERM_HEIGHT, &height, 2);
outcounter += plen;
- result = sendUDP(&data);
+ result = send_udp(&data);
}
/* reinstate signal handler */
signal(SIGWINCH, sig_winch);
}
-static void handlePacket(unsigned char *data, int data_len) {
+static void handle_packet(unsigned char *data, int data_len) {
struct mt_mactelnet_hdr pkthdr;
- parsePacket(data, &pkthdr);
+ parse_packet(data, &pkthdr);
/* We only care about packets with correct sessionkey */
if (pkthdr.seskey != sessionkey) {
@@ -160,8 +160,8 @@ static void handlePacket(unsigned char *data, int data_len) {
int success = 0;
/* Always transmit ACKNOWLEDGE packets in response to DATA packets */
- initPacket(&odata, MT_PTYPE_ACK, srcmac, dstmac, sessionkey, pkthdr.counter + (data_len - MT_HEADER_LEN));
- result = sendUDP(&odata);
+ init_packet(&odata, MT_PTYPE_ACK, srcmac, dstmac, sessionkey, pkthdr.counter + (data_len - MT_HEADER_LEN));
+ result = send_udp(&odata);
/* Accept first packet, and all packets greater than incounter, and if counter has
wrapped around. */
@@ -173,14 +173,14 @@ static void handlePacket(unsigned char *data, int data_len) {
}
/* Parse controlpacket data */
- success = parseControlPacket(data + MT_HEADER_LEN, data_len - MT_HEADER_LEN, &cpkt);
+ success = parse_control_packet(data + MT_HEADER_LEN, data_len - MT_HEADER_LEN, &cpkt);
while (success) {
/* If we receive encryptionkey, transmit auth data back */
if (cpkt.cptype == MT_CPTYPE_ENCRYPTIONKEY) {
memcpy(encryptionkey, cpkt.data, cpkt.length);
- sendAuthData(username, password);
+ send_auth(username, password);
}
/* If the (remaining) data did not have a control-packet magic byte sequence,
@@ -194,7 +194,7 @@ static void handlePacket(unsigned char *data, int data_len) {
terminal data may arrive, so we set up the terminal to raw mode. */
else if (cpkt.cptype == MT_CPTYPE_END_AUTH) {
/* stop input buffering at all levels. Give full control of terminal to RouterOS */
- rawTerm();
+ raw_term();
setvbuf(stdin, (char*)NULL, _IONBF, 0);
/* we have entered "terminal mode" */
@@ -205,7 +205,7 @@ static void handlePacket(unsigned char *data, int data_len) {
}
/* Parse next controlpacket */
- success = parseControlPacket(NULL, 0, &cpkt);
+ success = parse_control_packet(NULL, 0, &cpkt);
}
}
else if (pkthdr.ptype == MT_PTYPE_ACK) {
@@ -218,8 +218,8 @@ static void handlePacket(unsigned char *data, int data_len) {
int result=0;
/* Acknowledge the disconnection by sending a END packet in return */
- initPacket(&odata, MT_PTYPE_END, srcmac, dstmac, pkthdr.seskey, 0);
- result = sendUDP(&odata);
+ init_packet(&odata, MT_PTYPE_END, srcmac, dstmac, pkthdr.seskey, 0);
+ result = send_udp(&odata);
fprintf(stderr, "Connection closed.\n");
@@ -230,7 +230,7 @@ static void handlePacket(unsigned char *data, int data_len) {
}
}
-static int findInterface() {
+static int find_interface() {
struct mt_packet data;
struct sockaddr_in myip;
int success;
@@ -240,7 +240,7 @@ static int findInterface() {
struct timeval timeout;
int optval = 1;
- while ((success = getIps(devicename, 128, &myip))) {
+ while ((success = get_ips(devicename, 128, &myip))) {
char str[INET_ADDRSTRLEN];
/* Skip loopback interfaces */
@@ -267,17 +267,17 @@ static int findInterface() {
}
/* Find the mac address for the current device */
- if (getDeviceMAC(testsocket, devicename, srcmac) < 0) {
+ if (get_device_mac(testsocket, devicename, srcmac) < 0) {
close(testsocket);
continue;
}
- /* Set the global socket handle for sendUDP() */
- sendSocket = testsocket;
+ /* Set the global socket handle for send_udp() */
+ send_socket = testsocket;
/* Send a SESSIONSTART message with the current device */
- initPacket(&data, MT_PTYPE_SESSIONSTART, srcmac, dstmac, sessionkey, 0);
- sendUDP(&data);
+ init_packet(&data, MT_PTYPE_SESSIONSTART, srcmac, dstmac, sessionkey, 0);
+ send_udp(&data);
timeout.tv_sec = connect_timeout;
timeout.tv_usec = 0;
@@ -308,7 +308,7 @@ int main (int argc, char **argv) {
struct timeval timeout;
int keepalive_counter = 0;
fd_set read_fds;
- unsigned char printHelp = 0, haveUsername = 0, havePassword = 0;
+ unsigned char print_help = 0, have_username = 0, have_password = 0;
int c;
int optval = 1;
@@ -321,21 +321,21 @@ int main (int argc, char **argv) {
switch (c) {
case 'n':
- broadcastMode = 0;
+ broadcast_mode = 0;
break;
case 'u':
/* Save username */
strncpy(username, optarg, sizeof(username) - 1);
username[sizeof(username) - 1] = '\0';
- haveUsername = 1;
+ have_username = 1;
break;
case 'p':
/* Save password */
strncpy(password, optarg, sizeof(password) - 1);
password[sizeof(password) - 1] = '\0';
- havePassword = 1;
+ have_password = 1;
break;
case 't':
@@ -344,15 +344,15 @@ int main (int argc, char **argv) {
case 'h':
case '?':
- printHelp = 1;
+ print_help = 1;
break;
}
}
- if (argc - optind < 1 || printHelp) {
+ if (argc - optind < 1 || print_help) {
fprintf(stderr, "Usage: %s <MAC|identity> [-h] [-n] [-t <timeout>] [-u <username>] [-p <password>]\n", argv[0]);
- if (printHelp) {
+ if (print_help) {
fprintf(stderr, "\nParameters:\n");
fprintf(stderr, " ifname Network interface that the RouterOS resides on. (example: eth0)\n");
fprintf(stderr, " MAC MAC-Address of the RouterOS device. Use mndp to discover them.\n");
@@ -370,12 +370,12 @@ int main (int argc, char **argv) {
/* Seed randomizer */
srand(time(NULL));
- if (!broadcastMode && geteuid() != 0) {
+ if (!broadcast_mode && geteuid() != 0) {
fprintf(stderr, "You need to have root privileges to use the -n parameter.\n");
return 1;
}
- if (!broadcastMode) {
+ if (!broadcast_mode) {
/* Transmit raw packets with this socket */
sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (sockfd < 0) {
@@ -391,7 +391,7 @@ int main (int argc, char **argv) {
return 1;
}
- if (broadcastMode) {
+ if (broadcast_mode) {
if (setsockopt(insockfd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof (optval))==-1) {
perror("SO_BROADCAST");
return 1;
@@ -415,7 +415,7 @@ int main (int argc, char **argv) {
fprintf(stderr, "Searching for '%s'...", argv[optind]);
/* Search for Router by identity name, using MNDP */
- if (!queryMNDP(argv[optind], dstmac)) {
+ if (!query_mndp(argv[optind], dstmac)) {
fprintf(stderr, "not found\n");
return 1;
}
@@ -429,12 +429,12 @@ int main (int argc, char **argv) {
}
}
- if (!haveUsername) {
+ if (!have_username) {
printf("Login: ");
scanf("%254s", username);
}
- if (!havePassword) {
+ if (!have_password) {
char *tmp;
tmp = getpass("Passsword: ");
strncpy(password, tmp, sizeof(password) - 1);
@@ -473,24 +473,24 @@ int main (int argc, char **argv) {
return 1;
}
- if (!findInterface() || (result = recvfrom(insockfd, buff, 1400, 0, 0, 0)) < 1) {
+ if (!find_interface() || (result = recvfrom(insockfd, buff, 1400, 0, 0, 0)) < 1) {
fprintf(stderr, "Connection failed.\n");
return 1;
}
printf("done\n");
/* Handle first received packet */
- handlePacket(buff, result);
+ handle_packet(buff, result);
/*
* TODO: Should resubmit whenever a PTYPE_DATA packet is sent, and an ACK packet with correct datacounter is received
* or time out the connection, in all other cases.
*/
- initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, 0);
- outcounter += addControlPacket(&data, MT_CPTYPE_BEGINAUTH, NULL, 0);
+ init_packet(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, 0);
+ outcounter += add_control_packet(&data, MT_CPTYPE_BEGINAUTH, NULL, 0);
- /* TODO: handle result of sendUDP */
- result = sendUDP(&data);
+ /* TODO: handle result of send_udp */
+ result = send_udp(&data);
while (running) {
int reads;
@@ -509,7 +509,7 @@ int main (int argc, char **argv) {
if (FD_ISSET(insockfd, &read_fds)) {
memset(buff, 0, 1500);
result = recvfrom(insockfd, buff, 1500, 0, 0, 0);
- handlePacket(buff, result);
+ handle_packet(buff, result);
}
/* Handle data from keyboard/local terminal */
if (FD_ISSET(0, &read_fds)) {
@@ -518,10 +518,10 @@ int main (int argc, char **argv) {
datalen = read(STDIN_FILENO, &keydata, 512);
- initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
- addControlPacket(&data, MT_CPTYPE_PLAINDATA, &keydata, datalen);
+ init_packet(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
+ add_control_packet(&data, MT_CPTYPE_PLAINDATA, &keydata, datalen);
outcounter += datalen;
- result = sendUDP(&data);
+ result = send_udp(&data);
}
/* Handle select() timeout */
} else {
@@ -530,15 +530,15 @@ int main (int argc, char **argv) {
if ((keepalive_counter++ % 10) == 0) {
struct mt_packet odata;
int plen=0,result=0;
- plen = initPacket(&odata, MT_PTYPE_ACK, srcmac, dstmac, sessionkey, 0);
- result = sendUDP(&odata);
+ plen = init_packet(&odata, MT_PTYPE_ACK, srcmac, dstmac, sessionkey, 0);
+ result = send_udp(&odata);
}
}
}
if (terminalMode) {
/* Reset terminal back to old settings */
- resetTerm();
+ reset_term();
}
close(sockfd);
diff --git a/mactelnetd.c b/mactelnetd.c
index 79fa680..0245fe2 100644
--- a/mactelnetd.c
+++ b/mactelnetd.c
@@ -100,7 +100,7 @@ static void uwtmp_logout(struct mt_connection *);
struct mt_connection *connections_head = NULL;
-static void list_addConnection(struct mt_connection *conn) {
+static void list_add_connection(struct mt_connection *conn) {
struct mt_connection *p;
struct mt_connection *last;
if (connections_head == NULL) {
@@ -113,7 +113,7 @@ static void list_addConnection(struct mt_connection *conn) {
conn->next = NULL;
}
-static void list_removeConnection(struct mt_connection *conn) {
+static void list_remove_connection(struct mt_connection *conn) {
struct mt_connection *p;
struct mt_connection *last;
if (connections_head == NULL)
@@ -144,7 +144,7 @@ static void list_removeConnection(struct mt_connection *conn) {
}
}
-static struct mt_connection *list_findConnection(unsigned short seskey, unsigned char *srcmac) {
+static struct mt_connection *list_find_connection(unsigned short seskey, unsigned char *srcmac) {
struct mt_connection *p;
if (connections_head == NULL)
@@ -159,11 +159,11 @@ static struct mt_connection *list_findConnection(unsigned short seskey, unsigned
return NULL;
}
-static int sendUDP(const struct mt_connection *conn, const struct mt_packet *data) {
- return sendCustomUDP(sockfd, 2, conn->dstmac, conn->srcmac, &sourceip, sourceport, &destip, conn->srcport, data->data, data->size);
+static int send_udp(const struct mt_connection *conn, const struct mt_packet *data) {
+ return send_custom_udp(sockfd, 2, conn->dstmac, conn->srcmac, &sourceip, sourceport, &destip, conn->srcport, data->data, data->size);
}
-static void displayMotd() {
+static void display_motd() {
FILE *fp;
int c;
@@ -175,7 +175,7 @@ static void displayMotd() {
}
}
-static void displayNologin() {
+static void display_nologin() {
FILE *fp;
int c;
@@ -239,20 +239,20 @@ static void uwtmp_logout(struct mt_connection *conn) {
}
}
-static void abortConnection(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr, char *message) {
+static void abort_connection(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr, char *message) {
struct mt_packet pdata;
- initPacket(&pdata, MT_PTYPE_DATA, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
- addControlPacket(&pdata, MT_CPTYPE_PLAINDATA, message, strlen(message));
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_DATA, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
+ add_control_packet(&pdata, MT_CPTYPE_PLAINDATA, message, strlen(message));
+ send_udp(curconn, &pdata);
/* Make connection time out; lets the previous message get acked before disconnecting */
curconn->state = STATE_CLOSED;
- initPacket(&pdata, MT_PTYPE_END, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_END, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
+ send_udp(curconn, &pdata);
}
-static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr) {
+static void user_login(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr) {
struct mt_packet pdata;
unsigned char md5sum[17];
char md5data[100];
@@ -260,9 +260,9 @@ static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
char *slavename;
/* Reparse user file before each login */
- readUserfile();
+ read_userfile();
- if ((user = findUser(curconn->username)) != NULL) {
+ if ((user = find_user(curconn->username)) != NULL) {
md5_state_t state;
/* Concat string of 0 + password + encryptionkey */
md5data[0] = 0;
@@ -275,9 +275,9 @@ static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
md5_finish(&state, (md5_byte_t *)md5sum + 1);
md5sum[0] = 0;
- initPacket(&pdata, MT_PTYPE_DATA, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
- curconn->outcounter += addControlPacket(&pdata, MT_CPTYPE_END_AUTH, NULL, 0);
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_DATA, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
+ curconn->outcounter += add_control_packet(&pdata, MT_CPTYPE_END_AUTH, NULL, 0);
+ send_udp(curconn, &pdata);
if (curconn->state == STATE_ACTIVE)
return;
@@ -286,7 +286,7 @@ static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
if (user == NULL || memcmp(md5sum, trypassword, 17) != 0) {
syslog(LOG_NOTICE, "(%d) Invalid login by %s.", curconn->seskey, curconn->username);
- abortConnection(curconn, pkthdr, "Login failed, incorrect username or password\r\n");
+ abort_connection(curconn, pkthdr, "Login failed, incorrect username or password\r\n");
/* TODO: should wait some time (not with sleep) before returning, to minimalize brute force attacks */
return;
@@ -302,7 +302,7 @@ static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
curconn->ptsfd = posix_openpt(O_RDWR);
if (curconn->ptsfd == -1 || grantpt(curconn->ptsfd) == -1 || unlockpt(curconn->ptsfd) == -1) {
syslog(LOG_ERR, "posix_openpt: %s", strerror(errno));
- abortConnection(curconn, pkthdr, "Terminal error\r\n");
+ abort_connection(curconn, pkthdr, "Terminal error\r\n");
return;
}
@@ -315,8 +315,8 @@ static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
curconn->slavefd = open(slavename, O_RDWR);
if (curconn->slavefd == -1) {
syslog(LOG_ERR, "Error opening %s: %s", slavename, strerror(errno));
- abortConnection(curconn, pkthdr, "Error opening terminal\r\n");
- list_removeConnection(curconn);
+ abort_connection(curconn, pkthdr, "Error opening terminal\r\n");
+ list_remove_connection(curconn);
return;
}
@@ -324,7 +324,7 @@ static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
struct passwd *user = (struct passwd *)getpwnam(curconn->username);
if (user == NULL) {
syslog(LOG_WARNING, "(%d) Login ok, but local user not accessible (%s).", curconn->seskey, curconn->username);
- abortConnection(curconn, pkthdr, "Local user not accessible\r\n");
+ abort_connection(curconn, pkthdr, "Local user not accessible\r\n");
return;
}
@@ -361,22 +361,22 @@ static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
/* Set user id/group id */
if ((setgid(user->pw_gid) != 0) || (setuid(user->pw_uid) != 0)) {
syslog(LOG_ERR, "(%d) Could not log in %s (%d:%d): setuid/setgid: %s", curconn->seskey, curconn->username, user->pw_uid, user->pw_gid, strerror(errno));
- abortConnection(curconn, pkthdr, "Internal error\r\n");
+ abort_connection(curconn, pkthdr, "Internal error\r\n");
exit(0);
}
/* Abort login if /etc/nologin exists */
if (stat(_PATH_NOLOGIN, &sb) == 0 && getuid() != 0) {
syslog(LOG_NOTICE, "(%d) User %s disconnected with " _PATH_NOLOGIN " message.", curconn->seskey, curconn->username);
- displayNologin();
+ display_nologin();
curconn->state = STATE_CLOSED;
- initPacket(&pdata, MT_PTYPE_END, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_END, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
+ send_udp(curconn, &pdata);
exit(0);
}
/* Display MOTD */
- displayMotd();
+ display_motd();
/* Spawn shell */
chdir(user->pw_dir);
@@ -385,12 +385,12 @@ static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
}
close(curconn->slavefd);
curconn->pid = pid;
- setTerminalSize(curconn->ptsfd, curconn->terminal_width, curconn->terminal_height);
+ set_terminal_size(curconn->ptsfd, curconn->terminal_width, curconn->terminal_height);
}
}
-static void handleDataPacket(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr, int data_len) {
+static void handle_data_packet(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr, int data_len) {
struct mt_mactelnet_control_hdr cpkt;
struct mt_packet pdata;
unsigned char *data = pkthdr->data;
@@ -401,7 +401,7 @@ static void handleDataPacket(struct mt_connection *curconn, struct mt_mactelnet_
int success;
/* Parse first control packet */
- success = parseControlPacket(data, data_len - MT_HEADER_LEN, &cpkt);
+ success = parse_control_packet(data, data_len - MT_HEADER_LEN, &cpkt);
while (success) {
if (cpkt.cptype == MT_CPTYPE_BEGINAUTH) {
@@ -411,11 +411,11 @@ static void handleDataPacket(struct mt_connection *curconn, struct mt_mactelnet_
curconn->enckey[i] = rand() % 256;
}
- initPacket(&pdata, MT_PTYPE_DATA, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
- plen = addControlPacket(&pdata, MT_CPTYPE_ENCRYPTIONKEY, (curconn->enckey), 16);
+ init_packet(&pdata, MT_PTYPE_DATA, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
+ plen = add_control_packet(&pdata, MT_CPTYPE_ENCRYPTIONKEY, (curconn->enckey), 16);
curconn->outcounter += plen;
- sendUDP(curconn, &pdata);
+ send_udp(curconn, &pdata);
memset(trypassword, 0, sizeof(trypassword));
@@ -457,15 +457,15 @@ static void handleDataPacket(struct mt_connection *curconn, struct mt_mactelnet_
}
/* Parse next control packet */
- success = parseControlPacket(NULL, 0, &cpkt);
+ success = parse_control_packet(NULL, 0, &cpkt);
}
if (gotUserPacket && gotPassPacket) {
- userLogin(curconn, pkthdr);
+ user_login(curconn, pkthdr);
}
if (curconn->state == STATE_ACTIVE && (gotWidthPacket || gotHeightPacket)) {
- setTerminalSize(curconn->ptsfd, curconn->terminal_width, curconn->terminal_height);
+ set_terminal_size(curconn->ptsfd, curconn->terminal_width, curconn->terminal_height);
}
}
@@ -475,12 +475,12 @@ static void terminate() {
exit(0);
}
-static void handlePacket(unsigned char *data, int data_len, const struct sockaddr_in *address) {
+static void handle_packet(unsigned char *data, int data_len, const struct sockaddr_in *address) {
struct mt_mactelnet_hdr pkthdr;
struct mt_connection *curconn = NULL;
struct mt_packet pdata;
- parsePacket(data, &pkthdr);
+ parse_packet(data, &pkthdr);
switch (pkthdr.ptype) {
@@ -495,27 +495,27 @@ static void handlePacket(unsigned char *data, int data_len, const struct sockadd
curconn->srcport = htons(address->sin_port);
memcpy(curconn->dstmac, pkthdr.dstaddr, 6);
- list_addConnection(curconn);
+ list_add_connection(curconn);
- initPacket(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
+ send_udp(curconn, &pdata);
break;
case MT_PTYPE_END:
- curconn = list_findConnection(pkthdr.seskey, (unsigned char *)&(pkthdr.srcaddr));
+ curconn = list_find_connection(pkthdr.seskey, (unsigned char *)&(pkthdr.srcaddr));
if (curconn == NULL) {
break;
}
if (curconn->state != STATE_CLOSED) {
- initPacket(&pdata, MT_PTYPE_END, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_END, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
+ send_udp(curconn, &pdata);
}
syslog(LOG_DEBUG, "(%d) Connection closed.", curconn->seskey);
- list_removeConnection(curconn);
+ list_remove_connection(curconn);
return;
case MT_PTYPE_ACK:
- curconn = list_findConnection(pkthdr.seskey, (unsigned char *)&(pkthdr.srcaddr));
+ curconn = list_find_connection(pkthdr.seskey, (unsigned char *)&(pkthdr.srcaddr));
if (curconn == NULL) {
break;
}
@@ -528,22 +528,22 @@ static void handlePacket(unsigned char *data, int data_len, const struct sockadd
if (pkthdr.counter == curconn->outcounter) {
// Answer to anti-timeout packet
/* TODO: only answer if time() - lastpacket is somewhat high.. */
- initPacket(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
+ send_udp(curconn, &pdata);
}
return;
break;
case MT_PTYPE_DATA:
- curconn = list_findConnection(pkthdr.seskey, (unsigned char *)&(pkthdr.srcaddr));
+ curconn = list_find_connection(pkthdr.seskey, (unsigned char *)&(pkthdr.srcaddr));
if (curconn == NULL) {
break;
}
curconn->lastdata = time(NULL);
/* ack the data packet */
- initPacket(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter + (data_len - MT_HEADER_LEN));
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter + (data_len - MT_HEADER_LEN));
+ send_udp(curconn, &pdata);
/* Accept first packet, and all packets greater than incounter, and if counter has
wrapped around. */
@@ -554,13 +554,13 @@ static void handlePacket(unsigned char *data, int data_len, const struct sockadd
return;
}
- handleDataPacket(curconn, &pkthdr, data_len);
+ handle_data_packet(curconn, &pkthdr, data_len);
break;
default:
if (curconn) {
syslog(LOG_WARNING, "(%d) Unhandeled packet type: %d", curconn->seskey, pkthdr.ptype);
- initPacket(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
- sendUDP(curconn, &pdata);
+ init_packet(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
+ send_udp(curconn, &pdata);
}
}
if (0 && curconn != NULL) {
@@ -607,7 +607,7 @@ int main (int argc, char **argv) {
fd_set read_fds;
/* Try to read user file */
- readUserfile();
+ read_userfile();
/* Seed randomizer */
srand(time(NULL));
@@ -693,7 +693,7 @@ int main (int argc, char **argv) {
struct sockaddr_in saddress;
unsigned int slen = sizeof(saddress);
result = recvfrom(insockfd, buff, 1500, 0, (struct sockaddr *)&saddress, &slen);
- handlePacket(buff, result, &saddress);
+ handle_packet(buff, result, &saddress);
}
/* Handle data from terminal sessions */
for (p = connections_head; p != NULL; p = p->next) {
@@ -706,23 +706,23 @@ int main (int argc, char **argv) {
datalen = read(p->ptsfd, &keydata, 1024);
if (datalen != -1) {
/* Send it */
- initPacket(&pdata, MT_PTYPE_DATA, p->dstmac, p->srcmac, p->seskey, p->outcounter);
- plen = addControlPacket(&pdata, MT_CPTYPE_PLAINDATA, &keydata, datalen);
+ init_packet(&pdata, MT_PTYPE_DATA, p->dstmac, p->srcmac, p->seskey, p->outcounter);
+ plen = add_control_packet(&pdata, MT_CPTYPE_PLAINDATA, &keydata, datalen);
p->outcounter += plen;
p->waitForAck = 1;
- result = sendUDP(p, &pdata);
+ result = send_udp(p, &pdata);
} else {
/* Shell exited */
struct mt_connection tmp;
- initPacket(&pdata, MT_PTYPE_END, p->dstmac, p->srcmac, p->seskey, p->outcounter);
- sendUDP(p, &pdata);
+ init_packet(&pdata, MT_PTYPE_END, p->dstmac, p->srcmac, p->seskey, p->outcounter);
+ send_udp(p, &pdata);
if (p->username != NULL) {
syslog(LOG_INFO, "(%d) Connection to user %s closed.", p->seskey, p->username);
} else {
syslog(LOG_INFO, "(%d) Connection closed.", p->seskey);
}
tmp.next = p->next;
- list_removeConnection(p);
+ list_remove_connection(p);
p = &tmp;
}
}
@@ -737,14 +737,14 @@ int main (int argc, char **argv) {
for (p = connections_head; p != NULL; p = p->next) {
if (time(NULL) - p->lastdata >= MT_CONNECTION_TIMEOUT) {
syslog(LOG_INFO, "(%d) Session timed out", p->seskey);
- initPacket(&pdata, MT_PTYPE_DATA, p->dstmac, p->srcmac, p->seskey, p->outcounter);
- addControlPacket(&pdata, MT_CPTYPE_PLAINDATA, "Timeout\r\n", 9);
- sendUDP(p, &pdata);
- initPacket(&pdata, MT_PTYPE_END, p->dstmac, p->srcmac, p->seskey, p->outcounter);
- sendUDP(p, &pdata);
+ init_packet(&pdata, MT_PTYPE_DATA, p->dstmac, p->srcmac, p->seskey, p->outcounter);
+ add_control_packet(&pdata, MT_CPTYPE_PLAINDATA, "Timeout\r\n", 9);
+ send_udp(p, &pdata);
+ init_packet(&pdata, MT_PTYPE_END, p->dstmac, p->srcmac, p->seskey, p->outcounter);
+ send_udp(p, &pdata);
tmp.next = p->next;
- list_removeConnection(p);
+ list_remove_connection(p);
p = &tmp;
}
}
diff --git a/mndp.c b/mndp.c
index 1feaba9..716103c 100644
--- a/mndp.c
+++ b/mndp.c
@@ -77,7 +77,7 @@ int main(int argc, char **argv) {
}
/* Parse MNDP packet */
- packet = parseMNDP(buff, result);
+ packet = parse_mndp(buff, result);
if (packet != NULL) {
/* Print it */
diff --git a/protocol.c b/protocol.c
index 9bcd9a8..104c8e7 100644
--- a/protocol.c
+++ b/protocol.c
@@ -32,7 +32,7 @@ unsigned char mt_mactelnet_cpmagic[4] = { 0x56, 0x34, 0x12, 0xff };
unsigned char mt_mactelnet_clienttype[2] = { 0x00, 0x15 };
-int initPacket(struct mt_packet *packet, enum mt_ptype ptype, unsigned char *srcmac, unsigned char *dstmac, unsigned short sessionkey, unsigned int counter) {
+int init_packet(struct mt_packet *packet, enum mt_ptype ptype, unsigned char *srcmac, unsigned char *dstmac, unsigned short sessionkey, unsigned int counter) {
unsigned char *data = packet->data;
/* Packet version */
@@ -74,7 +74,7 @@ int initPacket(struct mt_packet *packet, enum mt_ptype ptype, unsigned char *src
return 22;
}
-int addControlPacket(struct mt_packet *packet, enum mt_cptype cptype, void *cpdata, int data_len) {
+int add_control_packet(struct mt_packet *packet, enum mt_cptype cptype, void *cpdata, int data_len) {
unsigned char *data = packet->data + packet->size;
/* Something is really wrong. Packets should never become over 1500 bytes */
@@ -114,7 +114,7 @@ int addControlPacket(struct mt_packet *packet, enum mt_cptype cptype, void *cpda
return MT_CPHEADER_LEN + data_len;
}
-void parsePacket(unsigned char *data, struct mt_mactelnet_hdr *pkthdr) {
+void parse_packet(unsigned char *data, struct mt_mactelnet_hdr *pkthdr) {
/* Packet version */
pkthdr->ver = data[0];
@@ -149,7 +149,7 @@ void parsePacket(unsigned char *data, struct mt_mactelnet_hdr *pkthdr) {
}
-int parseControlPacket(unsigned char *packetdata, int data_len, struct mt_mactelnet_control_hdr *cpkthdr) {
+int parse_control_packet(unsigned char *packetdata, int data_len, struct mt_mactelnet_control_hdr *cpkthdr) {
static unsigned char *int_data;
static unsigned int int_data_len;
static unsigned int int_pos;
@@ -206,7 +206,7 @@ int parseControlPacket(unsigned char *packetdata, int data_len, struct mt_mactel
}
}
-struct mt_mndp_packet *parseMNDP(const unsigned char *data, const int packetLen) {
+struct mt_mndp_packet *parse_mndp(const unsigned char *data, const int packetLen) {
static struct mt_mndp_packet packet;
unsigned short nameLen = 0;
@@ -234,7 +234,7 @@ struct mt_mndp_packet *parseMNDP(const unsigned char *data, const int packetLen)
return &packet;
}
-int queryMNDP(const char *identity, unsigned char *mac) {
+int query_mndp(const char *identity, unsigned char *mac) {
int fastlookup = 0;
int sock, length;
int optval = 1;
@@ -307,7 +307,7 @@ int queryMNDP(const char *identity, unsigned char *mac) {
}
/* Parse MNDP packet */
- packet = parseMNDP(buff, length);
+ packet = parse_mndp(buff, length);
if (packet != NULL) {
if (strcasecmp(identity, packet->identity) == 0) {
diff --git a/protocol.h b/protocol.h
index 72445da..385f8cd 100644
--- a/protocol.h
+++ b/protocol.h
@@ -83,14 +83,14 @@ struct mt_packet {
};
/* MacTelnet/Winbox packets */
-extern int initPacket(struct mt_packet *packet, enum mt_ptype ptype, unsigned char *srcmac, unsigned char *dstmac, unsigned short sessionkey, unsigned int counter);
-extern int addControlPacket(struct mt_packet *packet, enum mt_cptype cptype, void *cpdata, int data_len);
-extern void parsePacket(unsigned char *data, struct mt_mactelnet_hdr *pkthdr);
-extern int parseControlPacket(unsigned char *data, int data_len, struct mt_mactelnet_control_hdr *cpkthdr);
+extern int init_packet(struct mt_packet *packet, enum mt_ptype ptype, unsigned char *srcmac, unsigned char *dstmac, unsigned short sessionkey, unsigned int counter);
+extern int add_control_packet(struct mt_packet *packet, enum mt_cptype cptype, void *cpdata, int data_len);
+extern void parse_packet(unsigned char *data, struct mt_mactelnet_hdr *pkthdr);
+extern int parse_control_packet(unsigned char *data, int data_len, struct mt_mactelnet_control_hdr *cpkthdr);
/* MNDP packets */
-struct mt_mndp_packet *parseMNDP(const unsigned char *data, const int packetLen);
-int queryMNDP(const char *identity, unsigned char *mac);
+struct mt_mndp_packet *parse_mndp(const unsigned char *data, const int packetLen);
+int query_mndp(const char *identity, unsigned char *mac);
/* Control packet magic header */
extern unsigned char mt_mactelnet_cpmagic[4];
diff --git a/udp.c b/udp.c
index 4c1a383..68cb6c5 100644
--- a/udp.c
+++ b/udp.c
@@ -34,7 +34,7 @@ unsigned short in_cksum(unsigned short *addr, int len)
return (answer);
}
-int sendCustomUDP(const int socket, const int ifindex, const unsigned char *sourcemac, const unsigned char *destmac, const struct in_addr *sourceip, const int sourceport, const struct in_addr *destip, const int destport, const unsigned char *data, const int datalen) {
+int send_custom_udp(const int socket, const int ifindex, const unsigned char *sourcemac, const unsigned char *destmac, const struct in_addr *sourceip, const int sourceport, const struct in_addr *destip, const int destport, const unsigned char *data, const int datalen) {
struct sockaddr_ll socket_address;
/*
diff --git a/udp.h b/udp.h
index a8bb56c..90968cd 100644
--- a/udp.h
+++ b/udp.h
@@ -1,4 +1,4 @@
#ifndef _UDP_H
#define _UDP_H 1
-extern int sendCustomUDP(const int socket, const int ifindex, const unsigned char *sourcemac, const unsigned char *destmac, const struct in_addr *sourceip, const int sourceport, const struct in_addr *destip, const int destport, const unsigned char *data, const int datalen);
+extern int send_custom_udp(const int socket, const int ifindex, const unsigned char *sourcemac, const unsigned char *destmac, const struct in_addr *sourceip, const int sourceport, const struct in_addr *destip, const int destport, const unsigned char *data, const int datalen);
#endif
diff --git a/users.c b/users.c
index 1c0bb7d..006d0c7 100644
--- a/users.c
+++ b/users.c
@@ -25,7 +25,7 @@
struct mt_credentials mt_users[MT_CRED_MAXNUM];
-void readUserfile() {
+void read_userfile() {
FILE *file = fopen(USERSFILE, "r");
char line [BUFSIZ];
int i = 0;
@@ -60,7 +60,7 @@ void readUserfile() {
fclose(file);
}
-struct mt_credentials* findUser(char *username) {
+struct mt_credentials* find_user(char *username) {
int i = 0;
while (i < MT_CRED_MAXNUM && mt_users[i].username[0] != 0) {
diff --git a/users.h b/users.h
index a478434..1ab5e17 100644
--- a/users.h
+++ b/users.h
@@ -11,7 +11,7 @@ struct mt_credentials {
extern struct mt_credentials mt_users[MT_CRED_MAXNUM];
-extern void readUserfile();
-struct mt_credentials* findUser(char *username);
+extern void read_userfile();
+struct mt_credentials* find_user(char *username);
#endif