summaryrefslogtreecommitdiffstats
path: root/proxy/src
diff options
context:
space:
mode:
Diffstat (limited to 'proxy/src')
-rw-r--r--proxy/src/gp_init.c107
-rw-r--r--proxy/src/gp_utils.h39
-rw-r--r--proxy/src/gssproxy.c24
3 files changed, 167 insertions, 3 deletions
diff --git a/proxy/src/gp_init.c b/proxy/src/gp_init.c
new file mode 100644
index 0000000..eed0380
--- /dev/null
+++ b/proxy/src/gp_init.c
@@ -0,0 +1,107 @@
+/*
+ GSS-PROXY
+
+ Copyright (C) 2011 Red Hat, Inc.
+ Copyright (C) 2011 Simo Sorce <simo.sorce@redhat.com>
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <locale.h>
+#include <syslog.h>
+#include <signal.h>
+#include "gp_utils.h"
+
+void init_server(void)
+{
+
+ /* Set strict umask by default */
+ umask(0177);
+
+ /* Set up neutral locale */
+ setlocale(LC_ALL, "");
+
+ openlog("gssproxy",
+ LOG_CONS|LOG_NDELAY|LOG_NOWAIT|LOG_PERROR|LOG_PID,
+ LOG_AUTHPRIV);
+
+}
+
+void fini_server(void)
+{
+ closelog();
+}
+
+static void break_loop(verto_ctx *vctx, verto_ev *ev)
+{
+ syslog(LOG_WARNING, "Exiting after receiving a signal");
+ verto_break(vctx);
+}
+
+static void reload_conf(verto_ctx *vctx, verto_ev *ev)
+{
+ syslog(LOG_INFO, "Reloading configuration after receiving a signal");
+ /* TODO */
+}
+
+verto_ctx *init_event_loop(void)
+{
+ verto_ctx *vctx;
+ verto_ev *ev;
+
+ vctx = verto_default(NULL,
+ VERTO_EV_TYPE_IO |
+ VERTO_EV_TYPE_SIGNAL |
+ VERTO_EV_TYPE_TIMEOUT);
+ if (!vctx) {
+ return NULL;
+ }
+
+ ev = verto_add_signal(vctx, VERTO_EV_FLAG_PERSIST, break_loop, SIGINT);
+ if (!ev) {
+ verto_free(vctx);
+ return NULL;
+ }
+ ev = verto_add_signal(vctx, VERTO_EV_FLAG_PERSIST, break_loop, SIGTERM);
+ if (!ev) {
+ verto_free(vctx);
+ return NULL;
+ }
+ ev = verto_add_signal(vctx, VERTO_EV_FLAG_PERSIST, break_loop, SIGQUIT);
+ if (!ev) {
+ verto_free(vctx);
+ return NULL;
+ }
+ ev = verto_add_signal(vctx, VERTO_EV_FLAG_PERSIST, reload_conf, SIGHUP);
+ if (!ev) {
+ verto_free(vctx);
+ return NULL;
+ }
+ ev = verto_add_signal(vctx, VERTO_EV_FLAG_PERSIST, VERTO_SIG_IGN, SIGPIPE);
+ if (!ev) {
+ verto_free(vctx);
+ return NULL;
+ }
+
+ return vctx;
+}
+
diff --git a/proxy/src/gp_utils.h b/proxy/src/gp_utils.h
new file mode 100644
index 0000000..51d62e7
--- /dev/null
+++ b/proxy/src/gp_utils.h
@@ -0,0 +1,39 @@
+/*
+ GSS-PROXY
+
+ Copyright (C) 2011 Red Hat, Inc.
+ Copyright (C) 2011 Simo Sorce <simo.sorce@redhat.com>
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef _SRV_UTILS_H_
+#define _SRV_UTILS_H_
+
+#include <libintl.h>
+#include "verto.h"
+
+#define _(STRING) gettext(STRING)
+
+/* from gp_init.c */
+void init_server(void);
+void fini_server(void);
+verto_ctx *init_event_loop(void);
+
+#endif /* _SRV_UTILS_H_ */
diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c
index ca9d533..d128d2b 100644
--- a/proxy/src/gssproxy.c
+++ b/proxy/src/gssproxy.c
@@ -24,10 +24,8 @@
*/
#include "config.h"
-#include <libintl.h>
#include "popt.h"
-
-#define _(STRING) gettext(STRING)
+#include "gp_utils.h"
int main(int argc, const char *argv[])
{
@@ -38,6 +36,10 @@ int main(int argc, const char *argv[])
int opt_version = 0;
char *opt_config_file = NULL;
char *config_file = NULL;
+ verto_ctx *vctx;
+ verto_ev *ev;
+ int vflags;
+ int fd;
struct poptOption long_options[] = {
POPT_AUTOHELP
@@ -87,5 +89,21 @@ int main(int argc, const char *argv[])
* 5. Profit
*/
+ init_server();
+
+ fd = init_unix_socket(GSS_PROXY_SOCKET_NAME);
+ if (fd == -1) {
+ return 1;
+ }
+
+ vctx = init_event_loop();
+ if (!vctx) {
+ return 1;
+ }
+
+ verto_run(vctx);
+
+ fini_server();
+
return 0;
}