#include <linux/config.h>
#include <asm/uaccess.h>
+#include <linux/capability.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/ioctl.h>
#define NCP_PACKET_SIZE_INTERNAL 65536
static int
-ncp_get_fs_info(struct ncp_server* server, struct inode* inode, struct ncp_fs_info* arg)
+ncp_get_fs_info(struct ncp_server * server, struct file *file,
+ struct ncp_fs_info __user *arg)
{
+ struct inode *inode = file->f_dentry->d_inode;
struct ncp_fs_info info;
- if ((permission(inode, MAY_WRITE, NULL) != 0)
+ if ((file_permission(file, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid)) {
return -EACCES;
}
}
static int
-ncp_get_fs_info_v2(struct ncp_server* server, struct inode* inode, struct ncp_fs_info_v2* arg)
+ncp_get_fs_info_v2(struct ncp_server * server, struct file *file,
+ struct ncp_fs_info_v2 __user * arg)
{
+ struct inode *inode = file->f_dentry->d_inode;
struct ncp_fs_info_v2 info2;
- if ((permission(inode, MAY_WRITE, NULL) != 0)
+ if ((file_permission(file, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid)) {
return -EACCES;
}
* Thanks Petr Vandrovec for idea and many hints.
*/
static int
-ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl* arg)
+ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
{
struct ncp_nls_ioctl user;
struct nls_table *codepage;
}
static int
-ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl* arg)
+ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
{
struct ncp_nls_ioctl user;
int len;
int result;
struct ncp_ioctl_request request;
char* bouncebuffer;
+ void __user *argp = (void __user *)arg;
switch (cmd) {
case NCP_IOC_NCPREQUEST:
- if ((permission(inode, MAY_WRITE, NULL) != 0)
+ if ((file_permission(filp, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid)) {
return -EACCES;
}
- if (copy_from_user(&request, (struct ncp_ioctl_request *) arg,
- sizeof(request)))
+ if (copy_from_user(&request, argp, sizeof(request)))
return -EFAULT;
if ((request.function > 255)
return ncp_conn_logged_in(inode->i_sb);
case NCP_IOC_GET_FS_INFO:
- return ncp_get_fs_info(server, inode, (struct ncp_fs_info *)arg);
+ return ncp_get_fs_info(server, filp, argp);
case NCP_IOC_GET_FS_INFO_V2:
- return ncp_get_fs_info_v2(server, inode, (struct ncp_fs_info_v2 *)arg);
+ return ncp_get_fs_info_v2(server, filp, argp);
case NCP_IOC_GETMOUNTUID2:
{
unsigned long tmp = server->m.mounted_uid;
- if ( (permission(inode, MAY_READ, NULL) != 0)
+ if ((file_permission(filp, MAY_READ) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
}
- if (put_user(tmp, (unsigned long*) arg))
+ if (put_user(tmp, (unsigned long __user *)argp))
return -EFAULT;
return 0;
}
{
struct ncp_setroot_ioctl sr;
- if ( (permission(inode, MAY_READ, NULL) != 0)
+ if ((file_permission(filp, MAY_READ) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
sr.namespace = 0;
sr.dirEntNum = 0;
}
- if (copy_to_user((struct ncp_setroot_ioctl*)arg,
- &sr,
- sizeof(sr))) return -EFAULT;
+ if (copy_to_user(argp, &sr, sizeof(sr)))
+ return -EFAULT;
return 0;
}
case NCP_IOC_SETROOT:
{
struct ncp_setroot_ioctl sr;
- __u32 vnum, de, dosde;
+ __u32 vnum;
+ __le32 de;
+ __le32 dosde;
struct dentry* dentry;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
}
if (server->root_setuped) return -EBUSY;
- if (copy_from_user(&sr,
- (struct ncp_setroot_ioctl*)arg,
- sizeof(sr))) return -EFAULT;
+ if (copy_from_user(&sr, argp, sizeof(sr)))
+ return -EFAULT;
if (sr.volNumber < 0) {
server->m.mounted_vol[0] = 0;
vnum = NCP_NUMBER_OF_VOLUMES;
#ifdef CONFIG_NCPFS_PACKET_SIGNING
case NCP_IOC_SIGN_INIT:
- if ((permission(inode, MAY_WRITE, NULL) != 0)
+ if ((file_permission(filp, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
}
- if (arg) {
+ if (argp) {
if (server->sign_wanted)
{
struct ncp_sign_init sign;
- if (copy_from_user(&sign, (struct ncp_sign_init *) arg,
- sizeof(sign))) return -EFAULT;
+ if (copy_from_user(&sign, argp, sizeof(sign)))
+ return -EFAULT;
memcpy(server->sign_root,sign.sign_root,8);
memcpy(server->sign_last,sign.sign_last,16);
server->sign_active = 1;
return 0;
case NCP_IOC_SIGN_WANTED:
- if ( (permission(inode, MAY_READ, NULL) != 0)
+ if ((file_permission(filp, MAY_READ) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
}
- if (put_user(server->sign_wanted, (int*) arg))
+ if (put_user(server->sign_wanted, (int __user *)argp))
return -EFAULT;
return 0;
case NCP_IOC_SET_SIGN_WANTED:
{
int newstate;
- if ( (permission(inode, MAY_WRITE, NULL) != 0)
+ if ((file_permission(filp, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
}
/* get only low 8 bits... */
- if (get_user(newstate, (unsigned char *) arg))
+ if (get_user(newstate, (unsigned char __user *)argp))
return -EFAULT;
if (server->sign_active) {
/* cannot turn signatures OFF when active */
#ifdef CONFIG_NCPFS_IOCTL_LOCKING
case NCP_IOC_LOCKUNLOCK:
- if ( (permission(inode, MAY_WRITE, NULL) != 0)
+ if ((file_permission(filp, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
struct ncp_lock_ioctl rqdata;
int result;
- if (copy_from_user(&rqdata, (struct ncp_lock_ioctl*)arg,
- sizeof(rqdata))) return -EFAULT;
+ if (copy_from_user(&rqdata, argp, sizeof(rqdata)))
+ return -EFAULT;
if (rqdata.origin != 0)
return -EINVAL;
/* check for cmd */
struct ncp_objectname_ioctl user;
size_t outl;
- if (copy_from_user(&user,
- (struct ncp_objectname_ioctl*)arg,
- sizeof(user))) return -EFAULT;
+ if (copy_from_user(&user, argp, sizeof(user)))
+ return -EFAULT;
user.auth_type = server->auth.auth_type;
outl = user.object_name_len;
user.object_name_len = server->auth.object_name_len;
server->auth.object_name,
outl)) return -EFAULT;
}
- if (copy_to_user((struct ncp_objectname_ioctl*)arg,
- &user,
- sizeof(user))) return -EFAULT;
+ if (copy_to_user(argp, &user, sizeof(user)))
+ return -EFAULT;
return 0;
}
case NCP_IOC_SETOBJECTNAME:
void* oldprivate;
size_t oldprivatelen;
- if (copy_from_user(&user,
- (struct ncp_objectname_ioctl*)arg,
- sizeof(user))) return -EFAULT;
+ if (copy_from_user(&user, argp, sizeof(user)))
+ return -EFAULT;
if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN)
return -ENOMEM;
if (user.object_name_len) {
- newname = ncp_kmalloc(user.object_name_len, GFP_USER);
- if (!newname) return -ENOMEM;
+ newname = kmalloc(user.object_name_len, GFP_USER);
+ if (!newname)
+ return -ENOMEM;
if (copy_from_user(newname, user.object_name, user.object_name_len)) {
- ncp_kfree_s(newname, user.object_name_len);
+ kfree(newname);
return -EFAULT;
}
} else {
server->priv.len = 0;
server->priv.data = NULL;
/* leave critical section */
- if (oldprivate) ncp_kfree_s(oldprivate, oldprivatelen);
- if (oldname) ncp_kfree_s(oldname, oldnamelen);
+ kfree(oldprivate);
+ kfree(oldname);
return 0;
}
case NCP_IOC_GETPRIVATEDATA:
struct ncp_privatedata_ioctl user;
size_t outl;
- if (copy_from_user(&user,
- (struct ncp_privatedata_ioctl*)arg,
- sizeof(user))) return -EFAULT;
+ if (copy_from_user(&user, argp, sizeof(user)))
+ return -EFAULT;
outl = user.len;
user.len = server->priv.len;
if (outl > user.len) outl = user.len;
server->priv.data,
outl)) return -EFAULT;
}
- if (copy_to_user((struct ncp_privatedata_ioctl*)arg,
- &user,
- sizeof(user))) return -EFAULT;
+ if (copy_to_user(argp, &user, sizeof(user)))
+ return -EFAULT;
return 0;
}
case NCP_IOC_SETPRIVATEDATA:
void* old;
size_t oldlen;
- if (copy_from_user(&user,
- (struct ncp_privatedata_ioctl*)arg,
- sizeof(user))) return -EFAULT;
+ if (copy_from_user(&user, argp, sizeof(user)))
+ return -EFAULT;
if (user.len > NCP_PRIVATE_DATA_MAX_LEN)
return -ENOMEM;
if (user.len) {
- new = ncp_kmalloc(user.len, GFP_USER);
- if (!new) return -ENOMEM;
+ new = kmalloc(user.len, GFP_USER);
+ if (!new)
+ return -ENOMEM;
if (copy_from_user(new, user.data, user.len)) {
- ncp_kfree_s(new, user.len);
+ kfree(new);
return -EFAULT;
}
} else {
server->priv.len = user.len;
server->priv.data = new;
/* leave critical section */
- if (old) ncp_kfree_s(old, oldlen);
+ kfree(old);
return 0;
}
#ifdef CONFIG_NCPFS_NLS
case NCP_IOC_SETCHARSETS:
- return ncp_set_charsets(server, (struct ncp_nls_ioctl *)arg);
+ return ncp_set_charsets(server, argp);
case NCP_IOC_GETCHARSETS:
- return ncp_get_charsets(server, (struct ncp_nls_ioctl *)arg);
+ return ncp_get_charsets(server, argp);
#endif /* CONFIG_NCPFS_NLS */
case NCP_IOC_SETDENTRYTTL:
- if ((permission(inode, MAY_WRITE, NULL) != 0) &&
+ if ((file_permission(filp, MAY_WRITE) != 0) &&
(current->uid != server->m.mounted_uid))
return -EACCES;
{
u_int32_t user;
- if (copy_from_user(&user, (u_int32_t*)arg, sizeof(user)))
+ if (copy_from_user(&user, argp, sizeof(user)))
return -EFAULT;
/* 20 secs at most... */
if (user > 20000)
case NCP_IOC_GETDENTRYTTL:
{
u_int32_t user = (server->dentry_ttl * 1000) / HZ;
- if (copy_to_user((u_int32_t*)arg, &user, sizeof(user)))
+ if (copy_to_user(argp, &user, sizeof(user)))
return -EFAULT;
return 0;
}
so we have this out of switch */
if (cmd == NCP_IOC_GETMOUNTUID) {
__kernel_uid_t uid = 0;
- if ((permission(inode, MAY_READ, NULL) != 0)
+ if ((file_permission(filp, MAY_READ) != 0)
&& (current->uid != server->m.mounted_uid)) {
return -EACCES;
}
SET_UID(uid, server->m.mounted_uid);
- if (put_user(uid, (__kernel_uid_t *) arg))
+ if (put_user(uid, (__kernel_uid_t __user *)argp))
return -EFAULT;
return 0;
}