@@ -139,6 +139,8 @@ main (int argc, const char **argv)
139
139
int cert_mode = 0644 ;
140
140
int cert_key_mode = 0600 ;
141
141
142
+ char * create_mode = NULL ;
143
+
142
144
struct sscg_x509_cert * cacert ;
143
145
struct sscg_evp_pkey * cakey ;
144
146
struct sscg_x509_cert * svc_cert ;
@@ -201,6 +203,13 @@ main (int argc, const char **argv)
201
203
0 ,
202
204
_ ("Display the version number and exit." ),
203
205
NULL },
206
+ { "force" ,
207
+ 'f' ,
208
+ POPT_ARG_NONE ,
209
+ & options -> overwrite ,
210
+ 0 ,
211
+ _ ("Overwrite any pre-existing files in the requested locations" ),
212
+ NULL },
204
213
{ "lifetime" ,
205
214
'\0' ,
206
215
POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT ,
@@ -610,14 +619,25 @@ main (int argc, const char **argv)
610
619
611
620
/* ==== Output the final files ==== */
612
621
622
+ /* Set the file-creation mode */
623
+ if (options -> overwrite )
624
+ {
625
+ create_mode = talloc_strdup (main_ctx , "w" );
626
+ }
627
+ else
628
+ {
629
+ create_mode = talloc_strdup (main_ctx , "wx" );
630
+ }
631
+ CHECK_MEM (create_mode );
632
+
613
633
/* Create certificate private key file */
614
634
if (options -> verbosity >= SSCG_DEFAULT )
615
635
{
616
636
fprintf (
617
637
stdout , "Writing svc private key to %s \n" , options -> cert_key_file );
618
638
}
619
639
620
- cert_key_out = BIO_new_file (options -> cert_key_file , "w" );
640
+ cert_key_out = BIO_new_file (options -> cert_key_file , create_mode );
621
641
CHECK_BIO (cert_key_out , options -> cert_key_file );
622
642
623
643
sret = PEM_write_bio_PrivateKey (
@@ -650,7 +670,7 @@ main (int argc, const char **argv)
650
670
}
651
671
else
652
672
{
653
- cert_out = BIO_new_file (options -> cert_file , "w" );
673
+ cert_out = BIO_new_file (options -> cert_file , create_mode );
654
674
}
655
675
CHECK_BIO (cert_out , options -> cert_file );
656
676
@@ -696,7 +716,7 @@ main (int argc, const char **argv)
696
716
}
697
717
else
698
718
{
699
- ca_key_out = BIO_new_file (options -> ca_key_file , "w" );
719
+ ca_key_out = BIO_new_file (options -> ca_key_file , create_mode );
700
720
}
701
721
CHECK_BIO (ca_key_out , options -> ca_key_file );
702
722
@@ -728,7 +748,7 @@ main (int argc, const char **argv)
728
748
}
729
749
else
730
750
{
731
- ca_out = BIO_new_file (options -> ca_file , "w" );
751
+ ca_out = BIO_new_file (options -> ca_file , create_mode );
732
752
}
733
753
CHECK_BIO (ca_out , options -> ca_file );
734
754
0 commit comments