~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to g10/misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2009-03-08 22:46:47 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090308224647-gq17gatcl71lrc2k
Tags: 2.0.11-1
* New upstream release. (Closes: #496663)
* debian/control: Make the description a little more distinctive than
  gnupg v1's. Thanks Jari Aalto. (Closes: #496323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* misc.c - miscellaneous functions
2
 
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3
 
 *               2005, 2006, 2007 Free Software Foundation, Inc.
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
 
3
 *               2008 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
121
121
  sf->dev = buf.st_dev;
122
122
  sf->next = secured_files;
123
123
  secured_files = sf;
124
 
#endif /*ENABLE_SELINUX_HACKS*/
 
124
#else /*!ENABLE_SELINUX_HACKS*/
 
125
  (void)fname;
 
126
#endif /*!ENABLE_SELINUX_HACKS*/
125
127
}
126
128
 
127
129
/* Remove a file registered as secure. */
152
154
          return;
153
155
        }
154
156
    }
155
 
#endif /*ENABLE_SELINUX_HACKS*/
 
157
#else /*!ENABLE_SELINUX_HACKS*/
 
158
  (void)fname;
 
159
#endif /*!ENABLE_SELINUX_HACKS*/
156
160
}
157
161
 
158
162
/* Return true if FD is corresponds to a secured file.  Using -1 for
182
186
      if (sf->ino == buf.st_ino && sf->dev == buf.st_dev)
183
187
        return 1; /* Yes.  */
184
188
    }
185
 
#endif /*ENABLE_SELINUX_HACKS*/
 
189
#else /*!ENABLE_SELINUX_HACKS*/
 
190
  (void)fd;
 
191
#endif /*!ENABLE_SELINUX_HACKS*/
186
192
  return 0; /* No. */
187
193
}
188
194
 
217
223
      if (sf->ino == buf.st_ino && sf->dev == buf.st_dev)
218
224
        return 1; /* Yes.  */
219
225
    }
220
 
#endif /*ENABLE_SELINUX_HACKS*/
 
226
#else /*!ENABLE_SELINUX_HACKS*/
 
227
  (void)fname;
 
228
#endif /*!ENABLE_SELINUX_HACKS*/
221
229
  return 0; /* No. */
222
230
}
223
231
 
338
346
  switch (algo)
339
347
    {
340
348
    case CIPHER_ALGO_CAMELLIA128: return 310; 
 
349
    case CIPHER_ALGO_CAMELLIA192: return 311; 
341
350
    case CIPHER_ALGO_CAMELLIA256: return 312; 
342
351
    default: return algo;
343
352
    }
350
359
  switch (algo)
351
360
    {
352
361
    case 310: return CIPHER_ALGO_CAMELLIA128;
 
362
    case 311: return CIPHER_ALGO_CAMELLIA192;
353
363
    case 312: return CIPHER_ALGO_CAMELLIA256;
354
364
    default: return algo;
355
365
    }
356
366
}
357
367
 
 
368
 
 
369
/* Return the block length of an OpenPGP cipher algorithm.  */
 
370
int 
 
371
openpgp_cipher_blocklen (int algo)
 
372
{
 
373
  /* We use the numbers from OpenPGP to be sure that we get the right
 
374
     block length.  This is so that the packet parsing code works even
 
375
     for unknown algorithms (for which we assume 8 due to tradition).
 
376
 
 
377
     NOTE: If you change the the returned blocklen above 16, check
 
378
     the callers because they may use a fixed size buffer of that
 
379
     size. */
 
380
  switch (algo)
 
381
    {
 
382
    case 7: case 8: case 9: /* AES */
 
383
    case 10: /* Twofish */
 
384
    case 11: case 12: case 13: /* Camellia */
 
385
      return 16;
 
386
 
 
387
    default:
 
388
      return 8;
 
389
    }
 
390
}
 
391
 
358
392
/****************
359
393
 * Wrapper around the libgcrypt function with additonal checks on
360
394
 * the OpenPGP contraints for the algo ID.
370
404
     requested.  */
371
405
#ifndef USE_CAMELLIA
372
406
  if (algo == CIPHER_ALGO_CAMELLIA128 
373
 
       || algo == CIPHER_ALGO_CAMELLIA256)
 
407
      || algo == CIPHER_ALGO_CAMELLIA192
 
408
      || algo == CIPHER_ALGO_CAMELLIA256)
374
409
    return gpg_error (GPG_ERR_CIPHER_ALGO);
375
410
#endif
376
411
 
386
421
  return gcry_cipher_algo_name (map_cipher_openpgp_to_gcry (algo));
387
422
}
388
423
 
389
 
 
390
 
 
391
424
int
392
425
openpgp_pk_test_algo( int algo )
393
426
{
525
558
 
526
559
  while(*ch!='\0')
527
560
    {
528
 
      char *str=NULL;
529
 
 
530
561
      if(!done)
531
562
        {
532
563
          /* 8192 is way bigger than we'll need here */
635
666
              }
636
667
              break;
637
668
 
638
 
            case 't': /* e.g. "jpg" */
639
 
              str=image_type_to_string(args->imagetype,0);
640
 
              /* fall through */
641
 
 
642
 
            case 'T': /* e.g. "image/jpeg" */
643
 
              if(str==NULL)
644
 
                str=image_type_to_string(args->imagetype,2);
645
 
 
646
 
              if(idx+strlen(str)<maxlen)
 
669
            case 'v': /* validity letters */
 
670
              if(args->validity_info && idx+1<maxlen)
647
671
                {
648
 
                  strcpy(&ret[idx],str);
649
 
                  idx+=strlen(str);
 
672
                  ret[idx++]=args->validity_info;
 
673
                  ret[idx]='\0';
650
674
                  done=1;
651
675
                }
652
676
              break;
653
677
 
 
678
              /* The text string types */
 
679
            case 't':
 
680
            case 'T':
 
681
            case 'V':
 
682
              {
 
683
                const char *str=NULL;
 
684
 
 
685
                switch(*(ch+1))
 
686
                  {
 
687
                  case 't': /* e.g. "jpg" */
 
688
                    str=image_type_to_string(args->imagetype,0);
 
689
                    break;
 
690
                  
 
691
                  case 'T': /* e.g. "image/jpeg" */
 
692
                    str=image_type_to_string(args->imagetype,2);
 
693
                    break;
 
694
 
 
695
                  case 'V': /* e.g. "full", "expired", etc. */
 
696
                    str=args->validity_string;
 
697
                    break;
 
698
                  }
 
699
 
 
700
                if(str && idx+strlen(str)<maxlen)
 
701
                  {
 
702
                    strcpy(&ret[idx],str);
 
703
                    idx+=strlen(str);
 
704
                    done=1;
 
705
                  }
 
706
              }
 
707
              break;
 
708
 
654
709
            case '%':
655
710
              if(idx+1<maxlen)
656
711
                {
1193
1248
}
1194
1249
 
1195
1250
 
 
1251
/* Check whether the string has characters not valid in an RFC-822
 
1252
   address.  To cope with OpenPGP we ignore allow non-ascii characters
 
1253
   so that for example umlauts are legal in an email address.  An
 
1254
   OpenPGP user ID must be utf-8 encoded but there is no strict
 
1255
   requirement for RFC-822.  Thus to avoid IDNA encoding we put the
 
1256
   address verbatim as utf-8 into the user ID under the assumption
 
1257
   that mail programs handle IDNA at a lower level and take OpenPGP
 
1258
   user IDs as utf-8.  Note that we can't do an utf-8 encoding
 
1259
   checking here because in keygen.c this function is called with the
 
1260
   native encoding and native to utf-8 encoding is only done  later.  */
1196
1261
int
1197
1262
has_invalid_email_chars (const char *s)
1198
1263
{
1202
1267
 
1203
1268
  for ( ; *s; s++ ) 
1204
1269
    {
1205
 
      if ( *s & 0x80 )
1206
 
        return 1;
 
1270
      if ( (*s & 0x80) )
 
1271
        continue; /* We only care about ASCII.  */
1207
1272
      if ( *s == '@' )
1208
1273
        at_seen=1;
1209
1274
      else if ( !at_seen && !( !!strchr( valid_chars, *s ) || *s == '+' ) )