X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fauth%2FAuthMethodList.cc;fp=src%2Fceph%2Fsrc%2Fauth%2FAuthMethodList.cc;h=9ac1520fad96095d4e8705ab8abccc9152be4e95;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/auth/AuthMethodList.cc b/src/ceph/src/auth/AuthMethodList.cc new file mode 100644 index 0000000..9ac1520 --- /dev/null +++ b/src/ceph/src/auth/AuthMethodList.cc @@ -0,0 +1,69 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2009 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include "common/debug.h" +#include "include/str_list.h" + +#include "AuthMethodList.h" + +const static int dout_subsys = ceph_subsys_auth; + + +AuthMethodList::AuthMethodList(CephContext *cct, string str) +{ + list sup_list; + get_str_list(str, sup_list); + if (sup_list.empty()) { + lderr(cct) << "WARNING: empty auth protocol list" << dendl; + } + for (list::iterator iter = sup_list.begin(); iter != sup_list.end(); ++iter) { + ldout(cct, 5) << "adding auth protocol: " << *iter << dendl; + if (iter->compare("cephx") == 0) { + auth_supported.push_back(CEPH_AUTH_CEPHX); + } else if (iter->compare("none") == 0) { + auth_supported.push_back(CEPH_AUTH_NONE); + } else { + auth_supported.push_back(CEPH_AUTH_UNKNOWN); + lderr(cct) << "WARNING: unknown auth protocol defined: " << *iter << dendl; + } + } + if (auth_supported.empty()) { + lderr(cct) << "WARNING: no auth protocol defined, use 'cephx' by default" << dendl; + auth_supported.push_back(CEPH_AUTH_CEPHX); + } +} + +bool AuthMethodList::is_supported_auth(int auth_type) +{ + return std::find(auth_supported.begin(), auth_supported.end(), auth_type) != auth_supported.end(); +} + +int AuthMethodList::pick(const std::set<__u32>& supported) +{ + for (set<__u32>::const_reverse_iterator p = supported.rbegin(); p != supported.rend(); ++p) + if (is_supported_auth(*p)) + return *p; + return CEPH_AUTH_UNKNOWN; +} + +void AuthMethodList::remove_supported_auth(int auth_type) +{ + for (list<__u32>::iterator p = auth_supported.begin(); p != auth_supported.end(); ) { + if (*p == (__u32)auth_type) + auth_supported.erase(p++); + else + ++p; + } +}