download.c revision 2c9a247fb01631b3eb3b85a1127e72f0b60ae108
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include <libgen.h>
#include <fcntl.h>
#include <errno.h>
#include <cryptoutil.h>
#include "common.h"
#include <kmfapi.h>
int
{
int rv;
int opt;
extern int optind_av;
extern char *optarg_av;
int oclass = 0;
char *http_proxy = NULL;
int proxy_port = 0;
"t:(objtype)u:(url)h:(http_proxy)o:(outfile)d:(dir)")) != EOF) {
if (EMPTYSTRING(optarg_av))
return (PK_ERR_USAGE);
switch (opt) {
case 't':
if (oclass)
return (PK_ERR_USAGE);
return (PK_ERR_USAGE);
break;
case 'u':
if (url)
return (PK_ERR_USAGE);
break;
case 'h':
if (http_proxy)
return (PK_ERR_USAGE);
break;
case 'o':
if (outfile)
return (PK_ERR_USAGE);
break;
case 'd':
if (dir)
return (PK_ERR_USAGE);
break;
default:
"unrecognized download option '%s'\n"),
return (PK_ERR_USAGE);
}
}
/* No additional args allowed. */
if (argc) {
return (PK_ERR_USAGE);
}
/* Check the dir and outfile options */
/* If outfile is not specified, use the basename of URI */
}
"option value \n"));
return (PK_ERR_USAGE);
}
/* Check if the file exists and might be overwritten. */
gettext("Warning: file \"%s\" exists, "
"will be overwritten."), fullpath);
return (0);
}
}
/* URI MUST be specified */
rv = PK_ERR_USAGE;
goto end;
}
/*
* Get the http proxy from the command "http_proxy" option or the
* environment variable. The command option has a higher priority.
*/
if (http_proxy == NULL)
if (http_proxy != NULL) {
char *ptmp = http_proxy;
char *proxy_port_s;
if (proxy_port_s != NULL)
else
proxy_port = 8080;
}
/* If objtype is not specified, default to CRL */
if (oclass == 0) {
oclass = PK_CRL_OBJ;
}
rv = PK_ERR_USAGE;
goto end;
}
/* Now we are ready to download */
if (oclass & PK_CRL_OBJ) {
} else if (oclass & PK_CERT_OBJ) {
}
switch (rv) {
case KMF_ERR_BAD_URI:
gettext("Error in parsing URI\n"));
rv = PK_ERR_USAGE;
break;
case KMF_ERR_OPEN_FILE:
gettext("Error in opening file\n"));
rv = PK_ERR_USAGE;
break;
case KMF_ERR_WRITE_FILE:
gettext("Error in writing file\n"));
rv = PK_ERR_USAGE;
break;
case KMF_ERR_BAD_CRLFILE:
rv = PK_ERR_USAGE;
break;
case KMF_ERR_BAD_CERTFILE:
gettext("Not a certificate file\n"));
rv = PK_ERR_USAGE;
break;
case KMF_ERR_MEMORY:
gettext("Not enough memory\n"));
rv = PK_ERR_SYSTEM;
break;
default:
gettext("Error in downloading the file.\n"));
rv = PK_ERR_SYSTEM;
break;
}
goto end;
}
/*
* If the file is successfully downloaded, we also check the date.
* If the downloaded file is outdated, give a warning.
*/
if (oclass & PK_CRL_OBJ) {
} else { /* certificate */
goto end;
if (format == KMF_FORMAT_PEM) {
int len;
goto end;
}
}
end:
if (ch_rv == KMF_ERR_VALIDITY_PERIOD) {
gettext("Warning: the downloaded file is expired.\n"));
gettext("Warning: failed to check the validity.\n"));
}
if (fullpath)
(void) kmf_finalize(kmfhandle);
return (rv);
}