/*-
* Copyright (c) 2008-2014, Juniper Networks, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
__FBSDID("$FreeBSD$");
#include <netinet/in_systm.h>
#include <stand.h>
#include <net.h>
#include <string.h>
#include "bootstrap.h"
extern int pkgfs_init(const char *, struct fs_ops *);
extern void pkgfs_cleanup(void);
static char *inst_kernel;
static char **inst_modules;
static char *inst_rootfs;
static int
{
char *path;
int rel;
return (ENOMEM);
path[0] = '/';
return (0);
}
static int
{
char *s, *v;
count = 0;
v = val;
do {
count++;
s = strchr(v, ',');
} while (v != NULL);
return (ENOMEM);
if (s != NULL)
*s++ = '\0';
if (error)
return (error);
val = s;
}
return (0);
}
static int
{
int error;
if (fsize == -1)
return (errno);
/*
* Assume that if we read a whole buffer worth of data, we
* haven't read the entire file. In other words, the buffer
* size must always be larger than the file size. That way
* we can append a '\0' and use standard string operations.
* Return an error if this is not possible.
*/
return (ENOMEM);
error = 0;
break;
}
*val++ = '\0';
if (p == NULL) {
break;
}
*p++ = '\0';
tag = p;
}
return (error);
}
static void
cleanup(void)
{
u_int i;
if (inst_kernel != NULL) {
inst_kernel = NULL;
}
if (inst_modules != NULL) {
i = 0;
while (inst_modules[i] != NULL)
free(inst_modules[i++]);
inst_modules = NULL;
}
if (inst_rootfs != NULL) {
inst_rootfs = NULL;
}
}
/*
* usage: install URL
* where: URL = (tftp|file)://[host]/<package>
*/
static int
{
char *s, *currdev;
const char *devname;
if (s == NULL)
goto invalid_url;
i = s - pkgname;
devname = "net0";
proto = &tftp_fsops;
local = 0;
devname = "pxe0";
} else {
devname = "disk1";
proto = &dosfs_fsops;
}
local = 1;
} else
goto invalid_url;
s += 3;
if (*s == '\0')
goto invalid_url;
if (*s != '/' ) {
if (local)
goto invalid_url;
goto invalid_url;
*pkgname = '\0';
goto invalid_url;
*pkgname = '/';
} else
pkgname = s;
command_errmsg = "package name too long";
return (CMD_ERROR);
}
if (error) {
command_errmsg = "cannot open package";
goto fail;
}
/*
* Point of no return: unload anything that may have been
* loaded and prune the environment from harmful variables.
*/
unload();
unsetenv("vfs.root.mountfrom");
/*
* read the metatags file.
*/
if (fd != -1) {
if (error) {
command_errmsg = "cannot load metatags";
goto fail;
}
}
if (error) {
command_errmsg = "cannot load kernel from package";
goto fail;
}
i = 0;
if (error) {
command_errmsg = "cannot load module(s) from package";
goto fail;
}
i++;
}
command_errmsg = "cannot load root file system";
goto fail;
}
cleanup();
command_errmsg = "unable to start installation";
fail:
cleanup();
unload();
return (CMD_ERROR);
command_errmsg = "invalid URL";
return (CMD_ERROR);
}
static int
{
int argidx;
unsetenv("install_format");
argidx = 1;
while (1) {
"usage: install [--format] <URL>";
return (CMD_ERROR);
}
argidx++;
continue;
}
break;
}
}