- Implement svr4_emul_find() using kern_alternate_path(). This changes

the semantics in that the returned filename to use is now a kernel
  pointer rather than a user space pointer.  This required changing the
  arguments to the CHECKALT*() macros some and changing the various system
  calls that used pathnames to use the kern_foo() functions that can accept
  kernel space filename pointers instead of calling the system call
  directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
  kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
  kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
  kern_pathconf(), and kern_unlink().
This commit is contained in:
jhb 2005-02-07 21:53:42 +00:00
parent 60bd53b164
commit b03a8bb21b
7 changed files with 229 additions and 523 deletions

View File

@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
/*#include <sys/ioctl.h>*/
#include <sys/lock.h>
#include <sys/mac.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/namei.h>
@ -366,16 +367,14 @@ svr4_sys_open(td, uap)
struct svr4_sys_open_args *uap;
{
struct proc *p = td->td_proc;
int error, retval;
struct open_args cup;
char *newpath;
int bsd_flags, error, retval;
caddr_t sg = stackgap_init();
CHECKALTEXIST(td, &sg, uap->path);
CHECKALTEXIST(td, uap->path, &newpath);
(&cup)->path = uap->path;
(&cup)->flags = svr4_to_bsd_flags(uap->flags);
(&cup)->mode = uap->mode;
error = open(td, &cup);
bsd_flags = svr4_to_bsd_flags(uap->flags);
error = kern_open(td, newpath, UIO_SYSSPACE, bsd_flags, uap->mode);
free(newpath, M_TEMP);
if (error) {
/* uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path,
@ -386,8 +385,8 @@ svr4_sys_open(td, uap)
retval = td->td_retval[0];
PROC_LOCK(p);
if (!(cup.flags & O_NOCTTY) && SESS_LEADER(p) &&
!(td->td_proc->p_flag & P_CONTROLT)) {
if (!(bsd_flags & O_NOCTTY) && SESS_LEADER(p) &&
!(p->p_flag & P_CONTROLT)) {
#if defined(NOTYET)
struct file *fp;
@ -427,16 +426,15 @@ svr4_sys_creat(td, uap)
register struct thread *td;
struct svr4_sys_creat_args *uap;
{
struct open_args cup;
char *newpath;
int error;
caddr_t sg = stackgap_init();
CHECKALTEXIST(td, &sg, uap->path);
CHECKALTEXIST(td, uap->path, &newpath);
cup.path = uap->path;
cup.mode = uap->mode;
cup.flags = O_WRONLY | O_CREAT | O_TRUNC;
return open(td, &cup);
error = kern_open(td, newpath, UIO_SYSSPACE, O_WRONLY | O_CREAT |
O_TRUNC, uap->mode);
free(newpath, M_TEMP);
return (error);
}
int
@ -473,18 +471,13 @@ svr4_sys_access(td, uap)
register struct thread *td;
struct svr4_sys_access_args *uap;
{
struct access_args cup;
int *retval;
char *newpath;
int error;
caddr_t sg = stackgap_init();
CHECKALTEXIST(td, &sg, uap->path);
retval = td->td_retval;
cup.path = uap->path;
cup.flags = uap->flags;
return access(td, &cup);
CHECKALTEXIST(td, uap->path, &newpath);
error = kern_access(td, newpath, UIO_SYSSPACE, uap->flags);
free(newpath, M_TEMP);
return (error);
}
#if defined(NOTYET)

View File

@ -527,49 +527,32 @@ svr4_msgctl(p, v, retval)
void *v;
register_t *retval;
{
int error;
struct svr4_sys_msgctl_args *uap = v;
struct sys_msgctl_args ap;
struct svr4_msqid_ds ss;
struct msqid_ds bs;
caddr_t sg = stackgap_init();
ap.msqid = uap->msqid;
ap.cmd = uap->cmd;
ap.buf = stackgap_alloc(&sg, sizeof(bs));
int error;
switch (uap->cmd) {
case SVR4_IPC_STAT:
ap.cmd = IPC_STAT;
if ((error = sys_msgctl(p, &ap, retval)) != 0)
return error;
error = copyin(&bs, ap.buf, sizeof bs);
error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
if (error)
return error;
bsd_to_svr4_msqid_ds(&bs, &ss);
return copyout(&ss, uap->buf, sizeof ss);
case SVR4_IPC_SET:
ap.cmd = IPC_SET;
error = copyin(uap->buf, &ss, sizeof ss);
if (error)
return error;
svr4_to_bsd_msqid_ds(&ss, &bs);
error = copyout(&bs, ap.buf, sizeof bs);
if (error)
return error;
return sys_msgctl(p, &ap, retval);
return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
case SVR4_IPC_RMID:
ap.cmd = IPC_RMID;
error = copyin(uap->buf, &ss, sizeof ss);
if (error)
return error;
svr4_to_bsd_msqid_ds(&ss, &bs);
error = copyout(&bs, ap.buf, sizeof bs);
if (error)
return error;
return sys_msgctl(p, &ap, retval);
return (kern_msgctl(td, uap->msqid, IPC_RMID, &bs));
default:
return EINVAL;

View File

@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include <sys/dirent.h>
#include <sys/fcntl.h>
#include <sys/filedesc.h>
#include <sys/imgact.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mac.h>
@ -164,17 +165,18 @@ svr4_sys_execv(td, uap)
struct thread *td;
struct svr4_sys_execv_args *uap;
{
struct execve_args ap;
caddr_t sg;
struct image_args eargs;
char *path;
int error;
sg = stackgap_init();
CHECKALTEXIST(td, &sg, uap->path);
CHECKALTEXIST(td, uap->path, &path);
ap.fname = uap->path;
ap.argv = uap->argp;
ap.envv = NULL;
return execve(td, &ap);
error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}
int
@ -182,17 +184,19 @@ svr4_sys_execve(td, uap)
struct thread *td;
struct svr4_sys_execve_args *uap;
{
struct execve_args ap;
caddr_t sg;
struct image_args eargs;
char *path;
int error;
sg = stackgap_init();
CHECKALTEXIST(td, &sg, uap->path);
CHECKALTEXIST(td, uap->path, &path);
ap.fname = uap->path;
ap.argv = uap->argp;
ap.envv = uap->envp;
return execve(td, &ap);
error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
uap->envp);
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}
int
@ -638,22 +642,17 @@ svr4_mknod(td, retval, path, mode, dev)
svr4_mode_t mode;
svr4_dev_t dev;
{
caddr_t sg = stackgap_init();
char *newpath;
int error;
CHECKALTEXIST(td, &sg, path);
CHECKALTEXIST(td, path, &newpath);
if (S_ISFIFO(mode)) {
struct mkfifo_args ap;
ap.path = path;
ap.mode = mode;
return mkfifo(td, &ap);
} else {
struct mknod_args ap;
ap.path = path;
ap.mode = mode;
ap.dev = dev;
return mknod(td, &ap);
}
if (S_ISFIFO(mode))
error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode);
else
error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev);
free(newpath, M_TEMP);
return (error);
}
@ -1433,25 +1432,18 @@ svr4_sys_statvfs(td, uap)
struct thread *td;
struct svr4_sys_statvfs_args *uap;
{
struct statfs_args fs_args;
caddr_t sg = stackgap_init();
struct statfs *fs = stackgap_alloc(&sg, sizeof(struct statfs));
struct statfs bfs;
struct svr4_statvfs sfs;
struct statfs bfs;
char *path;
int error;
CHECKALTEXIST(td, &sg, uap->path);
fs_args.path = uap->path;
fs_args.buf = fs;
if ((error = statfs(td, &fs_args)) != 0)
return error;
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
return error;
CHECKALTEXIST(td, uap->path, &path);
error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
free(path, M_TEMP);
if (error)
return (error);
bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
return copyout(&sfs, uap->fs, sizeof(sfs));
}
@ -1461,24 +1453,14 @@ svr4_sys_fstatvfs(td, uap)
struct thread *td;
struct svr4_sys_fstatvfs_args *uap;
{
struct fstatfs_args fs_args;
caddr_t sg = stackgap_init();
struct statfs *fs = stackgap_alloc(&sg, sizeof(struct statfs));
struct statfs bfs;
struct svr4_statvfs sfs;
struct statfs bfs;
int error;
fs_args.fd = uap->fd;
fs_args.buf = fs;
if ((error = fstatfs(td, &fs_args)) != 0)
return error;
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
return error;
error = kern_fstatfs(td, uap->fd, &bfs);
if (error)
return (error);
bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
return copyout(&sfs, uap->fs, sizeof(sfs));
}
@ -1488,25 +1470,18 @@ svr4_sys_statvfs64(td, uap)
struct thread *td;
struct svr4_sys_statvfs64_args *uap;
{
struct statfs_args fs_args;
caddr_t sg = stackgap_init();
struct statfs *fs = stackgap_alloc(&sg, sizeof(struct statfs));
struct statfs bfs;
struct svr4_statvfs64 sfs;
struct statfs bfs;
char *path;
int error;
CHECKALTEXIST(td, &sg, uap->path);
fs_args.path = uap->path;
fs_args.buf = fs;
if ((error = statfs(td, &fs_args)) != 0)
return error;
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
return error;
CHECKALTEXIST(td, uap->path, &path);
error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
free(path, M_TEMP);
if (error)
return (error);
bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
return copyout(&sfs, uap->fs, sizeof(sfs));
}
@ -1516,24 +1491,14 @@ svr4_sys_fstatvfs64(td, uap)
struct thread *td;
struct svr4_sys_fstatvfs64_args *uap;
{
struct fstatfs_args fs_args;
caddr_t sg = stackgap_init();
struct statfs *fs = stackgap_alloc(&sg, sizeof(struct statfs));
struct statfs bfs;
struct svr4_statvfs64 sfs;
struct statfs bfs;
int error;
fs_args.fd = uap->fd;
fs_args.buf = fs;
if ((error = fstatfs(td, &fs_args)) != 0)
return error;
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
return error;
error = kern_fstatfs(td, uap->fd, &bfs);
if (error)
return (error);
bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
return copyout(&sfs, uap->fs, sizeof(sfs));
}
@ -1542,28 +1507,19 @@ svr4_sys_alarm(td, uap)
struct thread *td;
struct svr4_sys_alarm_args *uap;
{
struct itimerval itv, oitv;
int error;
struct itimerval *itp, *oitp;
struct setitimer_args sa;
caddr_t sg = stackgap_init();
itp = stackgap_alloc(&sg, sizeof(*itp));
oitp = stackgap_alloc(&sg, sizeof(*oitp));
timevalclear(&itp->it_interval);
itp->it_value.tv_sec = uap->sec;
itp->it_value.tv_usec = 0;
sa.which = ITIMER_REAL;
sa.itv = itp;
sa.oitv = oitp;
error = setitimer(td, &sa);
timevalclear(&itv.it_interval);
itv.it_value.tv_sec = uap->sec;
itv.it_value.tv_usec = 0;
error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
if (error)
return error;
if (oitp->it_value.tv_usec)
oitp->it_value.tv_sec++;
td->td_retval[0] = oitp->it_value.tv_sec;
return 0;
return (error);
if (oitv.it_value.tv_usec != 0)
oitv.it_value.tv_sec++;
td->td_retval[0] = oitv.it_value.tv_sec;
return (0);
}
int

View File

@ -36,8 +36,10 @@ __FBSDID("$FreeBSD$");
#include <sys/filedesc.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/unistd.h>
#include <sys/time.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/un.h>
@ -160,33 +162,23 @@ svr4_sys_stat(td, uap)
struct thread *td;
struct svr4_sys_stat_args *uap;
{
struct stat st;
struct svr4_stat svr4_st;
struct stat_args cup;
int error;
caddr_t sg = stackgap_init();
struct svr4_stat svr4_st;
struct stat st;
char *path;
int error;
CHECKALTEXIST(td, &sg, uap->path);
cup.path = uap->path;
cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = stat(td, &cup)) != 0)
return error;
if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
return error;
CHECKALTEXIST(td, uap->path, &path);
error = kern_stat(td, path, UIO_SYSSPACE, &st);
free(path, M_TEMP);
if (error)
return (error);
bsd_to_svr4_stat(&st, &svr4_st);
if (S_ISSOCK(st.st_mode))
(void) svr4_add_socket(td, uap->path, &st);
if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->ub, sizeof svr4_st));
}
@ -195,32 +187,23 @@ svr4_sys_lstat(td, uap)
register struct thread *td;
struct svr4_sys_lstat_args *uap;
{
struct stat st;
struct svr4_stat svr4_st;
struct lstat_args cup;
int error;
caddr_t sg = stackgap_init();
struct svr4_stat svr4_st;
struct stat st;
char *path;
int error;
CHECKALTEXIST(td, &sg, uap->path);
cup.path = uap->path;
cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = lstat(td, &cup)) != 0)
return error;
if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
return error;
CHECKALTEXIST(td, uap->path, &path);
error = kern_lstat(td, path, UIO_SYSSPACE, &st);
free(path, M_TEMP);
if (error)
return (error);
bsd_to_svr4_stat(&st, &svr4_st);
if (S_ISSOCK(st.st_mode))
(void) svr4_add_socket(td, uap->path, &st);
if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->ub, sizeof svr4_st));
}
@ -229,27 +212,16 @@ svr4_sys_fstat(td, uap)
register struct thread *td;
struct svr4_sys_fstat_args *uap;
{
struct stat st;
struct svr4_stat svr4_st;
struct fstat_args cup;
int error;
caddr_t sg = stackgap_init();
struct svr4_stat svr4_st;
struct stat st;
int error;
cup.fd = uap->fd;
cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = fstat(td, &cup)) != 0)
return error;
if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
return error;
error = kern_fstat(td, uap->fd, &st);
if (error)
return (error);
bsd_to_svr4_stat(&st, &svr4_st);
if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
}
@ -258,22 +230,17 @@ svr4_sys_xstat(td, uap)
register struct thread *td;
struct svr4_sys_xstat_args *uap;
{
struct stat st;
struct svr4_xstat svr4_st;
struct stat_args cup;
int error;
struct svr4_xstat svr4_st;
struct stat st;
char *path;
int error;
caddr_t sg = stackgap_init();
CHECKALTEXIST(td, &sg, uap->path);
CHECKALTEXIST(td, uap->path, &path);
cup.path = uap->path;
cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = stat(td, &cup)) != 0)
return error;
if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
return error;
error = kern_stat(td, path, UIO_SYSSPACE, &st);
free(path, M_TEMP);
if (error)
return (error);
bsd_to_svr4_xstat(&st, &svr4_st);
@ -282,10 +249,7 @@ svr4_sys_xstat(td, uap)
(void) svr4_add_socket(td, uap->path, &st);
#endif
if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->ub, sizeof svr4_st));
}
int
@ -293,21 +257,17 @@ svr4_sys_lxstat(td, uap)
register struct thread *td;
struct svr4_sys_lxstat_args *uap;
{
struct stat st;
struct svr4_xstat svr4_st;
struct lstat_args cup;
int error;
caddr_t sg = stackgap_init();
CHECKALTEXIST(td, &sg, uap->path);
struct svr4_xstat svr4_st;
struct stat st;
char *path;
int error;
cup.path = uap->path;
cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
CHECKALTEXIST(td, uap->path, &path);
if ((error = lstat(td, &cup)) != 0)
return error;
if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
return error;
error = kern_lstat(td, path, UIO_SYSSPACE, &st);
free(path, M_TEMP);
if (error)
return (error);
bsd_to_svr4_xstat(&st, &svr4_st);
@ -315,10 +275,7 @@ svr4_sys_lxstat(td, uap)
if (S_ISSOCK(st.st_mode))
(void) svr4_add_socket(td, uap->path, &st);
#endif
if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->ub, sizeof svr4_st));
}
@ -327,28 +284,16 @@ svr4_sys_fxstat(td, uap)
register struct thread *td;
struct svr4_sys_fxstat_args *uap;
{
struct stat st;
struct svr4_xstat svr4_st;
struct fstat_args cup;
int error;
struct svr4_xstat svr4_st;
struct stat st;
int error;
caddr_t sg = stackgap_init();
cup.fd = uap->fd;
cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = fstat(td, &cup)) != 0)
return error;
if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
return error;
error = kern_fstat(td, uap->fd, &st);
if (error)
return (error);
bsd_to_svr4_xstat(&st, &svr4_st);
if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
}
int
@ -356,32 +301,24 @@ svr4_sys_stat64(td, uap)
register struct thread *td;
struct svr4_sys_stat64_args *uap;
{
struct stat st;
struct svr4_stat64 svr4_st;
struct stat_args cup;
int error;
caddr_t sg = stackgap_init();
struct svr4_stat64 svr4_st;
struct stat st;
char *path;
int error;
CHECKALTEXIST(td, &sg, uap->path);
CHECKALTEXIST(td, uap->path, &path);
cup.path = uap->path;
cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = stat(td, &cup)) != 0)
return error;
if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
return error;
error = kern_stat(td, path, UIO_SYSSPACE, &st);
free(path, M_TEMP);
if (error)
return (error);
bsd_to_svr4_stat64(&st, &svr4_st);
if (S_ISSOCK(st.st_mode))
(void) svr4_add_socket(td, uap->path, &st);
if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
}
@ -390,32 +327,24 @@ svr4_sys_lstat64(td, uap)
register struct thread *td;
struct svr4_sys_lstat64_args *uap;
{
struct stat st;
struct svr4_stat64 svr4_st;
struct stat_args cup;
int error;
caddr_t sg = stackgap_init();
struct svr4_stat64 svr4_st;
struct stat st;
char *path;
int error;
CHECKALTEXIST(td, &sg, (char *) uap->path);
CHECKALTEXIST(td, uap->path, &path);
cup.path = uap->path;
cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = lstat(td, (struct lstat_args *)&cup)) != 0)
return error;
if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
return error;
error = kern_lstat(td, path, UIO_SYSSPACE, &st);
free(path, M_TEMP);
if (error)
return (error);
bsd_to_svr4_stat64(&st, &svr4_st);
if (S_ISSOCK(st.st_mode))
(void) svr4_add_socket(td, uap->path, &st);
if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
}
@ -424,27 +353,15 @@ svr4_sys_fstat64(td, uap)
register struct thread *td;
struct svr4_sys_fstat64_args *uap;
{
struct stat st;
struct svr4_stat64 svr4_st;
struct fstat_args cup;
int error;
caddr_t sg = stackgap_init();
cup.fd = uap->fd;
cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = fstat(td, &cup)) != 0)
return error;
if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
return error;
struct svr4_stat64 svr4_st;
struct stat st;
int error;
error = kern_fstat(td, uap->fd, &st);
if (error)
return (error);
bsd_to_svr4_stat64(&st, &svr4_st);
if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
return error;
return 0;
return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
}
@ -636,30 +553,26 @@ svr4_sys_utime(td, uap)
struct svr4_sys_utime_args *uap;
{
struct svr4_utimbuf ub;
struct timeval tbuf[2];
struct utimes_args ap;
struct timeval tbuf[2], *tp;
char *path;
int error;
caddr_t sg = stackgap_init();
void *ttp;
CHECKALTEXIST(td, &sg, uap->path);
ap.path = uap->path;
if (uap->ubuf != NULL) {
if ((error = copyin(uap->ubuf, &ub, sizeof(ub))) != 0)
return error;
error = copyin(uap->ubuf, &ub, sizeof(ub));
if (error)
return (error);
tbuf[0].tv_sec = ub.actime;
tbuf[0].tv_usec = 0;
tbuf[1].tv_sec = ub.modtime;
tbuf[1].tv_usec = 0;
ttp = stackgap_alloc(&sg, sizeof(tbuf));
error = copyout(tbuf, ttp, sizeof(tbuf));
if (error)
return error;
ap.tptr = ttp;
}
else
ap.tptr = NULL;
return utimes(td, &ap);
tp = tbuf;
} else
tp = NULL;
CHECKALTEXIST(td, uap->path, &path);
error = kern_utimes(td, path, UIO_SYSSPACE, tp, UIO_SYSSPACE);
free(path, M_TEMP);
return (error);
}
@ -668,9 +581,13 @@ svr4_sys_utimes(td, uap)
register struct thread *td;
struct svr4_sys_utimes_args *uap;
{
caddr_t sg = stackgap_init();
CHECKALTEXIST(td, &sg, uap->path);
return utimes(td, (struct utimes_args *)uap);
char *path;
int error;
CHECKALTEXIST(td, uap->path, &path);
error = kern_utimes(td, path, UIO_SYSSPACE, uap->tptr, UIO_USERSPACE);
free(path, M_TEMP);
return (error);
}
static int
@ -727,22 +644,23 @@ svr4_sys_pathconf(td, uap)
register struct thread *td;
struct svr4_sys_pathconf_args *uap;
{
caddr_t sg = stackgap_init();
register_t *retval = td->td_retval;
char *path;
int error, name;
CHECKALTEXIST(td, &sg, uap->path);
name = svr4_to_bsd_pathconf(uap->name);
uap->name = svr4_to_bsd_pathconf(uap->name);
switch (uap->name) {
switch (name) {
case -1:
*retval = -1;
return EINVAL;
td->td_retval[0] = -1;
return (EINVAL);
case 0:
*retval = 0;
return 0;
td->td_retval[0] = 0;
return (0);
default:
return pathconf(td, (struct pathconf_args *)uap);
CHECKALTEXIST(td, uap->path, &path);
error = kern_pathconf(td, path, UIO_SYSSPACE, name);
free(path, M_TEMP);
return (error);
}
}

View File

@ -80,7 +80,7 @@ __FBSDID("$FreeBSD$");
#include <compat/svr4/svr4_socket.h>
/* Utils */
static int clean_pipe(struct thread *, const char *);
static int clean_pipe(struct thread *, char *);
static void getparm(struct file *, struct svr4_si_sockparms *);
static int svr4_do_putmsg(struct thread *, struct svr4_sys_putmsg_args *,
struct file *);
@ -509,48 +509,26 @@ show_msg(str, fd, ctl, dat, flags)
static int
clean_pipe(td, path)
struct thread *td;
const char *path;
char *path;
{
struct lstat_args la;
struct unlink_args ua;
struct stat st;
int error;
caddr_t sg = stackgap_init();
size_t l = strlen(path) + 1;
void *tpath;
if ((tpath = stackgap_alloc(&sg, l)) == NULL)
return ENAMETOOLONG;
la.ub = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = copyout(path, tpath, l)) != 0)
return error;
la.path = tpath;
if ((error = lstat(td, &la)) != 0)
return 0;
if ((error = copyin(la.ub, &st, sizeof(st))) != 0)
return 0;
error = kern_lstat(td, path, UIO_SYSSPACE, &st);
/*
* Make sure we are dealing with a mode 0 named pipe.
*/
if ((st.st_mode & S_IFMT) != S_IFIFO)
return 0;
return (0);
if ((st.st_mode & ALLPERMS) != 0)
return 0;
return (0);
ua.path = la.path;
if ((error = unlink(td, &ua)) != 0) {
error = kern_unlink(td, path, UIO_SYSSPACE);
if (error)
DPRINTF(("clean_pipe: unlink failed %d\n", error));
return error;
}
return 0;
return (error);
}

View File

@ -44,13 +44,14 @@ __FBSDID("$FreeBSD$");
#include <sys/sysent.h>
#include <sys/imgact.h>
#include <sys/imgact_elf.h>
#include <sys/socket.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/namei.h>
#include <sys/socket.h>
#include <sys/syscallsubr.h>
#include <sys/vnode.h>
#include <sys/module.h>
#include <vm/vm.h>
#include <sys/exec.h>
#include <sys/kernel.h>
@ -193,6 +194,8 @@ struct sysentvec svr4_sysvec = {
NULL
};
const char svr4_emul_path[] = "/compat/svr4";
Elf32_Brandinfo svr4_brand = {
ELFOSABI_SYSV,
EM_386, /* XXX only implemented for x86 so far. */
@ -203,8 +206,6 @@ Elf32_Brandinfo svr4_brand = {
NULL,
};
const char svr4_emul_path[] = "/compat/svr4";
static int
svr4_fixup(register_t **stack_base, struct image_params *imgp)
{
@ -249,135 +250,14 @@ svr4_fixup(register_t **stack_base, struct image_params *imgp)
* If cflag is set, we check if an attempt can be made to create
* the named file, i.e. we check if the directory it should
* be in exists.
*
* Code shamelessly stolen by Mark Newton from IBCS2 emulation code.
*/
int
svr4_emul_find(td, sgp, prefix, path, pbuf, cflag)
struct thread *td;
caddr_t *sgp; /* Pointer to stackgap memory */
const char *prefix;
char *path;
char **pbuf;
int cflag;
svr4_emul_find(struct thread *td, char *path, enum uio_seg pathseg,
char **pbuf, int create)
{
struct nameidata nd;
struct nameidata ndroot;
struct vattr vat;
struct vattr vatroot;
int error;
char *ptr, *buf, *cp;
size_t sz, len;
buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
*pbuf = path;
for (ptr = buf; (*ptr = *prefix) != '\0'; ptr++, prefix++)
continue;
sz = MAXPATHLEN - (ptr - buf);
/*
* If sgp is not given then the path is already in kernel space
*/
if (sgp == NULL)
error = copystr(path, ptr, sz, &len);
else
error = copyinstr(path, ptr, sz, &len);
if (error) {
free(buf, M_TEMP);
return error;
}
if (*ptr != '/') {
free(buf, M_TEMP);
return EINVAL;
}
/*
* We know that there is a / somewhere in this pathname.
* Search backwards for it, to find the file's parent dir
* to see if it exists in the alternate tree. If it does,
* and we want to create a file (cflag is set). We don't
* need to worry about the root comparison in this case.
*/
if (cflag) {
for (cp = &ptr[len] - 1; *cp != '/'; cp--);
*cp = '\0';
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td);
if ((error = namei(&nd)) != 0) {
free(buf, M_TEMP);
return error;
}
NDFREE(&nd, NDF_ONLY_PNBUF);
*cp = '/';
}
else {
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td);
if ((error = namei(&nd)) != 0) {
free(buf, M_TEMP);
return error;
}
NDFREE(&nd, NDF_ONLY_PNBUF);
/*
* We now compare the vnode of the svr4_root to the one
* vnode asked. If they resolve to be the same, then we
* ignore the match so that the real root gets used.
* This avoids the problem of traversing "../.." to find the
* root directory and never finding it, because "/" resolves
* to the emulation root directory. This is expensive :-(
*/
NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, svr4_emul_path,
td);
if ((error = namei(&ndroot)) != 0) {
/* Cannot happen! */
free(buf, M_TEMP);
vrele(nd.ni_vp);
return error;
}
NDFREE(&ndroot, NDF_ONLY_PNBUF);
if ((error = VOP_GETATTR(nd.ni_vp, &vat, td->td_ucred, td)) != 0) {
goto done;
}
if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, td->td_ucred, td))
!= 0) {
goto done;
}
if (vat.va_fsid == vatroot.va_fsid &&
vat.va_fileid == vatroot.va_fileid) {
error = ENOENT;
goto done;
}
}
if (sgp == NULL)
*pbuf = buf;
else {
sz = &ptr[len] - buf;
if ((*pbuf = stackgap_alloc(sgp, sz + 1)) != NULL)
error = copyout(buf, *pbuf, sz);
else
error = ENAMETOOLONG;
free(buf, M_TEMP);
}
done:
vrele(nd.ni_vp);
if (!cflag)
vrele(ndroot.ni_vp);
return error;
return (kern_alternate_path(td, svr4_emul_path, path, pathseg, pbuf,
create));
}
static int

View File

@ -39,6 +39,7 @@
#include <sys/exec.h>
#include <sys/sysent.h>
#include <sys/cdefs.h>
#include <sys/uio.h>
#ifdef DEBUG_SVR4
#define DPRINTF(a) uprintf a;
@ -70,21 +71,18 @@ stackgap_alloc(sgp, sz)
return p;
}
extern const char svr4_emul_path[];
int svr4_emul_find(struct thread *, caddr_t *, const char *, char *,
char **, int);
int svr4_emul_find(struct thread *, char *, enum uio_seg, char **, int);
#define CHECKALT(p, sgp, path, i) \
#define CHECKALT(td, upath, pathp, i) \
do { \
int _error; \
\
_error = svr4_emul_find(p, sgp, svr4_emul_path, path, \
&path, i); \
if (_error == EFAULT) \
_error = svr4_emul_find(td, upath, UIO_USERSPACE, pathp, i); \
if (*(pathp) == NULL) \
return (_error); \
} while (0)
#define CHECKALTEXIST(p, sgp, path) CHECKALT(p, sgp, path, 0)
#define CHECKALTCREAT(p, sgp, path) CHECKALT(p, sgp, path, 1)
#define CHECKALTEXIST(td, upath, pathp) CHECKALT(td, upath, pathp, 0)
#define CHECKALTCREAT(td, upath, pathp) CHECKALT(td, upath, pathp, 1)
#endif /* !_SVR4_UTIL_H_ */