PR: 1854
[openssl.git] / apps / ca.c
index a659702d9162a6b1b2d83cfb1815cdffe87950ed..4f236cce2798c980a23fc92afae93abdaf49aa5e 100644 (file)
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -306,7 +306,8 @@ int MAIN(int argc, char **argv)
        ASN1_TIME *tmptm;
        ASN1_INTEGER *tmpser;
        char *f;
-       const char *p, **pp;
+       const char *p;
+       char * const *pp;
        int i,j;
        const EVP_MD *dgst=NULL;
        STACK_OF(CONF_VALUE) *attribs=NULL;
@@ -555,8 +556,10 @@ bad:
 
        if (badops)
                {
-               for (pp=ca_usage; (*pp != NULL); pp++)
-                       BIO_printf(bio_err,"%s",*pp);
+               const char **pp2;
+
+               for (pp2=ca_usage; (*pp2 != NULL); pp2++)
+                       BIO_printf(bio_err,"%s",*pp2);
                goto err;
                }
 
@@ -849,7 +852,11 @@ bad:
               that to access().  However, time's too short to do that just
               now.
            */
+#ifndef _WIN32
                if (access(outdir,R_OK|W_OK|X_OK) != 0)
+#else
+               if (_access(outdir,R_OK|W_OK|X_OK) != 0)
+#endif
                        {
                        BIO_printf(bio_err,"I am unable to access the %s directory\n",outdir);
                        perror(outdir);
@@ -876,9 +883,9 @@ bad:
        if (db == NULL) goto err;
 
        /* Lets check some fields */
-       for (i=0; i<sk_num(db->db->data); i++)
+       for (i=0; i<sk_PSTRING_num(db->db->data); i++)
                {
-               pp=(const char **)sk_value(db->db->data,i);
+               pp=sk_PSTRING_value(db->db->data,i);
                if ((pp[DB_type][0] != DB_TYPE_REV) &&
                        (pp[DB_rev_date][0] != '\0'))
                        {
@@ -931,7 +938,7 @@ bad:
 #endif
                TXT_DB_write(out,db->db);
                BIO_printf(bio_err,"%d entries loaded from the database\n",
-                       db->db->data->num);
+                          sk_PSTRING_num(db->db->data));
                BIO_printf(bio_err,"generating index\n");
                }
        
@@ -1102,9 +1109,9 @@ bad:
                        if (startdate == NULL)
                                ERR_clear_error();
                        }
-               if (startdate && !ASN1_UTCTIME_set_string(NULL,startdate))
+               if (startdate && !ASN1_TIME_set_string(NULL, startdate))
                        {
-                       BIO_printf(bio_err,"start date is invalid, it should be YYMMDDHHMMSSZ\n");
+                       BIO_printf(bio_err,"start date is invalid, it should be YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ\n");
                        goto err;
                        }
                if (startdate == NULL) startdate="today";
@@ -1116,9 +1123,9 @@ bad:
                        if (enddate == NULL)
                                ERR_clear_error();
                        }
-               if (enddate && !ASN1_UTCTIME_set_string(NULL,enddate))
+               if (enddate && !ASN1_TIME_set_string(NULL, enddate))
                        {
-                       BIO_printf(bio_err,"end date is invalid, it should be YYMMDDHHMMSSZ\n");
+                       BIO_printf(bio_err,"end date is invalid, it should be YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ\n");
                        goto err;
                        }
 
@@ -1396,14 +1403,14 @@ bad:
                if (!tmptm) goto err;
                X509_gmtime_adj(tmptm,0);
                X509_CRL_set_lastUpdate(crl, tmptm);    
-               X509_gmtime_adj(tmptm,(crldays*24+crlhours)*60*60 + crlsec);
+               X509_time_adj_ex(tmptm, crldays, crlhours*60*60 + crlsec, NULL);
                X509_CRL_set_nextUpdate(crl, tmptm);    
 
                ASN1_TIME_free(tmptm);
 
-               for (i=0; i<sk_num(db->db->data); i++)
+               for (i=0; i<sk_PSTRING_num(db->db->data); i++)
                        {
-                       pp=(const char **)sk_value(db->db->data,i);
+                       pp=sk_PSTRING_value(db->db->data,i);
                        if (pp[DB_type][0] == DB_TYPE_REV)
                                {
                                if ((r=X509_REVOKED_new()) == NULL) goto err;
@@ -2000,11 +2007,11 @@ again2:
 
        if (strcmp(startdate,"today") == 0)
                X509_gmtime_adj(X509_get_notBefore(ret),0);
-       else ASN1_UTCTIME_set_string(X509_get_notBefore(ret),startdate);
+       else ASN1_TIME_set_string(X509_get_notBefore(ret),startdate);
 
        if (enddate == NULL)
-               X509_gmtime_adj(X509_get_notAfter(ret),(long)60*60*24*days);
-       else ASN1_UTCTIME_set_string(X509_get_notAfter(ret),enddate);
+               X509_time_adj_ex(X509_get_notAfter(ret),days, 0, NULL);
+       else ASN1_TIME_set_string(X509_get_notAfter(ret),enddate);
 
        if (!X509_set_subject_name(ret,subject)) goto err;
 
@@ -2100,7 +2107,7 @@ again2:
                }
 
        BIO_printf(bio_err,"Certificate is to be certified until ");
-       ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ret));
+       ASN1_TIME_print(bio_err,X509_get_notAfter(ret));
        if (days) BIO_printf(bio_err," (%ld days)",days);
        BIO_printf(bio_err, "\n");
 
@@ -2390,17 +2397,9 @@ static int fix_data(int nid, int *type)
 
 static int check_time_format(const char *str)
        {
-       ASN1_UTCTIME tm;
-
-       tm.data=(unsigned char *)str;
-       tm.length=strlen(str);
-       tm.type=V_ASN1_UTCTIME;
-       return(ASN1_UTCTIME_check(&tm));
+       return ASN1_TIME_set_string(NULL, str);
        }
 
-static int index_name_cmp_nc(STRING *a, STRING *b)
-       { return index_name_cmp(a, b); }
-
 static int do_revoke(X509 *x509, CA_DB *db, int type, char *value)
        {
        ASN1_UTCTIME *tm=NULL;
@@ -2484,7 +2483,7 @@ static int do_revoke(X509 *x509, CA_DB *db, int type, char *value)
                goto err;
 
                }
-       else if (index_name_cmp_nc(row, rrow))
+       else if (index_name_cmp_noconst(row, rrow))
                {
                BIO_printf(bio_err,"ERROR:name does not match %s\n",
                           row[DB_name]);
@@ -2633,9 +2632,9 @@ static int do_updatedb (CA_DB *db)
        else
                a_y2k = 0;
 
-       for (i = 0; i < sk_num(db->db->data); i++)
+       for (i = 0; i < sk_PSTRING_num(db->db->data); i++)
                {
-               rrow = (char **) sk_value(db->db->data, i);
+               rrow = sk_PSTRING_value(db->db->data, i);
 
                if (rrow[DB_type][0] == 'V')
                        {