Mercurial > dropbear
comparison dbutil.c @ 1924:667937351c31
Fix tilde expansion of paths
(Part was missed from previous series of commits)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 30 Mar 2022 14:08:15 +0800 |
parents | 9382271da9ef |
children | 7ac3b6c380b1 |
comparison
equal
deleted
inserted
replaced
1923:ffa0f666fde2 | 1924:667937351c31 |
---|---|
631 *val = l; | 631 *val = l; |
632 return DROPBEAR_SUCCESS; | 632 return DROPBEAR_SUCCESS; |
633 } | 633 } |
634 } | 634 } |
635 | 635 |
636 /* Returns malloced path. inpath beginning with '/' is returned as-is, | 636 /* Returns malloced path. inpath beginning with '~/' expanded, |
637 otherwise home directory is prepended */ | 637 otherwise returned as-is */ |
638 char * expand_homedir_path(const char *inpath) { | 638 char * expand_homedir_path(const char *inpath) { |
639 struct passwd *pw = NULL; | 639 struct passwd *pw = NULL; |
640 if (inpath[0] != '/') { | 640 if (strncmp(inpath, "~/", 2) == 0) { |
641 char *homedir = getenv("HOME"); | 641 char *homedir = getenv("HOME"); |
642 | 642 |
643 if (!homedir) { | 643 if (!homedir) { |
644 pw = getpwuid(getuid()); | 644 pw = getpwuid(getuid()); |
645 if (pw) { | 645 if (pw) { |
646 homedir = pw->pw_dir; | 646 homedir = pw->pw_dir; |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 if (homedir) { | 650 if (homedir) { |
651 int len = strlen(inpath) + strlen(homedir) + 2; | 651 int len = strlen(inpath)-2 + strlen(homedir) + 2; |
652 char *buf = m_malloc(len); | 652 char *buf = m_malloc(len); |
653 snprintf(buf, len, "%s/%s", homedir, inpath); | 653 snprintf(buf, len, "%s/%s", homedir, inpath+2); |
654 return buf; | 654 return buf; |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 /* Fallback */ | 658 /* Fallback */ |