12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 22aa349f6SDavid Howells /* user-type.h: User-defined key type 32aa349f6SDavid Howells * 42aa349f6SDavid Howells * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved. 52aa349f6SDavid Howells * Written by David Howells (dhowells@redhat.com) 62aa349f6SDavid Howells */ 72aa349f6SDavid Howells 82aa349f6SDavid Howells #ifndef _KEYS_USER_TYPE_H 92aa349f6SDavid Howells #define _KEYS_USER_TYPE_H 102aa349f6SDavid Howells 112aa349f6SDavid Howells #include <linux/key.h> 122aa349f6SDavid Howells #include <linux/rcupdate.h> 132aa349f6SDavid Howells 14146aa8b1SDavid Howells #ifdef CONFIG_KEYS 15146aa8b1SDavid Howells 162aa349f6SDavid Howells /*****************************************************************************/ 172aa349f6SDavid Howells /* 189f6ed2caSJeff Layton * the payload for a key of type "user" or "logon" 192aa349f6SDavid Howells * - once filled in and attached to a key: 202aa349f6SDavid Howells * - the payload struct is invariant may not be changed, only replaced 212aa349f6SDavid Howells * - the payload must be read with RCU procedures or with the key semaphore 222aa349f6SDavid Howells * held 232aa349f6SDavid Howells * - the payload may only be replaced with the key semaphore write-locked 242aa349f6SDavid Howells * - the key's data length is the size of the actual data, not including the 252aa349f6SDavid Howells * payload wrapper 262aa349f6SDavid Howells */ 272aa349f6SDavid Howells struct user_key_payload { 282aa349f6SDavid Howells struct rcu_head rcu; /* RCU destructor */ 292aa349f6SDavid Howells unsigned short datalen; /* length of this data */ 302ce113faSGustavo A. R. Silva char data[] __aligned(__alignof__(u64)); /* actual data */ 312aa349f6SDavid Howells }; 322aa349f6SDavid Howells 332aa349f6SDavid Howells extern struct key_type key_type_user; 349f6ed2caSJeff Layton extern struct key_type key_type_logon; 352aa349f6SDavid Howells 36cf7f601cSDavid Howells struct key_preparsed_payload; 37cf7f601cSDavid Howells 38f9167789SDavid Howells extern int user_preparse(struct key_preparsed_payload *prep); 39f9167789SDavid Howells extern void user_free_preparse(struct key_preparsed_payload *prep); 40cf7f601cSDavid Howells extern int user_update(struct key *key, struct key_preparsed_payload *prep); 4131204ed9SDavid Howells extern void user_revoke(struct key *key); 422aa349f6SDavid Howells extern void user_destroy(struct key *key); 432aa349f6SDavid Howells extern void user_describe(const struct key *user, struct seq_file *m); 44d3ec10aaSWaiman Long extern long user_read(const struct key *key, char *buffer, size_t buflen); 452aa349f6SDavid Howells user_key_payload_rcu(const struct key * key)460837e49aSDavid Howellsstatic inline const struct user_key_payload *user_key_payload_rcu(const struct key *key) 47146aa8b1SDavid Howells { 480837e49aSDavid Howells return (struct user_key_payload *)dereference_key_rcu(key); 490837e49aSDavid Howells } 500837e49aSDavid Howells user_key_payload_locked(const struct key * key)510837e49aSDavid Howellsstatic inline struct user_key_payload *user_key_payload_locked(const struct key *key) 520837e49aSDavid Howells { 530837e49aSDavid Howells return (struct user_key_payload *)dereference_key_locked((struct key *)key); 54146aa8b1SDavid Howells } 55146aa8b1SDavid Howells 56146aa8b1SDavid Howells #endif /* CONFIG_KEYS */ 572aa349f6SDavid Howells 582aa349f6SDavid Howells #endif /* _KEYS_USER_TYPE_H */ 59