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$"); 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> 38160191Sjhb#include <sys/syscallsubr.h> 3911397Sswallace#include <sys/sysproto.h> 40160191Sjhb#include <sys/un.h> 4111397Sswallace 4211397Sswallace#include <i386/ibcs2/ibcs2_types.h> 4311397Sswallace#include <i386/ibcs2/ibcs2_signal.h> 4411397Sswallace#include <i386/ibcs2/ibcs2_util.h> 4511397Sswallace#include <i386/ibcs2/ibcs2_proto.h> 4611397Sswallace 4711397Sswallace#define IBCS2_SECURE_GETLUID 1 4811397Sswallace#define IBCS2_SECURE_SETLUID 2 4911397Sswallace 5011397Sswallaceint 5183366Sjulianibcs2_secure(struct thread *td, struct ibcs2_secure_args *uap) 5211397Sswallace{ 5311397Sswallace switch (uap->cmd) { 5411397Sswallace 5511397Sswallace case IBCS2_SECURE_GETLUID: /* get login uid */ 5691415Sjhb td->td_retval[0] = td->td_ucred->cr_uid; 5711397Sswallace return 0; 5811397Sswallace 5911397Sswallace case IBCS2_SECURE_SETLUID: /* set login uid */ 6011397Sswallace return EPERM; 6111397Sswallace 6211397Sswallace default: 6311397Sswallace printf("IBCS2: 'secure' cmd=%d not implemented\n", uap->cmd); 6411397Sswallace } 6511397Sswallace 6611397Sswallace return EINVAL; 6711397Sswallace} 6811397Sswallace 6911397Sswallaceint 7083366Sjulianibcs2_lseek(struct thread *td, register struct ibcs2_lseek_args *uap) 7111397Sswallace{ 7211397Sswallace struct lseek_args largs; 7311397Sswallace int error; 7411397Sswallace 7511397Sswallace largs.fd = uap->fd; 7611397Sswallace largs.offset = uap->offset; 7711397Sswallace largs.whence = uap->whence; 78225617Skmacy error = sys_lseek(td, &largs); 7911397Sswallace return (error); 8011397Sswallace} 8111527Sswallace 8211527Sswallace#ifdef SPX_HACK 8311527Sswallace#include <sys/socket.h> 8411527Sswallace#include <sys/un.h> 8511527Sswallace 8611527Sswallaceint 87141488Sjhbspx_open(struct thread *td) 8811527Sswallace{ 8911527Sswallace struct socket_args sock; 90160191Sjhb struct sockaddr_un sun; 9111527Sswallace int fd, error; 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; 98225617Skmacy error = sys_socket(td, &sock); 9911527Sswallace if (error) 10011527Sswallace return error; 101160191Sjhb fd = td->td_retval[0]; 10211527Sswallace 10311527Sswallace /* connect the socket to standard X socket */ 10411527Sswallace DPRINTF(("SPX: connect to /tmp/X11-unix/X0\n")); 105160191Sjhb sun.sun_family = AF_UNIX; 106160191Sjhb strcpy(sun.sun_path, "/tmp/.X11-unix/X0"); 107160191Sjhb sun.sun_len = sizeof(struct sockaddr_un) - sizeof(sun.sun_path) + 108160191Sjhb strlen(sun.sun_path) + 1; 10911527Sswallace 110160191Sjhb error = kern_connect(td, fd, (struct sockaddr *)&sun); 11111527Sswallace if (error) { 112160191Sjhb kern_close(td, fd); 11311527Sswallace return error; 11411527Sswallace } 11583366Sjulian td->td_retval[0] = fd; 11611527Sswallace return 0; 11711527Sswallace} 11811527Sswallace#endif /* SPX_HACK */ 119