imapext-2007

view src/osdep/amiga/env_ami.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line source
1 /* ========================================================================
2 * Copyright 1988-2008 University of Washington
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *
11 * ========================================================================
12 */
14 /*
15 * Program: Amiga environment routines
16 *
17 * Author: Mark Crispin
18 * UW Technology
19 * Seattle, WA 98195
20 * Internet: MRC@Washington.EDU
21 *
22 * Date: 1 August 1988
23 * Last Edited: 15 May 2008
24 */
26 #include <grp.h>
27 #include <signal.h>
28 #include <sys/wait.h>
30 /* c-client environment parameters */
32 static char *myUserName = NIL; /* user name */
33 static char *myHomeDir = NIL; /* home directory name */
34 static char *myMailboxDir = NIL;/* mailbox directory name */
35 static char *myLocalHost = NIL; /* local host name */
36 static char *myNewsrc = NIL; /* newsrc file name */
37 static char *mailsubdir = NIL; /* mail subdirectory name */
38 static char *sysInbox = NIL; /* system inbox name */
39 static char *newsActive = NIL; /* news active file */
40 static char *newsSpool = NIL; /* news spool */
41 /* anonymous home directory */
42 static char *anonymousHome = NIL;
43 static char *ftpHome = NIL; /* ftp export home directory */
44 static char *publicHome = NIL; /* public home directory */
45 static char *sharedHome = NIL; /* shared home directory */
46 static short anonymous = NIL; /* is anonymous */
47 static short restrictBox = NIL; /* is a restricted box */
48 static short has_no_life = NIL; /* is a cretin with no life */
49 /* block environment init */
50 static short block_env_init = NIL;
51 static short hideDotFiles = NIL;/* hide files whose names start with . */
52 /* advertise filesystem root */
53 static short advertisetheworld = NIL;
54 /* disable automatic shared namespaces */
55 static short noautomaticsharedns = NIL;
56 static short no822tztext = NIL; /* disable RFC [2]822 timezone text */
57 static short netfsstatbug = NIL;/* compensate for broken stat() on network
58 * filesystems (AFS and old NFS). Don't do
59 * this unless you really have to!
60 */
61 /* 1 = disable plaintext, 2 = if not SSL */
62 static long disablePlaintext = NIL;
63 static long list_max_level = 20;/* maximum level of list recursion */
64 /* default file protection */
65 static long mbx_protection = 0600;
66 /* default directory protection */
67 static long dir_protection = 0700;
68 /* default lock file protection */
69 static long lock_protection = MANDATORYLOCKPROT;
70 /* default ftp file protection */
71 static long ftp_protection = 0644;
72 static long ftp_dir_protection = 0755;
73 /* default public file protection */
74 static long public_protection = 0666;
75 static long public_dir_protection = 0777;
76 /* default shared file protection */
77 static long shared_protection = 0660;
78 static long shared_dir_protection = 0770;
79 static long locktimeout = 5; /* default lock timeout */
80 /* default prototypes */
81 static MAILSTREAM *createProto = NIL;
82 static MAILSTREAM *appendProto = NIL;
83 /* default user flags */
84 static char *userFlags[NUSERFLAGS] = {NIL};
85 static NAMESPACE *nslist[3]; /* namespace list */
86 static int logtry = 3; /* number of server login tries */
87 /* block notification */
88 static blocknotify_t mailblocknotify = mm_blocknotify;
90 /* Amiga namespaces */
92 /* personal mh namespace */
93 static NAMESPACE nsmhf = {"#mh/",'/',NIL,NIL};
94 static NAMESPACE nsmh = {"#mhinbox",NIL,NIL,&nsmhf};
95 /* home namespace */
96 static NAMESPACE nshome = {"",'/',NIL,&nsmh};
97 /* Amiga other user namespace */
98 static NAMESPACE nsamigaother = {"~",'/',NIL,NIL};
99 /* public (anonymous OK) namespace */
100 static NAMESPACE nspublic = {"#public/",'/',NIL,NIL};
101 /* netnews namespace */
102 static NAMESPACE nsnews = {"#news.",'.',NIL,&nspublic};
103 /* FTP export namespace */
104 static NAMESPACE nsftp = {"#ftp/",'/',NIL,&nsnews};
105 /* shared (no anonymous) namespace */
106 static NAMESPACE nsshared = {"#shared/",'/',NIL,&nsftp};
107 /* world namespace */
108 static NAMESPACE nsworld = {"/",'/',NIL,&nsshared};
110 #include "write.c" /* include safe writing routines */
111 #include "pmatch.c" /* include wildcard pattern matcher */
113 /* Get all authenticators */
115 #include "auths.c"
117 /* Environment manipulate parameters
118 * Accepts: function code
119 * function-dependent value
120 * Returns: function-dependent return value
121 */
123 void *env_parameters (long function,void *value)
124 {
125 void *ret = NIL;
126 switch ((int) function) {
127 case GET_NAMESPACE:
128 ret = (void *) nslist;
129 break;
130 case SET_USERNAME:
131 if (myUserName) fs_give ((void **) &myUserName);
132 myUserName = cpystr ((char *) value);
133 case GET_USERNAME:
134 ret = (void *) myUserName;
135 break;
136 case SET_HOMEDIR:
137 if (myHomeDir) fs_give ((void **) &myHomeDir);
138 myHomeDir = cpystr ((char *) value);
139 case GET_HOMEDIR:
140 ret = (void *) myHomeDir;
141 break;
142 case SET_LOCALHOST:
143 if (myLocalHost) fs_give ((void **) &myLocalHost);
144 myLocalHost = cpystr ((char *) value);
145 case GET_LOCALHOST:
146 ret = (void *) myLocalHost;
147 break;
148 case SET_NEWSRC:
149 if (myNewsrc) fs_give ((void **) &myNewsrc);
150 myNewsrc = cpystr ((char *) value);
151 case GET_NEWSRC:
152 ret = (void *) myNewsrc;
153 break;
154 case SET_NEWSACTIVE:
155 if (newsActive) fs_give ((void **) &newsActive);
156 newsActive = cpystr ((char *) value);
157 case GET_NEWSACTIVE:
158 ret = (void *) newsActive;
159 break;
160 case SET_NEWSSPOOL:
161 if (newsSpool) fs_give ((void **) &newsSpool);
162 newsSpool = cpystr ((char *) value);
163 case GET_NEWSSPOOL:
164 ret = (void *) newsSpool;
165 break;
167 case SET_ANONYMOUSHOME:
168 if (anonymousHome) fs_give ((void **) &anonymousHome);
169 anonymousHome = cpystr ((char *) value);
170 case GET_ANONYMOUSHOME:
171 if (!anonymousHome) anonymousHome = cpystr (ANONYMOUSHOME);
172 ret = (void *) anonymousHome;
173 break;
174 case SET_FTPHOME:
175 if (ftpHome) fs_give ((void **) &ftpHome);
176 ftpHome = cpystr ((char *) value);
177 case GET_FTPHOME:
178 ret = (void *) ftpHome;
179 break;
180 case SET_PUBLICHOME:
181 if (publicHome) fs_give ((void **) &publicHome);
182 publicHome = cpystr ((char *) value);
183 case GET_PUBLICHOME:
184 ret = (void *) publicHome;
185 break;
186 case SET_SHAREDHOME:
187 if (sharedHome) fs_give ((void **) &sharedHome);
188 sharedHome = cpystr ((char *) value);
189 case GET_SHAREDHOME:
190 ret = (void *) sharedHome;
191 break;
192 case SET_SYSINBOX:
193 if (sysInbox) fs_give ((void **) &sysInbox);
194 sysInbox = cpystr ((char *) value);
195 case GET_SYSINBOX:
196 ret = (void *) sysInbox;
197 break;
198 case SET_LISTMAXLEVEL:
199 list_max_level = (long) value;
200 case GET_LISTMAXLEVEL:
201 ret = (void *) list_max_level;
202 break;
204 case SET_MBXPROTECTION:
205 mbx_protection = (long) value;
206 case GET_MBXPROTECTION:
207 ret = (void *) mbx_protection;
208 break;
209 case SET_DIRPROTECTION:
210 dir_protection = (long) value;
211 case GET_DIRPROTECTION:
212 ret = (void *) dir_protection;
213 break;
214 case SET_LOCKPROTECTION:
215 lock_protection = (long) value;
216 case GET_LOCKPROTECTION:
217 ret = (void *) lock_protection;
218 break;
219 case SET_FTPPROTECTION:
220 ftp_protection = (long) value;
221 case GET_FTPPROTECTION:
222 ret = (void *) ftp_protection;
223 break;
224 case SET_PUBLICPROTECTION:
225 public_protection = (long) value;
226 case GET_PUBLICPROTECTION:
227 ret = (void *) public_protection;
228 break;
229 case SET_SHAREDPROTECTION:
230 shared_protection = (long) value;
231 case GET_SHAREDPROTECTION:
232 ret = (void *) shared_protection;
233 break;
234 case SET_FTPDIRPROTECTION:
235 ftp_dir_protection = (long) value;
236 case GET_FTPDIRPROTECTION:
237 ret = (void *) ftp_dir_protection;
238 break;
239 case SET_PUBLICDIRPROTECTION:
240 public_dir_protection = (long) value;
241 case GET_PUBLICDIRPROTECTION:
242 ret = (void *) public_dir_protection;
243 break;
244 case SET_SHAREDDIRPROTECTION:
245 shared_dir_protection = (long) value;
246 case GET_SHAREDDIRPROTECTION:
247 ret = (void *) shared_dir_protection;
248 break;
250 case SET_LOCKTIMEOUT:
251 locktimeout = (long) value;
252 case GET_LOCKTIMEOUT:
253 ret = (void *) locktimeout;
254 break;
255 case SET_HIDEDOTFILES:
256 hideDotFiles = value ? T : NIL;
257 case GET_HIDEDOTFILES:
258 ret = (void *) (hideDotFiles ? VOIDT : NIL);
259 break;
260 case SET_DISABLEPLAINTEXT:
261 disablePlaintext = (long) value;
262 case GET_DISABLEPLAINTEXT:
263 ret = (void *) disablePlaintext;
264 break;
265 case SET_ADVERTISETHEWORLD:
266 advertisetheworld = value ? T : NIL;
267 case GET_ADVERTISETHEWORLD:
268 ret = (void *) (advertisetheworld ? VOIDT : NIL);
269 break;
270 case SET_DISABLEAUTOSHAREDNS:
271 noautomaticsharedns = value ? T : NIL;
272 case GET_DISABLEAUTOSHAREDNS:
273 ret = (void *) (noautomaticsharedns ? VOIDT : NIL);
274 break;
275 case SET_DISABLE822TZTEXT:
276 no822tztext = value ? T : NIL;
277 case GET_DISABLE822TZTEXT:
278 ret = (void *) (no822tztext ? VOIDT : NIL);
279 break;
280 case SET_USERHASNOLIFE:
281 has_no_life = value ? T : NIL;
282 case GET_USERHASNOLIFE:
283 ret = (void *) (has_no_life ? VOIDT : NIL);
284 break;
285 case SET_NETFSSTATBUG:
286 netfsstatbug = value ? T : NIL;
287 case GET_NETFSSTATBUG:
288 ret = (void *) (netfsstatbug ? VOIDT : NIL);
289 break;
290 case SET_BLOCKENVINIT:
291 block_env_init = value ? T : NIL;
292 case GET_BLOCKENVINIT:
293 ret = (void *) (block_env_init ? VOIDT : NIL);
294 break;
295 case SET_BLOCKNOTIFY:
296 mailblocknotify = (blocknotify_t) value;
297 case GET_BLOCKNOTIFY:
298 ret = (void *) mailblocknotify;
299 break;
300 }
301 return ret;
302 }
304 /* Write current time
305 * Accepts: destination string
306 * optional format of day-of-week prefix
307 * format of date and time
308 * flag whether to append symbolic timezone
309 */
311 static void do_date (char *date,char *prefix,char *fmt,int suffix)
312 {
313 time_t tn = time (0);
314 struct tm *t = gmtime (&tn);
315 int zone = t->tm_hour * 60 + t->tm_min;
316 int julian = t->tm_yday;
317 t = localtime (&tn); /* get local time now */
318 /* minus UTC minutes since midnight */
319 zone = t->tm_hour * 60 + t->tm_min - zone;
320 /* julian can be one of:
321 * 36x local time is December 31, UTC is January 1, offset -24 hours
322 * 1 local time is 1 day ahead of UTC, offset +24 hours
323 * 0 local time is same day as UTC, no offset
324 * -1 local time is 1 day behind UTC, offset -24 hours
325 * -36x local time is January 1, UTC is December 31, offset +24 hours
326 */
327 if (julian = t->tm_yday -julian)
328 zone += ((julian < 0) == (abs (julian) == 1)) ? -24*60 : 24*60;
329 if (prefix) { /* want day of week? */
330 sprintf (date,prefix,days[t->tm_wday]);
331 date += strlen (date); /* make next sprintf append */
332 }
333 /* output the date */
334 sprintf (date,fmt,t->tm_mday,months[t->tm_mon],t->tm_year+1900,
335 t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60);
336 /* append timezone suffix if desired */
337 if (suffix) rfc822_timezone (date,(void *) t);
338 }
340 /* Write current time in RFC 822 format
341 * Accepts: destination string
342 */
344 void rfc822_date (char *date)
345 {
346 do_date (date,"%s, ","%d %s %d %02d:%02d:%02d %+03d%02d",
347 no822tztext ? NIL : T);
348 }
351 /* Write current time in fixed-width RFC 822 format
352 * Accepts: destination string
353 */
355 void rfc822_fixed_date (char *date)
356 {
357 do_date (date,NIL,"%02d %s %4d %02d:%02d:%02d %+03d%02d",NIL);
358 }
361 /* Write current time in internal format
362 * Accepts: destination string
363 */
365 void internal_date (char *date)
366 {
367 do_date (date,NIL,"%02d-%s-%d %02d:%02d:%02d %+03d%02d",NIL);
368 }
370 /* Initialize server
371 * Accepts: server name for syslog or NIL
372 * /etc/services service name or NIL
373 * alternate /etc/services service name or NIL
374 * clock interrupt handler
375 * kiss-of-death interrupt handler
376 * hangup interrupt handler
377 * termination interrupt handler
378 */
380 void server_init (char *server,char *service,char *sslservice,
381 void *clkint,void *kodint,void *hupint,void *trmint,
382 void *staint)
383 {
384 int onceonly = server && service && sslservice;
385 if (onceonly) { /* set server name in syslog */
386 int mask;
387 openlog (myServerName = cpystr (server),LOG_PID,syslog_facility);
388 fclose (stderr); /* possibly save a process ID */
390 switch (mask = umask (022)){/* check old umask */
391 case 0: /* definitely unreasonable */
392 case 022: /* don't need to change it */
393 break;
394 default: /* already was a reasonable value */
395 umask (mask); /* so change it back */
396 }
397 }
398 arm_signal (SIGALRM,clkint); /* prepare for clock interrupt */
399 arm_signal (SIGUSR2,kodint); /* prepare for Kiss Of Death */
400 arm_signal (SIGHUP,hupint); /* prepare for hangup */
401 arm_signal (SIGPIPE,hupint); /* alternative hangup */
402 arm_signal (SIGTERM,trmint); /* prepare for termination */
403 /* status dump */
404 if (staint) arm_signal (SIGUSR1,staint);
405 if (onceonly) { /* set up network and maybe SSL */
406 long port;
407 struct servent *sv;
408 /* Use SSL if SSL service, or if server starts with "s" and not service */
409 if (((port = tcp_serverport ()) >= 0)) {
410 if ((sv = getservbyname (service,"tcp")) && (port == ntohs (sv->s_port)))
411 syslog (LOG_DEBUG,"%s service init from %s",service,tcp_clientaddr ());
412 else if ((sv = getservbyname (sslservice,"tcp")) &&
413 (port == ntohs (sv->s_port))) {
414 syslog (LOG_DEBUG,"%s SSL service init from %s",sslservice,
415 tcp_clientaddr ());
416 ssl_server_init (server);
417 }
418 else { /* not service or SSL service port */
419 syslog (LOG_DEBUG,"port %ld service init from %s",port,
420 tcp_clientaddr ());
421 if (*server == 's') ssl_server_init (server);
422 }
423 }
424 }
425 }
427 /* Wait for stdin input
428 * Accepts: timeout in seconds
429 * Returns: T if have input on stdin, else NIL
430 */
432 long server_input_wait (long seconds)
433 {
434 fd_set rfd,efd;
435 struct timeval tmo;
436 FD_ZERO (&rfd);
437 FD_ZERO (&efd);
438 FD_SET (0,&rfd);
439 FD_SET (0,&efd);
440 tmo.tv_sec = seconds; tmo.tv_usec = 0;
441 return select (1,&rfd,0,&efd,&tmo) ? LONGT : NIL;
442 }
444 /* Return Amiga password entry for user name
445 * Accepts: user name string
446 * Returns: password entry
447 *
448 * Tries all-lowercase form of user name if given user name fails
449 */
451 static struct passwd *pwuser (unsigned char *user)
452 {
453 unsigned char *s;
454 struct passwd *pw = getpwnam (user);
455 if (!pw) { /* failed, see if any uppercase characters */
456 for (s = user; *s && ((*s < 'A') || (*s > 'Z')); s++);
457 if (*s) { /* yes, try all lowercase form */
458 pw = getpwnam (s = lcase (cpystr (user)));
459 fs_give ((void **) &s);
460 }
461 }
462 return pw;
463 }
466 /* Validate password for user name
467 * Accepts: user name string
468 * password string
469 * argument count
470 * argument vector
471 * Returns: password entry if validated
472 *
473 * Tries password+1 if password fails and starts with space
474 */
476 static struct passwd *valpwd (char *user,char *pwd,int argc,char *argv[])
477 {
478 char *s;
479 struct passwd *pw;
480 struct passwd *ret = NIL;
481 if (auth_md5.server) { /* using CRAM-MD5 authentication? */
482 if (s = auth_md5_pwd (user)) {
483 if (!strcmp (s,pwd) || ((*pwd == ' ') && pwd[1] && !strcmp (s,pwd+1)))
484 ret = pwuser (user); /* validated, get passwd entry for user */
485 memset (s,0,strlen (s)); /* erase sensitive information */
486 fs_give ((void **) &s);
487 }
488 }
489 else if (pw = pwuser (user)) {/* can get user? */
490 s = cpystr (pw->pw_name); /* copy returned name in case we need it */
491 if (*pwd && !(ret = checkpw (pw,pwd,argc,argv)) &&
492 (*pwd == ' ') && pwd[1] && (ret = pwuser (s)))
493 ret = checkpw (pw,pwd+1,argc,argv);
494 fs_give ((void **) &s); /* don't need copy of name any more */
495 }
496 return ret;
497 }
499 /* Server log in
500 * Accepts: user name string
501 * password string
502 * authenticating user name string
503 * argument count
504 * argument vector
505 * Returns: T if password validated, NIL otherwise
506 */
508 long server_login (char *user,char *pwd,char *authuser,int argc,char *argv[])
509 {
510 struct passwd *pw = NIL;
511 int level = LOG_NOTICE;
512 char *err = "failed";
513 /* cretins still haven't given up */
514 if ((strlen (user) >= NETMAXUSER) ||
515 (authuser && (strlen (authuser) >= NETMAXUSER))) {
516 level = LOG_ALERT; /* escalate this alert */
517 err = "SYSTEM BREAK-IN ATTEMPT";
518 logtry = 0; /* render this session useless */
519 }
520 else if (logtry-- <= 0) err = "excessive login failures";
521 else if (disablePlaintext) err = "disabled";
522 else if (!(authuser && *authuser)) pw = valpwd (user,pwd,argc,argv);
523 else if (valpwd (authuser,pwd,argc,argv)) pw = pwuser (user);
524 if (pw && pw_login (pw,authuser,pw->pw_name,NIL,argc,argv)) return T;
525 syslog (level|LOG_AUTH,"Login %s user=%.64s auth=%.64s host=%.80s",err,
526 user,(authuser && *authuser) ? authuser : user,tcp_clienthost ());
527 sleep (3); /* slow down possible cracker */
528 return NIL;
529 }
531 /* Authenticated server log in
532 * Accepts: user name string
533 * authenticating user name string
534 * argument count
535 * argument vector
536 * Returns: T if password validated, NIL otherwise
537 */
539 long authserver_login (char *user,char *authuser,int argc,char *argv[])
540 {
541 return pw_login (pwuser (user),authuser,user,NIL,argc,argv);
542 }
545 /* Log in as anonymous daemon
546 * Accepts: argument count
547 * argument vector
548 * Returns: T if successful, NIL if error
549 */
551 long anonymous_login (int argc,char *argv[])
552 {
553 /* log in Mr. A. N. Onymous */
554 return pw_login (getpwnam (ANONYMOUSUSER),NIL,NIL,
555 (char *) mail_parameters (NIL,GET_ANONYMOUSHOME,NIL),
556 argc,argv);
557 }
559 /* Finish log in and environment initialization
560 * Accepts: passwd struct for loginpw()
561 * optional authentication user name
562 * user name (NIL for anonymous)
563 * home directory (NIL to use directory from passwd struct)
564 * argument count
565 * argument vector
566 * Returns: T if successful, NIL if error
567 */
569 long pw_login (struct passwd *pw,char *auser,char *user,char *home,int argc,
570 char *argv[])
571 {
572 struct group *gr;
573 char **t;
574 long ret = NIL;
575 if (pw && pw->pw_uid) { /* must have passwd struct for non-UID 0 */
576 /* make safe copies of user and home */
577 if (user) user = cpystr (pw->pw_name);
578 home = cpystr (home ? home : pw->pw_dir);
579 /* authorization ID .NE. authentication ID? */
580 if (user && auser && *auser && compare_cstring (auser,user)) {
581 /* scan list of mail administrators */
582 if ((gr = getgrnam (ADMINGROUP)) && (t = gr->gr_mem)) while (*t && !ret)
583 if (!compare_cstring (auser,*t++))
584 ret = pw_login (pw,NIL,user,home,argc,argv);
585 syslog (LOG_NOTICE|LOG_AUTH,"%s %.80s override of user=%.80s host=%.80s",
586 ret ? "Admin" : "Failed",auser,user,tcp_clienthost ());
587 }
588 /* normal login */
589 else if (((pw->pw_uid == geteuid ()) || loginpw (pw,argc,argv)) &&
590 (ret = env_init (user,home))) chdir (myhomedir ());
591 fs_give ((void **) &home); /* clean up */
592 if (user) fs_give ((void **) &user);
593 }
594 return ret; /* return status */
595 }
597 /* Initialize environment
598 * Accepts: user name (NIL for anonymous)
599 * home directory name
600 * Returns: T, always
601 */
603 long env_init (char *user,char *home)
604 {
605 extern MAILSTREAM CREATEPROTO;
606 extern MAILSTREAM EMPTYPROTO;
607 struct passwd *pw;
608 struct stat sbuf;
609 char tmp[MAILTMPLEN];
610 /* don't init if blocked */
611 if (block_env_init) return LONGT;
612 if (myUserName) fatal ("env_init called twice!");
613 /* set up user name */
614 myUserName = cpystr (user ? user : ANONYMOUSUSER);
615 if (user) { /* remember user name and home directory */
616 nslist[0] = &nshome; /* home namespace */
617 nslist[1] = &nsamigaother;
618 nslist[2] = advertisetheworld ? &nsworld : &nsshared;
619 }
620 else { /* anonymous user */
621 nslist[0] = nslist[1] = NIL,nslist[2] = &nsftp;
622 sprintf (tmp,"%s/INBOX",
623 home = (char *) mail_parameters (NIL,GET_ANONYMOUSHOME,NIL));
624 sysInbox = cpystr (tmp); /* make system INBOX */
625 anonymous = T; /* flag as anonymous */
626 }
627 myHomeDir = cpystr (home); /* set home directory */
628 if (!noautomaticsharedns) {
629 /* #ftp namespace */
630 if (!ftpHome && (pw = getpwnam ("ftp"))) ftpHome = cpystr (pw->pw_dir);
631 /* #public namespace */
632 if (!publicHome && (pw = getpwnam ("imappublic")))
633 publicHome = cpystr (pw->pw_dir);
634 /* #shared namespace */
635 if (!anonymous && !sharedHome && (pw = getpwnam ("imapshared")))
636 sharedHome = cpystr (pw->pw_dir);
637 }
638 if (!myLocalHost) mylocalhost ();
639 if (!myNewsrc) myNewsrc = cpystr(strcat (strcpy (tmp,myHomeDir),"/.newsrc"));
640 if (!newsActive) newsActive = cpystr (ACTIVEFILE);
641 if (!newsSpool) newsSpool = cpystr (NEWSSPOOL);
642 /* force default prototype to be set */
643 if (!createProto) createProto = &CREATEPROTO;
644 if (!appendProto) appendProto = &EMPTYPROTO;
645 /* re-do open action to get flags */
646 (*createProto->dtb->open) (NIL);
647 endpwent (); /* close pw database */
648 return T;
649 }
651 /* Return my user name
652 * Accepts: pointer to optional flags
653 * Returns: my user name
654 */
656 char *myusername_full (unsigned long *flags)
657 {
658 struct passwd *pw;
659 struct stat sbuf;
660 char *s;
661 unsigned long euid;
662 char *ret = UNLOGGEDUSER;
663 /* no user name yet and not root? */
664 if (!myUserName && (euid = geteuid ())) {
665 /* yes, look up getlogin() user name or EUID */
666 if (((s = (char *) getlogin ()) && *s && (strlen (s) < NETMAXUSER) &&
667 (pw = getpwnam (s)) && (pw->pw_uid == euid)) ||
668 (pw = getpwuid (euid))) {
669 if (block_env_init) { /* don't env_init if blocked */
670 if (flags) *flags = MU_LOGGEDIN;
671 return pw->pw_name;
672 }
673 env_init (pw->pw_name,
674 ((s = getenv ("HOME")) && *s && (strlen (s) < NETMAXMBX) &&
675 !stat (s,&sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFDIR)) ?
676 s : pw->pw_dir);
677 }
678 else fatal ("Unable to look up user name");
679 }
680 if (myUserName) { /* logged in? */
681 if (flags) *flags = anonymous ? MU_ANONYMOUS : MU_LOGGEDIN;
682 ret = myUserName; /* return user name */
683 }
684 else if (flags) *flags = MU_NOTLOGGEDIN;
685 return ret;
686 }
687 /* Return my local host name
688 * Returns: my local host name
689 */
691 char *mylocalhost ()
692 {
693 char tmp[MAILTMPLEN];
694 struct hostent *host_name;
695 if (!myLocalHost) myLocalHost = cpystr (gethostname (tmp,MAILTMPLEN-1) ?
696 "random-pc" : tcp_canonical (tmp));
697 return myLocalHost;
698 }
700 /* Return my home directory name
701 * Returns: my home directory name
702 */
704 char *myhomedir ()
705 {
706 if (!myHomeDir) myusername ();/* initialize if first time */
707 return myHomeDir ? myHomeDir : "";
708 }
711 /* Return my home mailbox name
712 * Returns: my home directory name
713 */
715 static char *mymailboxdir ()
716 {
717 char *home = myhomedir ();
718 if (!myMailboxDir && home) { /* initialize if first time */
719 if (mailsubdir) {
720 char tmp[MAILTMPLEN];
721 sprintf (tmp,"%s/%s",home,mailsubdir);
722 myMailboxDir = cpystr (tmp);/* use pre-defined subdirectory of home */
723 }
724 else myMailboxDir = cpystr (home);
725 }
726 return myMailboxDir ? myMailboxDir : "";
727 }
730 /* Return system standard INBOX
731 * Accepts: buffer string
732 */
734 char *sysinbox ()
735 {
736 char tmp[MAILTMPLEN];
737 if (!sysInbox) { /* initialize if first time */
738 sprintf (tmp,"%s/%s",MAILSPOOL,myusername ());
739 sysInbox = cpystr (tmp); /* system inbox is from mail spool */
740 }
741 return sysInbox;
742 }
744 /* Return mailbox directory name
745 * Accepts: destination buffer
746 * directory prefix
747 * name in directory
748 * Returns: file name or NIL if error
749 */
751 char *mailboxdir (char *dst,char *dir,char *name)
752 {
753 char tmp[MAILTMPLEN];
754 if (dir || name) { /* if either argument provided */
755 if (dir) {
756 if (strlen (dir) > NETMAXMBX) return NIL;
757 strcpy (tmp,dir); /* write directory prefix */
758 }
759 else tmp[0] = '\0'; /* otherwise null string */
760 if (name) {
761 if (strlen (name) > NETMAXMBX) return NIL;
762 strcat (tmp,name); /* write name in directory */
763 }
764 /* validate name, return its name */
765 if (!mailboxfile (dst,tmp)) return NIL;
766 }
767 /* no arguments, wants mailbox directory */
768 else strcpy (dst,mymailboxdir ());
769 return dst; /* return the name */
770 }
772 /* Return mailbox file name
773 * Accepts: destination buffer
774 * mailbox name
775 * Returns: file name or empty string for driver-selected INBOX or NIL if error
776 */
778 char *mailboxfile (char *dst,char *name)
779 {
780 struct passwd *pw;
781 char *s;
782 if (!name || !*name || (*name == '{') || (strlen (name) > NETMAXMBX) ||
783 ((anonymous || restrictBox || (*name == '#')) &&
784 (strstr (name,"..") || strstr (name,"//") || strstr (name,"/~"))))
785 dst = NIL; /* invalid name */
786 else switch (*name) { /* determine mailbox type based upon name */
787 case '#': /* namespace name */
788 /* #ftp/ namespace */
789 if (((name[1] == 'f') || (name[1] == 'F')) &&
790 ((name[2] == 't') || (name[2] == 'T')) &&
791 ((name[3] == 'p') || (name[3] == 'P')) &&
792 (name[4] == '/') && ftpHome) sprintf (dst,"%s/%s",ftpHome,name+5);
793 /* #public/ and #shared/ namespaces */
794 else if ((((name[1] == 'p') || (name[1] == 'P')) &&
795 ((name[2] == 'u') || (name[2] == 'U')) &&
796 ((name[3] == 'b') || (name[3] == 'B')) &&
797 ((name[4] == 'l') || (name[4] == 'L')) &&
798 ((name[5] == 'i') || (name[5] == 'I')) &&
799 ((name[6] == 'c') || (name[6] == 'C')) &&
800 (name[7] == '/') && (s = publicHome)) ||
801 (!anonymous && ((name[1] == 's') || (name[1] == 'S')) &&
802 ((name[2] == 'h') || (name[2] == 'H')) &&
803 ((name[3] == 'a') || (name[3] == 'A')) &&
804 ((name[4] == 'r') || (name[4] == 'R')) &&
805 ((name[5] == 'e') || (name[5] == 'E')) &&
806 ((name[6] == 'd') || (name[6] == 'D')) &&
807 (name[7] == '/') && (s = sharedHome)))
808 sprintf (dst,"%s/%s",s,compare_cstring (name,"INBOX") ? name : "INBOX");
809 else dst = NIL; /* unknown namespace */
810 break;
812 case '/': /* root access */
813 if (anonymous) dst = NIL; /* anonymous forbidden to do this */
814 else if ((restrictBox & RESTRICTROOT) && strcmp (name,sysinbox ()))
815 dst = NIL; /* restricted and not access to sysinbox */
816 else strcpy (dst,name); /* unrestricted, copy root name */
817 break;
818 case '~': /* other user access */
819 /* bad syntax or anonymous can't win */
820 if (!*++name || anonymous) dst = NIL;
821 /* ~/ equivalent to ordinary name */
822 else if (*name == '/') sprintf (dst,"%s/%s",mymailboxdir (),name+1);
823 /* other user forbidden if restricted */
824 else if (restrictBox & RESTRICTOTHERUSER) dst = NIL;
825 else { /* clear box other user */
826 /* copy user name */
827 for (s = dst; *name && (*name != '/'); *s++ = *name++);
828 *s++ = '\0'; /* tie off user name, look up in passwd file */
829 if ((pw = getpwnam (dst)) && pw->pw_dir) {
830 if (*name) name++; /* skip past the slash */
831 /* canonicalize case of INBOX */
832 if (!compare_cstring (name,"INBOX")) name = "INBOX";
833 /* remove trailing / from directory */
834 if ((s = strrchr (pw->pw_dir,'/')) && !s[1]) *s = '\0';
835 /* don't allow ~root/ if restricted root */
836 if ((restrictBox & RESTRICTROOT) && !*pw->pw_dir) dst = NIL;
837 /* build final name w/ subdir if needed */
838 else if (mailsubdir) sprintf (dst,"%s/%s/%s",pw->pw_dir,mailsubdir,name);
839 else sprintf (dst,"%s/%s",pw->pw_dir,name);
840 }
841 else dst = NIL; /* no such user */
842 }
843 break;
844 case 'I': case 'i': /* possible INBOX */
845 if (!compare_cstring (name+1,"NBOX")) {
846 /* if anonymous, use INBOX in mailbox dir */
847 if (anonymous) sprintf (dst,"%s/INBOX",mymailboxdir ());
848 else *dst = '\0'; /* otherwise driver selects the name */
849 break;
850 }
851 /* drop into to ordinary name case */
852 default: /* ordinary name is easy */
853 sprintf (dst,"%s/%s",mymailboxdir (),name);
854 break;
855 }
856 return dst; /* return final name */
857 }
859 /* Dot-lock file locker
860 * Accepts: file name to lock
861 * destination buffer for lock file name
862 * open file description on file name to lock
863 * Returns: T if success, NIL if failure
864 */
866 long dotlock_lock (char *file,DOTLOCK *base,int fd)
867 {
868 int i = locktimeout * 60;
869 int j,mask,retry,pi[2],po[2];
870 char *s,tmp[MAILTMPLEN];
871 struct stat sb;
872 /* flush absurd file name */
873 if (strlen (file) > 512) return NIL;
874 /* build lock filename */
875 sprintf (base->lock,"%s.lock",file);
876 /* assume no pipe */
877 base->pipei = base->pipeo = -1;
878 do { /* make sure not symlink */
879 if (!(j = chk_notsymlink (base->lock,&sb))) return NIL;
880 /* time out if file older than 5 minutes */
881 if ((j > 0) && ((time (0)) >= (sb.st_ctime + locktimeout * 60))) i = 0;
882 /* try to create the lock */
883 if ((j = open (name,O_WRONLY|O_CREAT|O_EXCL,(int) lock_protection)) >= 0) {
884 close (i); /* make the file, now close it */
885 chmod (base->lock,(int) lock_protection);
886 return LONGT;
887 }
888 if (errno == EEXIST) { /* already locked? */
889 retry = -1; /* can try again */
890 if (!(i%15)) { /* time to notify? */
891 sprintf (tmp,"Mailbox %.80s is locked, will override in %d seconds...",
892 file,i);
893 mm_log (tmp,WARN);
894 }
895 sleep (1); /* wait 1 second before next try */
896 }
897 else retry = i = 0; /* hard failure, no more retries */
898 } while (i--); /* until out of retries */
899 if (retry < 0) { /* still returning retry after locktimeout? */
900 if (!(j = chk_notsymlink (base->lock,&sb))) return NIL;
901 if ((j > 0) && ((time (0)) < (sb.st_ctime + locktimeout * 60))) {
902 sprintf (tmp,"Mailbox vulnerable - seizing %ld second old lock",
903 (long) (time (0) - sb.st_ctime));
904 mm_log (tmp,WARN);
905 }
906 mask = umask (0);
907 unlink (base->lock); /* try to remove the old file */
908 /* seize the lock */
909 if ((i = open (base->lock,O_WRONLY|O_CREAT,(int) lock_protection)) >= 0) {
910 close (i); /* don't need descriptor any more */
911 sprintf (tmp,"Mailbox %.80s lock overridden",file);
912 mm_log (tmp,NIL);
913 chmod (base->lock,(int) lock_protection);
914 umask (mask) /* restore old umask */
915 return LONGT;
916 }
917 umask (mask) /* restore old umask */
918 }
920 if (fd >= 0) switch (errno) {
921 case EACCES: /* protection failure? */
922 /* make command pipes */
923 if (!stat (LOCKPGM,&sb) && (pipe (pi) >= 0)) {
924 /* if input pipes usable create output pipes */
925 if ((pi[0] < FD_SETSIZE) && (pi[1] < FD_SETSIZE) && (pipe (po) >= 0)) {
926 /* make sure output pipes are usable */
927 if ((po[0] >= FD_SETSIZE) || (po[1] >= FD_SETSIZE));
928 /* all is good, make inferior process */
929 else if (!(j = fork ())) {
930 if (!fork ()) { /* make grandchild so it's inherited by init */
931 long cf; /* don't change caller vars in case vfork() */
932 char *argv[4],arg[20];
933 /* prepare argument vector */
934 sprintf (arg,"%d",fd);
935 argv[0] = LOCKPGM; argv[1] = arg;
936 argv[2] = file; argv[3] = NIL;
937 /* set parent's I/O to my O/I */
938 dup2 (pi[1],1); dup2 (pi[1],2); dup2 (po[0],0);
939 /* close all unnecessary descriptors */
940 for (cf = max (20,max (max (pi[0],pi[1]),max(po[0],po[1])));
941 cf >= 3; --cf) if (cf != fd) close (cf);
942 /* be our own process group */
943 setpgrp (0,getpid ());
944 /* now run it */
945 _exit (execv (argv[0],argv));
946 }
947 _exit (1); /* child is done */
948 }
949 else if (j > 0) { /* parent process */
950 fd_set rfd;
951 struct timeval tmo;
952 FD_ZERO (&rfd);
953 FD_SET (pi[0],&rfd);
954 tmo.tv_sec = locktimeout * 60;
955 grim_pid_reap (j,NIL);/* reap child; grandchild now owned by init */
956 /* read response from locking program */
957 if (select (pi[0]+1,&rfd,0,0,&tmo) &&
958 (read (pi[0],tmp,1) == 1) && (tmp[0] == '+')) {
959 /* success, record pipes */
960 base->pipei = pi[0]; base->pipeo = po[1];
961 /* close child's side of the pipes */
962 close (pi[1]); close (po[0]);
963 return LONGT;
964 }
965 }
966 close (po[0]); close (po[1]);
967 }
968 close (pi[0]); close (pi[1]);
969 }
970 /* find directory/file delimiter */
971 if (s = strrchr (base->lock,'/')) {
972 *s = '\0'; /* tie off at directory */
973 sprintf(tmp, /* generate default message */
974 "Mailbox vulnerable - directory %.80s must have 1777 protection",
975 base->lock);
976 /* definitely not 1777 if can't stat */
977 mask = stat (base->lock,&sb) ? 0 : (sb.st_mode & 1777);
978 *s = '/'; /* restore lock name */
979 if (mask != 1777) { /* default warning if not 1777 */
980 MM_LOG (tmp,WARN);
981 break;
982 }
983 }
984 default:
985 sprintf (tmp,"Mailbox vulnerable - error creating %.80s: %s",
986 base->lock,strerror (errno));
987 mm_log (tmp,WARN); /* this is probably not good */
988 break;
989 }
990 base->lock[0] = '\0'; /* don't use lock files */
991 return NIL;
992 }
994 /* Dot-lock file unlocker
995 * Accepts: lock file name
996 * Returns: T if success, NIL if failure
997 */
999 long dotlock_unlock (DOTLOCK *base)
1001 long ret = LONGT;
1002 if (base && base->lock[0]) {
1003 if (base->pipei >= 0) { /* if running through a pipe unlocker */
1004 ret = (write (base->pipeo,"+",1) == 1);
1005 /* nuke the pipes */
1006 close (base->pipei); close (base->pipeo);
1008 else ret = !unlink (base->lock);
1010 return ret;
1013 /* Lock file name
1014 * Accepts: scratch buffer
1015 * file name
1016 * type of locking operation (LOCK_SH or LOCK_EX)
1017 * pointer to return PID of locker
1018 * Returns: file descriptor of lock or negative if error
1019 */
1021 int lockname (char *lock,char *fname,int op,long *pid)
1023 struct stat sbuf;
1024 *pid = 0; /* no locker PID */
1025 return stat (fname,&sbuf) ? -1 : lock_work (lock,&sbuf,op,pid);
1029 /* Lock file descriptor
1030 * Accepts: file descriptor
1031 * lock file name buffer
1032 * type of locking operation (LOCK_SH or LOCK_EX)
1033 * Returns: file descriptor of lock or negative if error
1034 */
1036 int lockfd (int fd,char *lock,int op)
1038 struct stat sbuf;
1039 return fstat (fd,&sbuf) ? -1 : lock_work (lock,&sbuf,op,NIL);
1042 /* Lock file name worker
1043 * Accepts: lock file name
1044 * pointer to stat() buffer
1045 * type of locking operation (LOCK_SH or LOCK_EX)
1046 * pointer to return PID of locker
1047 * Returns: file descriptor of lock or negative if error
1048 */
1050 int lock_work (char *lock,void *sb,int op,long *pid)
1052 struct stat lsb,fsb;
1053 struct stat *sbuf = (struct stat *) sb;
1054 char tmp[MAILTMPLEN];
1055 long i;
1056 int fd;
1057 int mask = umask (0);
1058 if (pid) *pid = 0; /* initialize return PID */
1059 /* make temporary lock file name */
1060 sprintf (lock,"%s/.%lx.%lx","/tmp",
1061 (unsigned long) sbuf->st_dev,(unsigned long) sbuf->st_ino);
1062 while (T) { /* until get a good lock */
1063 do switch ((int) chk_notsymlink (lock,&lsb)) {
1064 case 1: /* exists just once */
1065 if (((fd = open (lock,O_RDWR,lock_protection)) >= 0) ||
1066 (errno != ENOENT) || (chk_notsymlink (lock,&lsb) >= 0)) break;
1067 case -1: /* name doesn't exist */
1068 fd = open (lock,O_RDWR|O_CREAT|O_EXCL,lock_protection);
1069 break;
1070 default: /* multiple hard links */
1071 mm_log ("hard link to lock name",ERROR);
1072 syslog (LOG_CRIT,"SECURITY PROBLEM: hard link to lock name: %.80s",lock);
1073 case 0: /* symlink (already did syslog) */
1074 umask (mask); /* restore old mask */
1075 return -1; /* fail: no lock file */
1076 } while ((fd < 0) && (errno == EEXIST));
1077 if (fd < 0) { /* failed to get file descriptor */
1078 syslog (LOG_INFO,"Mailbox lock file %s open failure: %s",lock,
1079 strerror (errno));
1080 if (stat ("/tmp",&lsb))
1081 syslog (LOG_CRIT,"SYSTEM ERROR: no /tmp: %s",strerror (errno));
1082 else if ((lsb.st_mode & 01777) != 01777)
1083 mm_log ("Can't lock for write: /tmp must have 1777 protection",WARN);
1084 umask (mask); /* restore old mask */
1085 return -1; /* fail: can't open lock file */
1088 /* non-blocking form */
1089 if (op & LOCK_NB) i = flock (fd,op);
1090 else { /* blocking form */
1091 (*mailblocknotify) (BLOCK_FILELOCK,NIL);
1092 i = flock (fd,op);
1093 (*mailblocknotify) (BLOCK_NONE,NIL);
1095 if (i) { /* failed, get other process' PID */
1096 if (pid && !fstat (fd,&fsb) && (i = min (fsb.st_size,MAILTMPLEN-1)) &&
1097 (read (fd,tmp,i) == i) && !(tmp[i] = 0) && ((i = atol (tmp)) > 0))
1098 *pid = i;
1099 close (fd); /* failed, give up on lock */
1100 umask (mask); /* restore old mask */
1101 return -1; /* fail: can't lock */
1103 /* make sure this lock is good for us */
1104 if (!lstat (lock,&lsb) && ((lsb.st_mode & S_IFMT) != S_IFLNK) &&
1105 !fstat (fd,&fsb) && (lsb.st_dev == fsb.st_dev) &&
1106 (lsb.st_ino == fsb.st_ino) && (fsb.st_nlink == 1)) break;
1107 close (fd); /* lock not right, drop fd and try again */
1109 /* make sure mode OK (don't use fchmod()) */
1110 chmod (lock,(int) lock_protection);
1111 umask (mask); /* restore old mask */
1112 return fd; /* success */
1115 /* Check to make sure not a symlink
1116 * Accepts: file name
1117 * stat buffer
1118 * Returns: -1 if doesn't exist, NIL if symlink, else number of hard links
1119 */
1121 long chk_notsymlink (char *name,void *sb)
1123 struct stat *sbuf = (struct stat *) sb;
1124 /* name exists? */
1125 if (lstat (name,sbuf)) return -1;
1126 /* forbid symbolic link */
1127 if ((sbuf->st_mode & S_IFMT) == S_IFLNK) {
1128 mm_log ("symbolic link on lock name",ERROR);
1129 syslog (LOG_CRIT,"SECURITY PROBLEM: symbolic link on lock name: %.80s",
1130 name);
1131 return NIL;
1133 return (long) sbuf->st_nlink; /* return number of hard links */
1137 /* Unlock file descriptor
1138 * Accepts: file descriptor
1139 * lock file name from lockfd()
1140 */
1142 void unlockfd (int fd,char *lock)
1144 /* delete the file if no sharers */
1145 if (!flock (fd,LOCK_EX|LOCK_NB)) unlink (lock);
1146 flock (fd,LOCK_UN); /* unlock it */
1147 close (fd); /* close it */
1150 /* Set proper file protection for mailbox
1151 * Accepts: mailbox name
1152 * actual file path name
1153 * Returns: T, always
1154 */
1156 long set_mbx_protections (char *mailbox,char *path)
1158 struct stat sbuf;
1159 int mode = (int) mbx_protection;
1160 if (*mailbox == '#') { /* possible namespace? */
1161 if (((mailbox[1] == 'f') || (mailbox[1] == 'F')) &&
1162 ((mailbox[2] == 't') || (mailbox[2] == 'T')) &&
1163 ((mailbox[3] == 'p') || (mailbox[3] == 'P')) &&
1164 (mailbox[4] == '/')) mode = (int) ftp_protection;
1165 else if (((mailbox[1] == 'p') || (mailbox[1] == 'P')) &&
1166 ((mailbox[2] == 'u') || (mailbox[2] == 'U')) &&
1167 ((mailbox[3] == 'b') || (mailbox[3] == 'B')) &&
1168 ((mailbox[4] == 'l') || (mailbox[4] == 'L')) &&
1169 ((mailbox[5] == 'i') || (mailbox[5] == 'I')) &&
1170 ((mailbox[6] == 'c') || (mailbox[6] == 'C')) &&
1171 (mailbox[7] == '/')) mode = (int) public_protection;
1172 else if (((mailbox[1] == 's') || (mailbox[1] == 'S')) &&
1173 ((mailbox[2] == 'h') || (mailbox[2] == 'H')) &&
1174 ((mailbox[3] == 'a') || (mailbox[3] == 'A')) &&
1175 ((mailbox[4] == 'r') || (mailbox[4] == 'R')) &&
1176 ((mailbox[5] == 'e') || (mailbox[5] == 'E')) &&
1177 ((mailbox[6] == 'd') || (mailbox[6] == 'D')) &&
1178 (mailbox[7] == '/')) mode = (int) shared_protection;
1180 /* if a directory */
1181 if (!stat (path,&sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFDIR)) {
1182 /* set owner search if allow read or write */
1183 if (mode & 0600) mode |= 0100;
1184 if (mode & 060) mode |= 010;/* set group search if allow read or write */
1185 if (mode & 06) mode |= 01; /* set world search if allow read or write */
1186 /* preserve directory SGID bit */
1187 if (sbuf.st_mode & S_ISGID) mode |= S_ISGID;
1189 chmod (path,mode); /* set the new protection, ignore failure */
1190 return LONGT;
1193 /* Get proper directory protection
1194 * Accepts: mailbox name
1195 * Returns: directory mode, always
1196 */
1198 long get_dir_protection (char *mailbox)
1200 if (*mailbox == '#') { /* possible namespace? */
1201 if (((mailbox[1] == 'f') || (mailbox[1] == 'F')) &&
1202 ((mailbox[2] == 't') || (mailbox[2] == 'T')) &&
1203 ((mailbox[3] == 'p') || (mailbox[3] == 'P')) &&
1204 (mailbox[4] == '/')) return ftp_dir_protection;
1205 else if (((mailbox[1] == 'p') || (mailbox[1] == 'P')) &&
1206 ((mailbox[2] == 'u') || (mailbox[2] == 'U')) &&
1207 ((mailbox[3] == 'b') || (mailbox[3] == 'B')) &&
1208 ((mailbox[4] == 'l') || (mailbox[4] == 'L')) &&
1209 ((mailbox[5] == 'i') || (mailbox[5] == 'I')) &&
1210 ((mailbox[6] == 'c') || (mailbox[6] == 'C')) &&
1211 (mailbox[7] == '/')) return public_dir_protection;
1212 else if (((mailbox[1] == 's') || (mailbox[1] == 'S')) &&
1213 ((mailbox[2] == 'h') || (mailbox[2] == 'H')) &&
1214 ((mailbox[3] == 'a') || (mailbox[3] == 'A')) &&
1215 ((mailbox[4] == 'r') || (mailbox[4] == 'R')) &&
1216 ((mailbox[5] == 'e') || (mailbox[5] == 'E')) &&
1217 ((mailbox[6] == 'd') || (mailbox[6] == 'D')) &&
1218 (mailbox[7] == '/')) return shared_dir_protection;
1220 return dir_protection;
1223 /* Determine default prototype stream to user
1224 * Accepts: type (NIL for create, T for append)
1225 * Returns: default prototype stream
1226 */
1228 MAILSTREAM *default_proto (long type)
1230 myusername (); /* make sure initialized */
1231 /* return default driver's prototype */
1232 return type ? appendProto : createProto;
1236 /* Set up user flags for stream
1237 * Accepts: MAIL stream
1238 * Returns: MAIL stream with user flags set up
1239 */
1241 MAILSTREAM *user_flags (MAILSTREAM *stream)
1243 int i;
1244 myusername (); /* make sure initialized */
1245 for (i = 0; i < NUSERFLAGS && userFlags[i]; ++i)
1246 if (!stream->user_flags[i]) stream->user_flags[i] = cpystr (userFlags[i]);
1247 return stream;
1251 /* Return nth user flag
1252 * Accepts: user flag number
1253 * Returns: flag
1254 */
1256 char *default_user_flag (unsigned long i)
1258 myusername (); /* make sure initialized */
1259 return userFlags[i];
1262 /* Default block notify routine
1263 * Accepts: reason for calling
1264 * data
1265 * Returns: data
1266 */
1268 void *mm_blocknotify (int reason,void *data)
1270 void *ret = data;
1271 switch (reason) {
1272 case BLOCK_SENSITIVE: /* entering sensitive code */
1273 ret = (void *) alarm (0);
1274 break;
1275 case BLOCK_NONSENSITIVE: /* exiting sensitive code */
1276 if ((unsigned int) data) alarm ((unsigned int) data);
1277 break;
1278 default: /* ignore all other reasons */
1279 break;
1281 return ret;

UW-IMAP'd extensions by yuuji