1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-09-24 15:31:41 +02:00

* options.h, keyserver.c (parse_keyserver_options): Remove duplicate code

from parse_keyserver_options by calling the generic parse_options.

* keyserver.c (keyserver_spawn, keyserver_refresh), g10.c (main), gpgv.c
(main), mainproc.c (check_sig_and_print), import.c (revocation_present):
Change all callers.
This commit is contained in:
David Shaw 2004-04-15 18:16:17 +00:00
parent 8c4607568d
commit d20a79dd07
7 changed files with 90 additions and 95 deletions

View File

@ -1,3 +1,13 @@
2004-04-15 David Shaw <dshaw@jabberwocky.com>
* options.h, keyserver.c (parse_keyserver_options): Remove
duplicate code from parse_keyserver_options by calling the generic
parse_options.
* keyserver.c (keyserver_spawn, keyserver_refresh), g10.c (main),
gpgv.c (main), mainproc.c (check_sig_and_print), import.c
(revocation_present): Change all callers.
2004-04-14 David Shaw <dshaw@jabberwocky.com>
* packet.h, getkey.c (fixup_uidnode, merge_selfsigs_subkey): Keep

View File

@ -1436,9 +1436,8 @@ main( int argc, char **argv )
opt.export_options=EXPORT_INCLUDE_ATTRIBUTES;
opt.keyserver_options.import_options=IMPORT_REPAIR_PKS_SUBKEY_BUG;
opt.keyserver_options.export_options=EXPORT_INCLUDE_ATTRIBUTES;
opt.keyserver_options.include_subkeys=1;
opt.keyserver_options.include_revoked=1;
opt.keyserver_options.try_dns_srv=1;
opt.keyserver_options.options=
KEYSERVER_INCLUDE_SUBKEYS|KEYSERVER_INCLUDE_REVOKED|KEYSERVER_TRY_DNS_SRV;
opt.verify_options=
VERIFY_SHOW_POLICY_URLS|VERIFY_SHOW_NOTATIONS|VERIFY_SHOW_KEYSERVER_URLS;
opt.trust_model=TM_AUTO;
@ -2212,8 +2211,11 @@ main( int argc, char **argv )
case oNoRandomSeedFile: use_random_seed = 0; break;
case oAutoKeyRetrieve:
case oNoAutoKeyRetrieve:
opt.keyserver_options.auto_key_retrieve=
(pargs.r_opt==oAutoKeyRetrieve);
if(pargs.r_opt==oAutoKeyRetrieve)
opt.keyserver_options.options|=KEYSERVER_AUTO_KEY_RETRIEVE;
else
opt.keyserver_options.options&=~KEYSERVER_AUTO_KEY_RETRIEVE;
deprecated_warning(configname,configlineno,
pargs.r_opt==oAutoKeyRetrieve?"--auto-key-retrieve":
"--no-auto-key-retrieve","--keyserver-options ",

View File

@ -141,7 +141,7 @@ main( int argc, char **argv )
i18n_init();
opt.command_fd = -1; /* no command fd */
opt.pgp2_workarounds = 1;
opt.keyserver_options.auto_key_retrieve = 1;
opt.keyserver_options.options|=KEYSERVER_AUTO_KEY_RETRIEVE;
opt.trust_model = TM_ALWAYS;
opt.batch = 1;

View File

@ -1692,7 +1692,8 @@ revocation_present(KBNODE keyblock)
/* No, so try and get it */
if(opt.keyserver
&& opt.keyserver_options.auto_key_retrieve)
&& (opt.keyserver_options.options
& KEYSERVER_AUTO_KEY_RETRIEVE))
{
log_info(_("WARNING: key %s may be revoked:"
" fetching revocation key %s\n"),

View File

@ -52,22 +52,20 @@ struct keyrec
int lines;
};
struct kopts
{
char *name;
int tell; /* tell remote process about this one */
int *flag;
} keyserver_opts[]=
{
{"include-revoked",1,&opt.keyserver_options.include_revoked},
{"include-disabled",1,&opt.keyserver_options.include_disabled},
{"include-subkeys",1,&opt.keyserver_options.include_subkeys},
{"keep-temp-files",0,&opt.keyserver_options.keep_temp_files},
{"refresh-add-fake-v3-keyids",0,&opt.keyserver_options.fake_v3_keyids},
{"auto-key-retrieve",0,&opt.keyserver_options.auto_key_retrieve},
{"try-dns-srv",1,&opt.keyserver_options.try_dns_srv},
{NULL}
};
/* Tell remote processes about these options */
#define REMOTE_TELL (KEYSERVER_INCLUDE_REVOKED|KEYSERVER_INCLUDE_DISABLED|KEYSERVER_INCLUDE_SUBKEYS|KEYSERVER_TRY_DNS_SRV)
static struct parse_options keyserver_opts[]=
{
{"include-revoked",KEYSERVER_INCLUDE_REVOKED,NULL},
{"include-disabled",KEYSERVER_INCLUDE_DISABLED,NULL},
{"include-subkeys",KEYSERVER_INCLUDE_SUBKEYS,NULL},
{"keep-temp-files",KEYSERVER_KEEP_TEMP_FILES,NULL},
{"refresh-add-fake-v3-keyids",KEYSERVER_ADD_FAKE_V3,NULL},
{"auto-key-retrieve",KEYSERVER_AUTO_KEY_RETRIEVE,NULL},
{"try-dns-srv",KEYSERVER_TRY_DNS_SRV,NULL},
{NULL,0,NULL}
};
static int keyserver_work(int action,STRLIST list,
KEYDB_SEARCH_DESC *desc,int count);
@ -79,69 +77,53 @@ parse_keyserver_options(char *options)
while((tok=argsep(&options,&arg)))
{
int i,hit=0;
if(tok[0]=='\0')
continue;
for(i=0;keyserver_opts[i].name;i++)
{
if(ascii_strcasecmp(tok,keyserver_opts[i].name)==0)
{
*(keyserver_opts[i].flag)=1;
hit=1;
break;
}
else if(ascii_strncasecmp("no-",tok,3)==0 &&
ascii_strcasecmp(&tok[3],keyserver_opts[i].name)==0)
{
*(keyserver_opts[i].flag)=0;
hit=1;
break;
}
}
/* We accept quite a few possible options here - some options to
handle specially, the keyserver_options list, and import and
export options that pertain to keyserver operations. */
/* These options need more than just a flag */
if(!hit)
{
if(ascii_strcasecmp(tok,"verbose")==0)
opt.keyserver_options.verbose++;
else if(ascii_strcasecmp(tok,"no-verbose")==0)
opt.keyserver_options.verbose--;
if(ascii_strcasecmp(tok,"verbose")==0)
opt.keyserver_options.verbose++;
else if(ascii_strcasecmp(tok,"no-verbose")==0)
opt.keyserver_options.verbose--;
#ifdef EXEC_TEMPFILE_ONLY
else if(ascii_strcasecmp(tok,"use-temp-files")==0 ||
ascii_strcasecmp(tok,"no-use-temp-files")==0)
log_info(_("WARNING: keyserver option \"%s\" is not used "
"on this platform\n"),tok);
else if(ascii_strcasecmp(tok,"use-temp-files")==0 ||
ascii_strcasecmp(tok,"no-use-temp-files")==0)
log_info(_("WARNING: keyserver option \"%s\" is not used "
"on this platform\n"),tok);
#else
else if(ascii_strcasecmp(tok,"use-temp-files")==0)
opt.keyserver_options.use_temp_files=1;
else if(ascii_strcasecmp(tok,"no-use-temp-files")==0)
opt.keyserver_options.use_temp_files=0;
else if(ascii_strcasecmp(tok,"use-temp-files")==0)
opt.keyserver_options.options|=KEYSERVER_USE_TEMP_FILES;
else if(ascii_strcasecmp(tok,"no-use-temp-files")==0)
opt.keyserver_options.options&=~KEYSERVER_USE_TEMP_FILES;
#endif
else
if(!parse_import_options(tok,
&opt.keyserver_options.import_options,0)
&&
!parse_export_options(tok,
&opt.keyserver_options.export_options,0))
{
if(arg)
{
char *joined;
else if(!parse_options(tok,&opt.keyserver_options.options,
keyserver_opts,0)
&& !parse_import_options(tok,
&opt.keyserver_options.import_options,0)
&& !parse_export_options(tok,
&opt.keyserver_options.export_options,0))
{
/* All of the standard options have failed, so the option is
destined for a keyserver plugin. */
joined=m_alloc(strlen(tok)+1+strlen(arg)+1);
/* Make a canonical name=value form with no
spaces */
strcpy(joined,tok);
strcat(joined,"=");
strcat(joined,arg);
add_to_strlist(&opt.keyserver_options.other,joined);
m_free(joined);
}
else
add_to_strlist(&opt.keyserver_options.other,tok);
}
if(arg)
{
char *joined;
joined=m_alloc(strlen(tok)+1+strlen(arg)+1);
/* Make a canonical name=value form with no
spaces */
strcpy(joined,tok);
strcat(joined,"=");
strcat(joined,arg);
add_to_strlist(&opt.keyserver_options.other,joined);
m_free(joined);
}
else
add_to_strlist(&opt.keyserver_options.other,tok);
}
}
}
@ -720,7 +702,7 @@ keyserver_spawn(int action,STRLIST list,
unsigned int maxlen,buflen;
char *command=NULL,*searchstr=NULL;
byte *line=NULL;
struct kopts *kopts;
struct parse_options *kopts;
struct exec_info *spawn;
assert(opt.keyserver);
@ -742,9 +724,9 @@ keyserver_spawn(int action,STRLIST list,
strcpy(command,"gpgkeys_");
strcat(command,opt.keyserver->scheme);
if(opt.keyserver_options.use_temp_files)
if(opt.keyserver_options.options&KEYSERVER_USE_TEMP_FILES)
{
if(opt.keyserver_options.keep_temp_files)
if(opt.keyserver_options.options&KEYSERVER_KEEP_TEMP_FILES)
{
command=m_realloc(command,strlen(command)+
strlen(KEYSERVER_ARGS_KEEP)+1);
@ -784,15 +766,13 @@ keyserver_spawn(int action,STRLIST list,
/* Write options */
for(i=0,kopts=keyserver_opts;kopts[i].name;i++)
if(*(kopts[i].flag) && kopts[i].tell)
if(opt.keyserver_options.options & kopts[i].bit & REMOTE_TELL)
fprintf(spawn->tochild,"OPTION %s\n",kopts[i].name);
for(i=0;i<opt.keyserver_options.verbose;i++)
fprintf(spawn->tochild,"OPTION verbose\n");
temp=opt.keyserver_options.other;
for(;temp;temp=temp->next)
for(temp=opt.keyserver_options.other;temp;temp=temp->next)
fprintf(spawn->tochild,"OPTION %s\n",temp->d);
switch(action)
@ -1423,7 +1403,7 @@ keyserver_refresh(STRLIST users)
/* If refresh_add_fake_v3_keyids is on and it's a HKP or MAILTO
scheme, then enable fake v3 keyid generation. */
if(opt.keyserver_options.fake_v3_keyids && opt.keyserver
if((opt.keyserver_options.options&KEYSERVER_ADD_FAKE_V3) && opt.keyserver
&& (ascii_strcasecmp(opt.keyserver->scheme,"hkp")==0 ||
ascii_strcasecmp(opt.keyserver->scheme,"mailto")==0))
fakev3=1;

View File

@ -1346,7 +1346,7 @@ check_sig_and_print( CTX c, KBNODE node )
rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey );
if( rc == G10ERR_NO_PUBKEY && opt.keyserver
&& opt.keyserver_options.auto_key_retrieve)
&& (opt.keyserver_options.options&KEYSERVER_AUTO_KEY_RETRIEVE))
{
if( keyserver_import_keyid ( sig->keyid )==0 )
rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey );

View File

@ -136,14 +136,7 @@ struct
struct
{
int verbose;
int include_revoked;
int include_disabled;
int include_subkeys;
int use_temp_files;
int keep_temp_files;
int fake_v3_keyids;
int auto_key_retrieve;
int try_dns_srv;
unsigned int options;
unsigned int import_options;
unsigned int export_options;
STRLIST other;
@ -266,4 +259,13 @@ struct
#define VERIFY_SHOW_VALIDITY (1<<4)
#define VERIFY_SHOW_UNUSABLE_UIDS (1<<5)
#define KEYSERVER_INCLUDE_REVOKED (1<<0)
#define KEYSERVER_INCLUDE_DISABLED (1<<1)
#define KEYSERVER_INCLUDE_SUBKEYS (1<<2)
#define KEYSERVER_USE_TEMP_FILES (1<<3)
#define KEYSERVER_KEEP_TEMP_FILES (1<<4)
#define KEYSERVER_ADD_FAKE_V3 (1<<5)
#define KEYSERVER_AUTO_KEY_RETRIEVE (1<<6)
#define KEYSERVER_TRY_DNS_SRV (1<<7)
#endif /*G10_OPTIONS_H*/