2 * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 typedef int32_t key_serial_t;
32 #include "xlat/key_spec.h"
35 print_keyring_serial_number(key_serial_t id)
37 const char *str = xlookup(key_spec, id);
48 printstr(tcp, tcp->u_arg[0], -1);
51 printstr(tcp, tcp->u_arg[1], -1);
54 printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
56 tprintf(", %lu, ", tcp->u_arg[3]);
57 /* keyring serial number */
58 print_keyring_serial_number(tcp->u_arg[4]);
66 printstr(tcp, tcp->u_arg[0], -1);
69 printstr(tcp, tcp->u_arg[1], -1);
72 printstr(tcp, tcp->u_arg[2], -1);
73 /* keyring serial number */
75 print_keyring_serial_number(tcp->u_arg[3]);
81 keyctl_get_keyring_id(struct tcb *tcp, key_serial_t id, int create)
83 print_keyring_serial_number(id);
84 tprintf(", %d", create);
88 keyctl_update_key(struct tcb *tcp, key_serial_t id, long addr, long len)
90 print_keyring_serial_number(id);
92 printstr(tcp, addr, len);
93 tprintf(", %lu", len);
97 keyctl_handle_key_key(struct tcb *tcp, key_serial_t id1, key_serial_t id2)
99 print_keyring_serial_number(id1);
101 print_keyring_serial_number(id2);
105 keyctl_read_key(struct tcb *tcp, key_serial_t id, long addr, long len)
108 print_keyring_serial_number(id);
114 long rval = tcp->u_rval > len ?
115 len : (tcp->u_rval ? -1 : 0);
116 printstr(tcp, addr, rval);
118 tprintf(", %lu", len);
123 keyctl_keyring_search(struct tcb *tcp, key_serial_t id1, long addr1,
124 long addr2, key_serial_t id2)
126 print_keyring_serial_number(id1);
128 printstr(tcp, addr1, -1);
130 printstr(tcp, addr2, -1);
132 print_keyring_serial_number(id2);
136 keyctl_chown_key(struct tcb *tcp, key_serial_t id, int user, int group)
138 print_keyring_serial_number(id);
139 tprintf(", %d, %d", user, group);
143 keyctl_instantiate_key(struct tcb *tcp, key_serial_t id1, long addr,
144 long len, key_serial_t id2)
146 print_keyring_serial_number(id1);
148 printstr(tcp, addr, len);
149 tprintf(", %lu, ", len);
150 print_keyring_serial_number(id2);
154 keyctl_instantiate_key_iov(struct tcb *tcp, key_serial_t id1,
155 long addr, long len, key_serial_t id2)
157 print_keyring_serial_number(id1);
159 tprint_iov(tcp, len, addr, 1);
160 tprintf(", %lu, ", len);
161 print_keyring_serial_number(id2);
165 keyctl_negate_key(struct tcb *tcp, key_serial_t id1, unsigned timeout,
168 print_keyring_serial_number(id1);
169 tprintf(", %u, ", timeout);
170 print_keyring_serial_number(id2);
174 keyctl_reject_key(struct tcb *tcp, key_serial_t id1, unsigned timeout,
175 unsigned error, key_serial_t id2)
177 print_keyring_serial_number(id1);
178 tprintf(", %u, %u, ", timeout, error);
179 print_keyring_serial_number(id2);
183 keyctl_set_timeout(struct tcb *tcp, key_serial_t id, unsigned timeout)
185 print_keyring_serial_number(id);
186 tprintf(", %u", timeout);
190 keyctl_get_persistent(struct tcb *tcp, int uid, key_serial_t id)
192 tprintf("%d, ", uid);
193 print_keyring_serial_number(id);
196 #include "xlat/key_perms.h"
199 keyctl_setperm_key(struct tcb *tcp, key_serial_t id, uint32_t perm)
201 print_keyring_serial_number(id);
203 printflags(key_perms, perm, "KEY_???");
206 #include "xlat/key_reqkeys.h"
207 #include "xlat/keyctl_commands.h"
211 int cmd = tcp->u_arg[0];
214 printxval(keyctl_commands, cmd, "KEYCTL_???");
219 case KEYCTL_GET_KEYRING_ID:
220 keyctl_get_keyring_id(tcp, tcp->u_arg[1], tcp->u_arg[2]);
223 case KEYCTL_JOIN_SESSION_KEYRING:
224 printstr(tcp, tcp->u_arg[1], -1);
228 keyctl_update_key(tcp, tcp->u_arg[1],
229 tcp->u_arg[2], tcp->u_arg[3]);
234 case KEYCTL_INVALIDATE:
235 case KEYCTL_ASSUME_AUTHORITY:
236 print_keyring_serial_number(tcp->u_arg[1]);
241 keyctl_handle_key_key(tcp, tcp->u_arg[1], tcp->u_arg[2]);
244 case KEYCTL_DESCRIBE:
246 case KEYCTL_GET_SECURITY:
247 keyctl_read_key(tcp, tcp->u_arg[1],
248 tcp->u_arg[2], tcp->u_arg[3]);
252 keyctl_keyring_search(tcp, tcp->u_arg[1], tcp->u_arg[2],
253 tcp->u_arg[3], tcp->u_arg[4]);
257 keyctl_chown_key(tcp, tcp->u_arg[1],
258 tcp->u_arg[2], tcp->u_arg[3]);
262 keyctl_setperm_key(tcp, tcp->u_arg[1], tcp->u_arg[2]);
265 case KEYCTL_INSTANTIATE:
266 keyctl_instantiate_key(tcp, tcp->u_arg[1], tcp->u_arg[2],
267 tcp->u_arg[3], tcp->u_arg[4]);
271 keyctl_negate_key(tcp, tcp->u_arg[1],
272 tcp->u_arg[2], tcp->u_arg[3]);
275 case KEYCTL_SET_REQKEY_KEYRING:
276 printxval(key_reqkeys, tcp->u_arg[1], "KEY_REQKEY_DEFL_???");
279 case KEYCTL_SET_TIMEOUT:
280 keyctl_set_timeout(tcp, tcp->u_arg[1], tcp->u_arg[2]);
283 case KEYCTL_SESSION_TO_PARENT:
287 keyctl_reject_key(tcp, tcp->u_arg[1], tcp->u_arg[2],
288 tcp->u_arg[3], tcp->u_arg[4]);
291 case KEYCTL_INSTANTIATE_IOV:
292 keyctl_instantiate_key_iov(tcp, tcp->u_arg[1],
293 tcp->u_arg[2], tcp->u_arg[3],
297 case KEYCTL_GET_PERSISTENT:
298 keyctl_get_persistent(tcp, tcp->u_arg[1], tcp->u_arg[2]);
302 tprintf("%#lx, %#lx, %#lx, %#lx",
303 tcp->u_arg[1], tcp->u_arg[2],
304 tcp->u_arg[3], tcp->u_arg[4]);