Annotation of coherent/g/usr/lib/uucp/tay104/unix/recep.c, revision 1.1.1.1

1.1       root        1: /* recep.c
                      2:    See whether a file has already been received.
                      3: 
                      4:    Copyright (C) 1992 Ian Lance Taylor
                      5: 
                      6:    This file is part of the Taylor UUCP package.
                      7: 
                      8:    This program is free software; you can redistribute it and/or
                      9:    modify it under the terms of the GNU General Public License as
                     10:    published by the Free Software Foundation; either version 2 of the
                     11:    License, or (at your option) any later version.
                     12: 
                     13:    This program is distributed in the hope that it will be useful, but
                     14:    WITHOUT ANY WARRANTY; without even the implied warranty of
                     15:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     16:    General Public License for more details.
                     17: 
                     18:    You should have received a copy of the GNU General Public License
                     19:    along with this program; if not, write to the Free Software
                     20:    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     21: 
                     22:    The author of the program may be contacted at [email protected] or
                     23:    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
                     24:    */
                     25: 
                     26: #include "uucp.h"
                     27: 
                     28: #include "uudefs.h"
                     29: #include "uuconf.h"
                     30: #include "sysdep.h"
                     31: #include "system.h"
                     32: 
                     33: #include <errno.h>
                     34: 
                     35: #if HAVE_TIME_H
                     36: #include <time.h>
                     37: #endif
                     38: 
                     39: #if HAVE_FCNTL_H
                     40: #include <fcntl.h>
                     41: #else
                     42: #if HAVE_SYS_FILE_H
                     43: #include <sys/file.h>
                     44: #endif
                     45: #endif
                     46: 
                     47: static char *zsreceived_name P((const struct uuconf_system *qsys,
                     48:                                const char *ztemp));
                     49: 
                     50: /* These routines are used to see whether we have already received a
                     51:    file in a previous UUCP connection.  It is possible for the
                     52:    acknowledgement of a received file to be lost.  The sending system
                     53:    will then now know that the file was correctly received, and will
                     54:    send it again.  This can be a problem particularly with protocols
                     55:    which support channels, since they may send several small files in
                     56:    a single window, all of which may be received correctly although
                     57:    the sending system never sees the acknowledgement.  If these files
                     58:    involve an execution, the execution will happen twice, which will
                     59:    be bad.
                     60: 
                     61:    We use a simple system.  For each file we want to remember, we
                     62:    create an empty file names .Received/SYS/TEMP, where SYS is the
                     63:    name of the system and TEMP is the name of the temporary file used
                     64:    by the sender.  If no temporary file is used by the sender, we
                     65:    don't remember that we received the file.  This is not perfect, but
                     66:    execution files will always have a temporary file, so the most
                     67:    important case is handled.  Also, any file received from Taylor
                     68:    UUCP 1.04 or greater will always have a temporary file.  */
                     69: 
                     70: /* Return the name we are going use for the marker, or NULL if we have
                     71:    no name.  */
                     72: 
                     73: static char *
                     74: zsreceived_name (qsys, ztemp)
                     75:      const struct uuconf_system *qsys;
                     76:      const char *ztemp;
                     77: {
                     78:   if (ztemp != NULL
                     79:       && *ztemp == 'D'
                     80:       && strcmp (ztemp, "D.0") != 0)
                     81:     return zsappend3 (".Received", qsys->uuconf_zname, ztemp);
                     82:   else
                     83:     return NULL;
                     84: }
                     85: 
                     86: /* Remember that we have already received a file.  */
                     87: 
                     88: /*ARGSUSED*/
                     89: boolean
                     90: fsysdep_remember_reception (qsys, zto, ztemp)
                     91:      const struct uuconf_system *qsys;
                     92:      const char *zto;
                     93:      const char *ztemp;
                     94: {
                     95:   char *zfile;
                     96:   int o;
                     97: 
                     98:   zfile = zsreceived_name (qsys, ztemp);
                     99:   if (zfile == NULL)
                    100:     return TRUE;
                    101:   o = creat (zfile, IPUBLIC_FILE_MODE);
                    102:   if (o < 0)
                    103:     {
                    104:       if (errno == ENOENT)
                    105:        {
                    106:          if (fsysdep_make_dirs (zfile, TRUE))
                    107:            {
                    108:              ubuffree (zfile);
                    109:              return FALSE;
                    110:            }
                    111:          o = creat (zfile, IPUBLIC_FILE_MODE);
                    112:        }
                    113:       if (o < 0)
                    114:        {
                    115:          ulog (LOG_ERROR, "creat (%s): %s", zfile, strerror (errno));
                    116:          ubuffree (zfile);
                    117:          return FALSE;
                    118:        }
                    119:     }
                    120: 
                    121:   ubuffree (zfile);
                    122: 
                    123:   /* We don't have to actually put anything in the file; we just use
                    124:      the name.  This is more convenient than keeping a file with a
                    125:      list of names.  */
                    126:   if (close (o) < 0)
                    127:     {
                    128:       ulog (LOG_ERROR, "fsysdep_remember_reception: close: %s",
                    129:            strerror (errno));
                    130:       return FALSE;
                    131:     }
                    132: 
                    133:   return TRUE;
                    134: }
                    135: 
                    136: /* See if we have already received a file.  Note that don't delete the
                    137:    marker file here, because we need to know that the sending system
                    138:    has received our denial first.  This function returns TRUE if the
                    139:    file has already been received, FALSE if it has not.  */
                    140: 
                    141: /*ARGSUSED*/
                    142: boolean
                    143: fsysdep_already_received (qsys, zto, ztemp)
                    144:      const struct uuconf_system *qsys;
                    145:      const char *zto;
                    146:      const char *ztemp;
                    147: {
                    148:   char *zfile;
                    149:   struct stat s;
                    150:   boolean fret;
                    151: 
                    152:   zfile = zsreceived_name (qsys, ztemp);
                    153:   if (zfile == NULL)
                    154:     return FALSE;
                    155:   if (stat (zfile, &s) < 0)
                    156:     {
                    157:       if (errno != ENOENT)
                    158:        ulog (LOG_ERROR, "stat (%s): %s", zfile, strerror (errno));
                    159:       ubuffree (zfile);
                    160:       return FALSE;
                    161:     }
                    162: 
                    163:   /* Ignore the file (return FALSE) if it is over one week old.  */
                    164:   fret = s.st_mtime + 7 * 24 * 60 * 60 >= time ((time_t *) NULL);
                    165: 
                    166:   if (fret)
                    167:     DEBUG_MESSAGE1 (DEBUG_SPOOLDIR, "fsysdep_already_received: Found %s",
                    168:                    zfile);
                    169: 
                    170:   ubuffree (zfile);
                    171: 
                    172:   return fret;
                    173: }
                    174: 
                    175: /* Forget that we have received a file.  */
                    176: 
                    177: /*ARGSUSED*/
                    178: boolean
                    179: fsysdep_forget_reception (qsys, zto, ztemp)
                    180:      const struct uuconf_system *qsys;
                    181:      const char *zto;
                    182:      const char *ztemp;
                    183: {
                    184:   char *zfile;
                    185: 
                    186:   zfile = zsreceived_name (qsys, ztemp);
                    187:   if (zfile == NULL)
                    188:     return TRUE;
                    189:   if (remove (zfile) < 0
                    190:       && errno != ENOENT)
                    191:     {
                    192:       ulog (LOG_ERROR, "remove (%s): %s", zfile, strerror (errno));
                    193:       ubuffree (zfile);
                    194:       return FALSE;
                    195:     }
                    196:   return TRUE;
                    197: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.