@@ -100,6 +100,28 @@ static char *bundle_dest;
100
100
101
101
static FILE * mlf ;
102
102
103
+ /*
104
+ * Create a directory and its parents as needed.
105
+ */
106
+ static void
107
+ mkdirp (const char * dir )
108
+ {
109
+ struct stat sb ;
110
+ const char * sep ;
111
+ char * parent ;
112
+
113
+ if (stat (dir , & sb ) == 0 )
114
+ return ;
115
+ if ((sep = strrchr (dir , '/' )) != NULL ) {
116
+ parent = xasprintf ("%.*s" , (int )(sep - dir ), dir );
117
+ mkdirp (parent );
118
+ free (parent );
119
+ }
120
+ info ("creating %s" , dir );
121
+ if (mkdir (dir , 0755 ) != 0 )
122
+ err (1 , "mkdir %s" , dir );
123
+ }
124
+
103
125
/*
104
126
* Remove duplicate and trailing slashes from a path.
105
127
*/
@@ -685,7 +707,7 @@ save_trusted(void)
685
707
{
686
708
int ret ;
687
709
688
- /* save untrusted certs */
710
+ mkdirp ( trusted_dest );
689
711
ret = write_certs (trusted_dest , & trusted );
690
712
return (ret );
691
713
}
@@ -700,6 +722,7 @@ save_untrusted(void)
700
722
{
701
723
int ret ;
702
724
725
+ mkdirp (untrusted_dest );
703
726
ret = write_certs (untrusted_dest , & untrusted );
704
727
return (ret );
705
728
}
@@ -721,6 +744,7 @@ save_bundle(void)
721
744
} else {
722
745
dir = xasprintf ("%.*s" , (int )(sep - bundle_dest ), bundle_dest );
723
746
file = sep + 1 ;
747
+ mkdirp (dir );
724
748
}
725
749
ret = write_bundle (dir , file , & trusted );
726
750
free (dir );
@@ -995,17 +1019,17 @@ set_defaults(void)
995
1019
996
1020
if ((value = getenv ("TRUSTDESTDIR" )) != NULL ||
997
1021
(value = getenv ("CERTDESTDIR" )) != NULL )
998
- trusted_dest = xstrdup (value );
1022
+ trusted_dest = normalize_path (value );
999
1023
else
1000
1024
trusted_dest = expand_path (TRUSTED_PATH );
1001
1025
1002
1026
if ((value = getenv ("UNTRUSTDESTDIR" )) != NULL )
1003
- untrusted_dest = xstrdup (value );
1027
+ untrusted_dest = normalize_path (value );
1004
1028
else
1005
1029
untrusted_dest = expand_path (UNTRUSTED_PATH );
1006
1030
1007
1031
if ((value = getenv ("BUNDLE" )) != NULL )
1008
- bundle_dest = xstrdup (value );
1032
+ bundle_dest = normalize_path (value );
1009
1033
else
1010
1034
bundle_dest = expand_path (BUNDLE_PATH );
1011
1035
0 commit comments