Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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 */
17 VALUE cConfig;
18 /* Document-class: OpenSSL::ConfigError
19 *
20 * General error for openssl library configuration files. Including formating,
21 * parsing errors, etc.
22 */
23 VALUE eConfigError;
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 *
36 GetConfigPtr(VALUE obj)
37 {
38 CONF *conf;
39 VALUE str;
40 BIO *bio;
41 long eline = -1;
42
43 OSSL_Check_Kind(obj, cConfig);
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);
49 ossl_raise(eConfigError, NULL);
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);
56 ossl_raise(eConfigError, NULL);
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
72 Init_ossl_config()
73 {
74 char *default_config_file;
75 eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError);
76 cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject);
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 }
mOSSL
VALUE mOSSL
Definition: ossl.c:259
Init_ossl_config
void Init_ossl_config()
Definition: ossl_config.c:72
rb_funcall
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:775
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:676
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1553
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2225
eOSSLError
VALUE eOSSLError
Definition: ossl.c:264
rb_str_new2
#define rb_str_new2
Definition: intern.h:840
eConfigError
VALUE eConfigError
Definition: ossl_config.c:23
ossl_obj2bio
BIO * ossl_obj2bio(VALUE obj)
Definition: ossl_bio.c:17
VALUE
unsigned long VALUE
Definition: ruby.h:88
GetConfigPtr
CONF * GetConfigPtr(VALUE obj)
Definition: ossl_config.c:36
OSSL_Check_Kind
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:96
ossl_raise
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:333
ossl.h
CONF_get1_default_config_file
char * CONF_get1_default_config_file(void)
Definition: openssl_missing.c:286
rb_intern
#define rb_intern(str)
NULL
#define NULL
Definition: _sdbm.c:103
cConfig
VALUE cConfig
Definition: ossl_config.c:17