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-2006 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.
19 #include "include/types.h"
20 #include "include/rados/librados.hpp"
22 using namespace librados;
24 void buf_to_hex(const unsigned char *buf, int len, char *str)
27 for (int i = 0; i < len; i++) {
28 sprintf(&str[i*2], "%02x", (int)buf[i]);
41 void encode(bufferlist& bl) const {
42 bl.append((const char *)id, ID_SIZE);
44 void decode(bufferlist::iterator& iter) {
45 iter.copy(ID_SIZE, (char *)id);
48 WRITE_CLASS_ENCODER(ACLID)
50 typedef __u32 ACLFlags;
53 inline bool operator<(const ACLID& l, const ACLID& r)
55 return (memcmp(&l, &r, ID_SIZE) < 0);
64 map<ACLID, ACLFlags> acls_map;
68 void encode(bufferlist& bl) const {
69 ::encode(acls_map, bl);
71 void decode(bufferlist::iterator& bl) {
72 ::decode(acls_map, bl);
75 int read_acl(ACLID& id, ACLFlags *flags);
76 void set_acl(ACLID& id, ACLFlags flags);
78 WRITE_CLASS_ENCODER(ObjectACLs)
80 int ObjectACLs::read_acl(ACLID& id, ACLFlags *flags)
85 map<ACLID, ACLFlags>::iterator iter = acls_map.find(id);
87 if (iter == acls_map.end())
90 *flags = iter->second;
95 void ObjectACLs::set_acl(ACLID& id, ACLFlags flags)
105 map<ACLID, ACLEntity> groups;
108 typedef map<ACLID, ACLEntity> tACLIDEntityMap;
110 static map<ACLID, ACLEntity> users;
111 static map<ACLID, ACLEntity> groups;
113 void get_user(ACLID& aclid, ACLEntity *entity)
122 int main(int argc, const char **argv)
125 if (rados.init(NULL) < 0) {
126 cerr << "couldn't initialize rados!" << std::endl;
129 if (rados.conf_read_file(NULL)) {
130 cerr << "couldn't read Ceph configuration file!" << std::endl;
133 if (rados.connect() < 0) {
134 cerr << "couldn't connect to cluster!" << std::endl;
143 snprintf(buf, 128, "%s", ctime(&tm));
144 bl.append(buf, strlen(buf));
146 const char *oid = "bar";
149 int r = rados.ioctx_create("data", io_ctx);
150 cout << "open io_ctx result = " << r << " pool = " << io_ctx.get_pool_name() << std::endl;
154 snprintf(id.id, sizeof(id.id), "%.8x", 0x1234);
155 cout << "id=" << id.id << std::endl;
157 r = io_ctx.exec(oid, "acl", "get", bl, bl2);
158 cout << "exec(acl get) returned " << r
159 << " len=" << bl2.length() << std::endl;
162 bufferlist::iterator iter = bl2.begin();
166 oa.set_acl(id, ACL_RD);
169 r = io_ctx.exec(oid, "acl", "set", bl, bl2);
170 cout << "exec(acl set) returned " << r
171 << " len=" << bl2.length() << std::endl;
173 const unsigned char *md5 = (const unsigned char *)bl2.c_str();
174 char md5_str[bl2.length()*2 + 1];
175 buf_to_hex(md5, bl2.length(), md5_str);
176 cout << "md5 result=" << md5_str << std::endl;
178 int size = io_ctx.read(oid, bl2, 128, 0);
179 cout << "read result=" << bl2.c_str() << std::endl;
180 cout << "size=" << size << std::endl;