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 
17 struct source_tag;
18 struct auth_tag;
19 struct _fbinfo;
20 typedef struct _auth_thread_t auth_thread_t;
21 
22 #include <libxml/xmlmemory.h>
23 #include <libxml/parser.h>
24 #include <libxml/tree.h>
25 #include "client.h"
26 #include "thread/thread.h"
27 
28 typedef enum
29 {
30     AUTH_UNDEFINED,
31     AUTH_OK,
32     AUTH_FAILED,
33     AUTH_USERADDED,
34     AUTH_USEREXISTS,
35     AUTH_USERDELETED
36 } auth_result;
37 
38 typedef struct auth_client_tag
39 {
40     char        *mount;
41     char        *hostname;
42     int         port;
43     int         handler;
44     client_t    *client;
45     struct auth_tag *auth;
46     void        *thread_data;
47     void        (*process)(struct auth_client_tag *auth_user);
48     struct auth_client_tag *next;
49 } auth_client;
50 
51 
52 typedef struct auth_tag
53 {
54     char *mount;
55 
56     /* Authenticate using the given username and password */
57     auth_result (*authenticate)(auth_client *aclient);
58     auth_result (*release_listener)(auth_client *auth_user);
59 
60     /* auth handler for authenicating a connecting source client */
61     void (*stream_auth)(auth_client *auth_user);
62 
63     /* auth handler for source startup, no client passed as it may disappear */
64     void (*stream_start)(auth_client *auth_user);
65 
66     /* auth handler for source exit, no client passed as it may disappear */
67     void (*stream_end)(auth_client *auth_user);
68 
69     /* auth state-specific free call */
70     void (*release)(struct auth_tag *self);
71 
72     /* call to allocate any per auth thread data */
73     void *(*alloc_thread_data)(struct auth_tag *self);
74 
75     /* call to freeup any per auth thread data */
76     void (*release_thread_data)(struct auth_tag *self, void *data);
77 
78     auth_result (*adduser)(struct auth_tag *auth, const char *username, const char *password);
79     auth_result (*deleteuser)(struct auth_tag *auth, const char *username);
80     auth_result (*listuser)(struct auth_tag *auth, xmlNodePtr srcnode);
81 
82     mutex_t lock;
83 
84     int refcount;
85     short handlers;
86     short flags;
87 
88     /* mountpoint to send unauthenticated listeners */
89     char *rejected_mount;
90 
91     /* runtime allocated array of thread handlers for this auth */
92     auth_thread_t *handles;
93 
94     /* per-auth queue for clients */
95     auth_client *head, **tailp;
96     int pending_count;
97 
98     void *state;
99     char *type;
100     char *realm;
101 } auth_t;
102 
103 #define AUTH_RUNNING                    1
104 #define AUTH_DEL_EXISTING_LISTENER      (1<<1)
105 #define AUTH_ALLOW_LISTENER_DUP         (1<<2)
106 #define AUTH_SKIP_IF_SLOW               (1<<3)
107 #define AUTH_CLEAN_ENV                  (1<<4)
108 
109 
110 int  auth_add_listener (const char *mount, client_t *client);
111 int  auth_release_listener (client_t *client, const char *mount, struct _mount_proxy *mountinfo);
112 int  move_listener (client_t *client, struct _fbinfo *finfo);
113 int  auth_check_source (client_t *client, const char *mount);
114 
115 void auth_initialise (void);
116 void auth_shutdown (void);
117 
118 int auth_get_authenticator (xmlNodePtr node, void *x);
119 void    auth_release (auth_t *authenticator);
120 
121 /* call to trigger an event when a stream starts */
122 void auth_stream_start (struct _mount_proxy *mountinfo, struct source_tag *source);
123 
124 /* call to trigger an event when a stream ends */
125 void auth_stream_end (struct _mount_proxy *mountinfo, struct source_tag *source);
126 
127 /* call to trigger an event to authenticate a source client */
128 int auth_stream_authenticate (client_t *client, const char *mount, struct _mount_proxy *mountinfo);
129 
130 void auth_check_http (client_t *client);
131 
132 #endif
133 
134 
135