[dovecot-cvs] dovecot/src/lib-auth auth-client.c, 1.3,
1.4 auth-client.h, 1.4, 1.5 auth-server-connection.c, 1.4,
1.5 auth-server-connection.h, 1.3, 1.4
cras at procontrol.fi
cras at procontrol.fi
Sun May 30 04:40:50 EEST 2004
Update of /home/cvs/dovecot/src/lib-auth
In directory talvi:/tmp/cvs-serv4863/lib-auth
Modified Files:
auth-client.c auth-client.h auth-server-connection.c
auth-server-connection.h
Log Message:
Allow using more easily outside dovecot.
Index: auth-client.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-auth/auth-client.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/auth-client.c 29 May 2004 21:40:30 -0000 1.3
+++ b/auth-client.c 30 May 2004 01:40:47 -0000 1.4
@@ -12,13 +12,25 @@
struct auth_client *auth_client_new(unsigned int client_pid)
{
+ return auth_client_new_external(client_pid, NULL, NULL, NULL);
+}
+
+struct auth_client *auth_client_new_external(unsigned int client_pid,
+ const char *socket_paths,
+ input_func_add_t *add_func,
+ input_func_remove_t *remove_func)
+{
struct auth_client *client;
client = i_new(struct auth_client, 1);
client->pid = client_pid;
+ client->socket_paths = i_strdup(socket_paths);
client->available_auth_mechs =
buffer_create_dynamic(default_pool, 128, (size_t)-1);
+ client->ext_input_add = add_func;
+ client->ext_input_remove = remove_func;
+
auth_client_connect_missing_servers(client);
return client;
}
@@ -43,6 +55,7 @@
if (client->to_reconnect != NULL)
timeout_remove(client->to_reconnect);
+ i_free(client->socket_paths);
i_free(client);
}
@@ -76,7 +89,7 @@
int auth_client_is_connected(struct auth_client *client)
{
- return client->to_reconnect == NULL &&
+ return !client->reconnect &&
client->conn_waiting_handshake_count == 0;
}
@@ -95,42 +108,68 @@
auth_client_connect_missing_servers(client);
}
+static void auth_client_connect_missing_servers_list(struct auth_client *client,
+ const char *list)
+{
+ const char *const *path;
+
+ client->reconnect = FALSE;
+
+ t_push();
+ path = t_strsplit(list, ":");
+ for (; *path != NULL; path++) {
+ if (auth_server_connection_find_path(client, *path) == NULL) {
+ if (auth_server_connection_new(client, *path) == NULL)
+ client->reconnect = TRUE;
+ }
+ }
+ t_pop();
+}
+
void auth_client_connect_missing_servers(struct auth_client *client)
{
DIR *dirp;
struct dirent *dp;
struct stat st;
- int reconnect;
- /* we're chrooted into */
- dirp = opendir(".");
- if (dirp == NULL) {
- i_fatal("opendir(.) failed when trying to get list of "
- "authentication servers: %m");
- }
+ if (client->socket_paths != NULL) {
+ auth_client_connect_missing_servers_list(client,
+ client->socket_paths);
+ } else {
+ /* we're chrooted */
+ dirp = opendir(".");
+ if (dirp == NULL) {
+ i_fatal("opendir(.) failed when trying to get list of "
+ "authentication servers: %m");
+ }
- reconnect = FALSE;
- while ((dp = readdir(dirp)) != NULL) {
- if (dp->d_name[0] == '.')
- continue;
+ client->reconnect = FALSE;
+ while ((dp = readdir(dirp)) != NULL) {
+ const char *name = dp->d_name;
- if (auth_server_connection_find_path(client, dp->d_name) != NULL) {
- /* already connected */
- continue;
- }
+ if (name[0] == '.')
+ continue;
- if (stat(dp->d_name, &st) == 0 && S_ISSOCK(st.st_mode)) {
- if (auth_server_connection_new(client,
- dp->d_name) == NULL)
- reconnect = TRUE;
+ if (auth_server_connection_find_path(client,
+ name) != NULL) {
+ /* already connected */
+ continue;
+ }
+
+ if (stat(name, &st) == 0 && S_ISSOCK(st.st_mode)) {
+ if (auth_server_connection_new(client,
+ name) == NULL)
+ client->reconnect = TRUE;
+ }
}
- }
- if (closedir(dirp) < 0)
- i_error("closedir() failed: %m");
+ if (closedir(dirp) < 0)
+ i_error("closedir() failed: %m");
+ }
- if (reconnect || client->connections == NULL) {
- if (client->to_reconnect == NULL) {
+ if (client->reconnect || client->connections == NULL) {
+ if (client->to_reconnect == NULL &&
+ client->ext_input_add == NULL) {
client->to_reconnect =
timeout_add(5000, reconnect_timeout, client);
}
Index: auth-client.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-auth/auth-client.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/auth-client.h 29 May 2004 21:40:30 -0000 1.4
+++ b/auth-client.h 30 May 2004 01:40:47 -0000 1.5
@@ -34,8 +34,6 @@
const struct auth_mech_desc *
auth_client_find_mech(struct auth_client *client, const char *name);
-void auth_client_connect_missing_servers(struct auth_client *client);
-
/* Create a new authentication request. callback is called whenever something
happens for the request. */
struct auth_request *
@@ -61,4 +59,16 @@
/* Return the PID of the server that handled this request. */
unsigned int auth_client_request_get_server_pid(struct auth_request *request);
+/* -- Using lib-auth with external I/O loop -- */
+
+typedef void *input_func_add_t(int fd, void (*cb)(void *), void *context);
+typedef void *input_func_remove_t(void *io);
+
+struct auth_client *auth_client_new_external(unsigned int client_pid,
+ const char *socket_paths,
+ input_func_add_t *add_func,
+ input_func_remove_t *remove_func);
+/* Call every few seconds. */
+void auth_client_connect_missing_servers(struct auth_client *client);
+
#endif
Index: auth-server-connection.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-auth/auth-server-connection.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/auth-server-connection.c 29 May 2004 21:40:30 -0000 1.4
+++ b/auth-server-connection.c 30 May 2004 01:40:47 -0000 1.5
@@ -49,12 +49,6 @@
buffer_t *buf;
unsigned int i;
- if (handshake->server_pid == 0) {
- i_error("BUG: Auth server said it's PID 0");
- auth_server_connection_destroy(conn, FALSE);
- return;
- }
-
if (handshake->data_size == 0 || data[handshake->data_size-1] != '\0' ||
handshake->mech_count * sizeof(handshake_mech_desc) >=
handshake->data_size) {
@@ -191,7 +185,12 @@
conn->client = client;
conn->path = p_strdup(pool, path);
conn->fd = fd;
- conn->io = io_add(fd, IO_READ, auth_client_input, conn);
+ if (client->ext_input_add == NULL)
+ conn->io = io_add(fd, IO_READ, auth_client_input, conn);
+ else {
+ conn->ext_input_io =
+ client->ext_input_add(fd, auth_client_input, conn);
+ }
conn->input = i_stream_create_file(fd, default_pool, MAX_INBUF_SIZE,
FALSE);
conn->output = o_stream_create_file(fd, default_pool, MAX_OUTBUF_SIZE,
@@ -235,8 +234,14 @@
if (!conn->handshake_received)
client->conn_waiting_handshake_count--;
- io_remove(conn->io);
- conn->io = NULL;
+ if (conn->ext_input_io != NULL) {
+ client->ext_input_remove(conn->ext_input_io);
+ conn->ext_input_io = NULL;
+ }
+ if (conn->io != NULL) {
+ io_remove(conn->io);
+ conn->io = NULL;
+ }
i_stream_close(conn->input);
o_stream_close(conn->output);
@@ -294,7 +299,7 @@
for (conn = client->connections; conn != NULL; conn = conn->next) {
mech = conn->available_auth_mechs;
for (i = 0; i < conn->available_auth_mechs_count; i++) {
- if (strcmp(mech[i].name, name) == 0)
+ if (strcasecmp(mech[i].name, name) == 0)
return conn;
}
}
Index: auth-server-connection.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-auth/auth-server-connection.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/auth-server-connection.h 29 May 2004 21:40:30 -0000 1.3
+++ b/auth-server-connection.h 30 May 2004 01:40:47 -0000 1.4
@@ -3,6 +3,10 @@
struct auth_client {
unsigned int pid;
+ char *socket_paths;
+
+ input_func_add_t *ext_input_add;
+ input_func_remove_t *ext_input_remove;
struct auth_server_connection *connections;
struct timeout *to_reconnect;
@@ -14,6 +18,8 @@
auth_connect_notify_callback_t *connect_notify_callback;
void *connect_notify_context;
+
+ unsigned int reconnect:1;
};
struct auth_server_connection {
@@ -27,6 +33,7 @@
int fd;
struct io *io;
+ void *ext_input_io;
struct istream *input;
struct ostream *output;
More information about the dovecot-cvs
mailing list