freebsd-dev/sys/i386/ibcs2/ibcs2_other.c
Steven Wallace 473fbdbe96 Add a hack to emulator to emulat spx device for local X connections.
This is truly a hack.  The idea is taken from the Linux ibcs2 emulator.

To use this feature, you must use the option,
	options		SPX_HACK
in your config.

Also, in /compat/ibcs2/dev, you must do:

lrwxr-xr-x  1 root  wheel         9 Oct 15 22:20 X0R@ -> /dev/null
lrwxr-xr-x  1 root  wheel         7 Oct 15 22:20 nfsd@ -> socksys
lrwxr-xr-x  1 root  wheel         9 Oct 15 22:20 socksys@ -> /dev/null
crw-rw-rw-  1 root  wheel   41,   1 Oct 15 22:14 spx

Do NOT use old socksys driver as that has been removed.
This hack needs /compat/ibcs2/dev/spx to be any device that does NOT
exist/configured (so the now non-existant spx major/minor works fine).
When an open() is called, the error ENXIO is checked and then the
path is checked.  If spx open detected, then a unix socket is opened
to the hardcoded path "/tmp/.X11-unix/X0".

As the Linux hacker author mentioned, the real way would be to detect
the getmsg/putmsg through /dev/X0R and /dev/spx.  Until this true
solution is implemented (if ever), I think this hack is important
enough to be put into the tree, even though I don't like it dirtying
up my clean code (which is what #ifdef SPX_HACK is for).
1995-10-16 05:52:55 +00:00

123 lines
3.3 KiB
C

/*
* Copyright (c) 1995 Steven Wallace
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* 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.
*
* $Id$
*/
/*
* IBCS2 compatibility module.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/kernel.h>
#include <i386/ibcs2/ibcs2_types.h>
#include <i386/ibcs2/ibcs2_signal.h>
#include <i386/ibcs2/ibcs2_util.h>
#include <i386/ibcs2/ibcs2_proto.h>
#define IBCS2_SECURE_GETLUID 1
#define IBCS2_SECURE_SETLUID 2
int
ibcs2_secure(struct proc *p, struct ibcs2_secure_args *uap, int *retval)
{
switch (uap->cmd) {
case IBCS2_SECURE_GETLUID: /* get login uid */
*retval = p->p_ucred->cr_uid;
return 0;
case IBCS2_SECURE_SETLUID: /* set login uid */
return EPERM;
default:
printf("IBCS2: 'secure' cmd=%d not implemented\n", uap->cmd);
}
return EINVAL;
}
int
ibcs2_lseek(struct proc *p, register struct ibcs2_lseek_args *uap, int *retval)
{
struct lseek_args largs;
off_t lret;
int error;
largs.fd = uap->fd;
largs.offset = uap->offset;
largs.whence = uap->whence;
error = lseek(p, &largs, (int *)&lret);
*(long *)retval = lret;
return (error);
}
#ifdef SPX_HACK
#include <sys/socket.h>
#include <sys/un.h>
int
spx_open(struct proc *p, void *uap, int *retval)
{
struct socket_args sock;
struct connect_args conn;
struct sockaddr_un *Xaddr;
caddr_t name;
int fd, error;
caddr_t sg = stackgap_init();
/* obtain a socket. */
DPRINTF(("SPX: open socket\n"));
sock.domain = AF_UNIX;
sock.type = SOCK_STREAM;
sock.protocol = 0;
error = socket(p, &sock, retval);
if (error)
return error;
/* connect the socket to standard X socket */
DPRINTF(("SPX: connect to /tmp/X11-unix/X0\n"));
Xaddr = stackgap_alloc(&sg, sizeof(struct sockaddr_un));
Xaddr->sun_family = AF_UNIX;
Xaddr->sun_len = sizeof(struct sockaddr_un) - sizeof(Xaddr->sun_path) +
strlen(Xaddr->sun_path) + 1;
copyout("/tmp/.X11-unix/X0", Xaddr->sun_path, 18);
conn.s = fd = *retval;
conn.name = (caddr_t)Xaddr;
conn.namelen = sizeof(struct sockaddr_un);
error = connect(p, &conn, retval);
if (error) {
struct close_args cl;
cl.fd = fd;
close(p, &cl, retval);
return error;
}
*retval = fd;
return 0;
}
#endif /* SPX_HACK */