diff --git a/src/config.h b/src/config.h index 50781e3f..8eecddcf 100644 --- a/src/config.h +++ b/src/config.h @@ -92,7 +92,7 @@ struct vpn_config { int password_set; char otp[OTP_SIZE + 1]; char *cookie; - int saml_port; + uint16_t saml_port; char saml_session_id[MAX_SAML_SESSION_ID_LENGTH + 1]; char *otp_prompt; unsigned int otp_delay; diff --git a/src/http_server.c b/src/http_server.c index ad186caa..f151c4e7 100644 --- a/src/http_server.c +++ b/src/http_server.c @@ -141,7 +141,7 @@ static int process_request(int new_socket, char *id) int flag = 1; if (setsockopt(new_socket, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag))) { - log_error("Failed to set socket options\n"); + log_error("Failed to set socket options: %s\n", strerror(errno)); return -1; } @@ -155,7 +155,7 @@ static int process_request(int new_socket, char *id) // If the received request from the server is larger than the buffer, // the result will not be null-terminated causing strlen to behave wrong. if (read_result < 0) { - log_error("Bad request\n"); + log_error("Bad request: %s\n", strerror(errno)); send_status_response(new_socket, "Invalid redirect response from Fortinet server. VPN could not be established."); return -1; } @@ -230,36 +230,35 @@ int wait_for_http_request(struct vpn_config *config) struct sockaddr_in address; int opt = 1; int addrlen = sizeof(address); - long saml_port = config->saml_port; // Creating socket file descriptor server_fd = socket(AF_INET, SOCK_STREAM, 0); if (server_fd < 0) { - log_error("Failed to create socket\n"); + log_error("Failed to create socket: %s\n", strerror(errno)); return -1; } // Forcefully attaching socket to the port if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) { close(server_fd); - log_error("Failed to set socket options\n"); + log_error("Failed to set socket options: %s\n", strerror(errno)); return -1; } address.sin_family = AF_INET; address.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - address.sin_port = htons(saml_port); + address.sin_port = htons(config->saml_port); // Forcefully attaching socket to the port if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0) { close(server_fd); - log_error("Failed to bind socket to port %d\n", saml_port); + log_error("Failed to bind socket to port %u\n", config->saml_port); return -1; } if (listen(server_fd, 3) < 0) { close(server_fd); - log_error("Failed to listen on socket\n"); + log_error("Failed to listen on socket: %s\n", strerror(errno)); return -1; } @@ -267,7 +266,7 @@ int wait_for_http_request(struct vpn_config *config) fd_set readfds; struct timeval tv; - log_info("Listening for SAML login on port %d\n", saml_port); + log_info("Listening for SAML login on port %u\n", config->saml_port); print_url(config); while (max_tries > 0) { @@ -289,7 +288,8 @@ int wait_for_http_request(struct vpn_config *config) (struct sockaddr *)&address, (socklen_t *)&addrlen); if (new_socket < 0) { - log_error("Failed to accept connection\n"); + log_error("Failed to accept connection: %s\n", + strerror(errno)); continue; } } else {