Ruby  1.9.3p448(2013-06-27revision41675)
ossl_config.c
Go to the documentation of this file.
1 /*
2  * $Id: ossl_config.c 29359 2010-09-29 03:37:44Z nobu $
3  * 'OpenSSL for Ruby' project
4  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5  * All rights reserved.
6  */
7 /*
8  * This program is licenced under the same licence as Ruby.
9  * (See the file 'LICENCE'.)
10  */
11 #include "ossl.h"
12 
13 
14 /*
15  * Classes
16  */
19 
20 /*
21  * Public
22  */
23 
24 /*
25  * GetConfigPtr is a public C-level function for getting OpenSSL CONF struct
26  * from an OpenSSL::Config(eConfig) instance. We decided to implement
27  * OpenSSL::Config in Ruby level but we need to pass native CONF struct for
28  * some OpenSSL features such as X509V3_EXT_*.
29  */
30 CONF *
32 {
33  CONF *conf;
34  VALUE str;
35  BIO *bio;
36  long eline = -1;
37 
39  str = rb_funcall(obj, rb_intern("to_s"), 0);
40  bio = ossl_obj2bio(str);
41  conf = NCONF_new(NULL);
42  if(!conf){
43  BIO_free(bio);
45  }
46  if(!NCONF_load_bio(conf, bio, &eline)){
47  BIO_free(bio);
48  NCONF_free(conf);
49  if (eline <= 0) ossl_raise(eConfigError, "wrong config format");
50  else ossl_raise(eConfigError, "error in line %d", eline);
52  }
53  BIO_free(bio);
54 
55  return conf;
56 }
57 
58 
59 /*
60  * INIT
61  */
62 void
64 {
65  char *default_config_file;
68 
69  default_config_file = CONF_get1_default_config_file();
70  rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
71  rb_str_new2(default_config_file));
72  OPENSSL_free(default_config_file);
73  /* methods are defined by openssl/config.rb */
74 }
75