~ubuntu-branches/ubuntu/trusty/uucp/trusty

« back to all changes in this revision

Viewing changes to rec.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Palfrader
  • Date: 2004-12-30 15:30:22 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041230153022-mx4cdr9j3u9bldo3
Tags: 1.07-12
Add cs localisation for debconf templates (closes: #287305).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* rec.c
2
2
   Routines to receive a file.
3
3
 
4
 
   Copyright (C) 1991, 1992, 1993, 1994, 1995 Ian Lance Taylor
 
4
   Copyright (C) 1991, 1992, 1993, 1994, 1995, 2002 Ian Lance Taylor
5
5
 
6
6
   This file is part of the Taylor UUCP package.
7
7
 
17
17
 
18
18
   You should have received a copy of the GNU General Public License
19
19
   along with this program; if not, write to the Free Software
20
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
21
21
 
22
 
   The author of the program may be contacted at ian@airs.com or
23
 
   c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
 
22
   The author of the program may be contacted at ian@airs.com.
24
23
   */
25
24
 
26
25
#include "uucp.h"
27
26
 
28
27
#if USE_RCS_ID
29
 
const char rec_rcsid[] = "$Id: rec.c,v 1.43 1995/08/02 01:21:12 ian Rel $";
 
28
const char rec_rcsid[] = "$Id: rec.c,v 1.48 2002/03/05 19:10:41 ian Rel $";
30
29
#endif
31
30
 
32
31
#include <errno.h>
304
303
{
305
304
  struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
306
305
  long cbytes, cbytes2;
 
306
  boolean fquote;
 
307
  const struct scmd *qcmd;
 
308
  struct scmd squoted;
307
309
  size_t clen;
308
310
  char *zsend;
309
311
  boolean fret;
342
344
      && (cbytes == -1 || qdaemon->clocal_size < cbytes))
343
345
    cbytes = qdaemon->clocal_size;
344
346
 
 
347
  fquote = fcmd_needs_quotes (&qtrans->s);
 
348
  if (! fquote)
 
349
    qcmd = &qtrans->s;
 
350
  else
 
351
    {
 
352
      if ((qdaemon->ifeatures & FEATURE_QUOTES) == 0)
 
353
        return flocal_rec_fail (qtrans, &qtrans->s, qdaemon->qsys,
 
354
                                "remote system does not support required quoting");
 
355
      uquote_cmd (&qtrans->s, &squoted);
 
356
      qcmd = &squoted;
 
357
    }
 
358
 
345
359
  /* We send the string
346
360
     R from to user options
347
361
 
348
362
     We put a dash in front of options.  If we are talking to a
349
363
     counterpart, we also send the maximum size file we are prepared
350
364
     to accept, as returned by esysdep_open_receive.  */
351
 
  clen = (strlen (qtrans->s.zfrom) + strlen (qtrans->s.zto)
352
 
          + strlen (qtrans->s.zuser) + strlen (qtrans->s.zoptions) + 30);
 
365
  clen = (strlen (qcmd->zfrom) + strlen (qcmd->zto)
 
366
          + strlen (qcmd->zuser) + strlen (qcmd->zoptions) + 30);
353
367
  zsend = zbufalc (clen);
354
368
  if ((qdaemon->ifeatures & FEATURE_SIZES) == 0)
355
 
    sprintf (zsend, "R %s %s %s -%s", qtrans->s.zfrom, qtrans->s.zto,
356
 
             qtrans->s.zuser, qtrans->s.zoptions);
 
369
    sprintf (zsend, "R %s %s %s -%s", qcmd->zfrom, qcmd->zto,
 
370
             qcmd->zuser, qcmd->zoptions);
357
371
  else if ((qdaemon->ifeatures & FEATURE_V103) == 0)
358
 
    sprintf (zsend, "R %s %s %s -%s 0x%lx", qtrans->s.zfrom, qtrans->s.zto,
359
 
             qtrans->s.zuser, qtrans->s.zoptions, (unsigned long) cbytes);
 
372
    sprintf (zsend, "R %s %s %s -%s 0x%lx", qcmd->zfrom, qcmd->zto,
 
373
             qcmd->zuser, qcmd->zoptions, (unsigned long) cbytes);
360
374
  else
361
 
    sprintf (zsend, "R %s %s %s -%s %ld", qtrans->s.zfrom, qtrans->s.zto,
362
 
             qtrans->s.zuser, qtrans->s.zoptions, cbytes);
 
375
    sprintf (zsend, "R %s %s %s -%s %ld", qcmd->zfrom, qcmd->zto,
 
376
             qcmd->zuser, qcmd->zoptions, cbytes);
363
377
 
364
378
  fret = (*qdaemon->qproto->pfsendcmd) (qdaemon, zsend, qtrans->ilocal,
365
379
                                        qtrans->iremote);
366
380
  ubuffree (zsend);
367
381
 
 
382
  if (fquote)
 
383
    ufree_quoted_cmd (&squoted);
 
384
 
368
385
  /* There is a potential space leak here: if pfsendcmd fails, we
369
386
     might need to free qtrans.  However, it is possible that by the
370
387
     time pfsendcmd returns, a response will have been received which
384
401
     struct stransfer *qtrans;
385
402
     struct sdaemon *qdaemon;
386
403
     const char *zdata;
387
 
     size_t cdata;
 
404
     size_t cdata ATTRIBUTE_UNUSED;
388
405
{
389
406
  struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
390
407
  const char *zlog;
481
498
 
482
499
      if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, TRUE, FALSE,
483
500
                                        (long) -1, &fhandled))
484
 
        {
485
 
          (void) ffileclose (qtrans->e);
486
 
          return flocal_rec_fail (qtrans, &qtrans->s, qdaemon->qsys,
487
 
                                  (const char *) NULL);
488
 
        }
 
501
        return flocal_rec_fail (qtrans, &qtrans->s, qdaemon->qsys,
 
502
                                (const char *) NULL);
489
503
      if (fhandled)
490
504
        return TRUE;
491
505
    }
805
819
                                       qtrans->iremote))
806
820
    {
807
821
      (void) ffileclose (qtrans->e);
 
822
      qtrans->e = EFILECLOSED;
808
823
      (void) remove (qinfo->ztemp);
809
824
      /* Should probably free qtrans here, but see the comment at the
810
825
         end of flocal_rec_send_request.  */
818
833
      if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, TRUE, FALSE,
819
834
                                        (long) -1, &fhandled))
820
835
        {
821
 
          (void) ffileclose (qtrans->e);
822
836
          (void) remove (qinfo->ztemp);
823
837
          urrec_free (qtrans);
824
838
          return FALSE;
927
941
static boolean
928
942
fremote_discard (qtrans, qdaemon, zdata, cdata)
929
943
     struct stransfer *qtrans;
930
 
     struct sdaemon *qdaemon;
931
 
     const char *zdata;
 
944
     struct sdaemon *qdaemon ATTRIBUTE_UNUSED;
 
945
     const char *zdata ATTRIBUTE_UNUSED;
932
946
     size_t cdata;
933
947
{
934
948
  struct srecfailinfo *qinfo = (struct srecfailinfo *) qtrans->pinfo;
960
974
frec_file_end (qtrans, qdaemon, zdata, cdata)
961
975
     struct stransfer *qtrans;
962
976
     struct sdaemon *qdaemon;
963
 
     const char *zdata;
964
 
     size_t cdata;
 
977
     const char *zdata ATTRIBUTE_UNUSED;
 
978
     size_t cdata ATTRIBUTE_UNUSED;
965
979
{
966
980
  struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
967
981
  char *zalc;
979
993
      if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, FALSE, FALSE,
980
994
                                        (long) -1, &fhandled))
981
995
        {
982
 
          (void) ffileclose (qtrans->e);
983
996
          (void) remove (qinfo->ztemp);
984
997
          urrec_free (qtrans);
985
998
          return FALSE;
998
1011
    {
999
1012
      zerr = strerror (errno);
1000
1013
      (void) ffileclose (qtrans->e);
 
1014
      qtrans->e = EFILECLOSED;
1001
1015
      (void) remove (qinfo->ztemp);
1002
1016
    }
1003
1017
  else if (! ffileclose (qtrans->e))
1005
1019
      zerr = strerror (errno);
1006
1020
      ulog (LOG_ERROR, "%s: close: %s", qtrans->s.zto, zerr);
1007
1021
      (void) remove (qinfo->ztemp);
1008
 
    }
1009
 
  else if (! fsysdep_move_file (qinfo->ztemp, qinfo->zfile, qinfo->fspool,
1010
 
                                FALSE, ! qinfo->fspool,
1011
 
                                (qinfo->flocal
1012
 
                                 ? qtrans->s.zuser
1013
 
                                 : (const char *) NULL)))
1014
 
    {
1015
 
      long cspace;
1016
 
 
1017
 
      /* Keep the temporary file if there is 1.5 times the amount of
1018
 
         required free space.  This is just a random guess, to make an
1019
 
         unusual situtation potentially less painful.  */
1020
 
      cspace = csysdep_bytes_free (qinfo->ztemp);
1021
 
      if (cspace == -1)
1022
 
        cspace = FREE_SPACE_DELTA;
1023
 
      cspace -= (qdaemon->qsys->uuconf_cfree_space
1024
 
                 + qdaemon->qsys->uuconf_cfree_space / 2);
1025
 
      if (cspace < 0)
1026
 
        {
1027
 
          (void) remove (qinfo->ztemp);
1028
 
          zerr = "could not move to final location";
1029
 
        }
1030
 
      else
1031
 
        {
1032
 
          const char *az[20];
1033
 
          int i;
1034
 
 
1035
 
          zalc = zbufalc (sizeof "could not move to final location (left as )"
1036
 
                          + strlen (qinfo->ztemp));
1037
 
          sprintf (zalc, "could not move to final location (left as %s)",
1038
 
                   qinfo->ztemp);
1039
 
          zerr = zalc;
1040
 
 
1041
 
          i = 0;
1042
 
          az[i++] = "The file\n\t";
1043
 
          az[i++] = qinfo->ztemp;
1044
 
          az[i++] =
1045
 
            "\nwas saved because the move to the final location failed.\n";
1046
 
          az[i++] = "See the UUCP logs for more details.\n";
1047
 
          az[i++] = "The file transfer was from\n\t";
1048
 
          az[i++] = qdaemon->qsys->uuconf_zname;
1049
 
          az[i++] = "!";
1050
 
          az[i++] = qtrans->s.zfrom;
1051
 
          az[i++] = "\nto\n\t";
1052
 
          az[i++] = qtrans->s.zto;
1053
 
          az[i++] = "\nand was requested by\n\t";
1054
 
          az[i++] = qtrans->s.zuser;
1055
 
          az[i++] = "\n";
1056
 
          (void) fsysdep_mail (OWNER, "UUCP temporary file saved", i, az);
1057
 
        }
1058
 
      ulog (LOG_ERROR, "%s: %s", qinfo->zfile, zerr);
1059
 
      fnever = TRUE;
 
1022
      qtrans->e = EFILECLOSED;
1060
1023
    }
1061
1024
  else
1062
1025
    {
1063
 
      if (! qinfo->fspool)
 
1026
      qtrans->e = EFILECLOSED;
 
1027
      if (! fsysdep_move_file (qinfo->ztemp, qinfo->zfile, qinfo->fspool,
 
1028
                               FALSE, ! qinfo->fspool,
 
1029
                               (qinfo->flocal
 
1030
                                ? qtrans->s.zuser
 
1031
                                : (const char *) NULL)))
1064
1032
        {
1065
 
          unsigned int imode;
 
1033
          long cspace;
1066
1034
 
1067
 
          /* Unless we can change the ownership of the file, the only
1068
 
             choice to make about these bits is whether to set the
1069
 
             execute bit or not.  */
1070
 
          if ((qtrans->s.imode & 0111) != 0)
1071
 
            imode = 0777;
 
1035
          /* Keep the temporary file if there is 1.5 times the amount
 
1036
             of required free space.  This is just a random guess, to
 
1037
             make an unusual situtation potentially less painful.  */
 
1038
          cspace = csysdep_bytes_free (qinfo->ztemp);
 
1039
          if (cspace == -1)
 
1040
            cspace = FREE_SPACE_DELTA;
 
1041
          cspace -= (qdaemon->qsys->uuconf_cfree_space
 
1042
                     + qdaemon->qsys->uuconf_cfree_space / 2);
 
1043
          if (cspace < 0)
 
1044
            {
 
1045
              (void) remove (qinfo->ztemp);
 
1046
              zerr = "could not move to final location";
 
1047
            }
1072
1048
          else
1073
 
            imode = 0666;
1074
 
          (void) fsysdep_change_mode (qinfo->zfile, imode);
 
1049
            {
 
1050
              const char *az[20];
 
1051
              int i;
 
1052
 
 
1053
              zalc = zbufalc (sizeof "could not move to final location (left as )"
 
1054
                              + strlen (qinfo->ztemp));
 
1055
              sprintf (zalc, "could not move to final location (left as %s)",
 
1056
                       qinfo->ztemp);
 
1057
              zerr = zalc;
 
1058
 
 
1059
              i = 0;
 
1060
              az[i++] = "The file\n\t";
 
1061
              az[i++] = qinfo->ztemp;
 
1062
              az[i++] =
 
1063
                "\nwas saved because the move to the final location failed.\n";
 
1064
              az[i++] = "See the UUCP logs for more details.\n";
 
1065
              az[i++] = "The file transfer was from\n\t";
 
1066
              az[i++] = qdaemon->qsys->uuconf_zname;
 
1067
              az[i++] = "!";
 
1068
              az[i++] = qtrans->s.zfrom;
 
1069
              az[i++] = "\nto\n\t";
 
1070
              az[i++] = qtrans->s.zto;
 
1071
              az[i++] = "\nand was requested by\n\t";
 
1072
              az[i++] = qtrans->s.zuser;
 
1073
              az[i++] = "\n";
 
1074
              (void) fsysdep_mail (OWNER, "UUCP temporary file saved", i, az);
 
1075
            }
 
1076
          ulog (LOG_ERROR, "%s: %s", qinfo->zfile, zerr);
 
1077
          fnever = TRUE;
1075
1078
        }
 
1079
      else
 
1080
        {
 
1081
          if (! qinfo->fspool)
 
1082
            {
 
1083
              unsigned int imode;
 
1084
 
 
1085
              /* Unless we can change the ownership of the file, the
 
1086
                 only choice to make about these bits is whether to
 
1087
                 set the execute bit or not.  */
 
1088
              if ((qtrans->s.imode & 0111) != 0)
 
1089
                imode = 0777;
 
1090
              else
 
1091
                imode = 0666;
 
1092
              (void) fsysdep_change_mode (qinfo->zfile, imode);
 
1093
            }
1076
1094
  
1077
 
      zerr = NULL;
 
1095
          zerr = NULL;
 
1096
        }
1078
1097
    }
1079
1098
 
1080
1099
  ustats (zerr == NULL, qtrans->s.zuser, qdaemon->qsys->uuconf_zname,
1169
1188
          return FALSE;
1170
1189
        }
1171
1190
 
1172
 
      fprintf (e, "U %s %s\n", qtrans->s.zuser, qdaemon->qsys->uuconf_zname);
1173
 
      fprintf (e, "F %s\n", qtrans->s.zto);
1174
 
      fprintf (e, "I %s\n", qtrans->s.zto);
 
1191
      if (! fcmd_needs_quotes (&qtrans->s))
 
1192
        {
 
1193
          fprintf (e, "U %s %s\n", qtrans->s.zuser,
 
1194
                   qdaemon->qsys->uuconf_zname);
 
1195
          fprintf (e, "F %s\n", qtrans->s.zto);
 
1196
          fprintf (e, "I %s\n", qtrans->s.zto);
 
1197
          if (strchr (qtrans->s.zoptions, 'R') != NULL)
 
1198
            fprintf (e, "R %s\n", qtrans->s.znotify);
 
1199
          fprintf (e, "C %s\n", qtrans->s.zcmd);
 
1200
        }
 
1201
      else
 
1202
        {
 
1203
          char *z1;
 
1204
          char *z2;
 
1205
 
 
1206
          fprintf (e, "Q\n");
 
1207
 
 
1208
          z1 = zquote_cmd_string (qtrans->s.zuser, FALSE);
 
1209
          z2 = zquote_cmd_string (qdaemon->qsys->uuconf_zname, FALSE);
 
1210
          fprintf (e, "U %s %s\n", z1, z2);
 
1211
          ubuffree (z1);
 
1212
          ubuffree (z2);
 
1213
 
 
1214
          z1 = zquote_cmd_string (qtrans->s.zto, FALSE);
 
1215
          fprintf (e, "F %s\n", z1);
 
1216
          fprintf (e, "I %s\n", z1);
 
1217
          ubuffree (z1);
 
1218
 
 
1219
          if (strchr (qtrans->s.zoptions, 'R') != NULL)
 
1220
            {
 
1221
              z1 = zquote_cmd_string (qtrans->s.znotify, FALSE);
 
1222
              fprintf (e, "R %s\n", z1);
 
1223
              ubuffree (z1);
 
1224
            }
 
1225
 
 
1226
          z1 = zquote_cmd_string (qtrans->s.zcmd, TRUE);
 
1227
          fprintf (e, "C %s\n", z1);
 
1228
          ubuffree (z1);
 
1229
        }
 
1230
 
1175
1231
      if (strchr (qtrans->s.zoptions, 'N') != NULL)
1176
1232
        fprintf (e, "N\n");
1177
1233
      if (strchr (qtrans->s.zoptions, 'Z') != NULL)
1178
1234
        fprintf (e, "Z\n");
1179
 
      if (strchr (qtrans->s.zoptions, 'R') != NULL)
1180
 
        fprintf (e, "R %s\n", qtrans->s.znotify);
1181
1235
      if (strchr (qtrans->s.zoptions, 'e') != NULL)
1182
1236
        fprintf (e, "e\n");
1183
 
      fprintf (e, "C %s\n", qtrans->s.zcmd);
1184
1237
 
1185
1238
      fbad = FALSE;
1186
1239