Whitespace and indentation changes.

Also changed line-endings from DOS CRLF to only LF.
In addition, made functions const correct.
This commit is contained in:
Johan Wikman
2015-11-09 13:55:59 +02:00
parent 14b8dbc4d8
commit 90a8646ac2
2 changed files with 437 additions and 425 deletions

View File

@ -38,10 +38,10 @@ secrets_randomchar()
static int
secrets_random_str(unsigned char *output, int len)
{
int i;
int i;
srand((unsigned long )time(0L) ^ (unsigned long )output);
for ( i = 0; i < len; ++i )
for (i = 0; i < len; ++i)
{
output[i] = secrets_randomchar();
}
@ -56,19 +56,25 @@ int i;
* @return The keys structure or NULL on error
*/
static MAXKEYS *
secrets_readKeys(char* path)
secrets_readKeys(const char* path)
{
char secret_file[PATH_MAX+1];
char *home;
MAXKEYS *keys;
struct stat secret_stats;
int fd;
int len;
static int reported = 0;
if(path != NULL)
char secret_file[PATH_MAX+1];
char *home;
MAXKEYS *keys;
struct stat secret_stats;
int fd;
int len;
static int reported = 0;
if (path != NULL)
{
snprintf(secret_file, PATH_MAX, "%s/.secrets", path);
}
else
{
snprintf(secret_file, PATH_MAX, "%s/.secrets", get_datadir());
}
/* Try to access secrets file */
if (access(secret_file, R_OK) == -1)
{
@ -150,6 +156,7 @@ static int reported = 0;
strerror_r(eno, errbuf, sizeof(errbuf)))));
return NULL;
}
if (secret_stats.st_mode != (S_IRUSR|S_IFREG))
{
close(fd);
@ -224,18 +231,18 @@ static int reported = 0;
* @param secret_file The file with secret keys
* @return 0 on success and 1 on failure
*/
int secrets_writeKeys(char *path)
int secrets_writeKeys(const char *path)
{
int fd,randfd;
unsigned int randval;
MAXKEYS key;
char secret_file[PATH_MAX + 10];
int fd,randfd;
unsigned int randval;
MAXKEYS key;
char secret_file[PATH_MAX + 10];
if(strlen(path) > PATH_MAX)
{
if (strlen(path) > PATH_MAX)
{
skygw_log_write(LOGFILE_ERROR,"Error: Pathname too long.");
return 1;
}
}
snprintf(secret_file,PATH_MAX + 9,"%s/.secrets",path);
secret_file[PATH_MAX + 9] = '\0';
@ -267,7 +274,7 @@ if(strlen(path) > PATH_MAX)
return 1;
}
if(read(randfd,(void*)&randval,sizeof(unsigned int)) < 1)
if (read(randfd,(void*)&randval,sizeof(unsigned int)) < 1)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
@ -310,7 +317,7 @@ if(strlen(path) > PATH_MAX)
strerror_r(errno, errbuf, sizeof(errbuf)))));
}
if( chmod(secret_file, S_IRUSR) < 0)
if (chmod(secret_file, S_IRUSR) < 0)
{
char errbuf[STRERROR_BUFLEN];
LOGIF(LE, (skygw_log_write_flush(
@ -337,18 +344,20 @@ if(strlen(path) > PATH_MAX)
* @return The decrypted password
*/
char *
decryptPassword(char *crypt)
decryptPassword(const char *crypt)
{
MAXKEYS *keys;
AES_KEY aeskey;
unsigned char *plain;
char *ptr;
unsigned char encrypted[80];
int enlen;
MAXKEYS *keys;
AES_KEY aeskey;
unsigned char *plain;
const char *ptr;
unsigned char encrypted[80];
int enlen;
keys = secrets_readKeys(NULL);
if (!keys)
{
return strdup(crypt);
}
/*
** If the input is not a HEX string return the input
** it probably was not encrypted
@ -388,17 +397,19 @@ int enlen;
* @return The encrypted password
*/
char *
encryptPassword(char* path, char *password)
encryptPassword(const char* path, const char *password)
{
MAXKEYS *keys;
AES_KEY aeskey;
int padded_len;
char *hex_output;
unsigned char padded_passwd[80];
unsigned char encrypted[80];
MAXKEYS *keys;
AES_KEY aeskey;
int padded_len;
char *hex_output;
unsigned char padded_passwd[80];
unsigned char encrypted[80];
if ((keys = secrets_readKeys(path)) == NULL)
{
return NULL;
}
memset(padded_passwd, 0, 80);
strncpy((char *)padded_passwd, password, 79);

View File

@ -46,12 +46,13 @@
/**
* The key structure held in the secrets file
*/
typedef struct maxkeys {
typedef struct maxkeys
{
unsigned char enckey[MAXSCALE_KEYLEN];
unsigned char initvector[MAXSCALE_IV_LEN];
} MAXKEYS;
extern int secrets_writeKeys(char *filename);
extern char *decryptPassword(char *);
extern char *encryptPassword(char*,char *);
extern int secrets_writeKeys(const char *filename);
extern char *decryptPassword(const char *);
extern char *encryptPassword(const char*, const char *);
#endif