[dovecot-cvs] dovecot/src/login-common Makefile.am,1.3,1.4 auth-connection.c,1.11,1.12 client-common.h,1.2,1.3 main.c,1.7,1.8 master.c,1.5,1.6 master.h,1.2,1.3
cras at procontrol.fi
cras at procontrol.fi
Wed Mar 5 00:38:10 EET 2003
Update of /home/cvs/dovecot/src/login-common
In directory danu:/tmp/cvs-serv3661/login-common
Modified Files:
Makefile.am auth-connection.c client-common.h main.c master.c
master.h
Log Message:
login: Wait until we're connected to auth process before executing command
from client.
inetd usage: --group=name can now specify which login group to use. Default
is the binary name before '-' character (ie. imap or pop3).
Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/login-common/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile.am 4 Mar 2003 04:02:56 -0000 1.3
+++ Makefile.am 4 Mar 2003 22:38:08 -0000 1.4
@@ -17,7 +17,7 @@
noinst_HEADERS = \
auth-common.h \
auth-connection.h \
- common.h \
client-common.h \
+ common.h \
master.h \
ssl-proxy.h
Index: auth-connection.c
===================================================================
RCS file: /home/cvs/dovecot/src/login-common/auth-connection.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- auth-connection.c 4 Mar 2003 02:18:09 -0000 1.11
+++ auth-connection.c 4 Mar 2003 22:38:08 -0000 1.12
@@ -6,6 +6,7 @@
#include "network.h"
#include "istream.h"
#include "ostream.h"
+#include "client-common.h"
#include "auth-connection.h"
#include <unistd.h>
@@ -130,6 +131,9 @@
hash_foreach(conn->requests, request_hash_remove, NULL);
auth_connection_unref(conn);
+
+ if (auth_is_connected())
+ clients_notify_auth_process();
}
static void auth_connection_unref(struct auth_connection *conn)
@@ -200,8 +204,11 @@
conn->available_auth_mechs = handshake->auth_mechanisms;
conn->handshake_received = TRUE;
- auth_waiting_handshake_count--;
+ auth_waiting_handshake_count--;
update_available_auth_mechs();
+
+ if (auth_is_connected())
+ clients_notify_auth_process();
}
static void auth_handle_reply(struct auth_connection *conn,
Index: client-common.h
===================================================================
RCS file: /home/cvs/dovecot/src/login-common/client-common.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- client-common.h 2 Feb 2003 10:46:20 -0000 1.2
+++ client-common.h 4 Mar 2003 22:38:08 -0000 1.3
@@ -20,6 +20,7 @@
struct client *client_create(int fd, struct ip_addr *ip, int ssl);
unsigned int clients_get_count(void);
+void clients_notify_auth_process(void);
void clients_destroy_all(void);
void clients_init(void);
Index: main.c
===================================================================
RCS file: /home/cvs/dovecot/src/login-common/main.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- main.c 4 Mar 2003 04:02:56 -0000 1.7
+++ main.c 4 Mar 2003 22:38:08 -0000 1.8
@@ -64,7 +64,8 @@
}
closing_down = TRUE;
- master_notify_finished();
+ if (!is_inetd)
+ master_notify_finished();
}
static void sig_quit(int signo __attr_unused__)
@@ -77,13 +78,6 @@
struct ip_addr ip;
int fd;
- if (!auth_is_connected()) {
- /* we're not yet connected to auth process -
- don't accept client connections. FIXME: eats CPU if
- none of the other login processes accept it either.. */
- return;
- }
-
fd = net_accept(LOGIN_LISTEN_FD, &ip, NULL);
if (fd < 0) {
if (fd < -1)
@@ -102,13 +96,6 @@
struct ip_addr ip;
int fd, fd_ssl;
- if (!auth_is_connected()) {
- /* we're not yet connected to auth process -
- don't accept client connections. FIXME: eats CPU if
- none of the other login processes accept it either.. */
- return;
- }
-
fd = net_accept(LOGIN_SSL_LISTEN_FD, &ip, NULL);
if (fd < 0) {
if (fd < -1)
@@ -205,7 +192,7 @@
/* initialize master last - it sends the "we're ok"
notification */
- master_init(LOGIN_MASTER_SOCKET_FD);
+ master_init(LOGIN_MASTER_SOCKET_FD, TRUE);
}
}
@@ -228,9 +215,9 @@
int main(int argc __attr_unused__, char *argv[], char *envp[])
{
- const char *name;
+ const char *name, *group_name;
struct ip_addr ip;
- int fd = -1, master_fd = -1;
+ int i, fd = -1, master_fd = -1;
is_inetd = getenv("DOVECOT_MASTER") == NULL;
@@ -244,8 +231,19 @@
if (is_inetd) {
/* running from inetd. create master process before
- dropping privileges */
- master_fd = master_connect();
+ dropping privileges. */
+ group_name = strrchr(argv[0], '/');
+ group_name = group_name == NULL ? argv[0] : group_name+1;
+ group_name = t_strcut(group_name, '-');
+
+ for (i = 1; i < argc; i++) {
+ if (strncmp(argv[i], "--group=", 8) == 0) {
+ group_name = argv[1]+8;
+ break;
+ }
+ }
+
+ master_fd = master_connect(group_name);
}
name = strrchr(argv[0], '/');
@@ -253,30 +251,34 @@
process_title_init(argv, envp);
ioloop = io_loop_create(system_pool);
+ main_init();
if (is_inetd) {
- master_init(master_fd);
-
if (net_getsockname(1, &ip, NULL) < 0) {
i_fatal("%s can be started only through dovecot "
"master process, inetd or equilevant", argv[0]);
}
- if (argc < 2 || strcmp(argv[1], "--ssl") != 0)
- fd = 1;
- else
- fd = ssl_proxy_new(fd, &ip);
+ fd = 1;
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "--ssl") == 0) {
+ fd = ssl_proxy_new(fd, &ip);
+ if (fd == -1)
+ i_fatal("SSL initialization failed");
+ } else if (strncmp(argv[i], "--group=", 8) != 0)
+ i_fatal("Unknown parameter: %s", argv[i]);
+ }
+
+ master_init(master_fd, FALSE);
}
- if (fd != -1 || !is_inetd) {
- main_init();
+ main_close_listen();
- if (fd != -1)
- (void)client_create(fd, &ip, TRUE);
+ if (fd != -1)
+ (void)client_create(fd, &ip, TRUE);
- io_loop_run(ioloop);
- main_deinit();
- }
+ io_loop_run(ioloop);
+ main_deinit();
io_loop_destroy(ioloop);
lib_deinit();
Index: master.c
===================================================================
RCS file: /home/cvs/dovecot/src/login-common/master.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- master.c 4 Mar 2003 04:02:56 -0000 1.5
+++ master.c 4 Mar 2003 22:38:08 -0000 1.6
@@ -7,6 +7,7 @@
#include "fdpass.h"
#include "istream.h"
#include "env-util.h"
+#include "write-full.h"
#include "master.h"
#include "client-common.h"
@@ -133,7 +134,7 @@
i_stream_unref(input);
}
-int master_connect(void)
+int master_connect(const char *group_name)
{
const char *path = PKG_RUNDIR"/master";
int i, fd = -1;
@@ -164,6 +165,19 @@
if (fd == -1)
i_fatal("Couldn't use/create UNIX socket %s", path);
+ if (group_name[0] == '\0')
+ i_fatal("No login group name set");
+
+ if (strlen(group_name) >= 256)
+ i_fatal("Login group name too large: %s", group_name);
+
+ /* group_name length is now guaranteed to be in range of 1..255 so we
+ can send <length byte><name> */
+ group_name = t_strdup_printf("%c%s", (unsigned char)strlen(group_name),
+ group_name);
+ if (write_full(fd, group_name, strlen(group_name)) < 0)
+ i_fatal("write_full(master_fd) failed: %m");
+
master_read_env(fd);
return fd;
}
@@ -189,7 +203,7 @@
master_pos = 0;
}
-void master_init(int fd)
+void master_init(int fd, int notify)
{
main_ref();
@@ -200,9 +214,11 @@
master_pos = 0;
io_master = io_add(master_fd, IO_READ, master_input, NULL);
- /* just a note to master that we're ok. if we die before,
- master should shutdown itself. */
- master_notify_finished();
+ if (notify) {
+ /* just a note to master that we're ok. if we die before,
+ master should shutdown itself. */
+ master_notify_finished();
+ }
}
void master_deinit(void)
Index: master.h
===================================================================
RCS file: /home/cvs/dovecot/src/login-common/master.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- master.h 4 Mar 2003 04:02:56 -0000 1.2
+++ master.h 4 Mar 2003 22:38:08 -0000 1.3
@@ -17,9 +17,9 @@
void master_close(void);
/* inetd: Connect to existing master process, or create new one. */
-int master_connect(void);
+int master_connect(const char *group_name);
-void master_init(int fd);
+void master_init(int fd, int notify);
void master_deinit(void);
#endif
More information about the dovecot-cvs
mailing list