~ubuntu-dev/ubuntu/lucid/mutt/lucid-201002110857

« back to all changes in this revision

Viewing changes to gnupgparse.c

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-06-17 17:17:28 UTC
  • mfrom: (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090617171728-61dkl7w5fgn7ybdq
Tags: upstream-1.5.20
Import upstream version 1.5.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
  char *pend, *p;
124
124
  int trust = 0;
125
125
  int flags = 0;
 
126
  struct pgp_keyinfo tmp;
126
127
 
127
128
  *is_subkey = 0;
128
129
  if (!*buf)
129
130
    return NULL;
130
 
  
 
131
 
 
132
  /* if we're given a key, merge our parsing results, else
 
133
   * start with a fresh one to work with so that we don't
 
134
   * mess up the real key in case we find parsing errors. */
 
135
  if (k)
 
136
    memcpy (&tmp, k, sizeof (tmp));
 
137
  else
 
138
    memset (&tmp, 0, sizeof (tmp));
 
139
 
131
140
  dprint (2, (debugfile, "parse_pub_line: buf = `%s'\n", buf));
132
 
  
 
141
 
133
142
  for (p = buf; p; p = pend)
134
143
  {
135
144
    if ((pend = strchr (p, ':')))
143
152
      case 1:                   /* record type */
144
153
      {
145
154
        dprint (2, (debugfile, "record type: %s\n", p));
146
 
        
 
155
 
147
156
        if (!mutt_strcmp (p, "pub"))
148
157
          ;
149
158
        else if (!mutt_strcmp (p, "sub"))
156
165
          is_uid = 1;
157
166
        else
158
167
          return NULL;
159
 
        
 
168
 
160
169
        if (!(is_uid || (*is_subkey && option (OPTPGPIGNORESUB))))
161
 
          k = safe_calloc (sizeof *k, 1);
 
170
          memset (&tmp, 0, sizeof (tmp));
162
171
 
163
172
        break;
164
173
      }
165
174
      case 2:                   /* trust info */
166
175
      {
167
176
        dprint (2, (debugfile, "trust info: %s\n", p));
168
 
        
 
177
 
169
178
        switch (*p)
170
179
        {                               /* look only at the first letter */
171
180
          case 'e':
192
201
        }
193
202
 
194
203
        if (!is_uid && !(*is_subkey && option (OPTPGPIGNORESUB)))
195
 
          k->flags |= flags;
 
204
          tmp.flags |= flags;
196
205
 
197
206
        break;
198
207
      }
199
208
      case 3:                   /* key length  */
200
209
      {
201
 
        
202
210
        dprint (2, (debugfile, "key len: %s\n", p));
203
 
        
204
 
        if (!(*is_subkey && option (OPTPGPIGNORESUB)))
205
 
          k->keylen = atoi (p); /* fixme: add validation checks */
 
211
 
 
212
        if (!(*is_subkey && option (OPTPGPIGNORESUB)) &&
 
213
            mutt_atos (p, &tmp.keylen) < 0)
 
214
          goto bail;
206
215
        break;
207
216
      }
208
217
      case 4:                   /* pubkey algo */
209
218
      {
210
 
        
211
219
        dprint (2, (debugfile, "pubkey algorithm: %s\n", p));
212
 
        
 
220
 
213
221
        if (!(*is_subkey && option (OPTPGPIGNORESUB)))
214
222
        {
215
 
          k->numalg = atoi (p);
216
 
          k->algorithm = pgp_pkalgbytype (atoi (p));
 
223
          int x = 0;
 
224
          if (mutt_atoi (p, &x) < 0)
 
225
            goto bail;
 
226
          tmp.numalg = x;
 
227
          tmp.algorithm = pgp_pkalgbytype (x);
217
228
        }
218
229
        break;
219
230
      }
220
231
      case 5:                   /* 16 hex digits with the long keyid. */
221
232
      {
222
233
        dprint (2, (debugfile, "key id: %s\n", p));
223
 
        
 
234
 
224
235
        if (!(*is_subkey && option (OPTPGPIGNORESUB)))
225
 
          mutt_str_replace (&k->keyid, p);
 
236
          mutt_str_replace (&tmp.keyid, p);
226
237
        break;
227
238
 
228
239
      }
230
241
      {
231
242
        char tstr[11];
232
243
        struct tm time;
233
 
        
 
244
 
234
245
        dprint (2, (debugfile, "time stamp: %s\n", p));
235
 
        
 
246
 
236
247
        if (!p)
237
248
          break;
238
249
        time.tm_sec = 0;
240
251
        time.tm_hour = 12;
241
252
        strncpy (tstr, p, 11);
242
253
        tstr[4] = '\0';
243
 
        time.tm_year = atoi (tstr)-1900;
244
254
        tstr[7] = '\0';
245
 
        time.tm_mon = (atoi (tstr+5))-1;
246
 
        time.tm_mday = atoi (tstr+8);
247
 
        k->gen_time = mutt_mktime (&time, 0);
 
255
        if (mutt_atoi (tstr, &time.tm_year) < 0)
 
256
        {
 
257
          p = tstr;
 
258
          goto bail;
 
259
        }
 
260
        time.tm_year -= 1900;
 
261
        if (mutt_atoi (tstr+5, &time.tm_mon) < 0)
 
262
        {
 
263
          p = tstr+5;
 
264
          goto bail;
 
265
        }
 
266
        time.tm_mon -= 1;
 
267
        if (mutt_atoi (tstr+8, &time.tm_mday) < 0)
 
268
        {
 
269
          p = tstr+8;
 
270
          goto bail;
 
271
        }
 
272
        tmp.gen_time = mutt_mktime (&time, 0);
248
273
        break;
249
274
      }
250
275
      case 7:                   /* valid for n days */
261
286
        /* ignore user IDs on subkeys */
262
287
        if (!is_uid && (*is_subkey && option (OPTPGPIGNORESUB)))
263
288
          break;
264
 
        
 
289
 
265
290
        dprint (2, (debugfile, "user ID: %s\n", p));
266
 
        
 
291
 
267
292
        uid = safe_calloc (sizeof (pgp_uid_t), 1);
268
293
        fix_uid (p);
269
294
        uid->addr = safe_strdup (p);
270
295
        uid->trust = trust;
271
296
        uid->flags |= flags;
272
 
        uid->parent = k;
273
 
        uid->next = k->address;
274
 
        k->address = uid;
275
 
        
 
297
        uid->next = tmp.address;
 
298
        tmp.address = uid;
 
299
 
276
300
        if (strstr (p, "ENCR"))
277
 
          k->flags |= KEYFLAG_PREFER_ENCRYPTION;
 
301
          tmp.flags |= KEYFLAG_PREFER_ENCRYPTION;
278
302
        if (strstr (p, "SIGN"))
279
 
          k->flags |= KEYFLAG_PREFER_SIGNING;
 
303
          tmp.flags |= KEYFLAG_PREFER_SIGNING;
280
304
 
281
305
        break;
282
306
      }
308
332
             || !((flags & KEYFLAG_DISABLED)
309
333
                  || (flags & KEYFLAG_REVOKED)
310
334
                  || (flags & KEYFLAG_EXPIRED))))
311
 
          k->flags |= flags;
 
335
          tmp.flags |= flags;
312
336
 
313
337
        break;
314
338
      
316
340
        break;
317
341
    }
318
342
  }
 
343
 
 
344
  /* merge temp key back into real key */
 
345
  if (!(is_uid || (*is_subkey && option (OPTPGPIGNORESUB))))
 
346
    k = safe_malloc (sizeof (*k));
 
347
  memcpy (k, &tmp, sizeof (*k));
 
348
  /* fixup parentship of uids after mering the temp key into
 
349
   * the real key */
 
350
  if (tmp.address)
 
351
  {
 
352
    for (uid = k->address; uid; uid = uid->next)
 
353
      uid->parent = k;
 
354
  }
 
355
 
319
356
  return k;
 
357
 
 
358
bail:
 
359
  dprint(5,(debugfile,"parse_pub_line: invalid number: '%s'\n", p));
 
360
  return NULL;
320
361
}
321
362
 
322
363
pgp_key_t pgp_get_candidates (pgp_ring_t keyring, LIST * hints)
373
414
  if (ferror (fp))
374
415
    mutt_perror ("fgets");
375
416
 
376
 
  fclose (fp);
 
417
  safe_fclose (&fp);
377
418
  mutt_wait_filter (thepid);
378
419
 
379
420
  close (devnull);