issue #3 (rejecting http)
This commit is contained in:
24
fiche.c
24
fiche.c
@@ -66,12 +66,12 @@ void *thread_connection(void *args)
|
||||
printf("Rejected connection from unknown user.\n");
|
||||
display_line();
|
||||
save_log(NULL, data.ip_address, data.hostname);
|
||||
write(connection_socket, "You are not whitelisted!\n", 17);
|
||||
write(connection_socket, "You are not whitelisted!\n", 26);
|
||||
close(connection_socket);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
if ((BANLIST != NULL))
|
||||
if (BANLIST != NULL)
|
||||
if (check_banlist(data.ip_address) != NULL)
|
||||
{
|
||||
printf("Rejected connection from banned user.\n");
|
||||
@@ -82,6 +82,16 @@ void *thread_connection(void *args)
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
if (check_protocol(buffer) == 1)
|
||||
{
|
||||
printf("Rejected due to wrong protocol.\n");
|
||||
display_line();
|
||||
save_log(NULL, data.ip_address, data.hostname);
|
||||
write(connection_socket, "Use netcat!", 11);
|
||||
close(connection_socket);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
if (status != -1)
|
||||
{
|
||||
char slug[SLUG_SIZE+8];
|
||||
@@ -327,6 +337,16 @@ void set_uid_gid(char *username)
|
||||
GID = userdata->pw_gid;
|
||||
}
|
||||
|
||||
int check_protocol(char *buffer)
|
||||
{
|
||||
if (strlen(buffer) < 1)
|
||||
return 1;
|
||||
if ((strncmp(buffer, "GET", 3) == 0)||(strncmp(buffer, "POST", 4) == 0))
|
||||
if (strstr(buffer, "HTTP/1."))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_basedir()
|
||||
{
|
||||
BASEDIR = getenv("HOME");
|
||||
|
||||
2
fiche.h
2
fiche.h
@@ -60,11 +60,11 @@ const char *symbols = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
int create_socket();
|
||||
int create_directory(char *slug);
|
||||
int check_protocol(char *buffer);
|
||||
|
||||
void bind_to_port(int listen_socket, struct sockaddr_in serveraddr);
|
||||
void display_line(){printf("====================================\n");}
|
||||
void error(char *error_code){perror(error_code); exit(1);}
|
||||
void nerror(char *error_code){perror(error_code);}
|
||||
void display_date();
|
||||
void perform_connection(int listen_socket);
|
||||
void generate_url(char *buffer, char *slug, size_t slug_length);
|
||||
|
||||
Reference in New Issue
Block a user