IB/srp: Coverity fix to srp_parse_options()
[linux-2.6/verdex.git] / net / ipv4 / netfilter / ipt_owner.c
blob4843d0c9734f28c26a3d0bf35f4acb86f4204442
1 /* Kernel module to match various things tied to sockets associated with
2 locally generated outgoing packets. */
4 /* (C) 2000 Marc Boucher <marc@mbsi.ca>
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 */
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <linux/file.h>
14 #include <linux/rcupdate.h>
15 #include <net/sock.h>
17 #include <linux/netfilter_ipv4/ipt_owner.h>
18 #include <linux/netfilter_ipv4/ip_tables.h>
20 MODULE_LICENSE("GPL");
21 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
22 MODULE_DESCRIPTION("iptables owner match");
24 static int
25 match(const struct sk_buff *skb,
26 const struct net_device *in,
27 const struct net_device *out,
28 const void *matchinfo,
29 int offset,
30 unsigned int protoff,
31 int *hotdrop)
33 const struct ipt_owner_info *info = matchinfo;
35 if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
36 return 0;
38 if(info->match & IPT_OWNER_UID) {
39 if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
40 !!(info->invert & IPT_OWNER_UID))
41 return 0;
44 if(info->match & IPT_OWNER_GID) {
45 if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
46 !!(info->invert & IPT_OWNER_GID))
47 return 0;
50 return 1;
53 static int
54 checkentry(const char *tablename,
55 const void *ip,
56 void *matchinfo,
57 unsigned int matchsize,
58 unsigned int hook_mask)
60 const struct ipt_owner_info *info = matchinfo;
62 if (hook_mask
63 & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING))) {
64 printk("ipt_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
65 return 0;
68 if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) {
69 printk("Matchsize %u != %Zu\n", matchsize,
70 IPT_ALIGN(sizeof(struct ipt_owner_info)));
71 return 0;
74 if (info->match & (IPT_OWNER_PID|IPT_OWNER_SID|IPT_OWNER_COMM)) {
75 printk("ipt_owner: pid, sid and command matching "
76 "not supported anymore\n");
77 return 0;
80 return 1;
83 static struct ipt_match owner_match = {
84 .name = "owner",
85 .match = &match,
86 .checkentry = &checkentry,
87 .me = THIS_MODULE,
90 static int __init init(void)
92 return ipt_register_match(&owner_match);
95 static void __exit fini(void)
97 ipt_unregister_match(&owner_match);
100 module_init(init);
101 module_exit(fini);