summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <dshaw@jabberwocky.com>2002-10-09 04:03:22 +0200
committerDavid Shaw <dshaw@jabberwocky.com>2002-10-09 04:03:22 +0200
commit7a3e9403009aa66daec15074938966089d85edf6 (patch)
treea5ee192ac2a13af2796b415bc76a7b43262af6bd
parent* keyserver.h: Add new error code KEYSERVER_UNREACHABLE. (diff)
downloadgnupg2-7a3e9403009aa66daec15074938966089d85edf6.tar.xz
gnupg2-7a3e9403009aa66daec15074938966089d85edf6.zip
* gpgkeys_ldap.c (fail_all): New function to unwind a keylist and error
each item. (main): Call fail_all from here, as needed. Also add a NO_MEMORY error in an appropriate place and fix error return code. (ldap_err_to_gpg_err): Add KEYSERVER_UNREACHABLE. * gpgkeys_hkp.c (fail_all): New function to unwind a keylist and error each item. (main): Call fail_all from here. Also add a NO_MEMORY error in an appropriate place. (get_key): Use new UNREACHABLE error for network errors.
-rw-r--r--keyserver/ChangeLog14
-rw-r--r--keyserver/gpgkeys_hkp.c34
-rw-r--r--keyserver/gpgkeys_ldap.c43
3 files changed, 85 insertions, 6 deletions
diff --git a/keyserver/ChangeLog b/keyserver/ChangeLog
index c0a3acb97..ec44ee9b2 100644
--- a/keyserver/ChangeLog
+++ b/keyserver/ChangeLog
@@ -1,3 +1,17 @@
+2002-10-08 David Shaw <dshaw@jabberwocky.com>
+
+ * gpgkeys_ldap.c (fail_all): New function to unwind a keylist and
+ error each item.
+ (main): Call fail_all from here, as needed. Also add a NO_MEMORY
+ error in an appropriate place and fix error return code.
+ (ldap_err_to_gpg_err): Add KEYSERVER_UNREACHABLE.
+
+ * gpgkeys_hkp.c (fail_all): New function to unwind a keylist and
+ error each item.
+ (main): Call fail_all from here. Also add a NO_MEMORY error in an
+ appropriate place.
+ (get_key): Use new UNREACHABLE error for network errors.
+
2002-09-26 Werner Koch <wk@gnupg.org>
* gpgkeys_ldap.c (send_key): Removed non-constant initializers.
diff --git a/keyserver/gpgkeys_hkp.c b/keyserver/gpgkeys_hkp.c
index 0c701a3e8..2495d50ba 100644
--- a/keyserver/gpgkeys_hkp.c
+++ b/keyserver/gpgkeys_hkp.c
@@ -254,7 +254,8 @@ get_key(char *getkey)
{
fprintf(console,"gpgkeys: HKP fetch error: %s\n",
rc==G10ERR_NETWORK?strerror(errno):g10_errstr(rc));
- fprintf(output,"KEY 0x%s FAILED %d\n",getkey,KEYSERVER_INTERNAL_ERROR);
+ fprintf(output,"KEY 0x%s FAILED %d\n",getkey,
+ rc==G10ERR_NETWORK?KEYSERVER_UNREACHABLE:KEYSERVER_INTERNAL_ERROR);
}
else
{
@@ -682,6 +683,30 @@ search_key(char *searchkey)
return ret;
}
+void
+fail_all(struct keylist *keylist,int action,int err)
+{
+ if(!keylist)
+ return;
+
+ if(action==SEARCH)
+ {
+ fprintf(output,"SEARCH ");
+ while(keylist)
+ {
+ fprintf(output,"%s ",keylist->str);
+ keylist=keylist->next;
+ }
+ fprintf(output,"FAILED %d\n",err);
+ }
+ else
+ while(keylist)
+ {
+ fprintf(output,"KEY %s FAILED %d\n",keylist->str,err);
+ keylist=keylist->next;
+ }
+}
+
int
main(int argc,char *argv[])
{
@@ -856,6 +881,7 @@ main(int argc,char *argv[])
{
fprintf(console,"gpgkeys: out of memory while "
"building key list\n");
+ ret=KEYSERVER_NO_MEMORY;
goto fail;
}
@@ -960,7 +986,11 @@ main(int argc,char *argv[])
searchkey=malloc(len+1);
if(searchkey==NULL)
- goto fail;
+ {
+ ret=KEYSERVER_NO_MEMORY;
+ fail_all(keylist,action,KEYSERVER_NO_MEMORY);
+ goto fail;
+ }
searchkey[0]='\0';
diff --git a/keyserver/gpgkeys_ldap.c b/keyserver/gpgkeys_ldap.c
index 0aba452b9..7772bd43c 100644
--- a/keyserver/gpgkeys_ldap.c
+++ b/keyserver/gpgkeys_ldap.c
@@ -69,6 +69,10 @@ ldap_err_to_gpg_err(int err)
ret=KEYSERVER_KEY_EXISTS;
break;
+ case LDAP_SERVER_DOWN:
+ ret=KEYSERVER_UNREACHABLE;
+ break;
+
default:
ret=KEYSERVER_GENERAL_ERROR;
break;
@@ -670,6 +674,30 @@ search_key(char *searchkey)
return KEYSERVER_OK;
}
+void
+fail_all(struct keylist *keylist,int action,int err)
+{
+ if(!keylist)
+ return;
+
+ if(action==SEARCH)
+ {
+ fprintf(output,"SEARCH ");
+ while(keylist)
+ {
+ fprintf(output,"%s ",keylist->str);
+ keylist=keylist->next;
+ }
+ fprintf(output,"FAILED %d\n",err);
+ }
+ else
+ while(keylist)
+ {
+ fprintf(output,"KEY %s FAILED %d\n",keylist->str,err);
+ keylist=keylist->next;
+ }
+}
+
int main(int argc,char *argv[])
{
int port=0,arg,err,action=-1,ret=KEYSERVER_INTERNAL_ERROR;
@@ -844,6 +872,7 @@ int main(int argc,char *argv[])
{
fprintf(console,"gpgkeys: out of memory while "
"building key list\n");
+ ret=KEYSERVER_NO_MEMORY;
goto fail;
}
@@ -888,7 +917,9 @@ int main(int argc,char *argv[])
ldap=ldap_init(host,port);
if(ldap==NULL)
{
- fprintf(console,"gpgkeys: internal LDAP init error: %s\n",strerror(errno));
+ fprintf(console,"gpgkeys: internal LDAP init error: %s\n",
+ strerror(errno));
+ fail_all(keylist,action,KEYSERVER_INTERNAL_ERROR);
goto fail;
}
@@ -897,6 +928,7 @@ int main(int argc,char *argv[])
{
fprintf(console,"gpgkeys: internal LDAP bind error: %s\n",
ldap_err2string(err));
+ fail_all(keylist,action,ldap_err_to_gpg_err(err));
goto fail;
}
@@ -904,16 +936,18 @@ int main(int argc,char *argv[])
err=ldap_search_s(ldap,"cn=PGPServerInfo",LDAP_SCOPE_BASE,
"(objectclass=*)",attrs,0,&res);
- if(err==-1)
+ if(err!=0)
{
fprintf(console,"gpgkeys: error retrieving LDAP server info: %s\n",
ldap_err2string(err));
+ fail_all(keylist,action,ldap_err_to_gpg_err(err));
goto fail;
}
if(ldap_count_entries(ldap,res)!=1)
{
fprintf(console,"gpgkeys: more than one serverinfo record\n");
+ fail_all(keylist,action,KEYSERVER_INTERNAL_ERROR);
goto fail;
}
@@ -951,14 +985,14 @@ int main(int argc,char *argv[])
if(vals!=NULL)
{
basekeyspacedn=strdup(vals[0]);
+ ldap_value_free(vals);
if(basekeyspacedn==NULL)
{
fprintf(console,"gpgkeys: can't allocate string space "
"for LDAP base\n");
+ fail_all(keylist,action,KEYSERVER_NO_MEMORY);
goto fail;
}
-
- ldap_value_free(vals);
}
ldap_msgfree(res);
@@ -1011,6 +1045,7 @@ int main(int argc,char *argv[])
if(searchkey==NULL)
{
ret=KEYSERVER_NO_MEMORY;
+ fail_all(keylist,action,KEYSERVER_NO_MEMORY);
goto fail;
}