]>
git.proxmox.com Git - ceph.git/blob - ceph/src/auth/KeyRing.h
ed15af4eccec3f85d23f2087bdfd5c1210ccf575
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_KEYRING_H
16 #define CEPH_KEYRING_H
18 #include "auth/Auth.h"
19 #include "include/common_fwd.h"
21 class KeyRing
: public KeyStore
{
22 std::map
<EntityName
, EntityAuth
> keys
;
24 int set_modifier(const char *type
, const char *val
, EntityName
& name
, std::map
<std::string
, ceph::buffer::list
>& caps
);
26 void decode_plaintext(ceph::buffer::list::const_iterator
& bl
);
27 /* Create a KeyRing from a Ceph context.
28 * We will use the configuration stored inside the context. */
29 int from_ceph_context(CephContext
*cct
);
31 std::map
<EntityName
, EntityAuth
>& get_keys() { return keys
; } // yuck
33 int load(CephContext
*cct
, const std::string
&filename
);
34 void print(std::ostream
& out
);
37 bool exists(const EntityName
& name
) const {
38 auto p
= keys
.find(name
);
39 return p
!= keys
.end();
41 bool get_auth(const EntityName
& name
, EntityAuth
&a
) const {
42 std::map
<EntityName
, EntityAuth
>::const_iterator k
= keys
.find(name
);
48 bool get_secret(const EntityName
& name
, CryptoKey
& secret
) const override
{
49 std::map
<EntityName
, EntityAuth
>::const_iterator k
= keys
.find(name
);
52 secret
= k
->second
.key
;
55 bool get_service_secret(uint32_t service_id
, uint64_t secret_id
,
56 CryptoKey
& secret
) const override
{
59 bool get_caps(const EntityName
& name
,
60 const std::string
& type
, AuthCapsInfo
& caps
) const {
61 std::map
<EntityName
, EntityAuth
>::const_iterator k
= keys
.find(name
);
64 std::map
<std::string
,ceph::buffer::list
>::const_iterator i
= k
->second
.caps
.find(type
);
65 if (i
!= k
->second
.caps
.end()) {
66 caps
.caps
= i
->second
;
75 void add(const EntityName
& name
, EntityAuth
&a
) {
78 void add(const EntityName
& name
, CryptoKey
&k
) {
83 void remove(const EntityName
& name
) {
86 void set_caps(EntityName
& name
, std::map
<std::string
, ceph::buffer::list
>& caps
) {
87 keys
[name
].caps
= caps
;
89 void set_key(EntityName
& ename
, CryptoKey
& key
) {
90 keys
[ename
].key
= key
;
92 void import(CephContext
*cct
, KeyRing
& other
);
94 // decode as plaintext
95 void decode(ceph::buffer::list::const_iterator
& bl
);
97 void encode_plaintext(ceph::buffer::list
& bl
);
98 void encode_formatted(std::string label
, ceph::Formatter
*f
, ceph::buffer::list
& bl
);
101 // don't use WRITE_CLASS_ENCODER macro because we don't have an encode
102 // macro. don't juse encode_plaintext in that case because it is not
103 // wrappable; it assumes it gets the entire ceph::buffer::list.
104 static inline void decode(KeyRing
& kr
, ceph::buffer::list::const_iterator
& p
) {