1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

dirmngr: Fix lost flags during LDAP upload

* dirmngr/ldapserver.c (ldapserver_parse_one): Turn LINE into a const.
Use strtokenize instead of strtok style parsing.
--

This fixes a problem with resulted in a General Error for the second
key to be uploaded in the same session.  But only if the colon format
to specify a keyserver with flags was used.
This commit is contained in:
Werner Koch 2022-09-28 15:40:22 +02:00
parent 1b0c17dfab
commit 536b5cd663
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 18 additions and 15 deletions

View File

@ -69,18 +69,17 @@ ldapserver_list_free (ldap_server_t servers)
* FILENAME and LINENO are used for diagnostic purposes only. * FILENAME and LINENO are used for diagnostic purposes only.
*/ */
ldap_server_t ldap_server_t
ldapserver_parse_one (char *line, ldapserver_parse_one (const char *line,
const char *filename, unsigned int lineno) const char *filename, unsigned int lineno)
{ {
char *p; char *p;
char *endp;
const char *s; const char *s;
ldap_server_t server; ldap_server_t server;
int fieldno; int fieldno;
int fail = 0; int fail = 0;
int i; int i;
char **fields = NULL;
/* Parse the colon separated fields. */
server = xtrycalloc (1, sizeof *server); server = xtrycalloc (1, sizeof *server);
if (!server) if (!server)
{ {
@ -88,32 +87,35 @@ ldapserver_parse_one (char *line,
goto leave; goto leave;
} }
for (fieldno = 1, p = line; p; p = endp, fieldno++ ) fields = strtokenize (line, ":");
if (!fields)
{
fail = 1;
goto leave;
}
for (fieldno=0; (p = fields[fieldno]); fieldno++)
{ {
endp = strchr (p, ':');
if (endp)
*endp++ = '\0';
trim_spaces (p);
switch (fieldno) switch (fieldno)
{ {
case 1: case 0:
server->host = xtrystrdup (p); server->host = xtrystrdup (p);
if (!server->host) if (!server->host)
fail = 1; fail = 1;
break; break;
case 2: case 1:
if (*p) if (*p)
server->port = atoi (p); server->port = atoi (p);
break; break;
case 3: case 2:
server->user = xtrystrdup (p); server->user = xtrystrdup (p);
if (!server->user) if (!server->user)
fail = 1; fail = 1;
break; break;
case 4: case 3:
if (*p && !server->user) if (*p && !server->user)
{ {
if (filename) if (filename)
@ -131,7 +133,7 @@ ldapserver_parse_one (char *line,
} }
break; break;
case 5: case 4:
if (*p) if (*p)
{ {
server->base = xtrystrdup (p); server->base = xtrystrdup (p);
@ -140,7 +142,7 @@ ldapserver_parse_one (char *line,
} }
break; break;
case 6: case 5:
{ {
char **flags = NULL; char **flags = NULL;
@ -211,6 +213,7 @@ ldapserver_parse_one (char *line,
ldapserver_list_free (server); ldapserver_list_free (server);
server = NULL; server = NULL;
} }
xfree (fields);
return server; return server;
} }

View File

@ -26,7 +26,7 @@
void ldapserver_list_free (ldap_server_t servers); void ldapserver_list_free (ldap_server_t servers);
ldap_server_t ldapserver_parse_one (char *line, ldap_server_t ldapserver_parse_one (const char *line,
const char *filename, unsigned int lineno); const char *filename, unsigned int lineno);