~ubuntu-branches/ubuntu/vivid/gnupg2/vivid-proposed

« back to all changes in this revision

Viewing changes to g10/cpr.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2014-06-26 14:50:31 UTC
  • mfrom: (14.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20140626145031-tpg2xmbtvomb8erd
Tags: 2.0.24-1ubuntu1
* Merge from Debian, remaining changes:
  - Drop sh prefix from openpgp test environment as it leads to exec
    invocations of sh /bin/bash leading to syntax errors from sh.  Fixes
    FTBFS detected in Ubuntu saucy archive rebuild.
  - Add udev rules to give gpg access to some smartcard readers;
    Debian #543217.
  - debian/gnupg2.udev: udev rules to set ACLs on SCM smartcard readers.
  - Add upstart user job for gpg-agent.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* status.c - Status message and command-fd interface 
 
1
/* status.c - Status message and command-fd interface
2
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
3
3
 *               2004, 2005, 2006 Free Software Foundation, Inc.
4
4
 *
75
75
     prompt the user. */
76
76
  switch (no)
77
77
    {
78
 
    case STATUS_GET_BOOL:        
79
 
    case STATUS_GET_LINE:        
80
 
    case STATUS_GET_HIDDEN:      
81
 
    case STATUS_GOT_IT:  
 
78
    case STATUS_GET_BOOL:
 
79
    case STATUS_GET_LINE:
 
80
    case STATUS_GET_HIDDEN:
 
81
    case STATUS_GOT_IT:
82
82
    case STATUS_IMPORTED:
83
 
    case STATUS_IMPORT_OK:      
84
 
    case STATUS_IMPORT_CHECK:  
 
83
    case STATUS_IMPORT_OK:
 
84
    case STATUS_IMPORT_CHECK:
85
85
    case STATUS_IMPORT_RES:
86
86
      return 1; /* Yes. */
87
87
    default:
102
102
    if ( statusfp && statusfp != stdout && statusfp != stderr )
103
103
        fclose (statusfp);
104
104
    statusfp = NULL;
105
 
    if ( fd == -1 ) 
 
105
    if ( fd == -1 )
106
106
        return;
107
107
 
108
108
    if( fd == 1 )
132
132
    write_status_text( no, NULL );
133
133
}
134
134
 
 
135
 
 
136
/* Write a status line with code NO followed by the string TEXT and
 
137
   directly followed by the remaining strings up to a NULL. */
135
138
void
136
 
write_status_text ( int no, const char *text)
 
139
write_status_strings (int no, const char *text, ...)
137
140
{
138
 
    if( !statusfp || !status_currently_allowed (no) )
139
 
        return;  /* Not enabled or allowed. */
140
 
 
141
 
    fputs ( "[GNUPG:] ", statusfp );
142
 
    fputs ( get_status_string (no), statusfp );
143
 
    if( text ) {
144
 
        putc ( ' ', statusfp );
145
 
        for (; *text; text++) {
146
 
            if (*text == '\n')
147
 
                fputs ( "\\n", statusfp );
148
 
            else if (*text == '\r')
149
 
                fputs ( "\\r", statusfp );
150
 
            else 
151
 
                putc ( *(const byte *)text,  statusfp );
 
141
  va_list arg_ptr;
 
142
  const char *s;
 
143
 
 
144
  if (!statusfp || !status_currently_allowed (no) )
 
145
    return;  /* Not enabled or allowed. */
 
146
 
 
147
  fputs ("[GNUPG:] ", statusfp);
 
148
  fputs (get_status_string (no), statusfp);
 
149
  if ( text )
 
150
    {
 
151
      putc ( ' ', statusfp);
 
152
      va_start (arg_ptr, text);
 
153
      s = text;
 
154
      do
 
155
        {
 
156
          for (; *s; s++)
 
157
            {
 
158
              if (*s == '\n')
 
159
                fputs ("\\n", statusfp);
 
160
              else if (*s == '\r')
 
161
                fputs ("\\r", statusfp);
 
162
              else
 
163
                fputc (*(const byte *)s, statusfp);
 
164
            }
152
165
        }
 
166
      while ((s = va_arg (arg_ptr, const char*)));
 
167
      va_end (arg_ptr);
153
168
    }
154
 
    putc ('\n',statusfp);
155
 
    if ( fflush (statusfp) && opt.exit_on_status_write_error )
156
 
      g10_exit (0);
 
169
  putc ('\n', statusfp);
 
170
  if (fflush (statusfp) && opt.exit_on_status_write_error)
 
171
    g10_exit (0);
 
172
}
 
173
 
 
174
 
 
175
void
 
176
write_status_text (int no, const char *text)
 
177
{
 
178
  write_status_strings (no, text, NULL);
157
179
}
158
180
 
159
181
 
163
185
  if (!statusfp || !status_currently_allowed (STATUS_ERROR))
164
186
    return;  /* Not enabled or allowed. */
165
187
 
166
 
  fprintf (statusfp, "[GNUPG:] %s %s %u\n", 
 
188
  fprintf (statusfp, "[GNUPG:] %s %s %u\n",
167
189
           get_status_string (STATUS_ERROR), where, gpg_err_code (errcode));
168
190
  if (fflush (statusfp) && opt.exit_on_status_write_error)
169
191
    g10_exit (0);
187
209
 
188
210
    if( !statusfp || !status_currently_allowed (no) )
189
211
        return;  /* Not enabled or allowed. */
190
 
    
 
212
 
191
213
    if (wrap == -1) {
192
214
        lower_limit--;
193
215
        wrap = 0;
212
234
            first = 0;
213
235
        }
214
236
        for (esc=0, s=buffer, n=len; n && !esc; s++, n-- ) {
215
 
            if ( *s == '%' || *(const byte*)s <= lower_limit 
216
 
                           || *(const byte*)s == 127 ) 
 
237
            if ( *s == '%' || *(const byte*)s <= lower_limit
 
238
                           || *(const byte*)s == 127 )
217
239
                esc = 1;
218
240
            if ( wrap && ++count > wrap ) {
219
241
                dowrap=1;
223
245
        if (esc) {
224
246
            s--; n++;
225
247
        }
226
 
        if (s != buffer) 
 
248
        if (s != buffer)
227
249
            fwrite (buffer, s-buffer, 1, statusfp );
228
250
        if ( esc ) {
229
251
            fprintf (statusfp, "%%%02X", *(const byte*)s );
257
279
      char buf[100];
258
280
      size_t buflen;
259
281
      int i;
260
 
      
 
282
 
261
283
      /* We use a hard coded list of possible algorithms.  Using other
262
284
         algorithms than specified by OpenPGP does not make sense
263
285
         anyway.  We do this out of performance reasons: Walking all
270
292
        if (i < 4 || i > 7)
271
293
          if ( gcry_md_is_enabled (md, i) && buflen < DIM(buf) )
272
294
            {
273
 
              snprintf (buf+buflen, DIM(buf) - buflen - 1, 
 
295
              snprintf (buf+buflen, DIM(buf) - buflen - 1,
274
296
                        "%sH%d", buflen? " ":"",i);
275
297
              buflen += strlen (buf+buflen);
276
298
            }
302
324
            raise (SIGHUP); /* no more input data */
303
325
#endif
304
326
        }
305
 
    }    
 
327
    }
306
328
    return rc;
307
329
}
308
330
 
316
338
{
317
339
  int i, len;
318
340
  char *string;
319
 
  
 
341
 
320
342
  if (statusfp != stdout)
321
343
    fflush (stdout);
322
 
  
 
344
 
323
345
  write_status_text (getbool? STATUS_GET_BOOL :
324
346
                     hidden? STATUS_GET_HIDDEN : STATUS_GET_LINE, keyword);
325
347
 
326
 
  for (string = NULL, i = len = 200; ; i++ ) 
 
348
  for (string = NULL, i = len = 200; ; i++ )
327
349
    {
328
 
      if (i >= len-1 ) 
 
350
      if (i >= len-1 )
329
351
        {
330
352
          char *save = string;
331
353
          len += 100;
338
360
      /* Fixme: why not use our read_line function here? */
339
361
      if ( myread( opt.command_fd, string+i, 1) != 1 || string[i] == '\n'  )
340
362
        break;
341
 
      else if ( string[i] == CONTROL_D ) 
 
363
      else if ( string[i] == CONTROL_D )
342
364
        {
343
365
          /* Found ETX - Cancel the line and return a sole ETX.  */
344
366
          string[0] = CONTROL_D;