std::string binddn;
std::string searchdn;
std::string memberattr;
- LDAP *ldap, *tldap;
+ LDAP *ldap;
public:
LDAPHelper(std::string _uri, std::string _binddn, std::string _searchdn,
int init() {
int ret;
ret = ldap_initialize(&ldap, uri.c_str());
- return ret;
+ return (ret == LDAP_SUCCESS) ? ret : -EINVAL;
}
int bind() {
- return ldap_simple_bind_s(ldap, nullptr, nullptr);
+ int ret;
+ ret = ldap_simple_bind_s(ldap, nullptr, nullptr);
+ return (ret == LDAP_SUCCESS) ? ret : -EINVAL;
}
int simple_bind(const char *dn, const std::string& pwd) {
+ LDAP* tldap;
int ret = ldap_initialize(&tldap, uri.c_str());
ret = ldap_simple_bind_s(tldap, dn, pwd.c_str());
if (ret == LDAP_SUCCESS) {
ldap_unbind(tldap);
- return 0;
}
- return -1;
+ return ret; // OpenLDAP client error space
}
int auth(const std::string uid, const std::string pwd) {
if (ret == LDAP_SUCCESS) {
entry = ldap_first_entry(ldap, answer);
char *dn = ldap_get_dn(ldap, entry);
- //std::cout << dn << std::endl;
ret = simple_bind(dn, pwd);
ldap_memfree(dn);
ldap_msgfree(answer);
}
- return ret;
+ return (ret == LDAP_SUCCESS) ? ret : -EACCES;
}
~LDAPHelper() {
void usage()
{
- cout << "usage: radosgw-token [options...]" << std::endl;
- cout << "\t(maybe exporting RGW_ACCESS_KEY_ID and RGW_SECRET_ACCESS_KEY)"
+ cout << "usage: radosgw-token --encode --ttype=<token type> [options...]" << std::endl;
+ cout << "\t(maybe exporting RGW_ACCESS_KEY_ID and RGW_SECRET_ACCESS_KEY)"
<< std::endl;
+ cout << "\t <token type> := ad | ldap" << std::endl;
cout << "\n";
generic_client_usage();
}
void encode(bufferlist& bl) const {
uint32_t ver = version();
string typestr{from_type(type)};
+ ENCODE_START(1, 1, bl);
::encode(type_name, bl);
::encode(ver, bl);
::encode(typestr, bl);
::encode(id, bl);
::encode(key, bl);
+ ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
string name;
string typestr;
uint32_t version;
+ DECODE_START(1, bl);
::decode(name, bl);
::decode(version, bl);
::decode(typestr, bl);
type = to_type(typestr.c_str());
::decode(id, bl);
::decode(key, bl);
+ DECODE_FINISH(bl);
}
void dump(Formatter* f) const {