blob: 42f12bd65964e3223aa016bfbd044869a6a07a88 [file] [log] [blame]
Paul Moored15c3452006-08-03 16:48:37 -07001/*
2 * NetLabel NETLINK Interface
3 *
4 * This file defines the NETLINK interface for the NetLabel system. The
5 * NetLabel system manages static and dynamic label mappings for network
6 * protocols such as CIPSO and RIPSO.
7 *
8 * Author: Paul Moore <paul.moore@hp.com>
9 *
10 */
11
12/*
13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
23 * the GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 */
30
31#include <linux/init.h>
32#include <linux/types.h>
33#include <linux/list.h>
34#include <linux/socket.h>
Paul Moore32f50cd2006-09-28 14:51:47 -070035#include <linux/audit.h>
36#include <linux/tty.h>
37#include <linux/security.h>
Paul Moored15c3452006-08-03 16:48:37 -070038#include <net/sock.h>
39#include <net/netlink.h>
40#include <net/genetlink.h>
41#include <net/netlabel.h>
42#include <asm/bug.h>
43
44#include "netlabel_mgmt.h"
45#include "netlabel_unlabeled.h"
46#include "netlabel_cipso_v4.h"
47#include "netlabel_user.h"
48
Paul Moorede646882006-11-17 17:38:55 -050049/* do not do any auditing if audit_enabled == 0, see kernel/audit.c for
50 * details */
51extern int audit_enabled;
52
Paul Moored15c3452006-08-03 16:48:37 -070053/*
54 * NetLabel NETLINK Setup Functions
55 */
56
57/**
58 * netlbl_netlink_init - Initialize the NETLINK communication channel
59 *
60 * Description:
61 * Call out to the NetLabel components so they can register their families and
62 * commands with the Generic NETLINK mechanism. Returns zero on success and
63 * non-zero on failure.
64 *
65 */
66int netlbl_netlink_init(void)
67{
68 int ret_val;
69
70 ret_val = netlbl_mgmt_genl_init();
71 if (ret_val != 0)
72 return ret_val;
73
74 ret_val = netlbl_cipsov4_genl_init();
75 if (ret_val != 0)
76 return ret_val;
77
78 ret_val = netlbl_unlabel_genl_init();
79 if (ret_val != 0)
80 return ret_val;
81
82 return 0;
83}
Paul Moore32f50cd2006-09-28 14:51:47 -070084
85/*
86 * NetLabel Audit Functions
87 */
88
89/**
90 * netlbl_audit_start_common - Start an audit message
91 * @type: audit message type
Paul Moore95d4e6b2006-09-29 17:05:05 -070092 * @audit_info: NetLabel audit information
Paul Moore32f50cd2006-09-28 14:51:47 -070093 *
94 * Description:
95 * Start an audit message using the type specified in @type and fill the audit
96 * message with some fields common to all NetLabel audit messages. Returns
97 * a pointer to the audit buffer on success, NULL on failure.
98 *
99 */
Paul Moore95d4e6b2006-09-29 17:05:05 -0700100struct audit_buffer *netlbl_audit_start_common(int type,
101 struct netlbl_audit *audit_info)
Paul Moore32f50cd2006-09-28 14:51:47 -0700102{
103 struct audit_context *audit_ctx = current->audit_context;
104 struct audit_buffer *audit_buf;
Paul Moore32f50cd2006-09-28 14:51:47 -0700105 char *secctx;
106 u32 secctx_len;
107
Paul Moorede646882006-11-17 17:38:55 -0500108 if (audit_enabled == 0)
109 return NULL;
110
Paul Moore32f50cd2006-09-28 14:51:47 -0700111 audit_buf = audit_log_start(audit_ctx, GFP_ATOMIC, type);
112 if (audit_buf == NULL)
113 return NULL;
114
Paul Moore95d4e6b2006-09-29 17:05:05 -0700115 audit_log_format(audit_buf, "netlabel: auid=%u", audit_info->loginuid);
Paul Moore32f50cd2006-09-28 14:51:47 -0700116
Paul Moore95d4e6b2006-09-29 17:05:05 -0700117 if (audit_info->secid != 0 &&
118 security_secid_to_secctx(audit_info->secid,
119 &secctx,
120 &secctx_len) == 0)
Paul Moore32f50cd2006-09-28 14:51:47 -0700121 audit_log_format(audit_buf, " subj=%s", secctx);
122
123 return audit_buf;
124}