~ubuntu-branches/ubuntu/quantal/gnupg2/quantal-updates

« back to all changes in this revision

Viewing changes to tools/gpg-connect-agent.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-05-25 14:27:35 UTC
  • mfrom: (1.1.15 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110525142735-jccyw0fopnyv728q
Tags: 2.0.17-2ubuntu1
* Merge from debian unstable. Remaining changes:
  - Add udev rules to give gpg access to some smartcard readers;
    Debian #543217.
    . debian/gnupg2.dev: udev rules to set ACLs on SCM smartcard readers.
    . debian/rules: Call dh_installudev.
  - debian/control: Rename Vcs-* to XS-Debian-Vcs-*.

Show diffs side-by-side

added added

removed removed

Lines of Context:
159
159
 
160
160
/*-- local prototypes --*/
161
161
static char *substitute_line_copy (const char *buffer);
162
 
static int read_and_print_response (assuan_context_t ctx, int *r_goterr);
 
162
static int read_and_print_response (assuan_context_t ctx, int withhash,
 
163
                                    int *r_goterr);
163
164
static assuan_context_t start_agent (void);
164
165
 
165
166
 
1086
1087
 
1087
1088
 
1088
1089
 
1089
 
static int
 
1090
static gpg_error_t
1090
1091
getinfo_pid_cb (void *opaque, const void *buffer, size_t length)
1091
1092
{
1092
1093
  membuf_t *mb = opaque;
1155
1156
  i18n_init();
1156
1157
  init_common_subsystems ();
1157
1158
 
1158
 
  assuan_set_assuan_err_source (0);
 
1159
  assuan_set_gpg_err_source (0);
1159
1160
 
1160
1161
 
1161
1162
  opt.homedir = default_homedir ();
1162
 
  opt.connect_flags = 1; /* Use extended connect mode.  */
 
1163
  opt.connect_flags = 1;
1163
1164
 
1164
1165
  /* Parse the command line. */
1165
1166
  pargs.argc  = &argc;
1221
1222
    {
1222
1223
      int no_close[3];
1223
1224
 
1224
 
      no_close[0] = fileno (stderr);
1225
 
      no_close[1] = log_get_fd ();
 
1225
      no_close[0] = assuan_fd_from_posix_fd (fileno (stderr));
 
1226
      no_close[1] = assuan_fd_from_posix_fd (log_get_fd ());
1226
1227
      no_close[2] = -1;
1227
 
      rc = assuan_pipe_connect_ext (&ctx, *argv, (const char **)argv,
1228
 
                                    no_close, NULL, NULL,
1229
 
                                    opt.connect_flags);
 
1228
 
 
1229
      rc = assuan_new (&ctx);
 
1230
      if (rc)
 
1231
        {
 
1232
          log_error ("assuan_new failed: %s\n", gpg_strerror (rc));
 
1233
          exit (1);
 
1234
        }
 
1235
 
 
1236
      rc = assuan_pipe_connect
 
1237
        (ctx, *argv, (const char **)argv, no_close, NULL, NULL,
 
1238
         (opt.connect_flags & 1) ? ASSUAN_PIPE_CONNECT_FDPASSING : 0);
1230
1239
      if (rc)
1231
1240
        {
1232
1241
          log_error ("assuan_pipe_connect_ext failed: %s\n",
1240
1249
    }
1241
1250
  else if (opt.raw_socket)
1242
1251
    {
1243
 
      rc = assuan_socket_connect_ext (&ctx, opt.raw_socket, 0,
1244
 
                                      opt.connect_flags);
 
1252
      rc = assuan_new (&ctx);
 
1253
      if (rc)
 
1254
        {
 
1255
          log_error ("assuan_new failed: %s\n", gpg_strerror (rc));
 
1256
          exit (1);
 
1257
        }
 
1258
 
 
1259
      rc = assuan_socket_connect
 
1260
        (ctx, opt.raw_socket, 0,
 
1261
         (opt.connect_flags & 1) ? ASSUAN_SOCKET_CONNECT_FDPASSING : 0);
1245
1262
      if (rc)
1246
1263
        {
1247
1264
          log_error ("can't connect to socket `%s': %s\n",
1259
1276
     assuan did not run the initial handshaking).  */
1260
1277
  if (assuan_pending_line (ctx))
1261
1278
    {
1262
 
      rc = read_and_print_response (ctx, &cmderr);
 
1279
      rc = read_and_print_response (ctx, 0, &cmderr);
1263
1280
      if (rc)
1264
1281
        log_info (_("receiving line failed: %s\n"), gpg_strerror (rc) );
1265
1282
    }
1747
1764
      if (*line == '#' || !*line)
1748
1765
        continue; /* Don't expect a response for a comment line. */
1749
1766
 
1750
 
      rc = read_and_print_response (ctx, &cmderr);
 
1767
      rc = read_and_print_response (ctx, (!ascii_strncasecmp (line, "HELP", 4)
 
1768
                                          && (spacep (line+4) || !line[4])),
 
1769
                                    &cmderr);
1751
1770
      if (rc)
1752
1771
        log_info (_("receiving line failed: %s\n"), gpg_strerror (rc) );
1753
1772
      if ((rc || cmderr) && script_fp)
1876
1895
 
1877
1896
 
1878
1897
/* Read all response lines from server and print them.  Returns 0 on
1879
 
   success or an assuan error code.  Set R_GOTERR to true if the
1880
 
   command did not returned OK.  */
 
1898
   success or an assuan error code.  If WITHHASH istrue, comment lines
 
1899
   are printed.  Sets R_GOTERR to true if the command did not returned
 
1900
   OK.  */
1881
1901
static int
1882
 
read_and_print_response (assuan_context_t ctx, int *r_goterr)
 
1902
read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr)
1883
1903
{
1884
1904
  char *line;
1885
1905
  size_t linelen;
1886
 
  assuan_error_t rc;
 
1906
  gpg_error_t rc;
1887
1907
  int i, j;
1888
1908
  int need_lf = 0;
1889
1909
 
1896
1916
          if (rc)
1897
1917
            return rc;
1898
1918
 
1899
 
          if (opt.verbose > 1 && *line == '#')
 
1919
          if ((withhash || opt.verbose > 1) && *line == '#')
1900
1920
            {
1901
1921
              fwrite (line, linelen, 1, stdout);
1902
1922
              putchar ('\n');
2086
2106
    {
2087
2107
      char *sockname;
2088
2108
 
 
2109
      rc = assuan_new (&ctx);
 
2110
      if (rc)
 
2111
        {
 
2112
          log_error ("assuan_new failed: %s\n", gpg_strerror (rc));
 
2113
          exit (1);
 
2114
        }
 
2115
 
2089
2116
      /* Check whether we can connect at the standard socket.  */
2090
2117
      sockname = make_filename (opt.homedir, "S.gpg-agent", NULL);
2091
 
      rc = assuan_socket_connect (&ctx, sockname, 0);
 
2118
      rc = assuan_socket_connect (ctx, sockname, 0, 0);
2092
2119
 
2093
2120
#ifdef HAVE_W32_SYSTEM
2094
2121
      /* If we failed to connect under Windows, we fire up the agent.  */
2115
2142
              /* Give the agent some time to prepare itself. */
2116
2143
              gnupg_sleep (3);
2117
2144
              /* Now try again to connect the agent.  */
2118
 
              rc = assuan_socket_connect (&ctx, sockname, 0);
 
2145
              rc = assuan_new (&ctx);
 
2146
              if (rc)
 
2147
                {
 
2148
                  log_error ("assuan_new failed: %s\n", gpg_strerror (rc));
 
2149
                  exit (1);
 
2150
                }
 
2151
 
 
2152
              rc = assuan_socket_connect (ctx, sockname, 0, 0);
2119
2153
            }
2120
2154
          if (rc)
2121
2155
            rc = save_rc;
2148
2182
          exit (1);
2149
2183
        }
2150
2184
 
2151
 
      rc = assuan_socket_connect (&ctx, infostr, pid);
 
2185
      rc = assuan_new (&ctx);
 
2186
      if (rc)
 
2187
        {
 
2188
          log_error ("assuan_new failed: %s\n", gpg_strerror (rc));
 
2189
          exit (1);
 
2190
        }
 
2191
 
 
2192
      rc = assuan_socket_connect (ctx, infostr, pid, 0);
2152
2193
      xfree (infostr);
2153
2194
    }
2154
2195