~ubuntu-branches/ubuntu/vivid/gnupg/vivid

« back to all changes in this revision

Viewing changes to util/pka.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-12-04 22:26:16 UTC
  • mfrom: (1.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20121204222616-cr0fow26geq90l3y
Tags: 1.4.12-6ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Disable mlock() test since it fails with ulimit 0 (on buildds).
  - Set gpg (or gpg2) and gpgsm to use a passphrase agent by default.
  - Only suggest gnupg-curl and libldap; recommendations are pulled into
    minimal, and we don't need the keyserver utilities in a minimal Ubuntu
    system.
  - Remove the Win32 build.
  - Update config.guess/config.sub for aarch64.
* Dropped patches:
  - Fix udeb build failure on powerpc, building with -O2 instead of -Os.
    (No longer seems to be necessary.)
* Simplify removal of Win32 build, to make this easier to merge in future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
/* Parse the TXT resource record. Format is:
52
52
 
53
53
   v=pka1;fpr=a4d94e92b0986ab5ee9dcd755de249965b0358a2;uri=string
54
 
   
 
54
 
55
55
   For simplicity white spaces are not allowed.  Because we expect to
56
56
   use a new RRTYPE for this in the future we define the TXT really
57
57
   strict for simplicity: No white spaces, case sensitivity of the
74
74
  *pend++ = 0;
75
75
  if (strcmp (p, "v=pka1"))
76
76
    return -1; /* Wrong or missing version. */
77
 
  
 
77
 
78
78
  p = pend;
79
79
  pend = strchr (p, ';');
80
80
  if (pend)
86
86
    fpr[i] = xtoi_2 (p);
87
87
  if (i != 20)
88
88
    return -1; /* Fingerprint consists not of exactly 40 hexbytes. */
89
 
    
 
89
 
90
90
  p = pend;
91
91
  if (!p || !*p)
92
92
    {
93
 
      *buffer = 0;  
 
93
      *buffer = 0;
94
94
      return 0; /* Success (no URI given). */
95
95
    }
96
96
  if (strncmp (p, "uri=", 4))
116
116
char *
117
117
get_pka_info (const char *address, unsigned char *fpr)
118
118
{
119
 
  unsigned char answer[PACKETSZ];
 
119
  union
 
120
    {
 
121
      signed char p[PACKETSZ];
 
122
      HEADER h;
 
123
    } answer;
120
124
  int anslen;
121
 
  int qdcount, ancount, nscount, arcount;
 
125
  int qdcount, ancount;
122
126
  int rc;
123
127
  unsigned char *p, *pend;
124
128
  const char *domain;
133
137
  memcpy (name, address, domain - address);
134
138
  strcpy (stpcpy (name + (domain-address), "._pka."), domain+1);
135
139
 
136
 
  anslen = res_query (name, C_IN, T_TXT, answer, PACKETSZ);
 
140
  anslen = res_query (name, C_IN, T_TXT, answer.p, PACKETSZ);
137
141
  xfree (name);
138
142
  if (anslen < sizeof(HEADER))
139
143
    return NULL; /* DNS resolver returned a too short answer. */
140
 
  if ( (rc=((HEADER*)answer)->rcode) != NOERROR )
 
144
  if ( (rc=answer.h.rcode) != NOERROR )
141
145
    return NULL; /* DNS resolver returned an error. */
142
146
 
143
147
  /* We assume that PACKETSZ is large enough and don't do dynmically
145
149
  if (anslen > PACKETSZ)
146
150
    return NULL; /* DNS resolver returned a too long answer */
147
151
 
148
 
  qdcount = ntohs (((HEADER*)answer)->qdcount);
149
 
  ancount = ntohs (((HEADER*)answer)->ancount);
150
 
  nscount = ntohs (((HEADER*)answer)->nscount);
151
 
  arcount = ntohs (((HEADER*)answer)->arcount);
 
152
  qdcount = ntohs (answer.h.qdcount);
 
153
  ancount = ntohs (answer.h.ancount);
152
154
 
153
155
  if (!ancount)
154
156
    return NULL; /* Got no answer. */
155
157
 
156
 
  p = answer + sizeof (HEADER);
157
 
  pend = answer + anslen; /* Actually points directly behind the buffer. */
 
158
  p = answer.p + sizeof (HEADER);
 
159
  pend = answer.p + anslen; /* Actually points directly behind the buffer. */
158
160
 
159
161
  while (qdcount-- && p < pend)
160
162
    {
161
163
      rc = dn_skipname (p, pend);
162
164
      if (rc == -1)
163
165
        return NULL;
164
 
      p += rc + QFIXEDSZ; 
 
166
      p += rc + QFIXEDSZ;
165
167
    }
166
168
 
167
169
  if (ancount > 1)