]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - client_common.c
Merge topic branch t/openssl-3 into pu
[paraslash.git] / client_common.c
index 396fd88c894cda20e4f55a7955a9a4fe77e9633d..b6603f12aab51c55c9c60a5d0243295afa445581 100644 (file)
@@ -565,7 +565,7 @@ int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr,
        struct lls_parse_result *lpr;
        int ret, ll;
        struct client_task *ct;
-       char *kf = NULL, *user, *errctx, *home = para_homedir();
+       char *kf = NULL, *user, *errctx;
 
        ret = lls(lls_parse(argc, argv, cmd, &lpr, &errctx));
        if (ret < 0)
@@ -588,9 +588,16 @@ int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr,
                kf = para_strdup(CLIENT_OPT_STRING_VAL(KEY_FILE, lpr));
        else {
                struct stat statbuf;
-               kf = make_message("%s/.paraslash/key.%s", home, user);
+               const char *confdir = get_confdir();
+               kf = make_message("%s/key.%s", confdir, user);
                if (stat(kf, &statbuf) != 0) { /* assume file does not exist */
+                       const char *home = getenv("HOME");
                        free(kf);
+                       if (!home || !*home) {
+                               ret = -ERRNO_TO_PARA_ERROR(EINVAL);
+                               errctx = make_message("HOME unset or empty");
+                               goto out;
+                       }
                        kf = make_message("%s/.ssh/id_rsa", home);
                }
        }
@@ -605,7 +612,6 @@ int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr,
        *ct_ptr = ct;
        ret = lls_num_inputs(lpr);
 out:
-       free(home);
        if (ret < 0) {
                if (errctx)
                        PARA_ERROR_LOG("%s\n", errctx);