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

@ -56,7 +56,7 @@ int i;
* @return The keys structure or NULL on error * @return The keys structure or NULL on error
*/ */
static MAXKEYS * static MAXKEYS *
secrets_readKeys(char* path) secrets_readKeys(const char* path)
{ {
char secret_file[PATH_MAX+1]; char secret_file[PATH_MAX+1];
char *home; char *home;
@ -65,10 +65,16 @@ struct stat secret_stats;
int fd; int fd;
int len; int len;
static int reported = 0; static int reported = 0;
if (path != NULL) if (path != NULL)
{
snprintf(secret_file, PATH_MAX, "%s/.secrets", path); snprintf(secret_file, PATH_MAX, "%s/.secrets", path);
}
else else
{
snprintf(secret_file, PATH_MAX, "%s/.secrets", get_datadir()); snprintf(secret_file, PATH_MAX, "%s/.secrets", get_datadir());
}
/* Try to access secrets file */ /* Try to access secrets file */
if (access(secret_file, R_OK) == -1) if (access(secret_file, R_OK) == -1)
{ {
@ -150,6 +156,7 @@ static int reported = 0;
strerror_r(eno, errbuf, sizeof(errbuf))))); strerror_r(eno, errbuf, sizeof(errbuf)))));
return NULL; return NULL;
} }
if (secret_stats.st_mode != (S_IRUSR|S_IFREG)) if (secret_stats.st_mode != (S_IRUSR|S_IFREG))
{ {
close(fd); close(fd);
@ -224,7 +231,7 @@ static int reported = 0;
* @param secret_file The file with secret keys * @param secret_file The file with secret keys
* @return 0 on success and 1 on failure * @return 0 on success and 1 on failure
*/ */
int secrets_writeKeys(char *path) int secrets_writeKeys(const char *path)
{ {
int fd,randfd; int fd,randfd;
unsigned int randval; unsigned int randval;
@ -337,18 +344,20 @@ if(strlen(path) > PATH_MAX)
* @return The decrypted password * @return The decrypted password
*/ */
char * char *
decryptPassword(char *crypt) decryptPassword(const char *crypt)
{ {
MAXKEYS *keys; MAXKEYS *keys;
AES_KEY aeskey; AES_KEY aeskey;
unsigned char *plain; unsigned char *plain;
char *ptr; const char *ptr;
unsigned char encrypted[80]; unsigned char encrypted[80];
int enlen; int enlen;
keys = secrets_readKeys(NULL); keys = secrets_readKeys(NULL);
if (!keys) if (!keys)
{
return strdup(crypt); return strdup(crypt);
}
/* /*
** If the input is not a HEX string return the input ** If the input is not a HEX string return the input
** it probably was not encrypted ** it probably was not encrypted
@ -388,7 +397,7 @@ int enlen;
* @return The encrypted password * @return The encrypted password
*/ */
char * char *
encryptPassword(char* path, char *password) encryptPassword(const char* path, const char *password)
{ {
MAXKEYS *keys; MAXKEYS *keys;
AES_KEY aeskey; AES_KEY aeskey;
@ -398,7 +407,9 @@ unsigned char padded_passwd[80];
unsigned char encrypted[80]; unsigned char encrypted[80];
if ((keys = secrets_readKeys(path)) == NULL) if ((keys = secrets_readKeys(path)) == NULL)
{
return NULL; return NULL;
}
memset(padded_passwd, 0, 80); memset(padded_passwd, 0, 80);
strncpy((char *)padded_passwd, password, 79); strncpy((char *)padded_passwd, password, 79);

View File

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