auth.h 3.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2000-2004, Jack Moffitt <jack@xiph.org, 
 *                      Michael Smith <msmith@xiph.org>,
 *                      oddsock <oddsock@xiph.org>,
 *                      Karl Heyes <karl@xiph.org>
 *                      and others (see AUTHORS for details).
Philipp Schafft's avatar
Philipp Schafft committed
11
 * Copyright 2014,      Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
12
13
 */

Michael Smith's avatar
Michael Smith committed
14
15
16
#ifndef __AUTH_H__
#define __AUTH_H__

Karl Heyes's avatar
Karl Heyes committed
17
18
19
20
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

21
22
23
struct source_tag;
struct auth_tag;

24
25
26
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
27
#include "cfgfile.h"
Karl Heyes's avatar
Karl Heyes committed
28
#include "client.h"
Marvin Scholz's avatar
Marvin Scholz committed
29
#include "common/thread/thread.h"
Michael Smith's avatar
Michael Smith committed
30

Philipp Schafft's avatar
Philipp Schafft committed
31
32
33
34
35
36
37
/* implemented */
#define AUTH_TYPE_ANONYMOUS       "anonymous"
#define AUTH_TYPE_STATIC          "static"
#define AUTH_TYPE_LEGACY_PASSWORD "legacy-password"
#define AUTH_TYPE_URL             "url"
#define AUTH_TYPE_HTPASSWD        "htpasswd"

Michael Smith's avatar
Michael Smith committed
38
39
typedef enum
{
40
    /* XXX: ??? */
41
    AUTH_UNDEFINED,
42
    /* user authed successfull */
Michael Smith's avatar
Michael Smith committed
43
    AUTH_OK,
44
    /* user authed failed */
Michael Smith's avatar
Michael Smith committed
45
    AUTH_FAILED,
Philipp Schafft's avatar
Philipp Schafft committed
46
47
    /* session got terminated */
    AUTH_RELEASED,
48
    /* XXX: ??? */
49
    AUTH_FORBIDDEN,
50
51
52
    /* No match for given username or other identifier found */
    AUTH_NOMATCH,
    /* status codes for database changes */
53
54
    AUTH_USERADDED,
    AUTH_USEREXISTS,
55
    AUTH_USERDELETED
Michael Smith's avatar
Michael Smith committed
56
57
} auth_result;

58
59
typedef struct auth_client_tag
{
Philipp Schafft's avatar
Philipp Schafft committed
60
61
62
63
64
    client_t     *client;
    auth_result (*process)(struct auth_tag *auth, struct auth_client_tag *auth_user);
    void        (*on_no_match)(client_t *client, void (*on_result)(client_t *client, void *userdata, auth_result result), void *userdata);
    void        (*on_result)(client_t *client, void *userdata, auth_result result);
    void         *userdata;
65
66
67
68
    struct auth_client_tag *next;
} auth_client;


Michael Smith's avatar
Michael Smith committed
69
70
typedef struct auth_tag
{
71
72
73
    /* unique ID */
    unsigned long id;

74
75
    char *mount;

Philipp Schafft's avatar
Philipp Schafft committed
76
77
    /* filters */
    int method[httpp_req_unknown+1];
78

Philipp Schafft's avatar
Philipp Schafft committed
79
80
81
    /* Authenticate using the given username and password */
    auth_result (*authenticate_client)(auth_client *aclient);
    auth_result (*release_client)(auth_client *auth_user);
82

83
    /* auth state-specific free call */
Michael Smith's avatar
Michael Smith committed
84
    void (*free)(struct auth_tag *self);
85

86
87
88
89
    auth_result (*adduser)(struct auth_tag *auth, const char *username, const char *password);
    auth_result (*deleteuser)(struct auth_tag *auth, const char *username);
    auth_result (*listuser)(struct auth_tag *auth, xmlNodePtr srcnode);

90
    mutex_t lock;
91
    int running;
Philipp Schafft's avatar
Philipp Schafft committed
92
    size_t refcount;
93

94
95
96
97
98
99
    thread_type *thread;

    /* per-auth queue for clients */
    auth_client *head, **tailp;
    int pending_count;

Michael Smith's avatar
Michael Smith committed
100
    void *state;
101
    char *type;
Philipp Schafft's avatar
Philipp Schafft committed
102
103
104
105
106
107
    char *unique_tag;

    /* acl to set on succsessful auth */
    acl_t *acl;
    /* role name for later matching, may be NULL if no role name was given in config */
    char  *role;
Michael Smith's avatar
Michael Smith committed
108
109
} auth_t;

Philipp Schafft's avatar
Philipp Schafft committed
110
typedef struct auth_stack_tag auth_stack_t;
111

112
113
void auth_initialise (void);
void auth_shutdown (void);
114

115
116
auth_t  *auth_get_authenticator (xmlNodePtr node);
void    auth_release (auth_t *authenticator);
Philipp Schafft's avatar
Philipp Schafft committed
117
void    auth_addref (auth_t *authenticator);
118

Philipp Schafft's avatar
Philipp Schafft committed
119
int  auth_release_client(client_t *client);
Michael Smith's avatar
Michael Smith committed
120

Philipp Schafft's avatar
Philipp Schafft committed
121
void          auth_stack_add_client(auth_stack_t *stack, client_t *client, void (*on_result)(client_t *client, void *userdata, auth_result result), void *userdata);
122

Philipp Schafft's avatar
Philipp Schafft committed
123
124
125
126
127
128
129
void          auth_stack_release(auth_stack_t *stack);
void          auth_stack_addref(auth_stack_t *stack);
int           auth_stack_next(auth_stack_t **stack); /* returns -1 on error, 0 on success, +1 if no next element is present */
int           auth_stack_push(auth_stack_t **stack, auth_t *auth);
int           auth_stack_append(auth_stack_t *stack, auth_stack_t *tail);
auth_t       *auth_stack_get(auth_stack_t *stack);
acl_t        *auth_stack_get_anonymous_acl(auth_stack_t *stack);
Michael Smith's avatar
Michael Smith committed
130
131

#endif