From d2959364ef8d6bc948474a8facf497788b4e768b Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 15 Dec 2023 10:35:41 +0000 Subject: Prepare for 0.0.3.0; add XXX_no_translate Signed-off-by: Laurent Bercot --- src/tipideed/util.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/tipideed/util.c (limited to 'src/tipideed/util.c') diff --git a/src/tipideed/util.c b/src/tipideed/util.c new file mode 100644 index 0000000..2891306 --- /dev/null +++ b/src/tipideed/util.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include +#include + +#include +#include + +#include "tipideed-internal.h" + +size_t translate_path (char const *path) +{ + size_t n = g.sa.len ; + if (g.flagnoxlate) + { + if (!stralloc_readyplus(&g.sa, strlen(path) + 2)) return 0 ; + path_canonicalize(g.sa.s + n, path, 0) ; + return n ; + } + if (sarealpath(&g.sa, path) == -1 || !stralloc_0(&g.sa)) + { + g.sa.len = n ; + return 0 ; + } + g.sa.len = n ; + if (strncmp(g.sa.s + n, g.sa.s, g.cwdlen) || g.sa.s[n + g.cwdlen] != '/') + return (errno = EPERM, 0) ; + return n + g.cwdlen + 1 ; +} -- cgit v1.3.1