2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* ioctl.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996 by Volker Lendecke
|
|
|
|
* Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
|
|
|
|
* Modified 1998, 1999 Wolfram Pienkoss for NLS
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-01-11 23:17:46 +03:00
|
|
|
#include <linux/capability.h>
|
2006-10-01 10:27:55 +04:00
|
|
|
#include <linux/compat.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/ioctl.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/mm.h>
|
2008-02-16 01:37:39 +03:00
|
|
|
#include <linux/mount.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/highuid.h>
|
|
|
|
#include <linux/vmalloc.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-21 01:22:52 +04:00
|
|
|
#include <linux/sched.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
2011-01-13 01:37:47 +03:00
|
|
|
#include "ncp_fs.h"
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* maximum limit for ncp_objectname_ioctl */
|
|
|
|
#define NCP_OBJECT_NAME_MAX_LEN 4096
|
|
|
|
/* maximum limit for ncp_privatedata_ioctl */
|
|
|
|
#define NCP_PRIVATE_DATA_MAX_LEN 8192
|
|
|
|
/* maximum negotiable packet size */
|
|
|
|
#define NCP_PACKET_SIZE_INTERNAL 65536
|
|
|
|
|
|
|
|
static int
|
2010-09-27 03:47:33 +04:00
|
|
|
ncp_get_fs_info(struct ncp_server * server, struct inode *inode,
|
2005-11-09 08:35:04 +03:00
|
|
|
struct ncp_fs_info __user *arg)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct ncp_fs_info info;
|
|
|
|
|
|
|
|
if (copy_from_user(&info, arg, sizeof(info)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (info.version != NCP_GET_FS_INFO_VERSION) {
|
2014-04-09 03:04:15 +04:00
|
|
|
ncp_dbg(1, "info.version invalid: %d\n", info.version);
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/* TODO: info.addr = server->m.serv_addr; */
|
2012-02-08 04:28:28 +04:00
|
|
|
SET_UID(info.mounted_uid, from_kuid_munged(current_user_ns(), server->m.mounted_uid));
|
2005-04-17 02:20:36 +04:00
|
|
|
info.connection = server->connection;
|
|
|
|
info.buffer_size = server->buffer_size;
|
|
|
|
info.volume_number = NCP_FINFO(inode)->volNumber;
|
|
|
|
info.directory_id = NCP_FINFO(inode)->DosDirNum;
|
|
|
|
|
|
|
|
if (copy_to_user(arg, &info, sizeof(info)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-09-27 03:47:33 +04:00
|
|
|
ncp_get_fs_info_v2(struct ncp_server * server, struct inode *inode,
|
2005-11-09 08:35:04 +03:00
|
|
|
struct ncp_fs_info_v2 __user * arg)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct ncp_fs_info_v2 info2;
|
|
|
|
|
|
|
|
if (copy_from_user(&info2, arg, sizeof(info2)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (info2.version != NCP_GET_FS_INFO_VERSION_V2) {
|
2014-04-09 03:04:15 +04:00
|
|
|
ncp_dbg(1, "info.version invalid: %d\n", info2.version);
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-02-08 04:28:28 +04:00
|
|
|
info2.mounted_uid = from_kuid_munged(current_user_ns(), server->m.mounted_uid);
|
2005-04-17 02:20:36 +04:00
|
|
|
info2.connection = server->connection;
|
|
|
|
info2.buffer_size = server->buffer_size;
|
|
|
|
info2.volume_number = NCP_FINFO(inode)->volNumber;
|
|
|
|
info2.directory_id = NCP_FINFO(inode)->DosDirNum;
|
|
|
|
info2.dummy1 = info2.dummy2 = info2.dummy3 = 0;
|
|
|
|
|
|
|
|
if (copy_to_user(arg, &info2, sizeof(info2)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
struct compat_ncp_objectname_ioctl
|
|
|
|
{
|
|
|
|
s32 auth_type;
|
|
|
|
u32 object_name_len;
|
2008-12-30 00:14:56 +03:00
|
|
|
compat_caddr_t object_name; /* a userspace data, in most cases user name */
|
2006-10-01 10:27:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_ncp_fs_info_v2 {
|
|
|
|
s32 version;
|
|
|
|
u32 mounted_uid;
|
|
|
|
u32 connection;
|
|
|
|
u32 buffer_size;
|
|
|
|
|
|
|
|
u32 volume_number;
|
|
|
|
u32 directory_id;
|
|
|
|
|
|
|
|
u32 dummy1;
|
|
|
|
u32 dummy2;
|
|
|
|
u32 dummy3;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_ncp_ioctl_request {
|
|
|
|
u32 function;
|
|
|
|
u32 size;
|
|
|
|
compat_caddr_t data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_ncp_privatedata_ioctl
|
|
|
|
{
|
|
|
|
u32 len;
|
|
|
|
compat_caddr_t data; /* ~1000 for NDS */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct compat_ncp_fs_info_v2)
|
|
|
|
#define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct compat_ncp_ioctl_request)
|
|
|
|
#define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct compat_ncp_objectname_ioctl)
|
|
|
|
#define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct compat_ncp_objectname_ioctl)
|
|
|
|
#define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct compat_ncp_privatedata_ioctl)
|
|
|
|
#define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct compat_ncp_privatedata_ioctl)
|
|
|
|
|
|
|
|
static int
|
2010-09-27 03:47:33 +04:00
|
|
|
ncp_get_compat_fs_info_v2(struct ncp_server * server, struct inode *inode,
|
2006-10-01 10:27:55 +04:00
|
|
|
struct compat_ncp_fs_info_v2 __user * arg)
|
|
|
|
{
|
|
|
|
struct compat_ncp_fs_info_v2 info2;
|
|
|
|
|
|
|
|
if (copy_from_user(&info2, arg, sizeof(info2)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (info2.version != NCP_GET_FS_INFO_VERSION_V2) {
|
2014-04-09 03:04:15 +04:00
|
|
|
ncp_dbg(1, "info.version invalid: %d\n", info2.version);
|
2006-10-01 10:27:55 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-02-08 04:28:28 +04:00
|
|
|
info2.mounted_uid = from_kuid_munged(current_user_ns(), server->m.mounted_uid);
|
2006-10-01 10:27:55 +04:00
|
|
|
info2.connection = server->connection;
|
|
|
|
info2.buffer_size = server->buffer_size;
|
|
|
|
info2.volume_number = NCP_FINFO(inode)->volNumber;
|
|
|
|
info2.directory_id = NCP_FINFO(inode)->DosDirNum;
|
|
|
|
info2.dummy1 = info2.dummy2 = info2.dummy3 = 0;
|
|
|
|
|
|
|
|
if (copy_to_user(arg, &info2, sizeof(info2)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NCP_IOC_GETMOUNTUID16 _IOW('n', 2, u16)
|
|
|
|
#define NCP_IOC_GETMOUNTUID32 _IOW('n', 2, u32)
|
|
|
|
#define NCP_IOC_GETMOUNTUID64 _IOW('n', 2, u64)
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef CONFIG_NCPFS_NLS
|
|
|
|
/* Here we are select the iocharset and the codepage for NLS.
|
|
|
|
* Thanks Petr Vandrovec for idea and many hints.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
|
|
|
|
{
|
|
|
|
struct ncp_nls_ioctl user;
|
|
|
|
struct nls_table *codepage;
|
|
|
|
struct nls_table *iocharset;
|
|
|
|
struct nls_table *oldset_io;
|
|
|
|
struct nls_table *oldset_cp;
|
2010-09-27 03:47:33 +04:00
|
|
|
int utf8;
|
|
|
|
int err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (copy_from_user(&user, arg, sizeof(user)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
codepage = NULL;
|
|
|
|
user.codepage[NCP_IOCSNAME_LEN] = 0;
|
|
|
|
if (!user.codepage[0] || !strcmp(user.codepage, "default"))
|
|
|
|
codepage = load_nls_default();
|
|
|
|
else {
|
|
|
|
codepage = load_nls(user.codepage);
|
|
|
|
if (!codepage) {
|
|
|
|
return -EBADRQC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iocharset = NULL;
|
|
|
|
user.iocharset[NCP_IOCSNAME_LEN] = 0;
|
|
|
|
if (!user.iocharset[0] || !strcmp(user.iocharset, "default")) {
|
|
|
|
iocharset = load_nls_default();
|
2010-09-27 03:47:33 +04:00
|
|
|
utf8 = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else if (!strcmp(user.iocharset, "utf8")) {
|
|
|
|
iocharset = load_nls_default();
|
2010-09-27 03:47:33 +04:00
|
|
|
utf8 = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
iocharset = load_nls(user.iocharset);
|
|
|
|
if (!iocharset) {
|
|
|
|
unload_nls(codepage);
|
|
|
|
return -EBADRQC;
|
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
utf8 = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
mutex_lock(&server->root_setup_lock);
|
|
|
|
if (server->root_setuped) {
|
|
|
|
oldset_cp = codepage;
|
|
|
|
oldset_io = iocharset;
|
|
|
|
err = -EBUSY;
|
|
|
|
} else {
|
|
|
|
if (utf8)
|
|
|
|
NCP_SET_FLAG(server, NCP_FLAG_UTF8);
|
|
|
|
else
|
|
|
|
NCP_CLR_FLAG(server, NCP_FLAG_UTF8);
|
|
|
|
oldset_cp = server->nls_vol;
|
|
|
|
server->nls_vol = codepage;
|
|
|
|
oldset_io = server->nls_io;
|
|
|
|
server->nls_io = iocharset;
|
|
|
|
err = 0;
|
|
|
|
}
|
|
|
|
mutex_unlock(&server->root_setup_lock);
|
2009-08-17 01:05:08 +04:00
|
|
|
unload_nls(oldset_cp);
|
|
|
|
unload_nls(oldset_io);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
|
|
|
|
{
|
|
|
|
struct ncp_nls_ioctl user;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
memset(&user, 0, sizeof(user));
|
2010-09-27 03:47:33 +04:00
|
|
|
mutex_lock(&server->root_setup_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (server->nls_vol && server->nls_vol->charset) {
|
|
|
|
len = strlen(server->nls_vol->charset);
|
|
|
|
if (len > NCP_IOCSNAME_LEN)
|
|
|
|
len = NCP_IOCSNAME_LEN;
|
|
|
|
strncpy(user.codepage, server->nls_vol->charset, len);
|
|
|
|
user.codepage[len] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NCP_IS_FLAG(server, NCP_FLAG_UTF8))
|
|
|
|
strcpy(user.iocharset, "utf8");
|
|
|
|
else if (server->nls_io && server->nls_io->charset) {
|
|
|
|
len = strlen(server->nls_io->charset);
|
|
|
|
if (len > NCP_IOCSNAME_LEN)
|
|
|
|
len = NCP_IOCSNAME_LEN;
|
|
|
|
strncpy(user.iocharset, server->nls_io->charset, len);
|
|
|
|
user.iocharset[len] = 0;
|
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
mutex_unlock(&server->root_setup_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (copy_to_user(arg, &user, sizeof(user)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NCPFS_NLS */
|
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
static long __ncp_ioctl(struct inode *inode, unsigned int cmd, unsigned long arg)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct ncp_server *server = NCP_SERVER(inode);
|
|
|
|
int result;
|
|
|
|
struct ncp_ioctl_request request;
|
|
|
|
char* bouncebuffer;
|
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
|
|
|
|
switch (cmd) {
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
case NCP_IOC_NCPREQUEST_32:
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_NCPREQUEST:
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
if (cmd == NCP_IOC_NCPREQUEST_32) {
|
|
|
|
struct compat_ncp_ioctl_request request32;
|
|
|
|
if (copy_from_user(&request32, argp, sizeof(request32)))
|
|
|
|
return -EFAULT;
|
|
|
|
request.function = request32.function;
|
|
|
|
request.size = request32.size;
|
|
|
|
request.data = compat_ptr(request32.data);
|
|
|
|
} else
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy_from_user(&request, argp, sizeof(request)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if ((request.function > 255)
|
|
|
|
|| (request.size >
|
|
|
|
NCP_PACKET_SIZE - sizeof(struct ncp_request_header))) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
bouncebuffer = vmalloc(NCP_PACKET_SIZE_INTERNAL);
|
|
|
|
if (!bouncebuffer)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (copy_from_user(bouncebuffer, request.data, request.size)) {
|
|
|
|
vfree(bouncebuffer);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
ncp_lock_server(server);
|
|
|
|
|
|
|
|
/* FIXME: We hack around in the server's structures
|
|
|
|
here to be able to use ncp_request */
|
|
|
|
|
|
|
|
server->has_subfunction = 0;
|
|
|
|
server->current_size = request.size;
|
|
|
|
memcpy(server->packet, bouncebuffer, request.size);
|
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
result = ncp_request2(server, request.function,
|
2005-04-17 02:20:36 +04:00
|
|
|
bouncebuffer, NCP_PACKET_SIZE_INTERNAL);
|
|
|
|
if (result < 0)
|
|
|
|
result = -EIO;
|
|
|
|
else
|
|
|
|
result = server->reply_size;
|
|
|
|
ncp_unlock_server(server);
|
2014-04-09 03:04:15 +04:00
|
|
|
ncp_dbg(1, "copy %d bytes\n", result);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (result >= 0)
|
|
|
|
if (copy_to_user(request.data, bouncebuffer, result))
|
|
|
|
result = -EFAULT;
|
|
|
|
vfree(bouncebuffer);
|
|
|
|
return result;
|
|
|
|
|
|
|
|
case NCP_IOC_CONN_LOGGED_IN:
|
|
|
|
|
|
|
|
if (!(server->m.int_flags & NCP_IMOUNT_LOGGEDIN_POSSIBLE))
|
|
|
|
return -EINVAL;
|
2010-09-27 03:47:33 +04:00
|
|
|
mutex_lock(&server->root_setup_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (server->root_setuped)
|
2010-09-27 03:47:33 +04:00
|
|
|
result = -EBUSY;
|
|
|
|
else {
|
|
|
|
result = ncp_conn_logged_in(inode->i_sb);
|
|
|
|
if (result == 0)
|
|
|
|
server->root_setuped = 1;
|
|
|
|
}
|
|
|
|
mutex_unlock(&server->root_setup_lock);
|
|
|
|
return result;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
case NCP_IOC_GET_FS_INFO:
|
2010-09-27 03:47:33 +04:00
|
|
|
return ncp_get_fs_info(server, inode, argp);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
case NCP_IOC_GET_FS_INFO_V2:
|
2010-09-27 03:47:33 +04:00
|
|
|
return ncp_get_fs_info_v2(server, inode, argp);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
case NCP_IOC_GET_FS_INFO_V2_32:
|
2010-09-27 03:47:33 +04:00
|
|
|
return ncp_get_compat_fs_info_v2(server, inode, argp);
|
2006-10-01 10:27:55 +04:00
|
|
|
#endif
|
|
|
|
/* we have too many combinations of CONFIG_COMPAT,
|
|
|
|
* CONFIG_64BIT and CONFIG_UID16, so just handle
|
|
|
|
* any of the possible ioctls */
|
|
|
|
case NCP_IOC_GETMOUNTUID16:
|
2010-09-27 03:47:33 +04:00
|
|
|
{
|
2006-10-01 10:27:55 +04:00
|
|
|
u16 uid;
|
2010-09-27 03:47:33 +04:00
|
|
|
|
2012-02-08 04:28:28 +04:00
|
|
|
SET_UID(uid, from_kuid_munged(current_user_ns(), server->m.mounted_uid));
|
2006-10-01 10:27:55 +04:00
|
|
|
if (put_user(uid, (u16 __user *)argp))
|
|
|
|
return -EFAULT;
|
2010-09-27 03:47:33 +04:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
case NCP_IOC_GETMOUNTUID32:
|
2012-02-08 04:28:28 +04:00
|
|
|
{
|
|
|
|
uid_t uid = from_kuid_munged(current_user_ns(), server->m.mounted_uid);
|
|
|
|
if (put_user(uid, (u32 __user *)argp))
|
2010-09-27 03:47:33 +04:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
2012-02-08 04:28:28 +04:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
case NCP_IOC_GETMOUNTUID64:
|
2012-02-08 04:28:28 +04:00
|
|
|
{
|
|
|
|
uid_t uid = from_kuid_munged(current_user_ns(), server->m.mounted_uid);
|
|
|
|
if (put_user(uid, (u64 __user *)argp))
|
2010-09-27 03:47:33 +04:00
|
|
|
return -EFAULT;
|
2006-10-01 10:27:55 +04:00
|
|
|
return 0;
|
2012-02-08 04:28:28 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_GETROOT:
|
|
|
|
{
|
|
|
|
struct ncp_setroot_ioctl sr;
|
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
result = -EACCES;
|
|
|
|
mutex_lock(&server->root_setup_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (server->m.mounted_vol[0]) {
|
|
|
|
struct dentry* dentry = inode->i_sb->s_root;
|
|
|
|
|
|
|
|
if (dentry) {
|
2015-03-18 01:25:59 +03:00
|
|
|
struct inode* s_inode = d_inode(dentry);
|
2010-09-27 03:47:33 +04:00
|
|
|
|
2008-04-28 13:14:00 +04:00
|
|
|
if (s_inode) {
|
|
|
|
sr.volNumber = NCP_FINFO(s_inode)->volNumber;
|
|
|
|
sr.dirEntNum = NCP_FINFO(s_inode)->dirEntNum;
|
2005-04-17 02:20:36 +04:00
|
|
|
sr.namespace = server->name_space[sr.volNumber];
|
2010-09-27 03:47:33 +04:00
|
|
|
result = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else
|
2015-03-18 01:25:59 +03:00
|
|
|
ncp_dbg(1, "d_inode(s_root)==NULL\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
} else
|
2014-04-09 03:04:15 +04:00
|
|
|
ncp_dbg(1, "s_root==NULL\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
sr.volNumber = -1;
|
|
|
|
sr.namespace = 0;
|
|
|
|
sr.dirEntNum = 0;
|
2010-09-27 03:47:33 +04:00
|
|
|
result = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
mutex_unlock(&server->root_setup_lock);
|
|
|
|
if (!result && copy_to_user(argp, &sr, sizeof(sr)))
|
|
|
|
result = -EFAULT;
|
|
|
|
return result;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2008-11-14 02:38:58 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_SETROOT:
|
|
|
|
{
|
|
|
|
struct ncp_setroot_ioctl sr;
|
|
|
|
__u32 vnum;
|
|
|
|
__le32 de;
|
|
|
|
__le32 dosde;
|
|
|
|
struct dentry* dentry;
|
|
|
|
|
|
|
|
if (copy_from_user(&sr, argp, sizeof(sr)))
|
|
|
|
return -EFAULT;
|
2010-09-27 03:47:33 +04:00
|
|
|
mutex_lock(&server->root_setup_lock);
|
|
|
|
if (server->root_setuped)
|
|
|
|
result = -EBUSY;
|
|
|
|
else {
|
|
|
|
if (sr.volNumber < 0) {
|
|
|
|
server->m.mounted_vol[0] = 0;
|
|
|
|
vnum = NCP_NUMBER_OF_VOLUMES;
|
|
|
|
de = 0;
|
|
|
|
dosde = 0;
|
|
|
|
result = 0;
|
|
|
|
} else if (sr.volNumber >= NCP_NUMBER_OF_VOLUMES) {
|
|
|
|
result = -EINVAL;
|
|
|
|
} else if (ncp_mount_subdir(server, sr.volNumber,
|
|
|
|
sr.namespace, sr.dirEntNum,
|
|
|
|
&vnum, &de, &dosde)) {
|
|
|
|
result = -ENOENT;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else
|
2010-09-27 03:47:33 +04:00
|
|
|
result = 0;
|
|
|
|
|
|
|
|
if (result == 0) {
|
|
|
|
dentry = inode->i_sb->s_root;
|
|
|
|
if (dentry) {
|
2015-03-18 01:25:59 +03:00
|
|
|
struct inode* s_inode = d_inode(dentry);
|
2010-09-27 03:47:33 +04:00
|
|
|
|
|
|
|
if (s_inode) {
|
|
|
|
NCP_FINFO(s_inode)->volNumber = vnum;
|
|
|
|
NCP_FINFO(s_inode)->dirEntNum = de;
|
|
|
|
NCP_FINFO(s_inode)->DosDirNum = dosde;
|
|
|
|
server->root_setuped = 1;
|
|
|
|
} else {
|
2015-03-18 01:25:59 +03:00
|
|
|
ncp_dbg(1, "d_inode(s_root)==NULL\n");
|
2010-09-27 03:47:33 +04:00
|
|
|
result = -EIO;
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-09 03:04:15 +04:00
|
|
|
ncp_dbg(1, "s_root==NULL\n");
|
2010-09-27 03:47:33 +04:00
|
|
|
result = -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&server->root_setup_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
return result;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
#ifdef CONFIG_NCPFS_PACKET_SIGNING
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_SIGN_INIT:
|
2010-09-27 03:47:33 +04:00
|
|
|
{
|
|
|
|
struct ncp_sign_init sign;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
if (argp)
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy_from_user(&sign, argp, sizeof(sign)))
|
|
|
|
return -EFAULT;
|
2010-09-27 03:47:33 +04:00
|
|
|
ncp_lock_server(server);
|
|
|
|
mutex_lock(&server->rcv.creq_mutex);
|
|
|
|
if (argp) {
|
|
|
|
if (server->sign_wanted) {
|
|
|
|
memcpy(server->sign_root,sign.sign_root,8);
|
|
|
|
memcpy(server->sign_last,sign.sign_last,16);
|
|
|
|
server->sign_active = 1;
|
|
|
|
}
|
|
|
|
/* ignore when signatures not wanted */
|
|
|
|
} else {
|
|
|
|
server->sign_active = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
mutex_unlock(&server->rcv.creq_mutex);
|
|
|
|
ncp_unlock_server(server);
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_SIGN_WANTED:
|
2010-09-27 03:47:33 +04:00
|
|
|
{
|
|
|
|
int state;
|
|
|
|
|
|
|
|
ncp_lock_server(server);
|
|
|
|
state = server->sign_wanted;
|
|
|
|
ncp_unlock_server(server);
|
|
|
|
if (put_user(state, (int __user *)argp))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-14 02:38:58 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_SET_SIGN_WANTED:
|
|
|
|
{
|
|
|
|
int newstate;
|
|
|
|
|
|
|
|
/* get only low 8 bits... */
|
|
|
|
if (get_user(newstate, (unsigned char __user *)argp))
|
|
|
|
return -EFAULT;
|
2010-09-27 03:47:33 +04:00
|
|
|
result = 0;
|
|
|
|
ncp_lock_server(server);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (server->sign_active) {
|
|
|
|
/* cannot turn signatures OFF when active */
|
2010-09-27 03:47:33 +04:00
|
|
|
if (!newstate)
|
|
|
|
result = -EINVAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
server->sign_wanted = newstate != 0;
|
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
ncp_unlock_server(server);
|
|
|
|
return result;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NCPFS_PACKET_SIGNING */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NCPFS_IOCTL_LOCKING
|
|
|
|
case NCP_IOC_LOCKUNLOCK:
|
|
|
|
{
|
|
|
|
struct ncp_lock_ioctl rqdata;
|
|
|
|
|
|
|
|
if (copy_from_user(&rqdata, argp, sizeof(rqdata)))
|
|
|
|
return -EFAULT;
|
|
|
|
if (rqdata.origin != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
/* check for cmd */
|
|
|
|
switch (rqdata.cmd) {
|
|
|
|
case NCP_LOCK_EX:
|
|
|
|
case NCP_LOCK_SH:
|
2015-11-21 02:56:56 +03:00
|
|
|
if (rqdata.timeout < 0)
|
|
|
|
return -EINVAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (rqdata.timeout == 0)
|
|
|
|
rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT;
|
|
|
|
else if (rqdata.timeout > NCP_LOCK_MAX_TIMEOUT)
|
|
|
|
rqdata.timeout = NCP_LOCK_MAX_TIMEOUT;
|
|
|
|
break;
|
|
|
|
case NCP_LOCK_LOG:
|
|
|
|
rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; /* has no effect */
|
|
|
|
case NCP_LOCK_CLEAR:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/* locking needs both read and write access */
|
|
|
|
if ((result = ncp_make_open(inode, O_RDWR)) != 0)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = -EISDIR;
|
|
|
|
if (!S_ISREG(inode->i_mode))
|
|
|
|
goto outrel;
|
|
|
|
if (rqdata.cmd == NCP_LOCK_CLEAR)
|
|
|
|
{
|
|
|
|
result = ncp_ClearPhysicalRecord(NCP_SERVER(inode),
|
2010-09-27 03:47:33 +04:00
|
|
|
NCP_FINFO(inode)->file_handle,
|
2005-04-17 02:20:36 +04:00
|
|
|
rqdata.offset,
|
|
|
|
rqdata.length);
|
|
|
|
if (result > 0) result = 0; /* no such lock */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int lockcmd;
|
|
|
|
|
|
|
|
switch (rqdata.cmd)
|
|
|
|
{
|
|
|
|
case NCP_LOCK_EX: lockcmd=1; break;
|
|
|
|
case NCP_LOCK_SH: lockcmd=3; break;
|
|
|
|
default: lockcmd=0; break;
|
|
|
|
}
|
|
|
|
result = ncp_LogPhysicalRecord(NCP_SERVER(inode),
|
|
|
|
NCP_FINFO(inode)->file_handle,
|
|
|
|
lockcmd,
|
|
|
|
rqdata.offset,
|
|
|
|
rqdata.length,
|
|
|
|
rqdata.timeout);
|
|
|
|
if (result > 0) result = -EAGAIN;
|
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
outrel:
|
2005-04-17 02:20:36 +04:00
|
|
|
ncp_inode_close(inode);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NCPFS_IOCTL_LOCKING */
|
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
case NCP_IOC_GETOBJECTNAME_32:
|
|
|
|
{
|
|
|
|
struct compat_ncp_objectname_ioctl user;
|
|
|
|
size_t outl;
|
|
|
|
|
|
|
|
if (copy_from_user(&user, argp, sizeof(user)))
|
|
|
|
return -EFAULT;
|
2010-09-27 03:47:33 +04:00
|
|
|
down_read(&server->auth_rwsem);
|
2006-10-01 10:27:55 +04:00
|
|
|
user.auth_type = server->auth.auth_type;
|
|
|
|
outl = user.object_name_len;
|
|
|
|
user.object_name_len = server->auth.object_name_len;
|
|
|
|
if (outl > user.object_name_len)
|
|
|
|
outl = user.object_name_len;
|
2010-09-27 03:47:33 +04:00
|
|
|
result = 0;
|
2006-10-01 10:27:55 +04:00
|
|
|
if (outl) {
|
|
|
|
if (copy_to_user(compat_ptr(user.object_name),
|
|
|
|
server->auth.object_name,
|
2010-09-27 03:47:33 +04:00
|
|
|
outl))
|
|
|
|
result = -EFAULT;
|
2006-10-01 10:27:55 +04:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
up_read(&server->auth_rwsem);
|
|
|
|
if (!result && copy_to_user(argp, &user, sizeof(user)))
|
|
|
|
result = -EFAULT;
|
|
|
|
return result;
|
2006-10-01 10:27:55 +04:00
|
|
|
}
|
|
|
|
#endif
|
2008-11-14 02:38:58 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_GETOBJECTNAME:
|
|
|
|
{
|
|
|
|
struct ncp_objectname_ioctl user;
|
|
|
|
size_t outl;
|
|
|
|
|
|
|
|
if (copy_from_user(&user, argp, sizeof(user)))
|
|
|
|
return -EFAULT;
|
2010-09-27 03:47:33 +04:00
|
|
|
down_read(&server->auth_rwsem);
|
2005-04-17 02:20:36 +04:00
|
|
|
user.auth_type = server->auth.auth_type;
|
|
|
|
outl = user.object_name_len;
|
|
|
|
user.object_name_len = server->auth.object_name_len;
|
|
|
|
if (outl > user.object_name_len)
|
|
|
|
outl = user.object_name_len;
|
2010-09-27 03:47:33 +04:00
|
|
|
result = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (outl) {
|
|
|
|
if (copy_to_user(user.object_name,
|
|
|
|
server->auth.object_name,
|
2010-09-27 03:47:33 +04:00
|
|
|
outl))
|
|
|
|
result = -EFAULT;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
up_read(&server->auth_rwsem);
|
|
|
|
if (!result && copy_to_user(argp, &user, sizeof(user)))
|
|
|
|
result = -EFAULT;
|
|
|
|
return result;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2008-11-14 02:38:58 +03:00
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
case NCP_IOC_SETOBJECTNAME_32:
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_SETOBJECTNAME:
|
|
|
|
{
|
|
|
|
struct ncp_objectname_ioctl user;
|
|
|
|
void* newname;
|
|
|
|
void* oldname;
|
|
|
|
size_t oldnamelen;
|
|
|
|
void* oldprivate;
|
|
|
|
size_t oldprivatelen;
|
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
if (cmd == NCP_IOC_SETOBJECTNAME_32) {
|
|
|
|
struct compat_ncp_objectname_ioctl user32;
|
|
|
|
if (copy_from_user(&user32, argp, sizeof(user32)))
|
|
|
|
return -EFAULT;
|
|
|
|
user.auth_type = user32.auth_type;
|
|
|
|
user.object_name_len = user32.object_name_len;
|
|
|
|
user.object_name = compat_ptr(user32.object_name);
|
|
|
|
} else
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy_from_user(&user, argp, sizeof(user)))
|
|
|
|
return -EFAULT;
|
2006-10-01 10:27:55 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (user.object_name_len) {
|
2009-04-08 11:08:53 +04:00
|
|
|
newname = memdup_user(user.object_name,
|
|
|
|
user.object_name_len);
|
|
|
|
if (IS_ERR(newname))
|
|
|
|
return PTR_ERR(newname);
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
newname = NULL;
|
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
down_write(&server->auth_rwsem);
|
2005-04-17 02:20:36 +04:00
|
|
|
oldname = server->auth.object_name;
|
|
|
|
oldnamelen = server->auth.object_name_len;
|
|
|
|
oldprivate = server->priv.data;
|
|
|
|
oldprivatelen = server->priv.len;
|
|
|
|
server->auth.auth_type = user.auth_type;
|
|
|
|
server->auth.object_name_len = user.object_name_len;
|
|
|
|
server->auth.object_name = newname;
|
|
|
|
server->priv.len = 0;
|
|
|
|
server->priv.data = NULL;
|
2010-09-27 03:47:33 +04:00
|
|
|
up_write(&server->auth_rwsem);
|
2006-01-15 00:21:12 +03:00
|
|
|
kfree(oldprivate);
|
|
|
|
kfree(oldname);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2008-11-14 02:38:58 +03:00
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
case NCP_IOC_GETPRIVATEDATA_32:
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_GETPRIVATEDATA:
|
|
|
|
{
|
|
|
|
struct ncp_privatedata_ioctl user;
|
|
|
|
size_t outl;
|
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
if (cmd == NCP_IOC_GETPRIVATEDATA_32) {
|
|
|
|
struct compat_ncp_privatedata_ioctl user32;
|
|
|
|
if (copy_from_user(&user32, argp, sizeof(user32)))
|
|
|
|
return -EFAULT;
|
|
|
|
user.len = user32.len;
|
|
|
|
user.data = compat_ptr(user32.data);
|
|
|
|
} else
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy_from_user(&user, argp, sizeof(user)))
|
|
|
|
return -EFAULT;
|
2006-10-01 10:27:55 +04:00
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
down_read(&server->auth_rwsem);
|
2005-04-17 02:20:36 +04:00
|
|
|
outl = user.len;
|
|
|
|
user.len = server->priv.len;
|
|
|
|
if (outl > user.len) outl = user.len;
|
2010-09-27 03:47:33 +04:00
|
|
|
result = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (outl) {
|
|
|
|
if (copy_to_user(user.data,
|
|
|
|
server->priv.data,
|
2010-09-27 03:47:33 +04:00
|
|
|
outl))
|
|
|
|
result = -EFAULT;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
up_read(&server->auth_rwsem);
|
|
|
|
if (result)
|
|
|
|
return result;
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
if (cmd == NCP_IOC_GETPRIVATEDATA_32) {
|
|
|
|
struct compat_ncp_privatedata_ioctl user32;
|
|
|
|
user32.len = user.len;
|
|
|
|
user32.data = (unsigned long) user.data;
|
2006-10-09 23:24:49 +04:00
|
|
|
if (copy_to_user(argp, &user32, sizeof(user32)))
|
2006-10-01 10:27:55 +04:00
|
|
|
return -EFAULT;
|
|
|
|
} else
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy_to_user(argp, &user, sizeof(user)))
|
|
|
|
return -EFAULT;
|
2006-10-01 10:27:55 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2008-11-14 02:38:58 +03:00
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
case NCP_IOC_SETPRIVATEDATA_32:
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_SETPRIVATEDATA:
|
|
|
|
{
|
|
|
|
struct ncp_privatedata_ioctl user;
|
|
|
|
void* new;
|
|
|
|
void* old;
|
|
|
|
size_t oldlen;
|
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
if (cmd == NCP_IOC_SETPRIVATEDATA_32) {
|
|
|
|
struct compat_ncp_privatedata_ioctl user32;
|
|
|
|
if (copy_from_user(&user32, argp, sizeof(user32)))
|
|
|
|
return -EFAULT;
|
|
|
|
user.len = user32.len;
|
|
|
|
user.data = compat_ptr(user32.data);
|
|
|
|
} else
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy_from_user(&user, argp, sizeof(user)))
|
|
|
|
return -EFAULT;
|
2006-10-01 10:27:55 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (user.len > NCP_PRIVATE_DATA_MAX_LEN)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (user.len) {
|
2009-04-08 11:08:53 +04:00
|
|
|
new = memdup_user(user.data, user.len);
|
|
|
|
if (IS_ERR(new))
|
|
|
|
return PTR_ERR(new);
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
new = NULL;
|
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
down_write(&server->auth_rwsem);
|
2005-04-17 02:20:36 +04:00
|
|
|
old = server->priv.data;
|
|
|
|
oldlen = server->priv.len;
|
|
|
|
server->priv.len = user.len;
|
|
|
|
server->priv.data = new;
|
2010-09-27 03:47:33 +04:00
|
|
|
up_write(&server->auth_rwsem);
|
2006-01-15 00:21:12 +03:00
|
|
|
kfree(old);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NCPFS_NLS
|
|
|
|
case NCP_IOC_SETCHARSETS:
|
|
|
|
return ncp_set_charsets(server, argp);
|
2010-09-27 03:47:33 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_GETCHARSETS:
|
|
|
|
return ncp_get_charsets(server, argp);
|
|
|
|
|
|
|
|
#endif /* CONFIG_NCPFS_NLS */
|
|
|
|
|
|
|
|
case NCP_IOC_SETDENTRYTTL:
|
|
|
|
{
|
|
|
|
u_int32_t user;
|
|
|
|
|
|
|
|
if (copy_from_user(&user, argp, sizeof(user)))
|
|
|
|
return -EFAULT;
|
|
|
|
/* 20 secs at most... */
|
|
|
|
if (user > 20000)
|
|
|
|
return -EINVAL;
|
|
|
|
user = (user * HZ) / 1000;
|
2010-09-27 03:47:33 +04:00
|
|
|
atomic_set(&server->dentry_ttl, user);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
case NCP_IOC_GETDENTRYTTL:
|
|
|
|
{
|
2010-09-27 03:47:33 +04:00
|
|
|
u_int32_t user = (atomic_read(&server->dentry_ttl) * 1000) / HZ;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy_to_user(argp, &user, sizeof(user)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2006-10-01 10:27:55 +04:00
|
|
|
|
2010-09-27 03:47:33 +04:00
|
|
|
long ncp_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
2008-02-16 01:37:39 +03:00
|
|
|
{
|
2013-01-24 02:07:38 +04:00
|
|
|
struct inode *inode = file_inode(filp);
|
2010-09-27 03:47:33 +04:00
|
|
|
struct ncp_server *server = NCP_SERVER(inode);
|
2012-02-08 04:28:28 +04:00
|
|
|
kuid_t uid = current_uid();
|
2010-09-27 03:47:33 +04:00
|
|
|
int need_drop_write = 0;
|
|
|
|
long ret;
|
|
|
|
|
2008-02-16 01:37:39 +03:00
|
|
|
switch (cmd) {
|
|
|
|
case NCP_IOC_SETCHARSETS:
|
|
|
|
case NCP_IOC_CONN_LOGGED_IN:
|
|
|
|
case NCP_IOC_SETROOT:
|
2010-09-27 03:47:33 +04:00
|
|
|
if (!capable(CAP_SYS_ADMIN)) {
|
2013-02-20 06:13:55 +04:00
|
|
|
ret = -EPERM;
|
2010-09-27 03:47:33 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
2008-02-16 01:37:39 +03:00
|
|
|
}
|
2012-02-08 04:28:28 +04:00
|
|
|
if (!uid_eq(server->m.mounted_uid, uid)) {
|
2010-09-27 03:47:33 +04:00
|
|
|
switch (cmd) {
|
2008-02-16 01:37:39 +03:00
|
|
|
/*
|
2010-09-27 03:47:33 +04:00
|
|
|
* Only mount owner can issue these ioctls. Information
|
|
|
|
* necessary to authenticate to other NDS servers are
|
|
|
|
* stored here.
|
2008-02-16 01:37:39 +03:00
|
|
|
*/
|
2010-09-27 03:47:33 +04:00
|
|
|
case NCP_IOC_GETOBJECTNAME:
|
|
|
|
case NCP_IOC_SETOBJECTNAME:
|
|
|
|
case NCP_IOC_GETPRIVATEDATA:
|
|
|
|
case NCP_IOC_SETPRIVATEDATA:
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
case NCP_IOC_GETOBJECTNAME_32:
|
|
|
|
case NCP_IOC_SETOBJECTNAME_32:
|
|
|
|
case NCP_IOC_GETPRIVATEDATA_32:
|
|
|
|
case NCP_IOC_SETPRIVATEDATA_32:
|
|
|
|
#endif
|
2010-05-05 17:15:37 +04:00
|
|
|
ret = -EACCES;
|
|
|
|
goto out;
|
2010-09-27 03:47:33 +04:00
|
|
|
/*
|
|
|
|
* These require write access on the inode if user id
|
|
|
|
* does not match. Note that they do not write to the
|
|
|
|
* file... But old code did mnt_want_write, so I keep
|
|
|
|
* it as is. Of course not for mountpoint owner, as
|
|
|
|
* that breaks read-only mounts altogether as ncpmount
|
|
|
|
* needs working NCP_IOC_NCPREQUEST and
|
|
|
|
* NCP_IOC_GET_FS_INFO. Some of these codes (setdentryttl,
|
|
|
|
* signinit, setsignwanted) should be probably restricted
|
|
|
|
* to owner only, or even more to CAP_SYS_ADMIN).
|
|
|
|
*/
|
|
|
|
case NCP_IOC_GET_FS_INFO:
|
|
|
|
case NCP_IOC_GET_FS_INFO_V2:
|
|
|
|
case NCP_IOC_NCPREQUEST:
|
|
|
|
case NCP_IOC_SETDENTRYTTL:
|
|
|
|
case NCP_IOC_SIGN_INIT:
|
|
|
|
case NCP_IOC_LOCKUNLOCK:
|
|
|
|
case NCP_IOC_SET_SIGN_WANTED:
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
case NCP_IOC_GET_FS_INFO_V2_32:
|
|
|
|
case NCP_IOC_NCPREQUEST_32:
|
|
|
|
#endif
|
|
|
|
ret = mnt_want_write_file(filp);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
need_drop_write = 1;
|
|
|
|
ret = inode_permission(inode, MAY_WRITE);
|
|
|
|
if (ret)
|
|
|
|
goto outDropWrite;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Read access required.
|
|
|
|
*/
|
|
|
|
case NCP_IOC_GETMOUNTUID16:
|
|
|
|
case NCP_IOC_GETMOUNTUID32:
|
|
|
|
case NCP_IOC_GETMOUNTUID64:
|
|
|
|
case NCP_IOC_GETROOT:
|
|
|
|
case NCP_IOC_SIGN_WANTED:
|
|
|
|
ret = inode_permission(inode, MAY_READ);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Anybody can read these.
|
|
|
|
*/
|
|
|
|
case NCP_IOC_GETCHARSETS:
|
|
|
|
case NCP_IOC_GETDENTRYTTL:
|
|
|
|
default:
|
|
|
|
/* Three codes below are protected by CAP_SYS_ADMIN above. */
|
|
|
|
case NCP_IOC_SETCHARSETS:
|
|
|
|
case NCP_IOC_CONN_LOGGED_IN:
|
|
|
|
case NCP_IOC_SETROOT:
|
|
|
|
break;
|
2010-05-05 17:15:37 +04:00
|
|
|
}
|
2008-02-16 01:37:39 +03:00
|
|
|
}
|
2010-09-27 03:47:33 +04:00
|
|
|
ret = __ncp_ioctl(inode, cmd, arg);
|
|
|
|
outDropWrite:
|
|
|
|
if (need_drop_write)
|
2011-12-09 17:06:57 +04:00
|
|
|
mnt_drop_write_file(filp);
|
2010-05-05 17:15:37 +04:00
|
|
|
out:
|
2008-02-16 01:37:39 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-10-01 10:27:55 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2010-05-05 17:15:37 +04:00
|
|
|
long ret;
|
2006-10-01 10:27:55 +04:00
|
|
|
|
|
|
|
arg = (unsigned long) compat_ptr(arg);
|
2010-05-05 17:15:37 +04:00
|
|
|
ret = ncp_ioctl(file, cmd, arg);
|
2006-10-01 10:27:55 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|