Various fixes so Win32 compile may work. Convert GeneralNames to use safe stack.
[openssl.git] / crypto / x509v3 / v3_alt.c
index b8054eb6363c5f925f13a063f3ae6f17d809cb98..e9bfad80255a824a00b33edb1c69b5cdc142f9b2 100644 (file)
 #include "x509v3.h"
 
 #ifndef NOPROTO
-static STACK *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK *nval);
-static STACK *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK *nval);
-static int copy_email(X509V3_CTX *ctx, STACK *gens);
-static int copy_issuer(X509V3_CTX *ctx, STACK *gens);
+static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK *nval);
+static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK *nval);
+static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens);
+static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens);
 #else
 static STACK *v2i_issuer_alt();
 static STACK *v2i_subject_alt();
@@ -95,19 +95,20 @@ NULL, NULL, NULL},
 EXT_END
 };
 
-STACK *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, STACK *gens, STACK *ret)
+STACK *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
+                                STACK_OF(GENERAL_NAME) *gens, STACK *ret)
 {
        int i;
        GENERAL_NAME *gen;
-       for(i = 0; i < sk_num(gens); i++) {
-               gen = (GENERAL_NAME *)sk_value(gens, i);
+       for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
+               gen = sk_GENERAL_NAME_value(gens, i);
                ret = i2v_GENERAL_NAME(method, gen, ret);
        }
        return ret;
 }
 
 STACK *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen,
-            STACK *ret)
+                                                                STACK *ret)
 {
        char oline[256];
        unsigned char *p;
@@ -161,13 +162,13 @@ STACK *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen,
        return ret;
 }
 
-static STACK *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
-            STACK *nval)
+static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method,
+                                                X509V3_CTX *ctx, STACK *nval)
 {
-       STACK *gens = NULL;
+       STACK_OF(GENERAL_NAME) *gens = NULL;
        CONF_VALUE *cnf;
        int i;
-       if(!(gens = sk_new(NULL))) {
+       if(!(gens = sk_GENERAL_NAME_new(NULL))) {
                X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
                return NULL;
        }
@@ -180,21 +181,21 @@ static STACK *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
                        GENERAL_NAME *gen;
                        if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
                                                                 goto err; 
-                       sk_push(gens, (char *)gen);
+                       sk_GENERAL_NAME_push(gens, gen);
                }
        }
        return gens;
        err:
-       sk_pop_free(gens, GENERAL_NAME_free);
+       sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
        return NULL;
 }
 
 /* Append subject altname of issuer to issuer alt name of subject */
 
-static int copy_issuer(X509V3_CTX *ctx, STACK *gens)
+static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
 {
-       STACK *ialt;
-       char *gen;
+       STACK_OF(GENERAL_NAME) *ialt;
+       GENERAL_NAME *gen;
        X509_EXTENSION *ext;
        int i;
        if(ctx && (ctx->flags == CTX_TEST)) return 1;
@@ -205,19 +206,19 @@ static int copy_issuer(X509V3_CTX *ctx, STACK *gens)
         i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
        if(i < 0) return 1;
         if(!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
-                        !(ialt = (STACK *) X509V3_EXT_d2i(ext)) ) {
+                        !(ialt = X509V3_EXT_d2i(ext)) ) {
                X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR);
                goto err;
        }
 
-       for(i = 0; i < sk_num(ialt); i++) {
-               gen = sk_value(ialt, i);
-               if(!sk_push(gens, gen)) {
+       for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
+               gen = sk_GENERAL_NAME_value(ialt, i);
+               if(!sk_GENERAL_NAME_push(gens, gen)) {
                        X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE);
                        goto err;
                }
        }
-       sk_free(ialt);
+       sk_GENERAL_NAME_free(ialt);
 
        return 1;
                
@@ -226,13 +227,13 @@ static int copy_issuer(X509V3_CTX *ctx, STACK *gens)
        
 }
 
-static STACK *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
-            STACK *nval)
+static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method,
+                                                X509V3_CTX *ctx, STACK *nval)
 {
-       STACK *gens = NULL;
+       STACK_OF(GENERAL_NAME) *gens = NULL;
        CONF_VALUE *cnf;
        int i;
-       if(!(gens = sk_new(NULL))) {
+       if(!(gens = sk_GENERAL_NAME_new(NULL))) {
                X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
                return NULL;
        }
@@ -245,12 +246,12 @@ static STACK *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
                        GENERAL_NAME *gen;
                        if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
                                                                 goto err; 
-                       sk_push(gens, (char *)gen);
+                       sk_GENERAL_NAME_push(gens, gen);
                }
        }
        return gens;
        err:
-       sk_pop_free(gens, GENERAL_NAME_free);
+       sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
        return NULL;
 }
 
@@ -258,7 +259,7 @@ static STACK *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
  * GENERAL_NAMES
  */
 
-static int copy_email(X509V3_CTX *ctx, STACK *gens)
+static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
 {
        X509_NAME *nm;
        ASN1_IA5STRING *email = NULL;
@@ -287,7 +288,7 @@ static int copy_email(X509V3_CTX *ctx, STACK *gens)
                gen->d.ia5 = email;
                email = NULL;
                gen->type = GEN_EMAIL;
-               if(!sk_push(gens, (char *)gen)) {
+               if(!sk_GENERAL_NAME_push(gens, gen)) {
                        X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
                        goto err;
                }
@@ -304,30 +305,30 @@ static int copy_email(X509V3_CTX *ctx, STACK *gens)
        
 }
 
-STACK *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
-            STACK *nval)
+STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
+                                                X509V3_CTX *ctx, STACK *nval)
 {
        GENERAL_NAME *gen;
-       STACK *gens = NULL;
+       STACK_OF(GENERAL_NAME) *gens = NULL;
        CONF_VALUE *cnf;
        int i;
-       if(!(gens = sk_new(NULL))) {
+       if(!(gens = sk_GENERAL_NAME_new(NULL))) {
                X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
                return NULL;
        }
        for(i = 0; i < sk_num(nval); i++) {
                cnf = (CONF_VALUE *)sk_value(nval, i);
                if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err; 
-               sk_push(gens, (char *)gen);
+               sk_GENERAL_NAME_push(gens, gen);
        }
        return gens;
        err:
-       sk_pop_free(gens, GENERAL_NAME_free);
+       sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
        return NULL;
 }
 
 GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
-            CONF_VALUE *cnf)
+                                                        CONF_VALUE *cnf)
 {
 char is_string = 0;
 int type;