pki: Replace BUILD_FROM_FD with passing a chunk via BUILD_BLOB

This allows more than one builder to try parsing the data read from STDIN.
This commit is contained in:
Tobias Brunner
2013-10-23 17:20:39 +02:00
parent 46cded2627
commit 71c9565a3a
11 changed files with 54 additions and 74 deletions
+1 -42
View File
@@ -454,47 +454,12 @@ static void *load_from_file(char *file, credential_type_t type, int subtype,
return cred;
}
/**
* load the credential from a file descriptor
*/
static void *load_from_fd(int fd, credential_type_t type, int subtype,
identification_t *subject, x509_flag_t flags)
{
char buf[8096];
char *pos = buf;
ssize_t len, total = 0;
while (TRUE)
{
len = read(fd, pos, buf + sizeof(buf) - pos);
if (len < 0)
{
DBG1(DBG_LIB, "reading from file descriptor failed: %s",
strerror(errno));
return NULL;
}
if (len == 0)
{
break;
}
total += len;
if (total == sizeof(buf))
{
DBG1(DBG_LIB, "buffer too small to read from file descriptor");
return NULL;
}
}
return load_from_blob(chunk_create(buf, total), type, subtype,
subject, flags);
}
/**
* Load all kind of PEM encoded credentials.
*/
static void *pem_load(credential_type_t type, int subtype, va_list args)
{
char *file = NULL;
int fd = -1;
chunk_t pem = chunk_empty;
identification_t *subject = NULL;
int flags = 0;
@@ -506,9 +471,7 @@ static void *pem_load(credential_type_t type, int subtype, va_list args)
case BUILD_FROM_FILE:
file = va_arg(args, char*);
continue;
case BUILD_FROM_FD:
fd = va_arg(args, int);
continue;
case BUILD_BLOB:
case BUILD_BLOB_PEM:
pem = va_arg(args, chunk_t);
continue;
@@ -534,10 +497,6 @@ static void *pem_load(credential_type_t type, int subtype, va_list args)
{
return load_from_file(file, type, subtype, subject, flags);
}
if (fd != -1)
{
return load_from_fd(fd, type, subtype, subject, flags);
}
return NULL;
}