Ruby  2.0.0p594(2014-10-27revision48167)
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 }
VALUE mOSSL
Definition: ossl.c:259
void Init_ossl_config()
Definition: ossl_config.c:63
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:773
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:549
#define rb_str_new2
static VALUE char * str
Definition: tcltklib.c:3546
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2204
static VALUE VALUE obj
Definition: tcltklib.c:3157
VALUE eOSSLError
Definition: ossl.c:264
VALUE eConfigError
Definition: ossl_config.c:18
BIO * ossl_obj2bio(VALUE obj)
Definition: ossl_bio.c:17
CONF * GetConfigPtr(VALUE obj)
Definition: ossl_config.c:31
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:96
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1426
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:333
unsigned long VALUE
Definition: ripper.y:104
char * CONF_get1_default_config_file(void)
#define rb_intern(str)
#define NULL
Definition: _sdbm.c:103
VALUE cConfig
Definition: ossl_config.c:17