~nutznboltz-deactivatedaccount/ubuntu/precise/gnutls26/fix-lp926350

« back to all changes in this revision

Viewing changes to lib/opencdk/kbnode.c

  • Committer: Package Import Robot
  • Author(s): Andreas Metzler
  • Date: 2011-10-01 15:28:13 UTC
  • mfrom: (12.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20111001152813-yygm1c4cxonfxhzy
Tags: 2.12.11-1
* New upstream version.
  + Allow CA importing of 0 certificates to succeed. Closes: #640639
* Add libp11-kit-dev to libgnutls-dev dependencies. (see #643811)
* [20_guiledocstring.diff] guile: Fix docstring extraction with CPP 4.5+.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 *
24
24
 */
25
25
#ifdef HAVE_CONFIG_H
26
 
# include <config.h>
 
26
#include <config.h>
27
27
#endif
28
28
#include <stdio.h>
29
29
#include <stdlib.h>
78
78
    {
79
79
      n2 = node->next;
80
80
      if (!node->is_cloned)
81
 
        cdk_pkt_release (node->pkt);
 
81
        cdk_pkt_release (node->pkt);
82
82
      cdk_free (node);
83
83
      node = n2;
84
84
    }
122
122
 **/
123
123
void
124
124
cdk_kbnode_insert (cdk_kbnode_t root, cdk_kbnode_t node,
125
 
                   cdk_packet_type_t pkttype)
 
125
                   cdk_packet_type_t pkttype)
126
126
{
127
127
  if (!pkttype)
128
128
    {
134
134
      cdk_kbnode_t n1;
135
135
 
136
136
      for (n1 = root; n1->next; n1 = n1->next)
137
 
        if (pkttype != n1->next->pkt->pkttype)
138
 
          {
139
 
            node->next = n1->next;
140
 
            n1->next = node;
141
 
            return;
142
 
          }
 
137
        if (pkttype != n1->next->pkt->pkttype)
 
138
          {
 
139
            node->next = n1->next;
 
140
            n1->next = node;
 
141
            return;
 
142
          }
143
143
      /* No such packet, append */
144
144
      node->next = NULL;
145
145
      n1->next = node;
158
158
 **/
159
159
cdk_kbnode_t
160
160
cdk_kbnode_find_prev (cdk_kbnode_t root, cdk_kbnode_t node,
161
 
                      cdk_packet_type_t pkttype)
 
161
                      cdk_packet_type_t pkttype)
162
162
{
163
163
  cdk_kbnode_t n1;
164
164
 
165
165
  for (n1 = NULL; root && root != node; root = root->next)
166
166
    {
167
167
      if (!pkttype || root->pkt->pkttype == pkttype)
168
 
        n1 = root;
 
168
        n1 = root;
169
169
    }
170
170
  return n1;
171
171
}
189
189
  for (node = node->next; node; node = node->next)
190
190
    {
191
191
      if (!pkttype)
192
 
        return node;
 
192
        return node;
193
193
      else if (pkttype == CDK_PKT_USER_ID &&
194
 
               (node->pkt->pkttype == CDK_PKT_PUBLIC_KEY ||
195
 
                node->pkt->pkttype == CDK_PKT_SECRET_KEY))
196
 
        return NULL;
 
194
               (node->pkt->pkttype == CDK_PKT_PUBLIC_KEY ||
 
195
                node->pkt->pkttype == CDK_PKT_SECRET_KEY))
 
196
        return NULL;
197
197
      else if (pkttype == CDK_PKT_SIGNATURE &&
198
 
               (node->pkt->pkttype == CDK_PKT_USER_ID ||
199
 
                node->pkt->pkttype == CDK_PKT_PUBLIC_KEY ||
200
 
                node->pkt->pkttype == CDK_PKT_SECRET_KEY))
201
 
        return NULL;
 
198
               (node->pkt->pkttype == CDK_PKT_USER_ID ||
 
199
                node->pkt->pkttype == CDK_PKT_PUBLIC_KEY ||
 
200
                node->pkt->pkttype == CDK_PKT_SECRET_KEY))
 
201
        return NULL;
202
202
      else if (node->pkt->pkttype == pkttype)
203
 
        return node;
 
203
        return node;
204
204
    }
205
205
  return NULL;
206
206
}
219
219
  for (; node; node = node->next)
220
220
    {
221
221
      if (node->pkt->pkttype == pkttype)
222
 
        return node;
 
222
        return node;
223
223
    }
224
224
  return NULL;
225
225
}
258
258
  do
259
259
    {
260
260
      if (!*ctx)
261
 
        {
262
 
          *ctx = root;
263
 
          n = root;
264
 
        }
 
261
        {
 
262
          *ctx = root;
 
263
          n = root;
 
264
        }
265
265
      else
266
 
        {
267
 
          n = (*ctx)->next;
268
 
          *ctx = n;
269
 
        }
 
266
        {
 
267
          n = (*ctx)->next;
 
268
          *ctx = n;
 
269
        }
270
270
    }
271
271
  while (!all && n && n->is_deleted);
272
272
  return n;
292
292
  for (n = *root, nl = NULL; n; n = nl->next)
293
293
    {
294
294
      if (n->is_deleted)
295
 
        {
296
 
          if (n == *root)
297
 
            *root = nl = n->next;
298
 
          else
299
 
            nl->next = n->next;
300
 
          if (!n->is_cloned)
301
 
            cdk_pkt_release (n->pkt);
302
 
          cdk_free (n);
303
 
          changed = 1;
304
 
        }
 
295
        {
 
296
          if (n == *root)
 
297
            *root = nl = n->next;
 
298
          else
 
299
            nl->next = n->next;
 
300
          if (!n->is_cloned)
 
301
            cdk_pkt_release (n->pkt);
 
302
          cdk_free (n);
 
303
          changed = 1;
 
304
        }
305
305
      else
306
 
        nl = n;
 
306
        nl = n;
307
307
    }
308
308
  return changed;
309
309
}
324
324
  for (n = *root, nl = NULL; n; n = nl->next)
325
325
    {
326
326
      if (n == node)
327
 
        {
328
 
          if (n == *root)
329
 
            *root = nl = n->next;
330
 
          else
331
 
            nl->next = n->next;
332
 
          if (!n->is_cloned)
333
 
            cdk_pkt_release (n->pkt);
334
 
          cdk_free (n);
335
 
        }
 
327
        {
 
328
          if (n == *root)
 
329
            *root = nl = n->next;
 
330
          else
 
331
            nl->next = n->next;
 
332
          if (!n->is_cloned)
 
333
            cdk_pkt_release (n->pkt);
 
334
          cdk_free (n);
 
335
        }
336
336
      else
337
 
        nl = n;
 
337
        nl = n;
338
338
    }
339
339
}
340
340
 
358
358
  for (prev = *root; prev && prev->next != node; prev = prev->next)
359
359
    ;
360
360
  if (!prev)
361
 
    return;                     /* Node is not in the list */
 
361
    return;                     /* Node is not in the list */
362
362
 
363
363
  if (!where)
364
 
    {                           /* Move node before root */
 
364
    {                           /* Move node before root */
365
365
      if (node == *root)
366
 
        return;
 
366
        return;
367
367
      prev->next = node->next;
368
368
      node->next = *root;
369
369
      *root = node;
370
370
      return;
371
371
    }
372
 
  if (node == where)            /* Move it after where. */
 
372
  if (node == where)            /* Move it after where. */
373
373
    return;
374
374
  tmp = node->next;
375
375
  node->next = where->next;
405
405
 **/
406
406
cdk_error_t
407
407
cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node,
408
 
                          const byte * buf, size_t buflen)
 
408
                          const byte * buf, size_t buflen)
409
409
{
410
410
  cdk_stream_t inp;
411
411
  cdk_error_t rc;
439
439
 */
440
440
cdk_error_t
441
441
cdk_kbnode_write_to_mem_alloc (cdk_kbnode_t node,
442
 
                               byte ** r_buf, size_t * r_buflen)
 
442
                               byte ** r_buf, size_t * r_buflen)
443
443
{
444
444
  cdk_kbnode_t n;
445
445
  cdk_stream_t s;
466
466
    {
467
467
      /* Skip all packets which cannot occur in a key composition. */
468
468
      if (n->pkt->pkttype != CDK_PKT_PUBLIC_KEY &&
469
 
          n->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY &&
470
 
          n->pkt->pkttype != CDK_PKT_SECRET_KEY &&
471
 
          n->pkt->pkttype != CDK_PKT_SECRET_SUBKEY &&
472
 
          n->pkt->pkttype != CDK_PKT_SIGNATURE &&
473
 
          n->pkt->pkttype != CDK_PKT_USER_ID &&
474
 
          n->pkt->pkttype != CDK_PKT_ATTRIBUTE)
475
 
        continue;
 
469
          n->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY &&
 
470
          n->pkt->pkttype != CDK_PKT_SECRET_KEY &&
 
471
          n->pkt->pkttype != CDK_PKT_SECRET_SUBKEY &&
 
472
          n->pkt->pkttype != CDK_PKT_SIGNATURE &&
 
473
          n->pkt->pkttype != CDK_PKT_USER_ID &&
 
474
          n->pkt->pkttype != CDK_PKT_ATTRIBUTE)
 
475
        continue;
476
476
      rc = cdk_pkt_write (s, n->pkt);
477
477
      if (rc)
478
 
        {
479
 
          cdk_stream_close (s);
480
 
          gnutls_assert ();
481
 
          return rc;
482
 
        }
 
478
        {
 
479
          cdk_stream_close (s);
 
480
          gnutls_assert ();
 
481
          return rc;
 
482
        }
483
483
    }
484
484
 
485
485
  cdk_stream_seek (s, 0);
527
527
    {
528
528
      /* Skip all packets which cannot occur in a key composition. */
529
529
      if (n->pkt->pkttype != CDK_PKT_PUBLIC_KEY &&
530
 
          n->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY &&
531
 
          n->pkt->pkttype != CDK_PKT_SECRET_KEY &&
532
 
          n->pkt->pkttype != CDK_PKT_SECRET_SUBKEY &&
533
 
          n->pkt->pkttype != CDK_PKT_SIGNATURE &&
534
 
          n->pkt->pkttype != CDK_PKT_USER_ID &&
535
 
          n->pkt->pkttype != CDK_PKT_ATTRIBUTE)
536
 
        continue;
 
530
          n->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY &&
 
531
          n->pkt->pkttype != CDK_PKT_SECRET_KEY &&
 
532
          n->pkt->pkttype != CDK_PKT_SECRET_SUBKEY &&
 
533
          n->pkt->pkttype != CDK_PKT_SIGNATURE &&
 
534
          n->pkt->pkttype != CDK_PKT_USER_ID &&
 
535
          n->pkt->pkttype != CDK_PKT_ATTRIBUTE)
 
536
        continue;
537
537
      rc = cdk_pkt_write (s, n->pkt);
538
538
      if (rc)
539
 
        {
540
 
          cdk_stream_close (s);
541
 
          gnutls_assert ();
542
 
          return rc;
543
 
        }
 
539
        {
 
540
          cdk_stream_close (s);
 
541
          gnutls_assert ();
 
542
          return rc;
 
543
        }
544
544
    }
545
545
 
546
546
  cdk_stream_seek (s, 0);
547
547
  len = cdk_stream_get_length (s);
548
548
  if (!buf)
549
549
    {
550
 
      *r_nbytes = len;          /* Only return the length of the buffer */
 
550
      *r_nbytes = len;          /* Only return the length of the buffer */
551
551
      cdk_stream_close (s);
552
552
      return 0;
553
553
    }
580
580
 **/
581
581
cdk_error_t
582
582
cdk_kbnode_hash (cdk_kbnode_t node, digest_hd_st * md, int is_v4,
583
 
                 cdk_packet_type_t pkttype, int flags)
 
583
                 cdk_packet_type_t pkttype, int flags)
584
584
{
585
585
  cdk_packet_t pkt;
586
586
 
598
598
    {
599
599
      pkt = cdk_kbnode_find_packet (node, pkttype);
600
600
      if (!pkt)
601
 
        {
602
 
          gnutls_assert ();
603
 
          return CDK_Inv_Packet;
604
 
        }
 
601
        {
 
602
          gnutls_assert ();
 
603
          return CDK_Inv_Packet;
 
604
        }
605
605
    }
606
606
 
607
607
  switch (pkttype)