[Gluster-devel] [PATCH BUG:393 03/10] transport/encryption: add rot-13 demo

Corentin Chary corentin.chary at gmail.com
Wed Nov 18 11:13:55 UTC 2009


Signed-off-by: Corentin Chary <corentin.chary at gmail.com>
---
 transport/encryption/rot-13c/Makefile.am     |    1 +
 transport/encryption/rot-13c/src/Makefile.am |   14 ++++
 transport/encryption/rot-13c/src/rot-13c.c   |  106 ++++++++++++++++++++++++++
 transport/encryption/rot-13c/src/rot-13c.h   |   30 +++++++
 4 files changed, 151 insertions(+), 0 deletions(-)
 create mode 100644 transport/encryption/rot-13c/Makefile.am
 create mode 100644 transport/encryption/rot-13c/src/Makefile.am
 create mode 100644 transport/encryption/rot-13c/src/rot-13c.c
 create mode 100644 transport/encryption/rot-13c/src/rot-13c.h

diff --git a/transport/encryption/rot-13c/Makefile.am b/transport/encryption/rot-13c/Makefile.am
new file mode 100644
index 0000000..f963eff
--- /dev/null
+++ b/transport/encryption/rot-13c/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = src
\ No newline at end of file
diff --git a/transport/encryption/rot-13c/src/Makefile.am b/transport/encryption/rot-13c/src/Makefile.am
new file mode 100644
index 0000000..4cdcbff
--- /dev/null
+++ b/transport/encryption/rot-13c/src/Makefile.am
@@ -0,0 +1,14 @@
+xlator_LTLIBRARIES = rot-13c.la
+xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/transport/encryption
+
+rot_13c_la_LDFLAGS = -module -avoidversion
+
+rot_13c_la_SOURCES = rot-13c.c
+rot_13c_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
+
+noinst_HEADERS = rot-13c.h
+
+AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
+	-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)
+
+CLEANFILES =
diff --git a/transport/encryption/rot-13c/src/rot-13c.c b/transport/encryption/rot-13c/src/rot-13c.c
new file mode 100644
index 0000000..d37d389
--- /dev/null
+++ b/transport/encryption/rot-13c/src/rot-13c.c
@@ -0,0 +1,106 @@
+/*
+  Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com>
+  This file is part of GlusterFS.
+
+  GlusterFS is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published
+  by the Free Software Foundation; either version 3 of the License,
+  or (at your option) any later version.
+
+  GlusterFS is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see
+  <http://www.gnu.org/licenses/>.
+*/
+
+#include <ctype.h>
+#include <sys/uio.h>
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "glusterfs.h"
+#include "xlator.h"
+#include "transport.h"
+#include "logging.h"
+#include "protocol.h"
+
+#include "rot-13c.h"
+
+/*
+ * This is a rot13 ``encryption'' xlator. It rot13's data when
+ * writing to network and rot13's it back when reading it.
+ * This xlator is meant as an example, NOT FOR PRODUCTION
+ * USE ;) (hence no error-checking)
+ */
+
+static void
+rot13 (char *buf, int len)
+{
+	int i;
+	for (i = 0; i < len; i++) {
+		if (buf[i] >= 'a' && buf[i] <= 'z')
+			buf[i] = 'a' + ((buf[i] - 'a' + 13) % 26);
+		else if (buf[i] >= 'A' && buf[i] <= 'Z')
+			buf[i] = 'A' + ((buf[i] - 'A' + 13) % 26);
+	}
+}
+
+static void
+rot13_iovec (struct iovec *vector, int count)
+{
+	int i;
+	for (i = 0; i < count; i++) {
+		rot13 (vector[i].iov_base, vector[i].iov_len);
+	}
+}
+
+int32_t
+rot13c_encrypt (transport_t *this, char *hdr, size_t len,
+		struct iovec *vector, int count)
+{
+	rot13 (gf_param((gf_hdr_common_t *)hdr), len - GF_HDR_COMMON_SIZE);
+	rot13_iovec (vector, count);
+	return 0;
+}
+
+int32_t
+rot13c_decrypt (transport_t *this, char *hdr, size_t len,
+		struct iobuf *iobuf, size_t buflen)
+{
+	rot13 (gf_param((gf_hdr_common_t *)hdr), len - GF_HDR_COMMON_SIZE);
+	if (iobuf)
+		rot13 (iobuf->ptr, buflen);
+	return 0;
+}
+
+int32_t
+init (transport_crypto_t *crypto)
+{
+	crypto->xl_private = NULL;
+	crypto->magic = CRYPTO_MAGIC_ROT_13C;
+	gf_log ("rot13c", GF_LOG_DEBUG, "rot13c transport encryptor loaded");
+	return 0;
+}
+
+void
+fini (transport_crypto_t *crypto)
+{
+	FREE (crypto->xl_private);
+	return;
+}
+
+struct transport_crypto_ops tcops = {
+	.encrypt = rot13c_encrypt,
+	.decrypt = rot13c_decrypt,
+};
+
+struct volume_options options[] = {
+	{ .key  = {NULL} },
+};
diff --git a/transport/encryption/rot-13c/src/rot-13c.h b/transport/encryption/rot-13c/src/rot-13c.h
new file mode 100644
index 0000000..23f7494
--- /dev/null
+++ b/transport/encryption/rot-13c/src/rot-13c.h
@@ -0,0 +1,30 @@
+/*
+   Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com>
+   This file is part of GlusterFS.
+
+   GlusterFS is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3 of the License,
+   or (at your option) any later version.
+
+   GlusterFS is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __ROT_13C_H__
+#define __ROT_13C_H__
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#define CRYPTO_MAGIC_ROT_13C	13
+
+#endif /* __ROT_13_H__ */
-- 
1.6.4.4






More information about the Gluster-devel mailing list