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, string str)
26 list<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 (list<string>::iterator 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);
38 auth_supported.push_back(CEPH_AUTH_UNKNOWN);
39 lderr(cct) << "WARNING: unknown auth protocol defined: " << *iter << dendl;
42 if (auth_supported.empty()) {
43 lderr(cct) << "WARNING: no auth protocol defined, use 'cephx' by default" << dendl;
44 auth_supported.push_back(CEPH_AUTH_CEPHX);
48 bool AuthMethodList::is_supported_auth(int auth_type)
50 return std::find(auth_supported.begin(), auth_supported.end(), auth_type) != auth_supported.end();
53 int AuthMethodList::pick(const std::set<__u32>& supported)
55 for (set<__u32>::const_reverse_iterator p = supported.rbegin(); p != supported.rend(); ++p)
56 if (is_supported_auth(*p))
58 return CEPH_AUTH_UNKNOWN;
61 void AuthMethodList::remove_supported_auth(int auth_type)
63 for (list<__u32>::iterator p = auth_supported.begin(); p != auth_supported.end(); ) {
64 if (*p == (__u32)auth_type)
65 auth_supported.erase(p++);