1 /* Icecast
2  *
3  * This program is distributed under the GNU General Public License, version 2.
4  * A copy of this license is included with this source.
5  *
6  * Copyright 2000-2004, Jack Moffitt <jack@xiph.org,
7  *                      Michael Smith <msmith@xiph.org>,
8  *                      oddsock <oddsock@xiph.org>,
9  *                      Karl Heyes <karl@xiph.org>
10  *                      and others (see AUTHORS for details).
11  */
12 
13 #ifndef __AUTH_H__
14 #define __AUTH_H__
15 
16 #ifdef HAVE_CONFIG_H
17 #include <config.h>
18 #endif
19 
20 struct source_tag;
21 struct auth_tag;
22 
23 #include <libxml/xmlmemory.h>
24 #include <libxml/parser.h>
25 #include <libxml/tree.h>
26 #include "cfgfile.h"
27 #include "client.h"
28 #include "thread/thread.h"
29 
30 typedef enum
31 {
32     AUTH_UNDEFINED,
33     AUTH_OK,
34     AUTH_FAILED,
35     AUTH_FORBIDDEN,
36     AUTH_USERADDED,
37     AUTH_USEREXISTS,
38     AUTH_USERDELETED
39 } auth_result;
40 
41 typedef struct auth_client_tag
42 {
43     char        *mount;
44     client_t    *client;
45     void        (*process)(struct auth_tag *auth, struct auth_client_tag *auth_user);
46     struct auth_client_tag *next;
47 } auth_client;
48 
49 
50 typedef struct auth_tag
51 {
52     char *mount;
53 
54     /* Authenticate using the given username and password */
55     auth_result (*authenticate)(auth_client *aclient);
56     auth_result (*release_listener)(auth_client *auth_user);
57 
58     /* auth handler for authenicating a connecting source client */
59     void (*stream_auth)(auth_client *auth_user);
60 
61     /* auth handler for source startup, no client passed as it may disappear */
62     void (*stream_start)(auth_client *auth_user);
63 
64     /* auth handler for source exit, no client passed as it may disappear */
65     void (*stream_end)(auth_client *auth_user);
66 
67     /* auth state-specific free call */
68     void (*free)(struct auth_tag *self);
69 
70     auth_result (*adduser)(struct auth_tag *auth, const char *username, const char *password);
71     auth_result (*deleteuser)(struct auth_tag *auth, const char *username);
72     auth_result (*listuser)(struct auth_tag *auth, xmlNodePtr srcnode);
73 
74     mutex_t lock;
75     int running;
76     int refcount;
77     int allow_duplicate_users;
78 
79     thread_type *thread;
80 
81     /* per-auth queue for clients */
82     auth_client *head, **tailp;
83     int pending_count;
84 
85     void *state;
86     char *type;
87 } auth_t;
88 
89 void auth_add_listener (const char *mount, client_t *client);
90 int  auth_release_listener (client_t *client);
91 
92 void auth_initialise (void);
93 void auth_shutdown (void);
94 
95 auth_t  *auth_get_authenticator (xmlNodePtr node);
96 void    auth_release (auth_t *authenticator);
97 
98 /* call to trigger an event when a stream starts */
99 void auth_stream_start (struct _mount_proxy *mountinfo, const char *mount);
100 
101 /* call to trigger an event when a stream ends */
102 void auth_stream_end (struct _mount_proxy *mountinfo, const char *mount);
103 
104 /* call to trigger an event to authenticate a source client */
105 int auth_stream_authenticate (client_t *client, const char *mount, struct _mount_proxy *mountinfo);
106 
107 /* called from auth thread, after the client has successfully authenticated
108  * and requires adding to source or fserve. */
109 int auth_postprocess_listener (auth_client *auth_user);
110 
111 #endif
112 
113 
114