Remove some commented out code in libcrypto
[openssl.git] / crypto / x509v3 / v3_pmaps.c
1 /*
2  * Copyright 2003-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <stdio.h>
11 #include "internal/cryptlib.h"
12 #include <openssl/asn1t.h>
13 #include <openssl/conf.h>
14 #include <openssl/x509v3.h>
15 #include "ext_dat.h"
16
17 static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method,
18                                  X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
19 static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD
20                                                  *method, void *pmps, STACK_OF(CONF_VALUE)
21                                                  *extlist);
22
23 const X509V3_EXT_METHOD v3_policy_mappings = {
24     NID_policy_mappings, 0,
25     ASN1_ITEM_ref(POLICY_MAPPINGS),
26     0, 0, 0, 0,
27     0, 0,
28     i2v_POLICY_MAPPINGS,
29     v2i_POLICY_MAPPINGS,
30     0, 0,
31     NULL
32 };
33
34 ASN1_SEQUENCE(POLICY_MAPPING) = {
35         ASN1_SIMPLE(POLICY_MAPPING, issuerDomainPolicy, ASN1_OBJECT),
36         ASN1_SIMPLE(POLICY_MAPPING, subjectDomainPolicy, ASN1_OBJECT)
37 } ASN1_SEQUENCE_END(POLICY_MAPPING)
38
39 ASN1_ITEM_TEMPLATE(POLICY_MAPPINGS) =
40         ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, POLICY_MAPPINGS,
41                                                                 POLICY_MAPPING)
42 ASN1_ITEM_TEMPLATE_END(POLICY_MAPPINGS)
43
44 IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING)
45
46 static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD
47                                                  *method, void *a, STACK_OF(CONF_VALUE)
48                                                  *ext_list)
49 {
50     POLICY_MAPPINGS *pmaps = a;
51     POLICY_MAPPING *pmap;
52     int i;
53     char obj_tmp1[80];
54     char obj_tmp2[80];
55     for (i = 0; i < sk_POLICY_MAPPING_num(pmaps); i++) {
56         pmap = sk_POLICY_MAPPING_value(pmaps, i);
57         i2t_ASN1_OBJECT(obj_tmp1, 80, pmap->issuerDomainPolicy);
58         i2t_ASN1_OBJECT(obj_tmp2, 80, pmap->subjectDomainPolicy);
59         X509V3_add_value(obj_tmp1, obj_tmp2, &ext_list);
60     }
61     return ext_list;
62 }
63
64 static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method,
65                                  X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
66 {
67     POLICY_MAPPINGS *pmaps = NULL;
68     POLICY_MAPPING *pmap = NULL;
69     ASN1_OBJECT *obj1 = NULL, *obj2 = NULL;
70     CONF_VALUE *val;
71     int i;
72
73     if ((pmaps = sk_POLICY_MAPPING_new_null()) == NULL) {
74         X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE);
75         return NULL;
76     }
77
78     for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
79         val = sk_CONF_VALUE_value(nval, i);
80         if (!val->value || !val->name) {
81             X509V3err(X509V3_F_V2I_POLICY_MAPPINGS,
82                       X509V3_R_INVALID_OBJECT_IDENTIFIER);
83             X509V3_conf_err(val);
84             goto err;
85         }
86         obj1 = OBJ_txt2obj(val->name, 0);
87         obj2 = OBJ_txt2obj(val->value, 0);
88         if (!obj1 || !obj2) {
89             X509V3err(X509V3_F_V2I_POLICY_MAPPINGS,
90                       X509V3_R_INVALID_OBJECT_IDENTIFIER);
91             X509V3_conf_err(val);
92             goto err;
93         }
94         pmap = POLICY_MAPPING_new();
95         if (pmap == NULL) {
96             X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE);
97             goto err;
98         }
99         pmap->issuerDomainPolicy = obj1;
100         pmap->subjectDomainPolicy = obj2;
101         obj1 = obj2 = NULL;
102         sk_POLICY_MAPPING_push(pmaps, pmap);
103     }
104     return pmaps;
105  err:
106     ASN1_OBJECT_free(obj1);
107     ASN1_OBJECT_free(obj2);
108     sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free);
109     return NULL;
110 }