/[imapfilter]/imapfilter/imapfilter.c
ViewVC logotype

Contents of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (show annotations)
Tue Jan 29 21:23:41 2002 UTC (22 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.25: +21 -9 lines
File MIME type: text/plain
Added secure memory allocation subsystem.

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <limits.h>
6 #include <errno.h>
7
8 #include "config.h"
9 #include "imapfilter.h"
10 #include "data.h"
11
12
13 extern account_t *accounts;
14 extern filter_t *filters;
15
16 unsigned int options; /* Program options. */
17 unsigned int capabilities; /* Capabilities of mail server. */
18 char logfile[PATH_MAX]; /* Log file. */
19 char *home = NULL; /* User's home directory. */
20 uid_t ruid, euid; /* Real and effective UID. */
21
22
23 /*
24 * In the beginning there was main()...
25 */
26 int main(int argc, char *argv[])
27 {
28 int c, r;
29 char *confile = NULL; /* Configuration file. */
30 account_t *ca; /* Current account. */
31 mbox_t *cm; /* Current mailbox. */
32
33 ruid = getuid();
34 euid = geteuid();
35
36 seteuid(ruid); /* Drop root privileges. */
37
38 corefile_disable();
39
40 options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE);
41 *logfile = 0;
42 home = getenv("HOME");
43
44 #ifndef ENCRYPTED_PASSWORDS
45 while ((c = getopt(argc, argv, "c:hl:qv")) != -1) {
46 #else
47 while ((c = getopt(argc, argv, "c:hl:pqv")) != -1) {
48 #endif
49 switch (c) {
50 case 'c':
51 confile = optarg;
52 break;
53 case 'h':
54 usage();
55 exit(ERROR_UNDEFINED);
56 break;
57 case 'l':
58 strncat(logfile, optarg, PATH_MAX - 1);
59 break;
60 #ifdef ENCRYPTED_PASSWORDS
61 case 'p':
62 options |= OPTION_PASSWORD_EDITOR;
63 break;
64 #endif
65 case 'q':
66 options &= OPTION_DETAILS_CLEAR;
67 options |= OPTION_DETAILS_QUIET;
68 break;
69 case 'v':
70 options &= OPTION_DETAILS_CLEAR;
71 options |= OPTION_DETAILS_VERBOSE;
72 break;
73 default:
74 usage();
75 exit(ERROR_UNDEFINED);
76 break;
77 }
78 }
79
80 tty_store();
81 catch_signals();
82
83 create_homedir();
84
85 read_config(confile);
86 open_logfile();
87
88 #ifdef ENCRYPTED_PASSWORDS
89 read_passwords();
90
91 if ((options & OPTION_PASSWORD_EDITOR))
92 password_editor();
93 #endif
94
95 setuid(ruid); /* Capability to regain root privileges
96 will not be needed any more. */
97
98
99 for (ca = accounts; ca; ca = ca->next) {
100
101 #ifndef SSL_TLS
102 if (init_connection(ca->server, ca->port))
103 #else
104 if (init_connection(ca->server, ca->port, ca->ssl))
105 #endif
106 continue;
107
108 r = greeting_response();
109
110 if (r == RESPONSE_BYE || check_capabilities())
111 continue;
112
113 #ifdef DEBUG
114 test();
115 #endif
116
117 if (r != RESPONSE_PREAUTH) {
118 if (ca->passwdattr == PASSWORD_NONE) {
119 printf("Enter password for %s@%s: ", ca->username, ca->server);
120 get_password(ca->password, PASSWORD_LEN);
121 }
122 if (login(ca->username, ca->password))
123 continue;
124 }
125 check_namespace();
126
127 for (cm = ca->mboxes; cm; cm = cm->next)
128 if (!*cm->filters)
129 mailbox_status(cm->name);
130 else if (!select_mailbox(cm->name)) {
131 apply_filters(cm->filters);
132 close_mailbox();
133 }
134 logout();
135
136 close_connection();
137 }
138
139 secmem_clear();
140 close_logfile();
141 corefile_restore();
142
143 exit(0);
144 }
145
146
147 /*
148 * Print a very brief usage message.
149 */
150 void usage(void)
151 {
152 fprintf(stderr,
153 "usage: imapfilter [-h"
154 #ifdef ENCRYPTED_PASSWORDS
155 "p"
156 #endif
157 "qv] [-c configfile] [-l logfile]\n");
158 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26