ibcs2_other.c revision 225617
1221807Sstas/*-
2221807Sstas * Copyright (c) 1995 Steven Wallace
3221807Sstas * All rights reserved.
4221807Sstas *
5221807Sstas * Redistribution and use in source and binary forms, with or without
6221807Sstas * modification, are permitted provided that the following conditions
7221807Sstas * are met:
8221807Sstas * 1. Redistributions of source code must retain the above copyright
9221807Sstas *    notice, this list of conditions and the following disclaimer.
10221807Sstas * 2. The name of the author may not be used to endorse or promote products
11221807Sstas *    derived from this software without specific prior written permission
12221807Sstas *
13221807Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14221807Sstas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15221807Sstas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16221807Sstas * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17221807Sstas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18221807Sstas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19221807Sstas * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20221807Sstas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21221807Sstas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22221807Sstas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23221807Sstas */
24221807Sstas
25221807Sstas#include <sys/cdefs.h>
26221807Sstas__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_other.c 225617 2011-09-16 13:58:51Z kmacy $");
27221807Sstas
28221807Sstas/*
29221807Sstas * IBCS2 compatibility module.
30221807Sstas */
31221807Sstas
32221807Sstas#include "opt_spx_hack.h"
33221807Sstas
34221807Sstas#include <sys/param.h>
35221807Sstas#include <sys/systm.h>
36221807Sstas#include <sys/lock.h>
37221807Sstas#include <sys/mutex.h>
38221807Sstas#include <sys/syscallsubr.h>
39221807Sstas#include <sys/sysproto.h>
40221807Sstas#include <sys/un.h>
41221807Sstas
42221807Sstas#include <i386/ibcs2/ibcs2_types.h>
43221807Sstas#include <i386/ibcs2/ibcs2_signal.h>
44221807Sstas#include <i386/ibcs2/ibcs2_util.h>
45221807Sstas#include <i386/ibcs2/ibcs2_proto.h>
46221807Sstas
47221807Sstas#define IBCS2_SECURE_GETLUID 1
48221807Sstas#define IBCS2_SECURE_SETLUID 2
49221807Sstas
50221807Sstasint
51221807Sstasibcs2_secure(struct thread *td, struct ibcs2_secure_args *uap)
52221807Sstas{
53221807Sstas	switch (uap->cmd) {
54221807Sstas
55221807Sstas	case IBCS2_SECURE_GETLUID:		/* get login uid */
56221807Sstas		td->td_retval[0] = td->td_ucred->cr_uid;
57221807Sstas		return 0;
58221807Sstas
59221807Sstas	case IBCS2_SECURE_SETLUID:		/* set login uid */
60221807Sstas		return EPERM;
61221807Sstas
62221807Sstas	default:
63221807Sstas		printf("IBCS2: 'secure' cmd=%d not implemented\n", uap->cmd);
64221807Sstas	}
65221807Sstas
66221807Sstas	return EINVAL;
67221807Sstas}
68221807Sstas
69221807Sstasint
70221807Sstasibcs2_lseek(struct thread *td, register struct ibcs2_lseek_args *uap)
71221807Sstas{
72221807Sstas	struct lseek_args largs;
73221807Sstas	int error;
74221807Sstas
75221807Sstas	largs.fd = uap->fd;
76221807Sstas	largs.offset = uap->offset;
77221807Sstas	largs.whence = uap->whence;
78221807Sstas	error = sys_lseek(td, &largs);
79221807Sstas	return (error);
80221807Sstas}
81221807Sstas
82221807Sstas#ifdef SPX_HACK
83231384Sed#include <sys/socket.h>
84221807Sstas#include <sys/un.h>
85221807Sstas
86221807Sstasint
87221807Sstasspx_open(struct thread *td)
88221807Sstas{
89221807Sstas	struct socket_args sock;
90221807Sstas	struct sockaddr_un sun;
91221807Sstas	int fd, error;
92221807Sstas
93221807Sstas	/* obtain a socket. */
94221807Sstas	DPRINTF(("SPX: open socket\n"));
95221807Sstas	sock.domain = AF_UNIX;
96221807Sstas	sock.type = SOCK_STREAM;
97221807Sstas	sock.protocol = 0;
98221807Sstas	error = sys_socket(td, &sock);
99221807Sstas	if (error)
100221807Sstas		return error;
101221807Sstas	fd = td->td_retval[0];
102235602Sgleb
103221807Sstas	/* connect the socket to standard X socket */
104235602Sgleb	DPRINTF(("SPX: connect to /tmp/X11-unix/X0\n"));
105221807Sstas	sun.sun_family = AF_UNIX;
106221807Sstas	strcpy(sun.sun_path, "/tmp/.X11-unix/X0");
107221807Sstas	sun.sun_len = sizeof(struct sockaddr_un) - sizeof(sun.sun_path) +
108221807Sstas	    strlen(sun.sun_path) + 1;
109221807Sstas
110221807Sstas	error = kern_connect(td, fd, (struct sockaddr *)&sun);
111221807Sstas	if (error) {
112221807Sstas		kern_close(td, fd);
113221807Sstas		return error;
114221807Sstas	}
115221807Sstas	td->td_retval[0] = fd;
116221807Sstas	return 0;
117221807Sstas}
118221807Sstas#endif /* SPX_HACK */
119221807Sstas