ibcs2_other.c revision 28749
1/*
2 * Copyright (c) 1995 Steven Wallace
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. The name of the author may not be used to endorse or promote products
11 *    derived from this software without specific prior written permission
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * $Id: ibcs2_other.c,v 1.6 1997/07/20 09:39:45 bde Exp $
25 */
26
27/*
28 * IBCS2 compatibility module.
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/sysproto.h>
34
35#include <i386/ibcs2/ibcs2_types.h>
36#include <i386/ibcs2/ibcs2_signal.h>
37#include <i386/ibcs2/ibcs2_util.h>
38#include <i386/ibcs2/ibcs2_proto.h>
39
40#define IBCS2_SECURE_GETLUID 1
41#define IBCS2_SECURE_SETLUID 2
42
43int
44ibcs2_secure(struct proc *p, struct ibcs2_secure_args *uap, int *retval)
45{
46	switch (uap->cmd) {
47
48	case IBCS2_SECURE_GETLUID:		/* get login uid */
49		*retval = p->p_ucred->cr_uid;
50		return 0;
51
52	case IBCS2_SECURE_SETLUID:		/* set login uid */
53		return EPERM;
54
55	default:
56		printf("IBCS2: 'secure' cmd=%d not implemented\n", uap->cmd);
57	}
58
59	return EINVAL;
60}
61
62int
63ibcs2_lseek(struct proc *p, register struct ibcs2_lseek_args *uap, int *retval)
64{
65	struct lseek_args largs;
66	off_t lret;
67	int error;
68
69	largs.fd = uap->fd;
70	largs.offset = uap->offset;
71	largs.whence = uap->whence;
72	error = lseek(p, &largs, (int *)&lret);
73	*(long *)retval = lret;
74	return (error);
75}
76
77#ifdef SPX_HACK
78#include <sys/socket.h>
79#include <sys/un.h>
80
81int
82spx_open(struct proc *p, void *uap, int *retval)
83{
84	struct socket_args sock;
85	struct connect_args conn;
86	struct sockaddr_un *Xaddr;
87	int fd, error;
88	caddr_t sg = stackgap_init();
89
90	/* obtain a socket. */
91	DPRINTF(("SPX: open socket\n"));
92	sock.domain = AF_UNIX;
93	sock.type = SOCK_STREAM;
94	sock.protocol = 0;
95	error = socket(p, &sock, retval);
96	if (error)
97		return error;
98
99	/* connect the socket to standard X socket */
100	DPRINTF(("SPX: connect to /tmp/X11-unix/X0\n"));
101	Xaddr = stackgap_alloc(&sg, sizeof(struct sockaddr_un));
102	Xaddr->sun_family = AF_UNIX;
103	Xaddr->sun_len = sizeof(struct sockaddr_un) - sizeof(Xaddr->sun_path) +
104	  strlen(Xaddr->sun_path) + 1;
105	copyout("/tmp/.X11-unix/X0", Xaddr->sun_path, 18);
106
107	conn.s = fd = *retval;
108	conn.name = (caddr_t)Xaddr;
109	conn.namelen = sizeof(struct sockaddr_un);
110	error = connect(p, &conn, retval);
111	if (error) {
112		struct close_args cl;
113		cl.fd = fd;
114		close(p, &cl, retval);
115		return error;
116	}
117	*retval = fd;
118	return 0;
119}
120#endif /* SPX_HACK */
121