sock: Introduce cred_to_ucred
To keep the coming code clear and to allow both the sock code and the scm code to share the logic introduce a fuction to translate from struct cred to struct ucred. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Acked-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
5c1469de75
commit
3f551f9436
@@ -110,6 +110,7 @@
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/highmem.h>
|
||||
#include <linux/user_namespace.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/system.h>
|
||||
@@ -749,6 +750,19 @@ set_rcvbuf:
|
||||
EXPORT_SYMBOL(sock_setsockopt);
|
||||
|
||||
|
||||
void cred_to_ucred(struct pid *pid, const struct cred *cred,
|
||||
struct ucred *ucred)
|
||||
{
|
||||
ucred->pid = pid_vnr(pid);
|
||||
ucred->uid = ucred->gid = -1;
|
||||
if (cred) {
|
||||
struct user_namespace *current_ns = current_user_ns();
|
||||
|
||||
ucred->uid = user_ns_map_uid(current_ns, cred, cred->euid);
|
||||
ucred->gid = user_ns_map_gid(current_ns, cred, cred->egid);
|
||||
}
|
||||
}
|
||||
|
||||
int sock_getsockopt(struct socket *sock, int level, int optname,
|
||||
char __user *optval, int __user *optlen)
|
||||
{
|
||||
|
Reference in New Issue
Block a user