2014-09-09 02:50:09 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
/* Needs to be first to twiddle appropriate system configuration/HAVE_* flags */
|
|
|
|
#include "config.h"
|
|
|
|
|
2014-09-09 02:50:09 +00:00
|
|
|
#include <sys/param.h>
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_SYS_ACL_H
|
|
|
|
#include <sys/acl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MKDEV_H
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef __sun__
|
|
|
|
#define _USE_STAT64
|
2014-09-09 02:50:09 +00:00
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
|
|
|
|
#ifdef _USE_STAT64
|
|
|
|
typedef struct stat64 stat_t;
|
|
|
|
#else
|
|
|
|
typedef struct stat stat_t;
|
2014-09-09 02:50:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ALLPERMS
|
|
|
|
#define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum action {
|
|
|
|
ACTION_OPEN,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_OPENAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_OPENAT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_CREATE,
|
|
|
|
ACTION_UNLINK,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_UNLINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_UNLINKAT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_MKDIR,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKDIRAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_MKDIRAT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_RMDIR,
|
|
|
|
ACTION_LINK,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_LINKAT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_SYMLINK,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_SYMLINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_SYMLINKAT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_RENAME,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_RENAMEAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_RENAMEAT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_MKFIFO,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKFIFOAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_MKFIFOAT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_MKNOD,
|
|
|
|
ACTION_MKNODAT,
|
|
|
|
ACTION_BIND,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_BINDAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_BINDAT,
|
|
|
|
#endif
|
|
|
|
ACTION_CONNECT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CONNECTAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_CONNECTAT,
|
|
|
|
#endif
|
|
|
|
ACTION_CHMOD,
|
|
|
|
ACTION_FCHMOD,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LCHMOD
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_LCHMOD,
|
|
|
|
#endif
|
|
|
|
ACTION_FCHMODAT,
|
|
|
|
ACTION_CHOWN,
|
|
|
|
ACTION_FCHOWN,
|
|
|
|
ACTION_LCHOWN,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHOWNAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_FCHOWNAT,
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_CHFLAGS,
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_FCHFLAGS,
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CHFLAGSAT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_CHFLAGSAT,
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LCHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_LCHFLAGS,
|
|
|
|
#endif
|
|
|
|
ACTION_TRUNCATE,
|
|
|
|
ACTION_FTRUNCATE,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_POSIX_FALLOCATE
|
|
|
|
ACTION_POSIX_FALLOCATE,
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_STAT,
|
|
|
|
ACTION_FSTAT,
|
|
|
|
ACTION_LSTAT,
|
|
|
|
ACTION_FSTATAT,
|
|
|
|
ACTION_PATHCONF,
|
|
|
|
ACTION_FPATHCONF,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LPATHCONF
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_LPATHCONF,
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAS_NFSV4_ACL_SUPPORT
|
2014-09-09 02:50:09 +00:00
|
|
|
ACTION_PREPENDACL,
|
|
|
|
ACTION_READACL,
|
|
|
|
#endif
|
|
|
|
ACTION_WRITE,
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_UTIMENSAT
|
|
|
|
ACTION_UTIMENSAT,
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define TYPE_NONE 0x0000
|
|
|
|
#define TYPE_STRING 0x0001
|
|
|
|
#define TYPE_NUMBER 0x0002
|
|
|
|
#define TYPE_DESCRIPTOR 0x0003
|
|
|
|
#define TYPE_MASK 0x000f
|
|
|
|
|
|
|
|
#define TYPE_OPTIONAL 0x0100
|
|
|
|
|
|
|
|
#define MAX_ARGS 8
|
|
|
|
|
|
|
|
struct syscall_desc {
|
|
|
|
const char *sd_name;
|
|
|
|
enum action sd_action;
|
|
|
|
int sd_args[MAX_ARGS];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct syscall_desc syscalls[] = {
|
|
|
|
{ "open", ACTION_OPEN, { TYPE_STRING, TYPE_STRING, TYPE_NUMBER | TYPE_OPTIONAL, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_OPENAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "openat", ACTION_OPENAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NUMBER | TYPE_OPTIONAL, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "create", ACTION_CREATE, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
|
|
|
|
{ "unlink", ACTION_UNLINK, { TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_UNLINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "unlinkat", ACTION_UNLINKAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "mkdir", ACTION_MKDIR, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKDIRAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "mkdirat", ACTION_MKDIRAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "rmdir", ACTION_RMDIR, { TYPE_STRING, TYPE_NONE } },
|
|
|
|
{ "link", ACTION_LINK, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "linkat", ACTION_LINKAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "symlink", ACTION_SYMLINK, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_SYMLINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "symlinkat", ACTION_SYMLINKAT, { TYPE_STRING, TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "rename", ACTION_RENAME, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_RENAMEAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "renameat", ACTION_RENAMEAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "mkfifo", ACTION_MKFIFO, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKFIFOAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "mkfifoat", ACTION_MKFIFOAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "mknod", ACTION_MKNOD, { TYPE_STRING, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE} },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKNODAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "mknodat", ACTION_MKNODAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE} },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "bind", ACTION_BIND, { TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_BINDAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "bindat", ACTION_BINDAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } },
|
|
|
|
#endif
|
|
|
|
{ "connect", ACTION_CONNECT, { TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CONNECTAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "connectat", ACTION_CONNECTAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } },
|
|
|
|
#endif
|
|
|
|
{ "chmod", ACTION_CHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
|
|
|
|
{ "fchmod", ACTION_FCHMOD, { TYPE_DESCRIPTOR, TYPE_NUMBER, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LCHMOD
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "lchmod", ACTION_LCHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHMODAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "fchmodat", ACTION_FCHMODAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NUMBER, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "chown", ACTION_CHOWN, { TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } },
|
|
|
|
{ "fchown", ACTION_FCHOWN, { TYPE_DESCRIPTOR, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } },
|
|
|
|
{ "lchown", ACTION_LCHOWN, { TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHOWNAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "fchownat", ACTION_FCHOWNAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "chflags", ACTION_CHFLAGS, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "fchflags", ACTION_FCHFLAGS, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CHFLAGSAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "chflagsat", ACTION_CHFLAGSAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LCHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "lchflags", ACTION_LCHFLAGS, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
|
|
|
#endif
|
|
|
|
{ "truncate", ACTION_TRUNCATE, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
|
|
|
|
{ "ftruncate", ACTION_FTRUNCATE, { TYPE_DESCRIPTOR, TYPE_NUMBER, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_POSIX_FALLOCATE
|
|
|
|
{ "posix_fallocate", ACTION_POSIX_FALLOCATE, { TYPE_DESCRIPTOR, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } },
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "stat", ACTION_STAT, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
|
|
|
{ "fstat", ACTION_FSTAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } },
|
|
|
|
{ "lstat", ACTION_LSTAT, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FSTATAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "fstatat", ACTION_FSTATAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "pathconf", ACTION_PATHCONF, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
|
|
|
{ "fpathconf", ACTION_FPATHCONF, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LPATHCONF
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "lpathconf", ACTION_LPATHCONF, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAS_NFSV4_ACL_SUPPORT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ "prependacl", ACTION_PREPENDACL, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
|
|
|
|
{ "readacl", ACTION_READACL, { TYPE_STRING, TYPE_NONE } },
|
|
|
|
#endif
|
|
|
|
{ "write", ACTION_WRITE, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } },
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_UTIMENSAT
|
|
|
|
{ "utimensat", ACTION_UTIMENSAT, {
|
|
|
|
TYPE_DESCRIPTOR, /* Directory */
|
|
|
|
TYPE_STRING, /* Relative path */
|
|
|
|
TYPE_NUMBER, /* atime seconds */
|
|
|
|
TYPE_STRING, /* atime nanoseconds */
|
|
|
|
TYPE_NUMBER, /* mtime seconds */
|
|
|
|
TYPE_STRING, /* mtime nanoseconds */
|
|
|
|
TYPE_STRING, /* flags */}},
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ NULL, -1, { TYPE_NONE } }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct flag {
|
|
|
|
long long f_flag;
|
|
|
|
const char *f_str;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct flag open_flags[] = {
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_RDONLY
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_RDONLY, "O_RDONLY" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_WRONLY
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_WRONLY, "O_WRONLY" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_RDWR
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_RDWR, "O_RDWR" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_NONBLOCK
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_NONBLOCK, "O_NONBLOCK" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_APPEND
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_APPEND, "O_APPEND" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_CREAT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_CREAT, "O_CREAT" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_TRUNC
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_TRUNC, "O_TRUNC" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_EXCL
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_EXCL, "O_EXCL" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_SHLOCK
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_SHLOCK, "O_SHLOCK" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_EXLOCK
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_EXLOCK, "O_EXLOCK" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_DIRECT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_DIRECT, "O_DIRECT" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_FSYNC
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_FSYNC, "O_FSYNC" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_SYNC
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_SYNC, "O_SYNC" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_NOFOLLOW
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_NOFOLLOW, "O_NOFOLLOW" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_NOCTTY
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_NOCTTY, "O_NOCTTY" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef O_DIRECTORY
|
2014-09-09 02:50:09 +00:00
|
|
|
{ O_DIRECTORY, "O_DIRECTORY" },
|
|
|
|
#endif
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
static struct flag chflags_flags[] = {
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef UF_NODUMP
|
2014-09-09 02:50:09 +00:00
|
|
|
{ UF_NODUMP, "UF_NODUMP" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef UF_IMMUTABLE
|
2014-09-09 02:50:09 +00:00
|
|
|
{ UF_IMMUTABLE, "UF_IMMUTABLE" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef UF_APPEND
|
2014-09-09 02:50:09 +00:00
|
|
|
{ UF_APPEND, "UF_APPEND" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef UF_NOUNLINK
|
2014-09-09 02:50:09 +00:00
|
|
|
{ UF_NOUNLINK, "UF_NOUNLINK" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef UF_OPAQUE
|
2014-09-09 02:50:09 +00:00
|
|
|
{ UF_OPAQUE, "UF_OPAQUE" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef SF_ARCHIVED
|
2014-09-09 02:50:09 +00:00
|
|
|
{ SF_ARCHIVED, "SF_ARCHIVED" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef SF_IMMUTABLE
|
2014-09-09 02:50:09 +00:00
|
|
|
{ SF_IMMUTABLE, "SF_IMMUTABLE" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef SF_APPEND
|
2014-09-09 02:50:09 +00:00
|
|
|
{ SF_APPEND, "SF_APPEND" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef SF_NOUNLINK
|
2014-09-09 02:50:09 +00:00
|
|
|
{ SF_NOUNLINK, "SF_NOUNLINK" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef SF_SNAPSHOT
|
2014-09-09 02:50:09 +00:00
|
|
|
{ SF_SNAPSHOT, "SF_SNAPSHOT" },
|
|
|
|
#endif
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_UNLINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
static struct flag unlinkat_flags[] = {
|
|
|
|
{ AT_REMOVEDIR, "AT_REMOVEDIR" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
static struct flag linkat_flags[] = {
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef AT_SYMLINK_FOLLOW
|
2014-09-09 02:50:09 +00:00
|
|
|
{ AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CHFLAGSAT
|
2014-09-09 02:50:09 +00:00
|
|
|
static struct flag chflagsat_flags[] = {
|
|
|
|
{ AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHMODAT
|
2014-09-09 02:50:09 +00:00
|
|
|
static struct flag fchmodat_flags[] = {
|
|
|
|
{ AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHOWNAT
|
2014-09-09 02:50:09 +00:00
|
|
|
static struct flag fchownat_flags[] = {
|
|
|
|
{ AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FSTATAT
|
2014-09-09 02:50:09 +00:00
|
|
|
static struct flag fstatat_flags[] = {
|
|
|
|
{ AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
|
|
|
|
struct name {
|
|
|
|
int n_name;
|
|
|
|
const char *n_str;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct name pathconf_names[] = {
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _PC_LINK_MAX
|
2014-09-09 02:50:09 +00:00
|
|
|
{ _PC_LINK_MAX, "_PC_LINK_MAX" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _PC_NAME_MAX
|
2014-09-09 02:50:09 +00:00
|
|
|
{ _PC_NAME_MAX, "_PC_NAME_MAX" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _PC_PATH_MAX
|
2014-09-09 02:50:09 +00:00
|
|
|
{ _PC_PATH_MAX, "_PC_PATH_MAX" },
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _PC_SYMLINK_MAX
|
2014-09-09 02:50:09 +00:00
|
|
|
{ _PC_SYMLINK_MAX, "_PC_SYMLINK_MAX" },
|
|
|
|
#endif
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *err2str(int error);
|
|
|
|
|
|
|
|
static int *descriptors;
|
|
|
|
static int ndescriptors;
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "usage: pjdfstest [-U umask] [-u uid] [-g gid1[,gid2[...]]] syscall args ...\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static long long
|
|
|
|
str2flags(struct flag *tflags, char *sflags)
|
|
|
|
{
|
|
|
|
long long flags = 0;
|
|
|
|
unsigned int i;
|
|
|
|
char *f;
|
|
|
|
|
|
|
|
/* 'none' or '0' means no flags */
|
|
|
|
if (strcmp(sflags, "none") == 0 || strcmp(sflags, "0") == 0)
|
|
|
|
return (0);
|
|
|
|
for (f = strtok(sflags, ",|"); f != NULL; f = strtok(NULL, ",|")) {
|
|
|
|
for (i = 0; tflags[i].f_str != NULL; i++) {
|
|
|
|
if (strcmp(tflags[i].f_str, f) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tflags[i].f_str == NULL) {
|
|
|
|
fprintf(stderr, "unknown flag '%s'\n", f);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
flags |= tflags[i].f_flag;
|
|
|
|
}
|
|
|
|
return (flags);
|
|
|
|
}
|
|
|
|
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
static char *
|
|
|
|
flags2str(struct flag *tflags, long long flags)
|
|
|
|
{
|
|
|
|
static char sflags[1024];
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
sflags[0] = '\0';
|
|
|
|
for (i = 0; tflags[i].f_str != NULL; i++) {
|
|
|
|
if (flags & tflags[i].f_flag) {
|
|
|
|
if (sflags[0] != '\0')
|
|
|
|
strlcat(sflags, ",", sizeof(sflags));
|
|
|
|
strlcat(sflags, tflags[i].f_str, sizeof(sflags));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sflags[0] == '\0')
|
|
|
|
strlcpy(sflags, "none", sizeof(sflags));
|
|
|
|
return (sflags);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
str2name(struct name *names, char *name)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; names[i].n_str != NULL; i++) {
|
|
|
|
if (strcmp(names[i].n_str, name) == 0)
|
|
|
|
return (names[i].n_name);
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct syscall_desc *
|
|
|
|
find_syscall(const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; syscalls[i].sd_name != NULL; i++) {
|
|
|
|
if (strcmp(syscalls[i].sd_name, name) == 0)
|
|
|
|
return (&syscalls[i]);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-06-28 08:48:09 +00:00
|
|
|
show_stat(stat_t *sp, const char *what)
|
2014-09-09 02:50:09 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (strcmp(what, "mode") == 0)
|
|
|
|
printf("0%o", (unsigned int)(sp->st_mode & ALLPERMS));
|
|
|
|
else if (strcmp(what, "inode") == 0)
|
|
|
|
printf("%lld", (long long)sp->st_ino);
|
|
|
|
else if (strcmp(what, "nlink") == 0)
|
|
|
|
printf("%lld", (long long)sp->st_nlink);
|
|
|
|
else if (strcmp(what, "uid") == 0)
|
|
|
|
printf("%d", (int)sp->st_uid);
|
|
|
|
else if (strcmp(what, "gid") == 0)
|
|
|
|
printf("%d", (int)sp->st_gid);
|
|
|
|
else if (strcmp(what, "size") == 0)
|
|
|
|
printf("%lld", (long long)sp->st_size);
|
|
|
|
else if (strcmp(what, "blocks") == 0)
|
|
|
|
printf("%lld", (long long)sp->st_blocks);
|
|
|
|
else if (strcmp(what, "atime") == 0)
|
|
|
|
printf("%lld", (long long)sp->st_atime);
|
2017-06-28 08:48:09 +00:00
|
|
|
#if defined(HAVE_STRUCT_STAT_ST_ATIM) || \
|
|
|
|
defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
|
|
|
|
else if (strcmp(what, "atime_ns") == 0)
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_ATIMESPEC
|
|
|
|
printf("%lld", (long long)sp->st_atimespec.tv_nsec);
|
|
|
|
#else
|
|
|
|
printf("%lld", (long long)sp->st_atim.tv_nsec);
|
|
|
|
#endif
|
|
|
|
#endif /* st_atim* */
|
2014-09-09 02:50:09 +00:00
|
|
|
else if (strcmp(what, "ctime") == 0)
|
|
|
|
printf("%lld", (long long)sp->st_ctime);
|
2017-06-28 08:48:09 +00:00
|
|
|
#if defined(HAVE_STRUCT_STAT_ST_CTIM) || \
|
|
|
|
defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
|
|
|
|
else if (strcmp(what, "ctime_ns") == 0)
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_CTIMESPEC
|
|
|
|
printf("%lld", (long long)sp->st_ctimespec.tv_nsec);
|
|
|
|
#else
|
|
|
|
printf("%lld", (long long)sp->st_ctim.tv_nsec);
|
|
|
|
#endif
|
|
|
|
#endif /* st_ctim* */
|
|
|
|
else if (strcmp(what, "mtime") == 0)
|
|
|
|
printf("%lld", (long long)sp->st_mtime);
|
|
|
|
else if (strcmp(what, "mtime_ns") == 0)
|
|
|
|
#if defined(HAVE_STRUCT_STAT_ST_MTIM) || \
|
|
|
|
defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_MTIMESPEC
|
|
|
|
printf("%lld", (long long)sp->st_mtimespec.tv_nsec);
|
|
|
|
#else
|
|
|
|
printf("%lld", (long long)sp->st_mtim.tv_nsec);
|
|
|
|
#endif
|
|
|
|
#endif /* st_mtim* */
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
|
|
|
|
else if (strcmp(what, "birthtime") == 0)
|
|
|
|
printf("%lld", (long long)sp->st_birthtime);
|
|
|
|
#endif /* st_birthtime */
|
|
|
|
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIM) || \
|
|
|
|
defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC)
|
|
|
|
else if (strcmp(what, "birthtime_ns") == 0)
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC
|
|
|
|
printf("%lld", (long long)sp->st_birthtimespec.tv_nsec);
|
|
|
|
#else
|
|
|
|
printf("%lld", (long long)sp->st_birthtim.tv_nsec);
|
|
|
|
#endif
|
|
|
|
#endif /* st_birthtim{,espec} */
|
|
|
|
#ifdef HAVE_CHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
else if (strcmp(what, "flags") == 0)
|
|
|
|
printf("%s", flags2str(chflags_flags, (long long)sp->st_flags));
|
|
|
|
#endif
|
|
|
|
else if (strcmp(what, "major") == 0)
|
|
|
|
printf("%u", (unsigned int)major(sp->st_rdev));
|
|
|
|
else if (strcmp(what, "minor") == 0)
|
|
|
|
printf("%u", (unsigned int)minor(sp->st_rdev));
|
|
|
|
else if (strcmp(what, "type") == 0) {
|
|
|
|
switch (sp->st_mode & S_IFMT) {
|
|
|
|
case S_IFIFO:
|
|
|
|
printf("fifo");
|
|
|
|
break;
|
|
|
|
case S_IFCHR:
|
|
|
|
printf("char");
|
|
|
|
break;
|
|
|
|
case S_IFDIR:
|
|
|
|
printf("dir");
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
printf("block");
|
|
|
|
break;
|
|
|
|
case S_IFREG:
|
|
|
|
printf("regular");
|
|
|
|
break;
|
|
|
|
case S_IFLNK:
|
|
|
|
printf("symlink");
|
|
|
|
break;
|
|
|
|
case S_IFSOCK:
|
|
|
|
printf("socket");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-06-28 08:48:09 +00:00
|
|
|
show_stats(stat_t *sp, char *what)
|
2014-09-09 02:50:09 +00:00
|
|
|
{
|
|
|
|
const char *s = "";
|
|
|
|
char *w;
|
|
|
|
|
|
|
|
for (w = strtok(what, ","); w != NULL; w = strtok(NULL, ",")) {
|
|
|
|
printf("%s", s);
|
|
|
|
show_stat(sp, w);
|
|
|
|
s = ",";
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
descriptor_add(int fd)
|
|
|
|
{
|
|
|
|
|
|
|
|
ndescriptors++;
|
|
|
|
if (descriptors == NULL) {
|
|
|
|
descriptors = malloc(sizeof(descriptors[0]) * ndescriptors);
|
|
|
|
} else {
|
|
|
|
descriptors = realloc(descriptors,
|
|
|
|
sizeof(descriptors[0]) * ndescriptors);
|
|
|
|
}
|
|
|
|
assert(descriptors != NULL);
|
|
|
|
descriptors[ndescriptors - 1] = fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
descriptor_get(int pos)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (pos < 0 || pos >= ndescriptors) {
|
|
|
|
fprintf(stderr, "invalid descriptor %d\n", pos);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (descriptors[pos]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
call_syscall(struct syscall_desc *scall, char *argv[])
|
|
|
|
{
|
2017-06-28 08:48:09 +00:00
|
|
|
stat_t sb;
|
|
|
|
#ifdef HAVE_UTIMENSAT
|
|
|
|
struct timespec times[2];
|
|
|
|
int flag;
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
long long flags;
|
|
|
|
unsigned int i;
|
|
|
|
char *endp;
|
|
|
|
int name, rval;
|
|
|
|
union {
|
|
|
|
char *str;
|
|
|
|
long long num;
|
|
|
|
} args[MAX_ARGS];
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAS_NFSV4_ACL_SUPPORT
|
2014-09-09 02:50:09 +00:00
|
|
|
int entry_id = ACL_FIRST_ENTRY;
|
|
|
|
acl_t acl, newacl;
|
|
|
|
acl_entry_t entry, newentry;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify correctness of the arguments.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sizeof(args)/sizeof(args[0]); i++) {
|
|
|
|
if (scall->sd_args[i] == TYPE_NONE) {
|
|
|
|
if (argv[i] == NULL || strcmp(argv[i], ":") == 0)
|
|
|
|
break;
|
|
|
|
fprintf(stderr, "too many arguments [%s]\n", argv[i]);
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
if (argv[i] == NULL || strcmp(argv[i], ":") == 0) {
|
|
|
|
if (scall->sd_args[i] & TYPE_OPTIONAL)
|
|
|
|
break;
|
|
|
|
fprintf(stderr, "too few arguments\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((scall->sd_args[i] & TYPE_MASK) == TYPE_STRING) {
|
|
|
|
if (strcmp(argv[i], "NULL") == 0)
|
|
|
|
args[i].str = NULL;
|
|
|
|
else if (strcmp(argv[i], "DEADCODE") == 0)
|
|
|
|
args[i].str = (void *)0xdeadc0de;
|
|
|
|
else
|
|
|
|
args[i].str = argv[i];
|
|
|
|
} else if ((scall->sd_args[i] & TYPE_MASK) ==
|
|
|
|
TYPE_NUMBER) {
|
|
|
|
args[i].num = strtoll(argv[i], &endp, 0);
|
|
|
|
if (*endp != '\0' &&
|
|
|
|
!isspace((unsigned char)*endp)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"invalid argument %u, number expected [%s]\n",
|
|
|
|
i, endp);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else if ((scall->sd_args[i] & TYPE_MASK) ==
|
|
|
|
TYPE_DESCRIPTOR) {
|
|
|
|
if (strcmp(argv[i], "AT_FDCWD") == 0) {
|
|
|
|
args[i].num = AT_FDCWD;
|
|
|
|
} else if (strcmp(argv[i], "BADFD") == 0) {
|
|
|
|
/* In case AT_FDCWD is -1 on some systems... */
|
|
|
|
if (AT_FDCWD == -1)
|
|
|
|
args[i].num = -2;
|
|
|
|
else
|
|
|
|
args[i].num = -1;
|
|
|
|
} else {
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
pos = strtoll(argv[i], &endp, 0);
|
|
|
|
if (*endp != '\0' &&
|
|
|
|
!isspace((unsigned char)*endp)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"invalid argument %u, number expected [%s]\n",
|
|
|
|
i, endp);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
args[i].num = descriptor_get(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Call the given syscall.
|
|
|
|
*/
|
|
|
|
#define NUM(n) (args[(n)].num)
|
|
|
|
#define STR(n) (args[(n)].str)
|
|
|
|
switch (scall->sd_action) {
|
|
|
|
case ACTION_OPEN:
|
|
|
|
flags = str2flags(open_flags, STR(1));
|
|
|
|
if (flags & O_CREAT) {
|
|
|
|
if (i == 2) {
|
|
|
|
fprintf(stderr, "too few arguments\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rval = open(STR(0), (int)flags, (mode_t)NUM(2));
|
|
|
|
} else {
|
|
|
|
if (i == 3) {
|
|
|
|
fprintf(stderr, "too many arguments\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rval = open(STR(0), (int)flags);
|
|
|
|
}
|
|
|
|
if (rval >= 0)
|
|
|
|
descriptor_add(rval);
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_OPENAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_OPENAT:
|
|
|
|
flags = str2flags(open_flags, STR(2));
|
|
|
|
if (flags & O_CREAT) {
|
|
|
|
if (i == 3) {
|
|
|
|
fprintf(stderr, "too few arguments\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rval = openat(NUM(0), STR(1), (int)flags,
|
|
|
|
(mode_t)NUM(3));
|
|
|
|
} else {
|
|
|
|
if (i == 4) {
|
|
|
|
fprintf(stderr, "too many arguments\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rval = openat(NUM(0), STR(1), (int)flags);
|
|
|
|
}
|
|
|
|
if (rval >= 0)
|
|
|
|
descriptor_add(rval);
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_CREATE:
|
|
|
|
rval = open(STR(0), O_CREAT | O_EXCL, (mode_t)NUM(1));
|
|
|
|
if (rval >= 0)
|
|
|
|
close(rval);
|
|
|
|
break;
|
|
|
|
case ACTION_UNLINK:
|
|
|
|
rval = unlink(STR(0));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_UNLINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_UNLINKAT:
|
|
|
|
rval = unlinkat(NUM(0), STR(1),
|
|
|
|
(int)str2flags(unlinkat_flags, STR(2)));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_MKDIR:
|
|
|
|
rval = mkdir(STR(0), (mode_t)NUM(1));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKDIRAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_MKDIRAT:
|
|
|
|
rval = mkdirat(NUM(0), STR(1), (mode_t)NUM(2));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_RMDIR:
|
|
|
|
rval = rmdir(STR(0));
|
|
|
|
break;
|
|
|
|
case ACTION_LINK:
|
|
|
|
rval = link(STR(0), STR(1));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_LINKAT:
|
|
|
|
rval = linkat(NUM(0), STR(1), NUM(2), STR(3),
|
|
|
|
(int)str2flags(linkat_flags, STR(4)));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_SYMLINK:
|
|
|
|
rval = symlink(STR(0), STR(1));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_SYMLINKAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_SYMLINKAT:
|
|
|
|
rval = symlinkat(STR(0), NUM(1), STR(2));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_RENAME:
|
|
|
|
rval = rename(STR(0), STR(1));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_RENAMEAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_RENAMEAT:
|
|
|
|
rval = renameat(NUM(0), STR(1), NUM(2), STR(3));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_MKFIFO:
|
|
|
|
rval = mkfifo(STR(0), (mode_t)NUM(1));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKFIFOAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_MKFIFOAT:
|
|
|
|
rval = mkfifoat(NUM(0), STR(1), (mode_t)NUM(2));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_MKNOD:
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKNODAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_MKNODAT:
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
{
|
|
|
|
mode_t ntype;
|
|
|
|
dev_t dev;
|
|
|
|
int fa;
|
|
|
|
|
|
|
|
switch (scall->sd_action) {
|
|
|
|
case ACTION_MKNOD:
|
|
|
|
fa = 0;
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKNODAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_MKNODAT:
|
|
|
|
fa = 1;
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = makedev(NUM(fa + 3), NUM(fa + 4));
|
|
|
|
if (strcmp(STR(fa + 1), "c") == 0) /* character device */
|
|
|
|
ntype = S_IFCHR;
|
|
|
|
else if (strcmp(STR(fa + 1), "b") == 0) /* block device */
|
|
|
|
ntype = S_IFBLK;
|
|
|
|
else if (strcmp(STR(fa + 1), "f") == 0) /* fifo special */
|
|
|
|
ntype = S_IFIFO;
|
|
|
|
else if (strcmp(STR(fa + 1), "d") == 0) /* directory */
|
|
|
|
ntype = S_IFDIR;
|
|
|
|
else if (strcmp(STR(fa + 1), "o") == 0) /* regular file */
|
|
|
|
ntype = S_IFREG;
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "wrong argument 1\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
switch (scall->sd_action) {
|
|
|
|
case ACTION_MKNOD:
|
|
|
|
rval = mknod(STR(0), ntype | NUM(2), dev);
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_MKNODAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_MKNODAT:
|
|
|
|
rval = mknodat(NUM(0), STR(1), ntype | NUM(3), dev);
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTION_BIND:
|
|
|
|
{
|
|
|
|
struct sockaddr_un sunx;
|
|
|
|
|
|
|
|
sunx.sun_family = AF_UNIX;
|
|
|
|
strncpy(sunx.sun_path, STR(0), sizeof(sunx.sun_path) - 1);
|
|
|
|
sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0';
|
|
|
|
rval = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (rval < 0)
|
|
|
|
break;
|
|
|
|
rval = bind(rval, (struct sockaddr *)&sunx, sizeof(sunx));
|
|
|
|
break;
|
|
|
|
}
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_BINDAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_BINDAT:
|
|
|
|
{
|
|
|
|
struct sockaddr_un sunx;
|
|
|
|
|
|
|
|
sunx.sun_family = AF_UNIX;
|
|
|
|
strncpy(sunx.sun_path, STR(1), sizeof(sunx.sun_path) - 1);
|
|
|
|
sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0';
|
|
|
|
rval = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (rval < 0)
|
|
|
|
break;
|
|
|
|
rval = bindat(NUM(0), rval, (struct sockaddr *)&sunx,
|
|
|
|
sizeof(sunx));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case ACTION_CONNECT:
|
|
|
|
{
|
|
|
|
struct sockaddr_un sunx;
|
|
|
|
|
|
|
|
sunx.sun_family = AF_UNIX;
|
|
|
|
strncpy(sunx.sun_path, STR(0), sizeof(sunx.sun_path) - 1);
|
|
|
|
sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0';
|
|
|
|
rval = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (rval < 0)
|
|
|
|
break;
|
|
|
|
rval = connect(rval, (struct sockaddr *)&sunx, sizeof(sunx));
|
|
|
|
break;
|
|
|
|
}
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CONNECTAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_CONNECTAT:
|
|
|
|
{
|
|
|
|
struct sockaddr_un sunx;
|
|
|
|
|
|
|
|
sunx.sun_family = AF_UNIX;
|
|
|
|
strncpy(sunx.sun_path, STR(1), sizeof(sunx.sun_path) - 1);
|
|
|
|
sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0';
|
|
|
|
rval = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (rval < 0)
|
|
|
|
break;
|
|
|
|
rval = connectat(NUM(0), rval, (struct sockaddr *)&sunx,
|
|
|
|
sizeof(sunx));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case ACTION_CHMOD:
|
|
|
|
rval = chmod(STR(0), (mode_t)NUM(1));
|
|
|
|
break;
|
|
|
|
case ACTION_FCHMOD:
|
|
|
|
rval = fchmod(NUM(0), (mode_t)NUM(1));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LCHMOD
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_LCHMOD:
|
|
|
|
rval = lchmod(STR(0), (mode_t)NUM(1));
|
|
|
|
break;
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHMODAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_FCHMODAT:
|
|
|
|
rval = fchmodat(NUM(0), STR(1), (mode_t)NUM(2),
|
|
|
|
str2flags(fchmodat_flags, STR(3)));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_CHOWN:
|
|
|
|
rval = chown(STR(0), (uid_t)NUM(1), (gid_t)NUM(2));
|
|
|
|
break;
|
|
|
|
case ACTION_FCHOWN:
|
|
|
|
rval = fchown(NUM(0), (uid_t)NUM(1), (gid_t)NUM(2));
|
|
|
|
break;
|
|
|
|
case ACTION_LCHOWN:
|
|
|
|
rval = lchown(STR(0), (uid_t)NUM(1), (gid_t)NUM(2));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHOWNAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_FCHOWNAT:
|
|
|
|
rval = fchownat(NUM(0), STR(1), (uid_t)NUM(2), (gid_t)NUM(3),
|
|
|
|
(int)str2flags(fchownat_flags, STR(4)));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_CHFLAGS:
|
|
|
|
rval = chflags(STR(0),
|
|
|
|
(unsigned long)str2flags(chflags_flags, STR(1)));
|
|
|
|
break;
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FCHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_FCHFLAGS:
|
|
|
|
rval = fchflags(NUM(0),
|
|
|
|
(unsigned long)str2flags(chflags_flags, STR(1)));
|
|
|
|
break;
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_CHFLAGSAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_CHFLAGSAT:
|
|
|
|
rval = chflagsat(NUM(0), STR(1),
|
|
|
|
(unsigned long)str2flags(chflags_flags, STR(2)),
|
|
|
|
(int)str2flags(chflagsat_flags, STR(3)));
|
|
|
|
break;
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LCHFLAGS
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_LCHFLAGS:
|
|
|
|
rval = lchflags(STR(0),
|
|
|
|
(unsigned long)str2flags(chflags_flags, STR(1)));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case ACTION_TRUNCATE:
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _USE_STAT64
|
2014-09-09 02:50:09 +00:00
|
|
|
rval = truncate64(STR(0), NUM(1));
|
2017-06-28 08:48:09 +00:00
|
|
|
#else
|
|
|
|
rval = truncate(STR(0), NUM(1));
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
break;
|
|
|
|
case ACTION_FTRUNCATE:
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _USE_STAT64
|
2014-09-09 02:50:09 +00:00
|
|
|
rval = ftruncate64(NUM(0), NUM(1));
|
2017-06-28 08:48:09 +00:00
|
|
|
#else
|
|
|
|
rval = ftruncate(NUM(0), NUM(1));
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_POSIX_FALLOCATE
|
|
|
|
case ACTION_POSIX_FALLOCATE:
|
|
|
|
rval = posix_fallocate(NUM(0), NUM(1), NUM(2));
|
|
|
|
if (rval != 0) {
|
|
|
|
errno = rval;
|
|
|
|
rval = -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_STAT:
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _USE_STAT64
|
2014-09-09 02:50:09 +00:00
|
|
|
rval = stat64(STR(0), &sb);
|
2017-06-28 08:48:09 +00:00
|
|
|
#else
|
|
|
|
rval = stat(STR(0), &sb);
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
if (rval == 0) {
|
|
|
|
show_stats(&sb, STR(1));
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACTION_FSTAT:
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _USE_STAT64
|
2014-09-09 02:50:09 +00:00
|
|
|
rval = fstat64(NUM(0), &sb);
|
2017-06-28 08:48:09 +00:00
|
|
|
#else
|
|
|
|
rval = fstat(NUM(0), &sb);
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
if (rval == 0) {
|
|
|
|
show_stats(&sb, STR(1));
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACTION_LSTAT:
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef _USE_STAT64
|
2014-09-09 02:50:09 +00:00
|
|
|
rval = lstat64(STR(0), &sb);
|
2017-06-28 08:48:09 +00:00
|
|
|
#else
|
|
|
|
rval = lstat(STR(0), &sb);
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
if (rval == 0) {
|
|
|
|
show_stats(&sb, STR(1));
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_FSTATAT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_FSTATAT:
|
|
|
|
rval = fstatat(NUM(0), STR(1), &sb,
|
|
|
|
(int)str2flags(fstatat_flags, STR(2)));
|
|
|
|
if (rval == 0) {
|
|
|
|
show_stats(&sb, STR(3));
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_PATHCONF:
|
|
|
|
case ACTION_FPATHCONF:
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LPATHCONF
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_LPATHCONF:
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
long lrval;
|
|
|
|
|
|
|
|
name = str2name(pathconf_names, STR(1));
|
|
|
|
if (name == -1) {
|
|
|
|
fprintf(stderr, "unknown name %s", STR(1));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
errno = 0;
|
|
|
|
switch (scall->sd_action) {
|
|
|
|
case ACTION_PATHCONF:
|
|
|
|
lrval = pathconf(STR(0), name);
|
|
|
|
break;
|
|
|
|
case ACTION_FPATHCONF:
|
|
|
|
lrval = fpathconf(NUM(0), name);
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_LPATHCONF
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_LPATHCONF:
|
|
|
|
lrval = lpathconf(STR(0), name);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (lrval == -1 && errno == 0) {
|
|
|
|
printf("unlimited\n");
|
|
|
|
return (i);
|
|
|
|
} else if (lrval >= 0) {
|
|
|
|
printf("%ld\n", lrval);
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
rval = -1;
|
|
|
|
break;
|
|
|
|
}
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAS_NFSV4_ACL_SUPPORT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ACTION_PREPENDACL:
|
|
|
|
rval = -1;
|
|
|
|
|
|
|
|
acl = acl_get_file(STR(0), ACL_TYPE_NFS4);
|
|
|
|
if (acl == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
newacl = acl_from_text(STR(1));
|
|
|
|
if (acl == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
while (acl_get_entry(newacl, entry_id, &newentry) == 1) {
|
|
|
|
entry_id = ACL_NEXT_ENTRY;
|
|
|
|
|
|
|
|
if (acl_create_entry_np(&acl, &entry, 0))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (acl_copy_entry(entry, newentry))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rval = acl_set_file(STR(0), ACL_TYPE_NFS4, acl);
|
|
|
|
break;
|
|
|
|
case ACTION_READACL:
|
|
|
|
acl = acl_get_file(STR(0), ACL_TYPE_NFS4);
|
|
|
|
if (acl == NULL)
|
|
|
|
rval = -1;
|
|
|
|
else
|
|
|
|
rval = 0;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case ACTION_WRITE:
|
|
|
|
rval = write(NUM(0), STR(1), strlen(STR(1)));
|
|
|
|
break;
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef HAVE_UTIMENSAT
|
|
|
|
case ACTION_UTIMENSAT:
|
|
|
|
times[0].tv_sec = NUM(2);
|
|
|
|
if (strcmp(STR(3), "UTIME_NOW") == 0)
|
|
|
|
times[0].tv_nsec = UTIME_NOW;
|
|
|
|
else if (strcmp(STR(3), "UTIME_OMIT") == 0)
|
|
|
|
times[0].tv_nsec = UTIME_OMIT;
|
|
|
|
else
|
|
|
|
times[0].tv_nsec = strtol(STR(3), NULL, 10);
|
|
|
|
times[1].tv_sec = NUM(4);
|
|
|
|
if (strcmp(STR(5), "UTIME_NOW") == 0)
|
|
|
|
times[1].tv_nsec = UTIME_NOW;
|
|
|
|
else if (strcmp(STR(5), "UTIME_OMIT") == 0)
|
|
|
|
times[1].tv_nsec = UTIME_OMIT;
|
|
|
|
else
|
|
|
|
times[1].tv_nsec = strtol(STR(5), NULL, 10);
|
|
|
|
if (strcmp(STR(6), "AT_SYMLINK_NOFOLLOW") == 0)
|
|
|
|
flag = AT_SYMLINK_NOFOLLOW;
|
|
|
|
else
|
|
|
|
flag = strtol(STR(6), NULL, 10);
|
|
|
|
rval = utimensat(NUM(0), STR(1), times, flag);
|
|
|
|
break;
|
|
|
|
#endif
|
2014-09-09 02:50:09 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "unsupported syscall\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#undef STR
|
|
|
|
#undef NUM
|
|
|
|
if (rval < 0) {
|
|
|
|
const char *serrno;
|
|
|
|
|
|
|
|
serrno = err2str(errno);
|
|
|
|
fprintf(stderr, "%s returned %d\n", scall->sd_name, rval);
|
|
|
|
printf("%s\n", serrno);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
printf("0\n");
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_gids(char *gids)
|
|
|
|
{
|
|
|
|
gid_t *gidset;
|
|
|
|
long ngroups;
|
|
|
|
char *g, *endp;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
ngroups = sysconf(_SC_NGROUPS_MAX);
|
|
|
|
assert(ngroups > 0);
|
|
|
|
gidset = malloc(sizeof(*gidset) * ngroups);
|
|
|
|
assert(gidset != NULL);
|
|
|
|
for (i = 0, g = strtok(gids, ","); g != NULL;
|
|
|
|
g = strtok(NULL, ","), i++) {
|
2017-06-28 08:48:09 +00:00
|
|
|
if ((long)i >= ngroups) {
|
2014-09-09 02:50:09 +00:00
|
|
|
fprintf(stderr, "too many gids\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
gidset[i] = strtol(g, &endp, 0);
|
|
|
|
if (*endp != '\0' && !isspace((unsigned char)*endp)) {
|
|
|
|
fprintf(stderr, "invalid gid '%s' - number expected\n",
|
|
|
|
g);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (setgroups(i, gidset) < 0) {
|
|
|
|
fprintf(stderr, "cannot change groups: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (setegid(gidset[0]) < 0) {
|
|
|
|
fprintf(stderr, "cannot change effective gid: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
free(gidset);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct syscall_desc *scall;
|
|
|
|
unsigned int n;
|
|
|
|
char *gids, *endp;
|
|
|
|
int uid, umsk, ch;
|
|
|
|
|
|
|
|
uid = -1;
|
|
|
|
gids = NULL;
|
|
|
|
umsk = 0;
|
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, "g:u:U:")) != -1) {
|
|
|
|
switch(ch) {
|
|
|
|
case 'g':
|
|
|
|
gids = optarg;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
uid = (int)strtol(optarg, &endp, 0);
|
|
|
|
if (*endp != '\0' && !isspace((unsigned char)*endp)) {
|
|
|
|
fprintf(stderr, "invalid uid '%s' - number "
|
|
|
|
"expected\n", optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
umsk = (int)strtol(optarg, &endp, 0);
|
|
|
|
if (*endp != '\0' && !isspace((unsigned char)*endp)) {
|
|
|
|
fprintf(stderr, "invalid umask '%s' - number "
|
|
|
|
"expected\n", optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
fprintf(stderr, "too few arguments\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gids != NULL) {
|
|
|
|
fprintf(stderr, "changing groups to %s\n", gids);
|
|
|
|
set_gids(gids);
|
|
|
|
}
|
|
|
|
if (uid != -1) {
|
|
|
|
fprintf(stderr, "changing uid to %d\n", uid);
|
|
|
|
if (setuid(uid) < 0) {
|
|
|
|
fprintf(stderr, "cannot change uid: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change umask to requested value or to 0, if not requested. */
|
|
|
|
umask(umsk);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
scall = find_syscall(argv[0]);
|
|
|
|
if (scall == NULL) {
|
|
|
|
fprintf(stderr, "syscall '%s' not supported\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
argc++;
|
|
|
|
argv++;
|
|
|
|
n = call_syscall(scall, argv);
|
|
|
|
argc += n;
|
|
|
|
argv += n;
|
|
|
|
if (argv[0] == NULL)
|
|
|
|
break;
|
|
|
|
argc++;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
err2str(int error)
|
|
|
|
{
|
|
|
|
static char errnum[8];
|
|
|
|
|
|
|
|
switch (error) {
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPERM
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPERM:
|
|
|
|
return ("EPERM");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOENT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOENT:
|
|
|
|
return ("ENOENT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ESRCH
|
2014-09-09 02:50:09 +00:00
|
|
|
case ESRCH:
|
|
|
|
return ("ESRCH");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EINTR
|
2014-09-09 02:50:09 +00:00
|
|
|
case EINTR:
|
|
|
|
return ("EINTR");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EIO
|
2014-09-09 02:50:09 +00:00
|
|
|
case EIO:
|
|
|
|
return ("EIO");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENXIO
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENXIO:
|
|
|
|
return ("ENXIO");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef E2BIG
|
2014-09-09 02:50:09 +00:00
|
|
|
case E2BIG:
|
|
|
|
return ("E2BIG");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOEXEC
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOEXEC:
|
|
|
|
return ("ENOEXEC");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EBADF
|
2014-09-09 02:50:09 +00:00
|
|
|
case EBADF:
|
|
|
|
return ("EBADF");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ECHILD
|
2014-09-09 02:50:09 +00:00
|
|
|
case ECHILD:
|
|
|
|
return ("ECHILD");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EDEADLK
|
2014-09-09 02:50:09 +00:00
|
|
|
case EDEADLK:
|
|
|
|
return ("EDEADLK");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOMEM
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOMEM:
|
|
|
|
return ("ENOMEM");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EACCES
|
2014-09-09 02:50:09 +00:00
|
|
|
case EACCES:
|
|
|
|
return ("EACCES");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EFAULT
|
2014-09-09 02:50:09 +00:00
|
|
|
case EFAULT:
|
|
|
|
return ("EFAULT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOTBLK
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOTBLK:
|
|
|
|
return ("ENOTBLK");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EBUSY
|
2014-09-09 02:50:09 +00:00
|
|
|
case EBUSY:
|
|
|
|
return ("EBUSY");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EEXIST
|
2014-09-09 02:50:09 +00:00
|
|
|
case EEXIST:
|
|
|
|
return ("EEXIST");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EXDEV
|
2014-09-09 02:50:09 +00:00
|
|
|
case EXDEV:
|
|
|
|
return ("EXDEV");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENODEV
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENODEV:
|
|
|
|
return ("ENODEV");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOTDIR
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOTDIR:
|
|
|
|
return ("ENOTDIR");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EISDIR
|
2014-09-09 02:50:09 +00:00
|
|
|
case EISDIR:
|
|
|
|
return ("EISDIR");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EINVAL
|
2014-09-09 02:50:09 +00:00
|
|
|
case EINVAL:
|
|
|
|
return ("EINVAL");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENFILE
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENFILE:
|
|
|
|
return ("ENFILE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EMFILE
|
2014-09-09 02:50:09 +00:00
|
|
|
case EMFILE:
|
|
|
|
return ("EMFILE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOTTY
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOTTY:
|
|
|
|
return ("ENOTTY");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ETXTBSY
|
2014-09-09 02:50:09 +00:00
|
|
|
case ETXTBSY:
|
|
|
|
return ("ETXTBSY");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EFBIG
|
2014-09-09 02:50:09 +00:00
|
|
|
case EFBIG:
|
|
|
|
return ("EFBIG");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOSPC
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOSPC:
|
|
|
|
return ("ENOSPC");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ESPIPE
|
2014-09-09 02:50:09 +00:00
|
|
|
case ESPIPE:
|
|
|
|
return ("ESPIPE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EROFS
|
2014-09-09 02:50:09 +00:00
|
|
|
case EROFS:
|
|
|
|
return ("EROFS");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EMLINK
|
2014-09-09 02:50:09 +00:00
|
|
|
case EMLINK:
|
|
|
|
return ("EMLINK");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPIPE
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPIPE:
|
|
|
|
return ("EPIPE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EDOM
|
2014-09-09 02:50:09 +00:00
|
|
|
case EDOM:
|
|
|
|
return ("EDOM");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ERANGE
|
2014-09-09 02:50:09 +00:00
|
|
|
case ERANGE:
|
|
|
|
return ("ERANGE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EAGAIN
|
2014-09-09 02:50:09 +00:00
|
|
|
case EAGAIN:
|
|
|
|
return ("EAGAIN");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EINPROGRESS
|
2014-09-09 02:50:09 +00:00
|
|
|
case EINPROGRESS:
|
|
|
|
return ("EINPROGRESS");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EALREADY
|
2014-09-09 02:50:09 +00:00
|
|
|
case EALREADY:
|
|
|
|
return ("EALREADY");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOTSOCK
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOTSOCK:
|
|
|
|
return ("ENOTSOCK");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EDESTADDRREQ
|
2014-09-09 02:50:09 +00:00
|
|
|
case EDESTADDRREQ:
|
|
|
|
return ("EDESTADDRREQ");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EMSGSIZE
|
2014-09-09 02:50:09 +00:00
|
|
|
case EMSGSIZE:
|
|
|
|
return ("EMSGSIZE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPROTOTYPE
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPROTOTYPE:
|
|
|
|
return ("EPROTOTYPE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOPROTOOPT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOPROTOOPT:
|
|
|
|
return ("ENOPROTOOPT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPROTONOSUPPORT
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPROTONOSUPPORT:
|
|
|
|
return ("EPROTONOSUPPORT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ESOCKTNOSUPPORT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ESOCKTNOSUPPORT:
|
|
|
|
return ("ESOCKTNOSUPPORT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EOPNOTSUPP
|
2014-09-09 02:50:09 +00:00
|
|
|
case EOPNOTSUPP:
|
|
|
|
return ("EOPNOTSUPP");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPFNOSUPPORT
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPFNOSUPPORT:
|
|
|
|
return ("EPFNOSUPPORT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EAFNOSUPPORT
|
2014-09-09 02:50:09 +00:00
|
|
|
case EAFNOSUPPORT:
|
|
|
|
return ("EAFNOSUPPORT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EADDRINUSE
|
2014-09-09 02:50:09 +00:00
|
|
|
case EADDRINUSE:
|
|
|
|
return ("EADDRINUSE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EADDRNOTAVAIL
|
2014-09-09 02:50:09 +00:00
|
|
|
case EADDRNOTAVAIL:
|
|
|
|
return ("EADDRNOTAVAIL");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENETDOWN
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENETDOWN:
|
|
|
|
return ("ENETDOWN");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENETUNREACH
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENETUNREACH:
|
|
|
|
return ("ENETUNREACH");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENETRESET
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENETRESET:
|
|
|
|
return ("ENETRESET");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ECONNABORTED
|
2014-09-09 02:50:09 +00:00
|
|
|
case ECONNABORTED:
|
|
|
|
return ("ECONNABORTED");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ECONNRESET
|
2014-09-09 02:50:09 +00:00
|
|
|
case ECONNRESET:
|
|
|
|
return ("ECONNRESET");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOBUFS
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOBUFS:
|
|
|
|
return ("ENOBUFS");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EISCONN
|
2014-09-09 02:50:09 +00:00
|
|
|
case EISCONN:
|
|
|
|
return ("EISCONN");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOTCONN
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOTCONN:
|
|
|
|
return ("ENOTCONN");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ESHUTDOWN
|
2014-09-09 02:50:09 +00:00
|
|
|
case ESHUTDOWN:
|
|
|
|
return ("ESHUTDOWN");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ETOOMANYREFS
|
2014-09-09 02:50:09 +00:00
|
|
|
case ETOOMANYREFS:
|
|
|
|
return ("ETOOMANYREFS");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ETIMEDOUT
|
2014-09-09 02:50:09 +00:00
|
|
|
case ETIMEDOUT:
|
|
|
|
return ("ETIMEDOUT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ECONNREFUSED
|
2014-09-09 02:50:09 +00:00
|
|
|
case ECONNREFUSED:
|
|
|
|
return ("ECONNREFUSED");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ELOOP
|
2014-09-09 02:50:09 +00:00
|
|
|
case ELOOP:
|
|
|
|
return ("ELOOP");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENAMETOOLONG
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENAMETOOLONG:
|
|
|
|
return ("ENAMETOOLONG");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EHOSTDOWN
|
2014-09-09 02:50:09 +00:00
|
|
|
case EHOSTDOWN:
|
|
|
|
return ("EHOSTDOWN");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EHOSTUNREACH
|
2014-09-09 02:50:09 +00:00
|
|
|
case EHOSTUNREACH:
|
|
|
|
return ("EHOSTUNREACH");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOTEMPTY
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOTEMPTY:
|
|
|
|
return ("ENOTEMPTY");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPROCLIM
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPROCLIM:
|
|
|
|
return ("EPROCLIM");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EUSERS
|
2014-09-09 02:50:09 +00:00
|
|
|
case EUSERS:
|
|
|
|
return ("EUSERS");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EDQUOT
|
2014-09-09 02:50:09 +00:00
|
|
|
case EDQUOT:
|
|
|
|
return ("EDQUOT");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ESTALE
|
2014-09-09 02:50:09 +00:00
|
|
|
case ESTALE:
|
|
|
|
return ("ESTALE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EREMOTE
|
2014-09-09 02:50:09 +00:00
|
|
|
case EREMOTE:
|
|
|
|
return ("EREMOTE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EBADRPC
|
2014-09-09 02:50:09 +00:00
|
|
|
case EBADRPC:
|
|
|
|
return ("EBADRPC");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ERPCMISMATCH
|
2014-09-09 02:50:09 +00:00
|
|
|
case ERPCMISMATCH:
|
|
|
|
return ("ERPCMISMATCH");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPROGUNAVAIL
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPROGUNAVAIL:
|
|
|
|
return ("EPROGUNAVAIL");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPROGMISMATCH
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPROGMISMATCH:
|
|
|
|
return ("EPROGMISMATCH");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPROCUNAVAIL
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPROCUNAVAIL:
|
|
|
|
return ("EPROCUNAVAIL");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOLCK
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOLCK:
|
|
|
|
return ("ENOLCK");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOSYS
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOSYS:
|
|
|
|
return ("ENOSYS");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EFTYPE
|
2014-09-09 02:50:09 +00:00
|
|
|
case EFTYPE:
|
|
|
|
return ("EFTYPE");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EAUTH
|
2014-09-09 02:50:09 +00:00
|
|
|
case EAUTH:
|
|
|
|
return ("EAUTH");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENEEDAUTH
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENEEDAUTH:
|
|
|
|
return ("ENEEDAUTH");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EIDRM
|
2014-09-09 02:50:09 +00:00
|
|
|
case EIDRM:
|
|
|
|
return ("EIDRM");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOMSG
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOMSG:
|
|
|
|
return ("ENOMSG");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EOVERFLOW
|
2014-09-09 02:50:09 +00:00
|
|
|
case EOVERFLOW:
|
|
|
|
return ("EOVERFLOW");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ECANCELED
|
2014-09-09 02:50:09 +00:00
|
|
|
case ECANCELED:
|
|
|
|
return ("ECANCELED");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EILSEQ
|
2014-09-09 02:50:09 +00:00
|
|
|
case EILSEQ:
|
|
|
|
return ("EILSEQ");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOATTR
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOATTR:
|
|
|
|
return ("ENOATTR");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EDOOFUS
|
2014-09-09 02:50:09 +00:00
|
|
|
case EDOOFUS:
|
|
|
|
return ("EDOOFUS");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EBADMSG
|
2014-09-09 02:50:09 +00:00
|
|
|
case EBADMSG:
|
|
|
|
return ("EBADMSG");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EMULTIHOP
|
2014-09-09 02:50:09 +00:00
|
|
|
case EMULTIHOP:
|
|
|
|
return ("EMULTIHOP");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef ENOLINK
|
2014-09-09 02:50:09 +00:00
|
|
|
case ENOLINK:
|
|
|
|
return ("ENOLINK");
|
|
|
|
#endif
|
2017-06-28 08:48:09 +00:00
|
|
|
#ifdef EPROTO
|
2014-09-09 02:50:09 +00:00
|
|
|
case EPROTO:
|
|
|
|
return ("EPROTO");
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
snprintf(errnum, sizeof(errnum), "%d", error);
|
|
|
|
return (errnum);
|
|
|
|
}
|
|
|
|
}
|