From 08365d9ff3bbf5468fa94974de3801d2af90cbbc Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Sat, 6 Nov 2021 00:33:34 -0300 Subject: [PATCH] Add server with challenges Co-authored-by: Ezequiel Bellver Co-authored-by: Juan Barmasch --- .gitignore | 8 ++++++ .vscode/settings.json | 4 ++- Makefile | 26 +++++++++++------- challenges.c | 47 +++++++++++++++++++++++++++++++++ client.c | 12 +++------ client.o | Bin 21304 -> 0 bytes errors.o | Bin 5824 -> 0 bytes include/challenges.h | 22 ++++++++++++++++ include/client.h | 1 - include/server.h | 23 ++++++++++++++++ server.c | 60 ++++++++++++++++++++++++++++++++++++++++++ server.o | Bin 1256 -> 0 bytes 12 files changed, 183 insertions(+), 20 deletions(-) create mode 100644 .gitignore create mode 100644 challenges.c delete mode 100755 client.o delete mode 100644 errors.o create mode 100644 include/challenges.h create mode 100644 include/server.h delete mode 100644 server.o diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d529103 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.bash_history +.bashrc +.config/ +.gdb_history +.gdbinit +.idea/ +.inputrc +.viminfo diff --git a/.vscode/settings.json b/.vscode/settings.json index aa45b88..1adbd76 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,8 @@ "files.associations": { "error.h": "c", "client.h": "c", - "errors.h": "c" + "errors.h": "c", + "server.h": "c", + "challenges.h": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index c26f792..e052720 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,25 @@ CC = gcc CCFLAGS = -Wall -std=c99 -pedantic -g -OBJECTS = server.o errors.o client.o +# OBJECTS = errors.o server.o client.o -all: $(OBJECTS) +CLIENT=client.o +SERVER=server.o +ERROR=errors.o +CHALLENGE=challenges.o -server.o: server.c include/errors.h - $(CC) $(CCFLAGS) -c server.c -errors.o: errors.c include/errors.h - $(CC) $(CCFLAGS) -c errors.c -client.o: client.c errors.o - $(CC) $(CCFLAGS) client.c -o client.o errors.o +all: $(ERROR) $(CHALLENGE) $(CLIENT) $(SERVER) + +$(SERVER): + $(CC) $(CCFLAGS) server.c -o server challenges.o errors.o +$(CLIENT): + $(CC) $(CCFLAGS) client.c -o client errors.o + +%.o: %.c + $(CC) $(CCFLAGS) -I./include -c $< clean: - rm -rf $(OBJECTS) + rm -rf $(ERROR) $(CHALLENGE) $(CLIENT) $(SERVER) server client test: pvs-studio-analyzer trace -- make @@ -21,4 +27,4 @@ test: plog-converter -a '64:1,2,3;GA:1,2,3;OP:1,2,3' -t tasklist -o report.tasks PVS-Studio.log cppcheck --quiet --enable=all --force --inconclusive . -.PHONY: all clean test \ No newline at end of file +.PHONY: all clean test diff --git a/challenges.c b/challenges.c new file mode 100644 index 0000000..93d0b52 --- /dev/null +++ b/challenges.c @@ -0,0 +1,47 @@ +#include "include/challenges.h" + +// char introChallenge(int fd, char * output, char * message, char * question, char * flag) { +// printf("%s\n", message); + +// int readChars; +// while ((readChars = read(fd, output, MAX_LEN - 1)) != 0) { +// if (readChars < 0) +// printSystemError("Challenges: read()"); +// output[readChars] = '\0'; +// } + +// printf("%s\n", question); + +// return strcmp(output, flag) == 0; +// } + +// char genChallenge(int fd, char * output, char * message, char * question, char * flag) { +// printf("%s\n", message); + +// int readChars; +// while ((readChars = read(fd, output, MAX_LEN - 1)) != 0) { +// if (readChars < 0) +// printSystemError("Challenges: read()"); +// output[readChars] = '\0'; +// } + +// printf("%s\n", question); + +// return !strcmp(output, flag); +// } + +char genChallenge(int fd, char * output, challenge_t challenge) { + printf("%s\n", challenge.message); + + int readChars; + // while ((readChars = read(fd, output, MAX_LEN - 1)) != 0) { + readChars = read(fd, output, MAX_LEN - 1); + if (readChars < 0) + printSystemError("Challenges: read()"); + output[readChars] = '\0'; + // } + + printf("%s\n", challenge.question); + + return strcmp(output, challenge.flag); +} \ No newline at end of file diff --git a/client.c b/client.c index 187fb49..f8319a8 100644 --- a/client.c +++ b/client.c @@ -2,19 +2,16 @@ int main(int argc, char *argv[]) { int fd = 0; - struct sockaddr_in serv_addr; - - if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) printSystemError("User: socket()"); - } + struct sockaddr_in serv_addr; serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(PORT); serv_addr.sin_addr.s_addr = inet_addr(ADDRESS); - if (connect(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { + if (connect(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) printSystemError("User: connect()"); - } char input[MAX_LEN] = {0}; int readChars; @@ -23,9 +20,8 @@ int main(int argc, char *argv[]) { printSystemError("User: read()"); input[readChars] = '\0'; - if (write(fd, input, readChars) < 0) { + if (write(fd, input, readChars) < 0) printSystemError("User: write()"); - } } close(fd); diff --git a/client.o b/client.o deleted file mode 100755 index 85bf82b578d9434b4b04751e11646a7e667790dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 21304 zcmeHPdvH_NnLk(3wPXv+PrwFJWExUPVjBY?Kthmg3*=xP0h5qT$VHZ9TSb<zuM~(!CM>>LG9Vtd zn3W^Gl6{$#K(=vAq-_scI21;X;9s~UY1v=AL^w46_xH~&Cy8rqJ_=TP-8R_OAj^)!*R00+9qu1d0p2RYmwdQe4IxOEhsOcAFNfJZz{uVlW&xN8 zFE4=m3*gk6iSk)o0AEl5|7rpJrULj2z}+~^p$5Q2^`UVx5k9Q|{wi=c4s*Bz0Qt@w zsJkZ0e+}>|R?iN4goPTfEEx}O4X0RmFp^?@sdy~O2EvI%Ji&tTSS%b&F~dlv0>Q0D zuy3o;6Np4vA{+>@o`G~K$Re?D$_Ru)2`(pDG8KX`3r6F~Fbso(0i!1p3q&J#lZYV@ zq|6d2qdyRdv9Bc}sW2my#=#=Cva_SL&6wY`Fw4zvx{etgU8@ab8}5xHQ{hC{>b7V+ z7VZjkM=8(V{&-C0X$aK`6?vmA7#)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_@HR+HNv1iHx386K3|`wi|@~BdTL$C6v9Q^j^V4_La+pL6=f2U{A@WCUVU_k1+7a o8~<4lC%XQY0ykBW8y@lr`#GjWQ+06fHL?9kzp(Ey8JI-&UxdjfYXATM diff --git a/errors.o b/errors.o deleted file mode 100644 index a398c994aaa83376fedab9dd71412b046645c577..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5824 zcmbuCdpwls9>CvmO;ogquxE;t)P!~miE$Y-8;Q_viD`y$*&4T*)+kxBM3LHRyHLtH z+p5myM0Y}xHg()~vzw!AYSrn&l8tR`=Y3{=kH%yA=bY#BnfG~q-{0-Iz0dp1=Nw;e zH3oyig+aMeZzW7Aify3OmN(gyF=a#r^Ku^XGM?%4a<&Zdb{HWIZwF_Hmve`g)9_d! zYRape>(vwKhMZNS6!O+sf8?m}dTW84snI@-sEw6ng`urYK5FiU+I>G;v>y)sc=;@& z8CDaDncI(UusyS@ndx)MWMpbavu8`KC%4qc-|L>?5pVhqgs8N^x)Hka}^0%13%rB`ca7gGE=+5n|@@ns__%&&T7HiP- z_8#LAq3ryP*gt+62+f+mq}uK7GrOmai~sKXpOxKp70K7kT*5;GgZk!~XG-EH9?2*# zQ_sIT&}UUi^>lF@r}X?Xvr;eas%^XxOE0qY?DWb*CNmay&HTe9(DQ2zccJ%R%HQe&)oIRa4)=Io=C=kNTV`+OcZ4$E&v}$Gz&G?fD6v?3L0~&u%X_`u{ZCBUv$~wmsA=df z=nm72PUtzSaouaxjooEg`!dS8)5GjrLRo`50~o#w@0tjL|8XL>-!4?`S^r_tq7S^; zmCyg}%`^S=N^`^PqEzP6)VvsrnEz~s@vAt(QOliI1wt)_luX*#Pkwfw9PI2f$D(`mlj{M@Ne zb<2KeIwQquGPmnrb6#ZChNm5@nABV3+Vzt6aDr^=ri5$7 zFE?}3XKBhtGF@s0*Q`3s(|#!7C23iD^B0vj_{lU}b)1<$hI$-3G04vT!u4s5cBa?5 zLW|YI5tgxqE;UW9+cX^2_V2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3cA!Q zs?jI*#{j)ws{Bo0Lh$_#+mrt2y;ar!n#l?eJ8(q(N50q}_aD8Ns`B$7enpr)ezblD^bh;v^;4A_c}7G2G#IcU_>%rQG$-GE +#include +#include +#include +#include "errors.h" + +#define MAX_LEN 100 + +typedef struct challenge_t { + // char (* challenge) (int fd, char * output, char * message, char * question, char * flag); + char * message; + char * question; + char * flag; +} challenge_t; + +// char genChallenge(int fd, char * output, char * message, char * question, char * flag); +char genChallenge(int fd, char * output, challenge_t challenge); + +#endif \ No newline at end of file diff --git a/include/client.h b/include/client.h index 3b2505f..277e179 100644 --- a/include/client.h +++ b/include/client.h @@ -9,7 +9,6 @@ #include #include "errors.h" -#define MAX_ARGS 3 #define MAX_LEN 100 #define PORT 8080 #define ADDRESS "127.0.0.1" diff --git a/include/server.h b/include/server.h new file mode 100644 index 0000000..000c3e6 --- /dev/null +++ b/include/server.h @@ -0,0 +1,23 @@ +#ifndef SERVER_H +#define SERVER_H + +#include +#include +#include +#include +#include +#include +#include "errors.h" +#include +#include "challenges.h" + +#define MAX_LEN 100 +#define PORT 8080 +#define ADDRESS "127.0.0.1" +#define MAX_PEND_REQ 3 +#define MAX_CHALLENGES 2 +#define TIME_SLEEP 2 + +void startChallenge(); + +#endif \ No newline at end of file diff --git a/server.c b/server.c index e69de29..656f632 100644 --- a/server.c +++ b/server.c @@ -0,0 +1,60 @@ +#include "include/server.h" + +int clientFd; + +challenge_t challenges[] = { + {"A volar bobby", "Cómo es que matan?", "IZPUAN"}, + {"A cagar bobby", "A una niña", "PUANIZ"} +}; + +int main(int argc, char *argv[]) { + int fd; + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) + printSystemError("Server: socket()"); + + int opt = 1; + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) + printSystemError("Server: setsockopt()"); + + struct sockaddr_in address; + address.sin_family = AF_INET; + // address.sin_addr.s_addr = INADDR_ANY; + address.sin_addr.s_addr = inet_addr(ADDRESS); + address.sin_port = htons(PORT); + + if (bind(fd, (struct sockaddr *) &address, sizeof(address)) < 0) + printSystemError("Server: bind()"); + + if (listen(fd, MAX_PEND_REQ) < 0) + printSystemError("Server: listen()"); + + int addrlen = sizeof(address); + if ((clientFd = accept(fd, (struct sockaddr *) &address, (socklen_t *) &addrlen)) < 0) + printSystemError("Server: accept()"); + + startChallenge(); + + close(clientFd); + close(fd); + + return EXIT_SUCCESS; +} + +void startChallenge() { + int challengeCount = 0; + char ansChallenge = 1, output[MAX_LEN] = {0}; + + while (challengeCount < MAX_CHALLENGES && ansChallenge) { + challenge_t currentChallenge = challenges[challengeCount]; + printf("\033[1;1H\033[2J"); // Limpiamos shell + if ((ansChallenge = genChallenge(clientFd, output, currentChallenge))) { + challengeCount++; + } + else { + printf("Incorrecta\n"); + sleep(TIME_SLEEP); + } + } + + return; +} \ No newline at end of file diff --git a/server.o b/server.o deleted file mode 100644 index 3282402a652c9fb458cc4bace5787cd3dccb4e7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1256 zcmbVJ%Syvg5S`TbYawn5ZlW6%OwytjD^#LEMGz~r?u3%YOIvIbNp7WG^=kw_!KI($ z)-TYRdZ)%~S5BDBoH^&@PLko-)p^b^fWv@e_(41cc*zXi(b$C*ScZ%1Thl9-&0^6m z+6B`JWiJwymWV{s2@v{8(600kOIB&$v|6T>%KJ)CE<-AkCz03zIPEwTPTGwFyqwGW z>4|gTIkl=&zuBX-YE^&>&pR@=@vI$n5KQ9^Cguz#&LIcJ8_hTjg)?h2^{Wy;4IiJs zh6Kh7f}IXR={K>;