ibcs2_other.c revision 11527
111397Sswallace/*
211397Sswallace * Copyright (c) 1995 Steven Wallace
311397Sswallace * All rights reserved.
411397Sswallace *
511397Sswallace * Redistribution and use in source and binary forms, with or without
611397Sswallace * modification, are permitted provided that the following conditions
711397Sswallace * are met:
811397Sswallace * 1. Redistributions of source code must retain the above copyright
911397Sswallace *    notice, this list of conditions and the following disclaimer.
1011397Sswallace * 2. The name of the author may not be used to endorse or promote products
1111397Sswallace *    derived from this software without specific prior written permission
1211397Sswallace *
1311397Sswallace * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1411397Sswallace * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1511397Sswallace * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1611397Sswallace * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1711397Sswallace * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1811397Sswallace * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1911397Sswallace * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2011397Sswallace * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2111397Sswallace * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2211397Sswallace * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2311397Sswallace *
2411397Sswallace * $Id$
2511397Sswallace */
2611397Sswallace
2711397Sswallace/*
2811397Sswallace * IBCS2 compatibility module.
2911397Sswallace */
3011397Sswallace
3111397Sswallace#include <sys/param.h>
3211397Sswallace#include <sys/systm.h>
3311397Sswallace#include <sys/sysproto.h>
3411397Sswallace#include <sys/kernel.h>
3511397Sswallace
3611397Sswallace#include <i386/ibcs2/ibcs2_types.h>
3711397Sswallace#include <i386/ibcs2/ibcs2_signal.h>
3811397Sswallace#include <i386/ibcs2/ibcs2_util.h>
3911397Sswallace#include <i386/ibcs2/ibcs2_proto.h>
4011397Sswallace
4111397Sswallace#define IBCS2_SECURE_GETLUID 1
4211397Sswallace#define IBCS2_SECURE_SETLUID 2
4311397Sswallace
4411397Sswallaceint
4511397Sswallaceibcs2_secure(struct proc *p, struct ibcs2_secure_args *uap, int *retval)
4611397Sswallace{
4711397Sswallace	switch (uap->cmd) {
4811397Sswallace
4911397Sswallace	case IBCS2_SECURE_GETLUID:		/* get login uid */
5011397Sswallace		*retval = p->p_ucred->cr_uid;
5111397Sswallace		return 0;
5211397Sswallace
5311397Sswallace	case IBCS2_SECURE_SETLUID:		/* set login uid */
5411397Sswallace		return EPERM;
5511397Sswallace
5611397Sswallace	default:
5711397Sswallace		printf("IBCS2: 'secure' cmd=%d not implemented\n", uap->cmd);
5811397Sswallace	}
5911397Sswallace
6011397Sswallace	return EINVAL;
6111397Sswallace}
6211397Sswallace
6311397Sswallaceint
6411397Sswallaceibcs2_lseek(struct proc *p, register struct ibcs2_lseek_args *uap, int *retval)
6511397Sswallace{
6611397Sswallace	struct lseek_args largs;
6711397Sswallace	off_t lret;
6811397Sswallace	int error;
6911397Sswallace
7011397Sswallace	largs.fd = uap->fd;
7111397Sswallace	largs.offset = uap->offset;
7211397Sswallace	largs.whence = uap->whence;
7311397Sswallace	error = lseek(p, &largs, (int *)&lret);
7411397Sswallace	*(long *)retval = lret;
7511397Sswallace	return (error);
7611397Sswallace}
7711527Sswallace
7811527Sswallace#ifdef SPX_HACK
7911527Sswallace#include <sys/socket.h>
8011527Sswallace#include <sys/un.h>
8111527Sswallace
8211527Sswallaceint
8311527Sswallacespx_open(struct proc *p, void *uap, int *retval)
8411527Sswallace{
8511527Sswallace	struct socket_args sock;
8611527Sswallace	struct connect_args conn;
8711527Sswallace	struct sockaddr_un *Xaddr;
8811527Sswallace	caddr_t name;
8911527Sswallace	int fd, error;
9011527Sswallace	caddr_t sg = stackgap_init();
9111527Sswallace
9211527Sswallace	/* obtain a socket. */
9311527Sswallace	DPRINTF(("SPX: open socket\n"));
9411527Sswallace	sock.domain = AF_UNIX;
9511527Sswallace	sock.type = SOCK_STREAM;
9611527Sswallace	sock.protocol = 0;
9711527Sswallace	error = socket(p, &sock, retval);
9811527Sswallace	if (error)
9911527Sswallace		return error;
10011527Sswallace
10111527Sswallace	/* connect the socket to standard X socket */
10211527Sswallace	DPRINTF(("SPX: connect to /tmp/X11-unix/X0\n"));
10311527Sswallace	Xaddr = stackgap_alloc(&sg, sizeof(struct sockaddr_un));
10411527Sswallace	Xaddr->sun_family = AF_UNIX;
10511527Sswallace	Xaddr->sun_len = sizeof(struct sockaddr_un) - sizeof(Xaddr->sun_path) +
10611527Sswallace	  strlen(Xaddr->sun_path) + 1;
10711527Sswallace	copyout("/tmp/.X11-unix/X0", Xaddr->sun_path, 18);
10811527Sswallace
10911527Sswallace	conn.s = fd = *retval;
11011527Sswallace	conn.name = (caddr_t)Xaddr;
11111527Sswallace	conn.namelen = sizeof(struct sockaddr_un);
11211527Sswallace	error = connect(p, &conn, retval);
11311527Sswallace	if (error) {
11411527Sswallace		struct close_args cl;
11511527Sswallace		cl.fd = fd;
11611527Sswallace		close(p, &cl, retval);
11711527Sswallace		return error;
11811527Sswallace	}
11911527Sswallace	*retval = fd;
12011527Sswallace	return 0;
12111527Sswallace}
12211527Sswallace#endif /* SPX_HACK */
123