From 001ac591273afc4daf9b72a375c8e452b9051249 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 16 Jan 2019 14:11:03 +0000 Subject: [PATCH] Feature: Added auth backend "enforce_auth". Closes: #2348 --- src/Makefile.am | 3 ++- src/auth.c | 4 ++++ src/auth.h | 2 ++ src/auth_enforce_auth.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/auth_enforce_auth.c diff --git a/src/Makefile.am b/src/Makefile.am index a02637dd..f71ea1c3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -98,7 +98,8 @@ icecast_SOURCES = \ auth.c \ auth_htpasswd.c \ auth_anonymous.c \ - auth_static.c + auth_static.c \ + auth_enforce_auth.c if HAVE_CURL icecast_SOURCES += \ diff --git a/src/auth.c b/src/auth.c index e891ab1c..5fb57d6c 100644 --- a/src/auth.c +++ b/src/auth.c @@ -596,6 +596,10 @@ static int get_authenticator (auth_t *auth, config_options_t *options) if (auth_get_static_auth(auth, options) < 0) return -1; break; + } else if (strcmp(auth->type, AUTH_TYPE_ENFORCE_AUTH) == 0) { + if (auth_get_enforce_auth_auth(auth, options) < 0) + return -1; + break; } ICECAST_LOG_ERROR("Unrecognised authenticator type: \"%s\"", auth->type); diff --git a/src/auth.h b/src/auth.h index 91c4715c..873c45e9 100644 --- a/src/auth.h +++ b/src/auth.h @@ -34,6 +34,7 @@ #define AUTH_TYPE_LEGACY_PASSWORD "legacy-password" #define AUTH_TYPE_URL "url" #define AUTH_TYPE_HTPASSWD "htpasswd" +#define AUTH_TYPE_ENFORCE_AUTH "enforce-auth" #define MAX_ADMIN_COMMANDS 32 @@ -170,6 +171,7 @@ int auth_get_anonymous_auth(auth_t *auth, config_options_t *options); int auth_get_static_auth(auth_t *auth, config_options_t *options); int auth_get_url_auth(auth_t *authenticator, config_options_t *options); int auth_get_htpasswd_auth(auth_t *auth, config_options_t *options); +int auth_get_enforce_auth_auth(auth_t *auth, config_options_t *options); /* prototypes for auth.c */ void auth_initialise(void); diff --git a/src/auth_enforce_auth.c b/src/auth_enforce_auth.c new file mode 100644 index 00000000..045ed47c --- /dev/null +++ b/src/auth_enforce_auth.c @@ -0,0 +1,39 @@ +/* Icecast + * + * This program is distributed under the GNU General Public License, version 2. + * A copy of this license is included with this source. + * + * Copyright 2014-2019, Philipp "ph3-der-loewe" Schafft , + */ + +/** + * Client authentication functions + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "auth.h" +#include "client.h" + +#include "logging.h" +#define CATMODULE "auth_enforce_auth" + +static auth_result enforce_auth_auth(auth_client *auth_user) +{ + client_t *client = auth_user->client; + + if (client->password) + return AUTH_NOMATCH; + + return AUTH_FAILED; +} + +int auth_get_enforce_auth_auth(auth_t *authenticator, config_options_t *options) +{ + (void)options; + authenticator->authenticate_client = enforce_auth_auth; + authenticator->immediate = 1; + return 0; +}