1 |
/* GNU mailutils - a suite of utilities for electronic mail |
/* GNU Mailutils -- a suite of utilities for electronic mail |
2 |
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Mailutils is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2, or (at your option) |
the Free Software Foundation; either version 2, or (at your option) |
7 |
any later version. |
any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Mailutils is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
GNU General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
along with GNU Mailutils; if not, write to the Free Software |
16 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
17 |
|
|
18 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
28 |
#include <mailutils/argp.h> |
#include <mailutils/argp.h> |
29 |
#include <mailutils/errno.h> |
#include <mailutils/errno.h> |
30 |
#include <mailutils/locker.h> |
#include <mailutils/locker.h> |
31 |
|
#include <mailutils/nls.h> |
32 |
|
|
33 |
const char *argp_program_version = "GNU dotlock (" PACKAGE_STRING ")"; |
const char *argp_program_version = "GNU dotlock (" PACKAGE_STRING ")"; |
34 |
static char doc[] = |
static char doc[] = |
35 |
"GNU dotlock -- lock mail spool files" |
N_("GNU dotlock -- lock mail spool files" |
36 |
"\v" |
"\v" |
37 |
"Returns 0 on success, 3 if the locking the file fails because" |
"Returns 0 on success, 3 if the locking the file fails because" |
38 |
" it's already locked, and 1 if some other kind of error occurred." |
" it's already locked, and 1 if some other kind of error occurred."); |
39 |
; |
|
40 |
static char args_doc[] = "FILE"; |
static char args_doc[] = N_("FILE"); |
41 |
error_t argp_err_exit_status = MU_DL_EX_ERROR; |
error_t argp_err_exit_status = MU_DL_EX_ERROR; |
42 |
|
|
43 |
static struct argp_option options[] = { |
static struct argp_option options[] = { |
44 |
{"unlock", 'u', NULL, 0, |
{"unlock", 'u', NULL, 0, |
45 |
"Unlock", 0}, |
N_("Unlock"), 0}, |
46 |
|
|
47 |
{"force", 'f', "MINUTES", OPTION_ARG_OPTIONAL, |
{"force", 'f', "MINUTES", OPTION_ARG_OPTIONAL, |
48 |
"Forcibly break an existing lock older than a certain time", 0}, |
N_("Forcibly break an existing lock older than a certain time"), 0}, |
49 |
|
|
50 |
{"retry", 'r', "RETRIES", OPTION_ARG_OPTIONAL, |
{"retry", 'r', "RETRIES", OPTION_ARG_OPTIONAL, |
51 |
"Retry the lock a few times", 0}, |
N_("Retry the lock a few times"), 0}, |
52 |
|
|
53 |
{"debug", 'd', NULL, 0, |
{"debug", 'd', NULL, 0, |
54 |
"Print details of failure reasons to stderr", 0}, |
N_("Print details of failure reasons to stderr"), 0}, |
55 |
|
|
56 |
{"test", 'T', "PROGRAM", OPTION_HIDDEN, |
{"test", 'T', "PROGRAM", OPTION_HIDDEN, |
57 |
"Test external dotlocker", 0}, |
N_("Test external dotlocker"), 0}, |
58 |
|
|
59 |
{NULL, 0, NULL, 0, NULL, 0} |
{NULL, 0, NULL, 0, NULL, 0} |
60 |
}; |
}; |
101 |
{ |
{ |
102 |
retries = atoi (arg); |
retries = atoi (arg); |
103 |
if (retries <= 0) |
if (retries <= 0) |
104 |
argp_error (state, "RETRIES must be greater than 0"); |
argp_error (state, _("RETRIES must be greater than 0")); |
105 |
} |
} |
106 |
flags |= MU_LOCKER_RETRY; |
flags |= MU_LOCKER_RETRY; |
107 |
break; |
break; |
111 |
{ |
{ |
112 |
force = atoi (arg); |
force = atoi (arg); |
113 |
if (force <= 0) |
if (force <= 0) |
114 |
argp_error (state, "MINUTES must be greater than 0"); |
argp_error (state, _("MINUTES must be greater than 0")); |
115 |
force *= 60; |
force *= 60; |
116 |
} |
} |
117 |
flags |= MU_LOCKER_TIME; |
flags |= MU_LOCKER_TIME; |
119 |
|
|
120 |
case ARGP_KEY_ARG: |
case ARGP_KEY_ARG: |
121 |
if (file) |
if (file) |
122 |
argp_error (state, "only one FILE can be specified"); |
argp_error (state, _("only one FILE can be specified")); |
123 |
file = arg; |
file = arg; |
124 |
break; |
break; |
125 |
|
|
126 |
case ARGP_KEY_NO_ARGS: |
case ARGP_KEY_NO_ARGS: |
127 |
argp_error (state, "FILE must be specified"); |
argp_error (state, _("FILE must be specified")); |
128 |
|
|
129 |
default: |
default: |
130 |
return ARGP_ERR_UNKNOWN; |
return ARGP_ERR_UNKNOWN; |
140 |
pid_t usergid = getgid(); |
pid_t usergid = getgid(); |
141 |
pid_t mailgid = getegid(); |
pid_t mailgid = getegid(); |
142 |
|
|
143 |
|
/* Native Language Support */ |
144 |
|
mu_init_nls (); |
145 |
|
|
146 |
/* Drop permissions during argument parsing. */ |
/* Drop permissions during argument parsing. */ |
147 |
|
|
148 |
if(setegid(usergid) < 0) |
if(setegid(usergid) < 0) |
153 |
if ((err = locker_create (&locker, file, flags))) |
if ((err = locker_create (&locker, file, flags))) |
154 |
{ |
{ |
155 |
if (debug) |
if (debug) |
156 |
fprintf (stderr, "locker create failed: %s\n", mu_errstring (err)); |
fprintf (stderr, _("locker create failed: %s\n"), mu_errstring (err)); |
157 |
return MU_DL_EX_ERROR; |
return MU_DL_EX_ERROR; |
158 |
} |
} |
159 |
|
|
181 |
locker_destroy (&locker); |
locker_destroy (&locker); |
182 |
|
|
183 |
if (debug && err) |
if (debug && err) |
184 |
fprintf (stderr, "%slocking %s failed: %s\n", |
fprintf (stderr, _("%s %s failed: %s\n"), |
185 |
unlock ? "un" : "", file, mu_errstring (err)); |
unlock ? _("unlocking") : _("locking"), file, mu_errstring (err)); |
186 |
|
|
187 |
switch (err) |
switch (err) |
188 |
{ |
{ |