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;
}
tux-gpt - Assistente de IA para o Terminal
Instalação e configuração do Chrony
Programa IRPF - Guia de Instalação e Resolução de alguns Problemas
Como instalar no Linux Jogos da Steam só para Windows
Instalando o Team Viewer no Debian Trixie - problema no Policykit
O Que Fazer Após Instalar Ubuntu 25.04
Copiar Layout do Teclado para aplicar em outra Distribuição (6)
Alguém poderia me ajudar a escolher peças pra montar um desktop? [RESO... (34)