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: releng/11.0/sys/i386/ibcs2/ibcs2_other.c 274476 2014-11-13 18:01:51Z kib $");
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>
36274476Skib#include <sys/fcntl.h>
3776166Smarkm#include <sys/lock.h>
3876166Smarkm#include <sys/mutex.h>
39160191Sjhb#include <sys/syscallsubr.h>
4011397Sswallace#include <sys/sysproto.h>
41160191Sjhb#include <sys/un.h>
4211397Sswallace
4311397Sswallace#include <i386/ibcs2/ibcs2_types.h>
4411397Sswallace#include <i386/ibcs2/ibcs2_signal.h>
4511397Sswallace#include <i386/ibcs2/ibcs2_util.h>
4611397Sswallace#include <i386/ibcs2/ibcs2_proto.h>
4711397Sswallace
4811397Sswallace#define IBCS2_SECURE_GETLUID 1
4911397Sswallace#define IBCS2_SECURE_SETLUID 2
5011397Sswallace
5111397Sswallaceint
5283366Sjulianibcs2_secure(struct thread *td, struct ibcs2_secure_args *uap)
5311397Sswallace{
5411397Sswallace	switch (uap->cmd) {
5511397Sswallace
5611397Sswallace	case IBCS2_SECURE_GETLUID:		/* get login uid */
5791415Sjhb		td->td_retval[0] = td->td_ucred->cr_uid;
5811397Sswallace		return 0;
5911397Sswallace
6011397Sswallace	case IBCS2_SECURE_SETLUID:		/* set login uid */
6111397Sswallace		return EPERM;
6211397Sswallace
6311397Sswallace	default:
6411397Sswallace		printf("IBCS2: 'secure' cmd=%d not implemented\n", uap->cmd);
6511397Sswallace	}
6611397Sswallace
6711397Sswallace	return EINVAL;
6811397Sswallace}
6911397Sswallace
7011397Sswallaceint
7183366Sjulianibcs2_lseek(struct thread *td, register struct ibcs2_lseek_args *uap)
7211397Sswallace{
7311397Sswallace	struct lseek_args largs;
7411397Sswallace	int error;
7511397Sswallace
7611397Sswallace	largs.fd = uap->fd;
7711397Sswallace	largs.offset = uap->offset;
7811397Sswallace	largs.whence = uap->whence;
79225617Skmacy	error = sys_lseek(td, &largs);
8011397Sswallace	return (error);
8111397Sswallace}
8211527Sswallace
8311527Sswallace#ifdef SPX_HACK
8411527Sswallace#include <sys/socket.h>
8511527Sswallace#include <sys/un.h>
8611527Sswallace
8711527Sswallaceint
88141488Sjhbspx_open(struct thread *td)
8911527Sswallace{
9011527Sswallace	struct socket_args sock;
91160191Sjhb	struct sockaddr_un sun;
9211527Sswallace	int fd, error;
9311527Sswallace
9411527Sswallace	/* obtain a socket. */
9511527Sswallace	DPRINTF(("SPX: open socket\n"));
9611527Sswallace	sock.domain = AF_UNIX;
9711527Sswallace	sock.type = SOCK_STREAM;
9811527Sswallace	sock.protocol = 0;
99225617Skmacy	error = sys_socket(td, &sock);
10011527Sswallace	if (error)
10111527Sswallace		return error;
102160191Sjhb	fd = td->td_retval[0];
10311527Sswallace
10411527Sswallace	/* connect the socket to standard X socket */
10511527Sswallace	DPRINTF(("SPX: connect to /tmp/X11-unix/X0\n"));
106160191Sjhb	sun.sun_family = AF_UNIX;
107160191Sjhb	strcpy(sun.sun_path, "/tmp/.X11-unix/X0");
108160191Sjhb	sun.sun_len = sizeof(struct sockaddr_un) - sizeof(sun.sun_path) +
109160191Sjhb	    strlen(sun.sun_path) + 1;
11011527Sswallace
111274476Skib	error = kern_connectat(td, AT_FDCWD, fd, (struct sockaddr *)&sun);
11211527Sswallace	if (error) {
113160191Sjhb		kern_close(td, fd);
11411527Sswallace		return error;
11511527Sswallace	}
11683366Sjulian	td->td_retval[0] = fd;
11711527Sswallace	return 0;
11811527Sswallace}
11911527Sswallace#endif /* SPX_HACK */
120