auth.h 3.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/* 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).
 */

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

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

20
21
22
struct source_tag;
struct auth_tag;

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

typedef enum
{
32
    /* XXX: ??? */
33
    AUTH_UNDEFINED,
34
    /* user authed successfull */
Michael Smith's avatar
Michael Smith committed
35
    AUTH_OK,
36
    /* user authed failed */
Michael Smith's avatar
Michael Smith committed
37
    AUTH_FAILED,
38
    /* XXX: ??? */
39
    AUTH_FORBIDDEN,
40
41
42
    /* No match for given username or other identifier found */
    AUTH_NOMATCH,
    /* status codes for database changes */
43
44
    AUTH_USERADDED,
    AUTH_USEREXISTS,
45
    AUTH_USERDELETED
Michael Smith's avatar
Michael Smith committed
46
47
} auth_result;

48
49
50
51
typedef struct auth_client_tag
{
    char        *mount;
    client_t    *client;
52
    void        (*process)(struct auth_tag *auth, struct auth_client_tag *auth_user);
53
54
55
56
    struct auth_client_tag *next;
} auth_client;


Michael Smith's avatar
Michael Smith committed
57
58
typedef struct auth_tag
{
59
60
    char *mount;

Michael Smith's avatar
Michael Smith committed
61
    /* Authenticate using the given username and password */
62
    auth_result (*authenticate)(auth_client *aclient);
63
    auth_result (*release_listener)(auth_client *auth_user);
64

65
66
67
    /* auth handler for authenicating a connecting source client */
    void (*stream_auth)(auth_client *auth_user);

68
    /* auth handler for source startup, no client passed as it may disappear */
69
    void (*stream_start)(auth_client *auth_user);
70
71

    /* auth handler for source exit, no client passed as it may disappear */
72
73
    void (*stream_end)(auth_client *auth_user);

74
    /* auth state-specific free call */
Michael Smith's avatar
Michael Smith committed
75
    void (*free)(struct auth_tag *self);
76

77
78
79
80
    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);

81
    mutex_t lock;
82
    int running;
83
84
85
    int refcount;
    int allow_duplicate_users;

86
87
88
89
90
91
    thread_type *thread;

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

Michael Smith's avatar
Michael Smith committed
92
    void *state;
93
    char *type;
Michael Smith's avatar
Michael Smith committed
94
95
} auth_t;

96
97
void auth_add_listener (const char *mount, client_t *client);
int  auth_release_listener (client_t *client);
98

99
100
void auth_initialise (void);
void auth_shutdown (void);
101

102
103
104
auth_t  *auth_get_authenticator (xmlNodePtr node);
void    auth_release (auth_t *authenticator);

105
/* call to trigger an event when a stream starts */
106
107
void auth_stream_start (struct _mount_proxy *mountinfo, const char *mount);

108
/* call to trigger an event when a stream ends */
109
void auth_stream_end (struct _mount_proxy *mountinfo, const char *mount);
Michael Smith's avatar
Michael Smith committed
110

111
112
113
/* call to trigger an event to authenticate a source client */
int auth_stream_authenticate (client_t *client, const char *mount, struct _mount_proxy *mountinfo);

114
115
/* called from auth thread, after the client has successfully authenticated
 * and requires adding to source or fserve. */
116
int auth_postprocess_listener (auth_client *auth_user);
Michael Smith's avatar
Michael Smith committed
117
118
119
120

#endif