~ubuntu-branches/ubuntu/raring/gnupg2/raring-proposed

« back to all changes in this revision

Viewing changes to tests/asschk.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2010-01-09 21:15:18 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100109211518-jy03kb8hv1a12gfz
Tags: 2.0.14-1
* New upstream release.
* debian/control: Build depend on libreadline-dev instead of
  libreadline5-dev, since libreadline6-dev is out. (Closes: #548922)
* debian/source/format, debian/source/options,
  debian/source/patch-header: Convert to v3 quilt format, with
  single-debian-patch.
* debian/control: Tighten dependency on gnupg-agent. (Closes: #551792)

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
  exit (1);
200
200
}
201
201
 
202
 
#define die(format, args...) (die) ("%s: " format, __func__ , ##args)
 
202
#define die_0(format)          (die) ("%s: " format, __func__)
 
203
#define die_1(format, a)       (die) ("%s: " format, __func__, (a))
 
204
#define die_2(format, a, b)    (die) ("%s: " format, __func__, (a),(b))
 
205
#define die_3(format, a, b, c) (die) ("%s: " format, __func__, (a),(b),(c))
203
206
 
204
207
static void
205
208
err (const char *format, ...)
290
293
      if (pending_len)
291
294
        {
292
295
          if (pending_len >= nleft)
293
 
            die ("received line too large");
 
296
            die_0 ("received line too large");
294
297
          memcpy (buf, pending, pending_len);
295
298
          n = pending_len;
296
299
          pending_len = 0;
315
318
        }
316
319
 
317
320
      if (n < 0)
318
 
        die ("reading fd %d failed: %s", fd, strerror (errno));
 
321
        die_2 ("reading fd %d failed: %s", fd, strerror (errno));
319
322
      else if (!n)
320
 
        die ("received incomplete line on fd %d", fd);
 
323
        die_1 ("received incomplete line on fd %d", fd);
321
324
      p = buf;
322
325
      nleft -= n;
323
326
      buf += n;
337
340
        }
338
341
    }
339
342
  if (!nleft)
340
 
    die ("received line too large");
 
343
    die_0 ("received line too large");
341
344
 
342
345
  p = recv_line;
343
346
  if (p[0] == 'O' && p[1] == 'K' && (p[2] == ' ' || !p[2]))
367
370
      p += 3;
368
371
    }
369
372
  else 
370
 
    die ("invalid line type (%.5s)", p);
 
373
    die_1 ("invalid line type (%.5s)", p);
371
374
 
372
375
  return p;
373
376
}
381
384
  size_t n = strlen (line);
382
385
 
383
386
  if (n > 1024)
384
 
    die ("line too long for Assuan protocol");
 
387
    die_0 ("line too long for Assuan protocol");
385
388
  strcpy (buffer, line);
386
389
  if (!n || buffer[n-1] != '\n')
387
390
    buffer[n++] = '\n';
388
391
 
389
392
  if (writen (fd, buffer, n))
390
 
      die ("sending line (\"%s\") to %d failed: %s", buffer, fd,
 
393
      die_3 ("sending line (\"%s\") to %d failed: %s", buffer, fd,
391
394
           strerror (errno));
392
395
}
393
396
 
404
407
  pid_t pid;
405
408
 
406
409
  if (pipe (rp) < 0)
407
 
    die ("pipe creation failed: %s", strerror (errno));
 
410
    die_1 ("pipe creation failed: %s", strerror (errno));
408
411
  if (pipe (wp) < 0)
409
 
    die ("pipe creation failed: %s", strerror (errno));
 
412
    die_1 ("pipe creation failed: %s", strerror (errno));
410
413
 
411
414
  fflush (stdout);
412
415
  fflush (stderr);
413
416
  pid = fork ();
414
417
  if (pid < 0)
415
 
    die ("fork failed");
 
418
    die_0 ("fork failed");
416
419
 
417
420
  if (!pid)
418
421
    {
427
430
      if (wp[0] != STDIN_FILENO)
428
431
        {
429
432
          if (dup2 (wp[0], STDIN_FILENO) == -1)
430
 
              die ("dup2 failed in child: %s", strerror (errno));
 
433
            die_1 ("dup2 failed in child: %s", strerror (errno));
431
434
          close (wp[0]);
432
435
        }
433
436
      if (rp[1] != STDOUT_FILENO)
434
437
        {
435
438
          if (dup2 (rp[1], STDOUT_FILENO) == -1)
436
 
              die ("dup2 failed in child: %s", strerror (errno));
 
439
            die_1 ("dup2 failed in child: %s", strerror (errno));
437
440
          close (rp[1]);
438
441
        }
439
442
      if (!opt_verbose)
440
443
        {
441
444
          int fd = open ("/dev/null", O_WRONLY);
442
445
          if (fd == -1)
443
 
            die ("can't open `/dev/null': %s", strerror (errno));
 
446
            die_1 ("can't open `/dev/null': %s", strerror (errno));
444
447
          if (dup2 (fd, STDERR_FILENO) == -1)
445
 
            die ("dup2 failed in child: %s", strerror (errno));
 
448
            die_1 ("dup2 failed in child: %s", strerror (errno));
446
449
          close (fd);
447
450
        }
448
451
 
449
452
      close (wp[1]);
450
453
      close (rp[0]);
451
454
      execl (pgmname, arg0, "--server", NULL); 
452
 
      die ("exec failed for `%s': %s", pgmname, strerror (errno));
 
455
      die_2 ("exec failed for `%s': %s", pgmname, strerror (errno));
453
456
    }
454
457
  close (wp[0]);
455
458
  close (rp[1]);
458
461
 
459
462
  read_assuan (server_recv_fd);
460
463
  if (recv_type != LINE_OK)
461
 
    die ("no greating message");
 
464
    die_0 ("no greating message");
462
465
}
463
466
 
464
467
 
723
726
    }
724
727
  while (recv_type != LINE_OK && recv_type != LINE_ERR);
725
728
  if (recv_type != LINE_OK)
726
 
    die ("expected OK but got `%s'", recv_line);
 
729
    die_1 ("expected OK but got `%s'", recv_line);
727
730
}
728
731
 
729
732
static void
744
747
    }
745
748
  while (recv_type != LINE_OK && recv_type != LINE_ERR);
746
749
  if (recv_type != LINE_ERR)
747
 
    die ("expected ERR but got `%s'", recv_line);
 
750
    die_1 ("expected ERR but got `%s'", recv_line);
748
751
}
749
752
 
750
753
static void
753
756
  char *p;
754
757
 
755
758
  if (!*assign_to || !*arg)
756
 
    die ("syntax error: count-status requires an argument and a variable");
 
759
    die_0 ("syntax error: count-status requires an argument and a variable");
757
760
 
758
761
  for (p=arg; *p && !spacep (p); p++)
759
762
    ;
762
765
      for (*p++ = 0; spacep (p); p++)
763
766
        ;
764
767
      if (*p)
765
 
        die ("cmpfiles: syntax error");
 
768
        die_0 ("cmpfiles: syntax error");
766
769
    }
767
770
  set_type_var (assign_to, arg, VARTYPE_COUNTER);
768
771
}
777
780
    fd = open (arg, O_RDONLY);
778
781
  while (fd == -1 && errno == EINTR);
779
782
  if (fd == -1)
780
 
    die ("error opening `%s': %s", arg, strerror (errno));
 
783
    die_2 ("error opening `%s': %s", arg, strerror (errno));
781
784
  
782
785
  sprintf (numbuf, "%d", fd);
783
786
  set_type_var (assign_to, numbuf, VARTYPE_FD);
793
796
    fd = open (arg, O_WRONLY|O_CREAT|O_TRUNC, 0666);
794
797
  while (fd == -1 && errno == EINTR);
795
798
  if (fd == -1)
796
 
    die ("error creating `%s': %s", arg, strerror (errno));
 
799
    die_2 ("error creating `%s': %s", arg, strerror (errno));
797
800
 
798
801
  sprintf (numbuf, "%d", fd);
799
802
  set_type_var (assign_to, numbuf, VARTYPE_FD);
806
809
  (void)assign_to;
807
810
 
808
811
  if (!*arg)
809
 
    die ("syntax error: servername missing");
 
812
    die_0 ("syntax error: servername missing");
810
813
 
811
814
  start_server (arg);
812
815
}
846
849
  for (p=arg; *p && !spacep (p); p++)
847
850
    ;
848
851
  if (!*p)
849
 
    die ("cmpfiles: syntax error");
 
852
    die_0 ("cmpfiles: syntax error");
850
853
  for (*p++ = 0; spacep (p); p++)
851
854
    ;
852
855
  second = p;
857
860
      for (*p++ = 0; spacep (p); p++)
858
861
        ;
859
862
      if (*p)
860
 
        die ("cmpfiles: syntax error");
 
863
        die_0 ("cmpfiles: syntax error");
861
864
    }
862
865
  
863
866
  fp1 = fopen (arg, "rb");
973
976
        assign_to = line;
974
977
    }
975
978
  if (!*line)
976
 
    die ("syntax error");
 
979
    die_0 ("syntax error");
977
980
  stmt = line;
978
981
  save_c = 0;
979
982
  save_p = NULL;
1003
1006
  if (!cmdtbl[i].name)
1004
1007
    {
1005
1008
      if (!assign_to)
1006
 
        die ("invalid statement `%s'\n", stmt);
 
1009
        die_1 ("invalid statement `%s'\n", stmt);
1007
1010
      if (save_p)
1008
1011
        *save_p = save_c;
1009
1012
      set_var (assign_to, stmt);
1078
1081
    {
1079
1082
      p = strchr (buffer,'\n');
1080
1083
      if (!p)
1081
 
        die ("incomplete script line");
 
1084
        die_0 ("incomplete script line");
1082
1085
      *p = 0;
1083
1086
      if (interpreter (buffer))
1084
1087
        break;