]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/ipv4/netfilter/ipt_owner.c
Merge refs/heads/drm-latest from master.kernel.org:/pub/scm/linux/kernel/git/airlied...
[mirror_ubuntu-artful-kernel.git] / net / ipv4 / netfilter / ipt_owner.c
1 /* Kernel module to match various things tied to sockets associated with
2 locally generated outgoing packets. */
3
4 /* (C) 2000 Marc Boucher <marc@mbsi.ca>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <linux/file.h>
14 #include <net/sock.h>
15
16 #include <linux/netfilter_ipv4/ipt_owner.h>
17 #include <linux/netfilter_ipv4/ip_tables.h>
18
19 MODULE_LICENSE("GPL");
20 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
21 MODULE_DESCRIPTION("iptables owner match");
22
23 static int
24 match(const struct sk_buff *skb,
25 const struct net_device *in,
26 const struct net_device *out,
27 const void *matchinfo,
28 int offset,
29 int *hotdrop)
30 {
31 const struct ipt_owner_info *info = matchinfo;
32
33 if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
34 return 0;
35
36 if(info->match & IPT_OWNER_UID) {
37 if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
38 !!(info->invert & IPT_OWNER_UID))
39 return 0;
40 }
41
42 if(info->match & IPT_OWNER_GID) {
43 if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
44 !!(info->invert & IPT_OWNER_GID))
45 return 0;
46 }
47
48 return 1;
49 }
50
51 static int
52 checkentry(const char *tablename,
53 const struct ipt_ip *ip,
54 void *matchinfo,
55 unsigned int matchsize,
56 unsigned int hook_mask)
57 {
58 const struct ipt_owner_info *info = matchinfo;
59
60 if (hook_mask
61 & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING))) {
62 printk("ipt_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
63 return 0;
64 }
65
66 if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) {
67 printk("Matchsize %u != %Zu\n", matchsize,
68 IPT_ALIGN(sizeof(struct ipt_owner_info)));
69 return 0;
70 }
71
72 if (info->match & (IPT_OWNER_PID|IPT_OWNER_SID|IPT_OWNER_COMM)) {
73 printk("ipt_owner: pid, sid and command matching "
74 "not supported anymore\n");
75 return 0;
76 }
77
78 return 1;
79 }
80
81 static struct ipt_match owner_match = {
82 .name = "owner",
83 .match = &match,
84 .checkentry = &checkentry,
85 .me = THIS_MODULE,
86 };
87
88 static int __init init(void)
89 {
90 return ipt_register_match(&owner_match);
91 }
92
93 static void __exit fini(void)
94 {
95 ipt_unregister_match(&owner_match);
96 }
97
98 module_init(init);
99 module_exit(fini);