ibcs2_other.c revision 141488
1139799Simp/*-
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
25115684Sobrien#include <sys/cdefs.h>
26115684Sobrien__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_other.c 141488 2005-02-07 22:02:18Z jhb $");
27115684Sobrien
2811397Sswallace/*
2911397Sswallace * IBCS2 compatibility module.
3011397Sswallace */
3111397Sswallace
3233071Seivind#include "opt_spx_hack.h"
3333071Seivind
3411397Sswallace#include <sys/param.h>
3511397Sswallace#include <sys/systm.h>
3676166Smarkm#include <sys/lock.h>
3776166Smarkm#include <sys/mutex.h>
3811397Sswallace#include <sys/sysproto.h>
3911397Sswallace
4011397Sswallace#include <i386/ibcs2/ibcs2_types.h>
4111397Sswallace#include <i386/ibcs2/ibcs2_signal.h>
4211397Sswallace#include <i386/ibcs2/ibcs2_util.h>
4311397Sswallace#include <i386/ibcs2/ibcs2_proto.h>
4411397Sswallace
4511397Sswallace#define IBCS2_SECURE_GETLUID 1
4611397Sswallace#define IBCS2_SECURE_SETLUID 2
4711397Sswallace
4811397Sswallaceint
4983366Sjulianibcs2_secure(struct thread *td, struct ibcs2_secure_args *uap)
5011397Sswallace{
5111397Sswallace	switch (uap->cmd) {
5211397Sswallace
5311397Sswallace	case IBCS2_SECURE_GETLUID:		/* get login uid */
5491415Sjhb		td->td_retval[0] = td->td_ucred->cr_uid;
5511397Sswallace		return 0;
5611397Sswallace
5711397Sswallace	case IBCS2_SECURE_SETLUID:		/* set login uid */
5811397Sswallace		return EPERM;
5911397Sswallace
6011397Sswallace	default:
6111397Sswallace		printf("IBCS2: 'secure' cmd=%d not implemented\n", uap->cmd);
6211397Sswallace	}
6311397Sswallace
6411397Sswallace	return EINVAL;
6511397Sswallace}
6611397Sswallace
6711397Sswallaceint
6883366Sjulianibcs2_lseek(struct thread *td, register struct ibcs2_lseek_args *uap)
6911397Sswallace{
7011397Sswallace	struct lseek_args largs;
7111397Sswallace	int error;
7211397Sswallace
7311397Sswallace	largs.fd = uap->fd;
7411397Sswallace	largs.offset = uap->offset;
7511397Sswallace	largs.whence = uap->whence;
7683366Sjulian	error = lseek(td, &largs);
7711397Sswallace	return (error);
7811397Sswallace}
7911527Sswallace
8011527Sswallace#ifdef SPX_HACK
8111527Sswallace#include <sys/socket.h>
8211527Sswallace#include <sys/un.h>
8311527Sswallace
8411527Sswallaceint
85141488Sjhbspx_open(struct thread *td)
8611527Sswallace{
8711527Sswallace	struct socket_args sock;
8811527Sswallace	struct connect_args conn;
8911527Sswallace	struct sockaddr_un *Xaddr;
9011527Sswallace	int fd, error;
9111527Sswallace	caddr_t sg = stackgap_init();
9211527Sswallace
9311527Sswallace	/* obtain a socket. */
9411527Sswallace	DPRINTF(("SPX: open socket\n"));
9511527Sswallace	sock.domain = AF_UNIX;
9611527Sswallace	sock.type = SOCK_STREAM;
9711527Sswallace	sock.protocol = 0;
9883366Sjulian	error = socket(td, &sock);
9911527Sswallace	if (error)
10011527Sswallace		return error;
10111527Sswallace
10211527Sswallace	/* connect the socket to standard X socket */
10311527Sswallace	DPRINTF(("SPX: connect to /tmp/X11-unix/X0\n"));
10411527Sswallace	Xaddr = stackgap_alloc(&sg, sizeof(struct sockaddr_un));
10511527Sswallace	Xaddr->sun_family = AF_UNIX;
10611527Sswallace	Xaddr->sun_len = sizeof(struct sockaddr_un) - sizeof(Xaddr->sun_path) +
10711527Sswallace	  strlen(Xaddr->sun_path) + 1;
10811527Sswallace	copyout("/tmp/.X11-unix/X0", Xaddr->sun_path, 18);
10911527Sswallace
11083366Sjulian	conn.s = fd = td->td_retval[0];
11111527Sswallace	conn.name = (caddr_t)Xaddr;
11211527Sswallace	conn.namelen = sizeof(struct sockaddr_un);
11383366Sjulian	error = connect(td, &conn);
11411527Sswallace	if (error) {
11511527Sswallace		struct close_args cl;
11611527Sswallace		cl.fd = fd;
11783366Sjulian		close(td, &cl);
11811527Sswallace		return error;
11911527Sswallace	}
12083366Sjulian	td->td_retval[0] = fd;
12111527Sswallace	return 0;
12211527Sswallace}
12311527Sswallace#endif /* SPX_HACK */
124