ibcs2_other.c revision 331643
1164032Srwatson/*-
2164032Srwatson * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3164032Srwatson *
4164032Srwatson * Copyright (c) 1995 Steven Wallace
5164032Srwatson * All rights reserved.
6164032Srwatson *
7164032Srwatson * Redistribution and use in source and binary forms, with or without
8164032Srwatson * modification, are permitted provided that the following conditions
9164032Srwatson * are met:
10164032Srwatson * 1. Redistributions of source code must retain the above copyright
11164032Srwatson *    notice, this list of conditions and the following disclaimer.
12164032Srwatson * 2. The name of the author may not be used to endorse or promote products
13164032Srwatson *    derived from this software without specific prior written permission
14164032Srwatson *
15164032Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16164032Srwatson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17164032Srwatson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18164032Srwatson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19164032Srwatson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20164032Srwatson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21164032Srwatson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22164032Srwatson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23164032Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24164032Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25164032Srwatson */
26164032Srwatson
27164032Srwatson#include <sys/cdefs.h>
28164032Srwatson__FBSDID("$FreeBSD: stable/11/sys/i386/ibcs2/ibcs2_other.c 331643 2018-03-27 18:52:27Z dim $");
29164032Srwatson
30164032Srwatson/*
31164032Srwatson * IBCS2 compatibility module.
32164032Srwatson */
33164032Srwatson
34164032Srwatson#include "opt_spx_hack.h"
35164032Srwatson
36164032Srwatson#include <sys/param.h>
37164032Srwatson#include <sys/systm.h>
38164032Srwatson#include <sys/fcntl.h>
39164032Srwatson#include <sys/lock.h>
40164032Srwatson#include <sys/mutex.h>
41164032Srwatson#include <sys/syscallsubr.h>
42164032Srwatson#include <sys/sysproto.h>
43164032Srwatson#include <sys/un.h>
44164032Srwatson
45164032Srwatson#include <i386/ibcs2/ibcs2_types.h>
46164032Srwatson#include <i386/ibcs2/ibcs2_signal.h>
47164032Srwatson#include <i386/ibcs2/ibcs2_util.h>
48164032Srwatson#include <i386/ibcs2/ibcs2_proto.h>
49164032Srwatson
50164032Srwatson#define IBCS2_SECURE_GETLUID 1
51164032Srwatson#define IBCS2_SECURE_SETLUID 2
52164032Srwatson
53164032Srwatsonint
54164032Srwatsonibcs2_secure(struct thread *td, struct ibcs2_secure_args *uap)
55164032Srwatson{
56164032Srwatson	switch (uap->cmd) {
57164032Srwatson
58164032Srwatson	case IBCS2_SECURE_GETLUID:		/* get login uid */
59164032Srwatson		td->td_retval[0] = td->td_ucred->cr_uid;
60164032Srwatson		return 0;
61164032Srwatson
62164032Srwatson	case IBCS2_SECURE_SETLUID:		/* set login uid */
63164032Srwatson		return EPERM;
64164032Srwatson
65	default:
66		printf("IBCS2: 'secure' cmd=%d not implemented\n", uap->cmd);
67	}
68
69	return EINVAL;
70}
71
72int
73ibcs2_lseek(struct thread *td, struct ibcs2_lseek_args *uap)
74{
75	struct lseek_args largs;
76	int error;
77
78	largs.fd = uap->fd;
79	largs.offset = uap->offset;
80	largs.whence = uap->whence;
81	error = sys_lseek(td, &largs);
82	return (error);
83}
84
85#ifdef SPX_HACK
86#include <sys/socket.h>
87#include <sys/un.h>
88
89int
90spx_open(struct thread *td)
91{
92	struct socket_args sock;
93	struct sockaddr_un sun;
94	int fd, error;
95
96	/* obtain a socket. */
97	DPRINTF(("SPX: open socket\n"));
98	sock.domain = AF_UNIX;
99	sock.type = SOCK_STREAM;
100	sock.protocol = 0;
101	error = sys_socket(td, &sock);
102	if (error)
103		return error;
104	fd = td->td_retval[0];
105
106	/* connect the socket to standard X socket */
107	DPRINTF(("SPX: connect to /tmp/X11-unix/X0\n"));
108	sun.sun_family = AF_UNIX;
109	strcpy(sun.sun_path, "/tmp/.X11-unix/X0");
110	sun.sun_len = sizeof(struct sockaddr_un) - sizeof(sun.sun_path) +
111	    strlen(sun.sun_path) + 1;
112
113	error = kern_connectat(td, AT_FDCWD, fd, (struct sockaddr *)&sun);
114	if (error) {
115		kern_close(td, fd);
116		return error;
117	}
118	td->td_retval[0] = fd;
119	return 0;
120}
121#endif /* SPX_HACK */
122