]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Allow to save private key in output
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 7 Apr 2023 14:59:46 +0000 (15:59 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 7 Apr 2023 15:39:21 +0000 (16:39 +0100)
src/lua/lua_rsa.c

index 85d5f87458c33b1f27647f30998c711c67e1802e..571f62646e64bfdd37f3f9b9e609cc1521751400 100644 (file)
@@ -177,7 +177,12 @@ lua_rsa_privkey_save (lua_State *L)
        }
 
        if (rsa != NULL && filename != NULL) {
-               f = fopen (filename, "wb");
+               if (strcmp (filename, "-") == 0) {
+                       f = stdout;
+               }
+               else {
+                       f = fopen(filename, "wb");
+               }
                if (f == NULL) {
                        msg_err ("cannot save privkey to file: %s, %s",
                                filename,
@@ -185,8 +190,10 @@ lua_rsa_privkey_save (lua_State *L)
                        lua_pushboolean (L, FALSE);
                }
                else {
-                       /* Set secure permissions for the private key file */
-                       chmod (filename, S_IRUSR | S_IWUSR);
+                       if (f != stdout) {
+                               /* Set secure permissions for the private key file */
+                               chmod(filename, S_IRUSR | S_IWUSR);
+                       }
 
                        if (strcmp (type, "der") == 0) {
                                ret = i2d_RSAPrivateKey_fp (f, rsa);