summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSachidananda <sac@gluster.com>2011-01-25 05:32:01 +0000
committerAnand V. Avati <avati@dev.gluster.com>2011-01-27 12:18:05 -0800
commit066b1809876ba156d925edcb8fb470ee90319d3c (patch)
tree0bb4be38efac8773cf1604460288838e684989a3
parent7691550a5bd281e9d21771b37066d44434e92934 (diff)
Move hostname, ip address validating functions to libglusterfs.
hostname and ip address validation functions are duplicated in several source files. Move them to libglusterfs. Signed-off-by: Sachidananda Urs <sac@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 2249 (Problems with hostname validation) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2249
-rw-r--r--libglusterfs/src/common-utils.c121
-rw-r--r--libglusterfs/src/common-utils.h5
-rw-r--r--libglusterfs/src/xlator.c121
-rw-r--r--rpc/rpc-lib/src/rpc-transport.c122
4 files changed, 126 insertions, 243 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 6f40e7a6420..727983d0682 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1572,3 +1572,124 @@ strtail (char *str, const char *pattern)
return NULL;
}
+
+/* RFC 1123 & 952 */
+char
+valid_host_name (char *address, int length)
+{
+ int i = 0;
+ char ret = 1;
+
+ if ((length > 75) || (length == 1)) {
+ ret = 0;
+ goto out;
+ }
+
+ if (!isalnum (address[length - 1])) {
+ ret = 0;
+ goto out;
+ }
+
+ for (i = 0; i < length; i++) {
+ if (!isalnum (address[i]) && (address[i] != '.')
+ && (address[i] != '-')) {
+ ret = 0;
+ goto out;
+ }
+ }
+
+out:
+ return ret;
+}
+
+char
+valid_ipv4_address (char *address, int length)
+{
+ int octets = 0;
+ int value = 0;
+ char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
+ char ret = 1;
+
+ tmp = gf_strdup (address);
+ prev = tmp;
+ prev = strtok_r (tmp, ".", &ptr);
+
+ while (prev != NULL)
+ {
+ octets++;
+ value = strtol (prev, &endptr, 10);
+ if ((value > 255) || (value < 0) || (endptr != NULL)) {
+ ret = 0;
+ goto out;
+ }
+
+ prev = strtok_r (NULL, ".", &ptr);
+ }
+
+ if (octets != 4) {
+ ret = 0;
+ }
+
+out:
+ GF_FREE (tmp);
+ return ret;
+}
+
+char
+valid_ipv6_address (char *address, int length)
+{
+ int hex_numbers = 0;
+ int value = 0;
+ char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
+ char ret = 1;
+
+ tmp = gf_strdup (address);
+ prev = strtok_r (tmp, ":", &ptr);
+
+ while (prev != NULL)
+ {
+ hex_numbers++;
+ value = strtol (prev, &endptr, 16);
+ if ((value > 0xffff) || (value < 0)
+ || (endptr != NULL && *endptr != '\0')) {
+ ret = 0;
+ goto out;
+ }
+
+ prev = strtok_r (NULL, ":", &ptr);
+ }
+
+ if (hex_numbers > 8) {
+ ret = 0;
+ }
+
+out:
+ GF_FREE (tmp);
+ return ret;
+}
+
+char
+valid_internet_address (char *address)
+{
+ char ret = 0;
+ int length = 0;
+
+ if (address == NULL) {
+ goto out;
+ }
+
+ length = strlen (address);
+ if (length == 0) {
+ goto out;
+ }
+
+ if (valid_ipv4_address (address, length)
+ || valid_ipv6_address (address, length)
+ || valid_host_name (address, length)) {
+ ret = 1;
+ }
+
+out:
+ return ret;
+}
+
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 4371888d034..ca0990aa5d6 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -338,5 +338,10 @@ int gf_system (const char *command);
int get_checksum_for_path (char *path, uint32_t *checksum);
char *strtail (char *str, const char *pattern);
+
+char valid_host_name (char *address, int length);
+char valid_ipv4_address (char *address, int length);
+char valid_ipv6_address (char *address, int length);
+char valid_internet_address (char *address);
#endif /* _COMMON_UTILS_H */
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 37ea8162863..9db1ba26952 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -28,7 +28,6 @@
#include <fnmatch.h>
#include "defaults.h"
-
#define SET_DEFAULT_FOP(fn) do { \
if (!xl->fops->fn) \
xl->fops->fn = default_##fn; \
@@ -106,126 +105,6 @@ fill_defaults (xlator_t *xl)
return;
}
-/* RFC 1123 & 952 */
-static char
-valid_host_name (char *address, int length)
-{
- int i = 0;
- char ret = 1;
-
- if ((length > 75) || (length == 1)) {
- ret = 0;
- goto out;
- }
-
- if (!isalnum (address[length - 1])) {
- ret = 0;
- goto out;
- }
-
- for (i = 0; i < length; i++) {
- if (!isalnum (address[i]) && (address[i] != '.')
- && (address[i] != '-')) {
- ret = 0;
- goto out;
- }
- }
-
-out:
- return ret;
-}
-
-static char
-valid_ipv4_address (char *address, int length)
-{
- int octets = 0;
- int value = 0;
- char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
- char ret = 1;
-
- tmp = gf_strdup (address);
- prev = tmp;
- prev = strtok_r (tmp, ".", &ptr);
-
- while (prev != NULL)
- {
- octets++;
- value = strtol (prev, &endptr, 10);
- if ((value > 255) || (value < 0) || (endptr != NULL)) {
- ret = 0;
- goto out;
- }
-
- prev = strtok_r (NULL, ".", &ptr);
- }
-
- if (octets != 4) {
- ret = 0;
- }
-
-out:
- GF_FREE (tmp);
- return ret;
-}
-
-static char
-valid_ipv6_address (char *address, int length)
-{
- int hex_numbers = 0;
- int value = 0;
- char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
- char ret = 1;
-
- tmp = gf_strdup (address);
- prev = strtok_r (tmp, ":", &ptr);
-
- while (prev != NULL)
- {
- hex_numbers++;
- value = strtol (prev, &endptr, 16);
- if ((value > 0xffff) || (value < 0)
- || (endptr != NULL && *endptr != '\0')) {
- ret = 0;
- goto out;
- }
-
- prev = strtok_r (NULL, ":", &ptr);
- }
-
- if (hex_numbers > 8) {
- ret = 0;
- }
-
-out:
- GF_FREE (tmp);
- return ret;
-}
-
-static char
-valid_internet_address (char *address)
-{
- char ret = 0;
- int length = 0;
-
- if (address == NULL) {
- goto out;
- }
-
- length = strlen (address);
- if (length == 0) {
- goto out;
- }
-
- if (valid_ipv4_address (address, length)
- || valid_ipv6_address (address, length)
- || valid_host_name (address, length)) {
- ret = 1;
- }
-
-out:
- return ret;
-}
-
int
_volume_option_value_validate (xlator_t *xl,
data_pair_t *pair,
diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c
index 249c9398f79..61e31e9038e 100644
--- a/rpc/rpc-lib/src/rpc-transport.c
+++ b/rpc/rpc-lib/src/rpc-transport.c
@@ -42,128 +42,6 @@
#define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL)
#endif
-/* RFC 1123 & 952 */
-static char
-valid_host_name (char *address, int length)
-{
- int i = 0;
- char ret = 1;
-
- if ((length > 75) || (length == 1)) {
- ret = 0;
- goto out;
- }
-
- if (!isalnum (address[length - 1])) {
- ret = 0;
- goto out;
- }
-
- for (i = 0; i < length; i++) {
- if (!isalnum (address[i]) && (address[i] != '.')
- && (address[i] != '-')) {
- ret = 0;
- goto out;
- }
- }
-
-out:
- return ret;
-}
-
-static char
-valid_ipv4_address (char *address, int length)
-{
- int octets = 0;
- int value = 0;
- char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
- char ret = 1;
-
- tmp = gf_strdup (address);
- prev = strtok_r (tmp, ".", &ptr);
-
- while (prev != NULL)
- {
- octets++;
- value = strtol (prev, &endptr, 10);
- if ((value > 255) || (value < 0) || (endptr != NULL)) {
- ret = 0;
- goto out;
- }
-
- prev = strtok_r (NULL, ".", &ptr);
- }
-
- if (octets != 4) {
- ret = 0;
- }
-
-out:
- GF_FREE (tmp);
- return ret;
-}
-
-
-static char
-valid_ipv6_address (char *address, int length)
-{
- int hex_numbers = 0;
- int value = 0;
- char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
- char ret = 1;
-
- tmp = gf_strdup (address);
- prev = strtok_r (tmp, ":", &ptr);
-
- while (prev != NULL)
- {
- hex_numbers++;
- value = strtol (prev, &endptr, 16);
- if ((value > 0xffff) || (value < 0)
- || (endptr != NULL && *endptr != '\0')) {
- ret = 0;
- goto out;
- }
-
- prev = strtok_r (NULL, ":", &ptr);
- }
-
- if (hex_numbers > 8) {
- ret = 0;
- }
-
-out:
- GF_FREE (tmp);
- return ret;
-}
-
-
-static char
-valid_internet_address (char *address)
-{
- char ret = 0;
- int length = 0;
-
- if (address == NULL) {
- goto out;
- }
-
- length = strlen (address);
- if (length == 0) {
- goto out;
- }
-
- if (valid_ipv4_address (address, length)
- || valid_ipv6_address (address, length)
- || valid_host_name (address, length)) {
- ret = 1;
- }
-
-out:
- return ret;
-}
-
-
int
__volume_option_value_validate (char *name,
data_pair_t *pair,