+ int i, nid, ne_num=0;
+
+ char *ne_name = NULL;
+ char *ne_value = NULL;
+
+ char *tmp = NULL;
+ char *p[2];
+
+ char *str_list[256];
+
+ p[0] = ",/";
+ p[1] = "=";
+
+ n = X509_NAME_new();
+
+ tmp = strtok(subject, p[0]);
+ while((tmp != NULL) && (ne_num < (sizeof str_list/sizeof *str_list)))
+ {
+ char *token = tmp;
+
+ while (token[0] == ' ')
+ token++;
+ str_list[ne_num] = token;
+
+ tmp = strtok(NULL, p[0]);
+ ne_num++;
+ }
+
+ for(i = 0; i < ne_num; i++)
+ {
+ ne_name = strtok(str_list[i], p[1]);
+ ne_value = strtok(NULL, p[1]);
+
+ if ((nid=OBJ_txt2nid(ne_name)) == NID_undef)
+ {
+ BIO_printf(bio_err, "Subject Attribute %s has no known NID, skipped\n", ne_name);
+ continue;
+ }
+
+ if (ne_value == NULL)
+ {
+ BIO_printf(bio_err, "No value provided for Subject Attribute %s, skipped\n", ne_name);
+ continue;
+ }
+
+ if (!X509_NAME_add_entry_by_NID(n, nid, chtype, (unsigned char*)ne_value, -1,-1,0))
+ {
+ X509_NAME_free(n);
+ return 0;
+ }
+ }
+
+ if (!X509_REQ_set_subject_name(req, n))
+ return 0;
+ X509_NAME_free(n);
+ return 1;
+}
+
+
+static int prompt_info(X509_REQ *req,
+ STACK_OF(CONF_VALUE) *dn_sk, char *dn_sect,
+ STACK_OF(CONF_VALUE) *attr_sk, char *attr_sect, int attribs,
+ unsigned long chtype)
+ {
+ int i;
+ char *p,*q;
+ char buf[100];
+ int nid;
+ long n_min,n_max;
+ char *type,*def,*value;
+ CONF_VALUE *v;
+ X509_NAME *subj;
+ subj = X509_REQ_get_subject_name(req);
+
+ if(!batch)
+ {
+ BIO_printf(bio_err,"You are about to be asked to enter information that will be incorporated\n");
+ BIO_printf(bio_err,"into your certificate request.\n");
+ BIO_printf(bio_err,"What you are about to enter is what is called a Distinguished Name or a DN.\n");
+ BIO_printf(bio_err,"There are quite a few fields but you can leave some blank\n");
+ BIO_printf(bio_err,"For some fields there will be a default value,\n");
+ BIO_printf(bio_err,"If you enter '.', the field will be left blank.\n");
+ BIO_printf(bio_err,"-----\n");
+ }
+
+
+ if (sk_CONF_VALUE_num(dn_sk))