Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fcb939e
Fix up rb_rawbuf_get's cpylen, nothing calls rb_rawbuf_get at this point
synandro Jan 30, 2026
a7d718d
Don't compile the rb_rawbuf_get code, its still buggy and nothing cur…
synandro Jan 30, 2026
85fe3c6
Track rawbuf buffer stage in the individual buffer rather than the bu…
synandro Jan 30, 2026
9985395
validate that ssld has been passed a unix socket and fifo for control
synandro Jan 30, 2026
e2880f8
Get the timestamp of ConfigFileEntry.motd_path and not the hard coded…
synandro Jan 30, 2026
21dddd5
Don't leak memory from posix_spawnattr_init...call posix_spawnattr_de…
synandro Jan 30, 2026
11f4672
Add support for settings minimum tls version of 1.3
synandro Jan 30, 2026
b13ee04
rb_ssl_accept_common and rb_ssl_tryaccept were effectively the same c…
synandro Jan 30, 2026
4d8532b
Remove a few alloca calls
synandro Feb 2, 2026
93a7439
truncate the correct string if we have comma in do_whois
synandro Feb 2, 2026
3d094c3
unconditionally use our own LOCAL_COPY implementation based on glibc …
synandro Feb 2, 2026
685b83d
Pass the buffer sizes down through find_user_host rather than assumin…
synandro Feb 2, 2026
25e860f
strchr breaks const char by casting a pointer from a string to a non-…
synandro Feb 2, 2026
877a07f
Split nick on a local copy and use said local copy throughout consist…
synandro Feb 2, 2026
c04fdc4
close on exec for openssl and gnutls opens
synandro Feb 3, 2026
a253791
It's possible for the callback to free the request, so stash the valu…
synandro Feb 3, 2026
a966967
calculate the hashlen correctlyn
synandro Feb 3, 2026
f7c6c3e
Make the resolver IDs be a 32bit counter and the generated ID. The c…
synandro Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ typedef void DNSCB(const char *res, int status, int aftype, void *data);
void init_resolver(void);
void restart_resolver(void);
void rehash_resolver(void);
uint16_t __rb_must_check lookup_hostname(const char *hostname, int aftype, DNSCB * callback, void *data);
uint16_t __rb_must_check lookup_ip(const char *hostname, int aftype, DNSCB * callback, void *data);
void cancel_lookup(uint16_t xid);
uint32_t __rb_must_check lookup_hostname(const char *hostname, int aftype, DNSCB * callback, void *data);
uint32_t __rb_must_check lookup_ip(const char *hostname, int aftype, DNSCB * callback, void *data);
void cancel_lookup(uint32_t xid);
void report_dns_servers(struct Client *);
void rehash_dns_vhost(void);

Expand Down
2 changes: 1 addition & 1 deletion include/s_newconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ struct server_conf
int flags;
int servers;

uint16_t dns_query;
uint32_t dns_query;
};

#define SERVER_ILLEGAL 0x0001
Expand Down
57 changes: 27 additions & 30 deletions include/stdinc.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,40 +164,37 @@ extern int errno;
#endif



#ifdef strdupa
#define LOCAL_COPY(s) strdupa(s)
#else
#if defined(__INTEL_COMPILER) || defined(__GNUC__)
# define LOCAL_COPY(s) __extension__({ char *_s = alloca(strlen(s) + 1); strcpy(_s, s); _s; })
/* unconditionally use our own strdupa/strndupa.
* if you use a compiler other than these, fix it yourself
* these macros were lifted from glibc
*/
#if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__clang__)
#define LOCAL_COPY(s) \
(__extension__ \
({ \
const char *__old = (s); \
size_t __len = strlen (__old) + 1; \
char *__new = (char *) __builtin_alloca (__len); \
(char *) memcpy (__new, __old, __len); \
}))
#else
# define LOCAL_COPY(s) strcpy(alloca(strlen(s) + 1), s) /* XXX Is that allowed? */
#endif /* defined(__INTEL_COMPILER) || defined(__GNUC__) */
#endif /* strdupa */
#error "does your compiler support strdup/alloca?"
#endif /* defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__clang__) */

/* LOCAL_COPY_N copies n part of string and adds one to terminate the string */
#ifdef strndupa
#define LOCAL_COPY_N(s, n) strndupa(s, n)
#else
#if defined(__INTEL_COMPILER) || defined(__GNUC__)
#define LOCAL_COPY_N(s, n) __extension__({ size_t _l = strlen(s); _l = n > _l ? _l : n; char *_s = alloca(_l+1); memcpy(_s, s, _l); _s[_l] = '\0' ; _s; })
#if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__clang__)
# define LOCAL_COPY_N(s, n) \
(__extension__ \
({ \
const char *__old = (s); \
size_t __len = strnlen (__old, (n)); \
char *__new = (char *) __builtin_alloca (__len + 1); \
__new[__len] = '\0'; \
(char *) memcpy (__new, __old, __len); \
}))
#else
#define LOCAL_COPY_N(s, n) xc_strlcpy(alloca(strlen(s)+1), s, n)
INLINE_FUNC size_t
xc_strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = strlen(src);

if(size)
{
size_t len = (ret >= size) ? size - 1 : ret;
memcpy(dest, src, len);
dest[len] = '\0';
}
return dest;
}
#endif /* defined(__INTEL_COMPILER) || defined(__GNUC__) */
#endif /* strndupa */
#error "does your compiler support strndup/alloca?"
#endif /* defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__clang__) */

#ifndef INADDR_NONE
# define INADDR_NONE ((in_addr_t) 0xffffffff)
Expand Down
1 change: 1 addition & 0 deletions libratbox/include/rb_commio.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef enum _rb_tls_ver
RB_TLS_VER_TLS1,
RB_TLS_VER_TLS1_1,
RB_TLS_VER_TLS1_2,
RB_TLS_VER_TLS1_3,
RB_TLS_VER_LAST,
} rb_tls_ver_t;

Expand Down
2 changes: 2 additions & 0 deletions libratbox/include/rb_rawbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ typedef struct _rb_rawbuf_head rb_rawbuf_head_t;
void rb_init_rawbuffers(void);
void rb_free_rawbuffer(rb_rawbuf_head_t *);
rb_rawbuf_head_t *rb_new_rawbuffer(void);
#if 0
size_t rb_rawbuf_get(rb_rawbuf_head_t *, void *data, size_t len);
#endif
void rb_rawbuf_append(rb_rawbuf_head_t *, void *data, size_t len);
ssize_t rb_rawbuf_flush(rb_rawbuf_head_t *, rb_fde_t *F);
size_t rb_rawbuf_length(rb_rawbuf_head_t * rb);
Expand Down
1 change: 0 additions & 1 deletion libratbox/src/export-syms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ rb_patricia_search_exact
rb_pipe
rb_rawbuf_append
rb_rawbuf_flush
rb_rawbuf_get
rb_rawbuf_length
rb_read
rb_recv_fd_buf
Expand Down
2 changes: 1 addition & 1 deletion libratbox/src/gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ rb_load_file_into_datum_t(const char *file)
FILE *f;
gnutls_datum_t *datum;
struct stat fileinfo;
if((f = fopen(file, "r")) == NULL)
if((f = fopen(file, "re")) == NULL)
return NULL;
if(fstat(fileno(f), &fileinfo))
return NULL;
Expand Down
47 changes: 14 additions & 33 deletions libratbox/src/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,36 +195,6 @@ rb_ssl_tryaccept(rb_fde_t *F, void *data)
}


static void
rb_ssl_accept_common(rb_fde_t *new_F)
{
int ssl_err;
if((ssl_err = SSL_accept((SSL *) new_F->ssl)) <= 0)
{
switch (ssl_err = SSL_get_error((SSL *) new_F->ssl, ssl_err))
{
case SSL_ERROR_SYSCALL:
if(rb_ignore_errno(errno))
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
{
new_F->sslerr.ssl_errno = get_last_err();
rb_setselect(new_F, RB_SELECT_READ | RB_SELECT_WRITE,
rb_ssl_tryaccept, NULL);
return;
}
default:
new_F->sslerr.ssl_errno = get_last_err();
new_F->accept->callback(new_F, RB_ERROR_SSL, NULL, 0, new_F->accept->data);
return;
}
}
else
{
rb_ssl_tryaccept(new_F, NULL);
}
}

void
rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout)
{
Expand All @@ -250,7 +220,7 @@ rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout)
new_F->accept->addrlen = 0;
SSL_set_fd((SSL *) new_F->ssl, rb_get_fd(new_F));
rb_setup_ssl_cb(new_F);
rb_ssl_accept_common(new_F);
rb_ssl_tryaccept(new_F, NULL);
}


Expand Down Expand Up @@ -285,7 +255,7 @@ rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, rb_sockle

SSL_set_fd((SSL *) new_F->ssl, rb_get_fd(new_F));
rb_setup_ssl_cb(new_F);
rb_ssl_accept_common(new_F);
rb_ssl_tryaccept(new_F, NULL);
}

typedef enum {
Expand Down Expand Up @@ -492,6 +462,17 @@ rb_setup_ssl_server(const char *cacert, const char *cert, const char *keyfile, c
#endif
#ifdef SSL_OP_NO_TLSv1_1
tls_opts |= SSL_OP_NO_TLSv1_1;
#endif
break;
case RB_TLS_VER_TLS1_3:
#ifdef SSL_OP_NO_TLSv1
tls_opts |= SSL_OP_NO_TLSv1;
#endif
#ifdef SSL_OP_NO_TLSv1_1
tls_opts |= SSL_OP_NO_TLSv1_1;
#endif
#ifdef SSL_OP_NO_TLSv1_2
tls_opts |= SSL_OP_NO_TLSv1_2;
#endif
break;
case RB_TLS_VER_LAST:
Expand Down Expand Up @@ -558,7 +539,7 @@ rb_setup_ssl_server(const char *cacert, const char *cert, const char *keyfile, c
if(dhfile != NULL)
{
/* DH parameters aren't necessary, but they are nice..if they didn't pass one..that is their problem */
BIO *bio = BIO_new_file(dhfile, "r");
BIO *bio = BIO_new_file(dhfile, "re");
if(bio != NULL)
{
DH *dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
Expand Down
84 changes: 31 additions & 53 deletions libratbox/src/rawbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
struct _rb_rawbuf
{
rb_dlink_node node;
uint8_t data[RAWBUF_SIZE];
void *data;
size_t len;
size_t written;
bool flushing;
};

struct _rb_rawbuf_head
{
rb_dlink_list list;
size_t len;
size_t written;
};


Expand All @@ -55,6 +55,9 @@ static void
rb_rawbuf_done(rb_rawbuf_head_t * rb, rb_rawbuf_t * buf)
{
rb_rawbuf_t *ptr = buf;
if(buf->data != NULL)
rb_free(buf->data);

rb_dlinkDelete(&buf->node, &rb->list);
rb_free(ptr);
}
Expand Down Expand Up @@ -83,8 +86,8 @@ rb_rawbuf_flush_writev(rb_rawbuf_head_t * rb, rb_fde_t *F)
buf = ptr->data;
if(buf->flushing == true)
{
vec[x].iov_base = buf->data + rb->written;
vec[x++].iov_len = buf->len - rb->written;
vec[x].iov_base = buf->data + buf->written;
vec[x++].iov_len = buf->len - buf->written;
continue;
}
vec[x].iov_base = buf->data;
Expand All @@ -108,10 +111,10 @@ rb_rawbuf_flush_writev(rb_rawbuf_head_t * rb, rb_fde_t *F)
break;
if(buf->flushing == true)
{
if(xret >= (ssize_t)(buf->len - rb->written))
if(xret >= (ssize_t)(buf->len - buf->written))
{
xret -= buf->len - rb->written;
rb->len -= buf->len - rb->written;
xret -= buf->len - buf->written;
rb->len -= buf->len - buf->written;
rb_rawbuf_done(rb, buf);
continue;
}
Expand All @@ -126,7 +129,7 @@ rb_rawbuf_flush_writev(rb_rawbuf_head_t * rb, rb_fde_t *F)
else
{
buf->flushing = true;
rb->written = (size_t)xret;
buf->written = (size_t)xret;
rb->len -= (size_t)xret;
break;
}
Expand All @@ -140,6 +143,7 @@ rb_rawbuf_flush(rb_rawbuf_head_t * rb, rb_fde_t *F)
{
rb_rawbuf_t *buf;
ssize_t retval;

if(rb->list.head == NULL)
{
errno = EAGAIN;
Expand All @@ -153,19 +157,17 @@ rb_rawbuf_flush(rb_rawbuf_head_t * rb, rb_fde_t *F)
if(buf->flushing == false)
{
buf->flushing = true;
rb->written = 0;
buf->written = 0;
}

retval = rb_write(F, buf->data + rb->written, buf->len - rb->written);
retval = rb_write(F, buf->data + buf->written, buf->len - buf->written);
if(retval <= 0)
return retval;

rb->written += (size_t)retval;
if(rb->written == buf->len)
buf->written += (size_t)retval;
if(buf->written == buf->len)
{
rb->written = 0;
rb_dlinkDelete(&buf->node, &rb->list);
rb_free(buf);
rb_rawbuf_done(rb, buf);
}
rb->len -= (size_t)retval;
return retval;
Expand All @@ -178,38 +180,16 @@ rb_rawbuf_flush(rb_rawbuf_head_t * rb, rb_fde_t *F)
void
rb_rawbuf_append(rb_rawbuf_head_t * rb, void *in, size_t len)
{
rb_rawbuf_t *buf = NULL;
size_t clen;
void *ptr;
uint8_t *data = in;

if(rb->list.tail != NULL)
buf = rb->list.tail->data;

if(buf != NULL && buf->len < sizeof(buf->data) && buf->flushing == false)
{
ptr = (void *)((uintptr_t)buf->data + buf->len);
clen = IRCD_MIN((sizeof(buf->data) - buf->len), len);
memcpy(ptr, data, clen);
buf->len += clen;
rb->len += clen;
len -= clen;
data = (data + clen);
}

while(len > 0)
{
buf = rb_rawbuf_newbuf(rb);
clen = IRCD_MIN(sizeof(buf->data), len);
memcpy(buf->data, data, clen);
buf->len += clen;
rb->len += clen;
len -= clen;
data = (data + clen);
}
rb_rawbuf_t *buf;
buf = rb_rawbuf_newbuf(rb);
buf->data = rb_malloc(len);
buf->len = len;
memcpy(buf->data, in, len);
rb->len += buf->len;
}


#if 0
/* this is still broken..if somebody wants to use it, they need to fix it */
size_t
rb_rawbuf_get(rb_rawbuf_head_t * rb, void *data, size_t len)
{
Expand All @@ -222,31 +202,29 @@ rb_rawbuf_get(rb_rawbuf_head_t * rb, void *data, size_t len)
buf = rb->list.head->data;

if(buf->flushing == true)
ptr = (void *)(buf->data + rb->written);
ptr = (void *)(buf->data + buf->written);
else
ptr = buf->data;

if(len > buf->len)
cpylen = buf->len;
else
cpylen = len;
cpylen = IRCD_MIN(len, buf->len);

memcpy(data, ptr, cpylen);

if(cpylen == buf->len)
{
rb->written = 0;
buf->written = 0;
rb_rawbuf_done(rb, buf);
rb->len -= len;
rb->len -= cpylen;
return cpylen;
}

buf->flushing = true;
buf->len -= cpylen;
rb->len -= cpylen;
rb->written += cpylen;
buf->written += cpylen;
return cpylen;
}
#endif

size_t
rb_rawbuf_length(rb_rawbuf_head_t * rb)
Expand Down
Loading