~ubuntu-branches/ubuntu/hardy/gnupg2/hardy

« back to all changes in this revision

Viewing changes to agent/gpg-agent.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia, Michael Bienia, Kees Cook
  • Date: 2006-12-07 00:28:23 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061207002823-0i7ittrpmsm1nv0i
Tags: 2.0.1-0ubuntu1
[ Michael Bienia ]
* New upstream version.
* Remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
* g10/encr-data.c: remotely controllable function pointer (CVE-2006-6235)
* debian/control: add libcurl3-gnutls-dev to build-depends 
  (Closes Ubuntu: #62864)

[ Kees Cook ]
* debian/rules: include doc/ files as done with gnupg

Show diffs side-by-side

added added

removed removed

Lines of Context:
211
211
static int create_server_socket (int is_standard_name, const char *name);
212
212
static void create_directories (void);
213
213
 
 
214
static void agent_init_default_ctrl (ctrl_t ctrl);
 
215
static void agent_deinit_default_ctrl (ctrl_t ctrl);
 
216
 
214
217
static void handle_connections (int listen_fd, int listen_fd_ssh);
215
218
static int check_for_running_agent (int);
216
219
 
813
816
 
814
817
 
815
818
  if (pipe_server)
816
 
    { /* this is the simple pipe based server */
817
 
      start_command_handler (-1, -1);
 
819
    { 
 
820
      /* This is the simple pipe based server */
 
821
      ctrl_t ctrl;
 
822
 
 
823
      ctrl = xtrycalloc (1, sizeof *ctrl);
 
824
      if (!ctrl)
 
825
        {
 
826
          log_error ("error allocating connection control data: %s\n",
 
827
                     strerror (errno) );
 
828
          agent_exit (1);
 
829
        }
 
830
      agent_init_default_ctrl (ctrl);
 
831
      start_command_handler (ctrl, -1, -1);
 
832
      agent_deinit_default_ctrl (ctrl);
 
833
      xfree (ctrl);
818
834
    }
819
835
  else if (!is_daemon)
820
836
    ; /* NOTREACHED */
1073
1089
}
1074
1090
 
1075
1091
 
1076
 
void
1077
 
agent_init_default_ctrl (struct server_control_s *ctrl)
 
1092
static void
 
1093
agent_init_default_ctrl (ctrl_t ctrl)
1078
1094
{
1079
1095
  ctrl->connection_fd = -1;
1080
1096
 
1103
1119
}
1104
1120
 
1105
1121
 
 
1122
static void
 
1123
agent_deinit_default_ctrl (ctrl_t ctrl)
 
1124
{
 
1125
  if (ctrl->display)
 
1126
    free (ctrl->display);
 
1127
  if (ctrl->ttyname)
 
1128
    free (ctrl->ttyname);
 
1129
  if (ctrl->ttytype)
 
1130
    free (ctrl->ttytype);
 
1131
  if (ctrl->lc_ctype)
 
1132
    free (ctrl->lc_ctype);
 
1133
  if (ctrl->lc_messages)
 
1134
    free (ctrl->lc_messages);
 
1135
}
 
1136
 
1106
1137
/* Reread parts of the configuration.  Note, that this function is
1107
1138
   obviously not thread-safe and should only be called from the PTH
1108
1139
   signal handler. 
1400
1431
    case SIGUSR2:
1401
1432
      if (opt.verbose)
1402
1433
        log_info ("SIGUSR2 received - checking smartcard status\n");
 
1434
      /* Nothing to check right now.  We only increment a counter.  */
 
1435
      bump_card_eventcounter ();
1403
1436
      break;
1404
1437
 
1405
1438
    case SIGTERM:
1435
1468
static void *
1436
1469
start_connection_thread (void *arg)
1437
1470
{
1438
 
  int fd = (int)arg;
 
1471
  ctrl_t ctrl = arg;
1439
1472
 
 
1473
  agent_init_default_ctrl (ctrl);
1440
1474
  if (opt.verbose)
1441
1475
    log_info (_("handler 0x%lx for fd %d started\n"), 
1442
 
              (long)pth_self (), fd);
 
1476
              (long)pth_self (), ctrl->thread_startup.fd);
1443
1477
 
1444
 
  start_command_handler (-1, fd);
 
1478
  start_command_handler (ctrl, -1, ctrl->thread_startup.fd);
1445
1479
  if (opt.verbose)
1446
1480
    log_info (_("handler 0x%lx for fd %d terminated\n"), 
1447
 
              (long)pth_self (), fd);
 
1481
              (long)pth_self (), ctrl->thread_startup.fd);
1448
1482
  
 
1483
  agent_deinit_default_ctrl (ctrl);
 
1484
  xfree (ctrl);
1449
1485
  return NULL;
1450
1486
}
1451
1487
 
1454
1490
static void *
1455
1491
start_connection_thread_ssh (void *arg)
1456
1492
{
1457
 
  int fd = (int)arg;
 
1493
  ctrl_t ctrl = arg;
1458
1494
 
 
1495
  agent_init_default_ctrl (ctrl);
1459
1496
  if (opt.verbose)
1460
1497
    log_info (_("ssh handler 0x%lx for fd %d started\n"),
1461
 
              (long)pth_self (), fd);
 
1498
              (long)pth_self (), ctrl->thread_startup.fd);
1462
1499
 
1463
 
  start_command_handler_ssh (fd);
 
1500
  start_command_handler_ssh (ctrl, ctrl->thread_startup.fd);
1464
1501
  if (opt.verbose)
1465
1502
    log_info (_("ssh handler 0x%lx for fd %d terminated\n"),
1466
 
              (long)pth_self (), fd);
 
1503
              (long)pth_self (), ctrl->thread_startup.fd);
1467
1504
  
 
1505
  agent_deinit_default_ctrl (ctrl);
 
1506
  xfree (ctrl);
1468
1507
  return NULL;
1469
1508
}
1470
1509
 
1582
1621
 
1583
1622
      if (FD_ISSET (listen_fd, &read_fdset))
1584
1623
        {
 
1624
          ctrl_t ctrl;
 
1625
 
1585
1626
          plen = sizeof paddr;
1586
1627
          fd = pth_accept (listen_fd, (struct sockaddr *)&paddr, &plen);
1587
1628
          if (fd == -1)
1588
1629
            {
1589
1630
              log_error ("accept failed: %s\n", strerror (errno));
1590
1631
            }
 
1632
          else if ( !(ctrl = xtrycalloc (1, sizeof *ctrl)) )
 
1633
            {
 
1634
              log_error ("error allocating connection control data: %s\n",
 
1635
                         strerror (errno) );
 
1636
              close (fd);
 
1637
            }
1591
1638
          else 
1592
1639
            {
1593
1640
              char threadname[50];
 
1641
 
1594
1642
              snprintf (threadname, sizeof threadname-1,
1595
1643
                        "conn fd=%d (gpg)", fd);
1596
1644
              threadname[sizeof threadname -1] = 0;
1597
1645
              pth_attr_set (tattr, PTH_ATTR_NAME, threadname);
1598
 
              if (!pth_spawn (tattr, start_connection_thread, (void*)fd))
 
1646
              ctrl->thread_startup.fd = fd;
 
1647
              if (!pth_spawn (tattr, start_connection_thread, ctrl))
1599
1648
                {
1600
1649
                  log_error ("error spawning connection handler: %s\n",
1601
1650
                             strerror (errno) );
1602
1651
                  close (fd);
 
1652
                  xfree (ctrl);
1603
1653
                }
1604
1654
            }
1605
1655
          fd = -1;
1607
1657
 
1608
1658
      if (listen_fd_ssh != -1 && FD_ISSET (listen_fd_ssh, &read_fdset))
1609
1659
        {
 
1660
          ctrl_t ctrl;
 
1661
 
1610
1662
          plen = sizeof paddr;
1611
1663
          fd = pth_accept (listen_fd_ssh, (struct sockaddr *)&paddr, &plen);
1612
1664
          if (fd == -1)
1613
1665
            {
1614
1666
              log_error ("accept failed for ssh: %s\n", strerror (errno));
1615
1667
            }
 
1668
          else if ( !(ctrl = xtrycalloc (1, sizeof *ctrl)) )
 
1669
            {
 
1670
              log_error ("error allocating connection control data: %s\n",
 
1671
                         strerror (errno) );
 
1672
              close (fd);
 
1673
            }
1616
1674
          else
1617
1675
            {
1618
1676
              char threadname[50];
 
1677
 
 
1678
              agent_init_default_ctrl (ctrl);
1619
1679
              snprintf (threadname, sizeof threadname-1,
1620
1680
                        "conn fd=%d (ssh)", fd);
1621
1681
              threadname[sizeof threadname -1] = 0;
1622
1682
              pth_attr_set (tattr, PTH_ATTR_NAME, threadname);
1623
 
 
1624
 
              if (!pth_spawn (tattr, start_connection_thread_ssh, (void*)fd))
 
1683
              ctrl->thread_startup.fd = fd;
 
1684
              if (!pth_spawn (tattr, start_connection_thread_ssh, ctrl) )
1625
1685
                {
1626
1686
                  log_error ("error spawning ssh connection handler: %s\n",
1627
1687
                             strerror (errno) );
1628
1688
                  close (fd);
 
1689
                  xfree (ctrl);
1629
1690
                }
1630
1691
            }
1631
1692
          fd = -1;