aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorRichard M. Stallman1996-04-28 19:07:35 +0000
committerRichard M. Stallman1996-04-28 19:07:35 +0000
commit7f75d5c619a6498b8d92816f1c1e5852e147a5fb (patch)
treec3b1a1543e67db5421c5abe38f0f1bf2d840971d /lib-src
parenteac1956a777e8e94d17119f086f7848bc7df2b86 (diff)
downloademacs-7f75d5c619a6498b8d92816f1c1e5852e147a5fb.tar.gz
emacs-7f75d5c619a6498b8d92816f1c1e5852e147a5fb.zip
(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.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/movemail.c48
1 files changed, 38 insertions, 10 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index 4ac1343fa9b..295b006911b 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -1,6 +1,6 @@
1/* movemail foo bar -- move file foo to file bar, 1/* movemail foo bar -- move file foo to file bar,
2 locking file foo the way /bin/mail respects. 2 locking file foo the way /bin/mail respects.
3 Copyright (C) 1986, 1992, 1993, 1994 Free Software Foundation, Inc. 3 Copyright (C) 1986, 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
@@ -70,6 +70,19 @@ Boston, MA 02111-1307, USA. */
70#undef access 70#undef access
71#endif /* MSDOS */ 71#endif /* MSDOS */
72 72
73#ifdef WINDOWSNT
74#undef access
75#undef unlink
76#define fork() 0
77#define sys_wait(var) (*(var) = 0)
78/* Unfortunately, Samba doesn't seem to properly lock Unix files even
79 though the locking call succeeds (and indeed blocks local access from
80 other NT programs). If you have direct file access using an NFS
81 client or something other than Samba, the locking call might work
82 properly - make sure it does before you enable this! */
83#define DISABLE_DIRECT_ACCESS
84#endif /* WINDOWSNT */
85
73#ifdef USG 86#ifdef USG
74#include <fcntl.h> 87#include <fcntl.h>
75#include <unistd.h> 88#include <unistd.h>
@@ -85,7 +98,7 @@ Boston, MA 02111-1307, USA. */
85#include <unistd.h> 98#include <unistd.h>
86#endif 99#endif
87 100
88#ifdef XENIX 101#if defined (XENIX) || defined (WINDOWSNT)
89#include <sys/locking.h> 102#include <sys/locking.h>
90#endif 103#endif
91 104
@@ -150,7 +163,7 @@ main (argc, argv)
150 163
151 if (argc < 3) 164 if (argc < 3)
152 { 165 {
153 fprintf (stderr, "Usage: movemail inbox destfile\n"); 166 fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n");
154 exit(1); 167 exit(1);
155 } 168 }
156 169
@@ -174,7 +187,7 @@ main (argc, argv)
174 char *p; 187 char *p;
175 strcpy (buf, outname); 188 strcpy (buf, outname);
176 p = buf + strlen (buf); 189 p = buf + strlen (buf);
177 while (p > buf && p[-1] != '/') 190 while (p > buf && !IS_DIRECTORY_SEP (p[-1]))
178 *--p = 0; 191 *--p = 0;
179 if (p == buf) 192 if (p == buf)
180 *p++ = '.'; 193 *p++ = '.';
@@ -188,13 +201,15 @@ main (argc, argv)
188 { 201 {
189 int status; 202 int status;
190 203
191 status = popmail (inname + 3, outname); 204 status = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL);
192 exit (status); 205 exit (status);
193 } 206 }
194 207
195 setuid (getuid ()); 208 setuid (getuid ());
196#endif /* MAIL_USE_POP */ 209#endif /* MAIL_USE_POP */
197 210
211#ifndef DISABLE_DIRECT_ACCESS
212
198 /* Check access to input file. */ 213 /* Check access to input file. */
199 if (access (inname, R_OK | W_OK) != 0) 214 if (access (inname, R_OK | W_OK) != 0)
200 pfatal_with_name (inname); 215 pfatal_with_name (inname);
@@ -228,7 +243,7 @@ main (argc, argv)
228 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1); 243 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
229 strcpy (tempname, inname); 244 strcpy (tempname, inname);
230 p = tempname + strlen (tempname); 245 p = tempname + strlen (tempname);
231 while (p != tempname && p[-1] != '/') 246 while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
232 p--; 247 p--;
233 *p = 0; 248 *p = 0;
234 strcpy (p, "EXXXXXX"); 249 strcpy (p, "EXXXXXX");
@@ -305,8 +320,12 @@ main (argc, argv)
305#ifdef XENIX 320#ifdef XENIX
306 if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname); 321 if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname);
307#else 322#else
323#ifdef WINDOWSNT
324 if (locking (indesc, LK_RLCK, -1L) < 0) pfatal_with_name (inname);
325#else
308 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname); 326 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
309#endif 327#endif
328#endif
310#endif /* not MAIL_USE_LOCKF */ 329#endif /* not MAIL_USE_LOCKF */
311#endif /* MAIL_USE_SYSTEM_LOCK */ 330#endif /* MAIL_USE_SYSTEM_LOCK */
312 331
@@ -338,7 +357,7 @@ main (argc, argv)
338 pfatal_and_delete (outname); 357 pfatal_and_delete (outname);
339 358
340#ifdef MAIL_USE_SYSTEM_LOCK 359#ifdef MAIL_USE_SYSTEM_LOCK
341#if defined (STRIDE) || defined (XENIX) 360#if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT)
342 /* Stride, xenix have file locking, but no ftruncate. This mess will do. */ 361 /* Stride, xenix have file locking, but no ftruncate. This mess will do. */
343 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); 362 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
344#else 363#else
@@ -375,6 +394,9 @@ main (argc, argv)
375#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK) 394#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
376 unlink (lockname); 395 unlink (lockname);
377#endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */ 396#endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */
397
398#endif /* ! DISABLE_DIRECT_ACCESS */
399
378 return 0; 400 return 0;
379} 401}
380 402
@@ -451,9 +473,14 @@ xmalloc (size)
451 473
452#ifdef MAIL_USE_POP 474#ifdef MAIL_USE_POP
453 475
476#ifndef WINDOWSNT
454#include <sys/socket.h> 477#include <sys/socket.h>
455#include <netinet/in.h> 478#include <netinet/in.h>
456#include <netdb.h> 479#include <netdb.h>
480#else
481#undef _WINSOCKAPI_
482#include <winsock.h>
483#endif
457#include <stdio.h> 484#include <stdio.h>
458#include <pwd.h> 485#include <pwd.h>
459 486
@@ -477,9 +504,10 @@ char ibuffer[BUFSIZ];
477char obuffer[BUFSIZ]; 504char obuffer[BUFSIZ];
478char Errmsg[80]; 505char Errmsg[80];
479 506
480popmail (user, outfile) 507popmail (user, outfile, password)
481 char *user; 508 char *user;
482 char *outfile; 509 char *outfile;
510 char *password;
483{ 511{
484 int nmsgs, nbytes; 512 int nmsgs, nbytes;
485 register int i; 513 register int i;
@@ -490,7 +518,7 @@ popmail (user, outfile)
490 popserver server; 518 popserver server;
491 extern char *strerror (); 519 extern char *strerror ();
492 520
493 server = pop_open (0, user, 0, POP_NO_GETPASS); 521 server = pop_open (0, user, password, POP_NO_GETPASS);
494 if (! server) 522 if (! server)
495 { 523 {
496 error (pop_error); 524 error (pop_error);
@@ -518,7 +546,7 @@ popmail (user, outfile)
518 } 546 }
519 fchown (mbfi, getuid (), -1); 547 fchown (mbfi, getuid (), -1);
520 548
521 if ((mbf = fdopen (mbfi, "w")) == NULL) 549 if ((mbf = fdopen (mbfi, "wb")) == NULL)
522 { 550 {
523 pop_close (server); 551 pop_close (server);
524 error ("Error in fdopen: %s", strerror (errno)); 552 error ("Error in fdopen: %s", strerror (errno));