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;
}
Customizar a Instalação do Linux Debian com Preseed
Atualizando o Passado: Linux no Lenovo G460 em 2025
aaPanel - Um Painel de Hospedagem Gratuito e Poderoso
Um modo leve de ouvir/ver áudio/vídeo da internet em máquinas pererecas
Resolver algumas mensagens de erro do SSH
Instalar módulo de segurança do Banco do Brasil Warsaw do tipo .run
Sem espaço na partição home (4)
Aprendendo mais sobre Linux com livro (6)
Procrastinação e autossabotagem são problemas muito comuns na sociedad... (6)