Apache Mesos
auxprop.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __AUTHENTICATION_CRAM_MD5_AUXPROP_HPP__
18 #define __AUTHENTICATION_CRAM_MD5_AUXPROP_HPP__
19 
20 #include <mutex>
21 #include <string>
22 
23 #include <sasl/sasl.h>
24 #include <sasl/saslplug.h>
25 
26 #include <stout/foreach.hpp>
27 #include <stout/multimap.hpp>
28 #include <stout/none.hpp>
29 #include <stout/option.hpp>
30 #include <stout/synchronized.hpp>
31 
32 namespace mesos {
33 namespace internal {
34 namespace cram_md5 {
35 
36 struct Property
37 {
38  std::string name;
39  std::list<std::string> values;
40 };
41 
42 
44 {
45 public:
46  static const char* name() { return "in-memory-auxprop"; }
47 
48  static void load(const Multimap<std::string, Property>& _properties)
49  {
50  synchronized (mutex) {
51  properties = _properties;
52  }
53  }
54 
56  const std::string& user,
57  const std::string& name)
58  {
59  synchronized (mutex) {
60  if (properties.contains(user)) {
61  foreach (const Property& property, properties.get(user)) {
62  if (property.name == name) {
63  return property.values;
64  }
65  }
66  }
67  }
68 
69  return None();
70  }
71 
72  // SASL plugin initialize entry.
73  static int initialize(
74  const sasl_utils_t* utils,
75  int api,
76  int* version,
77  sasl_auxprop_plug_t** plug,
78  const char* name);
79 
80 private:
81 #if SASL_AUXPROP_PLUG_VERSION <= 4
82  static void lookup(
83 #else
84  static int lookup(
85 #endif
86  void* context,
87  sasl_server_params_t* sparams,
88  unsigned flags,
89  const char* user,
90  unsigned length);
91 
92  // TODO(tillt): For allowing multiple authenticators with differing
93  // credentials, consider using a non-static credential properties.
94  static Multimap<std::string, Property> properties;
95 
96  static sasl_auxprop_plug_t plugin;
97 
98  // Access to 'properties' has to be protected as multiple
99  // authenticator instances may be active concurrently.
100  static std::mutex mutex;
101 };
102 
103 } // namespace cram_md5 {
104 } // namespace internal {
105 } // namespace mesos {
106 
107 #endif // __AUTHENTICATION_CRAM_MD5_AUXPROP_HPP__
Definition: option.hpp:28
static Option< std::list< std::string > > lookup(const std::string &user, const std::string &name)
Definition: auxprop.hpp:55
Result< std::string > user(Option< uid_t > uid=None())
Definition: su.hpp:277
JSON::Object version()
Definition: version.hpp:32
std::list< std::string > values
Definition: auxprop.hpp:39
Definition: auxprop.hpp:36
static void load(const Multimap< std::string, Property > &_properties)
Definition: auxprop.hpp:48
std::string name
Definition: auxprop.hpp:38
static int initialize(const sasl_utils_t *utils, int api, int *version, sasl_auxprop_plug_t **plug, const char *name)
Definition: multimap.hpp:30
static const char * name()
Definition: auxprop.hpp:46
#define flags
Definition: decoder.hpp:18
Definition: none.hpp:27