annotate src/osdep/unix/env_unix.c @ 4:d741b3ecc917 draft

imapext-2007f
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 30 Oct 2014 00:03:05 +0900
parents 2366b362676d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1 /* ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
2 * Copyright 1988-2008 University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
3 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
6 * You may obtain a copy of the License at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
7 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
9 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
10 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
11 * ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
12 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
13
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
14 /*
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
15 * Program: UNIX environment routines
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
16 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
17 * Author: Mark Crispin
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
18 * UW Technology
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
19 * University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
20 * Seattle, WA 98195
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
21 * Internet: MRC@Washington.EDU
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
22 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
23 * Date: 1 August 1988
3
2366b362676d imap-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 1
diff changeset
24 * Last Edited: 23 February 2009
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
25 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
26
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
27 #include <grp.h>
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
28 #include <signal.h>
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
29 #include <sys/wait.h>
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
30
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
31
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
32 /* in case stat.h is ancient */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
33
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
34 #ifndef S_IRUSR
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
35 #define S_IRUSR S_IREAD
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
36 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
37 #ifndef S_IWUSR
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
38 #define S_IWUSR S_IWRITE
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
39 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
40 #ifndef S_IXUSR
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
41 #define S_IXUSR S_IEXEC
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
42 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
43 #ifndef S_IRGRP
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
44 #define S_IRGRP (S_IREAD >> 3)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
45 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
46 #ifndef S_IWGRP
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
47 #define S_IWGRP (S_IWRITE >> 3)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
48 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
49 #ifndef S_IXGRP
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
50 #define S_IXGRP (S_IEXEC >> 3)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
51 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
52 #ifndef S_IROTH
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
53 #define S_IROTH (S_IREAD >> 6)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
54 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
55 #ifndef S_IWOTH
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
56 #define S_IWOTH (S_IWRITE >> 6)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
57 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
58 #ifndef S_IXOTH
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
59 #define S_IXOTH (S_IEXEC >> 6)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
60 #endif
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
61
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
62 /* c-client environment parameters */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
63
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
64 static char *myUserName = NIL; /* user name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
65 static char *myHomeDir = NIL; /* home directory name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
66 static char *myServerName = NIL;/* server name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
67 static char *myLocalHost = NIL; /* local host name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
68 static char *myNewsrc = NIL; /* newsrc file name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
69 static char *mailsubdir = NIL; /* mailbox subdirectory name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
70 static char *sysInbox = NIL; /* system inbox name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
71 static char *newsActive = NIL; /* news active file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
72 static char *newsSpool = NIL; /* news spool */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
73 static char *blackBoxDir = NIL; /* black box directory name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
74 /* black box default home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
75 static char *blackBoxDefaultHome = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
76 static char *sslCApath = NIL; /* non-standard CA path */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
77 static short anonymous = NIL; /* is anonymous */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
78 static short blackBox = NIL; /* is a black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
79 static short closedBox = NIL; /* is a closed box (uses chroot() jail) */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
80 static short restrictBox = NIL; /* is a restricted box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
81 static short has_no_life = NIL; /* is a cretin with no life */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
82 /* block environment init */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
83 static short block_env_init = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
84 static short hideDotFiles = NIL;/* hide files whose names start with . */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
85 /* advertise filesystem root */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
86 static short advertisetheworld = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
87 /* only advertise own mailboxes and #shared */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
88 static short limitedadvertise = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
89 /* disable automatic shared namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
90 static short noautomaticsharedns = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
91 static short no822tztext = NIL; /* disable RFC [2]822 timezone text */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
92 /* client principals include service name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
93 static short kerb_cp_svr_name = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
94 static long locktimeout = 5; /* default lock timeout in minutes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
95 /* default prototypes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
96 static MAILSTREAM *createProto = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
97 static MAILSTREAM *appendProto = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
98 /* default user flags */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
99 static char *userFlags[NUSERFLAGS] = {NIL};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
100 static NAMESPACE *nslist[3]; /* namespace list */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
101 static int logtry = 3; /* number of server login tries */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
102 /* block notification */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
103 static blocknotify_t mailblocknotify = mm_blocknotify;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
104 /* logout function */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
105 static logouthook_t maillogouthook = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
106 /* logout data */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
107 static void *maillogoutdata = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
108 /* allow user config files */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
109 static short allowuserconfig = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
110 /* 1 = disable plaintext, 2 = if not SSL */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
111 static long disablePlaintext = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
112 static long list_max_level = 20;/* maximum level of list recursion */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
113 /* facility for syslog */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
114 static int syslog_facility = LOG_MAIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
115
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
116 /* Path of the privileged system lock program (mlock). Normally set by
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
117 * logic test.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
118 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
119
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
120 static char *lockpgm = LOCKPGM;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
121
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
122 /* Directory used for shared locks. MUST be the same for all users of the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
123 * system, and MUST be protected 1777. /var/tmp may be preferable on some
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
124 * systems.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
125 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
126
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
127 static const char *tmpdir = "/tmp";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
128
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
129 /* Do not change shlock_mode. Doing so can cause mailbox corruption and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
130 * denial of service. It also defeats the entire purpose of the shared
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
131 * lock mechanism. The right way to avoid shared locks is to set up a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
132 * closed box (see the closedBox setting).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
133 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
134
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
135 /* shared lock mode */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
136 static const int shlock_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
137
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
138
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
139 /* It is STRONGLY recommended that you do not change dotlock_mode. Doing so
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
140 * can cause denial of service with old dot-lock files left lying around.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
141 * However, since dot-locks are only used with traditional UNIX and MMDF
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
142 * formats which are not normally shared, it is much less harmful to tamper
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
143 * with this than with shlock_mode.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
144 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
145
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
146 /* dot-lock mode */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
147 static long dotlock_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
148
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
149 /* File/directory access and protection policies */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
150
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
151 /* Unlike shlock_mode, the ????_protection modes are intended to be fully
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
152 * customizable according to site policy. The values here are recommended
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
153 * settings, based upon the documented purposes of the namespaces.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
154 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
155
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
156 /* user space - only owner can read/write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
157 static char *myMailboxDir = NIL;/* user space directory name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
158 /* default file protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
159 static long mbx_protection = S_IRUSR|S_IWUSR;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
160 /* default directory protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
161 static long dir_protection = S_IRUSR|S_IWUSR|S_IXUSR;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
162
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
163 /* user space for user "anonymous" */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
164 /* anonymous home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
165 static char *anonymousHome = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
166
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
167 /* #ftp - everybody can read, only owner can write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
168 static char *ftpHome = NIL; /* ftp export home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
169 /* default ftp file protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
170 static long ftp_protection = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
171 static long ftp_dir_protection =/* default ftp directory protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
172 S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
173
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
174 /* #public - everybody can read/write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
175 static char *publicHome = NIL; /* public home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
176 static long public_protection = /* default public file protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
177 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
178 /* default public directory protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
179 static long public_dir_protection =
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
180 S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
181
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
182 /* #shared/ - owner and group members can read/write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
183 static char *sharedHome = NIL; /* shared home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
184 /* default shared file protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
185 static long shared_protection = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
186 /* default shared directory protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
187 static long shared_dir_protection =
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
188 S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
189
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
190 /* OS bug workarounds - should be avoided at all cost */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
191
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
192
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
193 /* Don't set fcntlhangbug unless you really have to, since it risks mailbox
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
194 * corruption. The flocksim.c mechanism is designed to detect NFS access
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
195 * and no-op in that cases only, so this flag should be unnecessary.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
196 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
197
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
198 static short fcntlhangbug = NIL;/* flock() emulator using fcntl() is a no-op */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
199
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
200
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
201 /* Don't set netfsstatbug unless you really have to, since it dramatically
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
202 * slows down traditional UNIX and MMDF mailbox performance.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
203 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
204
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
205 static short netfsstatbug = NIL;/* compensate for broken stat() on network
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
206 * filesystems (AFS and old NFS)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
207 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
208
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
209
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
210 /* Note: setting disableLockWarning means that you assert that the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
211 * so-modified copy of this software will NEVER be used:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
212 * 1) in conjunction with any software which expects .lock files
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
213 * 2) to access NFS-mounted files and directories
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
214 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
215 * Unless both of these conditions apply, then do not set this flag.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
216 * Instead, read the FAQ (item 7.10) and either use 1777 protection
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
217 * on the mail spool, or install mlock.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
218 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
219 * In addition, by setting this flag you also agree that you are fully
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
220 * legally and morally responsible when (not if) mail files are damaged
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
221 * as the result of your choice.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
222 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
223 * The mlock tool exists for a reason. Use it.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
224 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
225 /* disable warning if can't make .lock file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
226 static short disableLockWarning = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
227
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
228 /* UNIX Namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
229
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
230 /* personal mh namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
231 static NAMESPACE nsmhf = {"#mh/",'/',NIL,NIL};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
232 static NAMESPACE nsmh = {"#mhinbox",NIL,NIL,&nsmhf};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
233 /* home namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
234 static NAMESPACE nshome = {"",'/',NIL,&nsmh};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
235 /* UNIX other user namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
236 static NAMESPACE nsunixother = {"~",'/',NIL,NIL};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
237 /* black box other user namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
238 static NAMESPACE nsblackother = {"/",'/',NIL,NIL};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
239 /* public (anonymous OK) namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
240 static NAMESPACE nspublic = {"#public/",'/',NIL,NIL};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
241 /* netnews namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
242 static NAMESPACE nsnews = {"#news.",'.',NIL,&nspublic};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
243 /* FTP export namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
244 static NAMESPACE nsftp = {"#ftp/",'/',NIL,&nsnews};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
245 /* shared (no anonymous) namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
246 static NAMESPACE nsshared = {"#shared/",'/',NIL,&nsftp};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
247 /* world namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
248 static NAMESPACE nsworld = {"/",'/',NIL,&nsshared};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
249 /* only shared and public namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
250 static NAMESPACE nslimited = {"#shared/",'/',NIL,&nspublic};
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
251
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
252
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
253
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
254 #include "write.c" /* include safe writing routines */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
255 #include "crexcl.c" /* include exclusive create */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
256 #include "pmatch.c" /* include wildcard pattern matcher */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
257
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
258 /* Get all authenticators */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
259
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
260 #include "auths.c"
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
261
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
262 /* Environment manipulate parameters
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
263 * Accepts: function code
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
264 * function-dependent value
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
265 * Returns: function-dependent return value
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
266 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
267
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
268 void *env_parameters (long function,void *value)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
269 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
270 void *ret = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
271 switch ((int) function) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
272 case GET_NAMESPACE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
273 ret = (void *) nslist;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
274 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
275 case SET_USERNAME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
276 if (myUserName) fs_give ((void **) &myUserName);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
277 myUserName = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
278 case GET_USERNAME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
279 ret = (void *) myUserName;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
280 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
281 case SET_HOMEDIR:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
282 if (myHomeDir) fs_give ((void **) &myHomeDir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
283 myHomeDir = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
284 case GET_HOMEDIR:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
285 ret = (void *) myHomeDir;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
286 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
287 case SET_LOCALHOST:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
288 if (myLocalHost) fs_give ((void **) &myLocalHost);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
289 myLocalHost = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
290 case GET_LOCALHOST:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
291 ret = (void *) myLocalHost;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
292 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
293 case SET_NEWSRC:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
294 if (myNewsrc) fs_give ((void **) &myNewsrc);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
295 myNewsrc = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
296 case GET_NEWSRC:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
297 ret = (void *) myNewsrc;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
298 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
299 case SET_NEWSACTIVE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
300 if (newsActive) fs_give ((void **) &newsActive);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
301 newsActive = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
302 case GET_NEWSACTIVE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
303 ret = (void *) newsActive;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
304 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
305 case SET_NEWSSPOOL:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
306 if (newsSpool) fs_give ((void **) &newsSpool);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
307 newsSpool = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
308 case GET_NEWSSPOOL:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
309 ret = (void *) newsSpool;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
310 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
311
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
312 case SET_ANONYMOUSHOME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
313 if (anonymousHome) fs_give ((void **) &anonymousHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
314 anonymousHome = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
315 case GET_ANONYMOUSHOME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
316 if (!anonymousHome) anonymousHome = cpystr (ANONYMOUSHOME);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
317 ret = (void *) anonymousHome;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
318 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
319 case SET_FTPHOME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
320 if (ftpHome) fs_give ((void **) &ftpHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
321 ftpHome = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
322 case GET_FTPHOME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
323 ret = (void *) ftpHome;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
324 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
325 case SET_PUBLICHOME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
326 if (publicHome) fs_give ((void **) &publicHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
327 publicHome = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
328 case GET_PUBLICHOME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
329 ret = (void *) publicHome;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
330 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
331 case SET_SHAREDHOME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
332 if (sharedHome) fs_give ((void **) &sharedHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
333 sharedHome = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
334 case GET_SHAREDHOME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
335 ret = (void *) sharedHome;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
336 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
337 case SET_SYSINBOX:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
338 if (sysInbox) fs_give ((void **) &sysInbox);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
339 sysInbox = cpystr ((char *) value);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
340 case GET_SYSINBOX:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
341 ret = (void *) sysInbox;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
342 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
343 case SET_SSLCAPATH: /* this can be set null */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
344 if (sslCApath) fs_give ((void **) &sslCApath);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
345 sslCApath = value ? cpystr ((char *) value) : value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
346 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
347 case GET_SSLCAPATH:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
348 ret = (void *) sslCApath;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
349 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
350 case SET_LISTMAXLEVEL:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
351 list_max_level = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
352 case GET_LISTMAXLEVEL:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
353 ret = (void *) list_max_level;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
354 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
355
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
356 case SET_MBXPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
357 mbx_protection = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
358 case GET_MBXPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
359 ret = (void *) mbx_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
360 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
361 case SET_DIRPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
362 dir_protection = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
363 case GET_DIRPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
364 ret = (void *) dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
365 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
366 case SET_LOCKPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
367 dotlock_mode = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
368 case GET_LOCKPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
369 ret = (void *) dotlock_mode;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
370 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
371 case SET_FTPPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
372 ftp_protection = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
373 case GET_FTPPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
374 ret = (void *) ftp_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
375 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
376 case SET_PUBLICPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
377 public_protection = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
378 case GET_PUBLICPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
379 ret = (void *) public_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
380 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
381 case SET_SHAREDPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
382 shared_protection = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
383 case GET_SHAREDPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
384 ret = (void *) shared_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
385 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
386 case SET_FTPDIRPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
387 ftp_dir_protection = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
388 case GET_FTPDIRPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
389 ret = (void *) ftp_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
390 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
391 case SET_PUBLICDIRPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
392 public_dir_protection = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
393 case GET_PUBLICDIRPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
394 ret = (void *) public_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
395 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
396 case SET_SHAREDDIRPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
397 shared_dir_protection = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
398 case GET_SHAREDDIRPROTECTION:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
399 ret = (void *) shared_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
400 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
401
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
402 case SET_LOCKTIMEOUT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
403 locktimeout = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
404 case GET_LOCKTIMEOUT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
405 ret = (void *) locktimeout;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
406 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
407 case SET_DISABLEFCNTLLOCK:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
408 fcntlhangbug = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
409 case GET_DISABLEFCNTLLOCK:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
410 ret = (void *) (fcntlhangbug ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
411 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
412 case SET_LOCKEACCESERROR:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
413 disableLockWarning = value ? NIL : T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
414 case GET_LOCKEACCESERROR:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
415 ret = (void *) (disableLockWarning ? NIL : VOIDT);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
416 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
417 case SET_HIDEDOTFILES:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
418 hideDotFiles = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
419 case GET_HIDEDOTFILES:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
420 ret = (void *) (hideDotFiles ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
421 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
422 case SET_DISABLEPLAINTEXT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
423 disablePlaintext = (long) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
424 case GET_DISABLEPLAINTEXT:
4
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
425 #ifdef RESTRICT_POP
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
426 if (getenv("INTRANET") == NIL) disablePlaintext = 1;
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
427 else disablePlaintext = NIL;
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
428 #endif
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
429 ret = (void *) disablePlaintext;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
430 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
431 case SET_CHROOTSERVER:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
432 closedBox = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
433 case GET_CHROOTSERVER:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
434 ret = (void *) (closedBox ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
435 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
436 case SET_ADVERTISETHEWORLD:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
437 advertisetheworld = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
438 case GET_ADVERTISETHEWORLD:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
439 ret = (void *) (advertisetheworld ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
440 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
441 case SET_LIMITEDADVERTISE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
442 limitedadvertise = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
443 case GET_LIMITEDADVERTISE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
444 ret = (void *) (limitedadvertise ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
445 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
446 case SET_DISABLEAUTOSHAREDNS:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
447 noautomaticsharedns = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
448 case GET_DISABLEAUTOSHAREDNS:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
449 ret = (void *) (noautomaticsharedns ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
450 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
451 case SET_DISABLE822TZTEXT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
452 no822tztext = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
453 case GET_DISABLE822TZTEXT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
454 ret = (void *) (no822tztext ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
455 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
456
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
457 case SET_USERHASNOLIFE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
458 has_no_life = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
459 case GET_USERHASNOLIFE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
460 ret = (void *) (has_no_life ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
461 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
462 case SET_KERBEROS_CP_SVR_NAME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
463 kerb_cp_svr_name = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
464 case GET_KERBEROS_CP_SVR_NAME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
465 ret = (void *) (kerb_cp_svr_name ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
466 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
467 case SET_NETFSSTATBUG:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
468 netfsstatbug = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
469 case GET_NETFSSTATBUG:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
470 ret = (void *) (netfsstatbug ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
471 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
472 case SET_BLOCKENVINIT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
473 block_env_init = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
474 case GET_BLOCKENVINIT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
475 ret = (void *) (block_env_init ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
476 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
477 case SET_BLOCKNOTIFY:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
478 mailblocknotify = (blocknotify_t) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
479 case GET_BLOCKNOTIFY:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
480 ret = (void *) mailblocknotify;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
481 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
482 case SET_LOGOUTHOOK:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
483 maillogouthook = (logouthook_t) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
484 case GET_LOGOUTHOOK:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
485 ret = maillogouthook;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
486 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
487 case SET_LOGOUTDATA:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
488 maillogoutdata = (void *) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
489 case GET_LOGOUTDATA:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
490 ret = maillogoutdata;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
491 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
492 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
493 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
494
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
495 /* Write current time
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
496 * Accepts: destination string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
497 * optional format of day-of-week prefix
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
498 * format of date and time
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
499 * flag whether to append symbolic timezone
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
500 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
501
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
502 static void do_date (char *date,char *prefix,char *fmt,int suffix)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
503 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
504 time_t tn = time (0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
505 struct tm *t = gmtime (&tn);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
506 int zone = t->tm_hour * 60 + t->tm_min;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
507 int julian = t->tm_yday;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
508 t = localtime (&tn); /* get local time now */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
509 /* minus UTC minutes since midnight */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
510 zone = t->tm_hour * 60 + t->tm_min - zone;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
511 /* julian can be one of:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
512 * 36x local time is December 31, UTC is January 1, offset -24 hours
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
513 * 1 local time is 1 day ahead of UTC, offset +24 hours
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
514 * 0 local time is same day as UTC, no offset
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
515 * -1 local time is 1 day behind UTC, offset -24 hours
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
516 * -36x local time is January 1, UTC is December 31, offset +24 hours
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
517 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
518 if (julian = t->tm_yday -julian)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
519 zone += ((julian < 0) == (abs (julian) == 1)) ? -24*60 : 24*60;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
520 if (prefix) { /* want day of week? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
521 sprintf (date,prefix,days[t->tm_wday]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
522 date += strlen (date); /* make next sprintf append */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
523 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
524 /* output the date */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
525 sprintf (date,fmt,t->tm_mday,months[t->tm_mon],t->tm_year+1900,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
526 t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
527 /* append timezone suffix if desired */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
528 if (suffix) rfc822_timezone (date,(void *) t);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
529 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
530
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
531 /* Write current time in RFC 822 format
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
532 * Accepts: destination string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
533 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
534
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
535 void rfc822_date (char *date)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
536 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
537 do_date (date,"%s, ","%d %s %d %02d:%02d:%02d %+03d%02d",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
538 no822tztext ? NIL : T);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
539 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
540
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
541
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
542 /* Write current time in fixed-width RFC 822 format
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
543 * Accepts: destination string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
544 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
545
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
546 void rfc822_fixed_date (char *date)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
547 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
548 do_date (date,NIL,"%02d %s %4d %02d:%02d:%02d %+03d%02d",NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
549 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
550
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
551
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
552 /* Write current time in internal format
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
553 * Accepts: destination string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
554 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
555
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
556 void internal_date (char *date)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
557 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
558 do_date (date,NIL,"%02d-%s-%d %02d:%02d:%02d %+03d%02d",NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
559 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
560
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
561 /* Initialize server
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
562 * Accepts: server name for syslog or NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
563 * /etc/services service name or NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
564 * alternate /etc/services service name or NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
565 * clock interrupt handler
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
566 * kiss-of-death interrupt handler
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
567 * hangup interrupt handler
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
568 * termination interrupt handler
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
569 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
570
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
571 void server_init (char *server,char *service,char *sslservice,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
572 void *clkint,void *kodint,void *hupint,void *trmint,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
573 void *staint)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
574 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
575 int onceonly = server && service && sslservice;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
576 if (onceonly) { /* set server name in syslog */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
577 int mask;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
578 openlog (myServerName = cpystr (server),LOG_PID,syslog_facility);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
579 fclose (stderr); /* possibly save a process ID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
580 dorc (NIL,NIL); /* do systemwide configuration */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
581 switch (mask = umask (022)){/* check old umask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
582 case 0: /* definitely unreasonable */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
583 case 022: /* don't need to change it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
584 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
585 default: /* already was a reasonable value */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
586 umask (mask); /* so change it back */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
587 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
588 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
589 arm_signal (SIGALRM,clkint); /* prepare for clock interrupt */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
590 arm_signal (SIGUSR2,kodint); /* prepare for Kiss Of Death */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
591 arm_signal (SIGHUP,hupint); /* prepare for hangup */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
592 arm_signal (SIGPIPE,hupint); /* alternative hangup */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
593 arm_signal (SIGTERM,trmint); /* prepare for termination */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
594 /* status dump */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
595 if (staint) arm_signal (SIGUSR1,staint);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
596 if (onceonly) { /* set up network and maybe SSL */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
597 long port;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
598 struct servent *sv;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
599 /* Use SSL if SSL service, or if server starts with "s" and not service */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
600 if (((port = tcp_serverport ()) >= 0)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
601 if ((sv = getservbyname (service,"tcp")) && (port == ntohs (sv->s_port)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
602 syslog (LOG_DEBUG,"%s service init from %s",service,tcp_clientaddr ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
603 else if ((sv = getservbyname (sslservice,"tcp")) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
604 (port == ntohs (sv->s_port))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
605 syslog (LOG_DEBUG,"%s SSL service init from %s",sslservice,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
606 tcp_clientaddr ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
607 ssl_server_init (server);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
608 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
609 else { /* not service or SSL service port */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
610 syslog (LOG_DEBUG,"port %ld service init from %s",port,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
611 tcp_clientaddr ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
612 if (*server == 's') ssl_server_init (server);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
613 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
614 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
615 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
616 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
617
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
618 /* Wait for stdin input
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
619 * Accepts: timeout in seconds
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
620 * Returns: T if have input on stdin, else NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
621 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
622
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
623 long server_input_wait (long seconds)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
624 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
625 fd_set rfd,efd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
626 struct timeval tmo;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
627 FD_ZERO (&rfd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
628 FD_ZERO (&efd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
629 FD_SET (0,&rfd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
630 FD_SET (0,&efd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
631 tmo.tv_sec = seconds; tmo.tv_usec = 0;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
632 return select (1,&rfd,0,&efd,&tmo) ? LONGT : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
633 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
634
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
635 /* Return UNIX password entry for user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
636 * Accepts: user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
637 * Returns: password entry
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
638 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
639 * Tries all-lowercase form of user name if given user name fails
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
640 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
641
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
642 static struct passwd *pwuser (unsigned char *user)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
643 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
644 unsigned char *s;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
645 struct passwd *pw = getpwnam (user);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
646 if (!pw) { /* failed, see if any uppercase characters */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
647 for (s = user; *s && ((*s < 'A') || (*s > 'Z')); s++);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
648 if (*s) { /* yes, try all lowercase form */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
649 pw = getpwnam (s = lcase (cpystr (user)));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
650 fs_give ((void **) &s);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
651 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
652 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
653 return pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
654 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
655
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
656
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
657 /* Validate password for user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
658 * Accepts: user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
659 * password string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
660 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
661 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
662 * Returns: password entry if validated
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
663 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
664 * Tries password+1 if password fails and starts with space
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
665 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
666
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
667 static struct passwd *valpwd (char *user,char *pwd,int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
668 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
669 char *s;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
670 struct passwd *pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
671 struct passwd *ret = NIL;
4
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
672 #ifndef QMAIL /* imapext md5 checker run previously. no need to do here */
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
673 if (auth_md5.server) { /* using CRAM-MD5 authentication? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
674 if (s = auth_md5_pwd (user)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
675 if (!strcmp (s,pwd) || ((*pwd == ' ') && pwd[1] && !strcmp (s,pwd+1)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
676 ret = pwuser (user); /* validated, get passwd entry for user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
677 memset (s,0,strlen (s)); /* erase sensitive information */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
678 fs_give ((void **) &s);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
679 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
680 }
4
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
681 else
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
682 #endif
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
683 if (pw = pwuser (user)) {/* can get user? */
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
684 s = cpystr (pw->pw_name); /* copy returned name in case we need it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
685 if (*pwd && !(ret = checkpw (pw,pwd,argc,argv)) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
686 (*pwd == ' ') && pwd[1] && (ret = pwuser (s)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
687 ret = checkpw (pw,pwd+1,argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
688 fs_give ((void **) &s); /* don't need copy of name any more */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
689 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
690 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
691 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
692
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
693 /* Server log in
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
694 * Accepts: user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
695 * password string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
696 * authenticating user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
697 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
698 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
699 * Returns: T if password validated, NIL otherwise
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
700 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
701
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
702 long server_login (char *user,char *pwd,char *authuser,int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
703 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
704 struct passwd *pw = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
705 int level = LOG_NOTICE;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
706 char *err = "failed";
4
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
707 #ifdef QMAIL
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
708 char usr[MAILTMPLEN], *apoppswd;
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
709 strncpy(usr, user, MAILTMPLEN-1);
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
710 #endif
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
711 /* cretins still haven't given up */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
712 if ((strlen (user) >= NETMAXUSER) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
713 (authuser && (strlen (authuser) >= NETMAXUSER))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
714 level = LOG_ALERT; /* escalate this alert */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
715 err = "SYSTEM BREAK-IN ATTEMPT";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
716 logtry = 0; /* render this session useless */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
717 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
718 else if (logtry-- <= 0) err = "excessive login failures";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
719 else if (disablePlaintext) err = "disabled";
4
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
720 #ifdef QMAIL
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
721 else if ((logtry > 0) &&
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
722 (apoppswd = auth_md5_pwd(usr))
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
723 && !strcmp(apoppswd, pwd)
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
724 && (pw = getpwnam(usr))) {
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
725 memset(apoppswd, 0, strlen(apoppswd));
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
726 fs_give((void**) &apoppswd);
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
727 return pw_login(pw, usr, pw->pw_name, pw->pw_dir, argc, argv);
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
728 }
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
729 #endif
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
730 else if (!(authuser && *authuser)) pw = valpwd (user,pwd,argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
731 else if (valpwd (authuser,pwd,argc,argv)) pw = pwuser (user);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
732 if (pw && pw_login (pw,authuser,pw->pw_name,NIL,argc,argv)) return T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
733 syslog (level|LOG_AUTH,"Login %s user=%.64s auth=%.64s host=%.80s",err,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
734 user,(authuser && *authuser) ? authuser : user,tcp_clienthost ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
735 sleep (3); /* slow down possible cracker */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
736 return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
737 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
738
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
739 /* Authenticated server log in
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
740 * Accepts: user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
741 * authenticating user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
742 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
743 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
744 * Returns: T if password validated, NIL otherwise
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
745 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
746
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
747 long authserver_login (char *user,char *authuser,int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
748 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
749 return pw_login (pwuser (user),authuser,user,NIL,argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
750 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
751
4
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
752 void permitsmtp() /* to update tcp permission */
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
753 {
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
754 #ifdef POPBEFORESMTP
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
755 #include <sys/types.h>
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
756 #include <sys/wait.h>
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
757 #ifndef POP3RECORDER
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
758 # define POP3RECORDER "/usr/local/etc/pop3-record"
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
759 #endif
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
760 int child;
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
761 int wstat;
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
762 char *permsmtp = POP3RECORDER;
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
763
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
764 switch(child = fork())
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
765 {
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
766 case -1:
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
767 syslog (LOG_INFO,"Cannot exec %s", permsmtp);
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
768 _exit(111);
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
769 break;
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
770 case 0:
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
771 execl(permsmtp, permsmtp, 0);
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
772 syslog (LOG_INFO,"Cannot exec %s", permsmtp);
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
773 _exit(111); break;
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
774 }
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
775 waitpid(child, &wstat, 0);
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
776 #endif
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
777 }
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
778
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
779
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
780
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
781 /* Log in as anonymous daemon
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
782 * Accepts: argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
783 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
784 * Returns: T if successful, NIL if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
785 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
786
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
787 long anonymous_login (int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
788 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
789 /* log in Mr. A. N. Onymous */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
790 return pw_login (getpwnam (ANONYMOUSUSER),NIL,NIL,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
791 (char *) mail_parameters (NIL,GET_ANONYMOUSHOME,NIL),
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
792 argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
793 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
794
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
795 /* Finish log in and environment initialization
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
796 * Accepts: passwd struct for loginpw()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
797 * optional authentication user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
798 * user name (NIL for anonymous)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
799 * home directory (NIL to use directory from passwd struct)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
800 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
801 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
802 * Returns: T if successful, NIL if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
803 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
804
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
805 long pw_login (struct passwd *pw,char *auser,char *user,char *home,int argc,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
806 char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
807 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
808 struct group *gr;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
809 char **t;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
810 long ret = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
811 if (pw && pw->pw_uid) { /* must have passwd struct for non-UID 0 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
812 /* make safe copies of user and home */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
813 if (user) user = cpystr (pw->pw_name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
814 home = cpystr (home ? home : pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
815 /* authorization ID .NE. authentication ID? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
816 if (user && auser && *auser && compare_cstring (auser,user)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
817 /* scan list of mail administrators */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
818 if ((gr = getgrnam (ADMINGROUP)) && (t = gr->gr_mem)) while (*t && !ret)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
819 if (!compare_cstring (auser,*t++))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
820 ret = pw_login (pw,NIL,user,home,argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
821 syslog (LOG_NOTICE|LOG_AUTH,"%s %.80s override of user=%.80s host=%.80s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
822 ret ? "Admin" : "Failed",auser,user,tcp_clienthost ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
823 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
824 else if (closedBox) { /* paranoid site, lock out other directories */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
825 if (chdir (home) || chroot (home))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
826 syslog (LOG_NOTICE|LOG_AUTH,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
827 "Login %s failed: unable to set chroot=%.80s host=%.80s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
828 pw->pw_name,home,tcp_clienthost ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
829 else if (loginpw (pw,argc,argv)) ret = env_init (user,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
830 else fatal ("Login failed after chroot");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
831 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
832 /* normal login */
4
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
833 #ifdef QMAIL
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
834 else if (((pw->pw_uid == geteuid ()) || (permitsmtp(), loginpw (pw,argc,argv
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
835 ))) &&
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
836 (ret = env_init (user,home))) chdir (myhomedir ());
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
837 #else
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
838 else if (((pw->pw_uid == geteuid ()) || loginpw (pw,argc,argv)) &&
4
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
839 (ret = env_init (user,home))) chdir (myhomedir ());
d741b3ecc917 imapext-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 3
diff changeset
840 #endif
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
841 fs_give ((void **) &home); /* clean up */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
842 if (user) fs_give ((void **) &user);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
843 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
844 endpwent (); /* in case shadow passwords in pw data */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
845 return ret; /* return status */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
846 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
847
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
848 /* Initialize environment
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
849 * Accepts: user name (NIL for anonymous)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
850 * home directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
851 * Returns: T, always
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
852 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
853
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
854 long env_init (char *user,char *home)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
855 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
856 extern MAILSTREAM CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
857 extern MAILSTREAM EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
858 struct passwd *pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
859 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
860 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
861 /* don't init if blocked */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
862 if (block_env_init) return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
863 if (myUserName) fatal ("env_init called twice!");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
864 /* initially nothing in namespace list */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
865 nslist[0] = nslist[1] = nslist[2] = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
866 /* myUserName must be set before dorc() call */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
867 myUserName = cpystr (user ? user : ANONYMOUSUSER);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
868 /* force default prototypes to be set */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
869 if (!createProto) createProto = &CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
870 if (!appendProto) appendProto = &EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
871 dorc (NIL,NIL); /* do systemwide configuration */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
872 if (!home) { /* closed box server */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
873 /* standard user can only reference home */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
874 if (user) nslist[0] = &nshome;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
875 else { /* anonymous user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
876 nslist[0] = &nsblackother; /* set root */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
877 anonymous = T; /* flag as anonymous */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
878 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
879 myHomeDir = cpystr (""); /* home directory is root */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
880 sysInbox = cpystr ("INBOX");/* make system INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
881 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
882 else { /* open or black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
883 closedBox = NIL; /* definitely not a closed box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
884 if (user) { /* remember user name and home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
885 if (blackBoxDir) { /* build black box directory name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
886 sprintf (tmp,"%s/%s",blackBoxDir,myUserName);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
887 /* must exist */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
888 if (!((!stat (home = tmp,&sbuf) && (sbuf.st_mode & S_IFDIR)) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
889 (blackBoxDefaultHome &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
890 !stat (home = blackBoxDefaultHome,&sbuf) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
891 (sbuf.st_mode & S_IFDIR)))) fatal ("no home");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
892 sysInbox = (char *) fs_get (strlen (home) + 7);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
893 /* set system INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
894 sprintf (sysInbox,"%s/INBOX",home);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
895 blackBox = T; /* mark that it's a black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
896 /* mbox meaningless if black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
897 mail_parameters (NIL,DISABLE_DRIVER,(void *) "mbox");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
898 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
899 nslist[0] = &nshome; /* home namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
900 /* limited advertise namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
901 if (limitedadvertise) nslist[2] = &nslimited;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
902 else if (blackBox) { /* black box namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
903 nslist[1] = &nsblackother;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
904 nslist[2] = &nsshared;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
905 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
906 else { /* open box namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
907 nslist[1] = &nsunixother;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
908 nslist[2] = advertisetheworld ? &nsworld : &nsshared;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
909 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
910 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
911 else {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
912 nslist[2] = &nsftp; /* anonymous user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
913 sprintf (tmp,"%s/INBOX",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
914 home = (char *) mail_parameters (NIL,GET_ANONYMOUSHOME,NIL));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
915 sysInbox = cpystr (tmp); /* make system INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
916 anonymous = T; /* flag as anonymous */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
917 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
918 myHomeDir = cpystr (home); /* set home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
919 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
920
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
921 if (allowuserconfig) { /* allow user config files */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
922 dorc (strcat (strcpy (tmp,myHomeDir),"/.mminit"),T);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
923 dorc (strcat (strcpy (tmp,myHomeDir),"/.imaprc"),NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
924 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
925 if (!closedBox && !noautomaticsharedns) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
926 /* #ftp namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
927 if (!ftpHome && (pw = getpwnam ("ftp"))) ftpHome = cpystr (pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
928 /* #public namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
929 if (!publicHome && (pw = getpwnam ("imappublic")))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
930 publicHome = cpystr (pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
931 /* #shared namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
932 if (!anonymous && !sharedHome && (pw = getpwnam ("imapshared")))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
933 sharedHome = cpystr (pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
934 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
935 if (!myLocalHost) mylocalhost ();
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
936 if (!myNewsrc) myNewsrc = cpystr(strcat (strcpy (tmp,myHomeDir),"/.newsrc"));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
937 if (!newsActive) newsActive = cpystr (ACTIVEFILE);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
938 if (!newsSpool) newsSpool = cpystr (NEWSSPOOL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
939 /* re-do open action to get flags */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
940 (*createProto->dtb->open) (NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
941 endpwent (); /* close pw database */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
942 return T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
943 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
944
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
945 /* Return my user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
946 * Accepts: pointer to optional flags
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
947 * Returns: my user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
948 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
949
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
950 char *myusername_full (unsigned long *flags)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
951 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
952 struct passwd *pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
953 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
954 char *s;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
955 unsigned long euid;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
956 char *ret = UNLOGGEDUSER;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
957 /* no user name yet and not root? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
958 if (!myUserName && (euid = geteuid ())) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
959 /* yes, look up getlogin() user name or EUID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
960 if (((s = (char *) getlogin ()) && *s && (strlen (s) < NETMAXUSER) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
961 (pw = getpwnam (s)) && (pw->pw_uid == euid)) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
962 (pw = getpwuid (euid))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
963 if (block_env_init) { /* don't env_init if blocked */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
964 if (flags) *flags = MU_LOGGEDIN;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
965 return pw->pw_name;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
966 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
967 env_init (pw->pw_name,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
968 ((s = getenv ("HOME")) && *s && (strlen (s) < NETMAXMBX) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
969 !stat (s,&sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFDIR)) ?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
970 s : pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
971 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
972 else fatal ("Unable to look up user name");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
973 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
974 if (myUserName) { /* logged in? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
975 if (flags) *flags = anonymous ? MU_ANONYMOUS : MU_LOGGEDIN;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
976 ret = myUserName; /* return user name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
977 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
978 else if (flags) *flags = MU_NOTLOGGEDIN;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
979 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
980 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
981
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
982
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
983 /* Return my local host name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
984 * Returns: my local host name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
985 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
986
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
987 char *mylocalhost ()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
988 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
989 if (!myLocalHost) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
990 char *s,tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
991 char *t = "unknown";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
992 tmp[0] = tmp[MAILTMPLEN-1] = '\0';
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
993 if (!gethostname (tmp,MAILTMPLEN-1) && tmp[0]) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
994 /* sanity check of name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
995 for (s = tmp; (*s > 0x20) && (*s < 0x7f); ++s);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
996 if (!*s) t = tcp_canonical (tmp);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
997 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
998 myLocalHost = cpystr (t);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
999 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1000 return myLocalHost;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1001 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1002
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1003 /* Return my home directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1004 * Returns: my home directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1005 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1006
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1007 char *myhomedir ()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1008 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1009 if (!myHomeDir) myusername ();/* initialize if first time */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1010 return myHomeDir ? myHomeDir : "";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1011 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1012
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1013
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1014 /* Return my home mailbox name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1015 * Returns: my home directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1016 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1017
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1018 static char *mymailboxdir ()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1019 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1020 char *home = myhomedir ();
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1021 /* initialize if first time */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1022 if (!myMailboxDir && myHomeDir) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1023 if (mailsubdir) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1024 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1025 sprintf (tmp,"%s/%s",home,mailsubdir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1026 myMailboxDir = cpystr (tmp);/* use pre-defined subdirectory of home */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1027 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1028 else myMailboxDir = cpystr (home);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1029 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1030 return myMailboxDir ? myMailboxDir : "";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1031 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1032
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1033
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1034 /* Return system standard INBOX
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1035 * Accepts: buffer string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1036 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1037
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1038 char *sysinbox ()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1039 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1040 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1041 if (!sysInbox) { /* initialize if first time */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1042 sprintf (tmp,"%s/%s",MAILSPOOL,myusername ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1043 sysInbox = cpystr (tmp); /* system inbox is from mail spool */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1044 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1045 return sysInbox;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1046 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1047
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1048 /* Return mailbox directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1049 * Accepts: destination buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1050 * directory prefix
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1051 * name in directory
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1052 * Returns: file name or NIL if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1053 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1054
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1055 char *mailboxdir (char *dst,char *dir,char *name)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1056 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1057 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1058 if (dir || name) { /* if either argument provided */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1059 if (dir) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1060 if (strlen (dir) > NETMAXMBX) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1061 strcpy (tmp,dir); /* write directory prefix */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1062 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1063 else tmp[0] = '\0'; /* otherwise null string */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1064 if (name) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1065 if (strlen (name) > NETMAXMBX) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1066 strcat (tmp,name); /* write name in directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1067 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1068 /* validate name, return its name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1069 if (!mailboxfile (dst,tmp)) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1070 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1071 /* no arguments, wants mailbox directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1072 else strcpy (dst,mymailboxdir ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1073 return dst; /* return the name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1074 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1075
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1076 /* Return mailbox file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1077 * Accepts: destination buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1078 * mailbox name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1079 * Returns: file name or empty string for driver-selected INBOX or NIL if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1080 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1081
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1082 char *mailboxfile (char *dst,char *name)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1083 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1084 struct passwd *pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1085 char *s;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1086 if (!name || !*name || (*name == '{') || (strlen (name) > NETMAXMBX) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1087 ((anonymous || blackBox || restrictBox || (*name == '#')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1088 (strstr (name,"..") || strstr (name,"//") || strstr (name,"/~"))))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1089 dst = NIL; /* invalid name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1090 else switch (*name) { /* determine mailbox type based upon name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1091 case '#': /* namespace name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1092 /* #ftp/ namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1093 if (((name[1] == 'f') || (name[1] == 'F')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1094 ((name[2] == 't') || (name[2] == 'T')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1095 ((name[3] == 'p') || (name[3] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1096 (name[4] == '/') && ftpHome) sprintf (dst,"%s/%s",ftpHome,name+5);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1097 /* #public/ and #shared/ namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1098 else if ((((name[1] == 'p') || (name[1] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1099 ((name[2] == 'u') || (name[2] == 'U')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1100 ((name[3] == 'b') || (name[3] == 'B')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1101 ((name[4] == 'l') || (name[4] == 'L')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1102 ((name[5] == 'i') || (name[5] == 'I')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1103 ((name[6] == 'c') || (name[6] == 'C')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1104 (name[7] == '/') && (s = publicHome)) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1105 (!anonymous && ((name[1] == 's') || (name[1] == 'S')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1106 ((name[2] == 'h') || (name[2] == 'H')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1107 ((name[3] == 'a') || (name[3] == 'A')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1108 ((name[4] == 'r') || (name[4] == 'R')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1109 ((name[5] == 'e') || (name[5] == 'E')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1110 ((name[6] == 'd') || (name[6] == 'D')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1111 (name[7] == '/') && (s = sharedHome)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1112 sprintf (dst,"%s/%s",s,compare_cstring (name+8,"INBOX") ?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1113 name+8 : "INBOX");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1114 else dst = NIL; /* unknown namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1115 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1116
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1117 case '/': /* root access */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1118 if (anonymous) dst = NIL; /* anonymous forbidden to do this */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1119 else if (blackBox) { /* other user access if blackbox */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1120 if (restrictBox & RESTRICTOTHERUSER) dst = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1121 /* see if other user INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1122 else if ((s = strchr (name+1,'/')) && !compare_cstring (s+1,"INBOX")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1123 *s = '\0'; /* temporarily tie off string */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1124 sprintf (dst,"%s/%s/INBOX",blackBoxDir,name+1);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1125 *s = '/'; /* in case caller cares */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1126 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1127 else sprintf (dst,"%s/%s",blackBoxDir,name+1);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1128 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1129 else if ((restrictBox & RESTRICTROOT) && strcmp (name,sysinbox ()))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1130 dst = NIL; /* restricted and not access to sysinbox */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1131 else strcpy (dst,name); /* unrestricted, copy root name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1132 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1133 case '~': /* other user access */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1134 /* bad syntax or anonymous can't win */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1135 if (!*++name || anonymous) dst = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1136 /* ~/ equivalent to ordinary name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1137 else if (*name == '/') sprintf (dst,"%s/%s",mymailboxdir (),name+1);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1138 /* other user forbidden if closed/restricted */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1139 else if (closedBox || (restrictBox & RESTRICTOTHERUSER)) dst = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1140 else if (blackBox) { /* black box form of other user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1141 /* see if other user INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1142 if ((s = strchr (name,'/')) && compare_cstring (s+1,"INBOX")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1143 *s = '\0'; /* temporarily tie off string */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1144 sprintf (dst,"%s/%s/INBOX",blackBoxDir,name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1145 *s = '/'; /* in case caller cares */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1146 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1147 else sprintf (dst,"%s/%s",blackBoxDir,name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1148 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1149 else { /* clear box other user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1150 /* copy user name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1151 for (s = dst; *name && (*name != '/'); *s++ = *name++);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1152 *s++ = '\0'; /* tie off user name, look up in passwd file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1153 if ((pw = getpwnam (dst)) && pw->pw_dir) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1154 if (*name) name++; /* skip past the slash */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1155 /* canonicalize case of INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1156 if (!compare_cstring (name,"INBOX")) name = "INBOX";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1157 /* remove trailing / from directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1158 if ((s = strrchr (pw->pw_dir,'/')) && !s[1]) *s = '\0';
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1159 /* don't allow ~root/ if restricted root */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1160 if ((restrictBox & RESTRICTROOT) && !*pw->pw_dir) dst = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1161 /* build final name w/ subdir if needed */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1162 else if (mailsubdir) sprintf (dst,"%s/%s/%s",pw->pw_dir,mailsubdir,name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1163 else sprintf (dst,"%s/%s",pw->pw_dir,name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1164 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1165 else dst = NIL; /* no such user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1166 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1167 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1168
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1169 case 'I': case 'i': /* possible INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1170 if (!compare_cstring (name+1,"NBOX")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1171 /* if restricted, use INBOX in mailbox dir */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1172 if (anonymous || blackBox || closedBox)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1173 sprintf (dst,"%s/INBOX",mymailboxdir ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1174 else *dst = '\0'; /* otherwise driver selects the name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1175 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1176 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1177 /* drop into to ordinary name case */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1178 default: /* ordinary name is easy */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1179 sprintf (dst,"%s/%s",mymailboxdir (),name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1180 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1181 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1182 return dst; /* return final name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1183 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1184
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1185 /* Dot-lock file locker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1186 * Accepts: file name to lock
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1187 * destination buffer for lock file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1188 * open file description on file name to lock
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1189 * Returns: T if success, NIL if failure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1190 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1191
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1192 long dotlock_lock (char *file,DOTLOCK *base,int fd)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1193 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1194 int i = locktimeout * 60;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1195 int j,mask,retry,pi[2],po[2];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1196 char *s,tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1197 struct stat sb;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1198 /* flush absurd file name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1199 if (strlen (file) > 512) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1200 /* build lock filename */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1201 sprintf (base->lock,"%s.lock",file);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1202 /* assume no pipe */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1203 base->pipei = base->pipeo = -1;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1204 do { /* make sure not symlink */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1205 if (!(j = chk_notsymlink (base->lock,&sb))) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1206 /* time out if file older than 5 minutes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1207 if ((j > 0) && ((time (0)) >= (sb.st_ctime + locktimeout * 60))) i = 0;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1208 /* try to create the lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1209 switch (retry = crexcl (base->lock)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1210 case -1: /* OK to retry */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1211 if (!(i%15)) { /* time to notify? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1212 sprintf (tmp,"Mailbox %.80s is locked, will override in %d seconds...",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1213 file,i);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1214 MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1215 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1216 sleep (1); /* wait 1 second before next try */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1217 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1218 case NIL: /* failure, can't retry */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1219 i = 0;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1220 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1221 case T: /* success, make sure others can break lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1222 chmod (base->lock,(int) dotlock_mode);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1223 return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1224 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1225 } while (i--); /* until out of retries */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1226 if (retry < 0) { /* still returning retry after locktimeout? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1227 if (!(j = chk_notsymlink (base->lock,&sb))) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1228 if ((j > 0) && ((time (0)) < (sb.st_ctime + locktimeout * 60))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1229 sprintf (tmp,"Mailbox vulnerable - seizing %ld second old lock",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1230 (long) (time (0) - sb.st_ctime));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1231 MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1232 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1233 mask = umask (0); /* want our lock protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1234 unlink (base->lock); /* try to remove the old file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1235 /* seize the lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1236 if ((i = open (base->lock,O_WRONLY|O_CREAT,(int) dotlock_mode)) >= 0) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1237 close (i); /* don't need descriptor any more */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1238 sprintf (tmp,"Mailbox %.80s lock overridden",file);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1239 MM_LOG (tmp,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1240 chmod (base->lock,(int) dotlock_mode);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1241 umask (mask); /* restore old umask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1242 return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1243 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1244 umask (mask); /* restore old umask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1245 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1246
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1247 if (fd >= 0) switch (errno) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1248 case EACCES: /* protection failure? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1249 MM_CRITICAL (NIL); /* go critical */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1250 if (closedBox || !lockpgm); /* can't do on closed box or disabled */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1251 else if ((*lockpgm && stat (lockpgm,&sb)) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1252 (!*lockpgm && stat (lockpgm = LOCKPGM1,&sb) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1253 stat (lockpgm = LOCKPGM2,&sb) && stat (lockpgm = LOCKPGM3,&sb)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1254 lockpgm = NIL; /* disable if can't find lockpgm */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1255 else if (pipe (pi) >= 0) { /* make command pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1256 long cf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1257 char *argv[4],arg[20];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1258 /* if input pipes usable create output pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1259 if ((pi[0] < FD_SETSIZE) && (pi[1] < FD_SETSIZE) && (pipe (po) >= 0)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1260 /* make sure output pipes are usable */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1261 if ((po[0] >= FD_SETSIZE) || (po[1] >= FD_SETSIZE));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1262 /* all is good, make inferior process */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1263 else if (!(j = fork ())) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1264 if (!fork ()) { /* make grandchild so it's inherited by init */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1265 /* prepare argument vector */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1266 sprintf (arg,"%d",fd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1267 argv[0] = lockpgm; argv[1] = arg;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1268 argv[2] = file; argv[3] = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1269 /* set parent's I/O to my O/I */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1270 dup2 (pi[1],1); dup2 (pi[1],2); dup2 (po[0],0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1271 /* close all unnecessary descriptors */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1272 for (cf = max (20,max (max (pi[0],pi[1]),max(po[0],po[1])));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1273 cf >= 3; --cf) if (cf != fd) close (cf);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1274 /* be our own process group */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1275 setpgrp (0,getpid ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1276 /* now run it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1277 _exit (execv (argv[0],argv));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1278 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1279 _exit (1); /* child is done */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1280 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1281 else if (j > 0) { /* parent process */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1282 fd_set rfd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1283 struct timeval tmo;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1284 FD_ZERO (&rfd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1285 FD_SET (pi[0],&rfd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1286 tmo.tv_sec = locktimeout * 60;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1287 grim_pid_reap (j,NIL);/* reap child; grandchild now owned by init */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1288 /* read response from locking program */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1289 if (select (pi[0]+1,&rfd,0,0,&tmo) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1290 (read (pi[0],tmp,1) == 1) && (tmp[0] == '+')) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1291 /* success, record pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1292 base->pipei = pi[0]; base->pipeo = po[1];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1293 /* close child's side of the pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1294 close (pi[1]); close (po[0]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1295 MM_NOCRITICAL (NIL);/* no longer critical */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1296 return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1297 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1298 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1299 close (po[0]); close (po[1]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1300 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1301 close (pi[0]); close (pi[1]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1302 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1303
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1304 MM_NOCRITICAL (NIL); /* no longer critical */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1305 /* find directory/file delimiter */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1306 if (s = strrchr (base->lock,'/')) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1307 *s = '\0'; /* tie off at directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1308 sprintf(tmp, /* generate default message */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1309 "Mailbox vulnerable - directory %.80s must have 1777 protection",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1310 base->lock);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1311 /* definitely not 1777 if can't stat */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1312 mask = stat (base->lock,&sb) ? 0 : (sb.st_mode & 1777);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1313 *s = '/'; /* restore lock name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1314 if (mask != 1777) { /* default warning if not 1777 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1315 if (!disableLockWarning) MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1316 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1317 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1318 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1319 default:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1320 sprintf (tmp,"Mailbox vulnerable - error creating %.80s: %s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1321 base->lock,strerror (errno));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1322 if (!disableLockWarning) MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1323 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1324 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1325 base->lock[0] = '\0'; /* don't use lock files */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1326 return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1327 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1328
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1329 /* Dot-lock file unlocker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1330 * Accepts: lock file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1331 * Returns: T if success, NIL if failure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1332 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1333
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1334 long dotlock_unlock (DOTLOCK *base)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1335 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1336 long ret = LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1337 if (base && base->lock[0]) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1338 if (base->pipei >= 0) { /* if running through a pipe unlocker */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1339 ret = (write (base->pipeo,"+",1) == 1);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1340 /* nuke the pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1341 close (base->pipei); close (base->pipeo);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1342 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1343 else ret = !unlink (base->lock);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1344 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1345 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1346 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1347
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1348 /* Lock file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1349 * Accepts: scratch buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1350 * file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1351 * type of locking operation (LOCK_SH or LOCK_EX)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1352 * pointer to return PID of locker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1353 * Returns: file descriptor of lock or negative if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1354 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1355
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1356 int lockname (char *lock,char *fname,int op,long *pid)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1357 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1358 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1359 *pid = 0; /* no locker PID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1360 return stat (fname,&sbuf) ? -1 : lock_work (lock,&sbuf,op,pid);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1361 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1362
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1363
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1364 /* Lock file descriptor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1365 * Accepts: file descriptor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1366 * lock file name buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1367 * type of locking operation (LOCK_SH or LOCK_EX)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1368 * Returns: file descriptor of lock or negative if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1369 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1370
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1371 int lockfd (int fd,char *lock,int op)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1372 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1373 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1374 return fstat (fd,&sbuf) ? -1 : lock_work (lock,&sbuf,op,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1375 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1376
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1377 /* Lock file name worker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1378 * Accepts: lock file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1379 * pointer to stat() buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1380 * type of locking operation (LOCK_SH or LOCK_EX)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1381 * pointer to return PID of locker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1382 * Returns: file descriptor of lock or negative if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1383 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1384
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1385 int lock_work (char *lock,void *sb,int op,long *pid)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1386 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1387 struct stat lsb,fsb;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1388 struct stat *sbuf = (struct stat *) sb;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1389 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1390 long i;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1391 int fd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1392 int mask = umask (0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1393 if (pid) *pid = 0; /* initialize return PID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1394 /* make temporary lock file name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1395 sprintf (lock,"%s/.%lx.%lx",closedBox ? "" : tmpdir,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1396 (unsigned long) sbuf->st_dev,(unsigned long) sbuf->st_ino);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1397 while (T) { /* until get a good lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1398 do switch ((int) chk_notsymlink (lock,&lsb)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1399 case 1: /* exists just once */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1400 if (((fd = open (lock,O_RDWR,shlock_mode)) >= 0) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1401 (errno != ENOENT) || (chk_notsymlink (lock,&lsb) >= 0)) break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1402 case -1: /* name doesn't exist */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1403 fd = open (lock,O_RDWR|O_CREAT|O_EXCL,shlock_mode);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1404 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1405 default: /* multiple hard links */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1406 MM_LOG ("hard link to lock name",ERROR);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1407 syslog (LOG_CRIT,"SECURITY PROBLEM: hard link to lock name: %.80s",lock);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1408 case 0: /* symlink (already did syslog) */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1409 umask (mask); /* restore old mask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1410 return -1; /* fail: no lock file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1411 } while ((fd < 0) && (errno == EEXIST));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1412 if (fd < 0) { /* failed to get file descriptor */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1413 syslog (LOG_INFO,"Mailbox lock file %s open failure: %s",lock,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1414 strerror (errno));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1415 if (!closedBox) { /* more explicit snarl for bad configuration */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1416 if (stat (tmpdir,&lsb))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1417 syslog (LOG_CRIT,"SYSTEM ERROR: no %s: %s",tmpdir,strerror (errno));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1418 else if ((lsb.st_mode & 01777) != 01777) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1419 sprintf (tmp,"Can't lock for write: %.80s must have 1777 protection",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1420 tmpdir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1421 MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1422 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1423 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1424 umask (mask); /* restore old mask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1425 return -1; /* fail: can't open lock file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1426 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1427
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1428 /* non-blocking form */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1429 if (op & LOCK_NB) i = flock (fd,op);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1430 else { /* blocking form */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1431 (*mailblocknotify) (BLOCK_FILELOCK,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1432 i = flock (fd,op);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1433 (*mailblocknotify) (BLOCK_NONE,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1434 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1435 if (i) { /* failed, get other process' PID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1436 if (pid && !fstat (fd,&fsb) && (i = min (fsb.st_size,MAILTMPLEN-1)) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1437 (read (fd,tmp,i) == i) && !(tmp[i] = 0) && ((i = atol (tmp)) > 0))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1438 *pid = i;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1439 close (fd); /* failed, give up on lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1440 umask (mask); /* restore old mask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1441 return -1; /* fail: can't lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1442 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1443 /* make sure this lock is good for us */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1444 if (!lstat (lock,&lsb) && ((lsb.st_mode & S_IFMT) != S_IFLNK) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1445 !fstat (fd,&fsb) && (lsb.st_dev == fsb.st_dev) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1446 (lsb.st_ino == fsb.st_ino) && (fsb.st_nlink == 1)) break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1447 close (fd); /* lock not right, drop fd and try again */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1448 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1449 chmod (lock,shlock_mode); /* make sure mode OK (don't use fchmod()) */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1450 umask (mask); /* restore old mask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1451 return fd; /* success */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1452 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1453
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1454 /* Check to make sure not a symlink
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1455 * Accepts: file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1456 * stat buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1457 * Returns: -1 if doesn't exist, NIL if symlink, else number of hard links
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1458 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1459
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1460 long chk_notsymlink (char *name,void *sb)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1461 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1462 struct stat *sbuf = (struct stat *) sb;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1463 /* name exists? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1464 if (lstat (name,sbuf)) return -1;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1465 /* forbid symbolic link */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1466 if ((sbuf->st_mode & S_IFMT) == S_IFLNK) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1467 MM_LOG ("symbolic link on lock name",ERROR);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1468 syslog (LOG_CRIT,"SECURITY PROBLEM: symbolic link on lock name: %.80s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1469 name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1470 return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1471 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1472 return (long) sbuf->st_nlink; /* return number of hard links */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1473 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1474
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1475
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1476 /* Unlock file descriptor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1477 * Accepts: file descriptor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1478 * lock file name from lockfd()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1479 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1480
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1481 void unlockfd (int fd,char *lock)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1482 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1483 /* delete the file if no sharers */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1484 if (!flock (fd,LOCK_EX|LOCK_NB)) unlink (lock);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1485 flock (fd,LOCK_UN); /* unlock it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1486 close (fd); /* close it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1487 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1488
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1489 /* Set proper file protection for mailbox
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1490 * Accepts: mailbox name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1491 * actual file path name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1492 * Returns: T, always
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1493 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1494
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1495 long set_mbx_protections (char *mailbox,char *path)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1496 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1497 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1498 int mode = (int) mbx_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1499 if (*mailbox == '#') { /* possible namespace? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1500 if (((mailbox[1] == 'f') || (mailbox[1] == 'F')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1501 ((mailbox[2] == 't') || (mailbox[2] == 'T')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1502 ((mailbox[3] == 'p') || (mailbox[3] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1503 (mailbox[4] == '/')) mode = (int) ftp_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1504 else if (((mailbox[1] == 'p') || (mailbox[1] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1505 ((mailbox[2] == 'u') || (mailbox[2] == 'U')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1506 ((mailbox[3] == 'b') || (mailbox[3] == 'B')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1507 ((mailbox[4] == 'l') || (mailbox[4] == 'L')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1508 ((mailbox[5] == 'i') || (mailbox[5] == 'I')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1509 ((mailbox[6] == 'c') || (mailbox[6] == 'C')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1510 (mailbox[7] == '/')) mode = (int) public_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1511 else if (((mailbox[1] == 's') || (mailbox[1] == 'S')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1512 ((mailbox[2] == 'h') || (mailbox[2] == 'H')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1513 ((mailbox[3] == 'a') || (mailbox[3] == 'A')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1514 ((mailbox[4] == 'r') || (mailbox[4] == 'R')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1515 ((mailbox[5] == 'e') || (mailbox[5] == 'E')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1516 ((mailbox[6] == 'd') || (mailbox[6] == 'D')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1517 (mailbox[7] == '/')) mode = (int) shared_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1518 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1519 /* if a directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1520 if (!stat (path,&sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFDIR)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1521 /* set owner search if allow read or write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1522 if (mode & 0600) mode |= 0100;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1523 if (mode & 060) mode |= 010;/* set group search if allow read or write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1524 if (mode & 06) mode |= 01; /* set world search if allow read or write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1525 /* preserve directory SGID bit */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1526 if (sbuf.st_mode & S_ISGID) mode |= S_ISGID;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1527 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1528 chmod (path,mode); /* set the new protection, ignore failure */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1529 return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1530 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1531
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1532 /* Get proper directory protection
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1533 * Accepts: mailbox name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1534 * Returns: directory mode, always
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1535 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1536
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1537 long get_dir_protection (char *mailbox)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1538 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1539 if (*mailbox == '#') { /* possible namespace? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1540 if (((mailbox[1] == 'f') || (mailbox[1] == 'F')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1541 ((mailbox[2] == 't') || (mailbox[2] == 'T')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1542 ((mailbox[3] == 'p') || (mailbox[3] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1543 (mailbox[4] == '/')) return ftp_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1544 else if (((mailbox[1] == 'p') || (mailbox[1] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1545 ((mailbox[2] == 'u') || (mailbox[2] == 'U')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1546 ((mailbox[3] == 'b') || (mailbox[3] == 'B')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1547 ((mailbox[4] == 'l') || (mailbox[4] == 'L')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1548 ((mailbox[5] == 'i') || (mailbox[5] == 'I')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1549 ((mailbox[6] == 'c') || (mailbox[6] == 'C')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1550 (mailbox[7] == '/')) return public_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1551 else if (((mailbox[1] == 's') || (mailbox[1] == 'S')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1552 ((mailbox[2] == 'h') || (mailbox[2] == 'H')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1553 ((mailbox[3] == 'a') || (mailbox[3] == 'A')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1554 ((mailbox[4] == 'r') || (mailbox[4] == 'R')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1555 ((mailbox[5] == 'e') || (mailbox[5] == 'E')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1556 ((mailbox[6] == 'd') || (mailbox[6] == 'D')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1557 (mailbox[7] == '/')) return shared_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1558 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1559 return dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1560 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1561
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1562 /* Determine default prototype stream to user
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1563 * Accepts: type (NIL for create, T for append)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1564 * Returns: default prototype stream
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1565 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1566
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1567 MAILSTREAM *default_proto (long type)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1568 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1569 myusername (); /* make sure initialized */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1570 /* return default driver's prototype */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1571 return type ? appendProto : createProto;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1572 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1573
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1574
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1575 /* Set up user flags for stream
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1576 * Accepts: MAIL stream
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1577 * Returns: MAIL stream with user flags set up
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1578 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1579
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1580 MAILSTREAM *user_flags (MAILSTREAM *stream)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1581 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1582 int i;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1583 myusername (); /* make sure initialized */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1584 for (i = 0; i < NUSERFLAGS && userFlags[i]; ++i)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1585 if (!stream->user_flags[i]) stream->user_flags[i] = cpystr (userFlags[i]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1586 return stream;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1587 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1588
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1589
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1590 /* Return nth user flag
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1591 * Accepts: user flag number
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1592 * Returns: flag
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1593 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1594
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1595 char *default_user_flag (unsigned long i)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1596 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1597 myusername (); /* make sure initialized */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1598 return userFlags[i];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1599 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1600
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1601 /* Process rc file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1602 * Accepts: file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1603 * .mminit flag
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1604 * Don't use this feature.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1605 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1606
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1607 void dorc (char *file,long flag)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1608 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1609 int i;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1610 char *s,*t,*k,*r,tmp[MAILTMPLEN],tmpx[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1611 extern MAILSTREAM CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1612 extern MAILSTREAM EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1613 DRIVER *d;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1614 FILE *f;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1615 if ((f = fopen (file ? file : SYSCONFIG,"r")) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1616 (s = fgets (tmp,MAILTMPLEN,f)) && (t = strchr (s,'\n'))) do {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1617 *t++ = '\0'; /* tie off line, find second space */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1618 if ((k = strchr (s,' ')) && (k = strchr (++k,' '))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1619 *k++ = '\0'; /* tie off two words */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1620 if (!compare_cstring (s,"set keywords") && !userFlags[0]) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1621 /* yes, get first keyword */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1622 k = strtok_r (k,", ",&r);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1623 /* copy keyword list */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1624 for (i = 0; k && i < NUSERFLAGS; ++i) if (strlen (k) <= MAXUSERFLAG) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1625 if (userFlags[i]) fs_give ((void **) &userFlags[i]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1626 userFlags[i] = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1627 k = strtok_r (NIL,", ",&r);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1628 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1629 if (flag) break; /* found "set keywords" in .mminit */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1630 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1631
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1632 else if (!flag) { /* none of these valid in .mminit */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1633 if (myUserName) { /* only valid if logged in */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1634 if (!compare_cstring (s,"set new-mailbox-format") ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1635 !compare_cstring (s,"set new-folder-format")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1636 if (!compare_cstring (k,"same-as-inbox")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1637 if (d = mail_valid (NIL,"INBOX",NIL)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1638 if (!compare_cstring (d->name,"mbox"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1639 d = (DRIVER *) mail_parameters (NIL,GET_DRIVER,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1640 (void *) "unix");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1641 else if (!compare_cstring (d->name,"dummy")) d = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1642 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1643 createProto = d ? ((*d->open) (NIL)) : &CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1644 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1645 else if (!compare_cstring (k,"system-standard"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1646 createProto = &CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1647 else { /* canonicalize mbox to unix */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1648 if (!compare_cstring (k,"mbox")) k = "unix";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1649 /* see if a driver name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1650 if (d = (DRIVER *) mail_parameters (NIL,GET_DRIVER,(void *) k))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1651 createProto = (*d->open) (NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1652 else { /* duh... */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1653 sprintf (tmpx,"Unknown new mailbox format in %s: %s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1654 file ? file : SYSCONFIG,k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1655 MM_LOG (tmpx,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1656 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1657 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1658 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1659 if (!compare_cstring (s,"set empty-mailbox-format") ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1660 !compare_cstring (s,"set empty-folder-format")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1661 if (!compare_cstring (k,"invalid")) appendProto = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1662 else if (!compare_cstring (k,"same-as-inbox"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1663 appendProto = ((d = mail_valid (NIL,"INBOX",NIL)) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1664 compare_cstring (d->name,"dummy")) ?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1665 ((*d->open) (NIL)) : &EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1666 else if (!compare_cstring (k,"system-standard"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1667 appendProto = &EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1668 else { /* see if a driver name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1669 for (d = (DRIVER *) mail_parameters (NIL,GET_DRIVERS,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1670 d && compare_cstring (d->name,k); d = d->next);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1671 if (d) appendProto = (*d->open) (NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1672 else { /* duh... */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1673 sprintf (tmpx,"Unknown empty mailbox format in %s: %s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1674 file ? file : SYSCONFIG,k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1675 MM_LOG (tmpx,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1676 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1677 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1678 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1679 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1680
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1681 if (!compare_cstring (s,"set local-host")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1682 fs_give ((void **) &myLocalHost);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1683 myLocalHost = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1684 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1685 else if (!compare_cstring (s,"set news-active-file")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1686 fs_give ((void **) &newsActive);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1687 newsActive = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1688 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1689 else if (!compare_cstring (s,"set news-spool-directory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1690 fs_give ((void **) &newsSpool);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1691 newsSpool = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1692 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1693 else if (!compare_cstring (s,"set mh-path"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1694 mail_parameters (NIL,SET_MHPATH,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1695 else if (!compare_cstring (s,"set mh-allow-inbox"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1696 mail_parameters (NIL,SET_MHALLOWINBOX,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1697 else if (!compare_cstring (s,"set news-state-file")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1698 fs_give ((void **) &myNewsrc);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1699 myNewsrc = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1700 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1701 else if (!compare_cstring (s,"set ftp-export-directory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1702 fs_give ((void **) &ftpHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1703 ftpHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1704 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1705 else if (!compare_cstring (s,"set public-home-directory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1706 fs_give ((void **) &publicHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1707 publicHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1708 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1709 else if (!compare_cstring (s,"set shared-home-directory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1710 fs_give ((void **) &sharedHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1711 sharedHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1712 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1713 else if (!compare_cstring (s,"set system-inbox")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1714 fs_give ((void **) &sysInbox);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1715 sysInbox = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1716 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1717 else if (!compare_cstring (s,"set mail-subdirectory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1718 fs_give ((void **) &mailsubdir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1719 mailsubdir = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1720 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1721 else if (!compare_cstring (s,"set from-widget"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1722 mail_parameters (NIL,SET_FROMWIDGET,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1723 compare_cstring (k,"header-only") ?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1724 VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1725
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1726 else if (!compare_cstring (s,"set rsh-command"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1727 mail_parameters (NIL,SET_RSHCOMMAND,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1728 else if (!compare_cstring (s,"set rsh-path"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1729 mail_parameters (NIL,SET_RSHPATH,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1730 else if (!compare_cstring (s,"set ssh-command"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1731 mail_parameters (NIL,SET_SSHCOMMAND,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1732 else if (!compare_cstring (s,"set ssh-path"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1733 mail_parameters (NIL,SET_SSHPATH,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1734 else if (!compare_cstring (s,"set tcp-open-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1735 mail_parameters (NIL,SET_OPENTIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1736 else if (!compare_cstring (s,"set tcp-read-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1737 mail_parameters (NIL,SET_READTIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1738 else if (!compare_cstring (s,"set tcp-write-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1739 mail_parameters (NIL,SET_WRITETIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1740 else if (!compare_cstring (s,"set rsh-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1741 mail_parameters (NIL,SET_RSHTIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1742 else if (!compare_cstring (s,"set ssh-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1743 mail_parameters (NIL,SET_SSHTIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1744 else if (!compare_cstring (s,"set maximum-login-trials"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1745 mail_parameters (NIL,SET_MAXLOGINTRIALS,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1746 else if (!compare_cstring (s,"set lookahead"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1747 mail_parameters (NIL,SET_LOOKAHEAD,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1748 else if (!compare_cstring (s,"set prefetch"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1749 mail_parameters (NIL,SET_PREFETCH,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1750 else if (!compare_cstring (s,"set close-on-error"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1751 mail_parameters (NIL,SET_CLOSEONERROR,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1752 else if (!compare_cstring (s,"set imap-port"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1753 mail_parameters (NIL,SET_IMAPPORT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1754 else if (!compare_cstring (s,"set pop3-port"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1755 mail_parameters (NIL,SET_POP3PORT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1756 else if (!compare_cstring (s,"set uid-lookahead"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1757 mail_parameters (NIL,SET_UIDLOOKAHEAD,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1758 else if (!compare_cstring (s,"set try-ssl-first"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1759 mail_parameters (NIL,SET_TRYSSLFIRST,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1760
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1761 else if (!compare_cstring (s,"set mailbox-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1762 mbx_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1763 else if (!compare_cstring (s,"set directory-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1764 dir_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1765 else if (!compare_cstring (s,"set lock-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1766 dotlock_mode = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1767 else if (!compare_cstring (s,"set ftp-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1768 ftp_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1769 else if (!compare_cstring (s,"set public-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1770 public_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1771 else if (!compare_cstring (s,"set shared-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1772 shared_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1773 else if (!compare_cstring (s,"set ftp-directory-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1774 ftp_dir_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1775 else if (!compare_cstring (s,"set public-directory-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1776 public_dir_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1777 else if (!compare_cstring (s,"set shared-directory-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1778 shared_dir_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1779 else if (!compare_cstring (s,"set dot-lock-file-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1780 locktimeout = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1781 else if (!compare_cstring (s,"set disable-fcntl-locking"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1782 fcntlhangbug = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1783 else if (!compare_cstring (s,"set disable-lock-warning"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1784 disableLockWarning = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1785 else if (!compare_cstring (s,"set disable-unix-UIDs-and-keywords"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1786 has_no_life = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1787 else if (!compare_cstring (s,"set hide-dot-files"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1788 hideDotFiles = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1789 else if (!compare_cstring (s,"set list-maximum-level"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1790 list_max_level = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1791 else if (!compare_cstring (s,"set trust-dns"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1792 mail_parameters (NIL,SET_TRUSTDNS,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1793 else if (!compare_cstring (s,"set sasl-uses-ptr-name"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1794 mail_parameters (NIL,SET_SASLUSESPTRNAME,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1795 else if (!compare_cstring (s,"set network-filesystem-stat-bug"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1796 netfsstatbug = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1797 else if (!compare_cstring (s,"set nntp-range"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1798 mail_parameters (NIL,SET_NNTPRANGE,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1799
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1800 else if (!file) { /* only allowed in system init */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1801 if (!compare_cstring (s,"set black-box-directory") &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1802 !blackBoxDir) blackBoxDir = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1803 else if (!compare_cstring(s,"set black-box-default-home-directory")&&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1804 blackBoxDir && !blackBoxDefaultHome)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1805 blackBoxDefaultHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1806 else if (!compare_cstring (s,"set anonymous-home-directory") &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1807 !anonymousHome) anonymousHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1808 /* It's tempting to allow setting the CA path
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1809 * in a user init. However, that opens up a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1810 * vector of attack big enough to drive a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1811 * truck through... Resist the temptation.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1812 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1813 else if (!compare_cstring (s,"set CA-certificate-path"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1814 sslCApath = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1815 else if (!compare_cstring (s,"set disable-plaintext"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1816 disablePlaintext = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1817 else if (!compare_cstring (s,"set allowed-login-attempts"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1818 logtry = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1819 else if (!compare_cstring (s,"set chroot-server"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1820 closedBox = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1821 else if (!compare_cstring (s,"set restrict-mailbox-access"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1822 for (k = strtok_r (k,", ",&r); k; k = strtok_r (NIL,", ",&r)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1823 if (!compare_cstring (k,"root")) restrictBox |= RESTRICTROOT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1824 else if (!compare_cstring (k,"otherusers"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1825 restrictBox |= RESTRICTOTHERUSER;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1826 else if (!compare_cstring (k,"all")) restrictBox = -1;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1827 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1828 else if (!compare_cstring (s,"set advertise-the-world"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1829 advertisetheworld = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1830 else if (!compare_cstring (s,"set limited-advertise"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1831 limitedadvertise = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1832 else if (!compare_cstring
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1833 (s,"set disable-automatic-shared-namespaces"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1834 noautomaticsharedns = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1835 else if (!compare_cstring (s,"set allow-user-config"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1836 allowuserconfig = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1837 else if (!compare_cstring (s,"set allow-reverse-dns"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1838 mail_parameters (NIL,SET_ALLOWREVERSEDNS,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1839 else if (!compare_cstring (s,"set k5-cp-uses-service-name"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1840 kerb_cp_svr_name = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1841 /* must appear in file after any
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1842 * "set disable-plaintext" command! */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1843 else if (!compare_cstring (s,"set plaintext-allowed-clients")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1844 for (k = strtok_r (k,", ",&r); k && !tcp_isclienthost (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1845 k = strtok_r (NIL,", ",&r));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1846 if (k) disablePlaintext = 0;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1847 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1848 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1849 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1850 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1851 } while ((s = fgets (tmp,MAILTMPLEN,f)) && (t = strchr (s,'\n')));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1852 if (f) fclose (f); /* flush the file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1853 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1854
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1855 /* INBOX create function for tmail/dmail use only
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1856 * Accepts: mail stream
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1857 * path name buffer, preloaded with driver-dependent path
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1858 * Returns: T on success, NIL on failure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1859 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1860 * This routine is evil and a truly incredible kludge. It is private for
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1861 * tmail/dmail and is not supported for any other application.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1862 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1863
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1864 long path_create (MAILSTREAM *stream,char *path)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1865 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1866 long ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1867 short rsave = restrictBox;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1868 restrictBox = NIL; /* can't restrict */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1869 if (blackBox) { /* if black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1870 /* toss out driver dependent names */
3
2366b362676d imap-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 1
diff changeset
1871 sprintf (path,"%s/INBOX",mymailboxdir ());
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1872 blackBox = NIL; /* well that's evil - evil is going on */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1873 ret = mail_create (stream,path);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1874 blackBox = T; /* restore the box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1875 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1876 /* easy thing otherwise */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1877 else ret = mail_create (stream,path);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1878 restrictBox = rsave; /* restore restrictions */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1879 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1880 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1881
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1882 /* Default block notify routine
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1883 * Accepts: reason for calling
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1884 * data
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1885 * Returns: data
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1886 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1887
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1888 void *mm_blocknotify (int reason,void *data)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1889 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1890 void *ret = data;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1891 switch (reason) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1892 case BLOCK_SENSITIVE: /* entering sensitive code */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1893 ret = (void *) (unsigned long) alarm (0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1894 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1895 case BLOCK_NONSENSITIVE: /* exiting sensitive code */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1896 if ((unsigned long) data) alarm ((unsigned long) data);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1897 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1898 default: /* ignore all other reasons */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1899 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1900 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1901 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1902 }

yatex.org