Skip to content

Commit f5fb025

Browse files
Günther Deschnersimo5
authored andcommitted
Add dinglibs ini configuration detection and backend.
Signed-off-by: Günther Deschner <[email protected]> Reviewed-by: Simo Sorce <[email protected]>
1 parent 19d091b commit f5fb025

File tree

5 files changed

+302
-0
lines changed

5 files changed

+302
-0
lines changed

proxy/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ AM_CPPFLAGS = \
7171
-I. \
7272
$(POPT_CFLAGS) \
7373
$(GSSAPI_CFLAGS) \
74+
$(INI_CFLAGS) \
7475
-DLIBDIR=\"$(libdir)\" \
7576
-DVARDIR=\"$(localstatedir)\" \
7677
-DSHLIBEXT=\"$(SHLIBEXT)\" \
@@ -128,6 +129,7 @@ dist_noinst_HEADERS = \
128129
src/gp_conv.h \
129130
src/gp_config.h \
130131
src/gp_config_iniparser.h \
132+
src/gp_config_dinglibs.h \
131133
src/gp_debug.h \
132134
src/gp_rpc_creds.h \
133135
src/mechglue/gss_plugin.h
@@ -140,6 +142,7 @@ dist_noinst_HEADERS = \
140142
gssproxy_SOURCES = \
141143
src/gp_config.c \
142144
src/gp_config_iniparser.c \
145+
src/gp_config_dinglibs.c \
143146
src/gp_init.c \
144147
src/gp_socket.c \
145148
src/gp_workers.c \

proxy/configure.ac

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,22 @@ AC_CHECK_HEADERS([iniparser.h],
9090
[AC_MSG_ERROR([Iniparser development package is not installed])]
9191
)
9292

93+
#Check for libini_config
94+
PKG_CHECK_MODULES([LIBINI_CONFIG], [ini_config >= 1.0.0], [have_libini_config=1], [have_libini_config=])
95+
if test x$have_libini_config = x; then
96+
AC_MSG_WARN([Could not find LIBINI_CONFIG headers])
97+
else
98+
INI_CONFIG_CFLAGS="`$PKG_CONFIG --cflags ini_config`"
99+
INI_CONFIG_LIBS="`$PKG_CONFIG --libs ini_config`"
100+
AC_CHECK_LIB(ini_config, ini_config_file_open,
101+
[INI_LIBS="$INI_LIBS $INI_CONFIG_LIBS"; INI_CFLAGS="$INI_CONFIG_CFLAGS";
102+
AC_DEFINE([HAVE_DINGLIBS], [1], [Dinglibs library available.])],
103+
[AC_MSG_WARN([ini_config library must support ini_config_file_open])],
104+
[$INI_CONFIG_LIBS])
105+
fi
106+
93107
AC_SUBST(INI_LIBS)
108+
AC_SUBST(INI_CFLAGS)
94109

95110
AX_PTHREAD(,[AC_MSG_ERROR([Could not find Pthreads support])])
96111

proxy/src/gp_config.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,44 @@ int gp_config_close(struct gp_ini_context *ctx)
399399
}
400400

401401
#endif /* WITH_INIPARSER */
402+
403+
#ifdef WITH_DINGLIBS
404+
#include "gp_config_dinglibs.h"
405+
406+
int gp_config_init(const char *config_file,
407+
struct gp_ini_context *ctx)
408+
{
409+
return gp_dinglibs_init(config_file, ctx);
410+
}
411+
412+
char *gp_config_get_string(struct gp_ini_context *ctx,
413+
const char *secname,
414+
const char *keyname)
415+
{
416+
return gp_dinglibs_get_string(ctx, secname, keyname);
417+
}
418+
419+
int gp_config_get_int(struct gp_ini_context *ctx,
420+
const char *secname,
421+
const char *keyname)
422+
{
423+
return gp_dinglibs_get_int(ctx, secname, keyname);
424+
}
425+
426+
int gp_config_get_nsec(struct gp_ini_context *ctx)
427+
{
428+
return gp_dinglibs_get_nsec(ctx);
429+
}
430+
431+
char *gp_config_get_secname(struct gp_ini_context *ctx,
432+
int i)
433+
{
434+
return gp_dinglibs_get_secname(ctx, i);
435+
}
436+
437+
int gp_config_close(struct gp_ini_context *ctx)
438+
{
439+
return gp_dinglibs_close(ctx);
440+
}
441+
442+
#endif /* WITH_DINGLIBS */

proxy/src/gp_config_dinglibs.c

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/*
2+
GSS-PROXY
3+
4+
Copyright (C) 2011 Red Hat, Inc.
5+
Copyright (C) 2011 Simo Sorce <[email protected]>
6+
Copyright (C) 2012-2013 Guenther Deschner <[email protected]>
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a
9+
copy of this software and associated documentation files (the "Software"),
10+
to deal in the Software without restriction, including without limitation
11+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+
and/or sell copies of the Software, and to permit persons to whom the
13+
Software is furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
DEALINGS IN THE SOFTWARE.
25+
*/
26+
27+
#include "config.h"
28+
#include <stdio.h>
29+
#include <stdlib.h>
30+
#include <string.h>
31+
#include <errno.h>
32+
#include "gp_proxy.h"
33+
#include "gp_config.h"
34+
#include "gp_config_dinglibs.h"
35+
36+
#ifdef HAVE_DINGLIBS
37+
38+
#include <ini_configobj.h>
39+
40+
char *gp_dinglibs_get_string(struct gp_ini_context *ctx,
41+
const char *secname,
42+
const char *key)
43+
{
44+
struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data;
45+
struct value_obj *vo = NULL;
46+
const char *value;
47+
int ret;
48+
49+
ret = ini_get_config_valueobj(secname,
50+
key,
51+
ini_config,
52+
INI_GET_FIRST_VALUE,
53+
&vo);
54+
if (ret || !vo) {
55+
return NULL;
56+
}
57+
58+
value = ini_get_const_string_config_value(vo, &ret);
59+
if (ret) {
60+
return NULL;
61+
}
62+
63+
return value;
64+
}
65+
66+
int gp_dinglibs_get_int(struct gp_ini_context *ctx,
67+
const char *secname,
68+
const char *key)
69+
{
70+
struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data;
71+
struct value_obj *vo = NULL;
72+
int value;
73+
int ret;
74+
75+
ret = ini_get_config_valueobj(secname,
76+
key,
77+
ini_config,
78+
INI_GET_FIRST_VALUE,
79+
&vo);
80+
81+
if (ret || !vo) {
82+
return -1;
83+
}
84+
85+
value = ini_get_int_config_value(vo,
86+
0, /* strict */
87+
0, /* default */
88+
&ret);
89+
if (ret) {
90+
return -1;
91+
}
92+
93+
return value;
94+
}
95+
96+
int gp_dinglibs_init(const char *config_file,
97+
struct gp_ini_context *ctx)
98+
{
99+
struct ini_cfgobj *ini_config = NULL;
100+
struct ini_cfgfile *file_ctx = NULL;
101+
int ret;
102+
103+
if (!ctx) {
104+
return EINVAL;
105+
}
106+
107+
ret = ini_config_create(&ini_config);
108+
if (ret) {
109+
return ENOENT;
110+
}
111+
112+
ret = ini_config_file_open(config_file,
113+
0, /* metadata_flags, FIXME */
114+
&file_ctx);
115+
if (ret) {
116+
GPDEBUG("Failed to open config file: %d (%s)\n",
117+
ret, strerror(ret));
118+
ini_config_destroy(ini_config);
119+
return ret;
120+
}
121+
122+
ret = ini_config_parse(file_ctx,
123+
INI_STOP_ON_NONE, /* error_level */
124+
/* Merge section but allow duplicates */
125+
INI_MS_MERGE |
126+
INI_MV1S_ALLOW |
127+
INI_MV2S_ALLOW,
128+
INI_PARSE_NOWRAP, /* parse_flags */
129+
ini_config);
130+
if (ret) {
131+
/* we had a parsing failure */
132+
GPDEBUG("Failed to parse config file: %d (%s)\n",
133+
ret, strerror(ret));
134+
ini_config_file_destroy(file_ctx);
135+
ini_config_destroy(ini_config);
136+
return ret;
137+
}
138+
139+
ini_config_file_destroy(file_ctx);
140+
141+
ctx->private_data = ini_config;
142+
143+
return 0;
144+
}
145+
146+
int gp_dinglibs_close(struct gp_ini_context *ctx)
147+
{
148+
struct ini_cfgobj *ini_config = NULL;
149+
150+
if (!ctx) {
151+
return 0;
152+
}
153+
154+
ini_config = (struct ini_cfgobj *)ctx->private_data;
155+
156+
ini_config_destroy(ini_config);
157+
158+
return 0;
159+
}
160+
161+
int gp_dinglibs_get_nsec(struct gp_ini_context *ctx)
162+
{
163+
struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data;
164+
char **list = NULL;
165+
int count;
166+
int error;
167+
168+
list = ini_get_section_list(ini_config, &count, &error);
169+
if (error) {
170+
return 0;
171+
}
172+
173+
ini_free_section_list(list);
174+
175+
return count;
176+
}
177+
178+
char *gp_dinglibs_get_secname(struct gp_ini_context *ctx,
179+
int i)
180+
{
181+
struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data;
182+
char **list = NULL;
183+
int count;
184+
int error;
185+
char *secname;
186+
187+
list = ini_get_section_list(ini_config, &count, &error);
188+
if (error) {
189+
return NULL;
190+
}
191+
192+
if (i >= count) {
193+
return NULL;
194+
}
195+
196+
secname = strdup(list[i]);
197+
ini_free_section_list(list);
198+
if (!secname) {
199+
return NULL;
200+
}
201+
202+
return secname;
203+
}
204+
205+
#endif /* HAVE_DINGLIBS */

proxy/src/gp_config_dinglibs.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
GSS-PROXY
3+
4+
Copyright (C) 2011 Red Hat, Inc.
5+
Copyright (C) 2011 Simo Sorce <[email protected]>
6+
Copyright (C) 2012-2013 Guenther Deschner <[email protected]>
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a
9+
copy of this software and associated documentation files (the "Software"),
10+
to deal in the Software without restriction, including without limitation
11+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+
and/or sell copies of the Software, and to permit persons to whom the
13+
Software is furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
DEALINGS IN THE SOFTWARE.
25+
*/
26+
27+
char *gp_dinglibs_get_string(struct gp_ini_context *ctx,
28+
const char *secname,
29+
const char *key);
30+
int gp_dinglibs_get_int(struct gp_ini_context *ctx,
31+
const char *secname,
32+
const char *key);
33+
int gp_dinglibs_init(const char *config_file,
34+
struct gp_ini_context *ctx);
35+
int gp_dinglibs_close(struct gp_ini_context *ctx);
36+
int gp_dinglibs_get_nsec(struct gp_ini_context *ctx);
37+
char *gp_dinglibs_get_secname(struct gp_ini_context *ctx,
38+
int i);

0 commit comments

Comments
 (0)