]> git.proxmox.com Git - ceph.git/blob - ceph/src/auth/AuthMethodList.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / auth / AuthMethodList.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
7 *
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.
12 *
13 */
14
15 #include <algorithm>
16 #include "common/debug.h"
17 #include "include/str_list.h"
18
19 #include "AuthMethodList.h"
20
21 const static int dout_subsys = ceph_subsys_auth;
22
23
24 AuthMethodList::AuthMethodList(CephContext *cct, std::string str)
25 {
26 std::list<std::string> sup_list;
27 get_str_list(str, sup_list);
28 if (sup_list.empty()) {
29 lderr(cct) << "WARNING: empty auth protocol list" << dendl;
30 }
31 for (auto iter = sup_list.begin(); iter != sup_list.end(); ++iter) {
32 ldout(cct, 5) << "adding auth protocol: " << *iter << dendl;
33 if (iter->compare("cephx") == 0) {
34 auth_supported.push_back(CEPH_AUTH_CEPHX);
35 } else if (iter->compare("none") == 0) {
36 auth_supported.push_back(CEPH_AUTH_NONE);
37 } else if (iter->compare("gss") == 0) {
38 auth_supported.push_back(CEPH_AUTH_GSS);
39 } else {
40 auth_supported.push_back(CEPH_AUTH_UNKNOWN);
41 lderr(cct) << "WARNING: unknown auth protocol defined: " << *iter << dendl;
42 }
43 }
44 if (auth_supported.empty()) {
45 lderr(cct) << "WARNING: no auth protocol defined, use 'cephx' by default" << dendl;
46 auth_supported.push_back(CEPH_AUTH_CEPHX);
47 }
48 }
49
50 bool AuthMethodList::is_supported_auth(int auth_type)
51 {
52 return std::find(auth_supported.begin(), auth_supported.end(), auth_type) != auth_supported.end();
53 }
54
55 int AuthMethodList::pick(const std::set<__u32>& supported)
56 {
57 for (auto p = supported.rbegin(); p != supported.rend(); ++p)
58 if (is_supported_auth(*p))
59 return *p;
60 return CEPH_AUTH_UNKNOWN;
61 }
62
63 void AuthMethodList::remove_supported_auth(int auth_type)
64 {
65 for (auto p = auth_supported.begin(); p != auth_supported.end(); ) {
66 if (*p == (__u32)auth_type)
67 auth_supported.erase(p++);
68 else
69 ++p;
70 }
71 }