1 /* $NetBSD: mbox_conf.c,v 1.1.1.1 2009/06/23 10:08:47 tron Exp $ */
2
3 /*++
4 /* NAME
5 /* mbox_conf 3
6 /* SUMMARY
7 /* mailbox lock configuration
8 /* SYNOPSIS
9 /* #include <mbox_conf.h>
10 /*
11 /* int mbox_lock_mask(string)
12 /* const char *string;
13 /*
14 /* ARGV *mbox_lock_names()
15 /* DESCRIPTION
16 /* The functions in this module translate between external
17 /* mailbox locking method names and internal representations.
18 /*
19 /* mbox_lock_mask() translates a string with locking method names
20 /* into a bit mask. Names are separated by comma or whitespace.
21 /* The following gives the method names and corresponding bit
22 /* mask value:
23 /* .IP "flock (MBOX_FLOCK_LOCK)"
24 /* Use flock() style lock after opening the file. This is the mailbox
25 /* locking method traditionally used on BSD-ish systems (including
26 /* Ultrix and SunOS). It is not suitable for remote file systems.
27 /* .IP "fcntl (MBOX_FCNTL_LOCK)"
28 /* Use fcntl() style lock after opening the file. This is the mailbox
29 /* locking method on System-V-ish systems (Solaris, AIX, IRIX, HP-UX).
30 /* This method is supposed to work for remote systems, but often
31 /* has problems.
32 /* .IP "dotlock (MBOX_DOT_LOCK)"
33 /* Create a lock file with the name \fIfilename\fB.lock\fR. This
34 /* method pre-dates kernel locks. This works with remote file systems,
35 /* modulo cache coherency problems.
36 /* .PP
37 /* mbox_lock_names() returns an array with the names of available
38 /* mailbox locking methods. The result should be given to argv_free().
39 /* DIAGNOSTICS
40 /* Fatal errors: undefined locking method name.
41 /* LICENSE
42 /* .ad
43 /* .fi
44 /* The Secure Mailer license must be distributed with this software.
45 /* AUTHOR(S)
46 /* Wietse Venema
47 /* IBM T.J. Watson Research
48 /* P.O. Box 704
49 /* Yorktown Heights, NY 10598, USA
50 /*--*/
51
52 /* System library. */
53
54 #include <sys_defs.h>
55
56 /* Utility library. */
57
58 #include <name_mask.h>
59 #include <argv.h>
60
61 /* Global library. */
62
63 #include <mail_params.h>
64 #include <mbox_conf.h>
65
66 /*
67 * The table with available mailbox locking methods. Some systems have
68 * flock() locks; all POSIX-compatible systems have fcntl() locks. Even
69 * though some systems do not use dotlock files by default (4.4BSD), such
70 * locks can be necessary when accessing mailbox files over NFS.
71 */
72 static const NAME_MASK mbox_mask[] = {
73 #ifdef HAS_FLOCK_LOCK
74 "flock", MBOX_FLOCK_LOCK,
75 #endif
76 #ifdef HAS_FCNTL_LOCK
77 "fcntl", MBOX_FCNTL_LOCK,
78 #endif
79 "dotlock", MBOX_DOT_LOCK,
80 0,
81 };
82
83 /* mbox_lock_mask - translate mailbox lock names to bit mask */
84
mbox_lock_mask(const char * string)85 int mbox_lock_mask(const char *string)
86 {
87 return (name_mask(VAR_MAILBOX_LOCK, mbox_mask, string));
88 }
89
90 /* mbox_lock_names - return available mailbox lock method names */
91
mbox_lock_names(void)92 ARGV *mbox_lock_names(void)
93 {
94 const NAME_MASK *np;
95 ARGV *argv;
96
97 argv = argv_alloc(2);
98 for (np = mbox_mask; np->name != 0; np++)
99 argv_add(argv, np->name, ARGV_END);
100 argv_terminate(argv);
101 return (argv);
102 }
103