Nitori Engineering
This commit is contained in:
parent
2be3612092
commit
4a74b5bcfc
4
Makefile
4
Makefile
@ -1,14 +1,16 @@
|
||||
PREFIX?= /usr/local
|
||||
BINDIR= ${PREFIX}/sbin
|
||||
MANDIR= ${PREFIX}/man/man
|
||||
MANDIR= ${PREFIX}/man/man8
|
||||
|
||||
PROG= icbd
|
||||
SRCS= cmd.c dns.c icb.c icbd.c logger.c
|
||||
MAN= icbd.8
|
||||
|
||||
.ifdef __OpenBSD__
|
||||
CFLAGS+= -W -Wall -Werror
|
||||
CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
|
||||
CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
|
||||
.endif
|
||||
|
||||
DPADD= ${LIBEVENT}
|
||||
LDADD= -levent
|
||||
|
43
README
43
README
@ -1,5 +1,38 @@
|
||||
icbd: a simple ICB daemon written in C
|
||||
======================================
|
||||
|
||||
http://www.icb.net/
|
||||
http://www.icb.net/_jrudd/icb/protocol.html
|
||||
_____________________
|
||||
( A simple ICB daemon )
|
||||
---------------------
|
||||
\
|
||||
\
|
||||
\ ,__--**@@@**--__,
|
||||
\ ,@%* *%@m,
|
||||
,@* # +@*# @ *@,
|
||||
,@* @ # __ @ @,
|
||||
,*@m#, @, m*@ %_- ,@ ,#m@*,
|
||||
,@@*-% @ # # @ %-+m,
|
||||
@ @ @#=====#================#=====#@ @ %,
|
||||
@* ,*@m,## ##,m@*, @
|
||||
# :@ #====---__________________---====# @: @
|
||||
@* :@ @ @. @: @
|
||||
@ *m__m* #m, .# *m__* @
|
||||
@ @ .# % @ @ @ =- @*
|
||||
*, % ,% @ @ @ @. *% #, .- ,@
|
||||
@ *@ @ @, @ *@ :@ @ ,@ *, @. @
|
||||
@ @@. % *# @ ,@* #+* % .@ @
|
||||
@ % @, @ m--#@+*+@#-- # --#@+*+@#--m @ ,@+ @
|
||||
.@ @ *@# | @ @ @ @ @ @ | +@ ,@ % *,
|
||||
,@ @, @ @*^ @ @*^ @ @ #%* @ %,
|
||||
,@ *% @ @ @ % @ @ @ %
|
||||
@ ,*@ % *=_=* *=_=* % ,*+ @
|
||||
%* m* @ % % % @, @
|
||||
@ @* % ,@ @, @ @ @:
|
||||
@ @ @ @ *_* @ @ @ @:
|
||||
@: %, %, @**__, ,__**@ @ _% @
|
||||
@, *_ @, @ @. *--__, ,__--* .@ @ @ #, ,@*
|
||||
*--__+# @, @ @, . ^^^^^ . ,@ * ,@ *+@@*
|
||||
^*+# *%__*%,m***m,%*__%* #@@+*
|
||||
O O *=
|
||||
*m_m*
|
||||
# #
|
||||
# @*#
|
||||
# -#
|
||||
#+*^
|
||||
|
33
dns.c
33
dns.c
@ -27,7 +27,18 @@
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#ifdef __NetBSD__
|
||||
#define NO_ASYNC
|
||||
#endif
|
||||
|
||||
#ifdef NO_ASYNC
|
||||
struct asr_result {
|
||||
struct addrinfo* ar_addrinfo;
|
||||
int ar_gai_errno;
|
||||
};
|
||||
#else
|
||||
#include <asr.h>
|
||||
#endif
|
||||
|
||||
#include "icb.h"
|
||||
#include "icbd.h"
|
||||
@ -85,7 +96,11 @@ void
|
||||
dns_done_reverse(struct asr_result *ar, void *arg)
|
||||
{
|
||||
struct icb_session *is = arg;
|
||||
#ifdef NO_ASYNC
|
||||
struct asr_result result;
|
||||
#else
|
||||
struct asr_query *as;
|
||||
#endif
|
||||
struct addrinfo hints;
|
||||
|
||||
if (ISSETF(is->flags, ICB_SF_PENDINGDROP)) {
|
||||
@ -99,8 +114,14 @@ dns_done_reverse(struct asr_result *ar, void *arg)
|
||||
/* try to verify that it resolves back */
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
#ifdef NO_ASYNC
|
||||
getaddrinfo(is->hostname, NULL, &hints, &result.ar_addrinfo);
|
||||
result.ar_gai_errno = errno;
|
||||
dns_done_host(&result, is);
|
||||
#else
|
||||
as = getaddrinfo_async(is->hostname, NULL, &hints, NULL);
|
||||
event_asr_run(as, dns_done_host, is);
|
||||
#endif
|
||||
} else {
|
||||
icbd_log(is, LOG_DEBUG, "reverse dns resolution failed: %s",
|
||||
gai_strerror(ar->ar_gai_errno));
|
||||
@ -129,7 +150,11 @@ cmp_addr(struct sockaddr *a, struct sockaddr *b)
|
||||
void
|
||||
dns_resolve(struct icb_session *is)
|
||||
{
|
||||
#ifdef NO_ASYNC
|
||||
struct asr_result result;
|
||||
#else
|
||||
struct asr_query *as;
|
||||
#endif
|
||||
|
||||
if (!dodns)
|
||||
return;
|
||||
@ -139,9 +164,17 @@ dns_resolve(struct icb_session *is)
|
||||
if (verbose)
|
||||
icbd_log(is, LOG_DEBUG, "resolving: %s", is->host);
|
||||
|
||||
#ifdef NO_ASYNC
|
||||
getnameinfo((struct sockaddr *)&is->ss,
|
||||
((struct sockaddr *)&is->ss)->sa_len, is->hostname,
|
||||
sizeof is->hostname, NULL, 0, NI_NOFQDN);
|
||||
result.ar_gai_errno = errno;
|
||||
dns_done_reverse(&result, is);
|
||||
#else
|
||||
as = getnameinfo_async((struct sockaddr *)&is->ss,
|
||||
((struct sockaddr *)&is->ss)->sa_len, is->hostname,
|
||||
sizeof is->hostname, NULL, 0, NI_NOFQDN, NULL);
|
||||
event_asr_run(as, dns_done_reverse, is);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
4
icb.c
4
icb.c
@ -578,7 +578,11 @@ icb_dowho(struct icb_session *is, struct icb_group *ig)
|
||||
icb_cmdout(is, CMDOUT_CO, buf);
|
||||
LIST_FOREACH(s, &ig->sess, entry) {
|
||||
(void)snprintf(buf, sizeof buf,
|
||||
#ifdef __NetBSD__
|
||||
"%c%c%s%c%ld%c0%c%ld%c%s%c%s%c%s",
|
||||
#else
|
||||
"%c%c%s%c%lld%c0%c%lld%c%s%c%s%c%s",
|
||||
#endif
|
||||
icb_ismod(ig, s) ? 'm' : ' ', ICB_M_SEP,
|
||||
s->nick, ICB_M_SEP, now - s->last,
|
||||
ICB_M_SEP, ICB_M_SEP, s->login, ICB_M_SEP,
|
||||
|
20
icbd.c
20
icbd.c
@ -1,6 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Mike Belopuhov
|
||||
* Copyright (c) 2007 Oleg Safiullin
|
||||
* Copyright (c) 2024 Nishi
|
||||
* Copyright (C) 2025 Izuru Yakumo
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -174,12 +176,21 @@ main(int argc, char *argv[])
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
#ifdef __OpenBSD__
|
||||
/* Apparently OpenBSD is the only one that has icb on /etc/services */
|
||||
/* Sure, it could be easily added to any other system, but I'm personally against it */
|
||||
/* ~Izuru Yakumo */
|
||||
if ((error = getaddrinfo(addr, port ? port : "icb", &hints,
|
||||
&res0)) != 0) {
|
||||
syslog(LOG_ERR, "%s", gai_strerror(error));
|
||||
return (EX_UNAVAILABLE);
|
||||
}
|
||||
|
||||
#else
|
||||
if ((error = getaddrinfo(addr, port ? port : "7326", &hints, &res0)) != 0) {
|
||||
syslog(LOG_ERR, "%s", gai_strerror(error));
|
||||
return (EX_UNAVAILABLE);
|
||||
}
|
||||
#endif
|
||||
for (res = res0; res != NULL; res = res->ai_next) {
|
||||
if ((s = socket(res->ai_family, res->ai_socktype,
|
||||
res->ai_protocol)) < 0) {
|
||||
@ -475,12 +486,11 @@ icbd_restrict(void)
|
||||
syslog(LOG_ERR, "%s: %m", pw->pw_name);
|
||||
exit(EX_NOPERM);
|
||||
}
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (sb.st_uid != 0 || (sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
|
||||
syslog(LOG_ERR, "bad directory permissions");
|
||||
exit(EX_NOPERM);
|
||||
}
|
||||
|
||||
if (chroot(pw->pw_dir) < 0) {
|
||||
syslog(LOG_ERR, "%s: %m", pw->pw_dir);
|
||||
exit(EX_UNAVAILABLE);
|
||||
@ -492,12 +502,13 @@ icbd_restrict(void)
|
||||
}
|
||||
|
||||
chdir(ICBD_HOME);
|
||||
|
||||
#endif
|
||||
if (setuid(pw->pw_uid) < 0) {
|
||||
syslog(LOG_ERR, "%d: %m", pw->pw_uid);
|
||||
exit(EX_NOPERM);
|
||||
}
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (dodns) {
|
||||
if (pledge("stdio inet rpath dns", NULL) == -1) {
|
||||
syslog(LOG_ERR, "pledge");
|
||||
@ -509,6 +520,7 @@ icbd_restrict(void)
|
||||
exit(EX_NOPERM);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
(void)setproctitle("icbd");
|
||||
}
|
||||
|
10
logger.c
10
logger.c
@ -1,6 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Mike Belopuhov
|
||||
* Copyright (c) 2009 Michael Shalayeff
|
||||
* Copyright (c) 2014 Mike Belopuhov
|
||||
* Copyright (c) 2024 Nishi
|
||||
* Copyright (c) 2025 Izuru Yakumo
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -95,7 +97,7 @@ logger_init(void)
|
||||
ICBD_USER);
|
||||
exit(EX_NOUSER);
|
||||
}
|
||||
|
||||
#ifdef __OpenBSD
|
||||
if (chroot(pw->pw_dir) < 0) {
|
||||
syslog(LOG_ERR, "%s: %s: %m", __func__, pw->pw_dir);
|
||||
exit(EX_UNAVAILABLE);
|
||||
@ -112,11 +114,13 @@ logger_init(void)
|
||||
syslog(LOG_ERR, "%s: %d: %m", __func__, pw->pw_uid);
|
||||
exit(EX_NOPERM);
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio cpath wpath", NULL) == -1) {
|
||||
syslog(LOG_ERR, "%s: pledge", __func__);
|
||||
exit(EX_NOPERM);
|
||||
}
|
||||
#endif
|
||||
|
||||
event_init();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user