Commit 7f75d5c6 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(access, unlink) [WINDOWSNT]: Macros undefined.

(fork, syswait, DISABLE_DIRECT_ACCESS) [WINDOWSNT]: Macros defined.
[WINDOWSNT]: Include locking.h.
(main): Update usage message.  Use IS_DIRECTORY_SEP.
(main) [DISABLE_DIRECT_ACCESS]: Don't check access if defined.
(main) [WINDOWSNT]: Invoke locking instead of flock.
(main) [MAIL_USE_SYSTEM_LOCK && WINDOWSNT]: Emulate ftruncate.
(main) [MAIL_USE_POP]: Pass password to popmail if used.
Include winsock.h; don't include unix inet headers.
(popmail): Add password argument and pass it to pop_open.
Open output file in binary mode.
parent eac1956a
/* movemail foo bar -- move file foo to file bar, /* movemail foo bar -- move file foo to file bar,
locking file foo the way /bin/mail respects. locking file foo the way /bin/mail respects.
Copyright (C) 1986, 1992, 1993, 1994 Free Software Foundation, Inc. Copyright (C) 1986, 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of GNU Emacs. This file is part of GNU Emacs.
...@@ -70,6 +70,19 @@ Boston, MA 02111-1307, USA. */ ...@@ -70,6 +70,19 @@ Boston, MA 02111-1307, USA. */
#undef access #undef access
#endif /* MSDOS */ #endif /* MSDOS */
#ifdef WINDOWSNT
#undef access
#undef unlink
#define fork() 0
#define sys_wait(var) (*(var) = 0)
/* Unfortunately, Samba doesn't seem to properly lock Unix files even
though the locking call succeeds (and indeed blocks local access from
other NT programs). If you have direct file access using an NFS
client or something other than Samba, the locking call might work
properly - make sure it does before you enable this! */
#define DISABLE_DIRECT_ACCESS
#endif /* WINDOWSNT */
#ifdef USG #ifdef USG
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
...@@ -85,7 +98,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -85,7 +98,7 @@ Boston, MA 02111-1307, USA. */
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef XENIX #if defined (XENIX) || defined (WINDOWSNT)
#include <sys/locking.h> #include <sys/locking.h>
#endif #endif
...@@ -150,7 +163,7 @@ main (argc, argv) ...@@ -150,7 +163,7 @@ main (argc, argv)
if (argc < 3) if (argc < 3)
{ {
fprintf (stderr, "Usage: movemail inbox destfile\n"); fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n");
exit(1); exit(1);
} }
...@@ -174,7 +187,7 @@ main (argc, argv) ...@@ -174,7 +187,7 @@ main (argc, argv)
char *p; char *p;
strcpy (buf, outname); strcpy (buf, outname);
p = buf + strlen (buf); p = buf + strlen (buf);
while (p > buf && p[-1] != '/') while (p > buf && !IS_DIRECTORY_SEP (p[-1]))
*--p = 0; *--p = 0;
if (p == buf) if (p == buf)
*p++ = '.'; *p++ = '.';
...@@ -188,13 +201,15 @@ main (argc, argv) ...@@ -188,13 +201,15 @@ main (argc, argv)
{ {
int status; int status;
status = popmail (inname + 3, outname); status = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL);
exit (status); exit (status);
} }
setuid (getuid ()); setuid (getuid ());
#endif /* MAIL_USE_POP */ #endif /* MAIL_USE_POP */
#ifndef DISABLE_DIRECT_ACCESS
/* Check access to input file. */ /* Check access to input file. */
if (access (inname, R_OK | W_OK) != 0) if (access (inname, R_OK | W_OK) != 0)
pfatal_with_name (inname); pfatal_with_name (inname);
...@@ -228,7 +243,7 @@ main (argc, argv) ...@@ -228,7 +243,7 @@ main (argc, argv)
tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1); tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
strcpy (tempname, inname); strcpy (tempname, inname);
p = tempname + strlen (tempname); p = tempname + strlen (tempname);
while (p != tempname && p[-1] != '/') while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
p--; p--;
*p = 0; *p = 0;
strcpy (p, "EXXXXXX"); strcpy (p, "EXXXXXX");
...@@ -304,9 +319,13 @@ main (argc, argv) ...@@ -304,9 +319,13 @@ main (argc, argv)
#else /* not MAIL_USE_LOCKF */ #else /* not MAIL_USE_LOCKF */
#ifdef XENIX #ifdef XENIX
if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname); if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname);
#else
#ifdef WINDOWSNT
if (locking (indesc, LK_RLCK, -1L) < 0) pfatal_with_name (inname);
#else #else
if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname); if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
#endif #endif
#endif
#endif /* not MAIL_USE_LOCKF */ #endif /* not MAIL_USE_LOCKF */
#endif /* MAIL_USE_SYSTEM_LOCK */ #endif /* MAIL_USE_SYSTEM_LOCK */
...@@ -338,7 +357,7 @@ main (argc, argv) ...@@ -338,7 +357,7 @@ main (argc, argv)
pfatal_and_delete (outname); pfatal_and_delete (outname);
#ifdef MAIL_USE_SYSTEM_LOCK #ifdef MAIL_USE_SYSTEM_LOCK
#if defined (STRIDE) || defined (XENIX) #if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT)
/* Stride, xenix have file locking, but no ftruncate. This mess will do. */ /* Stride, xenix have file locking, but no ftruncate. This mess will do. */
close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
#else #else
...@@ -375,6 +394,9 @@ main (argc, argv) ...@@ -375,6 +394,9 @@ main (argc, argv)
#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK) #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
unlink (lockname); unlink (lockname);
#endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */ #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */
#endif /* ! DISABLE_DIRECT_ACCESS */
return 0; return 0;
} }
...@@ -451,9 +473,14 @@ xmalloc (size) ...@@ -451,9 +473,14 @@ xmalloc (size)
#ifdef MAIL_USE_POP #ifdef MAIL_USE_POP
#ifndef WINDOWSNT
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#else
#undef _WINSOCKAPI_
#include <winsock.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <pwd.h> #include <pwd.h>
...@@ -477,9 +504,10 @@ char ibuffer[BUFSIZ]; ...@@ -477,9 +504,10 @@ char ibuffer[BUFSIZ];
char obuffer[BUFSIZ]; char obuffer[BUFSIZ];
char Errmsg[80]; char Errmsg[80];
popmail (user, outfile) popmail (user, outfile, password)
char *user; char *user;
char *outfile; char *outfile;
char *password;
{ {
int nmsgs, nbytes; int nmsgs, nbytes;
register int i; register int i;
...@@ -490,7 +518,7 @@ popmail (user, outfile) ...@@ -490,7 +518,7 @@ popmail (user, outfile)
popserver server; popserver server;
extern char *strerror (); extern char *strerror ();
server = pop_open (0, user, 0, POP_NO_GETPASS); server = pop_open (0, user, password, POP_NO_GETPASS);
if (! server) if (! server)
{ {
error (pop_error); error (pop_error);
...@@ -518,7 +546,7 @@ popmail (user, outfile) ...@@ -518,7 +546,7 @@ popmail (user, outfile)
} }
fchown (mbfi, getuid (), -1); fchown (mbfi, getuid (), -1);
if ((mbf = fdopen (mbfi, "w")) == NULL) if ((mbf = fdopen (mbfi, "wb")) == NULL)
{ {
pop_close (server); pop_close (server);
error ("Error in fdopen: %s", strerror (errno)); error ("Error in fdopen: %s", strerror (errno));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment