summaryrefslogtreecommitdiffstats
path: root/net/rxrpc/security.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2016-06-13 07:16:05 -0400
committerDavid Howells <dhowells@redhat.com>2016-06-13 07:16:05 -0400
commit8c3e34a4ff85142ca5dba3f18cbc2061899e2612 (patch)
tree7e8098488c22da71b6a93296b182e29fe797ac3c /net/rxrpc/security.c
parent99860208bc62d8ebd5c57495b84856506fe075bc (diff)
rxrpc: Rename files matching ar-*.c to git rid of the "ar-" prefix
Rename files matching net/rxrpc/ar-*.c to get rid of the "ar-" prefix. This will aid splitting those files by making easier to come up with new names. Note that the not all files are simply renamed from ar-X.c to X.c. The following exceptions are made: (*) ar-call.c -> call_object.c ar-ack.c -> call_event.c call_object.c is going to contain the core of the call object handling. Call event handling is all going to be in call_event.c. (*) ar-accept.c -> call_accept.c Incoming call handling is going to be here. (*) ar-connection.c -> conn_object.c ar-connevent.c -> conn_event.c The former file is going to have the basic connection object handling, but there will likely be some differentiation between client connections and service connections in additional files later. The latter file will have all the connection-level event handling. (*) ar-local.c -> local_object.c This will have the local endpoint object handling code. The local endpoint event handling code will later be split out into local_event.c. (*) ar-peer.c -> peer_object.c This will have the peer endpoint object handling code. Peer event handling code will be placed in peer_event.c (for the moment, there is none). (*) ar-error.c -> peer_event.c This will become the peer event handling code, though for the moment it's actually driven from the local endpoint's perspective. Note that I haven't renamed ar-transport.c to transport_object.c as the intention is to delete it when the rxrpc_transport struct is excised. The only file that actually has its contents changed is net/rxrpc/Makefile. net/rxrpc/ar-internal.h will need its section marker comments updating, but I'll do that in a separate patch to make it easier for git to follow the history across the rename. I may also want to rename ar-internal.h at some point - but that would mean updating all the #includes and I'd rather do that in a separate step. Signed-off-by: David Howells <dhowells@redhat.com.
Diffstat (limited to 'net/rxrpc/security.c')
-rw-r--r--net/rxrpc/security.c168
1 files changed, 168 insertions, 0 deletions
diff --git a/net/rxrpc/security.c b/net/rxrpc/security.c
new file mode 100644
index 000000000000..d223253b22fa
--- /dev/null
+++ b/net/rxrpc/security.c
@@ -0,0 +1,168 @@
1/* RxRPC security handling
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/net.h>
14#include <linux/skbuff.h>
15#include <linux/udp.h>
16#include <linux/crypto.h>
17#include <net/sock.h>
18#include <net/af_rxrpc.h>
19#include <keys/rxrpc-type.h>
20#include "ar-internal.h"
21
22static LIST_HEAD(rxrpc_security_methods);
23static DECLARE_RWSEM(rxrpc_security_sem);
24
25static const struct rxrpc_security *rxrpc_security_types[] = {
26 [RXRPC_SECURITY_NONE] = &rxrpc_no_security,
27#ifdef CONFIG_RXKAD
28 [RXRPC_SECURITY_RXKAD] = &rxkad,
29#endif
30};
31
32int __init rxrpc_init_security(void)
33{
34 int i, ret;
35
36 for (i = 0; i < ARRAY_SIZE(rxrpc_security_types); i++) {
37 if (rxrpc_security_types[i]) {
38 ret = rxrpc_security_types[i]->init();
39 if (ret < 0)
40 goto failed;
41 }
42 }
43
44 return 0;
45
46failed:
47 for (i--; i >= 0; i--)
48 if (rxrpc_security_types[i])
49 rxrpc_security_types[i]->exit();
50 return ret;
51}
52
53void rxrpc_exit_security(void)
54{
55 int i;
56
57 for (i = 0; i < ARRAY_SIZE(rxrpc_security_types); i++)
58 if (rxrpc_security_types[i])
59 rxrpc_security_types[i]->exit();
60}
61
62/*
63 * look up an rxrpc security module
64 */
65static const struct rxrpc_security *rxrpc_security_lookup(u8 security_index)
66{
67 if (security_index >= ARRAY_SIZE(rxrpc_security_types))
68 return NULL;
69 return rxrpc_security_types[security_index];
70}
71
72/*
73 * initialise the security on a client connection
74 */
75int rxrpc_init_client_conn_security(struct rxrpc_connection *conn)
76{
77 const struct rxrpc_security *sec;
78 struct rxrpc_key_token *token;
79 struct key *key = conn->key;
80 int ret;
81
82 _enter("{%d},{%x}", conn->debug_id, key_serial(key));
83
84 if (!key)
85 return 0;
86
87 ret = key_validate(key);
88 if (ret < 0)
89 return ret;
90
91 token = key->payload.data[0];
92 if (!token)
93 return -EKEYREJECTED;
94
95 sec = rxrpc_security_lookup(token->security_index);
96 if (!sec)
97 return -EKEYREJECTED;
98 conn->security = sec;
99
100 ret = conn->security->init_connection_security(conn);
101 if (ret < 0) {
102 conn->security = &rxrpc_no_security;
103 return ret;
104 }
105
106 _leave(" = 0");
107 return 0;
108}
109
110/*
111 * initialise the security on a server connection
112 */
113int rxrpc_init_server_conn_security(struct rxrpc_connection *conn)
114{
115 const struct rxrpc_security *sec;
116 struct rxrpc_local *local = conn->trans->local;
117 struct rxrpc_sock *rx;
118 struct key *key;
119 key_ref_t kref;
120 char kdesc[5 + 1 + 3 + 1];
121
122 _enter("");
123
124 sprintf(kdesc, "%u:%u", conn->service_id, conn->security_ix);
125
126 sec = rxrpc_security_lookup(conn->security_ix);
127 if (!sec) {
128 _leave(" = -ENOKEY [lookup]");
129 return -ENOKEY;
130 }
131
132 /* find the service */
133 read_lock_bh(&local->services_lock);
134 list_for_each_entry(rx, &local->services, listen_link) {
135 if (rx->srx.srx_service == conn->service_id)
136 goto found_service;
137 }
138
139 /* the service appears to have died */
140 read_unlock_bh(&local->services_lock);
141 _leave(" = -ENOENT");
142 return -ENOENT;
143
144found_service:
145 if (!rx->securities) {
146 read_unlock_bh(&local->services_lock);
147 _leave(" = -ENOKEY");
148 return -ENOKEY;
149 }
150
151 /* look through the service's keyring */
152 kref = keyring_search(make_key_ref(rx->securities, 1UL),
153 &key_type_rxrpc_s, kdesc);
154 if (IS_ERR(kref)) {
155 read_unlock_bh(&local->services_lock);
156 _leave(" = %ld [search]", PTR_ERR(kref));
157 return PTR_ERR(kref);
158 }
159
160 key = key_ref_to_ptr(kref);
161 read_unlock_bh(&local->services_lock);
162
163 conn->server_key = key;
164 conn->security = sec;
165
166 _leave(" = 0");
167 return 0;
168}