diff options
Diffstat (limited to 'src')
40 files changed, 297 insertions, 350 deletions
diff --git a/src/clock/s6-clockadd.c b/src/clock/s6-clockadd.c index 990f3ba..cd0dcbb 100644 --- a/src/clock/s6-clockadd.c +++ b/src/clock/s6-clockadd.c @@ -1,7 +1,7 @@ /* ISC license. */ #include <skalibs/sgetopt.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/allreadwrite.h> #include <skalibs/strerr2.h> #include <skalibs/tai.h> @@ -19,7 +19,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "fe:", &l) ; + int opt = subgetopt_r(argc, argv, "fe:", &l) ; if (opt == -1) break ; switch (opt) { diff --git a/src/clock/s6-sntpclock.c b/src/clock/s6-sntpclock.c index 22c6727..1044be5 100644 --- a/src/clock/s6-sntpclock.c +++ b/src/clock/s6-sntpclock.c @@ -1,17 +1,14 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> #include <unistd.h> #include <errno.h> #include <skalibs/error.h> -#include <skalibs/uint16.h> -#include <skalibs/uint32.h> #include <skalibs/uint64.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/allreadwrite.h> -#include <skalibs/bytestr.h> #include <skalibs/error.h> #include <skalibs/strerr2.h> #include <skalibs/tai.h> @@ -26,12 +23,12 @@ static unsigned int verbosity = 1 ; -int ntp_exchange (int s, ip46_t const *ip, uint16 port, tain_t *stamps, tain_t const *deadline) +int ntp_exchange (int s, ip46_t const *ip, uint16_t port, tain_t *stamps, tain_t const *deadline) { char query[48] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ; char answer[48] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ; tain_t starttime ; - uint64 ntpstamp ; + uint64_t ntpstamp ; ip46_t dummyip ; uint16_t dummyport ; ssize_t r ; @@ -54,7 +51,7 @@ int ntp_exchange (int s, ip46_t const *ip, uint16 port, tain_t *stamps, tain_t c if (r < 48) return (errno = EPROTO, 0) ; if (((answer[0] & 7) != 2) && ((answer[0] & 7) != 4)) return (errno = EPROTO, 0) ; if (!(answer[0] & 56)) return (errno = EPROTO, 0) ; - if (byte_diff(query+40, 8, answer+24)) return (errno = EPROTO, 0) ; + if (memcmp(query+40, answer+24, 8)) return (errno = EPROTO, 0) ; stamps[0] = starttime ; uint64_unpack_big(answer+32, &ntpstamp) ; tain_from_ntp(stamps+1, ntpstamp) ; @@ -100,7 +97,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "fv:r:t:h:T:e:p:", &l) ; + int opt = subgetopt_r(argc, argv, "fv:r:t:h:T:e:p:", &l) ; if (opt == -1) break ; switch (opt) { @@ -169,7 +166,7 @@ int main (int argc, char const *const *argv) unsigned int j = 0 ; for (; j < 4 ; j++) { - uint64 ntp ; + uint64_t ntp ; localtmn_t l ; char fmt[UINT_FMT] ; char fmtntp[UINT64_XFMT] ; diff --git a/src/clock/s6-taiclock.c b/src/clock/s6-taiclock.c index bece37d..8ea58c1 100644 --- a/src/clock/s6-taiclock.c +++ b/src/clock/s6-taiclock.c @@ -1,16 +1,13 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> #include <unistd.h> #include <errno.h> #include <skalibs/error.h> -#include <skalibs/uint16.h> -#include <skalibs/uint32.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/allreadwrite.h> -#include <skalibs/bytestr.h> #include <skalibs/strerr2.h> #include <skalibs/tai.h> #include <skalibs/djbtime.h> @@ -27,7 +24,7 @@ static unsigned int verbosity = 1 ; #define N 28 -int tain_exchange (int s, ip46_t const *ip, uint16 port, tain_t *serversays, tain_t const *deadline) +int tain_exchange (int s, ip46_t const *ip, uint16_t port, tain_t *serversays, tain_t const *deadline) { char query[N] = "ctai" ; char answer[N] ; @@ -42,8 +39,8 @@ int tain_exchange (int s, ip46_t const *ip, uint16 port, tain_t *serversays, tai r = socket_recvnb46_g(s, answer, N, &dummyip, &dummyport, deadline) ; if (r < 0) return 0 ; if (r < N) return (errno = EPROTO, 0) ; - if (byte_diff(answer, 4, "stai")) return (errno = EPROTO, 0) ; - if (byte_diff(query+20, N-20, answer+20)) return (errno = EPROTO, 0) ; + if (memcmp(answer, "stai", 4)) return (errno = EPROTO, 0) ; + if (memcmp(query+20, answer+20, N-20)) return (errno = EPROTO, 0) ; tain_unpack(answer+4, serversays) ; return 1 ; } @@ -72,7 +69,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "fv:r:t:h:T:e:p:", &l) ; + int opt = subgetopt_r(argc, argv, "fv:r:t:h:T:e:p:", &l) ; if (opt == -1) break ; switch (opt) { diff --git a/src/clock/s6-taiclockd.c b/src/clock/s6-taiclockd.c index 0477ec5..504c4fc 100644 --- a/src/clock/s6-taiclockd.c +++ b/src/clock/s6-taiclockd.c @@ -1,12 +1,10 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> -#include <skalibs/uint16.h> -#include <skalibs/bytestr.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> -#include <skalibs/fmtscan.h> #include <skalibs/djbunix.h> #include <skalibs/socket.h> #include <skalibs/tai.h> @@ -24,7 +22,7 @@ int main (int argc, char const *const *argv) PROG = "s6-taiclockd" ; for (;;) { - register int opt = subgetopt_r(argc, argv, "i:p:", &l) ; + int opt = subgetopt_r(argc, argv, "i:p:", &l) ; if (opt == -1) break ; switch (opt) { @@ -43,8 +41,8 @@ int main (int argc, char const *const *argv) for (;;) { char packet[256] ; - register ssize_t r = socket_recv46(s, packet, 256, &ip, &port) ; - if ((r >= 20) && !byte_diff(packet, 4, "ctai")) + ssize_t r = socket_recv46(s, packet, 256, &ip, &port) ; + if ((r >= 20) && !memcmp(packet, "ctai", 4)) { tain_t now ; packet[0] = 's' ; diff --git a/src/conn-tools/s6-getservbyname.c b/src/conn-tools/s6-getservbyname.c index a7ccc9d..0c60320 100644 --- a/src/conn-tools/s6-getservbyname.c +++ b/src/conn-tools/s6-getservbyname.c @@ -2,7 +2,7 @@ #include <stdint.h> #include <netdb.h> -#include <skalibs/uint16.h> +#include <skalibs/types.h> #include <skalibs/buffer.h> #include <skalibs/strerr2.h> diff --git a/src/conn-tools/s6-ident-client.c b/src/conn-tools/s6-ident-client.c index d4876ae..1d24904 100644 --- a/src/conn-tools/s6-ident-client.c +++ b/src/conn-tools/s6-ident-client.c @@ -2,8 +2,7 @@ #include <stdint.h> #include <errno.h> -#include <skalibs/uint16.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/buffer.h> @@ -27,7 +26,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "t:", &l) ; + int opt = subgetopt_r(argc, argv, "t:", &l) ; if (opt == -1) break ; switch (opt) { @@ -56,7 +55,7 @@ int main (int argc, char const *const *argv) { char buf[BUFFER_OUTSIZE_SMALL] ; - register int r = s6net_ident_client_g(buf, BUFFER_OUTSIZE_SMALL, &ra, rp, &la, lp, &deadline) ; + int r = s6net_ident_client_g(buf, BUFFER_OUTSIZE_SMALL, &ra, rp, &la, lp, &deadline) ; if (r < 0) strerr_diefu1sys(errno == ETIMEDOUT ? 99 : 111, "s6net_ident_client") ; else if (!r) { diff --git a/src/conn-tools/s6-tcpclient.c b/src/conn-tools/s6-tcpclient.c index 3085e06..47be4a7 100644 --- a/src/conn-tools/s6-tcpclient.c +++ b/src/conn-tools/s6-tcpclient.c @@ -1,11 +1,9 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> #include <errno.h> -#include <skalibs/uint16.h> -#include <skalibs/uint.h> -#include <skalibs/bytestr.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/fmtscan.h> #include <skalibs/strerr2.h> @@ -65,7 +63,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, OPTSTRING, &l) ; + int opt = subgetopt_r(argc, argv, OPTSTRING, &l) ; if (opt == -1) break ; switch (opt) { @@ -119,8 +117,7 @@ int main (int argc, char const *const *argv) { ip46_t ip[2][MAXIP] ; unsigned int j = 0 ; - unsigned int n[2] = { 0, 0 } ; - register unsigned int i = 0 ; + size_t n[2] = { 0, 0 } ; if (!**argv || ((**argv == '0') && !argv[0][1])) { #ifdef SKALIBS_IPV6_ENABLED @@ -136,14 +133,14 @@ int main (int argc, char const *const *argv) if (flags.ip6 && !flags.ip4) { char ip6[MAXIP << 4] ; - register unsigned int i = 0 ; + size_t i = 0 ; if (!ip6_scanlist(ip6, MAXIP, argv[0], &n[0])) usage() ; for (; i < n[0] ; i++) ip46_from_ip6(&ip[0][i], ip6 + (i << 4)) ; } else if (!flags.ip6) { char ip4[MAXIP << 2] ; - register unsigned int i = 0 ; + size_t i = 0 ; if (!ip4_scanlist(ip4, MAXIP, argv[0], &n[0])) usage() ; for (; i < n[0] ; i++) ip46_from_ip4(&ip[0][i], ip4 + (i << 2)) ; } @@ -159,7 +156,8 @@ int main (int argc, char const *const *argv) if (!ip46_scanlist(ip[0], MAXIP, argv[0], &n[0])) { genalloc ips = STRALLOC_ZERO ; - if (s6dns_resolve_aaaaa_g(&ips, argv[0], str_len(argv[0]), flags.qualif, &deadline) <= 0) + size_t i = 0 ; + if (s6dns_resolve_aaaaa_g(&ips, argv[0], strlen(argv[0]), flags.qualif, &deadline) <= 0) strerr_diefu4x(111, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ; n[0] = genalloc_len(ip46_t, &ips) ; if (n[0] >= MAXIP) n[0] = MAXIP ; @@ -172,13 +170,14 @@ int main (int argc, char const *const *argv) char ip6[MAXIP << 4] ; if (ip6_scanlist(ip6, MAXIP, argv[0], &n[0])) { - register unsigned int i = 0 ; + size_t i = 0 ; for (; i < n[0] ; i++) ip46_from_ip6(&ip[0][i], ip6 + (i << 4)) ; } else { stralloc ip6s = STRALLOC_ZERO ; - if (s6dns_resolve_aaaa_g(&ip6s, argv[0], str_len(argv[0]), flags.qualif, &deadline) <= 0) + size_t i = 0 ; + if (s6dns_resolve_aaaa_g(&ip6s, argv[0], strlen(argv[0]), flags.qualif, &deadline) <= 0) strerr_diefu4x(111, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ; n[0] = ip6s.len >> 4 ; if (n[0] >= MAXIP) n[0] = MAXIP ; @@ -192,13 +191,14 @@ int main (int argc, char const *const *argv) char ip4[MAXIP << 2] ; if (ip4_scanlist(ip4, MAXIP, argv[0], &n[0])) { - register unsigned int i = 0 ; + size_t i = 0 ; for (; i < n[0] ; i++) ip46_from_ip4(&ip[0][i], ip4 + (i << 2)) ; } else { stralloc ip4s = STRALLOC_ZERO ; - if (s6dns_resolve_a_g(&ip4s, argv[0], str_len(argv[0]), flags.qualif, &deadline) <= 0) + size_t i = 0 ; + if (s6dns_resolve_a_g(&ip4s, argv[0], strlen(argv[0]), flags.qualif, &deadline) <= 0) strerr_diefu4x(111, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ; n[0] = ip4s.len >> 2 ; if (n[0] >= MAXIP) n[0] = MAXIP ; @@ -218,7 +218,7 @@ int main (int argc, char const *const *argv) for (; j < 2 ; j++) { - unsigned int i = 0 ; + size_t i = 0 ; for (; i < n[j] ; i++) { tain_t localdeadline ; @@ -319,7 +319,7 @@ int main (int argc, char const *const *argv) else { char s[256] ; - register unsigned int len = 0 ; + unsigned int len = 0 ; if (genalloc_len(s6dns_domain_t, &data[0].ds)) len = s6dns_domain_tostring(s, 255, genalloc_s(s6dns_domain_t, &data[0].ds)) ; genalloc_free(s6dns_domain_t, &data[0].ds) ; @@ -336,7 +336,7 @@ int main (int argc, char const *const *argv) else { char s[256] ; - register unsigned int len = 0 ; + unsigned int len = 0 ; if (genalloc_len(s6dns_domain_t, &data[1].ds)) len = s6dns_domain_tostring(s, 255, genalloc_s(s6dns_domain_t, &data[1].ds)) ; genalloc_free(s6dns_domain_t, &data[1].ds) ; @@ -357,7 +357,7 @@ int main (int argc, char const *const *argv) char idbuf[S6NET_IDENT_ID_SIZE] ; if (flags.remoteinfo) { - register int r = s6net_ident_client_g(idbuf, S6NET_IDENT_ID_SIZE, &remoteip, remoteport, &flags.localip, flags.localport, &deadline) ; + ssize_t r = s6net_ident_client_g(idbuf, S6NET_IDENT_ID_SIZE, &remoteip, remoteport, &flags.localip, flags.localport, &deadline) ; if (r <= 0) { if (flags.verbosity) diff --git a/src/conn-tools/s6-tcpserver-access.c b/src/conn-tools/s6-tcpserver-access.c index 72a3d2f..e16fe08 100644 --- a/src/conn-tools/s6-tcpserver-access.c +++ b/src/conn-tools/s6-tcpserver-access.c @@ -1,12 +1,11 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> #include <unistd.h> #include <errno.h> #include <skalibs/gccattributes.h> -#include <skalibs/uint16.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/strerr2.h> #include <skalibs/sgetopt.h> #include <skalibs/buffer.h> @@ -30,22 +29,22 @@ #define X() strerr_dief1x(101, "internal inconsistency. Please submit a bug-report.") -static void logit (unsigned int pid, ip46_t const *ip, int h) +static void logit (pid_t pid, ip46_t const *ip, int h) { - char fmtpid[UINT_FMT] ; + char fmtpid[PID_FMT] ; char fmtip[IP46_FMT] ; fmtip[ip46_fmt(fmtip, ip)] = 0 ; - fmtpid[uint_fmt(fmtpid, pid)] = 0 ; + fmtpid[pid_fmt(fmtpid, pid)] = 0 ; if (h) strerr_warni5x("allow", " pid ", fmtpid, " ip ", fmtip) ; else strerr_warni5sys("deny", " pid ", fmtpid, " ip ", fmtip) ; } -static inline void log_accept (unsigned int pid, ip46_t const *ip) +static inline void log_accept (pid_t pid, ip46_t const *ip) { logit(pid, ip, 1) ; } -static inline void log_deny (unsigned int pid, ip46_t const *ip) +static inline void log_deny (pid_t pid, ip46_t const *ip) { logit(pid, ip, 0) ; } @@ -76,7 +75,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "WwDdHhRrPpv:l:B:t:i:x:", &l) ; + int opt = subgetopt_r(argc, argv, "WwDdHhRrPpv:l:B:t:i:x:", &l) ; if (opt == -1) break ; switch (opt) { @@ -94,8 +93,8 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'l' : localname = l.arg ; break ; case 'B' : { - register size_t n = str_len(l.arg) ; - if (buffer_putnoflush(buffer_1small, l.arg, n) < n) + size_t n = strlen(l.arg) ; + if (buffer_putnoflush(buffer_1small, l.arg, n) < (ssize_t)n) strerr_dief1x(100, "banner too long") ; break ; } @@ -114,16 +113,16 @@ int main (int argc, char const *const *argv, char const *const *envp) proto = env_get2(envp, "PROTO") ; if (!proto) strerr_dienotset(100, "PROTO") ; - protolen = str_len(proto) ; + protolen = strlen(proto) ; { char const *x ; char tmp[protolen + 11] ; - byte_copy(tmp, protolen, proto) ; - byte_copy(tmp + protolen, 9, "REMOTEIP") ; + memcpy(tmp, proto, protolen) ; + memcpy(tmp + protolen, "REMOTEIP", 9) ; x = env_get2(envp, tmp) ; if (!x) strerr_dienotset(100, tmp) ; if (!ip46_scan(x, &remoteip)) strerr_dieinvalid(100, tmp) ; - byte_copy(tmp + protolen + 6, 5, "PORT") ; + memcpy(tmp + protolen + 6, "PORT", 5) ; x = env_get2(envp, tmp) ; if (!x) strerr_dienotset(100, tmp) ; if (!uint160_scan(x, &remoteport)) strerr_dieinvalid(100, tmp) ; @@ -184,16 +183,16 @@ int main (int argc, char const *const *argv, char const *const *envp) if (socket_local46(0, &localip, &localport) < 0) strerr_diefu1sys(111, "socket_local") ; fmt[ip46_fmt(fmt, &localip)] = 0 ; - byte_copy(tmp, protolen, proto) ; - byte_copy(tmp + protolen, 8, "LOCALIP") ; + memcpy(tmp, proto, protolen) ; + memcpy(tmp + protolen, "LOCALIP", 8) ; if (!env_addmodif(&modifs, tmp, fmt)) dienomem() ; fmt[uint16_fmt(fmt, localport)] = 0 ; - byte_copy(tmp + protolen + 5, 5, "PORT") ; + memcpy(tmp + protolen + 5, "PORT", 5) ; if (!env_addmodif(&modifs, tmp, fmt)) dienomem() ; - byte_copy(tmp + protolen, 11, "REMOTEINFO") ; + memcpy(tmp + protolen, "REMOTEINFO", 11) ; if (flagident) { - register int r = s6net_ident_client_g(idbuf, S6NET_IDENT_ID_SIZE, &remoteip, remoteport, &localip, localport, &deadline) ; + ssize_t r = s6net_ident_client_g(idbuf, S6NET_IDENT_ID_SIZE, &remoteip, remoteport, &localip, localport, &deadline) ; if (r < 0) { if (verbosity >= 3) strerr_warnwu1sys("s6net_ident_client") ; @@ -221,10 +220,10 @@ int main (int argc, char const *const *argv, char const *const *envp) if (!flagdnslookup) { char tmp[protolen + 11] ; - byte_copy(tmp, protolen, proto) ; - byte_copy(tmp + protolen, 10, "LOCALHOST") ; + memcpy(tmp, proto, protolen) ; + memcpy(tmp + protolen, "LOCALHOST", 10) ; if (!env_addmodif(&modifs, tmp, localname)) dienomem() ; - byte_copy(tmp + protolen, 11, "REMOTEHOST") ; + memcpy(tmp + protolen, "REMOTEHOST", 11) ; if (!env_addmodif(&modifs, tmp, 0)) dienomem() ; } else @@ -236,10 +235,10 @@ int main (int argc, char const *const *argv, char const *const *envp) unsigned int remotelen = 0 ; char tcplocalhost[(protolen << 1) + 21] ; char *tcpremotehost = tcplocalhost + protolen + 10 ; - byte_copy(tcplocalhost, protolen, proto) ; - byte_copy(tcplocalhost + protolen, 10, "LOCALHOST") ; - byte_copy(tcpremotehost, protolen, proto) ; - byte_copy(tcpremotehost + protolen, 11, "REMOTEHOST") ; + memcpy(tcplocalhost, proto, protolen) ; + memcpy(tcplocalhost + protolen, "LOCALHOST", 10) ; + memcpy(tcpremotehost, proto, protolen) ; + memcpy(tcpremotehost + protolen, "REMOTEHOST", 11) ; if (!s6dns_init()) { @@ -293,7 +292,7 @@ int main (int argc, char const *const *argv, char const *const *envp) else { char s[256] ; - register unsigned int len = 0 ; + unsigned int len = 0 ; if (genalloc_len(s6dns_domain_t, &data[0].ds)) { s6dns_domain_noqualify(genalloc_s(s6dns_domain_t, &data[0].ds)) ; @@ -314,7 +313,7 @@ int main (int argc, char const *const *argv, char const *const *envp) remotebuf[remotelen] = 0 ; if (flagparanoid) { - register int r ; + int r ; data[1].ds.len = 0 ; r = ip46_is6(&remoteip) ? s6dns_resolve_aaaa_g(&data[1].ds, remotebuf, remotelen, 0, &deadline) : s6dns_resolve_a_g(&data[1].ds, remotebuf, remotelen, 0, &deadline) ; if (r <= 0) @@ -329,9 +328,9 @@ int main (int argc, char const *const *argv, char const *const *envp) } else { - register unsigned int i = 0 ; + size_t i = 0 ; for (; i < data[1].ds.len ; i += ip46_is6(&remoteip) ? 16 : 4) - if (!byte_diff(remoteip.ip, ip46_is6(&remoteip) ? 16 : 4, data[1].ds.s + i)) break ; + if (!memcmp(remoteip.ip, data[1].ds.s + i, ip46_is6(&remoteip) ? 16 : 4)) break ; if (i >= data[1].ds.len) remotelen = 0 ; } } @@ -390,10 +389,10 @@ int main (int argc, char const *const *argv, char const *const *envp) reject: if (verbosity >= 2) { - char fmtpid[UINT_FMT] ; + char fmtpid[PID_FMT] ; char fmtip[IP46_FMT] ; fmtip[ip46_fmt(fmtip, &remoteip)] = 0 ; - fmtpid[uint_fmt(fmtpid, getpid())] = 0 ; + fmtpid[pid_fmt(fmtpid, getpid())] = 0 ; strerr_dief5x(e, "reject", " pid ", fmtpid, " ip ", fmtip) ; } else return e ; diff --git a/src/conn-tools/s6-tcpserver.c b/src/conn-tools/s6-tcpserver.c index 3036ce7..3866b75 100644 --- a/src/conn-tools/s6-tcpserver.c +++ b/src/conn-tools/s6-tcpserver.c @@ -2,9 +2,7 @@ #include <sys/types.h> #include <limits.h> -#include <skalibs/uint64.h> -#include <skalibs/uint.h> -#include <skalibs/gidstuff.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/djbunix.h> @@ -21,10 +19,10 @@ int main (int argc, char const *const *argv, char const *const *envp) int flag1 = 0 ; int flagU = 0 ; int flagreuse = 1 ; - uint64 uid = 0 ; + uid_t uid = 0 ; gid_t gid = 0 ; gid_t gids[NGROUPS_MAX] ; - unsigned int gidn = (unsigned int)-1 ; + size_t gidn = (size_t)-1 ; unsigned int maxconn = 0 ; unsigned int localmaxconn = 0 ; unsigned int backlog = (unsigned int)-1 ; @@ -34,7 +32,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "qQvDd1U46c:C:b:u:g:G:", &l) ; + int opt = subgetopt_r(argc, argv, "qQvDd1U46c:C:b:u:g:G:", &l) ; if (opt == -1) break ; switch (opt) { @@ -48,11 +46,11 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'c' : if (!uint0_scan(l.arg, &maxconn)) dieusage() ; if (!maxconn) maxconn = 1 ; break ; case 'C' : if (!uint0_scan(l.arg, &localmaxconn)) dieusage() ; if (!localmaxconn) localmaxconn = 1 ; break ; case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ; - case 'u' : if (!uint640_scan(l.arg, &uid)) dieusage() ; break ; + case 'u' : if (!uid0_scan(l.arg, &uid)) dieusage() ; break ; case 'g' : if (!gid0_scan(l.arg, &gid)) dieusage() ; break ; case 'G' : if (!gid_scanlist(gids, NGROUPS_MAX, l.arg, &gidn) && *l.arg) dieusage() ; break ; case '1' : flag1 = 1 ; break ; - case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (unsigned int)-1 ; break ; + case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (size_t)-1 ; break ; default : dieusage() ; } } @@ -70,7 +68,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { size_t pos = 0 ; unsigned int m = 0 ; - char fmt[UINT_FMT * 3 + UINT64_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; + char fmt[UINT_FMT * 3 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; char const *newargv[23 + argc] ; newargv[m++] = what == 6 ? S6_NETWORKING_BINPREFIX "s6-tcpserver6-socketbinder" : S6_NETWORKING_BINPREFIX "s6-tcpserver4-socketbinder" ; if (!flagreuse) newargv[m++] = "-D" ; @@ -84,7 +82,7 @@ int main (int argc, char const *const *argv, char const *const *envp) newargv[m++] = "--" ; newargv[m++] = *argv++ ; newargv[m++] = *argv++ ; - if (flagU || uid || gid || gidn != (unsigned int)-1) + if (flagU || uid || gid || gidn != (size_t)-1) { newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ; if (flagU) newargv[m++] = "-Uz" ; @@ -92,7 +90,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { newargv[m++] = "-u" ; newargv[m++] = fmt + pos ; - pos += uint64_fmt(fmt + pos, uid) ; + pos += uid_fmt(fmt + pos, uid) ; fmt[pos++] = 0 ; } if (gid) @@ -102,7 +100,7 @@ int main (int argc, char const *const *argv, char const *const *envp) pos += gid_fmt(fmt + pos, gid) ; fmt[pos++] = 0 ; } - if (gidn != (unsigned int)-1) + if (gidn != (size_t)-1) { newargv[m++] = "-G" ; newargv[m++] = fmt + pos ; diff --git a/src/conn-tools/s6-tcpserver4-socketbinder.c b/src/conn-tools/s6-tcpserver4-socketbinder.c index a15e5f1..cc97486 100644 --- a/src/conn-tools/s6-tcpserver4-socketbinder.c +++ b/src/conn-tools/s6-tcpserver4-socketbinder.c @@ -1,11 +1,9 @@ /* ISC license. */ -#include <sys/types.h> #include <stdint.h> #include <unistd.h> #include <sys/socket.h> -#include <skalibs/uint16.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/fmtscan.h> #include <skalibs/strerr2.h> @@ -27,7 +25,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ; + int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ; if (opt == -1) break ; switch (opt) { diff --git a/src/conn-tools/s6-tcpserver4.c b/src/conn-tools/s6-tcpserver4.c index f0836d3..6860871 100644 --- a/src/conn-tools/s6-tcpserver4.c +++ b/src/conn-tools/s6-tcpserver4.c @@ -2,9 +2,7 @@ #include <sys/types.h> #include <limits.h> -#include <skalibs/uint64.h> -#include <skalibs/uint.h> -#include <skalibs/gidstuff.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/djbunix.h> @@ -20,10 +18,10 @@ int main (int argc, char const *const *argv, char const *const *envp) int flag1 = 0 ; int flagU = 0 ; int flagreuse = 1 ; - uint64 uid = 0 ; + uid_t uid = 0 ; gid_t gid = 0 ; gid_t gids[NGROUPS_MAX] ; - unsigned int gidn = (unsigned int)-1 ; + size_t gidn = (size_t)-1 ; unsigned int maxconn = 0 ; unsigned int localmaxconn = 0 ; unsigned int backlog = (unsigned int)-1 ; @@ -32,7 +30,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "Dd1Uv:c:C:b:u:g:G:", &l) ; + int opt = subgetopt_r(argc, argv, "Dd1Uv:c:C:b:u:g:G:", &l) ; if (opt == -1) break ; switch (opt) { @@ -42,11 +40,11 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'c' : if (!uint0_scan(l.arg, &maxconn)) dieusage() ; if (!maxconn) maxconn = 1 ; break ; case 'C' : if (!uint0_scan(l.arg, &localmaxconn)) dieusage() ; if (!localmaxconn) localmaxconn = 1 ; break ; case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ; - case 'u' : if (!uint640_scan(l.arg, &uid)) dieusage() ; break ; + case 'u' : if (!uid0_scan(l.arg, &uid)) dieusage() ; break ; case 'g' : if (!gid0_scan(l.arg, &gid)) dieusage() ; break ; case 'G' : if (!gid_scanlist(gids, NGROUPS_MAX, l.arg, &gidn) && *l.arg) dieusage() ; break ; case '1' : flag1 = 1 ; break ; - case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (unsigned int)-1 ; break ; + case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (size_t)-1 ; break ; default : dieusage() ; } } @@ -57,7 +55,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { size_t pos = 0 ; unsigned int m = 0 ; - char fmt[UINT_FMT * 4 + UINT64_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; + char fmt[UINT_FMT * 4 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; char const *newargv[24 + argc] ; newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver4-socketbinder" ; if (!flagreuse) newargv[m++] = "-D" ; @@ -72,7 +70,7 @@ int main (int argc, char const *const *argv, char const *const *envp) newargv[m++] = "--" ; newargv[m++] = *argv++ ; newargv[m++] = *argv++ ; - if (flagU || uid || gid || gidn != (unsigned int)-1) + if (flagU || uid || gid || gidn != (size_t)-1) { newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ; if (flagU) newargv[m++] = "-Uz" ; @@ -80,7 +78,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { newargv[m++] = "-u" ; newargv[m++] = fmt + pos ; - pos += uint64_fmt(fmt + pos, uid) ; + pos += uid_fmt(fmt + pos, uid) ; fmt[pos++] = 0 ; } if (gid) @@ -90,7 +88,7 @@ int main (int argc, char const *const *argv, char const *const *envp) pos += gid_fmt(fmt + pos, gid) ; fmt[pos++] = 0 ; } - if (gidn != (unsigned int)-1) + if (gidn != (size_t)-1) { newargv[m++] = "-G" ; newargv[m++] = fmt + pos ; diff --git a/src/conn-tools/s6-tcpserver4d.c b/src/conn-tools/s6-tcpserver4d.c index e176ee5..7579ea2 100644 --- a/src/conn-tools/s6-tcpserver4d.c +++ b/src/conn-tools/s6-tcpserver4d.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> #include <sys/stat.h> #include <sys/wait.h> @@ -10,10 +10,7 @@ #include <signal.h> #include <skalibs/gccattributes.h> #include <skalibs/allreadwrite.h> -#include <skalibs/uint16.h> -#include <skalibs/uint32.h> -#include <skalibs/uint.h> -#include <skalibs/bytestr.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/fmtscan.h> @@ -29,11 +26,18 @@ #define USAGE "s6-tcpserver4d [ -v verbosity ] [ -1 ] [ -c maxconn ] [ -C localmaxconn ] prog..." +typedef struct pidip_s pidip_t, *pidip_t_ref ; +struct pidip_s +{ + pid_t left ; + uint32_t right ; +} ; + static unsigned int maxconn = 40 ; static unsigned int localmaxconn = 40 ; static unsigned int verbosity = 1 ; static int cont = 1 ; -static diuint32 *pidip = 0 ; +static pidip_t *pidip = 0 ; static unsigned int numconn = 0 ; static diuint32 *ipnum = 0 ; static unsigned int iplen = 0 ; @@ -57,22 +61,18 @@ static inline void X (void) /* Lookup primitives */ -static unsigned int lookup_diuint32 (diuint32 const *, unsigned int, unsigned int) gccattr_pure ; -static unsigned int lookup_diuint32 (diuint32 const *tab, unsigned int tablen, unsigned int key) +static inline unsigned int lookup_pid (pid_t pid) { - register unsigned int i = 0 ; - for (; i < tablen ; i++) if (key == tab[i].left) break ; + unsigned int i = 0 ; + for (; i < numconn ; i++) if (pid == pidip[i].left) break ; return i ; } -static inline unsigned int lookup_pid (uint32 pid) -{ - return lookup_diuint32(pidip, numconn, pid) ; -} - -static inline unsigned int lookup_ip (uint32 ip) +static inline unsigned int lookup_ip (uint32_t ip) { - return lookup_diuint32(ipnum, iplen, ip) ; + unsigned int i = 0 ; + for (; i < iplen ; i++) if (ip == ipnum[i].left) break ; + return i ; } @@ -106,27 +106,27 @@ static void log_deny (uint32_t ip, uint16_t port, unsigned int num) strerr_warni7sys("deny ", fmtip, ":", fmtport, " count ", fmtnum, fmtlocalmaxconn) ; } -static void log_accept (uint32_t pid, uint32_t ip, uint16_t port, unsigned int num) +static void log_accept (pid_t pid, uint32_t ip, uint16_t port, unsigned int num) { char fmtipport[IP4_FMT + UINT16_FMT + 1] ; - char fmtpid[UINT32_FMT] ; + char fmtpid[PID_FMT] ; char fmtnum[UINT_FMT] ; - register size_t n ; + size_t n ; n = ip4_fmtu32(fmtipport, ip) ; fmtipport[n++] = ':' ; n += uint16_fmt(fmtipport + n, port) ; fmtipport[n] = 0 ; fmtnum[uint_fmt(fmtnum, num)] = 0 ; - fmtpid[uint32_fmt(fmtpid, pid)] = 0 ; + fmtpid[pid_fmt(fmtpid, pid)] = 0 ; strerr_warni7x("allow ", fmtipport, " pid ", fmtpid, " count ", fmtnum, fmtlocalmaxconn) ; } -static void log_close (uint32_t pid, uint32_t ip, int w) +static void log_close (pid_t pid, uint32_t ip, int w) { - char fmtpid[UINT32_FMT] ; + char fmtpid[PID_FMT] ; char fmtip[IP4_FMT] = "?" ; char fmtw[UINT_FMT] ; - fmtpid[uint32_fmt(fmtpid, pid)] = 0 ; + fmtpid[pid_fmt(fmtpid, pid)] = 0 ; fmtip[ip4_fmtu32(fmtip, ip)] = 0 ; fmtw[uint_fmt(fmtw, WIFSIGNALED(w) ? WTERMSIG(w) : WEXITSTATUS(w))] = 0 ; strerr_warni6x("end pid ", fmtpid, " ip ", fmtip, WIFSIGNALED(w) ? " signal " : " exitcode ", fmtw) ; @@ -137,7 +137,7 @@ static void log_close (uint32_t pid, uint32_t ip, int w) static void killthem (int sig) { - register unsigned int i = 0 ; + unsigned int i = 0 ; for (; i < numconn ; i++) kill(pidip[i].left, sig) ; } @@ -147,7 +147,7 @@ static void wait_children (void) { unsigned int i ; int w ; - register pid_t pid = wait_nohang(&w) ; + pid_t pid = wait_nohang(&w) ; if (pid < 0) if (errno != ECHILD) strerr_diefu1sys(111, "wait_nohang") ; else break ; @@ -156,7 +156,7 @@ static void wait_children (void) if (i < numconn) /* it's one of ours ! */ { uint32_t ip = pidip[i].right ; - register unsigned int j = lookup_ip(ip) ; + unsigned int j = lookup_ip(ip) ; if (j >= iplen) X() ; if (!--ipnum[j].right) ipnum[j] = ipnum[--iplen] ; pidip[i] = pidip[--numconn] ; @@ -223,11 +223,11 @@ static void run_child (int s, uint32_t ip, uint16_t port, unsigned int num, char PROG = "s6-tcpserver (child)" ; if ((fd_move(0, s) < 0) || (fd_copy(1, 0) < 0)) strerr_diefu1sys(111, "move fds") ; - byte_copy(fmt+n, 22, "PROTO=TCP\0TCPREMOTEIP=") ; n += 22 ; + memcpy(fmt+n, "PROTO=TCP\0TCPREMOTEIP=", 22) ; n += 22 ; n += ip4_fmtu32(fmt+n, ip) ; fmt[n++] = 0 ; - byte_copy(fmt+n, 14, "TCPREMOTEPORT=") ; n += 14 ; + memcpy(fmt+n, "TCPREMOTEPORT=", 14) ; n += 14 ; n += uint16_fmt(fmt+n, port) ; fmt[n++] = 0 ; - byte_copy(fmt+n, 11, "TCPCONNNUM=") ; n += 11 ; + memcpy(fmt+n, "TCPCONNNUM=", 11) ; n += 11 ; n += uint_fmt(fmt+n, num) ; fmt[n++] = 0 ; pathexec_r(argv, envp, env_len(envp), fmt, n) ; strerr_dieexec(111, argv[0]) ; @@ -237,7 +237,7 @@ static void new_connection (int s, uint32_t ip, uint16_t port, char const *const { unsigned int i = lookup_ip(ip) ; unsigned int num = (i < iplen) ? ipnum[i].right : 0 ; - register pid_t pid ; + pid_t pid ; if (num >= localmaxconn) { log_deny(ip, port, num) ; @@ -261,11 +261,11 @@ static void new_connection (int s, uint32_t ip, uint16_t port, char const *const ipnum[iplen].left = ip ; ipnum[iplen++].right = 1 ; } - pidip[numconn].left = (uint32_t)pid ; + pidip[numconn].left = pid ; pidip[numconn++].right = ip ; if (verbosity >= 2) { - log_accept((uint32_t)pid, ip, port, ipnum[i].right) ; + log_accept(pid, ip, port, ipnum[i].right) ; log_status() ; } } @@ -282,7 +282,7 @@ int main (int argc, char const *const *argv, char const *const *envp) int flag1 = 0 ; for (;;) { - register int opt = subgetopt_r(argc, argv, "1c:C:v:", &l) ; + int opt = subgetopt_r(argc, argv, "1c:C:v:", &l) ; if (opt == -1) break ; switch (opt) { @@ -339,8 +339,9 @@ int main (int argc, char const *const *argv, char const *const *envp) } { - diuint32 inyostack[maxconn<<1] ; - pidip = inyostack ; ipnum = inyostack + maxconn ; + pidip_t pidip_inyostack[maxconn] ; + diuint32 ipnum_inyostack[maxconn] ; + pidip = pidip_inyostack ; ipnum = ipnum_inyostack ; while (cont) { if (iopause_g(x, 1 + (numconn < maxconn), 0) < 0) @@ -355,7 +356,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { char packedip[4] ; uint16_t port ; - register int fd = socket_accept4(x[1].fd, packedip, &port) ; + int fd = socket_accept4(x[1].fd, packedip, &port) ; if (fd < 0) { if (verbosity) strerr_warnwu1sys("accept") ; diff --git a/src/conn-tools/s6-tcpserver6-socketbinder.c b/src/conn-tools/s6-tcpserver6-socketbinder.c index e6c7fd8..4fc3ab4 100644 --- a/src/conn-tools/s6-tcpserver6-socketbinder.c +++ b/src/conn-tools/s6-tcpserver6-socketbinder.c @@ -1,10 +1,9 @@ /* ISC license. */ -#include <sys/types.h> +#include <stdint.h> #include <unistd.h> #include <sys/socket.h> -#include <skalibs/uint16.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/fmtscan.h> #include <skalibs/strerr2.h> @@ -20,13 +19,13 @@ int main (int argc, char const *const *argv, char const *const *envp) int flagreuse = 1 ; int flagudp = 0 ; char ip[16] ; - uint16 port ; + uint16_t port ; PROG = "s6-tcpserver6-socketbinder" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ; + int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ; if (opt == -1) break ; switch (opt) { diff --git a/src/conn-tools/s6-tcpserver6.c b/src/conn-tools/s6-tcpserver6.c index d48efe1..8648e8e 100644 --- a/src/conn-tools/s6-tcpserver6.c +++ b/src/conn-tools/s6-tcpserver6.c @@ -2,9 +2,7 @@ #include <sys/types.h> #include <limits.h> -#include <skalibs/uint64.h> -#include <skalibs/uint.h> -#include <skalibs/gidstuff.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/djbunix.h> @@ -20,10 +18,10 @@ int main (int argc, char const *const *argv, char const *const *envp) int flag1 = 0 ; int flagU = 0 ; int flagreuse = 1 ; - uint64 uid = 0 ; + uid_t uid = 0 ; gid_t gid = 0 ; gid_t gids[NGROUPS_MAX] ; - unsigned int gidn = (unsigned int)-1 ; + size_t gidn = (size_t)-1 ; unsigned int maxconn = 0 ; unsigned int localmaxconn = 0 ; unsigned int backlog = (unsigned int)-1 ; @@ -32,7 +30,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "Dd1Uv:c:C:b:u:g:G:", &l) ; + int opt = subgetopt_r(argc, argv, "Dd1Uv:c:C:b:u:g:G:", &l) ; if (opt == -1) break ; switch (opt) { @@ -42,11 +40,11 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'c' : if (!uint0_scan(l.arg, &maxconn)) dieusage() ; if (!maxconn) maxconn = 1 ; break ; case 'C' : if (!uint0_scan(l.arg, &localmaxconn)) dieusage() ; if (!localmaxconn) localmaxconn = 1 ; break ; case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ; - case 'u' : if (!uint640_scan(l.arg, &uid)) dieusage() ; break ; + case 'u' : if (!uid0_scan(l.arg, &uid)) dieusage() ; break ; case 'g' : if (!gid0_scan(l.arg, &gid)) dieusage() ; break ; case 'G' : if (!gid_scanlist(gids, NGROUPS_MAX, l.arg, &gidn) && *l.arg) dieusage() ; break ; case '1' : flag1 = 1 ; break ; - case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (unsigned int)-1 ; break ; + case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (size_t)-1 ; break ; default : dieusage() ; } } @@ -57,7 +55,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { size_t pos = 0 ; unsigned int m = 0 ; - char fmt[UINT_FMT * 4 + UINT64_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; + char fmt[UINT_FMT * 4 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; char const *newargv[24 + argc] ; newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver6-socketbinder" ; if (!flagreuse) newargv[m++] = "-D" ; @@ -72,7 +70,7 @@ int main (int argc, char const *const *argv, char const *const *envp) newargv[m++] = "--" ; newargv[m++] = *argv++ ; newargv[m++] = *argv++ ; - if (flagU || uid || gid || gidn != (unsigned int)-1) + if (flagU || uid || gid || gidn != (size_t)-1) { newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ; if (flagU) newargv[m++] = "-Uz" ; @@ -80,7 +78,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { newargv[m++] = "-u" ; newargv[m++] = fmt + pos ; - pos += uint64_fmt(fmt + pos, uid) ; + pos += uid_fmt(fmt + pos, uid) ; fmt[pos++] = 0 ; } if (gid) @@ -90,7 +88,7 @@ int main (int argc, char const *const *argv, char const *const *envp) pos += gid_fmt(fmt + pos, gid) ; fmt[pos++] = 0 ; } - if (gidn != (unsigned int)-1) + if (gidn != (size_t)-1) { newargv[m++] = "-G" ; newargv[m++] = fmt + pos ; diff --git a/src/conn-tools/s6-tcpserver6d.c b/src/conn-tools/s6-tcpserver6d.c index 5079d2e..ec45322 100644 --- a/src/conn-tools/s6-tcpserver6d.c +++ b/src/conn-tools/s6-tcpserver6d.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> #include <sys/stat.h> #include <sys/wait.h> @@ -10,9 +10,7 @@ #include <signal.h> #include <skalibs/gccattributes.h> #include <skalibs/allreadwrite.h> -#include <skalibs/uint16.h> -#include <skalibs/uint.h> -#include <skalibs/bytestr.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/fmtscan.h> @@ -27,21 +25,27 @@ #define USAGE "s6-tcpserver6d [ -v verbosity ] [ -1 ] [ -c maxconn ] [ -C localmaxconn ] prog..." +typedef struct pidip_s pidip_t, *pidip_t_ref ; +struct pidip_s +{ + pid_t pid ; + char ip[16] ; +} ; + typedef struct ipnum_s ipnum_t, *ipnum_t_ref ; struct ipnum_s { char ip[16] ; unsigned int num ; } ; -#define IPNUM_ZERO { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 0 } static unsigned int maxconn = 40 ; static unsigned int localmaxconn = 40 ; static unsigned int verbosity = 1 ; static int cont = 1 ; -static ipnum_t_ref pidip = 0 ; +static pidip_t *pidip = 0 ; static unsigned int numconn = 0 ; -static ipnum_t_ref ipnum = 0 ; +static ipnum_t *ipnum = 0 ; static unsigned int iplen = 0 ; static char fmtmaxconn[UINT_FMT+1] = "/" ; @@ -63,17 +67,17 @@ static inline void X (void) /* Lookup primitives */ -static unsigned int lookup_pid (unsigned int pid) +static inline unsigned int lookup_pid (pid_t pid) { - register unsigned int i = 0 ; - for (; i < numconn ; i++) if (pid == pidip[i].num) break ; + unsigned int i = 0 ; + for (; i < numconn ; i++) if (pid == pidip[i].pid) break ; return i ; } -static unsigned int lookup_ip (char const *ip) +static inline unsigned int lookup_ip (char const *ip) { - register unsigned int i = 0 ; - for (; i < iplen ; i++) if (!byte_diff(ip, 16, ipnum[i].ip)) break ; + unsigned int i = 0 ; + for (; i < iplen ; i++) if (!memcmp(ip, ipnum[i].ip, 16)) break ; return i ; } @@ -108,27 +112,27 @@ static void log_deny (char const *ip, uint16_t port, unsigned int num) strerr_warni7sys("deny ", fmtip, " port ", fmtport, " count ", fmtnum, fmtlocalmaxconn) ; } -static void log_accept (unsigned int pid, char const *ip, uint16_t port, unsigned int num) +static void log_accept (pid_t pid, char const *ip, uint16_t port, unsigned int num) { char fmtipport[IP6_FMT + UINT16_FMT + 6] ; - char fmtpid[UINT_FMT] ; + char fmtpid[PID_FMT] ; char fmtnum[UINT_FMT] ; - register size_t n ; + size_t n ; n = ip6_fmt(fmtipport, ip) ; - byte_copy(fmtipport + n, 6, " port ") ; n += 6 ; + memcpy(fmtipport + n, " port ", 6) ; n += 6 ; n += uint16_fmt(fmtipport + n, port) ; fmtipport[n] = 0 ; fmtnum[uint_fmt(fmtnum, num)] = 0 ; - fmtpid[uint_fmt(fmtpid, pid)] = 0 ; + fmtpid[pid_fmt(fmtpid, pid)] = 0 ; strerr_warni7x("allow ", fmtipport, " pid ", fmtpid, " count ", fmtnum, fmtlocalmaxconn) ; } -static void log_close (unsigned int pid, char const *ip, int w) +static void log_close (pid_t pid, char const *ip, int w) { - char fmtpid[UINT_FMT] ; + char fmtpid[PID_FMT] ; char fmtip[IP6_FMT] = "?" ; char fmtw[UINT_FMT] ; - fmtpid[uint_fmt(fmtpid, pid)] = 0 ; + fmtpid[pid_fmt(fmtpid, pid)] = 0 ; fmtip[ip6_fmt(fmtip, ip)] = 0 ; fmtw[uint_fmt(fmtw, WIFSIGNALED(w) ? WTERMSIG(w) : WEXITSTATUS(w))] = 0 ; strerr_warni6x("end pid ", fmtpid, " ip ", fmtip, WIFSIGNALED(w) ? " signal " : " exitcode ", fmtw) ; @@ -139,8 +143,8 @@ static void log_close (unsigned int pid, char const *ip, int w) static void killthem (int sig) { - register unsigned int i = 0 ; - for (; i < numconn ; i++) kill(pidip[i].num, sig) ; + unsigned int i = 0 ; + for (; i < numconn ; i++) kill(pidip[i].pid, sig) ; } static void wait_children (void) @@ -149,7 +153,7 @@ static void wait_children (void) { unsigned int i ; int w ; - register pid_t pid = wait_nohang(&w) ; + pid_t pid = wait_nohang(&w) ; if (pid < 0) if (errno != ECHILD) strerr_diefu1sys(111, "wait_nohang") ; else break ; @@ -157,7 +161,7 @@ static void wait_children (void) i = lookup_pid(pid) ; if (i < numconn) /* it's one of ours ! */ { - register unsigned int j = lookup_ip(pidip[i].ip) ; + unsigned int j = lookup_ip(pidip[i].ip) ; if (j >= iplen) X() ; if (!--ipnum[j].num) ipnum[j] = ipnum[--iplen] ; --numconn ; @@ -225,11 +229,11 @@ static void run_child (int s, char const *ip, uint16_t port, unsigned int num, c PROG = "s6-tcpserver6 (child)" ; if ((fd_move(0, s) < 0) || (fd_copy(1, 0) < 0)) strerr_diefu1sys(111, "move fds") ; - byte_copy(fmt+n, 24, "PROTO=TCP\0TCPREMOTEIP=") ; n += 22 ; + memcpy(fmt+n, "PROTO=TCP\0TCPREMOTEIP=", 24) ; n += 22 ; n += ip6_fmt(fmt+n, ip) ; fmt[n++] = 0 ; - byte_copy(fmt+n, 14, "TCPREMOTEPORT=") ; n += 14 ; + memcpy(fmt+n, "TCPREMOTEPORT=", 14) ; n += 14 ; n += uint16_fmt(fmt+n, port) ; fmt[n++] = 0 ; - byte_copy(fmt+n, 11, "TCPCONNNUM=") ; n += 11 ; + memcpy(fmt+n, "TCPCONNNUM=", 11) ; n += 11 ; n += uint_fmt(fmt+n, num) ; fmt[n++] = 0 ; pathexec_r(argv, envp, env_len(envp), fmt, n) ; strerr_dieexec(111, argv[0]) ; @@ -239,7 +243,7 @@ static void new_connection (int s, char const *ip, uint16_t port, char const *co { unsigned int i = lookup_ip(ip) ; unsigned int num = (i < iplen) ? ipnum[i].num : 0 ; - register pid_t pid ; + pid_t pid ; if (num >= localmaxconn) { log_deny(ip, port, num) ; @@ -260,11 +264,11 @@ static void new_connection (int s, char const *ip, uint16_t port, char const *co if (i < iplen) ipnum[i].num = num + 1 ; else { - byte_copy(ipnum[iplen].ip, 16, ip) ; + memcpy(ipnum[iplen].ip, ip, 16) ; ipnum[iplen++].num = 1 ; } - pidip[numconn].num = pid ; - byte_copy(pidip[numconn++].ip, 16, ip) ; + pidip[numconn].pid = pid ; + memcpy(pidip[numconn++].ip, ip, 16) ; if (verbosity >= 2) { log_accept(pid, ip, port, ipnum[i].num) ; @@ -282,7 +286,7 @@ int main (int argc, char const *const *argv, char const *const *envp) int flag1 = 0 ; for (;;) { - register int opt = subgetopt_r(argc, argv, "1c:C:v:", &l) ; + int opt = subgetopt_r(argc, argv, "1c:C:v:", &l) ; if (opt == -1) break ; switch (opt) { @@ -339,8 +343,10 @@ int main (int argc, char const *const *argv, char const *const *envp) } { - ipnum_t inyostack[maxconn<<1] ; - pidip = inyostack ; ipnum = inyostack + maxconn ; + pidip_t pidip_inyostack[maxconn] ; + ipnum_t ipnum_inyostack[maxconn] ; + pidip = pidip_inyostack ; ipnum = ipnum_inyostack ; + while (cont) { if (iopause_g(x, 1 + (numconn < maxconn), 0) < 0) @@ -355,7 +361,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { char ip[16] ; uint16_t port ; - register int fd = socket_accept6(x[1].fd, ip, &port) ; + int fd = socket_accept6(x[1].fd, ip, &port) ; if (fd < 0) { if (verbosity) strerr_warnwu1sys("accept") ; diff --git a/src/conn-tools/s6-tlsc.c b/src/conn-tools/s6-tlsc.c index 3e355f1..fb7272f 100644 --- a/src/conn-tools/s6-tlsc.c +++ b/src/conn-tools/s6-tlsc.c @@ -3,9 +3,7 @@ #include <sys/types.h> #include <stdint.h> #include <errno.h> -#include <skalibs/uint64.h> -#include <skalibs/uint.h> -#include <skalibs/gidstuff.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/tai.h> @@ -52,7 +50,7 @@ int main (int argc, char const *const *argv, char const *const *envp) unsigned int t = 0 ; for (;;) { - register int opt = subgetopt_r(argc, argv, "SsYyv:K:k:Zz6:7:", &l) ; + int opt = subgetopt_r(argc, argv, "SsYyv:K:k:Zz6:7:", &l) ; if (opt == -1) break ; switch (opt) { @@ -90,17 +88,9 @@ int main (int argc, char const *const *argv, char const *const *envp) if (!getuid()) { char const *x = env_get2(envp, "TLS_UID") ; - if (x) - { - uint64 u ; - if (!uint640_scan(x, &u)) strerr_dieinvalid(100, "TLS_UID") ; - uid = (uid_t)u ; - } + if (x && !uid0_scan(x, &uid)) strerr_dieinvalid(100, "TLS_UID") ; x = env_get2(envp, "TLS_GID") ; - if (x) - { - if (!gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ; - } + if (x && !gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ; } return s6tlsc(argv, envp, &tto, preoptions, options, uid, gid, verbosity, servername, fds) ; diff --git a/src/conn-tools/s6-tlsclient.c b/src/conn-tools/s6-tlsclient.c index eb5311d..5bcc7e7 100644 --- a/src/conn-tools/s6-tlsclient.c +++ b/src/conn-tools/s6-tlsclient.c @@ -1,10 +1,8 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> -#include <skalibs/uint16.h> -#include <skalibs/uint.h> -#include <skalibs/bytestr.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/djbunix.h> @@ -72,7 +70,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "qQv46DdHhRrnNt:l:T:i:p:SsYyK:k:Zz", &l) ; + int opt = subgetopt_r(argc, argv, "qQv46DdHhRrnNt:l:T:i:p:SsYyK:k:Zz", &l) ; if (opt == -1) break ; switch (opt) { @@ -93,7 +91,7 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'l' : o.localname = l.arg ; break ; case 'T' : { - unsigned int n = uint_scan(l.arg, &o.ximeout) ; + size_t n = uint_scan(l.arg, &o.ximeout) ; if (!n) dieusage() ; o.doxy = 1 ; if (!l.arg[n]) @@ -163,7 +161,7 @@ int main (int argc, char const *const *argv, char const *const *envp) pos += uint_fmt(fmt + pos, o.yimeout) ; fmt[pos++] = 0 ; } - if (byte_diff(o.localip.ip, 16, IP6_ANY)) + if (memcmp(o.localip.ip, IP6_ANY, 16)) { newargv[m++] = "-i" ; newargv[m++] = fmt + pos ; diff --git a/src/conn-tools/s6-tlsd.c b/src/conn-tools/s6-tlsd.c index da90179..d76b423 100644 --- a/src/conn-tools/s6-tlsd.c +++ b/src/conn-tools/s6-tlsd.c @@ -2,9 +2,7 @@ #include <sys/types.h> #include <stdint.h> -#include <skalibs/uint64.h> -#include <skalibs/uint.h> -#include <skalibs/gidstuff.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/tai.h> @@ -49,7 +47,7 @@ int main (int argc, char const *const *argv, char const *const *envp) unsigned int t = 0 ; for (;;) { - register int opt = subgetopt_r(argc, argv, "SsYyv:K:Zz", &l) ; + int opt = subgetopt_r(argc, argv, "SsYyv:K:Zz", &l) ; if (opt == -1) break ; switch (opt) { @@ -72,17 +70,9 @@ int main (int argc, char const *const *argv, char const *const *envp) if (!getuid()) { char const *x = env_get2(envp, "TLS_UID") ; - if (x) - { - uint64 u ; - if (!uint640_scan(x, &u)) strerr_dieinvalid(100, "TLS_UID") ; - uid = (uid_t)u ; - } + if (x && !uid0_scan(x, &uid)) strerr_dieinvalid(100, "TLS_UID") ; x = env_get2(envp, "TLS_GID") ; - if (x) - { - if (!gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ; - } + if (x && !gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ; } return s6tlsd(argv, envp, &tto, preoptions, options, uid, gid, verbosity) ; diff --git a/src/conn-tools/s6-tlsserver.c b/src/conn-tools/s6-tlsserver.c index 82f857a..d6c84f5 100644 --- a/src/conn-tools/s6-tlsserver.c +++ b/src/conn-tools/s6-tlsserver.c @@ -2,9 +2,7 @@ #include <sys/types.h> #include <limits.h> -#include <skalibs/uint64.h> -#include <skalibs/uint.h> -#include <skalibs/gidstuff.h> +#include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/djbunix.h> @@ -21,16 +19,16 @@ typedef struct options_s options_t, *options_t_ref ; struct options_s { - uint64 uid ; char const *localname ; char const *banner ; char const *rules ; gid_t gids[NGROUPS_MAX] ; + size_t gidn ; + uid_t uid ; gid_t gid ; unsigned int maxconn ; unsigned int localmaxconn ; unsigned int backlog ; - unsigned int gidn ; unsigned int timeout ; unsigned int kimeout ; unsigned int verbosity : 2 ; @@ -52,15 +50,15 @@ struct options_s #define OPTIONS_ZERO \ { \ - .uid = 0, \ .localname = 0, \ .banner = 0, \ .rules = 0, \ - .maxconn = 0, \ - .localmaxconn = 0, \ .backlog = (unsigned int)-1, \ - .gidn = (unsigned int)-1, \ + .gidn = (size_t)-1, \ + .uid = 0, \ .gid = 0, \ + .maxconn = 0, \ + .localmaxconn = 0, \ .timeout = 0, \ .kimeout = 0, \ .verbosity = 1, \ @@ -88,7 +86,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "qQv461c:C:b:G:g:u:UWwDdHhRrPpl:B:t:i:x:SsYyK:Zz", &l) ; + int opt = subgetopt_r(argc, argv, "qQv461c:C:b:G:g:u:UWwDdHhRrPpl:B:t:i:x:SsYyK:Zz", &l) ; if (opt == -1) break ; switch (opt) { @@ -102,9 +100,9 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'C' : if (!uint0_scan(l.arg, &o.localmaxconn)) dieusage() ; if (!o.localmaxconn) o.localmaxconn = 1 ; break ; case 'b' : if (!uint0_scan(l.arg, &o.backlog)) dieusage() ; break ; case 'G' : if (!gid_scanlist(o.gids, NGROUPS_MAX, l.arg, &o.gidn) && *l.arg) dieusage() ; o.doapply = 1 ; break ; - case 'g' : if (!uint0_scan(l.arg, &o.gid)) dieusage() ; o.doapply = 1 ; break ; - case 'u' : if (!uint0_scan(l.arg, &o.uid)) dieusage() ; o.doapply = 1 ; break ; - case 'U' : o.flagU = 1 ; o.uid = 0 ; o.gid = 0 ; o.gidn = (unsigned int)-1 ; o.doapply = 1 ; break ; + case 'g' : if (!gid0_scan(l.arg, &o.gid)) dieusage() ; o.doapply = 1 ; break ; + case 'u' : if (!uid0_scan(l.arg, &o.uid)) dieusage() ; o.doapply = 1 ; break ; + case 'U' : o.flagU = 1 ; o.uid = 0 ; o.gid = 0 ; o.gidn = (size_t)-1 ; o.doapply = 1 ; break ; case 'W' : o.flagw = 0 ; break ; case 'w' : o.flagw = 1 ; break ; case 'D' : o.flagD = 1 ; o.doaccess = 1 ; break ; @@ -137,7 +135,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { size_t pos = 0 ; unsigned int m = 0 ; - char fmt[UINT_FMT * 5 + GID_FMT * (NGROUPS_MAX + 1) + UINT64_FMT] ; + char fmt[UINT_FMT * 5 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; char const *newargv[45 + argc] ; newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver" ; if (o.verbosity != 1) newargv[m++] = o.verbosity ? "-v" : "-q" ; @@ -218,7 +216,7 @@ int main (int argc, char const *const *argv, char const *const *envp) if (o.doapply) { newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ; - if (o.gidn != (unsigned int)-1) + if (o.gidn != (size_t)-1) { newargv[m++] = "-G" ; newargv[m++] = fmt + pos ; @@ -236,7 +234,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { newargv[m++] = "-u" ; newargv[m++] = fmt + pos ; - pos += uint64_fmt(fmt + pos, o.uid) ; + pos += uid_fmt(fmt + pos, o.uid) ; fmt[pos++] = 0 ; } if (o.flagU) newargv[m++] = "-Uz" ; diff --git a/src/include/s6-networking/ident.h b/src/include/s6-networking/ident.h index 4a406b5..ec2c93b 100644 --- a/src/include/s6-networking/ident.h +++ b/src/include/s6-networking/ident.h @@ -13,7 +13,7 @@ /* High-level */ -extern int s6net_ident_client (char *, size_t, ip46_t const *, uint16_t, ip46_t const *, uint16_t, tain_t const *, tain_t *) ; +extern ssize_t s6net_ident_client (char *, size_t, ip46_t const *, uint16_t, ip46_t const *, uint16_t, tain_t const *, tain_t *) ; #define s6net_ident_client_g(s, max, ra, rp, la, lp, deadline) s6net_ident_client(s, max, ra, rp, la, lp, (deadline), &STAMP) extern char const *s6net_ident_error_str (int) ; diff --git a/src/libs6net/s6net_ident_client.c b/src/libs6net/s6net_ident_client.c index e4f4b87..a014fe2 100644 --- a/src/libs6net/s6net_ident_client.c +++ b/src/libs6net/s6net_ident_client.c @@ -1,22 +1,22 @@ /* ISC license. */ +#include <string.h> #include <stdint.h> #include <errno.h> -#include <skalibs/bytestr.h> #include <skalibs/tai.h> #include <skalibs/ip46.h> #include <s6-networking/ident.h> -int s6net_ident_client (char *s, size_t max, ip46_t const *remoteip, uint16_t remoteport, ip46_t const *localip, uint16_t localport, tain_t const *deadline, tain_t *stamp) +ssize_t s6net_ident_client (char *s, size_t max, ip46_t const *remoteip, uint16_t remoteport, ip46_t const *localip, uint16_t localport, tain_t const *deadline, tain_t *stamp) { char buf[S6NET_IDENT_REPLY_SIZE] ; size_t len ; - register ssize_t r = s6net_ident_reply_get(buf, remoteip, remoteport, localip, localport, deadline, stamp) ; + ssize_t r = s6net_ident_reply_get(buf, remoteip, remoteport, localip, localport, deadline, stamp) ; if (r < 0) return errno == EPIPE ? (errno = EIO, 0) : -1 ; /* the RFC says so */ len = r ; r = s6net_ident_reply_parse(buf, remoteport, localport) ; if (r <= 0) return r ; if (max + r < len + 1) return (errno = ENAMETOOLONG, -1) ; - byte_copy(s, len - r + 1, buf + r) ; + memcpy(s, buf + r, len - r + 1) ; return len - r + 1 ; } diff --git a/src/libs6net/s6net_ident_error.c b/src/libs6net/s6net_ident_error.c index de01714..fca41fc 100644 --- a/src/libs6net/s6net_ident_error.c +++ b/src/libs6net/s6net_ident_error.c @@ -27,7 +27,7 @@ static int const s6net_ident_error_codes[N] = char const *s6net_ident_error_str (int e) { - register unsigned int i = 0 ; + unsigned int i = 0 ; for (; i < N ; i++) if (e == s6net_ident_error_codes[i]) break ; return s6net_ident_error_strings[i] ; } diff --git a/src/libs6net/s6net_ident_reply_get.c b/src/libs6net/s6net_ident_reply_get.c index ee8c87e..18a833d 100644 --- a/src/libs6net/s6net_ident_reply_get.c +++ b/src/libs6net/s6net_ident_reply_get.c @@ -1,9 +1,8 @@ /* ISC license. */ -#include <sys/types.h> #include <stdint.h> #include <errno.h> -#include <skalibs/uint16.h> +#include <skalibs/types.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/error.h> @@ -15,7 +14,7 @@ ssize_t s6net_ident_reply_get (char *s, ip46_t const *remoteip, uint16_t remoteport, ip46_t const *localip, uint16_t localport, tain_t const *deadline, tain_t *stamp) { - unsigned int len ; /* XXX: change when skalibs changes */ + size_t len ; int fd ; if (ip46_is6(remoteip) != ip46_is6(localip)) return (errno = EAFNOSUPPORT, -1) ; fd = socket_tcp46(ip46_is6(remoteip)) ; diff --git a/src/libs6net/s6net_ident_reply_parse.c b/src/libs6net/s6net_ident_reply_parse.c index dd3e84c..f2e3308 100644 --- a/src/libs6net/s6net_ident_reply_parse.c +++ b/src/libs6net/s6net_ident_reply_parse.c @@ -1,16 +1,16 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> #include <errno.h> -#include <skalibs/uint16.h> +#include <skalibs/types.h> #include <skalibs/bytestr.h> #include <skalibs/error.h> #include <s6-networking/ident.h> static size_t skipspace (char const *s) { - register size_t n = 0 ; + size_t n = 0 ; while ((s[n] == ' ') || (s[n] == '\t')) n++ ; return n ; } @@ -33,8 +33,8 @@ ssize_t s6net_ident_reply_parse (char const *s, uint16_t rp, uint16_t lp) n += skipspace(s+n) ; if (!s[n]) goto err ; if (s[n++] != ':') goto err ; n += skipspace(s+n) ; if (!s[n]) goto err ; - if (!str_diffn(s+n, "ERROR", 5)) goto ERROR ; - if (!str_diffn(s+n, "USERID", 6)) goto USERID ; + if (!strncmp(s+n, "ERROR", 5)) goto ERROR ; + if (!strncmp(s+n, "USERID", 6)) goto USERID ; err: return (errno = EPROTO, -1) ; @@ -43,10 +43,10 @@ ssize_t s6net_ident_reply_parse (char const *s, uint16_t rp, uint16_t lp) n += skipspace(s+n) ; if (!s[n]) goto err ; if (s[n++] != ':') goto err ; n += skipspace(s+n) ; if (!s[n]) goto err ; - if (!str_diffn(s+n, "INVALID-PORT", 12)) return (errno = EINVAL, 0) ; - if (!str_diffn(s+n, "NO-USER", 7)) return (errno = ESRCH, 0) ; - if (!str_diffn(s+n, "HIDDEN-USER", 11)) return (errno = EPERM, 0) ; - if (!str_diffn(s+n, "UNKNOWN-ERROR", 13)) return (errno = EIO, 0) ; + if (!strncmp(s+n, "INVALID-PORT", 12)) return (errno = EINVAL, 0) ; + if (!strncmp(s+n, "NO-USER", 7)) return (errno = ESRCH, 0) ; + if (!strncmp(s+n, "HIDDEN-USER", 11)) return (errno = EPERM, 0) ; + if (!strncmp(s+n, "UNKNOWN-ERROR", 13)) return (errno = EIO, 0) ; if (s[n] == 'X') return (errno = EEXIST, 0) ; goto err ; diff --git a/src/minidentd/mgetuid-linux.c b/src/minidentd/mgetuid-linux.c index 18caba7..f374adf 100644 --- a/src/minidentd/mgetuid-linux.c +++ b/src/minidentd/mgetuid-linux.c @@ -1,12 +1,10 @@ /* ISC license. */ #include <sys/types.h> +#include <string.h> #include <stdint.h> -#include <skalibs/uint16.h> -#include <skalibs/uint32.h> #include <skalibs/uint64.h> -#include <skalibs/uint.h> -#include <skalibs/bytestr.h> +#include <skalibs/types.h> #include <skalibs/fmtscan.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> @@ -33,10 +31,10 @@ static int skipspace (char **s) static void reverse_address (char *s, size_t n) { - register size_t i = n >> 1 ; + size_t i = n >> 1 ; while (i--) { - register char tmp = s[i] ; + char tmp = s[i] ; s[i] = s[n-1-i] ; s[n-1-i] = tmp ; } @@ -46,9 +44,9 @@ static int parseline (char *s, size_t len, uid_t *u, char *la, uint16_t *lp, cha { char *cur = s ; size_t pos ; - uint64 uu ; + uint64_t uu ; uint32_t junk ; - register unsigned int iplen = is6 ? 16 : 4 ; + unsigned int iplen = is6 ? 16 : 4 ; if (!skipspace(&cur)) bug("initial whitespace") ; pos = uint32_scan(cur, &junk) ; /* sl */ @@ -149,7 +147,7 @@ uid_t mgetuid (ip46_t const *localaddr, uint16_t localport, ip46_t const *remote stralloc line = STRALLOC_ZERO ; buffer b ; char y[BUFFER_INSIZE] ; - register int is6 = ip46_is6(localaddr) ; + int is6 = ip46_is6(localaddr) ; int fd = open_readb(is6 ? "/proc/net/tcp6" : "/proc/net/tcp") ; if (fd == -1) return -2 ; buffer_init(&b, &buffer_read, fd, y, BUFFER_INSIZE_SMALL) ; @@ -173,8 +171,8 @@ uid_t mgetuid (ip46_t const *localaddr, uint16_t localport, ip46_t const *remote debuglog(lp, rp, nu, la, ra, is6) ; #endif if ((lp == localport) && (rp == remoteport) - && !byte_diff(la, is6 ? 16 : 4, localaddr->ip) - && !byte_diff(ra, is6 ? 16 : 4, remoteaddr->ip)) + && !memcmp(la, localaddr->ip, is6 ? 16 : 4) + && !memcmp(ra, remoteaddr->ip, is6 ? 16 : 4)) { u = nu ; break ; } diff --git a/src/minidentd/minidentd.c b/src/minidentd/minidentd.c index 4a73021..6d0f6a0 100644 --- a/src/minidentd/minidentd.c +++ b/src/minidentd/minidentd.c @@ -1,13 +1,11 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <stdint.h> #include <unistd.h> #include <errno.h> #include <pwd.h> -#include <skalibs/uint16.h> -#include <skalibs/uint32.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/allreadwrite.h> #include <skalibs/bytestr.h> #include <skalibs/fmtscan.h> @@ -33,8 +31,7 @@ static tain_t deadline ; static unsigned int nquery = 0 ; static char logfmt[UINT_FMT] ; -#define DECIMAL "0123456789" -#define godecimal(s) while (*(s) && !DECIMAL[str_chr(DECIMAL, *(s))]) (s)++ +#define godecimal(s) while (*(s) && !strchr("0123456789", *(s))) (s)++ static int parseline (char const *s, uint16_t *localport, uint16_t *remoteport) { @@ -106,12 +103,12 @@ static int userident (char *s, char const *home) int fd ; size_t r = 1 ; { - size_t homelen = str_len(home) ; - size_t userlen = str_len(userfile) ; + size_t homelen = strlen(home) ; + size_t userlen = strlen(userfile) ; char tmp[homelen + userlen + 2] ; - byte_copy(tmp, homelen, home) ; + memcpy(tmp, home, homelen) ; tmp[homelen] = '/' ; - byte_copy(tmp + homelen + 1, userlen + 1, userfile) ; + memcpy(tmp + homelen + 1, userfile, userlen + 1) ; fd = open_readb(tmp) ; } if (fd == -1) return (errno != ENOENT) ? -1 : 0 ; @@ -181,7 +178,7 @@ static void doit (char const *s, ip46_t const *localaddr, ip46_t const *remotead if (how) { char s[15] ; - register int r = userident(s, pw->pw_dir) ; + int r = userident(s, pw->pw_dir) ; if ((how == 1) || (r == 1)) { reply(lr, "ERROR", "HIDDEN-USER") ; @@ -213,7 +210,7 @@ int main (int argc, char const *const *argv, char const *const *envp) unsigned int t = 0 ; for (;;) { - register int opt = subgetopt_r(argc, argv, "vniry:t:", &l) ; + int opt = subgetopt_r(argc, argv, "vniry:t:", &l) ; if (opt == -1) break ; switch (opt) { @@ -235,14 +232,14 @@ int main (int argc, char const *const *argv, char const *const *envp) if (!proto) strerr_dienotset(100, "PROTO") ; { char const *x ; - size_t protolen = str_len(proto) ; + size_t protolen = strlen(proto) ; char tmp[protolen + 9] ; - byte_copy(tmp, protolen, proto) ; - byte_copy(tmp + protolen, 8, "LOCALIP") ; + memcpy(tmp, proto, protolen) ; + memcpy(tmp + protolen, "LOCALIP", 8) ; x = env_get2(envp, tmp) ; if (!x) strerr_dienotset(100, tmp) ; if (!ip46_scan(x, &localaddr)) strerr_dieinvalid(100, tmp) ; - byte_copy(tmp + protolen, 9, "REMOTEIP") ; + memcpy(tmp + protolen, "REMOTEIP", 9) ; x = env_get2(envp, tmp) ; if (!x) strerr_dienotset(100, tmp) ; if (!ip46_scan(x, &remoteaddr)) strerr_dieinvalid(100, tmp) ; @@ -258,7 +255,7 @@ int main (int argc, char const *const *argv, char const *const *envp) for (;;) { - register int r ; + int r ; line.len = 0 ; tain_add_g(&deadline, &tto) ; r = timed_getln_g(buffer_0small, &line, '\n', &deadline) ; diff --git a/src/sbearssl/sbearssl_cert_readbigpem.c b/src/sbearssl/sbearssl_cert_readbigpem.c index d09c997..9df5ebd 100644 --- a/src/sbearssl/sbearssl_cert_readbigpem.c +++ b/src/sbearssl/sbearssl_cert_readbigpem.c @@ -1,9 +1,8 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <errno.h> #include <bearssl.h> -#include <skalibs/bytestr.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> @@ -33,8 +32,8 @@ int sbearssl_cert_readbigpem (char const *fn, genalloc *certs, stralloc *sa) for (; i < n ; i++) { char const *name = sa->s + p[i].name ; - if (!str_diff(name, "CERTIFICATE") - || !str_diff(name, "X509 CERTIFICATE")) + if (!strcmp(name, "CERTIFICATE") + || !strcmp(name, "X509 CERTIFICATE")) { sbearssl_cert sc = { .data = p[i].data, .datalen = p[i].datalen } ; if (!genalloc_append(sbearssl_cert, certs, &sc)) goto fail ; diff --git a/src/sbearssl/sbearssl_cert_readfile.c b/src/sbearssl/sbearssl_cert_readfile.c index f63fde4..746c2e8 100644 --- a/src/sbearssl/sbearssl_cert_readfile.c +++ b/src/sbearssl/sbearssl_cert_readfile.c @@ -1,9 +1,8 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <errno.h> #include <bearssl.h> -#include <skalibs/bytestr.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> @@ -19,7 +18,7 @@ int sbearssl_cert_readfile (char const *fn, genalloc *certs, stralloc *sa) int certswasnull = !genalloc_s(sbearssl_cert, certs) ; int sawasnull = !sa->s ; { - register ssize_t r = openreadnclose(fn, buf, SBEARSSL_MAXCERTFILESIZE) ; + ssize_t r = openreadnclose(fn, buf, SBEARSSL_MAXCERTFILESIZE) ; if (r < 0) return r ; n = r ; } @@ -34,15 +33,15 @@ int sbearssl_cert_readfile (char const *fn, genalloc *certs, stralloc *sa) genalloc pems = GENALLOC_ZERO ; size_t i = 0 ; sbearssl_pemobject *p ; - register int r = sbearssl_pem_decode_from_string(buf, n, &pems, sa) ; + int r = sbearssl_pem_decode_from_string(buf, n, &pems, sa) ; if (r) return r ; p = genalloc_s(sbearssl_pemobject, &pems) ; n = genalloc_len(sbearssl_pemobject, &pems) ; for (; i < n ; i++) { char const *name = sa->s + p[i].name ; - if (!str_diff(name, "CERTIFICATE") - || !str_diff(name, "X509 CERTIFICATE")) + if (!strcmp(name, "CERTIFICATE") + || !strcmp(name, "X509 CERTIFICATE")) { sbearssl_cert cert = { .data = p[i].data, .datalen = p[i].datalen } ; if (!genalloc_append(sbearssl_cert, certs, &cert)) diff --git a/src/sbearssl/sbearssl_ec_issuer_keytype.c b/src/sbearssl/sbearssl_ec_issuer_keytype.c index 2958e8d..c59da37 100644 --- a/src/sbearssl/sbearssl_ec_issuer_keytype.c +++ b/src/sbearssl/sbearssl_ec_issuer_keytype.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <sys/types.h> #include <errno.h> #include <bearssl.h> #include <skalibs/stralloc.h> diff --git a/src/sbearssl/sbearssl_pem_decode_from_buffer.c b/src/sbearssl/sbearssl_pem_decode_from_buffer.c index e246b87..cacabd9 100644 --- a/src/sbearssl/sbearssl_pem_decode_from_buffer.c +++ b/src/sbearssl/sbearssl_pem_decode_from_buffer.c @@ -1,10 +1,9 @@ /* ISC license. */ -#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> #include <bearssl.h> #include <skalibs/error.h> -#include <skalibs/siovec.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> @@ -26,19 +25,19 @@ int sbearssl_pem_decode_from_buffer (buffer *b, genalloc *list, stralloc *sa) br_pem_decoder_init(&ctx) ; for (;;) { - siovec_t v[2] ; + struct iovec v[2] ; ssize_t rr = buffer_fill(b) ; if (rr < 0) goto rfail ; if (!rr) break ; buffer_rpeek(b, v) ; - r = sbearssl_pem_push(&ctx, v[0].s, v[0].len, &po, list, &blah, &inobj) ; + r = sbearssl_pem_push(&ctx, v[0].iov_base, v[0].iov_len, &po, list, &blah, &inobj) ; if (r) goto fail ; - if (v[1].len) + if (v[1].iov_len) { - r = sbearssl_pem_push(&ctx, v[1].s, v[1].len, &po, list, &blah, &inobj) ; + r = sbearssl_pem_push(&ctx, v[1].iov_base, v[1].iov_len, &po, list, &blah, &inobj) ; if (r) goto fail ; } - buffer_rseek(b, v[0].len + v[1].len) ; + buffer_rseek(b, v[0].iov_len + v[1].iov_len) ; } if (!inobj) return 0 ; diff --git a/src/sbearssl/sbearssl_s6tlsc.c b/src/sbearssl/sbearssl_s6tlsc.c index c6ca4c1..057929f 100644 --- a/src/sbearssl/sbearssl_s6tlsc.c +++ b/src/sbearssl/sbearssl_s6tlsc.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <sys/types.h> #include <stdint.h> #include <unistd.h> #include <errno.h> diff --git a/src/sbearssl/sbearssl_s6tlsd.c b/src/sbearssl/sbearssl_s6tlsd.c index 816d746..e91ef54 100644 --- a/src/sbearssl/sbearssl_s6tlsd.c +++ b/src/sbearssl/sbearssl_s6tlsd.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <sys/types.h> +#include <stdint.h> #include <unistd.h> #include <errno.h> #include <bearssl.h> diff --git a/src/sbearssl/sbearssl_setclientcert.c b/src/sbearssl/sbearssl_setclientcert.c index 07b1385..74bfd20 100644 --- a/src/sbearssl/sbearssl_setclientcert.c +++ b/src/sbearssl/sbearssl_setclientcert.c @@ -24,6 +24,5 @@ int sbearssl_setclientcert (br_ssl_client_context *cc, br_x509_certificate const strerr_dief1x(96, "unsupported private key type") ; } - return 0 ; } diff --git a/src/sbearssl/sbearssl_skey_readfile.c b/src/sbearssl/sbearssl_skey_readfile.c index c406de0..7e7df51 100644 --- a/src/sbearssl/sbearssl_skey_readfile.c +++ b/src/sbearssl/sbearssl_skey_readfile.c @@ -1,9 +1,8 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <errno.h> #include <bearssl.h> -#include <skalibs/bytestr.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/djbunix.h> @@ -49,9 +48,9 @@ int sbearssl_skey_readfile (char const *fn, sbearssl_skey *key, stralloc *sa) for (; i < n ; i++) { char const *name = tmp.s + p[i].name ; - if (!str_diff(name, "RSA PRIVATE KEY") - || !str_diff(name, "EC PRIVATE KEY") - || !str_diff(name, "PRIVATE KEY")) + if (!strcmp(name, "RSA PRIVATE KEY") + || !strcmp(name, "EC PRIVATE KEY") + || !strcmp(name, "PRIVATE KEY")) { r = decode_key(key, tmp.s + p[i].data, p[i].datalen, sa) ; if (r) goto fail ; diff --git a/src/sbearssl/sbearssl_ta_readdir.c b/src/sbearssl/sbearssl_ta_readdir.c index de39eca..829d7a6 100644 --- a/src/sbearssl/sbearssl_ta_readdir.c +++ b/src/sbearssl/sbearssl_ta_readdir.c @@ -1,8 +1,7 @@ /* ISC license. */ -#include <sys/types.h> +#include <string.h> #include <errno.h> -#include <skalibs/bytestr.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/direntry.h> @@ -13,7 +12,7 @@ int sbearssl_ta_readdir (char const *dirfn, genalloc *taga, stralloc *tasa) { size_t tasabase = tasa->len ; size_t tagabase = genalloc_len(sbearssl_ta, taga) ; - size_t dirfnlen = str_len(dirfn) ; + size_t dirfnlen = strlen(dirfn) ; int tasawasnull = !tasa->s ; int tagawasnull = !genalloc_s(sbearssl_ta, taga) ; stralloc certsa = STRALLOC_ZERO ; @@ -29,11 +28,11 @@ int sbearssl_ta_readdir (char const *dirfn, genalloc *taga, stralloc *tasa) if (!d) break ; if (d->d_name[0] == '.') continue ; { - size_t dlen = str_len(d->d_name) ; + size_t dlen = strlen(d->d_name) ; char fn[dirfnlen + dlen + 2] ; - byte_copy(fn, dirfnlen, dirfn) ; + memcpy(fn, dirfn, dirfnlen) ; fn[dirfnlen] = '/' ; - byte_copy(fn + dirfnlen + 1, dlen, d->d_name) ; + memcpy(fn + dirfnlen + 1, d->d_name, dlen) ; fn[dirfnlen + 1 + dlen] = 0 ; genalloc_setlen(sbearssl_cert, &certga, 0) ; certsa.len = 0 ; diff --git a/src/sbearssl/sbearssl_x500_from_ta.c b/src/sbearssl/sbearssl_x500_from_ta.c index 50a132b..d655919 100644 --- a/src/sbearssl/sbearssl_x500_from_ta.c +++ b/src/sbearssl/sbearssl_x500_from_ta.c @@ -1,15 +1,15 @@ /* ISC license. */ +#include <string.h> #include <bearssl.h> -#include <skalibs/bytestr.h> #include <s6-networking/sbearssl.h> void sbearssl_x500_from_ta (br_x500_name *names, sbearssl_ta const *sta, size_t n, char *storage, char const *tastorage) { while (n--) { - register size_t len = sta->dnlen ; - byte_copy(storage, len, tastorage + sta->dn) ; + size_t len = sta->dnlen ; + memcpy(storage, tastorage + sta->dn, len) ; sta++ ; names->data = (unsigned char *)storage ; names->len = len ; diff --git a/src/sbearssl/sbearssl_x509_minimal_set_tai.c b/src/sbearssl/sbearssl_x509_minimal_set_tai.c index 11b1ad6..cfa12be 100644 --- a/src/sbearssl/sbearssl_x509_minimal_set_tai.c +++ b/src/sbearssl/sbearssl_x509_minimal_set_tai.c @@ -9,7 +9,7 @@ int sbearssl_x509_minimal_set_tai (br_x509_minimal_context *ctx, tai_t const *t) { - uint64 u ; + uint64_t u ; if (!utc_from_tai(&u, t)) return 0 ; u -= TAI_MAGIC ; br_x509_minimal_set_time(ctx, (uint32_t)(u / 86400 + 719528), u % 86400) ; diff --git a/src/stls/stls_run.c b/src/stls/stls_run.c index 0ba10b0..8d7478f 100644 --- a/src/stls/stls_run.c +++ b/src/stls/stls_run.c @@ -1,7 +1,7 @@ /* ISC license. */ #include <skalibs/nonposix.h> -#include <sys/types.h> +#include <sys/uio.h> #include <stdint.h> #include <sys/socket.h> #include <errno.h> @@ -16,7 +16,6 @@ #include <skalibs/tai.h> #include <skalibs/iopause.h> #include <skalibs/djbunix.h> -#include <skalibs/siovec.h> #include <s6-networking/stls.h> typedef struct tlsbuf_s tlsbuf_t, *tlsbuf_t_ref ; @@ -29,10 +28,10 @@ struct tlsbuf_s static inline int buffer_tls_flush (struct tls *ctx, tlsbuf_t *b) { - siovec_t v[2] ; + struct iovec v[2] ; ssize_t r, w ; buffer_rpeek(&b[0].b, v) ; - r = tls_write(ctx, v[0].s, v[0].len) ; + r = tls_write(ctx, v[0].iov_base, v[0].iov_len) ; switch (r) { case -1 : return -1 ; @@ -43,9 +42,9 @@ static inline int buffer_tls_flush (struct tls *ctx, tlsbuf_t *b) default : break ; } w = r ; - if ((size_t)w == v[0].len && v[1].len) + if ((size_t)w == v[0].iov_len && v[1].iov_len) { - r = tls_write(ctx, v[1].s, v[1].len) ; + r = tls_write(ctx, v[1].iov_base, v[1].iov_len) ; switch (r) { case TLS_WANT_POLLIN : @@ -65,11 +64,11 @@ static inline int buffer_tls_flush (struct tls *ctx, tlsbuf_t *b) static inline int buffer_tls_fill (struct tls *ctx, tlsbuf_t *b) { - siovec_t v[2] ; + struct iovec v[2] ; ssize_t r, w ; int ok = 1 ; buffer_wpeek(&b[1].b, v) ; - r = tls_read(ctx, v[0].s, v[0].len) ; + r = tls_read(ctx, v[0].iov_base, v[0].iov_len) ; switch (r) { case 0 : return -2 ; @@ -81,9 +80,9 @@ static inline int buffer_tls_fill (struct tls *ctx, tlsbuf_t *b) default : break ; } w = r ; - if ((size_t)w == v[0].len && v[1].len) + if ((size_t)w == v[0].iov_len && v[1].iov_len) { - r = tls_read(ctx, v[1].s, v[1].len) ; + r = tls_read(ctx, v[1].iov_base, v[1].iov_len) ; switch (r) { case TLS_WANT_POLLOUT : @@ -121,9 +120,9 @@ int stls_run (struct tls *ctx, int *fds, unsigned int verbosity, uint32_t option tlsbuf_t b[2] = { { .blockedonother = 0 }, { .blockedonother = 0 } } ; iopause_fd x[4] ; unsigned int xindex[4] ; - register unsigned int i ; + unsigned int i = 0 ; - for (i = 0 ; i < 2 ; i++) + for (; i < 2 ; i++) { buffer_init(&b[i].b, i ? &buffer_write : &buffer_read, fds[i], b[i].buf, STLS_BUFSIZE) ; if (ndelay_on(fds[2+i]) < 0) strerr_diefu1sys(111, "set fds non-blocking") ; @@ -136,7 +135,7 @@ int stls_run (struct tls *ctx, int *fds, unsigned int verbosity, uint32_t option { tain_t deadline ; unsigned int xlen = 0 ; - register int r ; + int r ; tain_add_g(&deadline, fds[0] >= 0 && fds[2] >= 0 && buffer_isempty(&b[0].b) && buffer_isempty(&b[1].b) ? tto : &tain_infinite_relative) ; diff --git a/src/stls/stls_s6tlsc.c b/src/stls/stls_s6tlsc.c index 001953d..ed0476e 100644 --- a/src/stls/stls_s6tlsc.c +++ b/src/stls/stls_s6tlsc.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <sys/types.h> #include <stdint.h> #include <unistd.h> #include <errno.h> diff --git a/src/stls/stls_s6tlsd.c b/src/stls/stls_s6tlsd.c index 4b04560..aac188e 100644 --- a/src/stls/stls_s6tlsd.c +++ b/src/stls/stls_s6tlsd.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <sys/types.h> #include <stdint.h> #include <unistd.h> #include <errno.h> |