Ruby  2.1.10p492(2016-04-01revision54464)
ossl_config.c
Go to the documentation of this file.
1 /*
2  * $Id: ossl_config.c 43667 2013-11-13 09:34:08Z zzak $
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  */
18 /* Document-class: OpenSSL::ConfigError
19  *
20  * General error for openssl library configuration files. Including formating,
21  * parsing errors, etc.
22  */
24 
25 /*
26  * Public
27  */
28 
29 /*
30  * GetConfigPtr is a public C-level function for getting OpenSSL CONF struct
31  * from an OpenSSL::Config(eConfig) instance. We decided to implement
32  * OpenSSL::Config in Ruby level but we need to pass native CONF struct for
33  * some OpenSSL features such as X509V3_EXT_*.
34  */
35 CONF *
37 {
38  CONF *conf;
39  VALUE str;
40  BIO *bio;
41  long eline = -1;
42 
44  str = rb_funcall(obj, rb_intern("to_s"), 0);
45  bio = ossl_obj2bio(str);
46  conf = NCONF_new(NULL);
47  if(!conf){
48  BIO_free(bio);
50  }
51  if(!NCONF_load_bio(conf, bio, &eline)){
52  BIO_free(bio);
53  NCONF_free(conf);
54  if (eline <= 0) ossl_raise(eConfigError, "wrong config format");
55  else ossl_raise(eConfigError, "error in line %d", eline);
57  }
58  BIO_free(bio);
59 
60  return conf;
61 }
62 
63 /* Document-const: DEFAULT_CONFIG_FILE
64  *
65  * The default system configuration file for openssl
66  */
67 
68 /*
69  * INIT
70  */
71 void
73 {
74  char *default_config_file;
77 
78  default_config_file = CONF_get1_default_config_file();
79  rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
80  rb_str_new2(default_config_file));
81  OPENSSL_free(default_config_file);
82  /* methods are defined by openssl/config.rb */
83 }
VALUE mOSSL
Definition: ossl.c:259
void Init_ossl_config()
Definition: ossl_config.c:72
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:657
#define rb_str_new2
static VALUE char * str
Definition: tcltklib.c:3539
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2228
static VALUE VALUE obj
Definition: tcltklib.c:3150
VALUE eOSSLError
Definition: ossl.c:264
VALUE eConfigError
Definition: ossl_config.c:23
BIO * ossl_obj2bio(VALUE obj)
Definition: ossl_bio.c:17
CONF * GetConfigPtr(VALUE obj)
Definition: ossl_config.c:36
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:96
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1561
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:333
unsigned long VALUE
Definition: ripper.y:88
char * CONF_get1_default_config_file(void)
#define rb_intern(str)
#define NULL
Definition: _sdbm.c:102
VALUE cConfig
Definition: ossl_config.c:17