Commit 1a5304df authored by Casualet's avatar Casualet

do not install /use/lib

parent 14ac33fc
...@@ -17,10 +17,10 @@ $(OBJDIR)/libedbcrypto.a: $(CRYPTOOBJ) ...@@ -17,10 +17,10 @@ $(OBJDIR)/libedbcrypto.a: $(CRYPTOOBJ)
$(OBJDIR)/crypto/x: $(OBJDIR)/crypto/x.o $(OBJDIR)/libedbcrypto.so $(OBJDIR)/crypto/x: $(OBJDIR)/crypto/x.o $(OBJDIR)/libedbcrypto.so
$(CXX) $< -o $@ $(LDFLAGS) $(LDRPATH) -ledbcrypto $(CXX) $< -o $@ $(LDFLAGS) $(LDRPATH) -ledbcrypto
install: install_crypto #install: install_crypto
.PHONY: install_crypto #.PHONY: install_crypto
install_crypto: $(OBJDIR)/libedbcrypto.so #install_crypto: $(OBJDIR)/libedbcrypto.so
install -m 644 $(OBJDIR)/libedbcrypto.so /usr/lib # install -m 644 $(OBJDIR)/libedbcrypto.so /usr/lib
# vim: set noexpandtab: # vim: set noexpandtab:
...@@ -30,10 +30,12 @@ $(OBJDIR)/libcryptdb.so: $(CRYPTDB_OBJS) \ ...@@ -30,10 +30,12 @@ $(OBJDIR)/libcryptdb.so: $(CRYPTDB_OBJS) \
$(CXX) -shared -g -o $@ $(CRYPTDB_OBJS) $(LDFLAGS) $(LDRPATH) \ $(CXX) -shared -g -o $@ $(CRYPTDB_OBJS) $(LDFLAGS) $(LDRPATH) \
-ledbcrypto -ledbutil -ledbparser -lntl -lcrypto -ledbcrypto -ledbutil -ledbparser -lntl -lcrypto
install: install_main
.PHONY: install_main
install_main: $(OBJDIR)/libcryptdb.so #install: install_main
install -m 644 $(OBJDIR)/libcryptdb.so /usr/lib
#.PHONY: install_main
#install_main: $(OBJDIR)/libcryptdb.so
# install -m 644 $(OBJDIR)/libcryptdb.so /usr/lib
# vim: set noexpandtab: # vim: set noexpandtab:
...@@ -8,20 +8,27 @@ ...@@ -8,20 +8,27 @@
#include <main/serializers.hh> #include <main/serializers.hh>
// FIXME: Maybe should inherit from DBObject. // FIXME: Maybe should inherit from DBObject.(but it do not need an id??)
/*provide static factory for get a key type*/
class AbstractMetaKey : public NormalAlloc { class AbstractMetaKey : public NormalAlloc {
public: public:
AbstractMetaKey() {;} AbstractMetaKey() {;}
virtual ~AbstractMetaKey() {;} virtual ~AbstractMetaKey() {;}
virtual std::string getSerial() const = 0; virtual std::string getSerial() const = 0;
/* used in mappedDBmeta: factory<KeyType> */
template <typename ConcreteKey> template <typename ConcreteKey>
static ConcreteKey *factory(std::string serial) { static ConcreteKey *factory(std::string serial) {
/*dummy is not used!!*/
int dummy = 1; int dummy = 1;
return new ConcreteKey(dummy, serial); return new ConcreteKey(dummy, serial);
} }
}; };
//we have onionMetaKey,UIntMetaKey and IdentityMetaKey for metadata hierachy /*
*we have onionMetaKey,UIntMetaKey and IdentityMetaKey for metadata hierachy
*meta key provides KeyType and Serial
*/
template <typename KeyType> template <typename KeyType>
class MetaKey : public AbstractMetaKey { class MetaKey : public AbstractMetaKey {
const KeyType key_data; const KeyType key_data;
...@@ -36,6 +43,7 @@ public: ...@@ -36,6 +43,7 @@ public:
// Build MetaKey from 'actual' key value. // Build MetaKey from 'actual' key value.
MetaKey(KeyType key_data) {;} MetaKey(KeyType key_data) {;}
virtual ~MetaKey() = 0; virtual ~MetaKey() = 0;
/*key can be inserted into a map, so it must support those operations*/
bool operator <(const MetaKey<KeyType> &rhs) const; bool operator <(const MetaKey<KeyType> &rhs) const;
bool operator ==(const MetaKey<KeyType> &rhs) const; bool operator ==(const MetaKey<KeyType> &rhs) const;
...@@ -46,6 +54,10 @@ public: ...@@ -46,6 +54,10 @@ public:
template <typename KeyType> template <typename KeyType>
MetaKey<KeyType>::~MetaKey() {;} MetaKey<KeyType>::~MetaKey() {;}
/*
*this is metakey<string>
*/
class IdentityMetaKey : public MetaKey<std::string> { class IdentityMetaKey : public MetaKey<std::string> {
public: public:
IdentityMetaKey(std::string key_data) IdentityMetaKey(std::string key_data)
...@@ -66,6 +78,9 @@ private: ...@@ -66,6 +78,9 @@ private:
} }
}; };
/*
*this is metakey<onion>
*/
class OnionMetaKey : public MetaKey<onion> { class OnionMetaKey : public MetaKey<onion> {
public: public:
OnionMetaKey(onion key_data) OnionMetaKey(onion key_data)
...@@ -86,6 +101,10 @@ private: ...@@ -86,6 +101,10 @@ private:
} }
}; };
/*
*this is metakey<int>,and it should be noted that onion is different from int, althogh it can be converted
*/
class UIntMetaKey : public MetaKey<unsigned int> { class UIntMetaKey : public MetaKey<unsigned int> {
public: public:
UIntMetaKey(unsigned int key_data) UIntMetaKey(unsigned int key_data)
...@@ -95,13 +114,11 @@ public: ...@@ -95,13 +114,11 @@ public:
~UIntMetaKey() {;} ~UIntMetaKey() {;}
private: private:
virtual std::string serialize(unsigned int i) virtual std::string serialize(unsigned int i){
{
return serialize_string(std::to_string(i)); return serialize_string(std::to_string(i));
} }
virtual unsigned int unserialize(std::string s) virtual unsigned int unserialize(std::string s){
{
return serial_to_uint(s); return serial_to_uint(s);
} }
}; };
...@@ -122,14 +139,11 @@ public: ...@@ -122,14 +139,11 @@ public:
explicit DBObject(unsigned int id) : id(id) {} explicit DBObject(unsigned int id) : id(id) {}
virtual ~DBObject() {;} virtual ~DBObject() {;}
unsigned int getDatabaseID() const {return id;} unsigned int getDatabaseID() const {return id;}
// FIXME: This should possibly be a part of DBMeta.
// > Parent will definitely be DBMeta.
// > Parent-Child semantics aren't really added until DBMeta.
}; };
class Connect; class Connect;
/* /*
* DBMeta is also a design choice about how we use Deltas. * DBMeta is also a design choice about how we use Deltas.
* i) Read SchemaInfo from database, read Deltaz from database then * i) Read SchemaInfo from database, read Deltaz from database then
...@@ -143,6 +157,7 @@ class Connect; ...@@ -143,6 +157,7 @@ class Connect;
* read SchemaInfo from database. * read SchemaInfo from database.
* > Logic is in SQL. * > Logic is in SQL.
*/ */
class DBMeta : public DBObject, public NormalAlloc { class DBMeta : public DBObject, public NormalAlloc {
public: public:
DBMeta() {} DBMeta() {}
...@@ -159,6 +174,7 @@ public: ...@@ -159,6 +174,7 @@ public:
applyToChildren(std::function<bool(const DBMeta &)>) const = 0; applyToChildren(std::function<bool(const DBMeta &)>) const = 0;
/*traverse the map to get the key for the conresponding child(reference MappedDBMeta)*/ /*traverse the map to get the key for the conresponding child(reference MappedDBMeta)*/
virtual AbstractMetaKey const &getKey(const DBMeta &child) const = 0; virtual AbstractMetaKey const &getKey(const DBMeta &child) const = 0;
/*each item in the meta hierachy should be able to serialize,like tablemeta,databasemeta,onionmeta,enclayers*/
virtual std::string serialize(const DBObject &parent) const = 0; virtual std::string serialize(const DBObject &parent) const = 0;
protected: protected:
std::vector<DBMeta*> std::vector<DBMeta*>
...@@ -169,23 +185,26 @@ protected: ...@@ -169,23 +185,26 @@ protected:
deserialHandler); deserialHandler);
}; };
class LeafDBMeta : public DBMeta { class LeafDBMeta : public DBMeta {
public: public:
LeafDBMeta() {} LeafDBMeta() {}
LeafDBMeta(unsigned int id) : DBMeta(id) {} LeafDBMeta(unsigned int id) : DBMeta(id) {}
/*from DBmeta*/
std::vector<DBMeta *> std::vector<DBMeta *>
fetchChildren(const std::unique_ptr<Connect> &e_conn) { fetchChildren(const std::unique_ptr<Connect> &e_conn) {
return std::vector<DBMeta *>(); return std::vector<DBMeta *>();
} }
/*from DBmeta*/
bool applyToChildren(std::function<bool(const DBMeta &)> bool applyToChildren(std::function<bool(const DBMeta &)>
fn) const { fn) const {
return true; return true;
} }
/*if this is an abstract function, then enclayers can be acstract classes, which is not correct*/
AbstractMetaKey const &getKey(const DBMeta &child) const { AbstractMetaKey const &getKey(const DBMeta &child) const {
// FIXME:
assert(false); assert(false);
} }
}; };
...@@ -215,17 +234,19 @@ public: ...@@ -215,17 +234,19 @@ public:
virtual std::vector<DBMeta *> virtual std::vector<DBMeta *>
fetchChildren(const std::unique_ptr<Connect> &e_conn); fetchChildren(const std::unique_ptr<Connect> &e_conn);
/*what if we remove this declaration?*/
/*inherited from DBMeta*/
bool applyToChildren(std::function<bool(const DBMeta &)> fn) const; bool applyToChildren(std::function<bool(const DBMeta &)> fn) const;
const std::map<KeyType, std::unique_ptr<ChildType> > & const std::map<KeyType, std::unique_ptr<ChildType> > &
getChildren() const { getChildren() const {
return children; return children;
} }
/*when is this used???*/
virtual const ChildType * virtual const ChildType *
getChildWithGChild(const DBMeta &gchild) const; getChildWithGChild(const DBMeta &gchild) const;
private: private:
/*store the hirechy of metadata as a map. For example, each database has sever tables, /*store the hirechy of metadata as a map. For example, each database has sever tables,
*then in the databasemeta stores a map of tables. The keys are of type string(metakey), *then in the databasemeta stores a map of tables. The keys are of type string(metakey),
*and the values are of type DBMeta. *and the values are of type DBMeta.
...@@ -244,20 +265,17 @@ bool MetaKey<KeyType>::operator <(const MetaKey<KeyType> &rhs) const ...@@ -244,20 +265,17 @@ bool MetaKey<KeyType>::operator <(const MetaKey<KeyType> &rhs) const
} }
template <typename KeyType> template <typename KeyType>
bool MetaKey<KeyType>::operator ==(const MetaKey<KeyType> &rhs) const bool MetaKey<KeyType>::operator ==(const MetaKey<KeyType> &rhs) const{
{
return key_data == rhs.key_data; return key_data == rhs.key_data;
} }
template <typename ChildType, typename KeyType> template <typename ChildType, typename KeyType>
bool bool
MappedDBMeta<ChildType, KeyType>::addChild(KeyType key, MappedDBMeta<ChildType, KeyType>::addChild(KeyType key,
std::unique_ptr<ChildType> meta) std::unique_ptr<ChildType> meta){
{
if (childExists(key)) { if (childExists(key)) {
return false; return false;
} }
children[key] = std::move(meta); children[key] = std::move(meta);
return true; return true;
} }
...@@ -287,8 +305,7 @@ MappedDBMeta<ChildType, KeyType>::getChild(const KeyType &key) const ...@@ -287,8 +305,7 @@ MappedDBMeta<ChildType, KeyType>::getChild(const KeyType &key) const
// NOTE: Slow. // NOTE: Slow.
template <typename ChildType, typename KeyType> template <typename ChildType, typename KeyType>
KeyType const & KeyType const &
MappedDBMeta<ChildType, KeyType>::getKey(const DBMeta &child) const MappedDBMeta<ChildType, KeyType>::getKey(const DBMeta &child) const{
{
for (const auto &it : children) { for (const auto &it : children) {
if (it.second.get() == &child) { if (it.second.get() == &child) {
return it.first; return it.first;
...@@ -299,12 +316,10 @@ MappedDBMeta<ChildType, KeyType>::getKey(const DBMeta &child) const ...@@ -299,12 +316,10 @@ MappedDBMeta<ChildType, KeyType>::getKey(const DBMeta &child) const
template <typename ChildType, typename KeyType> template <typename ChildType, typename KeyType>
std::vector<DBMeta *> std::vector<DBMeta *>
MappedDBMeta<ChildType, KeyType>::fetchChildren(const std::unique_ptr<Connect> &e_conn) MappedDBMeta<ChildType, KeyType>::fetchChildren(const std::unique_ptr<Connect> &e_conn){
{
// Perhaps it's conceptually cleaner to have this lambda return // Perhaps it's conceptually cleaner to have this lambda return
// pairs of keys and children and then add the children from local // pairs of keys and children and then add the children from local
// scope. // scope.
std::function<DBMeta *(const std::string &, std::function<DBMeta *(const std::string &,
const std::string &, const std::string &,
const std::string &)> const std::string &)>
...@@ -330,8 +345,7 @@ MappedDBMeta<ChildType, KeyType>::fetchChildren(const std::unique_ptr<Connect> & ...@@ -330,8 +345,7 @@ MappedDBMeta<ChildType, KeyType>::fetchChildren(const std::unique_ptr<Connect> &
template <typename ChildType, typename KeyType> template <typename ChildType, typename KeyType>
bool bool
MappedDBMeta<ChildType, KeyType>::applyToChildren( MappedDBMeta<ChildType, KeyType>::applyToChildren(
std::function<bool(const DBMeta &)> fn) const std::function<bool(const DBMeta &)> fn) const{
{
for (const auto &it : children) { for (const auto &it : children) {
if (false == fn(*it.second.get())) { if (false == fn(*it.second.get())) {
return false; return false;
...@@ -341,12 +355,12 @@ MappedDBMeta<ChildType, KeyType>::applyToChildren( ...@@ -341,12 +355,12 @@ MappedDBMeta<ChildType, KeyType>::applyToChildren(
return true; return true;
} }
template <typename ChildType, typename KeyType> template <typename ChildType, typename KeyType>
const ChildType *MappedDBMeta<ChildType, KeyType>:: const ChildType *MappedDBMeta<ChildType, KeyType>::
getChildWithGChild(const DBMeta &gchild) const getChildWithGChild(const DBMeta &gchild) const{
{
bool match = false; bool match = false;
for (const auto &it : this->getChildren()) { for (const auto &it : this->getChildren()){
std::function<bool(const DBMeta &)> misGet = std::function<bool(const DBMeta &)> misGet =
[&it, &gchild, &match] (const DBMeta &possible_match) { [&it, &gchild, &match] (const DBMeta &possible_match) {
if (&possible_match == &gchild) { if (&possible_match == &gchild) {
...@@ -364,3 +378,5 @@ getChildWithGChild(const DBMeta &gchild) const ...@@ -364,3 +378,5 @@ getChildWithGChild(const DBMeta &gchild) const
} }
return nullptr; return nullptr;
} }
...@@ -13,20 +13,27 @@ ...@@ -13,20 +13,27 @@
#include <main/macro_util.hh> #include <main/macro_util.hh>
//对于schemaInfo而言, 先获得自己的id, 作为parent, 可以查找底下的databasemeta的serial,key以及id //对于schemaInfo而言, 先获得自己的id, 作为parent, 可以查找底下的databasemeta的serial,key以及id
//然后通过lambda表达式,先把databasemeta加入到schemainfo的map中, 然后返回这个databasemeta供后续使用. //然后通过lambda表达式,先把databasemeta加入到schemainfo的map中, 然后返回这写个databasemeta供后续使用.
/*
*for example, we have schemaInfo, then in this function, it first fetch it's own id, and use it as parent
*to fetch its children, the databasemeta. Then it adds those databasemeta as KV in the map, and return those
*databasemeta as a vector for recursive processing.
for this function, it only extract the dbmeta and
*/
std::vector<DBMeta *> std::vector<DBMeta *>
DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn, DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn,
std::function<DBMeta *(const std::string &, std::function<DBMeta *(const std::string &,
const std::string &, const std::string &,
const std::string &)> const std::string &)>
deserialHandler) deserialHandler) {
{
const std::string table_name = MetaData::Table::metaObject(); const std::string table_name = MetaData::Table::metaObject();
// Now that we know the table exists, SELECT the data we want. // Now that we know the table exists, SELECT the data we want.
std::vector<DBMeta *> out_vec; std::vector<DBMeta *> out_vec;
std::unique_ptr<DBResult> db_res; std::unique_ptr<DBResult> db_res;
//这个id来自于dbobject. //this is the id of the current class.
const std::string parent_id = std::to_string(this->getDatabaseID()); const std::string parent_id = std::to_string(this->getDatabaseID());
const std::string serials_query = const std::string serials_query =
" SELECT " + table_name + ".serial_object," " SELECT " + table_name + ".serial_object,"
...@@ -42,16 +49,13 @@ DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn, ...@@ -42,16 +49,13 @@ DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn,
while ((row = mysql_fetch_row(db_res->n))) { while ((row = mysql_fetch_row(db_res->n))) {
unsigned long * const l = mysql_fetch_lengths(db_res->n); unsigned long * const l = mysql_fetch_lengths(db_res->n);
assert(l != NULL); assert(l != NULL);
const std::string child_serial_object(row[0], l[0]); const std::string child_serial_object(row[0], l[0]);
const std::string child_key(row[1], l[1]); const std::string child_key(row[1], l[1]);
const std::string child_id(row[2], l[2]); const std::string child_id(row[2], l[2]);
DBMeta *const new_old_meta = DBMeta *const new_old_meta =
deserialHandler(child_key, child_serial_object, child_id); deserialHandler(child_key, child_serial_object, child_id);
out_vec.push_back(new_old_meta); out_vec.push_back(new_old_meta);
} }
return out_vec; return out_vec;
} }
......
...@@ -30,11 +30,9 @@ ...@@ -30,11 +30,9 @@
*/ */
class OnionMeta : public DBMeta { class OnionMeta : public DBMeta {
public: public:
// New.
OnionMeta(onion o, std::vector<SECLEVEL> levels, OnionMeta(onion o, std::vector<SECLEVEL> levels,
const AES_KEY * const m_key, const Create_field &cf, const AES_KEY * const m_key, const Create_field &cf,
unsigned long uniq_count, SECLEVEL minimum_seclevel); unsigned long uniq_count, SECLEVEL minimum_seclevel);
// Restore. // Restore.
static std::unique_ptr<OnionMeta> static std::unique_ptr<OnionMeta>
deserialize(unsigned int id, const std::string &serial); deserialize(unsigned int id, const std::string &serial);
...@@ -49,7 +47,9 @@ public: ...@@ -49,7 +47,9 @@ public:
std::vector<DBMeta *> std::vector<DBMeta *>
fetchChildren(const std::unique_ptr<Connect> &e_conn); fetchChildren(const std::unique_ptr<Connect> &e_conn);
bool applyToChildren(std::function<bool(const DBMeta &)>) const; bool applyToChildren(std::function<bool(const DBMeta &)>) const;
UIntMetaKey const &getKey(const DBMeta &child) const; UIntMetaKey const &getKey(const DBMeta &child) const;
EncLayer *getLayerBack() const; EncLayer *getLayerBack() const;
EncLayer *getLayer(const SECLEVEL &sl) const; EncLayer *getLayer(const SECLEVEL &sl) const;
bool hasEncLayer(const SECLEVEL &sl) const; bool hasEncLayer(const SECLEVEL &sl) const;
...@@ -67,6 +67,7 @@ private: ...@@ -67,6 +67,7 @@ private:
const std::string onionname; const std::string onionname;
const unsigned long uniq_count; const unsigned long uniq_count;
SECLEVEL minimum_seclevel; SECLEVEL minimum_seclevel;
/*what are those keys used for?*/
mutable std::list<std::unique_ptr<UIntMetaKey>> generated_keys; mutable std::list<std::unique_ptr<UIntMetaKey>> generated_keys;
}; };
......
cur=$(pwd)
export LD_LIBRARY_PATH=${cur}/obj
...@@ -9,11 +9,11 @@ $(OBJDIR)/libedbutil.so: $(patsubst %.cc,$(OBJDIR)/util/%.o,$(UTILSRC)) ...@@ -9,11 +9,11 @@ $(OBJDIR)/libedbutil.so: $(patsubst %.cc,$(OBJDIR)/util/%.o,$(UTILSRC))
$(OBJDIR)/libedbutil.a: $(patsubst %.cc,$(OBJDIR)/util/%.o,$(UTILSRC)) $(OBJDIR)/libedbutil.a: $(patsubst %.cc,$(OBJDIR)/util/%.o,$(UTILSRC))
$(AR) r $@ $^ $(AR) r $@ $^
install: install_util #install: install_util
.PHONY: install_util #.PHONY: install_util
install_util: $(OBJDIR)/libedbutil.so #install_util: $(OBJDIR)/libedbutil.so
install -m 644 $(OBJDIR)/libedbutil.so /usr/lib # install -m 644 $(OBJDIR)/libedbutil.so /usr/lib
$(OBJDIR)/util/version.cc: always $(OBJDIR)/util/version.cc: always
@mkdir -p $(@D) @mkdir -p $(@D)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment