2005-08-07 19:01:04 -04:00
|
|
|
/* Icecast
|
|
|
|
*
|
|
|
|
* This program is distributed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license is included with this source.
|
|
|
|
*
|
2015-01-10 13:53:44 -05:00
|
|
|
* Copyright 2000-2004, Jack Moffitt <jack@xiph.org,
|
2005-08-07 19:01:04 -04:00
|
|
|
* Michael Smith <msmith@xiph.org>,
|
|
|
|
* oddsock <oddsock@xiph.org>,
|
|
|
|
* Karl Heyes <karl@xiph.org>
|
|
|
|
* and others (see AUTHORS for details).
|
Wow. Mega patch!
This patch *replaces* the authentication system completly.
What is new:
- <authentication> in mount section is now a container object.
- <authentication> in root and mount section may hold any number of <role>-Tags.
- <role> tags:
Those tags define a 'role' and it's ACL rules.
A role is a instance of an authentication module (see below).
<role> takes the following options. All but type are optional.
- authentication related:
- type: Type of the authentication module (values: anonymous, static, legacy-password, url or htpasswd;
symbolic constants in auth.h)
- name: Name for the role. For later matching. (values: any string; default: (none))
- method: This rule is only active on the given list of HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- ACL related:
- allow-method: Allowed HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: get)
- deny-method: Rejected HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- allow-admin: Allowed admin commands. (list of enum values: admin command; default: buildm3u)
- deny-admin: Rejected admin commands. (list of enum values: admin command; default: *)
- allow-web: Allowed web pages. (values: empty or *; default: *)
- deny-web: Rejected web pages. (values: empty or *; default: (empty))
- connections-per-user: maximum number of simultaneous connections per role and username.
This is only active on active sources. (values: unlimited or number of connections; default: unlimited)
- connection-duration: maximum time of a connection. This is only active on active sources.
(values: unlimited or number of secounds; default: unlimited)
<role> takes <option> child tags. <option> tags contain a name and a value option.
Meaning of <option> tags is up to the authentication module.
- <role>s are considered to build a stack. If a role returns with AUTH_NOMATCH the next one will be tried.
- <role>s are tested in this order: mount specific, default mount specific, global, internal fallback.
Internal fallback is set to allow web/ access via GET, POST and HEAD (only GET supported by this time)
and rejects all other requests.
- New authentication module: anonymous
This module matches all requests. No options taken.
- New authentication module: static
This module matches with a static username and password.
It takes two <option>s. One with name="username" and one with name="password" to set username and password.
This replaces old style <*-username> and <*-password> tags.
- New authentication module: legacy-password
This module matches with a statich password.
It takes one <option> with name="password" to set password.
This replaces old ICE and ICY (shoutcast compat mode) authentication.
- Parsing <authentication> in <mount> with a type set in a special way to allow 100% backward compatibility.
- Parsing of <source-password>, <admin-password>, <admin-user>, <relay-password> and <relay-user> in global
<authentication> for 100% backward compatibility.
- <alias> is now proccessed very early. This enables them to be used for all kinds of requests.
To Do List & What does not yet work:
- type="url" auth: mount_add and mount_remove.
This should be replaced by an unique feature I would call '<event>'.
- Admin commands manageauth and manageauth.xsl are disabled as they need more review:
This code needs to be ported to support multiple <role>s per <mount>.
- url authentication module can not yet return AUTH_NOMATCH.
This needs to be reviewed and discussed on how to handle this case best way.
- Default config files needs to be updated to reflect the changes.
As this is quite some political act it should be done in dicussion with the whole team
and permission of the release manager.
- Docs need to be updated to reflect the changes.
How does it work:
Code has been changed so that authentification is done early for all clients.
This allows accessing the ACL data (client->acl) from nearly everywhere in the code.
After accept() and initial client setup the request is parsed. In the next step
all <alias>es are resolved. After this the client is passed for authentication.
After authentication it is passed to the corresponding subsystem depending on kind of request.
All authentication instances have a thread running for doing the authentication.
This thread works on a queue of clients.
Hints for testers:
- Test with default config.
- Test with diffrent authentication modules in <mount>.
- Test shoutcast compatibility mode.
- Test with new style <authentication> and any amount of <role> (zero to quite some).
- Test <alias> lookup on all kinds of objects.
- Test source level credential login into the admin interface.
- Test shoucast style meta data updates.
- Test playlist generation.
Thank you for reading this long commit message. Have fun reading the full patch!
svn path=/icecast/trunk/icecast/; revision=19358
2014-11-28 18:46:08 -05:00
|
|
|
* Copyright 2012-2014, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
|
2005-08-07 19:01:04 -04:00
|
|
|
*/
|
|
|
|
|
2015-01-10 13:53:44 -05:00
|
|
|
/**
|
2005-08-07 19:01:04 -04:00
|
|
|
* Client authentication functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "auth.h"
|
|
|
|
#include "source.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "cfgfile.h"
|
2014-12-02 16:50:57 -05:00
|
|
|
#include "common/httpp/httpp.h"
|
2005-08-07 19:01:04 -04:00
|
|
|
#include "md5.h"
|
|
|
|
|
|
|
|
#include "logging.h"
|
|
|
|
#define CATMODULE "auth_htpasswd"
|
2012-10-12 10:41:12 -04:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
2005-08-07 19:01:04 -04:00
|
|
|
|
|
|
|
static auth_result htpasswd_adduser (auth_t *auth, const char *username, const char *password);
|
|
|
|
static auth_result htpasswd_deleteuser(auth_t *auth, const char *username);
|
|
|
|
static auth_result htpasswd_userlist(auth_t *auth, xmlNodePtr srcnode);
|
|
|
|
static int _free_user (void *key);
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
typedef struct {
|
2005-08-07 19:01:04 -04:00
|
|
|
char *name;
|
|
|
|
char *pass;
|
|
|
|
} htpasswd_user;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *filename;
|
|
|
|
rwlock_t file_rwlock;
|
|
|
|
avl_tree *users;
|
|
|
|
time_t mtime;
|
|
|
|
} htpasswd_auth_state;
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
static void htpasswd_clear(auth_t *self)
|
|
|
|
{
|
2005-08-07 19:01:04 -04:00
|
|
|
htpasswd_auth_state *state = self->state;
|
|
|
|
free(state->filename);
|
|
|
|
if (state->users)
|
|
|
|
avl_tree_free (state->users, _free_user);
|
|
|
|
thread_rwlock_destroy(&state->file_rwlock);
|
|
|
|
free(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* md5 hash */
|
|
|
|
static char *get_hash(const char *data, int len)
|
|
|
|
{
|
|
|
|
struct MD5Context context;
|
|
|
|
unsigned char digest[16];
|
|
|
|
|
|
|
|
MD5Init(&context);
|
|
|
|
|
2007-10-04 12:48:38 -04:00
|
|
|
MD5Update(&context, (const unsigned char *)data, len);
|
2005-08-07 19:01:04 -04:00
|
|
|
|
|
|
|
MD5Final(digest, &context);
|
|
|
|
|
|
|
|
return util_bin_to_hex(digest, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
static int compare_users(void *arg, void *a, void *b)
|
2005-08-07 19:01:04 -04:00
|
|
|
{
|
|
|
|
htpasswd_user *user1 = (htpasswd_user *)a;
|
|
|
|
htpasswd_user *user2 = (htpasswd_user *)b;
|
|
|
|
|
2015-11-28 06:30:34 -05:00
|
|
|
(void)arg;
|
|
|
|
|
2005-08-07 19:01:04 -04:00
|
|
|
return strcmp (user1->name, user2->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
static int _free_user(void *key)
|
2005-08-07 19:01:04 -04:00
|
|
|
{
|
|
|
|
htpasswd_user *user = (htpasswd_user *)key;
|
|
|
|
|
|
|
|
free (user->name); /* ->pass is part of same buffer */
|
|
|
|
free (user);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd)
|
2005-08-07 19:01:04 -04:00
|
|
|
{
|
|
|
|
FILE *passwdfile;
|
|
|
|
avl_tree *new_users;
|
|
|
|
int num = 0;
|
|
|
|
struct stat file_stat;
|
|
|
|
char *sep;
|
|
|
|
char line [MAX_LINE_LEN];
|
|
|
|
|
2008-09-30 21:07:29 -04:00
|
|
|
if (htpasswd->filename == NULL)
|
|
|
|
return;
|
2015-01-25 13:57:27 -05:00
|
|
|
if (stat (htpasswd->filename, &file_stat) < 0) {
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_WARN("failed to check status of %s", htpasswd->filename);
|
2005-08-30 16:29:20 -04:00
|
|
|
|
|
|
|
/* Create a dummy users tree for things to use later */
|
|
|
|
thread_rwlock_wlock (&htpasswd->file_rwlock);
|
|
|
|
if(!htpasswd->users)
|
|
|
|
htpasswd->users = avl_tree_new(compare_users, NULL);
|
|
|
|
thread_rwlock_unlock (&htpasswd->file_rwlock);
|
|
|
|
|
2005-08-07 19:01:04 -04:00
|
|
|
return;
|
|
|
|
}
|
2005-08-30 16:29:20 -04:00
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
if (file_stat.st_mtime == htpasswd->mtime) {
|
2005-08-07 19:01:04 -04:00
|
|
|
/* common case, no update to file */
|
|
|
|
return;
|
|
|
|
}
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_INFO("re-reading htpasswd file \"%s\"", htpasswd->filename);
|
2005-08-07 19:01:04 -04:00
|
|
|
passwdfile = fopen (htpasswd->filename, "rb");
|
2015-01-25 13:57:27 -05:00
|
|
|
if (passwdfile == NULL) {
|
2015-01-10 13:53:44 -05:00
|
|
|
ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s",
|
2005-08-07 19:01:04 -04:00
|
|
|
htpasswd->filename, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
htpasswd->mtime = file_stat.st_mtime;
|
|
|
|
|
|
|
|
new_users = avl_tree_new (compare_users, NULL);
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
while (get_line(passwdfile, line, MAX_LINE_LEN)) {
|
2005-08-07 19:01:04 -04:00
|
|
|
int len;
|
|
|
|
htpasswd_user *entry;
|
|
|
|
|
|
|
|
num++;
|
2014-11-30 15:32:30 -05:00
|
|
|
if (!line[0] || line[0] == '#')
|
2005-08-07 19:01:04 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
sep = strrchr (line, ':');
|
2015-01-25 13:57:27 -05:00
|
|
|
if (sep == NULL) {
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_WARN("No separator on line %d (%s)", num, htpasswd->filename);
|
2005-08-07 19:01:04 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
entry = calloc (1, sizeof (htpasswd_user));
|
|
|
|
len = strlen (line) + 1;
|
|
|
|
entry->name = malloc (len);
|
|
|
|
*sep = 0;
|
|
|
|
memcpy (entry->name, line, len);
|
|
|
|
entry->pass = entry->name + (sep-line) + 1;
|
|
|
|
avl_insert (new_users, entry);
|
|
|
|
}
|
|
|
|
fclose (passwdfile);
|
|
|
|
|
|
|
|
thread_rwlock_wlock (&htpasswd->file_rwlock);
|
|
|
|
if (htpasswd->users)
|
|
|
|
avl_tree_free (htpasswd->users, _free_user);
|
|
|
|
htpasswd->users = new_users;
|
|
|
|
thread_rwlock_unlock (&htpasswd->file_rwlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static auth_result htpasswd_auth (auth_client *auth_user)
|
|
|
|
{
|
|
|
|
auth_t *auth = auth_user->client->auth;
|
|
|
|
htpasswd_auth_state *htpasswd = auth->state;
|
|
|
|
client_t *client = auth_user->client;
|
|
|
|
htpasswd_user entry;
|
|
|
|
void *result;
|
|
|
|
|
Wow. Mega patch!
This patch *replaces* the authentication system completly.
What is new:
- <authentication> in mount section is now a container object.
- <authentication> in root and mount section may hold any number of <role>-Tags.
- <role> tags:
Those tags define a 'role' and it's ACL rules.
A role is a instance of an authentication module (see below).
<role> takes the following options. All but type are optional.
- authentication related:
- type: Type of the authentication module (values: anonymous, static, legacy-password, url or htpasswd;
symbolic constants in auth.h)
- name: Name for the role. For later matching. (values: any string; default: (none))
- method: This rule is only active on the given list of HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- ACL related:
- allow-method: Allowed HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: get)
- deny-method: Rejected HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- allow-admin: Allowed admin commands. (list of enum values: admin command; default: buildm3u)
- deny-admin: Rejected admin commands. (list of enum values: admin command; default: *)
- allow-web: Allowed web pages. (values: empty or *; default: *)
- deny-web: Rejected web pages. (values: empty or *; default: (empty))
- connections-per-user: maximum number of simultaneous connections per role and username.
This is only active on active sources. (values: unlimited or number of connections; default: unlimited)
- connection-duration: maximum time of a connection. This is only active on active sources.
(values: unlimited or number of secounds; default: unlimited)
<role> takes <option> child tags. <option> tags contain a name and a value option.
Meaning of <option> tags is up to the authentication module.
- <role>s are considered to build a stack. If a role returns with AUTH_NOMATCH the next one will be tried.
- <role>s are tested in this order: mount specific, default mount specific, global, internal fallback.
Internal fallback is set to allow web/ access via GET, POST and HEAD (only GET supported by this time)
and rejects all other requests.
- New authentication module: anonymous
This module matches all requests. No options taken.
- New authentication module: static
This module matches with a static username and password.
It takes two <option>s. One with name="username" and one with name="password" to set username and password.
This replaces old style <*-username> and <*-password> tags.
- New authentication module: legacy-password
This module matches with a statich password.
It takes one <option> with name="password" to set password.
This replaces old ICE and ICY (shoutcast compat mode) authentication.
- Parsing <authentication> in <mount> with a type set in a special way to allow 100% backward compatibility.
- Parsing of <source-password>, <admin-password>, <admin-user>, <relay-password> and <relay-user> in global
<authentication> for 100% backward compatibility.
- <alias> is now proccessed very early. This enables them to be used for all kinds of requests.
To Do List & What does not yet work:
- type="url" auth: mount_add and mount_remove.
This should be replaced by an unique feature I would call '<event>'.
- Admin commands manageauth and manageauth.xsl are disabled as they need more review:
This code needs to be ported to support multiple <role>s per <mount>.
- url authentication module can not yet return AUTH_NOMATCH.
This needs to be reviewed and discussed on how to handle this case best way.
- Default config files needs to be updated to reflect the changes.
As this is quite some political act it should be done in dicussion with the whole team
and permission of the release manager.
- Docs need to be updated to reflect the changes.
How does it work:
Code has been changed so that authentification is done early for all clients.
This allows accessing the ACL data (client->acl) from nearly everywhere in the code.
After accept() and initial client setup the request is parsed. In the next step
all <alias>es are resolved. After this the client is passed for authentication.
After authentication it is passed to the corresponding subsystem depending on kind of request.
All authentication instances have a thread running for doing the authentication.
This thread works on a queue of clients.
Hints for testers:
- Test with default config.
- Test with diffrent authentication modules in <mount>.
- Test shoutcast compatibility mode.
- Test with new style <authentication> and any amount of <role> (zero to quite some).
- Test <alias> lookup on all kinds of objects.
- Test source level credential login into the admin interface.
- Test shoucast style meta data updates.
- Test playlist generation.
Thank you for reading this long commit message. Have fun reading the full patch!
svn path=/icecast/trunk/icecast/; revision=19358
2014-11-28 18:46:08 -05:00
|
|
|
if (!client->username || !client->password)
|
|
|
|
return AUTH_NOMATCH;
|
2005-08-07 19:01:04 -04:00
|
|
|
|
Wow. Mega patch!
This patch *replaces* the authentication system completly.
What is new:
- <authentication> in mount section is now a container object.
- <authentication> in root and mount section may hold any number of <role>-Tags.
- <role> tags:
Those tags define a 'role' and it's ACL rules.
A role is a instance of an authentication module (see below).
<role> takes the following options. All but type are optional.
- authentication related:
- type: Type of the authentication module (values: anonymous, static, legacy-password, url or htpasswd;
symbolic constants in auth.h)
- name: Name for the role. For later matching. (values: any string; default: (none))
- method: This rule is only active on the given list of HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- ACL related:
- allow-method: Allowed HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: get)
- deny-method: Rejected HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- allow-admin: Allowed admin commands. (list of enum values: admin command; default: buildm3u)
- deny-admin: Rejected admin commands. (list of enum values: admin command; default: *)
- allow-web: Allowed web pages. (values: empty or *; default: *)
- deny-web: Rejected web pages. (values: empty or *; default: (empty))
- connections-per-user: maximum number of simultaneous connections per role and username.
This is only active on active sources. (values: unlimited or number of connections; default: unlimited)
- connection-duration: maximum time of a connection. This is only active on active sources.
(values: unlimited or number of secounds; default: unlimited)
<role> takes <option> child tags. <option> tags contain a name and a value option.
Meaning of <option> tags is up to the authentication module.
- <role>s are considered to build a stack. If a role returns with AUTH_NOMATCH the next one will be tried.
- <role>s are tested in this order: mount specific, default mount specific, global, internal fallback.
Internal fallback is set to allow web/ access via GET, POST and HEAD (only GET supported by this time)
and rejects all other requests.
- New authentication module: anonymous
This module matches all requests. No options taken.
- New authentication module: static
This module matches with a static username and password.
It takes two <option>s. One with name="username" and one with name="password" to set username and password.
This replaces old style <*-username> and <*-password> tags.
- New authentication module: legacy-password
This module matches with a statich password.
It takes one <option> with name="password" to set password.
This replaces old ICE and ICY (shoutcast compat mode) authentication.
- Parsing <authentication> in <mount> with a type set in a special way to allow 100% backward compatibility.
- Parsing of <source-password>, <admin-password>, <admin-user>, <relay-password> and <relay-user> in global
<authentication> for 100% backward compatibility.
- <alias> is now proccessed very early. This enables them to be used for all kinds of requests.
To Do List & What does not yet work:
- type="url" auth: mount_add and mount_remove.
This should be replaced by an unique feature I would call '<event>'.
- Admin commands manageauth and manageauth.xsl are disabled as they need more review:
This code needs to be ported to support multiple <role>s per <mount>.
- url authentication module can not yet return AUTH_NOMATCH.
This needs to be reviewed and discussed on how to handle this case best way.
- Default config files needs to be updated to reflect the changes.
As this is quite some political act it should be done in dicussion with the whole team
and permission of the release manager.
- Docs need to be updated to reflect the changes.
How does it work:
Code has been changed so that authentification is done early for all clients.
This allows accessing the ACL data (client->acl) from nearly everywhere in the code.
After accept() and initial client setup the request is parsed. In the next step
all <alias>es are resolved. After this the client is passed for authentication.
After authentication it is passed to the corresponding subsystem depending on kind of request.
All authentication instances have a thread running for doing the authentication.
This thread works on a queue of clients.
Hints for testers:
- Test with default config.
- Test with diffrent authentication modules in <mount>.
- Test shoutcast compatibility mode.
- Test with new style <authentication> and any amount of <role> (zero to quite some).
- Test <alias> lookup on all kinds of objects.
- Test source level credential login into the admin interface.
- Test shoucast style meta data updates.
- Test playlist generation.
Thank you for reading this long commit message. Have fun reading the full patch!
svn path=/icecast/trunk/icecast/; revision=19358
2014-11-28 18:46:08 -05:00
|
|
|
if (!htpasswd->filename) {
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_ERROR("No filename given in options for authenticator.");
|
Wow. Mega patch!
This patch *replaces* the authentication system completly.
What is new:
- <authentication> in mount section is now a container object.
- <authentication> in root and mount section may hold any number of <role>-Tags.
- <role> tags:
Those tags define a 'role' and it's ACL rules.
A role is a instance of an authentication module (see below).
<role> takes the following options. All but type are optional.
- authentication related:
- type: Type of the authentication module (values: anonymous, static, legacy-password, url or htpasswd;
symbolic constants in auth.h)
- name: Name for the role. For later matching. (values: any string; default: (none))
- method: This rule is only active on the given list of HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- ACL related:
- allow-method: Allowed HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: get)
- deny-method: Rejected HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- allow-admin: Allowed admin commands. (list of enum values: admin command; default: buildm3u)
- deny-admin: Rejected admin commands. (list of enum values: admin command; default: *)
- allow-web: Allowed web pages. (values: empty or *; default: *)
- deny-web: Rejected web pages. (values: empty or *; default: (empty))
- connections-per-user: maximum number of simultaneous connections per role and username.
This is only active on active sources. (values: unlimited or number of connections; default: unlimited)
- connection-duration: maximum time of a connection. This is only active on active sources.
(values: unlimited or number of secounds; default: unlimited)
<role> takes <option> child tags. <option> tags contain a name and a value option.
Meaning of <option> tags is up to the authentication module.
- <role>s are considered to build a stack. If a role returns with AUTH_NOMATCH the next one will be tried.
- <role>s are tested in this order: mount specific, default mount specific, global, internal fallback.
Internal fallback is set to allow web/ access via GET, POST and HEAD (only GET supported by this time)
and rejects all other requests.
- New authentication module: anonymous
This module matches all requests. No options taken.
- New authentication module: static
This module matches with a static username and password.
It takes two <option>s. One with name="username" and one with name="password" to set username and password.
This replaces old style <*-username> and <*-password> tags.
- New authentication module: legacy-password
This module matches with a statich password.
It takes one <option> with name="password" to set password.
This replaces old ICE and ICY (shoutcast compat mode) authentication.
- Parsing <authentication> in <mount> with a type set in a special way to allow 100% backward compatibility.
- Parsing of <source-password>, <admin-password>, <admin-user>, <relay-password> and <relay-user> in global
<authentication> for 100% backward compatibility.
- <alias> is now proccessed very early. This enables them to be used for all kinds of requests.
To Do List & What does not yet work:
- type="url" auth: mount_add and mount_remove.
This should be replaced by an unique feature I would call '<event>'.
- Admin commands manageauth and manageauth.xsl are disabled as they need more review:
This code needs to be ported to support multiple <role>s per <mount>.
- url authentication module can not yet return AUTH_NOMATCH.
This needs to be reviewed and discussed on how to handle this case best way.
- Default config files needs to be updated to reflect the changes.
As this is quite some political act it should be done in dicussion with the whole team
and permission of the release manager.
- Docs need to be updated to reflect the changes.
How does it work:
Code has been changed so that authentification is done early for all clients.
This allows accessing the ACL data (client->acl) from nearly everywhere in the code.
After accept() and initial client setup the request is parsed. In the next step
all <alias>es are resolved. After this the client is passed for authentication.
After authentication it is passed to the corresponding subsystem depending on kind of request.
All authentication instances have a thread running for doing the authentication.
This thread works on a queue of clients.
Hints for testers:
- Test with default config.
- Test with diffrent authentication modules in <mount>.
- Test shoutcast compatibility mode.
- Test with new style <authentication> and any amount of <role> (zero to quite some).
- Test <alias> lookup on all kinds of objects.
- Test source level credential login into the admin interface.
- Test shoucast style meta data updates.
- Test playlist generation.
Thank you for reading this long commit message. Have fun reading the full patch!
svn path=/icecast/trunk/icecast/; revision=19358
2014-11-28 18:46:08 -05:00
|
|
|
return AUTH_NOMATCH;
|
2008-04-22 22:48:53 -04:00
|
|
|
}
|
2005-08-07 19:01:04 -04:00
|
|
|
htpasswd_recheckfile (htpasswd);
|
|
|
|
|
|
|
|
thread_rwlock_rlock (&htpasswd->file_rwlock);
|
|
|
|
entry.name = client->username;
|
2015-01-25 13:57:27 -05:00
|
|
|
if (avl_get_by_key (htpasswd->users, &entry, &result) == 0) {
|
2005-08-07 19:01:04 -04:00
|
|
|
htpasswd_user *found = result;
|
|
|
|
char *hashed_pw;
|
|
|
|
|
|
|
|
thread_rwlock_unlock (&htpasswd->file_rwlock);
|
|
|
|
hashed_pw = get_hash (client->password, strlen (client->password));
|
2015-01-25 13:57:27 -05:00
|
|
|
if (strcmp (found->pass, hashed_pw) == 0) {
|
2005-08-07 19:01:04 -04:00
|
|
|
free (hashed_pw);
|
|
|
|
return AUTH_OK;
|
|
|
|
}
|
|
|
|
free (hashed_pw);
|
2015-03-01 11:51:09 -05:00
|
|
|
ICECAST_LOG_DEBUG("incorrect password for client with username: %s", client->username);
|
2005-08-07 19:01:04 -04:00
|
|
|
return AUTH_FAILED;
|
|
|
|
}
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("no such username: %s", client->username);
|
2005-08-07 19:01:04 -04:00
|
|
|
thread_rwlock_unlock (&htpasswd->file_rwlock);
|
Wow. Mega patch!
This patch *replaces* the authentication system completly.
What is new:
- <authentication> in mount section is now a container object.
- <authentication> in root and mount section may hold any number of <role>-Tags.
- <role> tags:
Those tags define a 'role' and it's ACL rules.
A role is a instance of an authentication module (see below).
<role> takes the following options. All but type are optional.
- authentication related:
- type: Type of the authentication module (values: anonymous, static, legacy-password, url or htpasswd;
symbolic constants in auth.h)
- name: Name for the role. For later matching. (values: any string; default: (none))
- method: This rule is only active on the given list of HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- ACL related:
- allow-method: Allowed HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: get)
- deny-method: Rejected HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- allow-admin: Allowed admin commands. (list of enum values: admin command; default: buildm3u)
- deny-admin: Rejected admin commands. (list of enum values: admin command; default: *)
- allow-web: Allowed web pages. (values: empty or *; default: *)
- deny-web: Rejected web pages. (values: empty or *; default: (empty))
- connections-per-user: maximum number of simultaneous connections per role and username.
This is only active on active sources. (values: unlimited or number of connections; default: unlimited)
- connection-duration: maximum time of a connection. This is only active on active sources.
(values: unlimited or number of secounds; default: unlimited)
<role> takes <option> child tags. <option> tags contain a name and a value option.
Meaning of <option> tags is up to the authentication module.
- <role>s are considered to build a stack. If a role returns with AUTH_NOMATCH the next one will be tried.
- <role>s are tested in this order: mount specific, default mount specific, global, internal fallback.
Internal fallback is set to allow web/ access via GET, POST and HEAD (only GET supported by this time)
and rejects all other requests.
- New authentication module: anonymous
This module matches all requests. No options taken.
- New authentication module: static
This module matches with a static username and password.
It takes two <option>s. One with name="username" and one with name="password" to set username and password.
This replaces old style <*-username> and <*-password> tags.
- New authentication module: legacy-password
This module matches with a statich password.
It takes one <option> with name="password" to set password.
This replaces old ICE and ICY (shoutcast compat mode) authentication.
- Parsing <authentication> in <mount> with a type set in a special way to allow 100% backward compatibility.
- Parsing of <source-password>, <admin-password>, <admin-user>, <relay-password> and <relay-user> in global
<authentication> for 100% backward compatibility.
- <alias> is now proccessed very early. This enables them to be used for all kinds of requests.
To Do List & What does not yet work:
- type="url" auth: mount_add and mount_remove.
This should be replaced by an unique feature I would call '<event>'.
- Admin commands manageauth and manageauth.xsl are disabled as they need more review:
This code needs to be ported to support multiple <role>s per <mount>.
- url authentication module can not yet return AUTH_NOMATCH.
This needs to be reviewed and discussed on how to handle this case best way.
- Default config files needs to be updated to reflect the changes.
As this is quite some political act it should be done in dicussion with the whole team
and permission of the release manager.
- Docs need to be updated to reflect the changes.
How does it work:
Code has been changed so that authentification is done early for all clients.
This allows accessing the ACL data (client->acl) from nearly everywhere in the code.
After accept() and initial client setup the request is parsed. In the next step
all <alias>es are resolved. After this the client is passed for authentication.
After authentication it is passed to the corresponding subsystem depending on kind of request.
All authentication instances have a thread running for doing the authentication.
This thread works on a queue of clients.
Hints for testers:
- Test with default config.
- Test with diffrent authentication modules in <mount>.
- Test shoutcast compatibility mode.
- Test with new style <authentication> and any amount of <role> (zero to quite some).
- Test <alias> lookup on all kinds of objects.
- Test source level credential login into the admin interface.
- Test shoucast style meta data updates.
- Test playlist generation.
Thank you for reading this long commit message. Have fun reading the full patch!
svn path=/icecast/trunk/icecast/; revision=19358
2014-11-28 18:46:08 -05:00
|
|
|
return AUTH_NOMATCH;
|
2005-08-07 19:01:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int auth_get_htpasswd_auth (auth_t *authenticator, config_options_t *options)
|
|
|
|
{
|
|
|
|
htpasswd_auth_state *state;
|
|
|
|
|
Wow. Mega patch!
This patch *replaces* the authentication system completly.
What is new:
- <authentication> in mount section is now a container object.
- <authentication> in root and mount section may hold any number of <role>-Tags.
- <role> tags:
Those tags define a 'role' and it's ACL rules.
A role is a instance of an authentication module (see below).
<role> takes the following options. All but type are optional.
- authentication related:
- type: Type of the authentication module (values: anonymous, static, legacy-password, url or htpasswd;
symbolic constants in auth.h)
- name: Name for the role. For later matching. (values: any string; default: (none))
- method: This rule is only active on the given list of HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- ACL related:
- allow-method: Allowed HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: get)
- deny-method: Rejected HTTP methods.
(list of enum values: methods as recognized by httpp/ (e.g: get,post); default: *)
- allow-admin: Allowed admin commands. (list of enum values: admin command; default: buildm3u)
- deny-admin: Rejected admin commands. (list of enum values: admin command; default: *)
- allow-web: Allowed web pages. (values: empty or *; default: *)
- deny-web: Rejected web pages. (values: empty or *; default: (empty))
- connections-per-user: maximum number of simultaneous connections per role and username.
This is only active on active sources. (values: unlimited or number of connections; default: unlimited)
- connection-duration: maximum time of a connection. This is only active on active sources.
(values: unlimited or number of secounds; default: unlimited)
<role> takes <option> child tags. <option> tags contain a name and a value option.
Meaning of <option> tags is up to the authentication module.
- <role>s are considered to build a stack. If a role returns with AUTH_NOMATCH the next one will be tried.
- <role>s are tested in this order: mount specific, default mount specific, global, internal fallback.
Internal fallback is set to allow web/ access via GET, POST and HEAD (only GET supported by this time)
and rejects all other requests.
- New authentication module: anonymous
This module matches all requests. No options taken.
- New authentication module: static
This module matches with a static username and password.
It takes two <option>s. One with name="username" and one with name="password" to set username and password.
This replaces old style <*-username> and <*-password> tags.
- New authentication module: legacy-password
This module matches with a statich password.
It takes one <option> with name="password" to set password.
This replaces old ICE and ICY (shoutcast compat mode) authentication.
- Parsing <authentication> in <mount> with a type set in a special way to allow 100% backward compatibility.
- Parsing of <source-password>, <admin-password>, <admin-user>, <relay-password> and <relay-user> in global
<authentication> for 100% backward compatibility.
- <alias> is now proccessed very early. This enables them to be used for all kinds of requests.
To Do List & What does not yet work:
- type="url" auth: mount_add and mount_remove.
This should be replaced by an unique feature I would call '<event>'.
- Admin commands manageauth and manageauth.xsl are disabled as they need more review:
This code needs to be ported to support multiple <role>s per <mount>.
- url authentication module can not yet return AUTH_NOMATCH.
This needs to be reviewed and discussed on how to handle this case best way.
- Default config files needs to be updated to reflect the changes.
As this is quite some political act it should be done in dicussion with the whole team
and permission of the release manager.
- Docs need to be updated to reflect the changes.
How does it work:
Code has been changed so that authentification is done early for all clients.
This allows accessing the ACL data (client->acl) from nearly everywhere in the code.
After accept() and initial client setup the request is parsed. In the next step
all <alias>es are resolved. After this the client is passed for authentication.
After authentication it is passed to the corresponding subsystem depending on kind of request.
All authentication instances have a thread running for doing the authentication.
This thread works on a queue of clients.
Hints for testers:
- Test with default config.
- Test with diffrent authentication modules in <mount>.
- Test shoutcast compatibility mode.
- Test with new style <authentication> and any amount of <role> (zero to quite some).
- Test <alias> lookup on all kinds of objects.
- Test source level credential login into the admin interface.
- Test shoucast style meta data updates.
- Test playlist generation.
Thank you for reading this long commit message. Have fun reading the full patch!
svn path=/icecast/trunk/icecast/; revision=19358
2014-11-28 18:46:08 -05:00
|
|
|
authenticator->authenticate_client = htpasswd_auth;
|
2005-08-07 19:01:04 -04:00
|
|
|
authenticator->free = htpasswd_clear;
|
|
|
|
authenticator->adduser = htpasswd_adduser;
|
|
|
|
authenticator->deleteuser = htpasswd_deleteuser;
|
|
|
|
authenticator->listuser = htpasswd_userlist;
|
2014-12-19 12:27:54 -05:00
|
|
|
authenticator->immediate = 1;
|
2005-08-07 19:01:04 -04:00
|
|
|
|
|
|
|
state = calloc(1, sizeof(htpasswd_auth_state));
|
|
|
|
|
|
|
|
while(options) {
|
2015-01-25 13:57:27 -05:00
|
|
|
if(!strcmp(options->name, "filename")) {
|
2008-04-22 22:48:53 -04:00
|
|
|
free (state->filename);
|
2005-08-07 19:01:04 -04:00
|
|
|
state->filename = strdup(options->value);
|
2008-04-22 22:48:53 -04:00
|
|
|
}
|
2005-08-07 19:01:04 -04:00
|
|
|
options = options->next;
|
|
|
|
}
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
if (state->filename) {
|
2015-01-10 13:53:44 -05:00
|
|
|
ICECAST_LOG_INFO("Configured htpasswd authentication using password file \"%s\"",
|
2008-04-22 22:48:53 -04:00
|
|
|
state->filename);
|
2015-01-25 13:57:27 -05:00
|
|
|
} else {
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_ERROR("No filename given in options for authenticator.");
|
2015-01-25 13:57:27 -05:00
|
|
|
}
|
2005-08-07 19:01:04 -04:00
|
|
|
|
|
|
|
authenticator->state = state;
|
|
|
|
|
|
|
|
thread_rwlock_create(&state->file_rwlock);
|
2014-11-30 15:32:30 -05:00
|
|
|
htpasswd_recheckfile(state);
|
2005-08-07 19:01:04 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static auth_result htpasswd_adduser (auth_t *auth, const char *username, const char *password)
|
|
|
|
{
|
|
|
|
FILE *passwdfile;
|
|
|
|
char *hashed_password = NULL;
|
|
|
|
htpasswd_auth_state *state = auth->state;
|
|
|
|
htpasswd_user entry;
|
|
|
|
void *result;
|
|
|
|
|
|
|
|
htpasswd_recheckfile (state);
|
|
|
|
|
|
|
|
thread_rwlock_wlock (&state->file_rwlock);
|
|
|
|
|
|
|
|
entry.name = (char*)username;
|
2015-01-25 13:57:27 -05:00
|
|
|
if (avl_get_by_key (state->users, &entry, &result) == 0) {
|
2005-08-07 19:01:04 -04:00
|
|
|
thread_rwlock_unlock (&state->file_rwlock);
|
|
|
|
return AUTH_USEREXISTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
passwdfile = fopen(state->filename, "ab");
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
if (passwdfile == NULL) {
|
2005-08-07 19:01:04 -04:00
|
|
|
thread_rwlock_unlock (&state->file_rwlock);
|
2015-01-10 13:53:44 -05:00
|
|
|
ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s",
|
2005-08-07 19:01:04 -04:00
|
|
|
state->filename, strerror(errno));
|
|
|
|
return AUTH_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
hashed_password = get_hash(password, strlen(password));
|
|
|
|
if (hashed_password) {
|
|
|
|
fprintf(passwdfile, "%s:%s\n", username, hashed_password);
|
|
|
|
free(hashed_password);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(passwdfile);
|
|
|
|
thread_rwlock_unlock (&state->file_rwlock);
|
|
|
|
|
|
|
|
return AUTH_USERADDED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static auth_result htpasswd_deleteuser(auth_t *auth, const char *username)
|
|
|
|
{
|
|
|
|
FILE *passwdfile;
|
|
|
|
FILE *tmp_passwdfile;
|
|
|
|
htpasswd_auth_state *state;
|
|
|
|
char line[MAX_LINE_LEN];
|
|
|
|
char *sep;
|
|
|
|
char *tmpfile = NULL;
|
|
|
|
int tmpfile_len = 0;
|
|
|
|
struct stat file_info;
|
|
|
|
|
|
|
|
state = auth->state;
|
|
|
|
thread_rwlock_wlock (&state->file_rwlock);
|
|
|
|
passwdfile = fopen(state->filename, "rb");
|
|
|
|
|
|
|
|
if(passwdfile == NULL) {
|
2015-01-10 13:53:44 -05:00
|
|
|
ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s",
|
2005-08-07 19:01:04 -04:00
|
|
|
state->filename, strerror(errno));
|
|
|
|
thread_rwlock_unlock (&state->file_rwlock);
|
|
|
|
return AUTH_FAILED;
|
|
|
|
}
|
|
|
|
tmpfile_len = strlen(state->filename) + 6;
|
|
|
|
tmpfile = calloc(1, tmpfile_len);
|
|
|
|
snprintf (tmpfile, tmpfile_len, "%s.tmp", state->filename);
|
2015-01-25 13:57:27 -05:00
|
|
|
if (stat (tmpfile, &file_info) == 0) {
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_WARN("temp file \"%s\" exists, rejecting operation", tmpfile);
|
2005-08-07 19:01:04 -04:00
|
|
|
free (tmpfile);
|
|
|
|
fclose (passwdfile);
|
|
|
|
thread_rwlock_unlock (&state->file_rwlock);
|
|
|
|
return AUTH_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_passwdfile = fopen(tmpfile, "wb");
|
|
|
|
|
|
|
|
if(tmp_passwdfile == NULL) {
|
2015-01-10 13:53:44 -05:00
|
|
|
ICECAST_LOG_WARN("Failed to open temporary authentication database \"%s\": %s",
|
2005-08-07 19:01:04 -04:00
|
|
|
tmpfile, strerror(errno));
|
|
|
|
fclose(passwdfile);
|
|
|
|
free(tmpfile);
|
|
|
|
thread_rwlock_unlock (&state->file_rwlock);
|
|
|
|
return AUTH_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while(get_line(passwdfile, line, MAX_LINE_LEN)) {
|
|
|
|
if(!line[0] || line[0] == '#')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sep = strchr(line, ':');
|
|
|
|
if(sep == NULL) {
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("No separator in line");
|
2005-08-07 19:01:04 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sep = 0;
|
|
|
|
if (strcmp(username, line)) {
|
|
|
|
/* We did not match on the user, so copy it to the temp file */
|
|
|
|
/* and put the : back in */
|
|
|
|
*sep = ':';
|
|
|
|
fprintf(tmp_passwdfile, "%s\n", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(tmp_passwdfile);
|
|
|
|
fclose(passwdfile);
|
|
|
|
|
|
|
|
/* Now move the contents of the tmp file to the original */
|
|
|
|
/* Windows won't let us rename a file if the destination file
|
|
|
|
exists...so, lets remove the original first */
|
|
|
|
if (remove(state->filename) != 0) {
|
2015-01-10 13:53:44 -05:00
|
|
|
ICECAST_LOG_ERROR("Problem moving temp authentication file to original \"%s\" - \"%s\": %s",
|
2005-08-07 19:01:04 -04:00
|
|
|
tmpfile, state->filename, strerror(errno));
|
2015-01-25 13:57:27 -05:00
|
|
|
} else {
|
2005-08-07 19:01:04 -04:00
|
|
|
if (rename(tmpfile, state->filename) != 0) {
|
2015-01-10 13:53:44 -05:00
|
|
|
ICECAST_LOG_ERROR("Problem moving temp authentication file to original \"%s\" - \"%s\": %s",
|
2005-08-07 19:01:04 -04:00
|
|
|
tmpfile, state->filename, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(tmpfile);
|
2014-11-30 15:32:30 -05:00
|
|
|
thread_rwlock_unlock(&state->file_rwlock);
|
|
|
|
htpasswd_recheckfile(state);
|
2005-08-07 19:01:04 -04:00
|
|
|
|
|
|
|
return AUTH_USERDELETED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static auth_result htpasswd_userlist(auth_t *auth, xmlNodePtr srcnode)
|
|
|
|
{
|
|
|
|
htpasswd_auth_state *state;
|
|
|
|
xmlNodePtr newnode;
|
|
|
|
avl_node *node;
|
|
|
|
|
|
|
|
state = auth->state;
|
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
htpasswd_recheckfile(state);
|
2005-08-07 19:01:04 -04:00
|
|
|
|
2015-01-25 13:57:27 -05:00
|
|
|
thread_rwlock_rlock(&state->file_rwlock);
|
|
|
|
node = avl_get_first(state->users);
|
|
|
|
while (node) {
|
2005-08-07 19:01:04 -04:00
|
|
|
htpasswd_user *user = (htpasswd_user *)node->key;
|
2015-01-25 13:57:27 -05:00
|
|
|
newnode = xmlNewChild(srcnode, NULL, XMLSTR("user"), NULL);
|
2016-02-10 14:56:56 -05:00
|
|
|
xmlNewTextChild(newnode, NULL, XMLSTR("username"), XMLSTR(user->name));
|
|
|
|
xmlNewTextChild(newnode, NULL, XMLSTR("password"), XMLSTR(user->pass));
|
2015-01-25 13:57:27 -05:00
|
|
|
node = avl_get_next(node);
|
2005-08-07 19:01:04 -04:00
|
|
|
}
|
2015-01-25 13:57:27 -05:00
|
|
|
thread_rwlock_unlock(&state->file_rwlock);
|
2005-08-07 19:01:04 -04:00
|
|
|
|
|
|
|
return AUTH_OK;
|
|
|
|
}
|