]>
git.proxmox.com Git - ceph.git/blob - 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
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.
16 #include "common/debug.h"
17 #include "include/str_list.h"
19 #include "AuthMethodList.h"
21 const static int dout_subsys
= ceph_subsys_auth
;
24 AuthMethodList::AuthMethodList(CephContext
*cct
, std::string str
)
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
;
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
);
40 auth_supported
.push_back(CEPH_AUTH_UNKNOWN
);
41 lderr(cct
) << "WARNING: unknown auth protocol defined: " << *iter
<< dendl
;
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
);
50 bool AuthMethodList::is_supported_auth(int auth_type
)
52 return std::find(auth_supported
.begin(), auth_supported
.end(), auth_type
) != auth_supported
.end();
55 int AuthMethodList::pick(const std::set
<__u32
>& supported
)
57 for (auto p
= supported
.rbegin(); p
!= supported
.rend(); ++p
)
58 if (is_supported_auth(*p
))
60 return CEPH_AUTH_UNKNOWN
;
63 void AuthMethodList::remove_supported_auth(int auth_type
)
65 for (auto p
= auth_supported
.begin(); p
!= auth_supported
.end(); ) {
66 if (*p
== (__u32
)auth_type
)
67 auth_supported
.erase(p
++);