annotate src/osdep/unix/env_unix.c @ 3:2366b362676d draft

imap-2007f
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 30 Oct 2014 00:00:57 +0900
parents 28a55bc1110c
children d741b3ecc917
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:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
425 ret = (void *) disablePlaintext;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
426 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
427 case SET_CHROOTSERVER:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
428 closedBox = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
429 case GET_CHROOTSERVER:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
430 ret = (void *) (closedBox ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
431 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
432 case SET_ADVERTISETHEWORLD:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
433 advertisetheworld = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
434 case GET_ADVERTISETHEWORLD:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
435 ret = (void *) (advertisetheworld ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
436 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
437 case SET_LIMITEDADVERTISE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
438 limitedadvertise = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
439 case GET_LIMITEDADVERTISE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
440 ret = (void *) (limitedadvertise ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
441 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
442 case SET_DISABLEAUTOSHAREDNS:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
443 noautomaticsharedns = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
444 case GET_DISABLEAUTOSHAREDNS:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
445 ret = (void *) (noautomaticsharedns ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
446 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
447 case SET_DISABLE822TZTEXT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
448 no822tztext = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
449 case GET_DISABLE822TZTEXT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
450 ret = (void *) (no822tztext ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
451 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
452
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
453 case SET_USERHASNOLIFE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
454 has_no_life = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
455 case GET_USERHASNOLIFE:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
456 ret = (void *) (has_no_life ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
457 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
458 case SET_KERBEROS_CP_SVR_NAME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
459 kerb_cp_svr_name = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
460 case GET_KERBEROS_CP_SVR_NAME:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
461 ret = (void *) (kerb_cp_svr_name ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
462 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
463 case SET_NETFSSTATBUG:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
464 netfsstatbug = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
465 case GET_NETFSSTATBUG:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
466 ret = (void *) (netfsstatbug ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
467 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
468 case SET_BLOCKENVINIT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
469 block_env_init = value ? T : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
470 case GET_BLOCKENVINIT:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
471 ret = (void *) (block_env_init ? VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
472 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
473 case SET_BLOCKNOTIFY:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
474 mailblocknotify = (blocknotify_t) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
475 case GET_BLOCKNOTIFY:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
476 ret = (void *) mailblocknotify;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
477 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
478 case SET_LOGOUTHOOK:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
479 maillogouthook = (logouthook_t) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
480 case GET_LOGOUTHOOK:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
481 ret = maillogouthook;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
482 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
483 case SET_LOGOUTDATA:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
484 maillogoutdata = (void *) value;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
485 case GET_LOGOUTDATA:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
486 ret = maillogoutdata;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
487 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
488 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
489 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
490
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
491 /* Write current time
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
492 * Accepts: destination string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
493 * optional format of day-of-week prefix
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
494 * format of date and time
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
495 * flag whether to append symbolic timezone
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
496 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
497
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
498 static void do_date (char *date,char *prefix,char *fmt,int suffix)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
499 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
500 time_t tn = time (0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
501 struct tm *t = gmtime (&tn);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
502 int zone = t->tm_hour * 60 + t->tm_min;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
503 int julian = t->tm_yday;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
504 t = localtime (&tn); /* get local time now */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
505 /* minus UTC minutes since midnight */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
506 zone = t->tm_hour * 60 + t->tm_min - zone;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
507 /* julian can be one of:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
508 * 36x local time is December 31, UTC is January 1, offset -24 hours
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
509 * 1 local time is 1 day ahead of UTC, offset +24 hours
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
510 * 0 local time is same day as UTC, no offset
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
511 * -1 local time is 1 day behind UTC, offset -24 hours
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
512 * -36x local time is January 1, UTC is December 31, offset +24 hours
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
513 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
514 if (julian = t->tm_yday -julian)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
515 zone += ((julian < 0) == (abs (julian) == 1)) ? -24*60 : 24*60;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
516 if (prefix) { /* want day of week? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
517 sprintf (date,prefix,days[t->tm_wday]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
518 date += strlen (date); /* make next sprintf append */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
519 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
520 /* output the date */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
521 sprintf (date,fmt,t->tm_mday,months[t->tm_mon],t->tm_year+1900,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
522 t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
523 /* append timezone suffix if desired */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
524 if (suffix) rfc822_timezone (date,(void *) t);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
525 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
526
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
527 /* Write current time in RFC 822 format
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
528 * Accepts: destination string
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 void rfc822_date (char *date)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
532 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
533 do_date (date,"%s, ","%d %s %d %02d:%02d:%02d %+03d%02d",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
534 no822tztext ? NIL : T);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
535 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
536
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
537
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
538 /* Write current time in fixed-width RFC 822 format
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
539 * Accepts: destination string
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 void rfc822_fixed_date (char *date)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
543 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
544 do_date (date,NIL,"%02d %s %4d %02d:%02d:%02d %+03d%02d",NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
545 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
546
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
547
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
548 /* Write current time in internal format
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
549 * Accepts: destination string
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 void internal_date (char *date)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
553 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
554 do_date (date,NIL,"%02d-%s-%d %02d:%02d:%02d %+03d%02d",NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
555 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
556
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
557 /* Initialize server
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
558 * Accepts: server name for syslog or NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
559 * /etc/services service name or NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
560 * alternate /etc/services service name or NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
561 * clock interrupt handler
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
562 * kiss-of-death interrupt handler
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
563 * hangup interrupt handler
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
564 * termination interrupt handler
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
565 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
566
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
567 void server_init (char *server,char *service,char *sslservice,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
568 void *clkint,void *kodint,void *hupint,void *trmint,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
569 void *staint)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
570 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
571 int onceonly = server && service && sslservice;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
572 if (onceonly) { /* set server name in syslog */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
573 int mask;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
574 openlog (myServerName = cpystr (server),LOG_PID,syslog_facility);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
575 fclose (stderr); /* possibly save a process ID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
576 dorc (NIL,NIL); /* do systemwide configuration */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
577 switch (mask = umask (022)){/* check old umask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
578 case 0: /* definitely unreasonable */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
579 case 022: /* don't need to change it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
580 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
581 default: /* already was a reasonable value */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
582 umask (mask); /* so change it back */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
583 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
584 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
585 arm_signal (SIGALRM,clkint); /* prepare for clock interrupt */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
586 arm_signal (SIGUSR2,kodint); /* prepare for Kiss Of Death */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
587 arm_signal (SIGHUP,hupint); /* prepare for hangup */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
588 arm_signal (SIGPIPE,hupint); /* alternative hangup */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
589 arm_signal (SIGTERM,trmint); /* prepare for termination */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
590 /* status dump */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
591 if (staint) arm_signal (SIGUSR1,staint);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
592 if (onceonly) { /* set up network and maybe SSL */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
593 long port;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
594 struct servent *sv;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
595 /* Use SSL if SSL service, or if server starts with "s" and not service */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
596 if (((port = tcp_serverport ()) >= 0)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
597 if ((sv = getservbyname (service,"tcp")) && (port == ntohs (sv->s_port)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
598 syslog (LOG_DEBUG,"%s service init from %s",service,tcp_clientaddr ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
599 else if ((sv = getservbyname (sslservice,"tcp")) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
600 (port == ntohs (sv->s_port))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
601 syslog (LOG_DEBUG,"%s SSL service init from %s",sslservice,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
602 tcp_clientaddr ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
603 ssl_server_init (server);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
604 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
605 else { /* not service or SSL service port */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
606 syslog (LOG_DEBUG,"port %ld service init from %s",port,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
607 tcp_clientaddr ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
608 if (*server == 's') ssl_server_init (server);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
609 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
610 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
611 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
612 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
613
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
614 /* Wait for stdin input
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
615 * Accepts: timeout in seconds
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
616 * Returns: T if have input on stdin, else NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
617 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
618
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
619 long server_input_wait (long seconds)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
620 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
621 fd_set rfd,efd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
622 struct timeval tmo;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
623 FD_ZERO (&rfd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
624 FD_ZERO (&efd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
625 FD_SET (0,&rfd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
626 FD_SET (0,&efd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
627 tmo.tv_sec = seconds; tmo.tv_usec = 0;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
628 return select (1,&rfd,0,&efd,&tmo) ? LONGT : NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
629 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
630
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
631 /* Return UNIX password entry for user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
632 * Accepts: user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
633 * Returns: password entry
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
634 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
635 * Tries all-lowercase form of user name if given user name fails
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
636 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
637
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
638 static struct passwd *pwuser (unsigned char *user)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
639 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
640 unsigned char *s;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
641 struct passwd *pw = getpwnam (user);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
642 if (!pw) { /* failed, see if any uppercase characters */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
643 for (s = user; *s && ((*s < 'A') || (*s > 'Z')); s++);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
644 if (*s) { /* yes, try all lowercase form */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
645 pw = getpwnam (s = lcase (cpystr (user)));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
646 fs_give ((void **) &s);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
647 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
648 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
649 return pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
650 }
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 /* Validate password for user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
654 * Accepts: user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
655 * password string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
656 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
657 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
658 * Returns: password entry if validated
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
659 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
660 * Tries password+1 if password fails and starts with space
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
661 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
662
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
663 static struct passwd *valpwd (char *user,char *pwd,int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
664 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
665 char *s;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
666 struct passwd *pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
667 struct passwd *ret = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
668 if (auth_md5.server) { /* using CRAM-MD5 authentication? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
669 if (s = auth_md5_pwd (user)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
670 if (!strcmp (s,pwd) || ((*pwd == ' ') && pwd[1] && !strcmp (s,pwd+1)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
671 ret = pwuser (user); /* validated, get passwd entry for user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
672 memset (s,0,strlen (s)); /* erase sensitive information */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
673 fs_give ((void **) &s);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
674 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
675 }
3
2366b362676d imap-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 1
diff changeset
676 else if (pw = pwuser (user)) {/* can get user? */
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
677 s = cpystr (pw->pw_name); /* copy returned name in case we need it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
678 if (*pwd && !(ret = checkpw (pw,pwd,argc,argv)) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
679 (*pwd == ' ') && pwd[1] && (ret = pwuser (s)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
680 ret = checkpw (pw,pwd+1,argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
681 fs_give ((void **) &s); /* don't need copy of name any more */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
682 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
683 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
684 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
685
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
686 /* Server log in
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
687 * Accepts: user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
688 * password string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
689 * authenticating user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
690 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
691 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
692 * Returns: T if password validated, NIL otherwise
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
693 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
694
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
695 long server_login (char *user,char *pwd,char *authuser,int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
696 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
697 struct passwd *pw = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
698 int level = LOG_NOTICE;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
699 char *err = "failed";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
700 /* cretins still haven't given up */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
701 if ((strlen (user) >= NETMAXUSER) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
702 (authuser && (strlen (authuser) >= NETMAXUSER))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
703 level = LOG_ALERT; /* escalate this alert */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
704 err = "SYSTEM BREAK-IN ATTEMPT";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
705 logtry = 0; /* render this session useless */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
706 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
707 else if (logtry-- <= 0) err = "excessive login failures";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
708 else if (disablePlaintext) err = "disabled";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
709 else if (!(authuser && *authuser)) pw = valpwd (user,pwd,argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
710 else if (valpwd (authuser,pwd,argc,argv)) pw = pwuser (user);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
711 if (pw && pw_login (pw,authuser,pw->pw_name,NIL,argc,argv)) return T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
712 syslog (level|LOG_AUTH,"Login %s user=%.64s auth=%.64s host=%.80s",err,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
713 user,(authuser && *authuser) ? authuser : user,tcp_clienthost ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
714 sleep (3); /* slow down possible cracker */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
715 return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
716 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
717
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
718 /* Authenticated server log in
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
719 * Accepts: user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
720 * authenticating user name string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
721 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
722 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
723 * Returns: T if password validated, NIL otherwise
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
724 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
725
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
726 long authserver_login (char *user,char *authuser,int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
727 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
728 return pw_login (pwuser (user),authuser,user,NIL,argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
729 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
730
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
731
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
732 /* Log in as anonymous daemon
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
733 * Accepts: argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
734 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
735 * Returns: T if successful, NIL if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
736 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
737
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
738 long anonymous_login (int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
739 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
740 /* log in Mr. A. N. Onymous */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
741 return pw_login (getpwnam (ANONYMOUSUSER),NIL,NIL,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
742 (char *) mail_parameters (NIL,GET_ANONYMOUSHOME,NIL),
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
743 argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
744 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
745
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
746 /* Finish log in and environment initialization
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
747 * Accepts: passwd struct for loginpw()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
748 * optional authentication user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
749 * user name (NIL for anonymous)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
750 * home directory (NIL to use directory from passwd struct)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
751 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
752 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
753 * Returns: T if successful, NIL if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
754 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
755
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
756 long pw_login (struct passwd *pw,char *auser,char *user,char *home,int argc,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
757 char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
758 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
759 struct group *gr;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
760 char **t;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
761 long ret = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
762 if (pw && pw->pw_uid) { /* must have passwd struct for non-UID 0 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
763 /* make safe copies of user and home */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
764 if (user) user = cpystr (pw->pw_name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
765 home = cpystr (home ? home : pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
766 /* authorization ID .NE. authentication ID? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
767 if (user && auser && *auser && compare_cstring (auser,user)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
768 /* scan list of mail administrators */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
769 if ((gr = getgrnam (ADMINGROUP)) && (t = gr->gr_mem)) while (*t && !ret)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
770 if (!compare_cstring (auser,*t++))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
771 ret = pw_login (pw,NIL,user,home,argc,argv);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
772 syslog (LOG_NOTICE|LOG_AUTH,"%s %.80s override of user=%.80s host=%.80s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
773 ret ? "Admin" : "Failed",auser,user,tcp_clienthost ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
774 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
775 else if (closedBox) { /* paranoid site, lock out other directories */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
776 if (chdir (home) || chroot (home))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
777 syslog (LOG_NOTICE|LOG_AUTH,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
778 "Login %s failed: unable to set chroot=%.80s host=%.80s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
779 pw->pw_name,home,tcp_clienthost ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
780 else if (loginpw (pw,argc,argv)) ret = env_init (user,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
781 else fatal ("Login failed after chroot");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
782 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
783 /* normal login */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
784 else if (((pw->pw_uid == geteuid ()) || loginpw (pw,argc,argv)) &&
3
2366b362676d imap-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 1
diff changeset
785 (ret = env_init (user,home))) chdir (myhomedir ());
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
786 fs_give ((void **) &home); /* clean up */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
787 if (user) fs_give ((void **) &user);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
788 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
789 endpwent (); /* in case shadow passwords in pw data */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
790 return ret; /* return status */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
791 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
792
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
793 /* Initialize environment
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
794 * Accepts: user name (NIL for anonymous)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
795 * home directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
796 * Returns: T, always
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
797 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
798
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
799 long env_init (char *user,char *home)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
800 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
801 extern MAILSTREAM CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
802 extern MAILSTREAM EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
803 struct passwd *pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
804 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
805 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
806 /* don't init if blocked */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
807 if (block_env_init) return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
808 if (myUserName) fatal ("env_init called twice!");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
809 /* initially nothing in namespace list */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
810 nslist[0] = nslist[1] = nslist[2] = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
811 /* myUserName must be set before dorc() call */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
812 myUserName = cpystr (user ? user : ANONYMOUSUSER);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
813 /* force default prototypes to be set */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
814 if (!createProto) createProto = &CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
815 if (!appendProto) appendProto = &EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
816 dorc (NIL,NIL); /* do systemwide configuration */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
817 if (!home) { /* closed box server */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
818 /* standard user can only reference home */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
819 if (user) nslist[0] = &nshome;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
820 else { /* anonymous user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
821 nslist[0] = &nsblackother; /* set root */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
822 anonymous = T; /* flag as anonymous */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
823 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
824 myHomeDir = cpystr (""); /* home directory is root */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
825 sysInbox = cpystr ("INBOX");/* make system INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
826 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
827 else { /* open or black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
828 closedBox = NIL; /* definitely not a closed box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
829 if (user) { /* remember user name and home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
830 if (blackBoxDir) { /* build black box directory name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
831 sprintf (tmp,"%s/%s",blackBoxDir,myUserName);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
832 /* must exist */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
833 if (!((!stat (home = tmp,&sbuf) && (sbuf.st_mode & S_IFDIR)) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
834 (blackBoxDefaultHome &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
835 !stat (home = blackBoxDefaultHome,&sbuf) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
836 (sbuf.st_mode & S_IFDIR)))) fatal ("no home");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
837 sysInbox = (char *) fs_get (strlen (home) + 7);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
838 /* set system INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
839 sprintf (sysInbox,"%s/INBOX",home);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
840 blackBox = T; /* mark that it's a black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
841 /* mbox meaningless if black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
842 mail_parameters (NIL,DISABLE_DRIVER,(void *) "mbox");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
843 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
844 nslist[0] = &nshome; /* home namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
845 /* limited advertise namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
846 if (limitedadvertise) nslist[2] = &nslimited;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
847 else if (blackBox) { /* black box namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
848 nslist[1] = &nsblackother;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
849 nslist[2] = &nsshared;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
850 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
851 else { /* open box namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
852 nslist[1] = &nsunixother;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
853 nslist[2] = advertisetheworld ? &nsworld : &nsshared;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
854 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
855 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
856 else {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
857 nslist[2] = &nsftp; /* anonymous user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
858 sprintf (tmp,"%s/INBOX",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
859 home = (char *) mail_parameters (NIL,GET_ANONYMOUSHOME,NIL));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
860 sysInbox = cpystr (tmp); /* make system INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
861 anonymous = T; /* flag as anonymous */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
862 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
863 myHomeDir = cpystr (home); /* set home directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
864 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
865
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
866 if (allowuserconfig) { /* allow user config files */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
867 dorc (strcat (strcpy (tmp,myHomeDir),"/.mminit"),T);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
868 dorc (strcat (strcpy (tmp,myHomeDir),"/.imaprc"),NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
869 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
870 if (!closedBox && !noautomaticsharedns) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
871 /* #ftp namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
872 if (!ftpHome && (pw = getpwnam ("ftp"))) ftpHome = cpystr (pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
873 /* #public namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
874 if (!publicHome && (pw = getpwnam ("imappublic")))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
875 publicHome = cpystr (pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
876 /* #shared namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
877 if (!anonymous && !sharedHome && (pw = getpwnam ("imapshared")))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
878 sharedHome = cpystr (pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
879 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
880 if (!myLocalHost) mylocalhost ();
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
881 if (!myNewsrc) myNewsrc = cpystr(strcat (strcpy (tmp,myHomeDir),"/.newsrc"));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
882 if (!newsActive) newsActive = cpystr (ACTIVEFILE);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
883 if (!newsSpool) newsSpool = cpystr (NEWSSPOOL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
884 /* re-do open action to get flags */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
885 (*createProto->dtb->open) (NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
886 endpwent (); /* close pw database */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
887 return T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
888 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
889
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
890 /* Return my user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
891 * Accepts: pointer to optional flags
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
892 * Returns: my user name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
893 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
894
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
895 char *myusername_full (unsigned long *flags)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
896 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
897 struct passwd *pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
898 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
899 char *s;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
900 unsigned long euid;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
901 char *ret = UNLOGGEDUSER;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
902 /* no user name yet and not root? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
903 if (!myUserName && (euid = geteuid ())) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
904 /* yes, look up getlogin() user name or EUID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
905 if (((s = (char *) getlogin ()) && *s && (strlen (s) < NETMAXUSER) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
906 (pw = getpwnam (s)) && (pw->pw_uid == euid)) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
907 (pw = getpwuid (euid))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
908 if (block_env_init) { /* don't env_init if blocked */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
909 if (flags) *flags = MU_LOGGEDIN;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
910 return pw->pw_name;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
911 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
912 env_init (pw->pw_name,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
913 ((s = getenv ("HOME")) && *s && (strlen (s) < NETMAXMBX) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
914 !stat (s,&sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFDIR)) ?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
915 s : pw->pw_dir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
916 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
917 else fatal ("Unable to look up user name");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
918 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
919 if (myUserName) { /* logged in? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
920 if (flags) *flags = anonymous ? MU_ANONYMOUS : MU_LOGGEDIN;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
921 ret = myUserName; /* return user name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
922 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
923 else if (flags) *flags = MU_NOTLOGGEDIN;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
924 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
925 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
926
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
927
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
928 /* Return my local host name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
929 * Returns: my local host name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
930 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
931
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
932 char *mylocalhost ()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
933 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
934 if (!myLocalHost) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
935 char *s,tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
936 char *t = "unknown";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
937 tmp[0] = tmp[MAILTMPLEN-1] = '\0';
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
938 if (!gethostname (tmp,MAILTMPLEN-1) && tmp[0]) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
939 /* sanity check of name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
940 for (s = tmp; (*s > 0x20) && (*s < 0x7f); ++s);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
941 if (!*s) t = tcp_canonical (tmp);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
942 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
943 myLocalHost = cpystr (t);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
944 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
945 return myLocalHost;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
946 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
947
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
948 /* Return my home directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
949 * Returns: my home directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
950 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
951
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
952 char *myhomedir ()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
953 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
954 if (!myHomeDir) myusername ();/* initialize if first time */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
955 return myHomeDir ? myHomeDir : "";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
956 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
957
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
958
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
959 /* Return my home mailbox name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
960 * Returns: my home directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
961 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
962
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
963 static char *mymailboxdir ()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
964 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
965 char *home = myhomedir ();
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
966 /* initialize if first time */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
967 if (!myMailboxDir && myHomeDir) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
968 if (mailsubdir) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
969 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
970 sprintf (tmp,"%s/%s",home,mailsubdir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
971 myMailboxDir = cpystr (tmp);/* use pre-defined subdirectory of home */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
972 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
973 else myMailboxDir = cpystr (home);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
974 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
975 return myMailboxDir ? myMailboxDir : "";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
976 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
977
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
978
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
979 /* Return system standard INBOX
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
980 * Accepts: buffer string
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 char *sysinbox ()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
984 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
985 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
986 if (!sysInbox) { /* initialize if first time */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
987 sprintf (tmp,"%s/%s",MAILSPOOL,myusername ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
988 sysInbox = cpystr (tmp); /* system inbox is from mail spool */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
989 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
990 return sysInbox;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
991 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
992
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
993 /* Return mailbox directory name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
994 * Accepts: destination buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
995 * directory prefix
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
996 * name in directory
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
997 * Returns: file name or NIL if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
998 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
999
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1000 char *mailboxdir (char *dst,char *dir,char *name)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1001 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1002 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1003 if (dir || name) { /* if either argument provided */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1004 if (dir) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1005 if (strlen (dir) > NETMAXMBX) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1006 strcpy (tmp,dir); /* write directory prefix */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1007 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1008 else tmp[0] = '\0'; /* otherwise null string */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1009 if (name) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1010 if (strlen (name) > NETMAXMBX) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1011 strcat (tmp,name); /* write name in directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1012 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1013 /* validate name, return its name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1014 if (!mailboxfile (dst,tmp)) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1015 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1016 /* no arguments, wants mailbox directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1017 else strcpy (dst,mymailboxdir ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1018 return dst; /* return the name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1019 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1020
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1021 /* Return mailbox file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1022 * Accepts: destination buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1023 * mailbox name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1024 * Returns: file name or empty string for driver-selected INBOX or NIL if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1025 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1026
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1027 char *mailboxfile (char *dst,char *name)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1028 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1029 struct passwd *pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1030 char *s;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1031 if (!name || !*name || (*name == '{') || (strlen (name) > NETMAXMBX) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1032 ((anonymous || blackBox || restrictBox || (*name == '#')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1033 (strstr (name,"..") || strstr (name,"//") || strstr (name,"/~"))))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1034 dst = NIL; /* invalid name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1035 else switch (*name) { /* determine mailbox type based upon name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1036 case '#': /* namespace name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1037 /* #ftp/ namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1038 if (((name[1] == 'f') || (name[1] == 'F')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1039 ((name[2] == 't') || (name[2] == 'T')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1040 ((name[3] == 'p') || (name[3] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1041 (name[4] == '/') && ftpHome) sprintf (dst,"%s/%s",ftpHome,name+5);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1042 /* #public/ and #shared/ namespaces */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1043 else if ((((name[1] == 'p') || (name[1] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1044 ((name[2] == 'u') || (name[2] == 'U')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1045 ((name[3] == 'b') || (name[3] == 'B')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1046 ((name[4] == 'l') || (name[4] == 'L')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1047 ((name[5] == 'i') || (name[5] == 'I')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1048 ((name[6] == 'c') || (name[6] == 'C')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1049 (name[7] == '/') && (s = publicHome)) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1050 (!anonymous && ((name[1] == 's') || (name[1] == 'S')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1051 ((name[2] == 'h') || (name[2] == 'H')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1052 ((name[3] == 'a') || (name[3] == 'A')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1053 ((name[4] == 'r') || (name[4] == 'R')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1054 ((name[5] == 'e') || (name[5] == 'E')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1055 ((name[6] == 'd') || (name[6] == 'D')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1056 (name[7] == '/') && (s = sharedHome)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1057 sprintf (dst,"%s/%s",s,compare_cstring (name+8,"INBOX") ?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1058 name+8 : "INBOX");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1059 else dst = NIL; /* unknown namespace */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1060 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1061
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1062 case '/': /* root access */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1063 if (anonymous) dst = NIL; /* anonymous forbidden to do this */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1064 else if (blackBox) { /* other user access if blackbox */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1065 if (restrictBox & RESTRICTOTHERUSER) dst = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1066 /* see if other user INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1067 else if ((s = strchr (name+1,'/')) && !compare_cstring (s+1,"INBOX")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1068 *s = '\0'; /* temporarily tie off string */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1069 sprintf (dst,"%s/%s/INBOX",blackBoxDir,name+1);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1070 *s = '/'; /* in case caller cares */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1071 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1072 else sprintf (dst,"%s/%s",blackBoxDir,name+1);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1073 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1074 else if ((restrictBox & RESTRICTROOT) && strcmp (name,sysinbox ()))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1075 dst = NIL; /* restricted and not access to sysinbox */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1076 else strcpy (dst,name); /* unrestricted, copy root name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1077 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1078 case '~': /* other user access */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1079 /* bad syntax or anonymous can't win */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1080 if (!*++name || anonymous) dst = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1081 /* ~/ equivalent to ordinary name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1082 else if (*name == '/') sprintf (dst,"%s/%s",mymailboxdir (),name+1);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1083 /* other user forbidden if closed/restricted */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1084 else if (closedBox || (restrictBox & RESTRICTOTHERUSER)) dst = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1085 else if (blackBox) { /* black box form of other user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1086 /* see if other user INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1087 if ((s = strchr (name,'/')) && compare_cstring (s+1,"INBOX")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1088 *s = '\0'; /* temporarily tie off string */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1089 sprintf (dst,"%s/%s/INBOX",blackBoxDir,name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1090 *s = '/'; /* in case caller cares */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1091 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1092 else sprintf (dst,"%s/%s",blackBoxDir,name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1093 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1094 else { /* clear box other user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1095 /* copy user name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1096 for (s = dst; *name && (*name != '/'); *s++ = *name++);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1097 *s++ = '\0'; /* tie off user name, look up in passwd file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1098 if ((pw = getpwnam (dst)) && pw->pw_dir) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1099 if (*name) name++; /* skip past the slash */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1100 /* canonicalize case of INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1101 if (!compare_cstring (name,"INBOX")) name = "INBOX";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1102 /* remove trailing / from directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1103 if ((s = strrchr (pw->pw_dir,'/')) && !s[1]) *s = '\0';
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1104 /* don't allow ~root/ if restricted root */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1105 if ((restrictBox & RESTRICTROOT) && !*pw->pw_dir) dst = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1106 /* build final name w/ subdir if needed */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1107 else if (mailsubdir) sprintf (dst,"%s/%s/%s",pw->pw_dir,mailsubdir,name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1108 else sprintf (dst,"%s/%s",pw->pw_dir,name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1109 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1110 else dst = NIL; /* no such user */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1111 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1112 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1113
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1114 case 'I': case 'i': /* possible INBOX */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1115 if (!compare_cstring (name+1,"NBOX")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1116 /* if restricted, use INBOX in mailbox dir */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1117 if (anonymous || blackBox || closedBox)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1118 sprintf (dst,"%s/INBOX",mymailboxdir ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1119 else *dst = '\0'; /* otherwise driver selects the name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1120 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1121 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1122 /* drop into to ordinary name case */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1123 default: /* ordinary name is easy */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1124 sprintf (dst,"%s/%s",mymailboxdir (),name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1125 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1126 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1127 return dst; /* return final name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1128 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1129
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1130 /* Dot-lock file locker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1131 * Accepts: file name to lock
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1132 * destination buffer for lock file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1133 * open file description on file name to lock
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1134 * Returns: T if success, NIL if failure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1135 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1136
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1137 long dotlock_lock (char *file,DOTLOCK *base,int fd)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1138 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1139 int i = locktimeout * 60;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1140 int j,mask,retry,pi[2],po[2];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1141 char *s,tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1142 struct stat sb;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1143 /* flush absurd file name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1144 if (strlen (file) > 512) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1145 /* build lock filename */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1146 sprintf (base->lock,"%s.lock",file);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1147 /* assume no pipe */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1148 base->pipei = base->pipeo = -1;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1149 do { /* make sure not symlink */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1150 if (!(j = chk_notsymlink (base->lock,&sb))) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1151 /* time out if file older than 5 minutes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1152 if ((j > 0) && ((time (0)) >= (sb.st_ctime + locktimeout * 60))) i = 0;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1153 /* try to create the lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1154 switch (retry = crexcl (base->lock)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1155 case -1: /* OK to retry */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1156 if (!(i%15)) { /* time to notify? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1157 sprintf (tmp,"Mailbox %.80s is locked, will override in %d seconds...",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1158 file,i);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1159 MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1160 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1161 sleep (1); /* wait 1 second before next try */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1162 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1163 case NIL: /* failure, can't retry */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1164 i = 0;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1165 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1166 case T: /* success, make sure others can break lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1167 chmod (base->lock,(int) dotlock_mode);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1168 return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1169 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1170 } while (i--); /* until out of retries */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1171 if (retry < 0) { /* still returning retry after locktimeout? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1172 if (!(j = chk_notsymlink (base->lock,&sb))) return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1173 if ((j > 0) && ((time (0)) < (sb.st_ctime + locktimeout * 60))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1174 sprintf (tmp,"Mailbox vulnerable - seizing %ld second old lock",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1175 (long) (time (0) - sb.st_ctime));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1176 MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1177 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1178 mask = umask (0); /* want our lock protection */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1179 unlink (base->lock); /* try to remove the old file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1180 /* seize the lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1181 if ((i = open (base->lock,O_WRONLY|O_CREAT,(int) dotlock_mode)) >= 0) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1182 close (i); /* don't need descriptor any more */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1183 sprintf (tmp,"Mailbox %.80s lock overridden",file);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1184 MM_LOG (tmp,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1185 chmod (base->lock,(int) dotlock_mode);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1186 umask (mask); /* restore old umask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1187 return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1188 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1189 umask (mask); /* restore old umask */
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 if (fd >= 0) switch (errno) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1193 case EACCES: /* protection failure? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1194 MM_CRITICAL (NIL); /* go critical */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1195 if (closedBox || !lockpgm); /* can't do on closed box or disabled */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1196 else if ((*lockpgm && stat (lockpgm,&sb)) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1197 (!*lockpgm && stat (lockpgm = LOCKPGM1,&sb) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1198 stat (lockpgm = LOCKPGM2,&sb) && stat (lockpgm = LOCKPGM3,&sb)))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1199 lockpgm = NIL; /* disable if can't find lockpgm */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1200 else if (pipe (pi) >= 0) { /* make command pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1201 long cf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1202 char *argv[4],arg[20];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1203 /* if input pipes usable create output pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1204 if ((pi[0] < FD_SETSIZE) && (pi[1] < FD_SETSIZE) && (pipe (po) >= 0)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1205 /* make sure output pipes are usable */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1206 if ((po[0] >= FD_SETSIZE) || (po[1] >= FD_SETSIZE));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1207 /* all is good, make inferior process */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1208 else if (!(j = fork ())) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1209 if (!fork ()) { /* make grandchild so it's inherited by init */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1210 /* prepare argument vector */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1211 sprintf (arg,"%d",fd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1212 argv[0] = lockpgm; argv[1] = arg;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1213 argv[2] = file; argv[3] = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1214 /* set parent's I/O to my O/I */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1215 dup2 (pi[1],1); dup2 (pi[1],2); dup2 (po[0],0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1216 /* close all unnecessary descriptors */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1217 for (cf = max (20,max (max (pi[0],pi[1]),max(po[0],po[1])));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1218 cf >= 3; --cf) if (cf != fd) close (cf);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1219 /* be our own process group */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1220 setpgrp (0,getpid ());
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1221 /* now run it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1222 _exit (execv (argv[0],argv));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1223 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1224 _exit (1); /* child is done */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1225 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1226 else if (j > 0) { /* parent process */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1227 fd_set rfd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1228 struct timeval tmo;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1229 FD_ZERO (&rfd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1230 FD_SET (pi[0],&rfd);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1231 tmo.tv_sec = locktimeout * 60;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1232 grim_pid_reap (j,NIL);/* reap child; grandchild now owned by init */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1233 /* read response from locking program */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1234 if (select (pi[0]+1,&rfd,0,0,&tmo) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1235 (read (pi[0],tmp,1) == 1) && (tmp[0] == '+')) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1236 /* success, record pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1237 base->pipei = pi[0]; base->pipeo = po[1];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1238 /* close child's side of the pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1239 close (pi[1]); close (po[0]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1240 MM_NOCRITICAL (NIL);/* no longer critical */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1241 return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1242 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1243 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1244 close (po[0]); close (po[1]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1245 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1246 close (pi[0]); close (pi[1]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1247 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1248
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1249 MM_NOCRITICAL (NIL); /* no longer critical */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1250 /* find directory/file delimiter */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1251 if (s = strrchr (base->lock,'/')) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1252 *s = '\0'; /* tie off at directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1253 sprintf(tmp, /* generate default message */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1254 "Mailbox vulnerable - directory %.80s must have 1777 protection",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1255 base->lock);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1256 /* definitely not 1777 if can't stat */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1257 mask = stat (base->lock,&sb) ? 0 : (sb.st_mode & 1777);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1258 *s = '/'; /* restore lock name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1259 if (mask != 1777) { /* default warning if not 1777 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1260 if (!disableLockWarning) MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1261 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1262 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1263 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1264 default:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1265 sprintf (tmp,"Mailbox vulnerable - error creating %.80s: %s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1266 base->lock,strerror (errno));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1267 if (!disableLockWarning) MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1268 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1269 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1270 base->lock[0] = '\0'; /* don't use lock files */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1271 return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1272 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1273
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1274 /* Dot-lock file unlocker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1275 * Accepts: lock file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1276 * Returns: T if success, NIL if failure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1277 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1278
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1279 long dotlock_unlock (DOTLOCK *base)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1280 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1281 long ret = LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1282 if (base && base->lock[0]) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1283 if (base->pipei >= 0) { /* if running through a pipe unlocker */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1284 ret = (write (base->pipeo,"+",1) == 1);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1285 /* nuke the pipes */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1286 close (base->pipei); close (base->pipeo);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1287 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1288 else ret = !unlink (base->lock);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1289 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1290 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1291 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1292
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1293 /* Lock file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1294 * Accepts: scratch buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1295 * file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1296 * type of locking operation (LOCK_SH or LOCK_EX)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1297 * pointer to return PID of locker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1298 * Returns: file descriptor of lock or negative if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1299 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1300
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1301 int lockname (char *lock,char *fname,int op,long *pid)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1302 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1303 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1304 *pid = 0; /* no locker PID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1305 return stat (fname,&sbuf) ? -1 : lock_work (lock,&sbuf,op,pid);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1306 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1307
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1308
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1309 /* Lock file descriptor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1310 * Accepts: file descriptor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1311 * lock file name buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1312 * type of locking operation (LOCK_SH or LOCK_EX)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1313 * Returns: file descriptor of lock or negative if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1314 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1315
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1316 int lockfd (int fd,char *lock,int op)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1317 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1318 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1319 return fstat (fd,&sbuf) ? -1 : lock_work (lock,&sbuf,op,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1320 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1321
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1322 /* Lock file name worker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1323 * Accepts: lock file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1324 * pointer to stat() buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1325 * type of locking operation (LOCK_SH or LOCK_EX)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1326 * pointer to return PID of locker
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1327 * Returns: file descriptor of lock or negative if error
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1328 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1329
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1330 int lock_work (char *lock,void *sb,int op,long *pid)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1331 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1332 struct stat lsb,fsb;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1333 struct stat *sbuf = (struct stat *) sb;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1334 char tmp[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1335 long i;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1336 int fd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1337 int mask = umask (0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1338 if (pid) *pid = 0; /* initialize return PID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1339 /* make temporary lock file name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1340 sprintf (lock,"%s/.%lx.%lx",closedBox ? "" : tmpdir,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1341 (unsigned long) sbuf->st_dev,(unsigned long) sbuf->st_ino);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1342 while (T) { /* until get a good lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1343 do switch ((int) chk_notsymlink (lock,&lsb)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1344 case 1: /* exists just once */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1345 if (((fd = open (lock,O_RDWR,shlock_mode)) >= 0) ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1346 (errno != ENOENT) || (chk_notsymlink (lock,&lsb) >= 0)) break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1347 case -1: /* name doesn't exist */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1348 fd = open (lock,O_RDWR|O_CREAT|O_EXCL,shlock_mode);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1349 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1350 default: /* multiple hard links */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1351 MM_LOG ("hard link to lock name",ERROR);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1352 syslog (LOG_CRIT,"SECURITY PROBLEM: hard link to lock name: %.80s",lock);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1353 case 0: /* symlink (already did syslog) */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1354 umask (mask); /* restore old mask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1355 return -1; /* fail: no lock file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1356 } while ((fd < 0) && (errno == EEXIST));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1357 if (fd < 0) { /* failed to get file descriptor */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1358 syslog (LOG_INFO,"Mailbox lock file %s open failure: %s",lock,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1359 strerror (errno));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1360 if (!closedBox) { /* more explicit snarl for bad configuration */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1361 if (stat (tmpdir,&lsb))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1362 syslog (LOG_CRIT,"SYSTEM ERROR: no %s: %s",tmpdir,strerror (errno));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1363 else if ((lsb.st_mode & 01777) != 01777) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1364 sprintf (tmp,"Can't lock for write: %.80s must have 1777 protection",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1365 tmpdir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1366 MM_LOG (tmp,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1367 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1368 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1369 umask (mask); /* restore old mask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1370 return -1; /* fail: can't open lock file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1371 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1372
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1373 /* non-blocking form */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1374 if (op & LOCK_NB) i = flock (fd,op);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1375 else { /* blocking form */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1376 (*mailblocknotify) (BLOCK_FILELOCK,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1377 i = flock (fd,op);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1378 (*mailblocknotify) (BLOCK_NONE,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1379 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1380 if (i) { /* failed, get other process' PID */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1381 if (pid && !fstat (fd,&fsb) && (i = min (fsb.st_size,MAILTMPLEN-1)) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1382 (read (fd,tmp,i) == i) && !(tmp[i] = 0) && ((i = atol (tmp)) > 0))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1383 *pid = i;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1384 close (fd); /* failed, give up on lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1385 umask (mask); /* restore old mask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1386 return -1; /* fail: can't lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1387 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1388 /* make sure this lock is good for us */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1389 if (!lstat (lock,&lsb) && ((lsb.st_mode & S_IFMT) != S_IFLNK) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1390 !fstat (fd,&fsb) && (lsb.st_dev == fsb.st_dev) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1391 (lsb.st_ino == fsb.st_ino) && (fsb.st_nlink == 1)) break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1392 close (fd); /* lock not right, drop fd and try again */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1393 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1394 chmod (lock,shlock_mode); /* make sure mode OK (don't use fchmod()) */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1395 umask (mask); /* restore old mask */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1396 return fd; /* success */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1397 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1398
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1399 /* Check to make sure not a symlink
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1400 * Accepts: file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1401 * stat buffer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1402 * Returns: -1 if doesn't exist, NIL if symlink, else number of hard links
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1403 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1404
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1405 long chk_notsymlink (char *name,void *sb)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1406 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1407 struct stat *sbuf = (struct stat *) sb;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1408 /* name exists? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1409 if (lstat (name,sbuf)) return -1;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1410 /* forbid symbolic link */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1411 if ((sbuf->st_mode & S_IFMT) == S_IFLNK) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1412 MM_LOG ("symbolic link on lock name",ERROR);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1413 syslog (LOG_CRIT,"SECURITY PROBLEM: symbolic link on lock name: %.80s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1414 name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1415 return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1416 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1417 return (long) sbuf->st_nlink; /* return number of hard links */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1418 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1419
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1420
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1421 /* Unlock file descriptor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1422 * Accepts: file descriptor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1423 * lock file name from lockfd()
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1424 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1425
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1426 void unlockfd (int fd,char *lock)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1427 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1428 /* delete the file if no sharers */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1429 if (!flock (fd,LOCK_EX|LOCK_NB)) unlink (lock);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1430 flock (fd,LOCK_UN); /* unlock it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1431 close (fd); /* close it */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1432 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1433
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1434 /* Set proper file protection for mailbox
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1435 * Accepts: mailbox name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1436 * actual file path name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1437 * Returns: T, always
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1438 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1439
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1440 long set_mbx_protections (char *mailbox,char *path)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1441 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1442 struct stat sbuf;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1443 int mode = (int) mbx_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1444 if (*mailbox == '#') { /* possible namespace? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1445 if (((mailbox[1] == 'f') || (mailbox[1] == 'F')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1446 ((mailbox[2] == 't') || (mailbox[2] == 'T')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1447 ((mailbox[3] == 'p') || (mailbox[3] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1448 (mailbox[4] == '/')) mode = (int) ftp_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1449 else if (((mailbox[1] == 'p') || (mailbox[1] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1450 ((mailbox[2] == 'u') || (mailbox[2] == 'U')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1451 ((mailbox[3] == 'b') || (mailbox[3] == 'B')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1452 ((mailbox[4] == 'l') || (mailbox[4] == 'L')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1453 ((mailbox[5] == 'i') || (mailbox[5] == 'I')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1454 ((mailbox[6] == 'c') || (mailbox[6] == 'C')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1455 (mailbox[7] == '/')) mode = (int) public_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1456 else if (((mailbox[1] == 's') || (mailbox[1] == 'S')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1457 ((mailbox[2] == 'h') || (mailbox[2] == 'H')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1458 ((mailbox[3] == 'a') || (mailbox[3] == 'A')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1459 ((mailbox[4] == 'r') || (mailbox[4] == 'R')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1460 ((mailbox[5] == 'e') || (mailbox[5] == 'E')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1461 ((mailbox[6] == 'd') || (mailbox[6] == 'D')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1462 (mailbox[7] == '/')) mode = (int) shared_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1463 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1464 /* if a directory */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1465 if (!stat (path,&sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFDIR)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1466 /* set owner search if allow read or write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1467 if (mode & 0600) mode |= 0100;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1468 if (mode & 060) mode |= 010;/* set group search if allow read or write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1469 if (mode & 06) mode |= 01; /* set world search if allow read or write */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1470 /* preserve directory SGID bit */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1471 if (sbuf.st_mode & S_ISGID) mode |= S_ISGID;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1472 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1473 chmod (path,mode); /* set the new protection, ignore failure */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1474 return LONGT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1475 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1476
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1477 /* Get proper directory protection
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1478 * Accepts: mailbox name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1479 * Returns: directory mode, always
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1480 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1481
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1482 long get_dir_protection (char *mailbox)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1483 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1484 if (*mailbox == '#') { /* possible namespace? */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1485 if (((mailbox[1] == 'f') || (mailbox[1] == 'F')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1486 ((mailbox[2] == 't') || (mailbox[2] == 'T')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1487 ((mailbox[3] == 'p') || (mailbox[3] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1488 (mailbox[4] == '/')) return ftp_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1489 else if (((mailbox[1] == 'p') || (mailbox[1] == 'P')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1490 ((mailbox[2] == 'u') || (mailbox[2] == 'U')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1491 ((mailbox[3] == 'b') || (mailbox[3] == 'B')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1492 ((mailbox[4] == 'l') || (mailbox[4] == 'L')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1493 ((mailbox[5] == 'i') || (mailbox[5] == 'I')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1494 ((mailbox[6] == 'c') || (mailbox[6] == 'C')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1495 (mailbox[7] == '/')) return public_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1496 else if (((mailbox[1] == 's') || (mailbox[1] == 'S')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1497 ((mailbox[2] == 'h') || (mailbox[2] == 'H')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1498 ((mailbox[3] == 'a') || (mailbox[3] == 'A')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1499 ((mailbox[4] == 'r') || (mailbox[4] == 'R')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1500 ((mailbox[5] == 'e') || (mailbox[5] == 'E')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1501 ((mailbox[6] == 'd') || (mailbox[6] == 'D')) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1502 (mailbox[7] == '/')) return shared_dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1503 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1504 return dir_protection;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1505 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1506
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1507 /* Determine default prototype stream to user
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1508 * Accepts: type (NIL for create, T for append)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1509 * Returns: default prototype stream
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1510 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1511
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1512 MAILSTREAM *default_proto (long type)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1513 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1514 myusername (); /* make sure initialized */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1515 /* return default driver's prototype */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1516 return type ? appendProto : createProto;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1517 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1518
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1519
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1520 /* Set up user flags for stream
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1521 * Accepts: MAIL stream
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1522 * Returns: MAIL stream with user flags set up
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1523 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1524
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1525 MAILSTREAM *user_flags (MAILSTREAM *stream)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1526 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1527 int i;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1528 myusername (); /* make sure initialized */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1529 for (i = 0; i < NUSERFLAGS && userFlags[i]; ++i)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1530 if (!stream->user_flags[i]) stream->user_flags[i] = cpystr (userFlags[i]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1531 return stream;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1532 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1533
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1534
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1535 /* Return nth user flag
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1536 * Accepts: user flag number
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1537 * Returns: flag
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1538 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1539
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1540 char *default_user_flag (unsigned long i)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1541 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1542 myusername (); /* make sure initialized */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1543 return userFlags[i];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1544 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1545
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1546 /* Process rc file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1547 * Accepts: file name
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1548 * .mminit flag
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1549 * Don't use this feature.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1550 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1551
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1552 void dorc (char *file,long flag)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1553 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1554 int i;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1555 char *s,*t,*k,*r,tmp[MAILTMPLEN],tmpx[MAILTMPLEN];
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1556 extern MAILSTREAM CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1557 extern MAILSTREAM EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1558 DRIVER *d;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1559 FILE *f;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1560 if ((f = fopen (file ? file : SYSCONFIG,"r")) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1561 (s = fgets (tmp,MAILTMPLEN,f)) && (t = strchr (s,'\n'))) do {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1562 *t++ = '\0'; /* tie off line, find second space */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1563 if ((k = strchr (s,' ')) && (k = strchr (++k,' '))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1564 *k++ = '\0'; /* tie off two words */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1565 if (!compare_cstring (s,"set keywords") && !userFlags[0]) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1566 /* yes, get first keyword */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1567 k = strtok_r (k,", ",&r);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1568 /* copy keyword list */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1569 for (i = 0; k && i < NUSERFLAGS; ++i) if (strlen (k) <= MAXUSERFLAG) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1570 if (userFlags[i]) fs_give ((void **) &userFlags[i]);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1571 userFlags[i] = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1572 k = strtok_r (NIL,", ",&r);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1573 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1574 if (flag) break; /* found "set keywords" in .mminit */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1575 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1576
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1577 else if (!flag) { /* none of these valid in .mminit */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1578 if (myUserName) { /* only valid if logged in */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1579 if (!compare_cstring (s,"set new-mailbox-format") ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1580 !compare_cstring (s,"set new-folder-format")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1581 if (!compare_cstring (k,"same-as-inbox")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1582 if (d = mail_valid (NIL,"INBOX",NIL)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1583 if (!compare_cstring (d->name,"mbox"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1584 d = (DRIVER *) mail_parameters (NIL,GET_DRIVER,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1585 (void *) "unix");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1586 else if (!compare_cstring (d->name,"dummy")) d = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1587 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1588 createProto = d ? ((*d->open) (NIL)) : &CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1589 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1590 else if (!compare_cstring (k,"system-standard"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1591 createProto = &CREATEPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1592 else { /* canonicalize mbox to unix */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1593 if (!compare_cstring (k,"mbox")) k = "unix";
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1594 /* see if a driver name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1595 if (d = (DRIVER *) mail_parameters (NIL,GET_DRIVER,(void *) k))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1596 createProto = (*d->open) (NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1597 else { /* duh... */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1598 sprintf (tmpx,"Unknown new mailbox format in %s: %s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1599 file ? file : SYSCONFIG,k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1600 MM_LOG (tmpx,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1601 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1602 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1603 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1604 if (!compare_cstring (s,"set empty-mailbox-format") ||
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1605 !compare_cstring (s,"set empty-folder-format")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1606 if (!compare_cstring (k,"invalid")) appendProto = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1607 else if (!compare_cstring (k,"same-as-inbox"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1608 appendProto = ((d = mail_valid (NIL,"INBOX",NIL)) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1609 compare_cstring (d->name,"dummy")) ?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1610 ((*d->open) (NIL)) : &EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1611 else if (!compare_cstring (k,"system-standard"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1612 appendProto = &EMPTYPROTO;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1613 else { /* see if a driver name */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1614 for (d = (DRIVER *) mail_parameters (NIL,GET_DRIVERS,NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1615 d && compare_cstring (d->name,k); d = d->next);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1616 if (d) appendProto = (*d->open) (NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1617 else { /* duh... */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1618 sprintf (tmpx,"Unknown empty mailbox format in %s: %s",
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1619 file ? file : SYSCONFIG,k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1620 MM_LOG (tmpx,WARN);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1621 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1622 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1623 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1624 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1625
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1626 if (!compare_cstring (s,"set local-host")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1627 fs_give ((void **) &myLocalHost);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1628 myLocalHost = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1629 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1630 else if (!compare_cstring (s,"set news-active-file")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1631 fs_give ((void **) &newsActive);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1632 newsActive = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1633 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1634 else if (!compare_cstring (s,"set news-spool-directory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1635 fs_give ((void **) &newsSpool);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1636 newsSpool = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1637 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1638 else if (!compare_cstring (s,"set mh-path"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1639 mail_parameters (NIL,SET_MHPATH,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1640 else if (!compare_cstring (s,"set mh-allow-inbox"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1641 mail_parameters (NIL,SET_MHALLOWINBOX,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1642 else if (!compare_cstring (s,"set news-state-file")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1643 fs_give ((void **) &myNewsrc);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1644 myNewsrc = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1645 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1646 else if (!compare_cstring (s,"set ftp-export-directory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1647 fs_give ((void **) &ftpHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1648 ftpHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1649 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1650 else if (!compare_cstring (s,"set public-home-directory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1651 fs_give ((void **) &publicHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1652 publicHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1653 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1654 else if (!compare_cstring (s,"set shared-home-directory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1655 fs_give ((void **) &sharedHome);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1656 sharedHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1657 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1658 else if (!compare_cstring (s,"set system-inbox")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1659 fs_give ((void **) &sysInbox);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1660 sysInbox = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1661 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1662 else if (!compare_cstring (s,"set mail-subdirectory")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1663 fs_give ((void **) &mailsubdir);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1664 mailsubdir = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1665 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1666 else if (!compare_cstring (s,"set from-widget"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1667 mail_parameters (NIL,SET_FROMWIDGET,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1668 compare_cstring (k,"header-only") ?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1669 VOIDT : NIL);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1670
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1671 else if (!compare_cstring (s,"set rsh-command"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1672 mail_parameters (NIL,SET_RSHCOMMAND,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1673 else if (!compare_cstring (s,"set rsh-path"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1674 mail_parameters (NIL,SET_RSHPATH,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1675 else if (!compare_cstring (s,"set ssh-command"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1676 mail_parameters (NIL,SET_SSHCOMMAND,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1677 else if (!compare_cstring (s,"set ssh-path"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1678 mail_parameters (NIL,SET_SSHPATH,(void *) k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1679 else if (!compare_cstring (s,"set tcp-open-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1680 mail_parameters (NIL,SET_OPENTIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1681 else if (!compare_cstring (s,"set tcp-read-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1682 mail_parameters (NIL,SET_READTIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1683 else if (!compare_cstring (s,"set tcp-write-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1684 mail_parameters (NIL,SET_WRITETIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1685 else if (!compare_cstring (s,"set rsh-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1686 mail_parameters (NIL,SET_RSHTIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1687 else if (!compare_cstring (s,"set ssh-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1688 mail_parameters (NIL,SET_SSHTIMEOUT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1689 else if (!compare_cstring (s,"set maximum-login-trials"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1690 mail_parameters (NIL,SET_MAXLOGINTRIALS,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1691 else if (!compare_cstring (s,"set lookahead"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1692 mail_parameters (NIL,SET_LOOKAHEAD,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1693 else if (!compare_cstring (s,"set prefetch"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1694 mail_parameters (NIL,SET_PREFETCH,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1695 else if (!compare_cstring (s,"set close-on-error"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1696 mail_parameters (NIL,SET_CLOSEONERROR,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1697 else if (!compare_cstring (s,"set imap-port"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1698 mail_parameters (NIL,SET_IMAPPORT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1699 else if (!compare_cstring (s,"set pop3-port"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1700 mail_parameters (NIL,SET_POP3PORT,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1701 else if (!compare_cstring (s,"set uid-lookahead"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1702 mail_parameters (NIL,SET_UIDLOOKAHEAD,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1703 else if (!compare_cstring (s,"set try-ssl-first"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1704 mail_parameters (NIL,SET_TRYSSLFIRST,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1705
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1706 else if (!compare_cstring (s,"set mailbox-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1707 mbx_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1708 else if (!compare_cstring (s,"set directory-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1709 dir_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1710 else if (!compare_cstring (s,"set lock-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1711 dotlock_mode = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1712 else if (!compare_cstring (s,"set ftp-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1713 ftp_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1714 else if (!compare_cstring (s,"set public-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1715 public_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1716 else if (!compare_cstring (s,"set shared-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1717 shared_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1718 else if (!compare_cstring (s,"set ftp-directory-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1719 ftp_dir_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1720 else if (!compare_cstring (s,"set public-directory-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1721 public_dir_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1722 else if (!compare_cstring (s,"set shared-directory-protection"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1723 shared_dir_protection = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1724 else if (!compare_cstring (s,"set dot-lock-file-timeout"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1725 locktimeout = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1726 else if (!compare_cstring (s,"set disable-fcntl-locking"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1727 fcntlhangbug = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1728 else if (!compare_cstring (s,"set disable-lock-warning"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1729 disableLockWarning = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1730 else if (!compare_cstring (s,"set disable-unix-UIDs-and-keywords"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1731 has_no_life = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1732 else if (!compare_cstring (s,"set hide-dot-files"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1733 hideDotFiles = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1734 else if (!compare_cstring (s,"set list-maximum-level"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1735 list_max_level = atol (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1736 else if (!compare_cstring (s,"set trust-dns"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1737 mail_parameters (NIL,SET_TRUSTDNS,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1738 else if (!compare_cstring (s,"set sasl-uses-ptr-name"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1739 mail_parameters (NIL,SET_SASLUSESPTRNAME,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1740 else if (!compare_cstring (s,"set network-filesystem-stat-bug"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1741 netfsstatbug = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1742 else if (!compare_cstring (s,"set nntp-range"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1743 mail_parameters (NIL,SET_NNTPRANGE,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1744
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1745 else if (!file) { /* only allowed in system init */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1746 if (!compare_cstring (s,"set black-box-directory") &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1747 !blackBoxDir) blackBoxDir = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1748 else if (!compare_cstring(s,"set black-box-default-home-directory")&&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1749 blackBoxDir && !blackBoxDefaultHome)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1750 blackBoxDefaultHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1751 else if (!compare_cstring (s,"set anonymous-home-directory") &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1752 !anonymousHome) anonymousHome = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1753 /* It's tempting to allow setting the CA path
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1754 * in a user init. However, that opens up a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1755 * vector of attack big enough to drive a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1756 * truck through... Resist the temptation.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1757 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1758 else if (!compare_cstring (s,"set CA-certificate-path"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1759 sslCApath = cpystr (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1760 else if (!compare_cstring (s,"set disable-plaintext"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1761 disablePlaintext = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1762 else if (!compare_cstring (s,"set allowed-login-attempts"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1763 logtry = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1764 else if (!compare_cstring (s,"set chroot-server"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1765 closedBox = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1766 else if (!compare_cstring (s,"set restrict-mailbox-access"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1767 for (k = strtok_r (k,", ",&r); k; k = strtok_r (NIL,", ",&r)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1768 if (!compare_cstring (k,"root")) restrictBox |= RESTRICTROOT;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1769 else if (!compare_cstring (k,"otherusers"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1770 restrictBox |= RESTRICTOTHERUSER;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1771 else if (!compare_cstring (k,"all")) restrictBox = -1;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1772 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1773 else if (!compare_cstring (s,"set advertise-the-world"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1774 advertisetheworld = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1775 else if (!compare_cstring (s,"set limited-advertise"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1776 limitedadvertise = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1777 else if (!compare_cstring
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1778 (s,"set disable-automatic-shared-namespaces"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1779 noautomaticsharedns = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1780 else if (!compare_cstring (s,"set allow-user-config"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1781 allowuserconfig = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1782 else if (!compare_cstring (s,"set allow-reverse-dns"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1783 mail_parameters (NIL,SET_ALLOWREVERSEDNS,(void *) atol (k));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1784 else if (!compare_cstring (s,"set k5-cp-uses-service-name"))
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1785 kerb_cp_svr_name = atoi (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1786 /* must appear in file after any
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1787 * "set disable-plaintext" command! */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1788 else if (!compare_cstring (s,"set plaintext-allowed-clients")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1789 for (k = strtok_r (k,", ",&r); k && !tcp_isclienthost (k);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1790 k = strtok_r (NIL,", ",&r));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1791 if (k) disablePlaintext = 0;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1792 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1793 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1794 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1795 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1796 } while ((s = fgets (tmp,MAILTMPLEN,f)) && (t = strchr (s,'\n')));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1797 if (f) fclose (f); /* flush the file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1798 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1799
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1800 /* INBOX create function for tmail/dmail use only
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1801 * Accepts: mail stream
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1802 * path name buffer, preloaded with driver-dependent path
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1803 * Returns: T on success, NIL on failure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1804 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1805 * This routine is evil and a truly incredible kludge. It is private for
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1806 * tmail/dmail and is not supported for any other application.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1807 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1808
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1809 long path_create (MAILSTREAM *stream,char *path)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1810 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1811 long ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1812 short rsave = restrictBox;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1813 restrictBox = NIL; /* can't restrict */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1814 if (blackBox) { /* if black box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1815 /* toss out driver dependent names */
3
2366b362676d imap-2007f
HIROSE Yuuji <yuuji@gentei.org>
parents: 1
diff changeset
1816 sprintf (path,"%s/INBOX",mymailboxdir ());
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1817 blackBox = NIL; /* well that's evil - evil is going on */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1818 ret = mail_create (stream,path);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1819 blackBox = T; /* restore the box */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1820 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1821 /* easy thing otherwise */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1822 else ret = mail_create (stream,path);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1823 restrictBox = rsave; /* restore restrictions */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1824 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1825 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1826
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1827 /* Default block notify routine
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1828 * Accepts: reason for calling
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1829 * data
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1830 * Returns: data
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1831 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1832
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1833 void *mm_blocknotify (int reason,void *data)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1834 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1835 void *ret = data;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1836 switch (reason) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1837 case BLOCK_SENSITIVE: /* entering sensitive code */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1838 ret = (void *) (unsigned long) alarm (0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1839 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1840 case BLOCK_NONSENSITIVE: /* exiting sensitive code */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1841 if ((unsigned long) data) alarm ((unsigned long) data);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1842 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1843 default: /* ignore all other reasons */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1844 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1845 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1846 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1847 }

yatex.org