* gpgkeys_ldap.c (get_key): Don't print keysize unless it's >0.
authorDavid Shaw <dshaw@jabberwocky.com>
Mon, 14 Oct 2002 19:02:11 +0000 (19:02 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Mon, 14 Oct 2002 19:02:11 +0000 (19:02 +0000)
(printquoted): Use %-encoding instead of \-encoding. (search_key): Use new
keyserver key listing format.

keyserver/ChangeLog
keyserver/gpgkeys_ldap.c

index 565545c..f300240 100644 (file)
@@ -1,3 +1,9 @@
+2002-10-14  David Shaw  <dshaw@jabberwocky.com>
+
+       * gpgkeys_ldap.c (get_key): Don't print keysize unless it's >0.
+       (printquoted): Use %-encoding instead of \-encoding.
+       (search_key): Use new keyserver key listing format.
+
 2002-10-08  David Shaw  <dshaw@jabberwocky.com>
 
        * gpgkeys_ldap.c (search_key, main): Make sure LDAP values are
index 10ace54..ad8f0cf 100644 (file)
@@ -110,9 +110,7 @@ int
 send_key(int *eof)
 {
   int err,gotit=0,keysize=1,ret=KEYSERVER_INTERNAL_ERROR;
-  char *dn=NULL;
-  char line[MAX_LINE];
-  char *key[2]={NULL,NULL};
+  char *dn=NULL,line[MAX_LINE],*key[2]={NULL,NULL};
   char keyid[17];
   LDAPMod mod, *attrs[2];
 
@@ -435,7 +433,8 @@ get_key(char *getkey)
                  vals=ldap_get_values(ldap,each,"pgpkeysize");
                  if(vals!=NULL)
                    {
-                     fprintf(console,"Key size:\t%d\n",atoi(vals[0]));
+                     if(atoi(vals[0])>0)
+                       fprintf(console,"Key size:\t%d\n",atoi(vals[0]));
                      ldap_value_free(vals);
                    }
 
@@ -485,7 +484,8 @@ get_key(char *getkey)
   return ret;
 }
 
-time_t ldap2epochtime(const char *timestr)
+time_t
+ldap2epochtime(const char *timestr)
 {
   struct tm pgptime;
 
@@ -508,12 +508,13 @@ time_t ldap2epochtime(const char *timestr)
   return mktime(&pgptime);
 }
 
-void printquoted(FILE *stream,char *string,char delim)
+void
+printquoted(FILE *stream,char *string,char delim)
 {
   while(*string)
     {
-      if(*string==delim || *string=='\\')
-       fprintf(stream,"\\x%02x",*string);
+      if(*string==delim || *string=='%')
+       fprintf(stream,"%%%02x",*string);
       else
        fputc(*string,stream);
 
@@ -567,103 +568,106 @@ search_key(char *searchkey)
   count=ldap_count_entries(ldap,res);
 
   if(count<1)
-    fprintf(output,"COUNT 0\n");
+    fprintf(output,"info:1:0\n");
   else
     {
-      fprintf(output,"COUNT %d\n",count);
+      fprintf(output,"info:1:%d\n",count);
 
       each=ldap_first_entry(ldap,res);
       while(each!=NULL)
        {
-         int flags=0;
+         fprintf(output,"pub:");
 
          vals=ldap_get_values(ldap,each,"pgpcertid");
          if(vals!=NULL)
            {
-             fprintf(output,"%s:",vals[0]);
+             fprintf(output,"%s",vals[0]);
              ldap_value_free(vals);
            }
-         else
-           fputc(':',output);
 
-         vals=ldap_get_values(ldap,each,"pgpuserid");
-         if(vals!=NULL)
-           {
-             /* Need to escape any colons */
-             printquoted(output,vals[0],':');
-             fputc(':',output);
-             ldap_value_free(vals);
-           }
-         else
-           fputc(':',output);
+         fputc(':',output);
 
-         vals=ldap_get_values(ldap,each,"pgprevoked");
+         vals=ldap_get_values(ldap,each,"pgpkeytype");
          if(vals!=NULL)
            {
-             if(atoi(vals[0])==1)
-               flags|=1;
+             /* The LDAP server doesn't exactly handle this well. */
+             if(strcasecmp(vals[0],"RSA")==0)
+               fprintf(output,"1");
+             else if(strcasecmp(vals[0],"DSS/DH")==0)
+               fprintf(output,"17");
              ldap_value_free(vals);
            }
 
-         vals=ldap_get_values(ldap,each,"pgpdisabled");
+         fputc(':',output);
+
+         vals=ldap_get_values(ldap,each,"pgpkeysize");
          if(vals!=NULL)
            {
-             if(atoi(vals[0])==1)
-               flags|=2;
+             /* Not sure why, but some keys are listed with a key size of
+                0.  Treat that like an unknown. */
+             if(atoi(vals[0])>0)
+               fprintf(output,"%d",atoi(vals[0]));
              ldap_value_free(vals);
            }
 
-         fprintf(output,"%d:",flags);
+         fputc(':',output);
 
          /* YYYYMMDDHHmmssZ */
 
          vals=ldap_get_values(ldap,each,"pgpkeycreatetime");
          if(vals!=NULL && strlen(vals[0])==15)
            {
-             fprintf(output,"%u:",(unsigned int)ldap2epochtime(vals[0]));
+             fprintf(output,"%u",(unsigned int)ldap2epochtime(vals[0]));
              ldap_value_free(vals);
            }
-         else
-           fputc(':',output);
+
+         fputc(':',output);
 
          vals=ldap_get_values(ldap,each,"pgpkeyexpiretime");
          if(vals!=NULL && strlen(vals[0])==15)
            {
-             fprintf(output,"%u:",(unsigned int)ldap2epochtime(vals[0]));
+             fprintf(output,"%u",(unsigned int)ldap2epochtime(vals[0]));
              ldap_value_free(vals);
            }
-         else
-           fputc(':',output);
 
-         vals=ldap_get_values(ldap,each,"modifytimestamp");
-         if(vals!=NULL && strlen(vals[0])==15)
+         fputc(':',output);
+
+         vals=ldap_get_values(ldap,each,"pgprevoked");
+         if(vals!=NULL)
            {
-             fprintf(output,"%u:",(unsigned int)ldap2epochtime(vals[0]));
+             if(atoi(vals[0])==1)
+               fprintf(output,"r");
              ldap_value_free(vals);
            }
-         else
-           fputc(':',output);
 
-         vals=ldap_get_values(ldap,each,"pgpkeytype");
+         vals=ldap_get_values(ldap,each,"pgpdisabled");
          if(vals!=NULL)
            {
-             fprintf(output,"%s:",vals[0]);
+             if(atoi(vals[0])==1)
+               fprintf(output,"d");
              ldap_value_free(vals);
            }
-         else
-           fputc(':',output);
 
-         vals=ldap_get_values(ldap,each,"pgpkeysize");
+         fputc(':',output);
+
+         vals=ldap_get_values(ldap,each,"modifytimestamp");
+         if(vals!=NULL && strlen(vals[0])==15)
+           {
+             fprintf(output,"%u",(unsigned int)ldap2epochtime(vals[0]));
+             ldap_value_free(vals);
+           }
+
+         fprintf(output,"\nuid:");
+
+         vals=ldap_get_values(ldap,each,"pgpuserid");
          if(vals!=NULL)
            {
-             /* Not sure why, but some keys are listed with a key size of
-                0.  Treat that like an unknown. */
-             if(atoi(vals[0])>0)
-               fprintf(output,"%d",atoi(vals[0]));
+             /* Need to escape any colons */
+             printquoted(output,vals[0],':');
              ldap_value_free(vals);
            }
 
-         fputc('\n',output);
+         fprintf(output,"\n");
 
          each=ldap_next_entry(ldap,each);
        }
@@ -700,7 +704,8 @@ fail_all(struct keylist *keylist,int action,int err)
       }
 }
 
-int main(int argc,char *argv[])
+int
+main(int argc,char *argv[])
 {
   int port=0,arg,err,action=-1,ret=KEYSERVER_INTERNAL_ERROR;
   char line[MAX_LINE],**vals;
@@ -796,7 +801,7 @@ int main(int argc,char *argv[])
 
       if(sscanf(line,"VERSION %d\n",&version)==1)
        {
-         if(version!=0)
+         if(version!=KEYSERVER_PROTO_VERSION)
            {
              ret=KEYSERVER_VERSION_ERROR;
              goto fail;
@@ -904,7 +909,7 @@ int main(int argc,char *argv[])
 
   /* Send the response */
 
-  fprintf(output,"VERSION 0\n");
+  fprintf(output,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
   fprintf(output,"PROGRAM %s\n\n",VERSION);
 
   if(verbose>1)
@@ -916,6 +921,8 @@ int main(int argc,char *argv[])
              action==SEND?"SEND":"SEARCH");
     }
 
+  /* Note that this tries all A records on a given host (or at least,
+     OpenLDAP does). */
   ldap=ldap_init(host,port);
   if(ldap==NULL)
     {