(pop3d_begin_session): New function. Implement bulletin facility
Showing
1 changed file
with
69 additions
and
76 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2002, 2003, 2005, 2007 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -18,14 +18,77 @@ | ... | @@ -18,14 +18,77 @@ |
18 | 18 | ||
19 | #include "pop3d.h" | 19 | #include "pop3d.h" |
20 | 20 | ||
21 | struct mu_auth_data *auth_data; | ||
22 | |||
23 | int | ||
24 | pop3d_begin_session () | ||
25 | { | ||
26 | int status; | ||
27 | |||
28 | if (check_login_delay (auth_data->name)) | ||
29 | { | ||
30 | syslog (LOG_INFO, | ||
31 | _("User `%s' tried to log in within the minimum allowed delay"), | ||
32 | auth_data->name); | ||
33 | state = AUTHORIZATION; | ||
34 | mu_auth_data_destroy (&auth_data); | ||
35 | return ERR_LOGIN_DELAY; | ||
36 | } | ||
37 | |||
38 | if (auth_data->change_uid) | ||
39 | setuid (auth_data->uid); | ||
40 | |||
41 | if ((status = mu_mailbox_create (&mbox, auth_data->mailbox)) != 0 | ||
42 | || (status = mu_mailbox_open (mbox, MU_STREAM_CREAT | MU_STREAM_RDWR)) != 0) | ||
43 | { | ||
44 | mu_mailbox_destroy (&mbox); | ||
45 | state = AUTHORIZATION; | ||
46 | mu_auth_data_destroy (&auth_data); | ||
47 | return ERR_MBOX_LOCK; | ||
48 | } | ||
49 | |||
50 | if (pop3d_lock ()) | ||
51 | { | ||
52 | mu_mailbox_close (mbox); | ||
53 | mu_mailbox_destroy (&mbox); | ||
54 | mu_auth_data_destroy (&auth_data); | ||
55 | state = AUTHORIZATION; | ||
56 | return ERR_MBOX_LOCK; | ||
57 | } | ||
58 | |||
59 | username = strdup (auth_data->name); | ||
60 | if (username == NULL) | ||
61 | pop3d_abquit (ERR_NO_MEM); | ||
62 | state = TRANSACTION; | ||
63 | |||
64 | pop3d_outf ("+OK opened mailbox for %s\r\n", username); | ||
65 | |||
66 | if (undelete_on_startup) | ||
67 | pop3d_undelete_all (); | ||
68 | |||
69 | deliver_pending_bulletins (); | ||
70 | |||
71 | /* mailbox name */ | ||
72 | { | ||
73 | mu_url_t url = NULL; | ||
74 | size_t total = 0; | ||
75 | mu_mailbox_get_url (mbox, &url); | ||
76 | mu_mailbox_messages_count (mbox, &total); | ||
77 | syslog (LOG_INFO, | ||
78 | ngettext ("User `%s' logged in with mailbox `%s' (%s message)", | ||
79 | "User `%s' logged in with mailbox `%s' (%s messages)", | ||
80 | (unsigned long) total), | ||
81 | username, mu_url_to_string (url), mu_umaxtostr (0, total)); | ||
82 | } | ||
83 | |||
84 | return OK; | ||
85 | } | ||
86 | |||
21 | int | 87 | int |
22 | pop3d_user (const char *arg) | 88 | pop3d_user (const char *arg) |
23 | { | 89 | { |
24 | char *buf, pass[POP_MAXCMDLEN], *tmp, *cmd; | 90 | char *buf, pass[POP_MAXCMDLEN], *tmp, *cmd; |
25 | char buffer[512]; | 91 | char buffer[512]; |
26 | int status; | ||
27 | int lockit = 1; | ||
28 | struct mu_auth_data *auth_data; | ||
29 | 92 | ||
30 | if (state != AUTHORIZATION) | 93 | if (state != AUTHORIZATION) |
31 | return ERR_WRONG_STATE; | 94 | return ERR_WRONG_STATE; |
... | @@ -85,7 +148,7 @@ pop3d_user (const char *arg) | ... | @@ -85,7 +148,7 @@ pop3d_user (const char *arg) |
85 | if (rc) | 148 | if (rc) |
86 | { | 149 | { |
87 | syslog (LOG_INFO, _("User `%s': authentication failed"), arg); | 150 | syslog (LOG_INFO, _("User `%s': authentication failed"), arg); |
88 | mu_auth_data_free (auth_data); | 151 | mu_auth_data_destroy (&auth_data); |
89 | return ERR_BAD_LOGIN; | 152 | return ERR_BAD_LOGIN; |
90 | } | 153 | } |
91 | } | 154 | } |
... | @@ -101,76 +164,6 @@ pop3d_user (const char *arg) | ... | @@ -101,76 +164,6 @@ pop3d_user (const char *arg) |
101 | return ERR_BAD_CMD; | 164 | return ERR_BAD_CMD; |
102 | } | 165 | } |
103 | 166 | ||
104 | if (check_login_delay (auth_data->name)) | 167 | return pop3d_begin_session (); |
105 | { | ||
106 | syslog (LOG_INFO, | ||
107 | _("User `%s' tried to log in within the minimum allowed delay"), | ||
108 | auth_data->name); | ||
109 | state = AUTHORIZATION; | ||
110 | mu_auth_data_free (auth_data); | ||
111 | return ERR_LOGIN_DELAY; | ||
112 | } | ||
113 | |||
114 | if (auth_data->change_uid) | ||
115 | setuid (auth_data->uid); | ||
116 | |||
117 | if ((status = mu_mailbox_create (&mbox, auth_data->mailbox)) != 0 | ||
118 | || (status = mu_mailbox_open (mbox, MU_STREAM_RDWR)) != 0) | ||
119 | { | ||
120 | mu_mailbox_destroy (&mbox); | ||
121 | /* For non existent mailbox, we fake. */ | ||
122 | if (status == ENOENT) | ||
123 | { | ||
124 | if (mu_mailbox_create (&mbox, "/dev/null") != 0 | ||
125 | || mu_mailbox_open (mbox, MU_STREAM_READ) != 0) | ||
126 | { | ||
127 | state = AUTHORIZATION; | ||
128 | mu_auth_data_free (auth_data); | ||
129 | return ERR_UNKNOWN; | ||
130 | } | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | state = AUTHORIZATION; | ||
135 | mu_auth_data_free (auth_data); | ||
136 | return ERR_MBOX_LOCK; | ||
137 | } | ||
138 | lockit = 0; /* Do not attempt to lock /dev/null ! */ | ||
139 | } | ||
140 | |||
141 | if (lockit && pop3d_lock ()) | ||
142 | { | ||
143 | mu_mailbox_close (mbox); | ||
144 | mu_mailbox_destroy (&mbox); | ||
145 | mu_auth_data_free (auth_data); | ||
146 | state = AUTHORIZATION; | ||
147 | return ERR_MBOX_LOCK; | ||
148 | } | ||
149 | |||
150 | username = strdup (auth_data->name); | ||
151 | if (username == NULL) | ||
152 | pop3d_abquit (ERR_NO_MEM); | ||
153 | state = TRANSACTION; | ||
154 | |||
155 | mu_auth_data_free (auth_data); | ||
156 | |||
157 | pop3d_outf ("+OK opened mailbox for %s\r\n", username); | ||
158 | |||
159 | if (undelete_on_startup) | ||
160 | pop3d_undelete_all (); | ||
161 | |||
162 | /* mailbox name */ | ||
163 | { | ||
164 | mu_url_t url = NULL; | ||
165 | size_t total = 0; | ||
166 | mu_mailbox_get_url (mbox, &url); | ||
167 | mu_mailbox_messages_count (mbox, &total); | ||
168 | syslog (LOG_INFO, | ||
169 | ngettext ("User `%s' logged in with mailbox `%s' (%s message)", | ||
170 | "User `%s' logged in with mailbox `%s' (%s messages)", | ||
171 | (unsigned long) total), | ||
172 | username, mu_url_to_string (url), mu_umaxtostr (0, total)); | ||
173 | } | ||
174 | return OK; | ||
175 | } | 168 | } |
176 | 169 | ... | ... |
-
Please register or sign in to post a comment