From 374ae17a4db2991cd3f8783068adc678a543f865 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 28 May 2015 14:50:12 +0200 Subject: [PATCH] split KKDCP config line parsing from config.c --- src/Makefile.am | 2 +- src/cfg.h | 2 + src/config-kkdcp.c | 109 +++++++++++++++++++++++++++++++++++++++++++++ src/config.c | 52 +-------------------- 4 files changed, 114 insertions(+), 51 deletions(-) create mode 100644 src/config-kkdcp.c diff --git a/src/Makefile.am b/src/Makefile.am index f7463629..c102df54 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -70,7 +70,7 @@ ACCT_SOURCES=acct/pam.c acct/pam.h acct/radius.c acct/radius.h ocserv_SOURCES = main.c main-auth.c worker-vpn.c worker-auth.c tlslib.c \ cookies.c main-misc.c ip-lease.c ip-lease.h \ - vpn.h cookies.h tlslib.h log.c tun.c tun.h \ + vpn.h cookies.h tlslib.h log.c tun.c tun.h config-kkdcp.c \ config.c worker-resume.c worker.h main-resume.c main.h \ worker-extras.c html.c html.h worker-http.c \ main-user.c worker-misc.c route-add.c route-add.h worker-privs.c \ diff --git a/src/cfg.h b/src/cfg.h index 4d26514d..122e90ad 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -55,4 +55,6 @@ void *radius_get_brackets_string(struct perm_cfg_st *config, const char *str); void *pam_get_brackets_string(struct perm_cfg_st *config, const char *str); void *plain_get_brackets_string(struct perm_cfg_st *config, const char *str); +void parse_kkdcp_string(char *str, int *socktype, char **_port, char **_server, char **_path, char **_realm); + #endif diff --git a/src/config-kkdcp.c b/src/config-kkdcp.c new file mode 100644 index 00000000..f8935651 --- /dev/null +++ b/src/config-kkdcp.c @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include + +#ifdef HAVE_GSSAPI + +#include +#include +#include +#include +#include + +static char *find_space(char *str) +{ + while(*str != 0 && c_isspace(*str) == 0) { + str++; + } + if (c_isspace(*str)) + return str; + return NULL; +} + +void parse_kkdcp_string(char *str, int *socktype, char **_port, char **_server, char **_path, char **_realm) +{ + char *path, *server, *port, *realm, *p; + + path = str; + realm = find_space(path); + if (realm == NULL) { + fprintf(stderr, "Cannot parse kkdcp string: %s\n", path); + exit(1); + } + + *realm = 0; + realm++; + while (c_isspace(*realm)) + realm++; + + server = find_space(realm); + if (server == NULL) { + fprintf(stderr, "Cannot parse kkdcp string: %s\n", realm); + exit(1); + } + + /* null terminate the realm */ + *server = 0; + server++; + + while (c_isspace(*server)) + server++; + + if (strncmp(server, "udp@", 4) == 0) { + *socktype = SOCK_DGRAM; + } else if (strncmp(server, "tcp@", 4) == 0) { + *socktype = SOCK_STREAM; + } else { + fprintf(stderr, "cannot handle protocol %s\n", server); + exit(1); + } + server += 4; + + p = strchr(server, ']'); + if (p == NULL) { /* IPv4 address or server.name:port */ + port = strchr(server, ':'); + } else { /* [::IPV6address]:PORT */ + port = strchr(p, ':'); + if (port) { + *p = 0; + p = strchr(server, '['); + if (p) + server = p+1; + } + } + + if (port == NULL) { + fprintf(stderr, "No server port specified in: %s\n", server); + exit(1); + } + *port = 0; + port++; + + *_port = port; + *_realm = realm; + *_path = path; + *_server = server; + + return; +} + +#endif diff --git a/src/config.c b/src/config.c index 806a3a70..ba33ea10 100644 --- a/src/config.c +++ b/src/config.c @@ -513,7 +513,7 @@ static void figure_acct_funcs(struct perm_cfg_st *config, const char *acct) static void parse_kkdcp(struct cfg_st *config, char **urlfw, unsigned urlfw_size) { unsigned i, j; - char *path, *server, *port, *realm, *p; + char *path, *server, *port, *realm; struct addrinfo hints, *res; int ret; struct kkdcp_st *kkdcp; @@ -528,57 +528,9 @@ static void parse_kkdcp(struct cfg_st *config, char **urlfw, unsigned urlfw_size config->kkdcp_size = 0; for (i=0;i