]>
git.proxmox.com Git - ceph.git/blob - ceph/src/auth/KeyRing.h
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"
22 class KeyRing
: public KeyStore
{
23 map
<EntityName
, EntityAuth
> keys
;
25 int set_modifier(const char *type
, const char *val
, EntityName
& name
, map
<string
, bufferlist
>& caps
);
27 void decode_plaintext(bufferlist::iterator
& bl
);
28 /* Create a KeyRing from a Ceph context.
29 * We will use the configuration stored inside the context. */
30 int from_ceph_context(CephContext
*cct
);
32 /* Create an empty KeyRing */
33 static KeyRing
*create_empty();
35 map
<EntityName
, EntityAuth
>& get_keys() { return keys
; } // yuck
37 int load(CephContext
*cct
, const std::string
&filename
);
38 void print(ostream
& out
);
41 bool get_auth(const EntityName
& name
, EntityAuth
&a
) const {
42 map
<EntityName
, EntityAuth
>::const_iterator k
= keys
.find(name
);
48 bool get_secret(const EntityName
& name
, CryptoKey
& secret
) const override
{
49 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 map
<EntityName
, EntityAuth
>::const_iterator k
= keys
.find(name
);
64 map
<string
,bufferlist
>::const_iterator i
= k
->second
.caps
.find(type
);
65 if (i
!= k
->second
.caps
.end()) {
66 caps
.caps
= i
->second
;
72 void add(const EntityName
& name
, EntityAuth
&a
) {
75 void add(const EntityName
& name
, CryptoKey
&k
) {
80 void remove(const EntityName
& name
) {
83 void set_caps(EntityName
& name
, map
<string
, bufferlist
>& caps
) {
84 keys
[name
].caps
= caps
;
86 void set_uid(EntityName
& ename
, uint64_t auid
) {
87 keys
[ename
].auid
= auid
;
89 void set_key(EntityName
& ename
, CryptoKey
& key
) {
90 keys
[ename
].key
= key
;
92 void import(CephContext
*cct
, KeyRing
& other
);
95 void decode(bufferlist::iterator
& bl
);
97 void encode_plaintext(bufferlist
& bl
);
98 void encode_formatted(string label
, Formatter
*f
, bufferlist
& 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 bufferlist.
104 static inline void decode(KeyRing
& kr
, bufferlist::iterator
& p
) {