From b7a7b617fa8425ce9192a7d0bc55797407edcf46 Mon Sep 17 00:00:00 2001 From: Egor Date: Sat, 1 Mar 2025 15:40:22 +0200 Subject: [PATCH] remove windows support --- Makefile | 6 ++--- config.example.mk | 3 --- src/job.c | 25 ----------------- src/main.c | 69 ----------------------------------------------- src/netpoll.c | 5 ---- src/netsock.c | 31 --------------------- src/netsock.h | 31 --------------------- src/passwd.c | 9 ------- 8 files changed, 2 insertions(+), 177 deletions(-) diff --git a/Makefile b/Makefile index 2f1adfd..dc61e31 100644 --- a/Makefile +++ b/Makefile @@ -36,15 +36,13 @@ LDLIBS += $(shell pkg-config --libs lua5.4) endif .PHONY: all clean -all: $(TARGET) $(if $(CC.w32),$(TARGET).exe,) setpass +all: $(TARGET) setpass clean: - $(RM) $(TARGET) $(TARGET).exe setpass + $(RM) $(TARGET) setpass $(TARGET): $(SOURCES) $(HEADERS) $(CC) $(CFLAGS) $(LDFLAGS) $(SOURCES) $(LDLIBS) -o $@ $(TARGET)-cxx: $(SOURCES) $(HEADERS) $(CXX) -x c++ $(CXXFLAGS) $(LDFLAGS) $(SOURCES) $(LDLIBS) -o $@ -$(TARGET).exe: $(SOURCES) $(HEADERS) - $(CC.w32) $(CFLAGS.w32) $(LDFLAGS.w32) $(SOURCES) $(LDLIBS.w32) -o $@ setpass: src/setpass.c src/passwd.c src/crypt_blowfish.c src/passwd.h src/netsock.h $(CC) $(CFLAGS) $(LDFLAGS) src/setpass.c src/passwd.c src/crypt_blowfish.c $(LDLIBS) -o $@ diff --git a/config.example.mk b/config.example.mk index d446f2e..f558b9c 100644 --- a/config.example.mk +++ b/config.example.mk @@ -6,7 +6,4 @@ WARNSXX=-Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wmissing-proto CFLAGS=$(WARNS) -DHAS_TLS -DNETPOLL_USE_POLL -D_GNU_SOURCE CXXFLAGS=$(WARNSXX) -DHAS_TLS -DNETPOLL_USE_POLL -D_GNU_SOURCE LDLIBS=-ltls -CC.w32=i686-w64-mingw32-gcc -CFLAGS.w32=$(WARNS) -DNETPOLL_USE_SELECT -LDLIBS.w32=-lws2_32 -lbcrypt USE_LUA=1 diff --git a/src/job.c b/src/job.c index 8a82e73..1fef031 100644 --- a/src/job.c +++ b/src/job.c @@ -1,11 +1,9 @@ #include "common.h" #include "job.h" #include "passwd.h" -#ifndef _WIN32 #include #include #include -#endif struct jobent { struct client_data *client; @@ -17,7 +15,6 @@ struct jobent { static struct jobent *jobtab; static int joblen = 0, jobcap = 0; -#ifndef _WIN32 static pid_t current_child = -1; static int current_result = 0; static void job_child(int signum) @@ -84,26 +81,6 @@ void job_process_end(void) sigaddset(&mask, SIGCHLD); sigprocmask(SIG_UNBLOCK, &mask, 0); } -#else -void job_init(void) -{ -} -void job_process_begin(void) -{ - struct jobent *ent = jobtab; - while (joblen) { - int res = ent->job(ent->client, ent->data, ent->len); - memset(ent->data, 0, ent->len); - free(ent->data); - ent->then(ent->client, res); - joblen--; - ent++; - } -} -void job_process_end(void) -{ -} -#endif void job_add(struct client_data *cl, jobproc_t job, contproc_t then, char *data, size_t len) { @@ -122,10 +99,8 @@ void job_kill(struct client_data *cl) { struct jobent *p, *q; p = q = jobtab; -#ifndef _WIN32 if (joblen && jobtab[0].client == cl) current_child = -1; -#endif while (p < jobtab+joblen) { if (p->client != cl) { *q++ = *p; diff --git a/src/main.c b/src/main.c index 5e31673..ecb0a19 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,6 @@ static int is_running = 1; -#ifndef _WIN32 #include static volatile sig_atomic_t is_siginted = 0; static void on_sigint(int signum) @@ -28,55 +27,6 @@ static void set_handler(void) if (sigaction(SIGPIPE, &sa, NULL) == -1) perror("sigaction"); } -#else -static int is_siginted_once = 0; -static volatile int is_siginted = 0; -static SOCKET self_sock = INVALID_SOCKET; -static BOOL WINAPI on_sigint(DWORD dwCtrlType) -{ - if ((dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_CLOSE_EVENT) && !is_siginted_once) { - is_siginted_once = 1; - is_siginted = 1; - char x = 0; - if (self_sock != INVALID_SOCKET) { - send(self_sock, &x, 0, 0); // FIXME: this could EAGAIN in theory - } - return TRUE; - } else { - return FALSE; - } -} -static void set_handler(void) -{ - SetConsoleCtrlHandler(on_sigint, TRUE); - - self_sock = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0); - if (self_sock == INVALID_SOCKET) { - net_perror("ERROR CREATING SELF SOCK"); - return; - } - struct sockaddr_in sin; - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(0x7F000069); - int addrlen = sizeof(sin); - if (bind(self_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) - goto err; - if (getsockname(self_sock, (struct sockaddr *)&sin, &addrlen) == -1) - goto err; - if (connect(self_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) - goto err; - if (net_nonblock(self_sock) == -1) - goto err; - net_poll_add(self_sock, SOCKTYPE_SELFPIPE, 0); - net_poll_reg(self_sock, NETPOLL_IN); - return; -err: - net_perror("ERROR CREATING SELF SOCK"); - closesocket(self_sock); - self_sock = INVALID_SOCKET; -} -#endif // Client linked list struct client_data *clients = NULL, *dyingclients = NULL; @@ -109,13 +59,11 @@ static SOCKET create_listen_sock(const char *ip, const char *port) } // Set socket options int opt = 1; -#ifndef _WIN32 if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*)&opt, sizeof(opt)) == -1) { net_perror("ERROR SOCKET"); freeaddrinfo(res); exit(EXIT_FAILURE); } -#endif if(res->ai_family == AF_INET6 && setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&opt, sizeof(opt)) == -1) { net_perror("ERROR SOCKET IPV6"); freeaddrinfo(res); @@ -390,12 +338,10 @@ int main(int argc, char *argv[]) job_process_begin(); if (net_poll_begin() == -1) { -#ifndef _WIN32 if (errno == EINTR) { job_process_end(); continue; } -#endif net_perror("ERROR SELECT"); job_process_end(); } @@ -404,15 +350,6 @@ int main(int argc, char *argv[]) struct net_pollfd pfd; while ((ev = net_poll_get(&pfd))) { switch (pfd.type) { -#ifdef _WIN32 - case SOCKTYPE_SELFPIPE: - if (ev & NETPOLL_IN) { - char x; - while (recv(pfd.fd, &x, 0, 0) != -1) - ; - } - break; -#endif case SOCKTYPE_LISTENER: if (ev & NETPOLL_IN) accept_from_sock((struct listener *)pfd.assoc); @@ -455,12 +392,6 @@ int main(int argc, char *argv[]) } } -#ifdef _WIN32 - if (self_sock != INVALID_SOCKET) { - net_poll_del(self_sock); - closesocket(self_sock); - } -#endif #ifdef HAS_LUA admin_fini(); #endif diff --git a/src/netpoll.c b/src/netpoll.c index 9ace612..33aea7c 100644 --- a/src/netpoll.c +++ b/src/netpoll.c @@ -56,16 +56,11 @@ int net_poll_begin(void) { memcpy(&xreadfds, &readfds, sizeof(readfds)); memcpy(&xwritefds, &writefds, sizeof(writefds)); -#ifdef _WIN32 - int highfd = 0; - int rv = select(highfd, &xreadfds, &xwritefds, 0, 0); -#else sigset_t mask; sigprocmask(0, 0, &mask); sigdelset(&mask, SIGCHLD); int highfd = nfds ? fds[nfds-1].fd+1 : 0; int rv = pselect(highfd, &xreadfds, &xwritefds, 0, 0, &mask); -#endif lastptr = 0; return rv; } diff --git a/src/netsock.c b/src/netsock.c index 51abc5c..3a11521 100644 --- a/src/netsock.c +++ b/src/netsock.c @@ -1,42 +1,11 @@ #include "netsock.h" -#ifdef _WIN32 -void net_init(void) -{ - WSADATA wsaData; - int err = WSAStartup(MAKEWORD(2, 0), &wsaData); - if (err) { - fprintf(stderr, "Winsock API startup failed: %s\n", net_strerror(err)); - exit(EXIT_FAILURE); - } - fprintf(stderr, "[NetSock]: WinSock initialized V%d.%d!\n",LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion)); -} -void net_cleanup(void) -{ - WSACleanup(); -} -const char *net_strerror(int e) -{ - static char msg[256]; - if (!FormatMessageA( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, e, 0, msg, 256, NULL)) - sprintf(msg, "WSA Error %d", e); - return msg; -} -#endif - int net_nonblock(SOCKET fd) { -#if !defined(_WIN32) && defined(O_NONBLOCK) int f = fcntl(fd, F_GETFL); if (f == -1) return -1; return fcntl(fd, F_SETFL, f | O_NONBLOCK); -#else - u_long v = 1; - return ioctlsocket(fd, FIONBIO, &v); -#endif } void net_perror(const char *p) diff --git a/src/netsock.h b/src/netsock.h index fe7834c..ee8561e 100644 --- a/src/netsock.h +++ b/src/netsock.h @@ -30,42 +30,12 @@ * Win32 has 64 as default, Linux has 1024. Increase the limit on Win32. */ #define FD_SETSIZE 1024 -/* Set target Win32 version to Vista. - * In particular, inet_ntop and AI_NUMERICSERV require this. */ -#ifdef _WIN32 -#define WINVER 0x0600 -#define _WIN32_WINNT 0x0600 -#endif - /* Standard headers */ #include #include #include #include -#ifdef _WIN32 -/* Win32 */ -/* Include winsock2.h first, because windows.h defauts to Winsock 1 */ -#include -#include -#include -#ifdef _WIN64 -#define PRISocket "llu" -#else -#define PRISocket "u" -#endif -#define net_errno() (WSAGetLastError()) -const char *net_strerror(int e); -#define net_wouldblock() (WSAGetLastError() == WSAEWOULDBLOCK) -void net_init(void); -void net_cleanup(void); -#define SHUT_RD SD_RECEIVE -#define SHUT_WR SD_SEND -#define SHUT_RDWR SD_BOTH -#define SOCK_CLOEXEC 0 -#define FOPEN_CLOEXEC "" -#define accept4(a,b,c,d) accept((a),(b),(c)) -#else /* POSIX */ #include #include @@ -95,4 +65,3 @@ typedef int SOCKET; void net_perror(const char *p); int net_nonblock(SOCKET fd); -#endif diff --git a/src/passwd.c b/src/passwd.c index 62e9375..e203262 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -1,11 +1,7 @@ #include "netsock.h" #include #include -#ifndef _WIN32 #include -#else -#include -#endif #include "passwd.h" #include "crypt_blowfish.h" char *password_crypt(const char *key, const char *setting) @@ -22,13 +18,8 @@ char *password_hash2(const char *pw, int algo, int strength) "./0123456789ABCDEFGHIJKLMNOPQRST" "UVWXYZabcdefghijklmnopqrstuvwxyz"; unsigned char ubytes[16]; -#ifndef _WIN32 if (getentropy(ubytes, 16) == -1) return NULL; -#else - if (BCryptGenRandom(0, ubytes, 16, BCRYPT_USE_SYSTEM_PREFERRED_RNG)) - return NULL; -#endif char salt[7 + 22 + 1]; // 20 for SHA512 if (algo == 2) { memcpy(salt, "$2b$10$", 7); -- 2.56.0