]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
b835996f | 14 | #include <linux/rcupdate.h> |
1da177e4 LT |
15 | #include <net/sock.h> |
16 | ||
17 | #include <linux/netfilter_ipv4/ipt_owner.h> | |
6709dbbb | 18 | #include <linux/netfilter/x_tables.h> |
1da177e4 LT |
19 | |
20 | MODULE_LICENSE("GPL"); | |
21 | MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>"); | |
22 | MODULE_DESCRIPTION("iptables owner match"); | |
23 | ||
1da177e4 LT |
24 | static int |
25 | match(const struct sk_buff *skb, | |
26 | const struct net_device *in, | |
27 | const struct net_device *out, | |
c4986734 | 28 | const struct xt_match *match, |
1da177e4 LT |
29 | const void *matchinfo, |
30 | int offset, | |
2e4e6a17 | 31 | unsigned int protoff, |
1da177e4 LT |
32 | int *hotdrop) |
33 | { | |
34 | const struct ipt_owner_info *info = matchinfo; | |
35 | ||
36 | if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file) | |
37 | return 0; | |
38 | ||
39 | if(info->match & IPT_OWNER_UID) { | |
40 | if ((skb->sk->sk_socket->file->f_uid != info->uid) ^ | |
41 | !!(info->invert & IPT_OWNER_UID)) | |
42 | return 0; | |
43 | } | |
44 | ||
45 | if(info->match & IPT_OWNER_GID) { | |
46 | if ((skb->sk->sk_socket->file->f_gid != info->gid) ^ | |
47 | !!(info->invert & IPT_OWNER_GID)) | |
48 | return 0; | |
49 | } | |
50 | ||
1da177e4 LT |
51 | return 1; |
52 | } | |
53 | ||
54 | static int | |
55 | checkentry(const char *tablename, | |
e905a9ed | 56 | const void *ip, |
c4986734 | 57 | const struct xt_match *match, |
e905a9ed YH |
58 | void *matchinfo, |
59 | unsigned int hook_mask) | |
1da177e4 | 60 | { |
34b4a4a6 CH |
61 | const struct ipt_owner_info *info = matchinfo; |
62 | ||
34b4a4a6 CH |
63 | if (info->match & (IPT_OWNER_PID|IPT_OWNER_SID|IPT_OWNER_COMM)) { |
64 | printk("ipt_owner: pid, sid and command matching " | |
65 | "not supported anymore\n"); | |
1da177e4 LT |
66 | return 0; |
67 | } | |
1da177e4 LT |
68 | return 1; |
69 | } | |
70 | ||
6709dbbb | 71 | static struct xt_match owner_match = { |
1da177e4 | 72 | .name = "owner", |
6709dbbb | 73 | .family = AF_INET, |
1d5cd909 PM |
74 | .match = match, |
75 | .matchsize = sizeof(struct ipt_owner_info), | |
76 | .hooks = (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING), | |
77 | .checkentry = checkentry, | |
1da177e4 LT |
78 | .me = THIS_MODULE, |
79 | }; | |
80 | ||
65b4b4e8 | 81 | static int __init ipt_owner_init(void) |
1da177e4 | 82 | { |
6709dbbb | 83 | return xt_register_match(&owner_match); |
1da177e4 LT |
84 | } |
85 | ||
65b4b4e8 | 86 | static void __exit ipt_owner_fini(void) |
1da177e4 | 87 | { |
6709dbbb | 88 | xt_unregister_match(&owner_match); |
1da177e4 LT |
89 | } |
90 | ||
65b4b4e8 AM |
91 | module_init(ipt_owner_init); |
92 | module_exit(ipt_owner_fini); |