]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
CRED: Introduce credential access wrappers
authorDavid Howells <dhowells@redhat.com>
Wed, 13 Aug 2008 15:20:04 +0000 (16:20 +0100)
committerJames Morris <jmorris@namei.org>
Wed, 13 Aug 2008 23:35:23 +0000 (09:35 +1000)
The patches that are intended to introduce copy-on-write credentials for 2.6.28
require abstraction of access to some fields of the task structure,
particularly for the case of one task accessing another's credentials where RCU
will have to be observed.

Introduced here are trivial no-op versions of the desired accessors for current
and other tasks so that other subsystems can start to be converted over more
easily.

Wrappers are introduced into a new header (linux/cred.h) for UID/GID,
EUID/EGID, SUID/SGID, FSUID/FSGID, cap_effective and current's subscribed
user_struct.  These wrappers are macros because the ordering between header
files mitigates against making them inline functions.

linux/cred.h is #included from linux/sched.h.

Further, XFS is modified such that it no longer defines and uses parameterised
versions of current_fs[ug]id(), thus getting rid of the namespace collision
otherwise incurred.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
fs/xfs/linux-2.6/xfs_linux.h
fs/xfs/xfs_inode.c
fs/xfs/xfs_vnodeops.c
include/linux/cred.h [new file with mode: 0644]
include/linux/sched.h

index 3b7c4ff48ba0b42a5efff2c68cb432fa07c069b3..cc0f7b3a97957687114dd961d9543cd5c807aeb3 100644 (file)
 
 #define current_cpu()          (raw_smp_processor_id())
 #define current_pid()          (current->pid)
-#define current_fsuid(cred)    (current->fsuid)
-#define current_fsgid(cred)    (current->fsgid)
 #define current_test_flags(f)  (current->flags & (f))
 #define current_set_flags_nested(sp, f)                \
                (*(sp) = current->flags, current->flags |= (f))
index 358511b85ced103748730eb3886a95f1c0e6c71f..00e80df9dd9d727191f15fefc79cd92055d4e9d6 100644 (file)
@@ -1081,8 +1081,8 @@ xfs_ialloc(
        ip->i_d.di_onlink = 0;
        ip->i_d.di_nlink = nlink;
        ASSERT(ip->i_d.di_nlink == nlink);
-       ip->i_d.di_uid = current_fsuid(cr);
-       ip->i_d.di_gid = current_fsgid(cr);
+       ip->i_d.di_uid = current_fsuid();
+       ip->i_d.di_gid = current_fsgid();
        ip->i_d.di_projid = prid;
        memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
 
index 588bb4aa215d0bebba9106ec9b2afaf0120bfa33..aa238c8fbd7ae605e9f316969bb3012ee4c32f3c 100644 (file)
@@ -182,7 +182,7 @@ xfs_setattr(
        xfs_ilock(ip, lock_flags);
 
        /* boolean: are we the file owner? */
-       file_owner = (current_fsuid(credp) == ip->i_d.di_uid);
+       file_owner = (current_fsuid() == ip->i_d.di_uid);
 
        /*
         * Change various properties of a file.
@@ -1533,7 +1533,7 @@ xfs_create(
         * Make sure that we have allocated dquot(s) on disk.
         */
        error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(credp), current_fsgid(credp), prid,
+                       current_fsuid(), current_fsgid(), prid,
                        XFS_QMOPT_QUOTALL|XFS_QMOPT_INHERIT, &udqp, &gdqp);
        if (error)
                goto std_return;
@@ -2269,7 +2269,7 @@ xfs_mkdir(
         * Make sure that we have allocated dquot(s) on disk.
         */
        error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(credp), current_fsgid(credp), prid,
+                       current_fsuid(), current_fsgid(), prid,
                        XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp);
        if (error)
                goto std_return;
@@ -2495,7 +2495,7 @@ xfs_symlink(
         * Make sure that we have allocated dquot(s) on disk.
         */
        error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(credp), current_fsgid(credp), prid,
+                       current_fsuid(), current_fsgid(), prid,
                        XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp);
        if (error)
                goto std_return;
diff --git a/include/linux/cred.h b/include/linux/cred.h
new file mode 100644 (file)
index 0000000..b69222c
--- /dev/null
@@ -0,0 +1,50 @@
+/* Credentials management
+ *
+ * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_CRED_H
+#define _LINUX_CRED_H
+
+#define get_current_user()     (get_uid(current->user))
+
+#define task_uid(task)         ((task)->uid)
+#define task_gid(task)         ((task)->gid)
+#define task_euid(task)                ((task)->euid)
+#define task_egid(task)                ((task)->egid)
+
+#define current_uid()          (current->uid)
+#define current_gid()          (current->gid)
+#define current_euid()         (current->euid)
+#define current_egid()         (current->egid)
+#define current_suid()         (current->suid)
+#define current_sgid()         (current->sgid)
+#define current_fsuid()                (current->fsuid)
+#define current_fsgid()                (current->fsgid)
+#define current_cap()          (current->cap_effective)
+
+#define current_uid_gid(_uid, _gid)            \
+do {                                           \
+       *(_uid) = current->uid;                 \
+       *(_gid) = current->gid;                 \
+} while(0)
+
+#define current_euid_egid(_uid, _gid)          \
+do {                                           \
+       *(_uid) = current->euid;                \
+       *(_gid) = current->egid;                \
+} while(0)
+
+#define current_fsuid_fsgid(_uid, _gid)                \
+do {                                           \
+       *(_uid) = current->fsuid;               \
+       *(_gid) = current->fsgid;               \
+} while(0)
+
+#endif /* _LINUX_CRED_H */
index 5850bfb968a87079d767387169a0847e8530f217..cfb0d87b99fcafb8ff0eb753e0ea489dc20478dd 100644 (file)
@@ -87,6 +87,7 @@ struct sched_param {
 #include <linux/task_io_accounting.h>
 #include <linux/kobject.h>
 #include <linux/latencytop.h>
+#include <linux/cred.h>
 
 #include <asm/processor.h>