Revert to Fedora kernel-2.6.17-1.2187_FC5 patched with vs2.0.2.1; there are too many...
[linux-2.6.git] / fs / ncpfs / ioctl.c
index 6a35315..eb3813a 100644 (file)
@@ -10,6 +10,7 @@
 #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;
        }
@@ -58,11 +61,13 @@ ncp_get_fs_info(struct ncp_server* server, struct inode* inode, struct ncp_fs_in
 }
 
 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;
        }
@@ -90,7 +95,7 @@ ncp_get_fs_info_v2(struct ncp_server* server, struct inode* inode, struct ncp_fs
  * Thanks Petr Vandrovec for idea and many hints.
  */
 static int
-ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctlarg)
+ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
 {
        struct ncp_nls_ioctl user;
        struct nls_table *codepage;
@@ -148,7 +153,7 @@ ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl* arg)
 }
 
 static int
-ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctlarg)
+ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
 {
        struct ncp_nls_ioctl user;
        int len;
@@ -185,16 +190,16 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
        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)
@@ -245,21 +250,21 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
                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;
                }
@@ -268,7 +273,7 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
                {
                        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;
@@ -292,15 +297,16 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
                                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))
@@ -308,9 +314,8 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
                                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;
@@ -343,18 +348,18 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
 
 #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;
@@ -366,26 +371,26 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
                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 */
@@ -400,7 +405,7 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
 
 #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;
@@ -409,8 +414,8 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
                        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 */
@@ -480,9 +485,8 @@ outrel:
                        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;
@@ -493,9 +497,8 @@ outrel:
                                                 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:
@@ -510,16 +513,16 @@ outrel:
                        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 {
@@ -538,8 +541,8 @@ outrel:
                        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:
@@ -550,9 +553,8 @@ outrel:
                        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;
@@ -561,9 +563,8 @@ outrel:
                                                 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:
@@ -576,16 +577,16 @@ outrel:
                        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 {
@@ -597,27 +598,27 @@ outrel:
                        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)
@@ -630,7 +631,7 @@ outrel:
        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;
                }
@@ -641,12 +642,12 @@ outrel:
            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;
        }