diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-01-15 20:51:39 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-01-15 20:51:39 +0000 |
commit | ebfd0ba17e0d4b220725018d16e294e8e22a1745 (patch) | |
tree | 4b29683050ce9e8f24f1920f1be38b2f837ef5ad /src/libs6net | |
parent | 20c7d8e1b328155145ce9e8648435e127b60c208 (diff) | |
download | s6-networking-ebfd0ba17e0d4b220725018d16e294e8e22a1745.tar.xz |
Move Unix domain socket and access control stuff to s6.
Move seekablepipe to s6-portable-utils.
Version: 2.0.1.0, release candidate
Diffstat (limited to 'src/libs6net')
-rw-r--r-- | src/libs6net/deps-lib/s6net | 8 | ||||
-rw-r--r-- | src/libs6net/s6net_accessrules_backend_cdb.c | 38 | ||||
-rw-r--r-- | src/libs6net/s6net_accessrules_backend_fs.c | 58 | ||||
-rw-r--r-- | src/libs6net/s6net_accessrules_keycheck_ip4.c | 24 | ||||
-rw-r--r-- | src/libs6net/s6net_accessrules_keycheck_ip6.c | 27 | ||||
-rw-r--r-- | src/libs6net/s6net_accessrules_keycheck_reversedns.c | 27 | ||||
-rw-r--r-- | src/libs6net/s6net_accessrules_keycheck_uidgid.c | 16 | ||||
-rw-r--r-- | src/libs6net/s6net_accessrules_uidgid_cdb.c | 11 | ||||
-rw-r--r-- | src/libs6net/s6net_accessrules_uidgid_fs.c | 10 |
9 files changed, 0 insertions, 219 deletions
diff --git a/src/libs6net/deps-lib/s6net b/src/libs6net/deps-lib/s6net index 7b497ac..1b15735 100644 --- a/src/libs6net/deps-lib/s6net +++ b/src/libs6net/deps-lib/s6net @@ -1,11 +1,3 @@ -s6net_accessrules_backend_cdb.o -s6net_accessrules_backend_fs.o -s6net_accessrules_keycheck_ip4.o -s6net_accessrules_keycheck_ip6.o -s6net_accessrules_keycheck_reversedns.o -s6net_accessrules_keycheck_uidgid.o -s6net_accessrules_uidgid_cdb.o -s6net_accessrules_uidgid_fs.o s6net_ident_client.o s6net_ident_reply_get.o s6net_ident_reply_parse.o diff --git a/src/libs6net/s6net_accessrules_backend_cdb.c b/src/libs6net/s6net_accessrules_backend_cdb.c deleted file mode 100644 index e75f755..0000000 --- a/src/libs6net/s6net_accessrules_backend_cdb.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ISC license. */ - -#include <unistd.h> -#include <errno.h> -#include <skalibs/bytestr.h> -#include <skalibs/uint16.h> -#include <skalibs/cdb.h> -#include <skalibs/stralloc.h> -#include <s6-networking/accessrules.h> - -s6net_accessrules_result_t s6net_accessrules_backend_cdb (char const *key, unsigned int keylen, void *data, s6net_accessrules_params_t *params) -{ - struct cdb *c = data ; - unsigned int execbase, n ; - uint16 envlen, execlen ; - register int r = cdb_find(c, key, keylen) ; - if (r < 0) return S6NET_ACCESSRULES_ERROR ; - else if (!r) return S6NET_ACCESSRULES_NOTFOUND ; - n = cdb_datalen(c) ; - if ((n < 5U) || (n > 8197U)) return (errno = EINVAL, S6NET_ACCESSRULES_ERROR) ; - if (!stralloc_readyplus(¶ms->exec, n)) return S6NET_ACCESSRULES_ERROR ; - execbase = params->exec.len ; - if (cdb_read(c, params->exec.s + execbase, n, cdb_datapos(c)) < 0) return S6NET_ACCESSRULES_ERROR ; - if (params->exec.s[execbase] == 'D') return S6NET_ACCESSRULES_DENY ; - else if (params->exec.s[execbase] != 'A') return S6NET_ACCESSRULES_NOTFOUND ; - uint16_unpack_big(params->exec.s + execbase + 1U, &envlen) ; - if ((envlen > 4096U) || (envlen+5U > n)) return (errno = EINVAL, S6NET_ACCESSRULES_ERROR) ; - uint16_unpack_big(params->exec.s + execbase + 3 + envlen, &execlen) ; - if ((execlen > 4096U) || (5U + envlen + execlen != n)) return (errno = EINVAL, S6NET_ACCESSRULES_ERROR) ; - if (!stralloc_catb(¶ms->env, params->exec.s + execbase + 3U, envlen)) return S6NET_ACCESSRULES_ERROR ; - byte_copy(params->exec.s + execbase, execlen, params->exec.s + execbase + 5U + envlen) ; - if (execlen) - { - params->exec.len += execlen ; - params->exec.s[params->exec.len++] = 0 ; - } - return S6NET_ACCESSRULES_ALLOW ; -} diff --git a/src/libs6net/s6net_accessrules_backend_fs.c b/src/libs6net/s6net_accessrules_backend_fs.c deleted file mode 100644 index d609285..0000000 --- a/src/libs6net/s6net_accessrules_backend_fs.c +++ /dev/null @@ -1,58 +0,0 @@ -/* ISC license. */ - -#include <unistd.h> -#include <errno.h> -#include <skalibs/bytestr.h> -#include <skalibs/fmtscan.h> -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> -#include <s6-networking/accessrules.h> - -s6net_accessrules_result_t s6net_accessrules_backend_fs (char const *key, unsigned int keylen, void *data, s6net_accessrules_params_t *params) -{ - char *dir = data ; - unsigned int dirlen = str_len(dir) ; - unsigned int envbase = params->env.len ; - int wasnull = !params->env.s ; - { - char tmp[dirlen + keylen + 10] ; - byte_copy(tmp, dirlen, dir) ; - tmp[dirlen] = '/' ; - byte_copy(tmp + dirlen + 1, keylen, key) ; - byte_copy(tmp + dirlen + keylen + 1, 7, "/allow") ; - if (access(tmp, R_OK) < 0) - { - if ((errno != EACCES) && (errno != ENOENT)) - return S6NET_ACCESSRULES_ERROR ; - byte_copy(tmp + dirlen + keylen + 2, 5, "deny") ; - return (access(tmp, R_OK) == 0) ? S6NET_ACCESSRULES_DENY : - (errno != EACCES) && (errno != ENOENT) ? S6NET_ACCESSRULES_ERROR : - S6NET_ACCESSRULES_NOTFOUND ; - } - byte_copy(tmp + dirlen + keylen + 2, 4, "env") ; - if ((envdir(tmp, ¶ms->env) < 0) && (errno != ENOENT)) - return S6NET_ACCESSRULES_ERROR ; - if (!stralloc_readyplus(¶ms->exec, 4097)) - { - if (wasnull) stralloc_free(¶ms->env) ; - else params->env.len = envbase ; - return S6NET_ACCESSRULES_ERROR ; - } - byte_copy(tmp + dirlen + keylen + 2, 5, "exec") ; - { - register int r = openreadnclose(tmp, params->exec.s + params->exec.len, 4096) ; - if ((r < 0) && (errno != EACCES) && (errno != ENOENT)) - { - if (wasnull) stralloc_free(¶ms->env) ; - else params->env.len = envbase ; - return S6NET_ACCESSRULES_ERROR ; - } - if (r > 0) - { - params->exec.len += r ; - params->exec.s[params->exec.len++] = 0 ; - } - } - } - return S6NET_ACCESSRULES_ALLOW ; -} diff --git a/src/libs6net/s6net_accessrules_keycheck_ip4.c b/src/libs6net/s6net_accessrules_keycheck_ip4.c deleted file mode 100644 index 1f96bd8..0000000 --- a/src/libs6net/s6net_accessrules_keycheck_ip4.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/uint.h> -#include <skalibs/fmtscan.h> -#include <s6-networking/accessrules.h> - -s6net_accessrules_result_t s6net_accessrules_keycheck_ip4 (void const *key, void *data, s6net_accessrules_params_t *params, s6net_accessrules_backend_func_t_ref check1) -{ - char fmt[IP4_FMT + UINT_FMT + 6] = "ip4/" ; - uint32 ip ; - unsigned int i = 0 ; - uint32_unpack_big((char const *)key, &ip) ; - for (; i <= 32 ; i++) - { - register s6net_accessrules_result_t r ; - register unsigned int len = 4 + ip4_fmtu32(fmt+4, (i == 32) ? 0 : ip & ~((1U << i) - 1)) ; - fmt[len++] = '_' ; - len += uint_fmt(fmt + len, 32 - i) ; - r = (*check1)(fmt, len, data, params) ; - if (r != S6NET_ACCESSRULES_NOTFOUND) return r ; - } - return S6NET_ACCESSRULES_NOTFOUND ; -} diff --git a/src/libs6net/s6net_accessrules_keycheck_ip6.c b/src/libs6net/s6net_accessrules_keycheck_ip6.c deleted file mode 100644 index c2ee5ae..0000000 --- a/src/libs6net/s6net_accessrules_keycheck_ip6.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint.h> -#include <skalibs/bytestr.h> -#include <skalibs/bitarray.h> -#include <skalibs/fmtscan.h> -#include <s6-networking/accessrules.h> - -s6net_accessrules_result_t s6net_accessrules_keycheck_ip6 (void const *key, void *data, s6net_accessrules_params_t *params, s6net_accessrules_backend_func_t_ref check1) -{ - char fmt[IP6_FMT + UINT_FMT + 6] = "ip6/" ; - char ip6[16] ; - unsigned int i = 0 ; - byte_copy(ip6, 16, (char const *)key) ; - for (; i <= 128 ; i++) - { - unsigned int len ; - register s6net_accessrules_result_t r ; - if (i) bitarray_clear(ip6, 128 - i) ; - len = 4 + ip6_fmt(fmt+4, ip6) ; - fmt[len++] = '_' ; - len += uint_fmt(fmt + len, 128 - i) ; - r = (*check1)(fmt, len, data, params) ; - if (r != S6NET_ACCESSRULES_NOTFOUND) return r ; - } - return S6NET_ACCESSRULES_NOTFOUND ; -} diff --git a/src/libs6net/s6net_accessrules_keycheck_reversedns.c b/src/libs6net/s6net_accessrules_keycheck_reversedns.c deleted file mode 100644 index f4c0213..0000000 --- a/src/libs6net/s6net_accessrules_keycheck_reversedns.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/bytestr.h> -#include <s6-networking/accessrules.h> - -s6net_accessrules_result_t s6net_accessrules_keycheck_reversedns (void const *key, void *data, s6net_accessrules_params_t *params, s6net_accessrules_backend_func_t_ref check1) -{ - char const *name = key ; - unsigned int len = str_len(name) ; - if (!len) return (errno = EINVAL, S6NET_ACCESSRULES_ERROR) ; - if (name[len-1] == '.') len-- ; - { - unsigned int i = 0 ; - char tmp[len + 11] ; - byte_copy(tmp, 11, "reversedns/") ; - while (i < len) - { - register s6net_accessrules_result_t r ; - byte_copy(tmp+11, len-i, name+i) ; - r = (*check1)(tmp, 11+len-i, data, params) ; - if (r != S6NET_ACCESSRULES_NOTFOUND) return r ; - i += byte_chr(name+i, len-i, '.') + 1 ; - } - } - return (*check1)("reversedns/@", 12, data, params) ; -} diff --git a/src/libs6net/s6net_accessrules_keycheck_uidgid.c b/src/libs6net/s6net_accessrules_keycheck_uidgid.c deleted file mode 100644 index a7e2200..0000000 --- a/src/libs6net/s6net_accessrules_keycheck_uidgid.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint.h> -#include <skalibs/diuint.h> -#include <s6-networking/accessrules.h> - -s6net_accessrules_result_t s6net_accessrules_keycheck_uidgid (void const *key, void *data, s6net_accessrules_params_t *params, s6net_accessrules_backend_func_t_ref check1) -{ - char fmt[4 + UINT_FMT] = "uid/" ; - register s6net_accessrules_result_t r = (*check1)(fmt, 4 + uint_fmt(fmt+4, ((diuint const *)key)->left), data, params) ; - if (r != S6NET_ACCESSRULES_NOTFOUND) return r ; - fmt[0] = 'g' ; - r = (*check1)(fmt, 4 + uint_fmt(fmt+4, ((diuint const *)key)->right), data, params) ; - return (r != S6NET_ACCESSRULES_NOTFOUND) ? r : - (*check1)("uid/default", 11, data, params) ; -} diff --git a/src/libs6net/s6net_accessrules_uidgid_cdb.c b/src/libs6net/s6net_accessrules_uidgid_cdb.c deleted file mode 100644 index 1836389..0000000 --- a/src/libs6net/s6net_accessrules_uidgid_cdb.c +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include <skalibs/diuint.h> -#include <skalibs/cdb.h> -#include <s6-networking/accessrules.h> - -s6net_accessrules_result_t s6net_accessrules_uidgid_cdb (unsigned int uid, unsigned int gid, struct cdb *c, s6net_accessrules_params_t *params) -{ - diuint uidgid = { uid, gid } ; - return s6net_accessrules_keycheck_uidgid(&uidgid, c, params, &s6net_accessrules_backend_cdb) ; -} diff --git a/src/libs6net/s6net_accessrules_uidgid_fs.c b/src/libs6net/s6net_accessrules_uidgid_fs.c deleted file mode 100644 index db2e909..0000000 --- a/src/libs6net/s6net_accessrules_uidgid_fs.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/diuint.h> -#include <s6-networking/accessrules.h> - -s6net_accessrules_result_t s6net_accessrules_uidgid_fs (unsigned int uid, unsigned int gid, char const *rulesdir, s6net_accessrules_params_t *params) -{ - diuint uidgid = { uid, gid } ; - return s6net_accessrules_keycheck_uidgid(&uidgid, (void *)rulesdir, params, &s6net_accessrules_backend_fs) ; -} |