misc.c revision f48205be61a214698b763ff550ab9e657525104c
/*
* 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
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <assert.h>
#include <alloca.h>
#include <errno.h>
#include <fcntl.h>
#include <strings.h>
#include <macros.h>
#include <sys/sysmacros.h>
#include <sys/systeminfo.h>
#include <sys/lx_types.h>
#include <sys/lx_debug.h>
#include <sys/lx_syscall.h>
#include <sys/lx_thunk_server.h>
#include <unistd.h>
#include <libintl.h>
extern int sethostname(char *, int);
/* ARGUSED */
int
{
int ret;
if (ret < 0) {
/*
* If rename(2) failed and we're in install mode, return
* success if the the reason we failed was either because the
* source file didn't actually exist or if it was because we
* tried to rename it to be the name of a device currently in
* use (resulting in an EBUSY.)
*
* To help install along further, if the failure was due
* to an EBUSY, delete the original file so we don't leave
* extra files lying around.
*/
if (lx_install != 0) {
return (0);
return (0);
}
}
return (-errno);
}
return (0);
}
/*ARGSUSED*/
int
{
int rc;
if (magic != LINUX_REBOOT_MAGIC1)
return (-EINVAL);
return (-EINVAL);
if (geteuid() != 0)
return (-EPERM);
switch (flag) {
case LINUX_REBOOT_CMD_CAD_ON:
case LINUX_REBOOT_CMD_CAD_OFF:
/* ignored */
rc = 0;
break;
case LINUX_REBOOT_CMD_HALT:
break;
case LINUX_REBOOT_CMD_RESTART:
/* RESTART2 may need more work */
break;
default:
return (-EINVAL);
}
}
/*
* getcwd() - Linux syscall semantics are slightly different; we need to return
* the length of the pathname copied (+ 1 for the terminating NULL byte.)
*/
int
{
char *buf;
return (-errno);
/*
* We need the length of the pathname getcwd() copied but we never want
* to dereference a Linux pointer for any reason.
*
* Thus, to get the string length we will uucopy() up to copylen bytes
* at a time into a local buffer and will walk each chunk looking for
* the string-terminating NULL byte.
*
* We can use strlen() to find the length of the string in the
* local buffer by delimiting the buffer with a NULL byte in the
* last element that will never be overwritten.
*/
return (-ENOMEM);
for (;;) {
return (-errno);
/*
* If the strlen() is less than copylen, we found the
* real end of the string -- not the NULL byte used to
* delimit the end of our buffer.
*/
break;
/* prepare to check the next chunk of the string */
}
return (len + 1);
}
int
{
return (-errno);
else
return (0);
}
/*
* {get,set}groups16() - Handle the conversion between 16-bit Linux gids and
* 32-bit Solaris gids.
*/
int
{
int ret;
int i;
if (grouplist32 == NULL)
return (-ENOMEM);
return (-errno);
for (i = 0; i < ret; i++)
return (ret);
}
int
{
int i;
if (grouplist32 == NULL)
return (-ENOMEM);
for (i = 0; i < count; i++)
}
/*
* personality() - Solaris doesn't support Linux personalities, but we have to
* emulate enough to show that we support the basic personality.
*/
#define LX_PER_LINUX 0x0
int
{
switch (per) {
case -1:
/* Request current personality */
return (LX_PER_LINUX);
case LX_PER_LINUX:
return (0);
default:
return (-EINVAL);
}
}
/*
* mknod() - Since we don't have the SYS_CONFIG privilege within a zone, the
* only mode we have to support is S_IFIFO. We also have to distinguish between
* an invalid type and insufficient privileges.
*/
#define LX_S_IFMT 0170000
#define LX_S_IFDIR 0040000
#define LX_S_IFCHR 0020000
#define LX_S_IFBLK 0060000
#define LX_S_IFREG 0100000
#define LX_S_IFIFO 0010000
#define LX_S_IFLNK 0120000
#define LX_S_IFSOCK 0140000
/*ARGSUSED*/
int
{
struct sockaddr_un sockaddr;
int fd;
switch (type) {
case 0:
case LX_S_IFREG:
/* create a regular file */
return (-EEXIST);
return (-errno);
return (-errno);
return (0);
case LX_S_IFSOCK:
/*
* Create a UNIX domain socket.
*
* Most programmers aren't even aware you can do this.
*
* Note you can also do this via Solaris' mknod(2), but
* Linux allows anyone who can create a UNIX domain
* socket via bind(2) to create one via mknod(2);
* Solaris requires the caller to be privileged.
*/
return (-errno);
return (-EEXIST);
return (-errno);
return (-errno);
/* assure NULL termination of sockaddr.sun_path */
sizeof (sockaddr.sun_family)) < 0)
return (-errno);
return (0);
case LX_S_IFIFO:
dev = 0;
break;
case LX_S_IFCHR:
case LX_S_IFBLK:
/*
* The "dev" RPM package wants to create all possible Linux
* device nodes, so just report its mknod()s as having
* succeeded if we're in install mode.
*/
if (lx_install != 0) {
lx_debug("lx_mknod: install mode spoofed creation of "
"Linux device [%lld, %lld]\n",
return (0);
}
break;
default:
return (-EINVAL);
}
}
int
{
}
int
{
long rval;
return (-EINVAL);
}
int
lx_getpid(void)
{
int pid;
/* First call the thunk server hook. */
if (lxt_server_pid(&pid) != 0)
return (pid);
}
int
{
char path[64];
/* First call the thunk server hook. */
/* Get a copy of the executable we're trying to run */
path[0] = '\0';
/* Check if we're trying to run a native binary */
sizeof (path)) == 0) {
/* Skip the first element in the argv array */
argv++;
/*
* The name of the new program to execute was the first
* parameter passed to lx_native.
*/
return (-errno);
return (-errno);
}
/* This is a normal exec call. */
return (-errno);
}
int
{
int i, r;
if (ng > 0) {
return (-ENOMEM);
return (-errno);
/*
* Linux doesn't check the validity of the group IDs, but
* Solaris does. Change any invalid group IDs to a known, valid
* value (yuck).
*/
for (i = 0; i < ng; i++) {
}
}
return ((r == -1) ? -errno : r);
}