summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-02-27 15:23:05 +1100
committerdaurnimator <quae@daurnimator.com>2017-02-27 15:26:03 +1100
commit3d7180c36adb6b9be8f4bb9825d3e35eef146bf5 (patch)
tree95709f2dcbabe9550041f543a2570068f8a1649f
parentb4bf06dcb61dbd735b328f47d8a36afb856d5d16 (diff)
downloadluaossl-3d7180c36adb6b9be8f4bb9825d3e35eef146bf5.tar.gz
luaossl-3d7180c36adb6b9be8f4bb9825d3e35eef146bf5.tar.bz2
luaossl-3d7180c36adb6b9be8f4bb9825d3e35eef146bf5.zip
extension.new: Factor out conf loading to own function
-rw-r--r--src/openssl.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/openssl.c b/src/openssl.c
index fa7dd79..900b909 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -4958,6 +4958,25 @@ static _Bool xe_new_isder(const char *value, _Bool *crit) {
4958 return 0; 4958 return 0;
4959} /* xs_new_isder() */ 4959} /* xs_new_isder() */
4960 4960
4961static CONF* loadconf(lua_State *L, int idx) {
4962 CONF *conf;
4963 size_t len;
4964 const char *cdata = luaL_checklstring(L, idx, &len);
4965 BIO *bio = getbio(L);
4966 if (BIO_write(bio, cdata, len) < 0)
4967 return NULL;
4968
4969 if (!(conf = NCONF_new(NULL)))
4970 return NULL;
4971
4972 if (!NCONF_load_bio(conf, bio, NULL)) {
4973 NCONF_free(conf);
4974 return NULL;
4975 }
4976
4977 return conf;
4978}
4979
4961static int xe_new(lua_State *L) { 4980static int xe_new(lua_State *L) {
4962 const char *name = luaL_checkstring(L, 1); 4981 const char *name = luaL_checkstring(L, 1);
4963 const char *value = luaL_checkstring(L, 2); 4982 const char *value = luaL_checkstring(L, 2);
@@ -4991,13 +5010,7 @@ static int xe_new(lua_State *L) {
4991 return 1; 5010 return 1;
4992 } 5011 }
4993 5012
4994 BIO *bio = getbio(L); 5013 if (!(conf = loadconf(L, 3)))
4995 if (BIO_puts(bio, cdata) < 0)
4996 goto error;
4997
4998 if (!(conf = NCONF_new(NULL)))
4999 goto error;
5000 if (!NCONF_load_bio(conf, bio, NULL))
5001 goto error; 5014 goto error;
5002 5015
5003 ctx = &cbuf; 5016 ctx = &cbuf;