(main): Imply debug mode if the input stream is
connected to a tty. Don't try to switch to "mail" group id in debug mode. (imap4d_mainloop): Do not reveal our version. One may issue X-VERSION command in authenticated state to get it.
Showing
1 changed file
with
41 additions
and
22 deletions
... | @@ -25,6 +25,7 @@ FILE *ofile; | ... | @@ -25,6 +25,7 @@ FILE *ofile; |
25 | mailbox_t mbox; | 25 | mailbox_t mbox; |
26 | char *homedir; | 26 | char *homedir; |
27 | int state = STATE_NONAUTH; | 27 | int state = STATE_NONAUTH; |
28 | int debug_mode = 0; | ||
28 | 29 | ||
29 | struct daemon_param daemon_param = { | 30 | struct daemon_param daemon_param = { |
30 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ | 31 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
... | @@ -114,21 +115,30 @@ main (int argc, char **argv) | ... | @@ -114,21 +115,30 @@ main (int argc, char **argv) |
114 | pam_service = "gnu-imap4d"; | 115 | pam_service = "gnu-imap4d"; |
115 | #endif | 116 | #endif |
116 | 117 | ||
117 | /* First we want our group to be mail so we can access the spool. */ | 118 | if (isatty (0)) |
118 | gr = getgrnam ("mail"); | ||
119 | if (gr == NULL) | ||
120 | { | 119 | { |
121 | perror ("Error getting mail group"); | 120 | /* If input is a tty, switch to debug mode */ |
122 | exit (1); | 121 | debug_mode = 1; |
123 | } | 122 | } |
124 | 123 | else | |
125 | if (setgid (gr->gr_gid) == -1) | ||
126 | { | 124 | { |
127 | perror ("Error setting mail group"); | 125 | /* Normal operation: */ |
128 | exit (1); | 126 | /* First we want our group to be mail so we can access the spool. */ |
127 | gr = getgrnam ("mail"); | ||
128 | if (gr == NULL) | ||
129 | { | ||
130 | perror ("Error getting mail group"); | ||
131 | exit (1); | ||
132 | } | ||
133 | |||
134 | if (setgid (gr->gr_gid) == -1) | ||
135 | { | ||
136 | perror ("Error setting mail group"); | ||
137 | exit (1); | ||
138 | } | ||
129 | } | 139 | } |
130 | 140 | ||
131 | /* Register the desire formats. We only need Mbox mail format. */ | 141 | /* Register the desired formats. */ |
132 | { | 142 | { |
133 | list_t bookie; | 143 | list_t bookie; |
134 | registrar_get_list (&bookie); | 144 | registrar_get_list (&bookie); |
... | @@ -190,6 +200,8 @@ main (int argc, char **argv) | ... | @@ -190,6 +200,8 @@ main (int argc, char **argv) |
190 | static int | 200 | static int |
191 | imap4d_mainloop (int infile, int outfile) | 201 | imap4d_mainloop (int infile, int outfile) |
192 | { | 202 | { |
203 | char *text; | ||
204 | |||
193 | /* Reset hup to exit. */ | 205 | /* Reset hup to exit. */ |
194 | signal (SIGHUP, imap4d_signal); | 206 | signal (SIGHUP, imap4d_signal); |
195 | /* Timeout alarm. */ | 207 | /* Timeout alarm. */ |
... | @@ -202,21 +214,28 @@ imap4d_mainloop (int infile, int outfile) | ... | @@ -202,21 +214,28 @@ imap4d_mainloop (int infile, int outfile) |
202 | 214 | ||
203 | setvbuf(ofile, NULL, _IOLBF, 0); | 215 | setvbuf(ofile, NULL, _IOLBF, 0); |
204 | 216 | ||
205 | syslog (LOG_INFO, "Incoming connection opened"); | ||
206 | |||
207 | /* log information on the connecting client */ | 217 | /* log information on the connecting client */ |
208 | { | 218 | if (!debug_mode) |
209 | struct sockaddr_in cs; | 219 | { |
210 | int len = sizeof cs; | 220 | struct sockaddr_in cs; |
211 | if (getpeername (infile, (struct sockaddr*)&cs, &len) < 0) | 221 | int len = sizeof cs; |
212 | syslog (LOG_ERR, "can't obtain IP address of client: %s", | ||
213 | strerror (errno)); | ||
214 | else | ||
215 | syslog (LOG_INFO, "connect from %s", inet_ntoa(cs.sin_addr)); | ||
216 | } | ||
217 | 222 | ||
223 | syslog (LOG_INFO, "Incoming connection opened"); | ||
224 | if (getpeername (infile, (struct sockaddr*)&cs, &len) < 0) | ||
225 | syslog (LOG_ERR, "can't obtain IP address of client: %s", | ||
226 | strerror (errno)); | ||
227 | else | ||
228 | syslog (LOG_INFO, "connect from %s", inet_ntoa(cs.sin_addr)); | ||
229 | text = "IMAP4rev1"; | ||
230 | } | ||
231 | else | ||
232 | { | ||
233 | syslog (LOG_INFO, "Started in debugging mode"); | ||
234 | text = "IMAP4rev1 Debugging mode"; | ||
235 | } | ||
236 | |||
218 | /* Greetings. */ | 237 | /* Greetings. */ |
219 | util_out (RESP_OK, "IMAP4rev1 GNU " PACKAGE " " VERSION); | 238 | util_out (RESP_OK, text); |
220 | fflush (ofile); | 239 | fflush (ofile); |
221 | 240 | ||
222 | while (1) | 241 | while (1) | ... | ... |
-
Please register or sign in to post a comment