From: Egor Date: Thu, 12 Jun 2025 23:49:47 +0000 (+0300) Subject: assume FOPEN_CLOEXEC exists X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=aeaddb4a2eab844093fb9327f6b3c3202e6a70d7;p=patchyircd.git assume FOPEN_CLOEXEC exists --- diff --git a/src/irc.cpp b/src/irc.cpp index f21809b..349c0bc 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -532,7 +532,7 @@ saslcleanup: if (!hash) return 0; // TODO: error message memset(args[1], 0, strlen(args[1])); - FILE *f = fopen(getdatafile("newusers.txt"), "ab" FOPEN_CLOEXEC); + FILE *f = fopen(getdatafile("newusers.txt"), "abe"); if (!f) return 0; // TODO: error message fprintf(f, "%s:%s\n", args[0], hash); @@ -803,7 +803,7 @@ saslcleanup: if (!is_registered(client)) return err_notregistered(client), sendbuf(client), 0; char line[512]; - FILE *f = fopen(getdatafile("help.txt"), "r" FOPEN_CLOEXEC); + FILE *f = fopen(getdatafile("help.txt"), "re"); if (f) { rpl_helpstart(client), sendbuf(client); while (fgets(line, 512, f)) { @@ -830,7 +830,7 @@ saslcleanup: if (args[0] && strcmp(args[0], hostname) != 0) return err_nosuchserver(client, args[0]), sendbuf(client), 0; char line[512]; - FILE *f = fopen(getdatafile("admin.txt"), "r" FOPEN_CLOEXEC); + FILE *f = fopen(getdatafile("admin.txt"), "re"); if (f) { auto nextline = [f, &line]()->bool{ if (fgets(line, 512, f)) { @@ -1286,7 +1286,7 @@ void sendLUSERS(struct client_data *client) void sendMOTD(struct client_data *client) { char line[512]; - FILE *f = fopen(getdatafile("motd.txt"), "r" FOPEN_CLOEXEC); + FILE *f = fopen(getdatafile("motd.txt"), "re"); if (f) { rpl_motdstart(client), sendbuf(client); while (fgets(line, 512, f)) { diff --git a/src/main.cpp b/src/main.cpp index 3663412..3670f22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -292,7 +292,7 @@ int main(int argc, char *argv[]) netpoll::reg(listener.sock, UV_READABLE); } - FILE *f = fopen(getdatafile("init.txt"), "rb" FOPEN_CLOEXEC); + FILE *f = fopen(getdatafile("init.txt"), "rbe"); if (f) { struct client_data *fake = allocClient(); fake->FD = INVALID_SOCKET; @@ -344,7 +344,7 @@ int main(int argc, char *argv[]) set_time(0); fclose(f); } - fchanlog = fopen(getdatafile("chanlog.txt"), "ab" FOPEN_CLOEXEC); + fchanlog = fopen(getdatafile("chanlog.txt"), "abe"); if (fchanlog) { fprintf(fchanlog, "$0 AAA :server starting %lu\r\n", (unsigned long)get_time()); fflush(fchanlog); diff --git a/src/netsock.h b/src/netsock.h index 2213fc8..e5fc000 100644 --- a/src/netsock.h +++ b/src/netsock.h @@ -56,8 +56,4 @@ typedef int SOCKET; #define net_perror(p) (perror((p))) #define net_wouldblock() (errno == EAGAIN || errno == EWOULDBLOCK) #define closesocket close -#ifndef SOCK_CLOEXEC -#error "SOCK_CLOEXEC is required" -#endif -#define FOPEN_CLOEXEC "e" #endif diff --git a/src/passwd.cpp b/src/passwd.cpp index 569614c..018b4e0 100644 --- a/src/passwd.cpp +++ b/src/passwd.cpp @@ -1,6 +1,5 @@ // Copyright (c) 2022-2025 Egor // SPDX-License-Identifier: GPL-2.0-or-later -#include "netsock.h" #include #include #include @@ -49,10 +48,10 @@ char *password_hash(const char *pw) } int password_set(const char *key, const char *pw, const char *fn, const char *tmpfn) { - FILE *fi = fopen(fn, "rb" FOPEN_CLOEXEC); + FILE *fi = fopen(fn, "rbe"); if (!fi) return -1; - FILE *fo = fopen(tmpfn, "wb" FOPEN_CLOEXEC); + FILE *fo = fopen(tmpfn, "wbe"); if (!fo) { fclose(fi); return -1; @@ -97,7 +96,7 @@ int password_set(const char *key, const char *pw, const char *fn, const char *tm char *password_get(const char *key, const char *fn) { // NOTE: there are probably a lot of timing leaks in here - FILE *fi = fopen(fn, "rb" FOPEN_CLOEXEC); + FILE *fi = fopen(fn, "rbe"); if (!fi) return 0; int keylen = strlen(key); @@ -131,7 +130,7 @@ int password_check(const char *key, const char *pw, const char *fn) } } const char *db_read_rhs(const char *key, const char *fn) { - FILE *fi = fopen(fn, "rb" FOPEN_CLOEXEC); + FILE *fi = fopen(fn, "rbe"); if (!fi) return 0; int keylen = strlen(key);