include/linux/cred.h
author Florian Westphal <fw@strlen.de>
Thu, 09 Apr 2009 12:07:21 +0200
changeset 2 d1f6d8b6f81c
parent 0 aa628870c1d3
permissions -rw-r--r--
Linux 2.6.29 for NSC 0.5.0.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
     1
/* Credentials management - see Documentation/credentials.txt
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     2
 *
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     3
 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     4
 * Written by David Howells (dhowells@redhat.com)
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     5
 *
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     7
 * modify it under the terms of the GNU General Public Licence
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     8
 * as published by the Free Software Foundation; either version
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     9
 * 2 of the Licence, or (at your option) any later version.
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    10
 */
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    11
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    12
#ifndef _LINUX_CRED_H
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    13
#define _LINUX_CRED_H
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    14
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    15
#include <linux/capability.h>
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    16
#include <linux/key.h>
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    17
#include <asm/atomic.h>
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    18
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    19
struct user_struct;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    20
struct cred;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    21
struct inode;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    22
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    23
/*
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    24
 * COW Supplementary groups list
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    25
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    26
#define NGROUPS_SMALL		32
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    27
#define NGROUPS_PER_BLOCK	((unsigned int)(PAGE_SIZE / sizeof(gid_t)))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    28
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    29
struct group_info {
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    30
	atomic_t	usage;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    31
	int		ngroups;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    32
	int		nblocks;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    33
	gid_t		small_block[NGROUPS_SMALL];
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    34
	gid_t		*blocks[0];
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    35
};
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    36
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    37
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    38
 * get_group_info - Get a reference to a group info structure
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    39
 * @group_info: The group info to reference
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    40
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    41
 * This gets a reference to a set of supplementary groups.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    42
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    43
 * If the caller is accessing a task's credentials, they must hold the RCU read
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    44
 * lock when reading.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    45
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    46
static inline struct group_info *get_group_info(struct group_info *gi)
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    47
{
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    48
	atomic_inc(&gi->usage);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    49
	return gi;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    50
}
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    51
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    52
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    53
 * put_group_info - Release a reference to a group info structure
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    54
 * @group_info: The group info to release
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    55
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    56
#define put_group_info(group_info)			\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    57
do {							\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    58
	if (atomic_dec_and_test(&(group_info)->usage))	\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    59
		groups_free(group_info);		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    60
} while (0)
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    61
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    62
extern struct group_info *groups_alloc(int);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    63
extern struct group_info init_groups;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    64
extern void groups_free(struct group_info *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    65
extern int set_current_groups(struct group_info *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    66
extern int set_groups(struct cred *, struct group_info *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    67
extern int groups_search(const struct group_info *, gid_t);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    68
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    69
/* access the groups "array" with this macro */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    70
#define GROUP_AT(gi, i) \
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    71
	((gi)->blocks[(i) / NGROUPS_PER_BLOCK][(i) % NGROUPS_PER_BLOCK])
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    72
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    73
extern int in_group_p(gid_t);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    74
extern int in_egroup_p(gid_t);
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    75
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    76
/*
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    77
 * The common credentials for a thread group
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    78
 * - shared by CLONE_THREAD
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    79
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    80
#ifdef CONFIG_KEYS
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    81
struct thread_group_cred {
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    82
	atomic_t	usage;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    83
	pid_t		tgid;			/* thread group process ID */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    84
	spinlock_t	lock;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    85
	struct key	*session_keyring;	/* keyring inherited over fork */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    86
	struct key	*process_keyring;	/* keyring private to this process */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    87
	struct rcu_head	rcu;			/* RCU deletion hook */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    88
};
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    89
#endif
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    90
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    91
/*
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    92
 * The security context of a task
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    93
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    94
 * The parts of the context break down into two categories:
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    95
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    96
 *  (1) The objective context of a task.  These parts are used when some other
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    97
 *	task is attempting to affect this one.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    98
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
    99
 *  (2) The subjective context.  These details are used when the task is acting
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   100
 *	upon another object, be that a file, a task, a key or whatever.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   101
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   102
 * Note that some members of this structure belong to both categories - the
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   103
 * LSM security pointer for instance.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   104
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   105
 * A task has two security pointers.  task->real_cred points to the objective
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   106
 * context that defines that task's actual details.  The objective part of this
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   107
 * context is used whenever that task is acted upon.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   108
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   109
 * task->cred points to the subjective context that defines the details of how
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   110
 * that task is going to act upon another object.  This may be overridden
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   111
 * temporarily to point to another security context, but normally points to the
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   112
 * same context as task->real_cred.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   113
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   114
struct cred {
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   115
	atomic_t	usage;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   116
	uid_t		uid;		/* real UID of the task */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   117
	gid_t		gid;		/* real GID of the task */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   118
	uid_t		suid;		/* saved UID of the task */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   119
	gid_t		sgid;		/* saved GID of the task */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   120
	uid_t		euid;		/* effective UID of the task */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   121
	gid_t		egid;		/* effective GID of the task */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   122
	uid_t		fsuid;		/* UID for VFS ops */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   123
	gid_t		fsgid;		/* GID for VFS ops */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   124
	unsigned	securebits;	/* SUID-less security management */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   125
	kernel_cap_t	cap_inheritable; /* caps our children can inherit */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   126
	kernel_cap_t	cap_permitted;	/* caps we're permitted */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   127
	kernel_cap_t	cap_effective;	/* caps we can actually use */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   128
	kernel_cap_t	cap_bset;	/* capability bounding set */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   129
#ifdef CONFIG_KEYS
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   130
	unsigned char	jit_keyring;	/* default keyring to attach requested
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   131
					 * keys to */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   132
	struct key	*thread_keyring; /* keyring private to this thread */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   133
	struct key	*request_key_auth; /* assumed request_key authority */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   134
	struct thread_group_cred *tgcred; /* thread-group shared credentials */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   135
#endif
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   136
#ifdef CONFIG_SECURITY
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   137
	void		*security;	/* subjective LSM security */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   138
#endif
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   139
	struct user_struct *user;	/* real user ID subscription */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   140
	struct group_info *group_info;	/* supplementary groups for euid/fsgid */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   141
	struct rcu_head	rcu;		/* RCU deletion hook */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   142
};
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   143
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   144
extern void __put_cred(struct cred *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   145
extern int copy_creds(struct task_struct *, unsigned long);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   146
extern struct cred *prepare_creds(void);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   147
extern struct cred *prepare_exec_creds(void);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   148
extern struct cred *prepare_usermodehelper_creds(void);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   149
extern int commit_creds(struct cred *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   150
extern void abort_creds(struct cred *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   151
extern const struct cred *override_creds(const struct cred *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   152
extern void revert_creds(const struct cred *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   153
extern struct cred *prepare_kernel_cred(struct task_struct *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   154
extern int change_create_files_as(struct cred *, struct inode *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   155
extern int set_security_override(struct cred *, u32);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   156
extern int set_security_override_from_ctx(struct cred *, const char *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   157
extern int set_create_files_as(struct cred *, struct inode *);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   158
extern void __init cred_init(void);
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   159
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   160
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   161
 * get_new_cred - Get a reference on a new set of credentials
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   162
 * @cred: The new credentials to reference
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   163
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   164
 * Get a reference on the specified set of new credentials.  The caller must
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   165
 * release the reference.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   166
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   167
static inline struct cred *get_new_cred(struct cred *cred)
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   168
{
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   169
	atomic_inc(&cred->usage);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   170
	return cred;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   171
}
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   172
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   173
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   174
 * get_cred - Get a reference on a set of credentials
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   175
 * @cred: The credentials to reference
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   176
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   177
 * Get a reference on the specified set of credentials.  The caller must
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   178
 * release the reference.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   179
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   180
 * This is used to deal with a committed set of credentials.  Although the
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   181
 * pointer is const, this will temporarily discard the const and increment the
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   182
 * usage count.  The purpose of this is to attempt to catch at compile time the
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   183
 * accidental alteration of a set of credentials that should be considered
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   184
 * immutable.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   185
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   186
static inline const struct cred *get_cred(const struct cred *cred)
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   187
{
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   188
	return get_new_cred((struct cred *) cred);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   189
}
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   190
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   191
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   192
 * put_cred - Release a reference to a set of credentials
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   193
 * @cred: The credentials to release
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   194
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   195
 * Release a reference to a set of credentials, deleting them when the last ref
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   196
 * is released.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   197
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   198
 * This takes a const pointer to a set of credentials because the credentials
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   199
 * on task_struct are attached by const pointers to prevent accidental
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   200
 * alteration of otherwise immutable credential sets.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   201
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   202
static inline void put_cred(const struct cred *_cred)
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   203
{
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   204
	struct cred *cred = (struct cred *) _cred;
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   205
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   206
	BUG_ON(atomic_read(&(cred)->usage) <= 0);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   207
	if (atomic_dec_and_test(&(cred)->usage))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   208
		__put_cred(cred);
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   209
}
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   210
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   211
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   212
 * current_cred - Access the current task's subjective credentials
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   213
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   214
 * Access the subjective credentials of the current task.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   215
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   216
#define current_cred() \
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   217
	(current->cred)
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   218
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   219
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   220
 * __task_cred - Access a task's objective credentials
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   221
 * @task: The task to query
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   222
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   223
 * Access the objective credentials of a task.  The caller must hold the RCU
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   224
 * readlock.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   225
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   226
 * The caller must make sure task doesn't go away, either by holding a ref on
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   227
 * task or by holding tasklist_lock to prevent it from being unlinked.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   228
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   229
#define __task_cred(task) \
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   230
	((const struct cred *)(rcu_dereference((task)->real_cred)))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   231
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   232
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   233
 * get_task_cred - Get another task's objective credentials
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   234
 * @task: The task to query
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   235
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   236
 * Get the objective credentials of a task, pinning them so that they can't go
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   237
 * away.  Accessing a task's credentials directly is not permitted.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   238
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   239
 * The caller must make sure task doesn't go away, either by holding a ref on
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   240
 * task or by holding tasklist_lock to prevent it from being unlinked.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   241
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   242
#define get_task_cred(task)				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   243
({							\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   244
	struct cred *__cred;				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   245
	rcu_read_lock();				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   246
	__cred = (struct cred *) __task_cred((task));	\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   247
	get_cred(__cred);				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   248
	rcu_read_unlock();				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   249
	__cred;						\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   250
})
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   251
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   252
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   253
 * get_current_cred - Get the current task's subjective credentials
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   254
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   255
 * Get the subjective credentials of the current task, pinning them so that
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   256
 * they can't go away.  Accessing the current task's credentials directly is
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   257
 * not permitted.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   258
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   259
#define get_current_cred()				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   260
	(get_cred(current_cred()))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   261
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   262
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   263
 * get_current_user - Get the current task's user_struct
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   264
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   265
 * Get the user record of the current task, pinning it so that it can't go
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   266
 * away.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   267
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   268
#define get_current_user()				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   269
({							\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   270
	struct user_struct *__u;			\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   271
	struct cred *__cred;				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   272
	__cred = (struct cred *) current_cred();	\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   273
	__u = get_uid(__cred->user);			\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   274
	__u;						\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   275
})
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   276
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   277
/**
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   278
 * get_current_groups - Get the current task's supplementary group list
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   279
 *
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   280
 * Get the supplementary group list of the current task, pinning it so that it
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   281
 * can't go away.
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   282
 */
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   283
#define get_current_groups()				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   284
({							\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   285
	struct group_info *__groups;			\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   286
	struct cred *__cred;				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   287
	__cred = (struct cred *) current_cred();	\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   288
	__groups = get_group_info(__cred->group_info);	\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   289
	__groups;					\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   290
})
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   291
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   292
#define task_cred_xxx(task, xxx)			\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   293
({							\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   294
	__typeof__(((struct cred *)NULL)->xxx) ___val;	\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   295
	rcu_read_lock();				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   296
	___val = __task_cred((task))->xxx;		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   297
	rcu_read_unlock();				\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   298
	___val;						\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   299
})
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   300
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   301
#define task_uid(task)		(task_cred_xxx((task), uid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   302
#define task_euid(task)		(task_cred_xxx((task), euid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   303
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   304
#define current_cred_xxx(xxx)			\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   305
({						\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   306
	current->cred->xxx;			\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   307
})
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   308
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   309
#define current_uid()		(current_cred_xxx(uid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   310
#define current_gid()		(current_cred_xxx(gid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   311
#define current_euid()		(current_cred_xxx(euid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   312
#define current_egid()		(current_cred_xxx(egid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   313
#define current_suid()		(current_cred_xxx(suid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   314
#define current_sgid()		(current_cred_xxx(sgid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   315
#define current_fsuid() 	(current_cred_xxx(fsuid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   316
#define current_fsgid() 	(current_cred_xxx(fsgid))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   317
#define current_cap()		(current_cred_xxx(cap_effective))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   318
#define current_user()		(current_cred_xxx(user))
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   319
#define current_user_ns()	(current_cred_xxx(user)->user_ns)
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   320
#define current_security()	(current_cred_xxx(security))
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   321
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   322
#define current_uid_gid(_uid, _gid)		\
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   323
do {						\
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   324
	const struct cred *__cred;		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   325
	__cred = current_cred();		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   326
	*(_uid) = __cred->uid;			\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   327
	*(_gid) = __cred->gid;			\
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   328
} while(0)
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   329
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   330
#define current_euid_egid(_euid, _egid)		\
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   331
do {						\
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   332
	const struct cred *__cred;		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   333
	__cred = current_cred();		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   334
	*(_euid) = __cred->euid;		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   335
	*(_egid) = __cred->egid;		\
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   336
} while(0)
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   337
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   338
#define current_fsuid_fsgid(_fsuid, _fsgid)	\
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   339
do {						\
2
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   340
	const struct cred *__cred;		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   341
	__cred = current_cred();		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   342
	*(_fsuid) = __cred->fsuid;		\
d1f6d8b6f81c Linux 2.6.29 for NSC 0.5.0.
Florian Westphal <fw@strlen.de>
parents: 0
diff changeset
   343
	*(_fsgid) = __cred->fsgid;		\
0
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   344
} while(0)
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   345
aa628870c1d3 Port of Linux 2.6.28 for use with network simulation cradle.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   346
#endif /* _LINUX_CRED_H */