[rt-commit] r127 - in /redwax-tool/trunk: ChangeLog redwax-tool.c redwax-tool.h

rt-commit at redwax.eu rt-commit at redwax.eu
Fri Dec 10 23:07:43 CET 2021


Author: minfrin at redwax.eu
Date: Fri Dec 10 23:07:42 2021
New Revision: 127

Log:
Add support for ~ expansion to pathnames in and out.

Modified:
    redwax-tool/trunk/ChangeLog
    redwax-tool/trunk/redwax-tool.c
    redwax-tool/trunk/redwax-tool.h

Modified: redwax-tool/trunk/ChangeLog
==============================================================================
--- redwax-tool/trunk/ChangeLog	(original)
+++ redwax-tool/trunk/ChangeLog	Fri Dec 10 23:07:42 2021
@@ -1,5 +1,8 @@
 
 Changes with v0.9.1
+
+ *) Add support for ~ expansion to pathnames in and out.
+    [Graham Leggett]
 
  *) Default to --filter passthrough and --text-out. [Graham
     Leggett]

Modified: redwax-tool/trunk/redwax-tool.c
==============================================================================
--- redwax-tool/trunk/redwax-tool.c	(original)
+++ redwax-tool/trunk/redwax-tool.c	Fri Dec 10 23:07:42 2021
@@ -1056,6 +1056,17 @@
     return APR_SUCCESS;
 }
 
+const char *redwax_home(redwax_tool_t *r, const char *path)
+{
+    if (path[0] == '~') {
+        if (r->home && r->home[0]) {
+            path = apr_pstrcat(r->pool, r->home, path + 1, NULL);
+        }
+    }
+
+    return path;
+}
+
 int redwax_is_secret_path(redwax_tool_t *r, const char *base,
         const char *secret_suffix)
 {
@@ -1220,7 +1231,7 @@
 {
     apr_dir_t *thedir;
     apr_finfo_t dirent;
-    char *dir, *base, *prefix;
+    const char *dir, *base, *prefix;
     apr_status_t status;
     int base_len;
 
@@ -1247,6 +1258,8 @@
 
     base_len = strlen(base);
 
+    dir = redwax_home(r, dir);
+
     if ((status = apr_dir_open(&thedir, dir, r->pool)) != APR_SUCCESS) {
         return status;
     }
@@ -1303,7 +1316,7 @@
 {
     apr_dir_t *thedir;
     apr_finfo_t dirent;
-    char *dir, *base, *prefix;
+    const char *dir, *base, *prefix;
     apr_status_t status;
     int base_len;
 
@@ -1331,6 +1344,8 @@
 
     base_len = strlen(base);
 
+    dir = redwax_home(r, dir);
+
     if ((status = apr_dir_open(&thedir, dir, r->pool)) != APR_SUCCESS) {
         return status;
     }
@@ -1365,7 +1380,7 @@
         case APR_REG: {
 
             if (!strncmp(base, dirent.name, base_len)) {
-                                apr_file_printf(r->out, "%s \n", redwax_pescape_echo_quoted(r->pool,
+                apr_file_printf(r->out, "%s \n", redwax_pescape_echo_quoted(r->pool,
                         apr_pstrcat(r->pool, prefix, dirent.name, NULL),
                         quoted, 1));
             }
@@ -1591,7 +1606,7 @@
 apr_status_t redwax_file_out(redwax_tool_t *r, const char *path,
         apr_status_t (out)(redwax_tool_t *r, const char *path, const char *secret))
 {
-    char *dir, *base;
+    const char *dir, *base;
     apr_status_t status;
 
     if (!strcmp(path, "-")) {
@@ -1600,6 +1615,8 @@
 
     base = basename(apr_pstrdup(r->pool, path));
     dir = dirname(apr_pstrdup(r->pool, path));
+
+    dir = redwax_home(r, dir);
 
     status = out(r, path, redwax_secret_path(r, dir, base, r->secret_suffix_out));
     if (APR_SUCCESS != status) {
@@ -1637,12 +1654,14 @@
 {
     apr_dir_t *thedir;
     apr_finfo_t dirent;
-    char *dir, *base;
+    const char *dir, *base;
     apr_status_t status;
 
     if (!strcmp(path, "-")) {
         return walk(r, path, NULL);
     }
+
+    path = redwax_home(r, path);
 
     base = basename(apr_pstrdup(r->pool, path));
     dir = dirname(apr_pstrdup(r->pool, path));
@@ -1928,7 +1947,7 @@
 static apr_status_t redwax_set_secret_token_in(redwax_tool_t *r, const char *arg)
 {
     if (arg && arg[0]) {
-        r->secret_token_in = arg;
+        r->secret_token_in = redwax_home(r, arg);
     }
     else {
         r->secret_token_in = NULL;
@@ -1940,7 +1959,7 @@
 static apr_status_t redwax_set_secret_token_out(redwax_tool_t *r, const char *arg)
 {
     if (arg && arg[0]) {
-        r->secret_token_out = arg;
+        r->secret_token_out = redwax_home(r, arg);
     }
     else {
         r->secret_token_out = NULL;
@@ -1970,14 +1989,14 @@
         r->nss_out.needs_write = 0;
     }
     else if (!r->nss_out.dir) {
-        r->nss_out.dir = arg;
+        r->nss_out.dir = redwax_home(r, arg);;
         r->nss_out.needs_write = 1;
     }
     else {
         if (r->nss_out.needs_write) {
             redwax_token_out(r, r->nss_out.dir, NULL, &rt_run_process_nss_out);
         }
-        r->nss_out.dir = arg;
+        r->nss_out.dir = redwax_home(r, arg);;
         r->nss_out.needs_write = 1;
     }
 
@@ -2034,6 +2053,7 @@
 
 static apr_status_t redwax_metadata_out(redwax_tool_t *r, const char *arg)
 {
+    arg = redwax_home(r, arg);
 
     apr_status_t status = rt_run_process_metadata_out(r, arg);
 
@@ -2050,6 +2070,7 @@
 
 static apr_status_t redwax_jwks_out(redwax_tool_t *r, const char *arg)
 {
+    arg = redwax_home(r, arg);
 
     apr_status_t status = rt_run_process_jwks_out(r, arg);
 
@@ -2800,6 +2821,8 @@
         r.hostname = apr_pstrdup(r.pool, str);
     }
 
+    r.home = getenv("HOME");
+
     if (OK != rt_run_initialise(&r)) {
 
         apr_pool_destroy(r.pool);

Modified: redwax-tool/trunk/redwax-tool.h
==============================================================================
--- redwax-tool/trunk/redwax-tool.h	(original)
+++ redwax-tool/trunk/redwax-tool.h	Fri Dec 10 23:07:42 2021
@@ -61,6 +61,7 @@
     apr_file_t *out;
     const char *base;
     const char *hostname;
+    const char *home;
     const char *breaks;
     apr_array_header_t *certs_in;
     apr_array_header_t *certs_out;



More information about the rt-commit mailing list