* 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.
This commit is contained in:
David Shaw 2002-10-09 02:03:22 +00:00
parent 9c011f8280
commit 7a3e940300
3 changed files with 85 additions and 6 deletions

View File

@ -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.

View File

@ -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';

View File

@ -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;
}