Enviado em 31/07/2018 - 11:18h
Observer o seguinte trecho de código
void _hash_pass(char *password){
w_log("...", "Hashing password", SRV_LOG, 0);
size_t len=snprintf(NULL, 0, SALT, strlen(password), password);
char *saltpass=malloc(len*sizeof(char)+1);
snprintf(saltpass, len+1, SALT, strlen(password), password);
unsigned char digest[SHA256_DIGEST_LENGTH];
SHA256((unsigned char*)saltpass, strlen(saltpass)+1, digest);
char password_md[SHA256_DIGEST_LENGTH*2+1];
for(unsigned int i=0; i<SHA256_DIGEST_LENGTH; i++){
snprintf(&password_md[i*2], 3, "%02x", (unsigned int)digest[i]);
}
strncpy(password, password_md, strlen(password_md)+1);
free(saltpass);
}
short int check_data(struct __user user, short int permitions){
w_log("...", "Checking user data", SRV_LOG, 0);
size_t len=snprintf(NULL, 0, SRV_USR_PATH, user.username);
char *path=malloc(len*sizeof(char)+1);
snprintf(path, len+1, SRV_USR_PATH, user.username);
FILE *usr_file=fopen(path, "rb");
short int rv=-1;
if(usr_file==NULL){
w_log(strerror(errno), "Opening data", SRV_LOG, 2);
}else{
w_log("successful", "Opening data", SRV_LOG, 0);
struct __user aux=user;
_hash_pass(aux.password);
if(fread(&user, sizeof(struct __user), 1, usr_file)!=1){
w_log(strerror(errno), "Loading data", SRV_LOG, 2);
}else{
w_log("Successful", "Loading data", SRV_LOG, 0);
if(strncmp(user.password, aux.password, strlen(user.password)+1)!=0){
w_log(user.username, "Invalid password", SRV_LOG, 2);
}else if(strncmp(user.username, aux.username, strlen(user.username+1)+1)!=0){
w_log(user.username, "Invalid username", SRV_LOG, 2);
}else if(user.permitions<aux.permitions){
w_log(user.username, "Invalid permission", SRV_LOG, 2);
}else{
rv=0;
}
}
if(fclose(usr_file)!=0){
w_log(strerror(errno), "ERROR", SRV_LOG, 2);
exit(EXIT_FAILURE);
}else{
w_log("successful", "Checking user data", SRV_LOG, 0);
}
}
free(path);
return rv;
}
O que é o THP na configuração de RAM do Linux e quando desabilitá-lo
Comparação entre os escalonadores BFQ e MQ-Deadline (acesso a disco) no Arch e Debian
Conciliando o uso da ZRAM e SWAP em disco na sua máquina
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Hardware antigo no Arch Linux e outras distribuições
Aprenda a proteger sua rede Wi-Fi!
Deixando o Plasma6 mais fluido no Linux
Como unir duas coleções de ROMs preservando as versões traduzidas (sem duplicatas)
Isso acontece com vcs também? (10)
O que você está ouvindo agora? [2] (222)
Gerar menu automaticamente no fluxbox (3)