| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
#define NO_SHORTNAMES |
|---|
| 59 |
#include <config.h> |
|---|
| 60 |
#include <sys/types.h> |
|---|
| 61 |
#include <sys/stat.h> |
|---|
| 62 |
#include <sys/file.h> |
|---|
| 63 |
#include <stdio.h> |
|---|
| 64 |
#include <errno.h> |
|---|
| 65 |
|
|---|
| 66 |
#include <getopt.h> |
|---|
| 67 |
#ifdef HAVE_UNISTD_H |
|---|
| 68 |
#include <unistd.h> |
|---|
| 69 |
#endif |
|---|
| 70 |
#ifdef HAVE_FCNTL_H |
|---|
| 71 |
#include <fcntl.h> |
|---|
| 72 |
#endif |
|---|
| 73 |
#include "syswait.h" |
|---|
| 74 |
#ifdef MAIL_USE_POP |
|---|
| 75 |
#include "pop.h" |
|---|
| 76 |
#endif |
|---|
| 77 |
|
|---|
| 78 |
#ifdef MSDOS |
|---|
| 79 |
#undef access |
|---|
| 80 |
#endif |
|---|
| 81 |
|
|---|
| 82 |
#ifndef DIRECTORY_SEP |
|---|
| 83 |
#define DIRECTORY_SEP '/' |
|---|
| 84 |
#endif |
|---|
| 85 |
#ifndef IS_DIRECTORY_SEP |
|---|
| 86 |
#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP) |
|---|
| 87 |
#endif |
|---|
| 88 |
|
|---|
| 89 |
#ifdef WINDOWSNT |
|---|
| 90 |
#include "ntlib.h" |
|---|
| 91 |
#ifndef MEADOW |
|---|
| 92 |
#undef access |
|---|
| 93 |
#undef unlink |
|---|
| 94 |
#endif |
|---|
| 95 |
#define fork() 0 |
|---|
| 96 |
#define wait(var) (*(var) = 0) |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
#include <fcntl.h> |
|---|
| 109 |
#endif |
|---|
| 110 |
|
|---|
| 111 |
#ifndef F_OK |
|---|
| 112 |
#define F_OK 0 |
|---|
| 113 |
#define X_OK 1 |
|---|
| 114 |
#define W_OK 2 |
|---|
| 115 |
#define R_OK 4 |
|---|
| 116 |
#endif |
|---|
| 117 |
|
|---|
| 118 |
#if defined (XENIX) || defined (WINDOWSNT) |
|---|
| 119 |
#include <sys/locking.h> |
|---|
| 120 |
#endif |
|---|
| 121 |
|
|---|
| 122 |
#ifdef MAIL_USE_LOCKF |
|---|
| 123 |
#define MAIL_USE_SYSTEM_LOCK |
|---|
| 124 |
#endif |
|---|
| 125 |
|
|---|
| 126 |
#ifdef MAIL_USE_FLOCK |
|---|
| 127 |
#define MAIL_USE_SYSTEM_LOCK |
|---|
| 128 |
#endif |
|---|
| 129 |
|
|---|
| 130 |
#ifdef MAIL_USE_MMDF |
|---|
| 131 |
extern int lk_open (), lk_close (); |
|---|
| 132 |
#endif |
|---|
| 133 |
|
|---|
| 134 |
#if !defined (MAIL_USE_SYSTEM_LOCK) && !defined (MAIL_USE_MMDF) && \ |
|---|
| 135 |
(defined (HAVE_LIBMAIL) || defined (HAVE_LIBLOCKFILE)) && \ |
|---|
| 136 |
defined (HAVE_MAILLOCK_H) |
|---|
| 137 |
#include <maillock.h> |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
#ifdef MAILDIR |
|---|
| 141 |
#define MAIL_USE_MAILLOCK |
|---|
| 142 |
static char *mail_spool_name (); |
|---|
| 143 |
#endif |
|---|
| 144 |
#endif |
|---|
| 145 |
|
|---|
| 146 |
#ifndef errno |
|---|
| 147 |
extern int errno; |
|---|
| 148 |
#endif |
|---|
| 149 |
char *strerror (); |
|---|
| 150 |
#ifdef HAVE_INDEX |
|---|
| 151 |
extern char *index __P ((const char *, int)); |
|---|
| 152 |
#endif |
|---|
| 153 |
#ifdef HAVE_RINDEX |
|---|
| 154 |
extern char *rindex __P((const char *, int)); |
|---|
| 155 |
#endif |
|---|
| 156 |
|
|---|
| 157 |
void fatal (); |
|---|
| 158 |
void error (); |
|---|
| 159 |
void pfatal_with_name (); |
|---|
| 160 |
void pfatal_and_delete (); |
|---|
| 161 |
char *concat (); |
|---|
| 162 |
long *xmalloc (); |
|---|
| 163 |
int popmail (); |
|---|
| 164 |
int pop_retr (); |
|---|
| 165 |
int mbx_write (); |
|---|
| 166 |
int mbx_delimit_begin (); |
|---|
| 167 |
int mbx_delimit_end (); |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
char *delete_lockname; |
|---|
| 171 |
|
|---|
| 172 |
#ifdef MEADOW |
|---|
| 173 |
#define USE_POP_OPT |
|---|
| 174 |
#endif |
|---|
| 175 |
|
|---|
| 176 |
int |
|---|
| 177 |
main (argc, argv) |
|---|
| 178 |
int argc; |
|---|
| 179 |
char **argv; |
|---|
| 180 |
{ |
|---|
| 181 |
char *inname, *outname; |
|---|
| 182 |
int indesc, outdesc; |
|---|
| 183 |
int nread; |
|---|
| 184 |
WAITTYPE status; |
|---|
| 185 |
int c, preserve_mail = 0; |
|---|
| 186 |
|
|---|
| 187 |
#ifndef MAIL_USE_SYSTEM_LOCK |
|---|
| 188 |
struct stat st; |
|---|
| 189 |
long now; |
|---|
| 190 |
int tem; |
|---|
| 191 |
char *lockname, *p; |
|---|
| 192 |
char *tempname; |
|---|
| 193 |
int desc; |
|---|
| 194 |
#endif |
|---|
| 195 |
|
|---|
| 196 |
#ifdef MAIL_USE_MAILLOCK |
|---|
| 197 |
char *spool_name; |
|---|
| 198 |
#endif |
|---|
| 199 |
|
|---|
| 200 |
#ifdef MAIL_USE_POP |
|---|
| 201 |
int pop_reverse_order = 0; |
|---|
| 202 |
# define ARGSTR "pr" |
|---|
| 203 |
#else |
|---|
| 204 |
# define ARGSTR "p" |
|---|
| 205 |
#endif |
|---|
| 206 |
|
|---|
| 207 |
#ifdef WINDOWSNT |
|---|
| 208 |
|
|---|
| 209 |
_fmode = _O_BINARY; |
|---|
| 210 |
#endif |
|---|
| 211 |
|
|---|
| 212 |
delete_lockname = 0; |
|---|
| 213 |
|
|---|
| 214 |
while ((c = getopt (argc, argv, ARGSTR)) != EOF) |
|---|
| 215 |
{ |
|---|
| 216 |
switch (c) { |
|---|
| 217 |
#ifdef MAIL_USE_POP |
|---|
| 218 |
case 'r': |
|---|
| 219 |
pop_reverse_order = 1; |
|---|
| 220 |
break; |
|---|
| 221 |
#endif |
|---|
| 222 |
case 'p': |
|---|
| 223 |
preserve_mail++; |
|---|
| 224 |
break; |
|---|
| 225 |
default: |
|---|
| 226 |
exit (EXIT_FAILURE); |
|---|
| 227 |
} |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
if ( |
|---|
| 231 |
#ifdef MAIL_USE_POP |
|---|
| 232 |
(argc - optind < 2) || (argc - optind > 3) |
|---|
| 233 |
#else |
|---|
| 234 |
(argc - optind != 2) |
|---|
| 235 |
#endif |
|---|
| 236 |
) |
|---|
| 237 |
{ |
|---|
| 238 |
#ifdef MAIL_USE_POP |
|---|
| 239 |
fprintf (stderr, "Usage: movemail [-p] inbox destfile%s\n", |
|---|
| 240 |
" [POP-password]"); |
|---|
| 241 |
#else |
|---|
| 242 |
fprintf (stderr, "Usage: movemail [-p] inbox destfile%s\n", ""); |
|---|
| 243 |
#endif |
|---|
| 244 |
exit (EXIT_FAILURE); |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
inname = argv[optind]; |
|---|
| 248 |
outname = argv[optind+1]; |
|---|
| 249 |
|
|---|
| 250 |
#ifdef MAIL_USE_MMDF |
|---|
| 251 |
mmdf_init (argv[0]); |
|---|
| 252 |
#endif |
|---|
| 253 |
|
|---|
| 254 |
if (*outname == 0) |
|---|
| 255 |
fatal ("Destination file name is empty", 0, 0); |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0) |
|---|
| 259 |
pfatal_with_name (outname); |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
{ |
|---|
| 263 |
char *buf = (char *) xmalloc (strlen (outname) + 1); |
|---|
| 264 |
char *p; |
|---|
| 265 |
strcpy (buf, outname); |
|---|
| 266 |
p = buf + strlen (buf); |
|---|
| 267 |
while (p > buf && !IS_DIRECTORY_SEP (p[-1])) |
|---|
| 268 |
*--p = 0; |
|---|
| 269 |
if (p == buf) |
|---|
| 270 |
*p++ = '.'; |
|---|
| 271 |
if (access (buf, W_OK) != 0) |
|---|
| 272 |
pfatal_with_name (buf); |
|---|
| 273 |
free (buf); |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
#ifdef MAIL_USE_POP |
|---|
| 277 |
if (!strncmp (inname, "po:", 3)) |
|---|
| 278 |
{ |
|---|
| 279 |
int status; |
|---|
| 280 |
|
|---|
| 281 |
status = popmail (inname + 3, outname, preserve_mail, |
|---|
| 282 |
(argc - optind == 3) ? argv[optind+2] : NULL, |
|---|
| 283 |
pop_reverse_order); |
|---|
| 284 |
exit (status); |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
setuid (getuid ()); |
|---|
| 288 |
#endif |
|---|
| 289 |
|
|---|
| 290 |
#ifndef DISABLE_DIRECT_ACCESS |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
if (access (inname, R_OK | W_OK) != 0) |
|---|
| 294 |
pfatal_with_name (inname); |
|---|
| 295 |
|
|---|
| 296 |
#ifndef MAIL_USE_MMDF |
|---|
| 297 |
#ifndef MAIL_USE_SYSTEM_LOCK |
|---|
| 298 |
#ifdef MAIL_USE_MAILLOCK |
|---|
| 299 |
spool_name = mail_spool_name (inname); |
|---|
| 300 |
if (! spool_name) |
|---|
| 301 |
#endif |
|---|
| 302 |
{ |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
lockname = concat (inname, ".lock", ""); |
|---|
| 327 |
tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1); |
|---|
| 328 |
strcpy (tempname, inname); |
|---|
| 329 |
p = tempname + strlen (tempname); |
|---|
| 330 |
while (p != tempname && !IS_DIRECTORY_SEP (p[-1])) |
|---|
| 331 |
p--; |
|---|
| 332 |
*p = 0; |
|---|
| 333 |
strcpy (p, "EXXXXXX"); |
|---|
| 334 |
mktemp (tempname); |
|---|
| 335 |
unlink (tempname); |
|---|
| 336 |
|
|---|
| 337 |
while (1) |
|---|
| 338 |
{ |
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
|---|
| 342 |
if (desc < 0) |
|---|
| 343 |
{ |
|---|
| 344 |
char *message = (char *) xmalloc (strlen (tempname) + 50); |
|---|
| 345 |
sprintf (message, "creating %s, which would become the lock file", |
|---|
| 346 |
tempname); |
|---|
| 347 |
pfatal_with_name (message); |
|---|
| 348 |
} |
|---|
| 349 |
close (desc); |
|---|
| 350 |
|
|---|
| 351 |
tem = link (tempname, lockname); |
|---|
| 352 |
unlink (tempname); |
|---|
| 353 |
if (tem >= 0) |
|---|
| 354 |
break; |
|---|
| 355 |
sleep (1); |
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
if (stat (lockname, &st) >= 0) |
|---|
| 362 |
{ |
|---|
| 363 |
now = time (0); |
|---|
| 364 |
if (st.st_ctime < now - 300) |
|---|
| 365 |
unlink (lockname); |
|---|
| 366 |
} |
|---|
| 367 |
} |
|---|
| 368 |
|
|---|
| 369 |
delete_lockname = lockname; |
|---|
| 370 |
} |
|---|
| 371 |
#endif |
|---|
| 372 |
#endif |
|---|
| 373 |
|
|---|
| 374 |
if (fork () == 0) |
|---|
| 375 |
{ |
|---|
| 376 |
int lockcount = 0; |
|---|
| 377 |
int status = 0; |
|---|
| 378 |
#if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK) |
|---|
| 379 |
long touched_lock, now; |
|---|
| 380 |
#endif |
|---|
| 381 |
|
|---|
| 382 |
setuid (getuid ()); |
|---|
| 383 |
|
|---|
| 384 |
#ifndef MAIL_USE_MMDF |
|---|
| 385 |
#ifdef MAIL_USE_SYSTEM_LOCK |
|---|
| 386 |
indesc = open (inname, O_RDWR); |
|---|
| 387 |
#else |
|---|
| 388 |
indesc = open (inname, O_RDONLY); |
|---|
| 389 |
#endif |
|---|
| 390 |
#else |
|---|
| 391 |
indesc = lk_open (inname, O_RDONLY, 0, 0, 10); |
|---|
| 392 |
#endif |
|---|
| 393 |
|
|---|
| 394 |
if (indesc < 0) |
|---|
| 395 |
pfatal_with_name (inname); |
|---|
| 396 |
|
|---|
| 397 |
#if defined (BSD_SYSTEM) || defined (XENIX) |
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
umask (umask (0) & 0333); |
|---|
| 403 |
#endif |
|---|
| 404 |
outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
|---|
| 405 |
if (outdesc < 0) |
|---|
| 406 |
pfatal_with_name (outname); |
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
retry_lock: |
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
#ifdef MAIL_USE_MAILLOCK |
|---|
| 414 |
if (spool_name) |
|---|
| 415 |
{ |
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
status = 0 - maillock (spool_name, 1); |
|---|
| 419 |
#ifdef HAVE_TOUCHLOCK |
|---|
| 420 |
touched_lock = time (0); |
|---|
| 421 |
#endif |
|---|
| 422 |
lockcount = 5; |
|---|
| 423 |
} |
|---|
| 424 |
else |
|---|
| 425 |
#endif |
|---|
| 426 |
{ |
|---|
| 427 |
#ifdef MAIL_USE_SYSTEM_LOCK |
|---|
| 428 |
#ifdef MAIL_USE_LOCKF |
|---|
| 429 |
status = lockf (indesc, F_LOCK, 0); |
|---|
| 430 |
#else |
|---|
| 431 |
#ifdef XENIX |
|---|
| 432 |
status = locking (indesc, LK_RLCK, 0L); |
|---|
| 433 |
#else |
|---|
| 434 |
#ifdef WINDOWSNT |
|---|
| 435 |
status = locking (indesc, LK_RLCK, -1L); |
|---|
| 436 |
#else |
|---|
| 437 |
status = flock (indesc, LOCK_EX); |
|---|
| 438 |
#endif |
|---|
| 439 |
#endif |
|---|
| 440 |
#endif |
|---|
| 441 |
#endif |
|---|
| 442 |
} |
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
if (status < 0) |
|---|
| 447 |
{ |
|---|
| 448 |
if (++lockcount <= 5) |
|---|
| 449 |
{ |
|---|
| 450 |
#ifdef EAGAIN |
|---|
| 451 |
if (errno == EAGAIN) |
|---|
| 452 |
{ |
|---|
| 453 |
sleep (1); |
|---|
| 454 |
goto retry_lock; |
|---|
| 455 |
} |
|---|
| 456 |
#endif |
|---|
| 457 |
#ifdef EBUSY |
|---|
| 458 |
if (errno == EBUSY) |
|---|
| 459 |
{ |
|---|
| 460 |
sleep (1); |
|---|
| 461 |
goto retry_lock; |
|---|
| 462 |
} |
|---|
| 463 |
#endif |
|---|
| 464 |
} |
|---|
| 465 |
|
|---|
| 466 |
pfatal_with_name (inname); |
|---|
| 467 |
} |
|---|
| 468 |
|
|---|
| 469 |
{ |
|---|
| 470 |
char buf[1024]; |
|---|
| 471 |
|
|---|
| 472 |
while (1) |
|---|
| 473 |
{ |
|---|
| 474 |
nread = read (indesc, buf, sizeof buf); |
|---|
| 475 |
if (nread < 0) |
|---|
| 476 |
pfatal_with_name (inname); |
|---|
| 477 |
if (nread != write (outdesc, buf, nread)) |
|---|
| 478 |
{ |
|---|
| 479 |
int saved_errno = errno; |
|---|
| 480 |
unlink (outname); |
|---|
| 481 |
errno = saved_errno; |
|---|
| 482 |
pfatal_with_name (outname); |
|---|
| 483 |
} |
|---|
| 484 |
if (nread < sizeof buf) |
|---|
| 485 |
break; |
|---|
| 486 |
#if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK) |
|---|
| 487 |
if (spool_name) |
|---|
| 488 |
{ |
|---|
| 489 |
now = time (0); |
|---|
| 490 |
if (now - touched_lock > 60) |
|---|
| 491 |
{ |
|---|
| 492 |
touchlock (); |
|---|
| 493 |
touched_lock = now; |
|---|
| 494 |
} |
|---|
| 495 |
} |
|---|
| 496 |
#endif |
|---|
| 497 |
} |
|---|
| 498 |
} |
|---|
| 499 |
|
|---|
| 500 |
#ifdef BSD_SYSTEM |
|---|
| 501 |
if (fsync (outdesc) < 0) |
|---|
| 502 |
pfatal_and_delete (outname); |
|---|
| 503 |
#endif |
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
if (close (outdesc) != 0) |
|---|
| 507 |
pfatal_and_delete (outname); |
|---|
| 508 |
|
|---|
| 509 |
#ifdef MAIL_USE_SYSTEM_LOCK |
|---|
| 510 |
if (! preserve_mail) |
|---|
| 511 |
{ |
|---|
| 512 |
#if defined (STRIDE) || defined (XENIX) |
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); |
|---|
| 516 |
#else |
|---|
| 517 |
ftruncate (indesc, 0L); |
|---|
| 518 |
#endif |
|---|
| 519 |
} |
|---|
| 520 |
#endif |
|---|
| 521 |
|
|---|
| 522 |
#ifdef MAIL_USE_MMDF |
|---|
| 523 |
lk_close (indesc, 0, 0, 0); |
|---|
| 524 |
#else |
|---|
| 525 |
close (indesc); |
|---|
| 526 |
#endif |
|---|
| 527 |
|
|---|
| 528 |
#ifndef MAIL_USE_SYSTEM_LOCK |
|---|
| 529 |
if (! preserve_mail) |
|---|
| 530 |
{ |
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
#ifdef MAIL_UNLINK_SPOOL |
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
if (unlink (inname) < 0 && errno != ENOENT) |
|---|
| 537 |
#endif |
|---|
| 538 |
creat (inname, 0600); |
|---|
| 539 |
} |
|---|
| 540 |
#endif |
|---|
| 541 |
|
|---|
| 542 |
#ifdef MAIL_USE_MAILLOCK |
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 |
if (spool_name) |
|---|
| 546 |
mailunlock (); |
|---|
| 547 |
#endif |
|---|
| 548 |
exit (EXIT_SUCCESS); |
|---|
| 549 |
} |
|---|
| 550 |
|
|---|
| 551 |
wait (&status); |
|---|
| 552 |
if (!WIFEXITED (status)) |
|---|
| 553 |
exit (EXIT_FAILURE); |
|---|
| 554 |
else if (WRETCODE (status) != 0) |
|---|
| 555 |
exit (WRETCODE (status)); |
|---|
| 556 |
|
|---|
| 557 |
#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK) |
|---|
| 558 |
#ifdef MAIL_USE_MAILLOCK |
|---|
| 559 |
if (! spool_name) |
|---|
| 560 |
#endif |
|---|
| 561 |
unlink (lockname); |
|---|
| 562 |
#endif |
|---|
| 563 |
|
|---|
| 564 |
#endif |
|---|
| 565 |
|
|---|
| 566 |
return EXIT_SUCCESS; |
|---|
| 567 |
} |
|---|
| 568 |
|
|---|
| 569 |
#ifdef MAIL_USE_MAILLOCK |
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
static char * |
|---|
| 575 |
mail_spool_name (inname) |
|---|
| 576 |
char *inname; |
|---|
| 577 |
{ |
|---|
| 578 |
struct stat stat1, stat2; |
|---|
| 579 |
char *indir, *fname; |
|---|
| 580 |
int status; |
|---|
| 581 |
|
|---|
| 582 |
if (! (fname = rindex (inname, '/'))) |
|---|
| 583 |
return NULL; |
|---|
| 584 |
|
|---|
| 585 |
fname++; |
|---|
| 586 |
|
|---|
| 587 |
if (stat (MAILDIR, &stat1) < 0) |
|---|
| 588 |
return NULL; |
|---|
| 589 |
|
|---|
| 590 |
indir = (char *) xmalloc (fname - inname + 1); |
|---|
| 591 |
strncpy (indir, inname, fname - inname); |
|---|
| 592 |
indir[fname-inname] = '\0'; |
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
status = stat (indir, &stat2); |
|---|
| 596 |
|
|---|
| 597 |
free (indir); |
|---|
| 598 |
|
|---|
| 599 |
if (status < 0) |
|---|
| 600 |
return NULL; |
|---|
| 601 |
|
|---|
| 602 |
if (stat1.st_dev == stat2.st_dev |
|---|
| 603 |
&& stat1.st_ino == stat2.st_ino) |
|---|
| 604 |
return fname; |
|---|
| 605 |
|
|---|
| 606 |
return NULL; |
|---|
| 607 |
} |
|---|
| 608 |
#endif |
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
void |
|---|
| 613 |
fatal (s1, s2, s3) |
|---|
| 614 |
char *s1, *s2, *s3; |
|---|
| 615 |
{ |
|---|
| 616 |
if (delete_lockname) |
|---|
| 617 |
unlink (delete_lockname); |
|---|
| 618 |
error (s1, s2, s3); |
|---|
| 619 |
exit (EXIT_FAILURE); |
|---|
| 620 |
} |
|---|
| 621 |
|
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
|
|---|
| 625 |
void |
|---|
| 626 |
error (s1, s2, s3) |
|---|
| 627 |
char *s1, *s2, *s3; |
|---|
| 628 |
{ |
|---|
| 629 |
fprintf (stderr, "movemail: "); |
|---|
| 630 |
if (s3) |
|---|
| 631 |
fprintf (stderr, s1, s2, s3); |
|---|
| 632 |
else if (s2) |
|---|
| 633 |
fprintf (stderr, s1, s2); |
|---|
| 634 |
else |
|---|
| 635 |
fprintf (stderr, s1); |
|---|
| 636 |
fprintf (stderr, "\n"); |
|---|
| 637 |
} |
|---|
| 638 |
|
|---|
| 639 |
void |
|---|
| 640 |
pfatal_with_name (name) |
|---|
| 641 |
char *name; |
|---|
| 642 |
{ |
|---|
| 643 |
fatal ("%s for %s", strerror (errno), name); |
|---|
| 644 |
} |
|---|
| 645 |
|
|---|
| 646 |
void |
|---|
| 647 |
pfatal_and_delete (name) |
|---|
| 648 |
char *name; |
|---|
| 649 |
{ |
|---|
| 650 |
char *s = strerror (errno); |
|---|
| 651 |
unlink (name); |
|---|
| 652 |
fatal ("%s for %s", s, name); |
|---|
| 653 |
} |
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
char * |
|---|
| 658 |
concat (s1, s2, s3) |
|---|
| 659 |
char *s1, *s2, *s3; |
|---|
| 660 |
{ |
|---|
| 661 |
int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); |
|---|
| 662 |
char *result = (char *) xmalloc (len1 + len2 + len3 + 1); |
|---|
| 663 |
|
|---|
| 664 |
strcpy (result, s1); |
|---|
| 665 |
strcpy (result + len1, s2); |
|---|
| 666 |
strcpy (result + len1 + len2, s3); |
|---|
| 667 |
*(result + len1 + len2 + len3) = 0; |
<
|---|