Fix PRNG code and windows compilation errors

This commit is contained in:
brenosilva 2012-06-15 19:27:59 +00:00
parent 575356f10c
commit 4ab785c192
4 changed files with 26 additions and 39 deletions

View File

@ -686,6 +686,7 @@ void init_directory_config(directory_config *dcfg)
/* Encryption */ /* Encryption */
if (dcfg->crypto_key == NOT_SET_P) dcfg->crypto_key = getkey(dcfg->mp); if (dcfg->crypto_key == NOT_SET_P) dcfg->crypto_key = getkey(dcfg->mp);
if (dcfg->crypto_key_len == NOT_SET) dcfg->crypto_key_len = strlen(dcfg->crypto_key);
if (dcfg->crypto_key_add == NOT_SET) dcfg->crypto_key_add = ENCRYPTION_KEYONLY; if (dcfg->crypto_key_add == NOT_SET) dcfg->crypto_key_add = ENCRYPTION_KEYONLY;
if (dcfg->crypto_param_name == NOT_SET_P) dcfg->crypto_param_name = "crypt"; if (dcfg->crypto_param_name == NOT_SET_P) dcfg->crypto_param_name = "crypt";
if (dcfg->encryption_is_enabled == NOT_SET) dcfg->encryption_is_enabled = ENCRYPTION_DISABLED; if (dcfg->encryption_is_enabled == NOT_SET) dcfg->encryption_is_enabled = ENCRYPTION_DISABLED;
@ -2315,9 +2316,9 @@ static const char *cmd_encryption_key(cmd_parms *cmd, void *_dcfg, const char *_
char *p1 = NULL; char *p1 = NULL;
if (dcfg == NULL) return NULL; if (dcfg == NULL) return NULL;
if (_p1 == NULL) return NULL;
if (p1 == NULL) return NULL; if (strcasecmp(_p1, "Rand") == 0) {
if (strcasecmp(p1, "Rand") == 0) {
p1 = apr_pstrdup(cmd->pool, getkey(cmd->pool)); p1 = apr_pstrdup(cmd->pool, getkey(cmd->pool));
dcfg->crypto_key = p1; dcfg->crypto_key = p1;
dcfg->crypto_key_len = strlen(dcfg->crypto_key); dcfg->crypto_key_len = strlen(dcfg->crypto_key);

View File

@ -177,24 +177,10 @@ unsigned long prng() {
*/ */
unsigned char *getkey(apr_pool_t *mp) { unsigned char *getkey(apr_pool_t *mp) {
unsigned short int length = 12; unsigned short int length = 12;
struct glinear data; unsigned char *key = NULL;
uint64_t seed; unsigned long int seed = time(NULL);
char output[13];
char *key = NULL;
output[length] = '\0'; key = apr_psprintf(mp,"%lu%lu",prng(),seed);
seed = data.seed;
srand(data.seed);
while(length--) {
seed *= data.mul;
seed += data.add;
data.seed = seed % data.mod;
output[length] = (rand() % 94 + 33);
srand(data.seed + prng());
}
key = apr_psprintf(mp,"%s",output);
return key; return key;
} }

View File

@ -27,13 +27,6 @@
#define INT32_MAX (2147483647) #define INT32_MAX (2147483647)
#endif #endif
struct glinear {
uint32_t seed;
uint32_t mod;
uint32_t mul;
uint32_t add;
};
#define N16BITS_MASK 65536L #define N16BITS_MASK 65536L
#define N16BITS_MAX 0xFFFF #define N16BITS_MAX 0xFFFF
#define N15BITS_MASK 0x7FFF #define N15BITS_MASK 0x7FFF

View File

@ -16,6 +16,13 @@
#define __MSC_TREE_H__ #define __MSC_TREE_H__
#include "modsecurity.h" #include "modsecurity.h"
#include <stdint.h>
typedef struct CPTData CPTData;
typedef struct TreePrefix TreePrefix;
typedef struct TreeNode TreeNode;
typedef struct CPTTree CPTTree;
typedef struct TreeRoot TreeRoot;
#define IPV4_TREE 0x1 #define IPV4_TREE 0x1
#define IPV6_TREE 0x2 #define IPV6_TREE 0x2
@ -37,36 +44,36 @@
#define NETMASK_4 0x4 #define NETMASK_4 0x4
#define NETMASK_2 0x2 #define NETMASK_2 0x2
typedef struct CPTData_ { struct CPTData {
uint8_t netmask; uint8_t netmask;
struct CPTData_ *next; struct CPTData *next;
} CPTData; };
typedef struct TreePrefix_ { struct TreePrefix {
uint8_t *buffer; uint8_t *buffer;
uint16_t bitlen; uint16_t bitlen;
CPTData *prefix_data; CPTData *prefix_data;
} TreePrefix; };
typedef struct TreeNode_ { struct TreeNode {
uint16_t bit; uint16_t bit;
int count; int count;
uint8_t *netmasks; uint8_t *netmasks;
TreePrefix *prefix; TreePrefix *prefix;
struct TreeNode_ *left, *right; struct TreeNode *left, *right;
struct TreeNode_ *parent; struct TreeNode *parent;
} TreeNode; };
typedef struct CPTTree_ { struct CPTTree {
int count; int count;
apr_pool_t *pool; apr_pool_t *pool;
TreeNode *head; TreeNode *head;
} CPTTree; };
typedef struct TreeRoot_ { struct TreeRoot {
CPTTree *ipv4_tree; CPTTree *ipv4_tree;
CPTTree *ipv6_tree; CPTTree *ipv6_tree;
} TreeRoot; };
DSOLOCAL CPTTree *CPTCreateRadixTree(apr_pool_t *pool); DSOLOCAL CPTTree *CPTCreateRadixTree(apr_pool_t *pool);
DSOLOCAL TreeNode *CPTIpMatch(modsec_rec *, uint8_t *, CPTTree *, int); DSOLOCAL TreeNode *CPTIpMatch(modsec_rec *, uint8_t *, CPTTree *, int);