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;
}
Desktop Linux ganha fôlego enquanto distros refinam experiência e segurança
Wayland em alta, IA em debate e novos ventos para distros e devices
Qt 6.10 e Python 3.14 puxam o ritmo do software livre nesta quarta
Atualizações de Apps, Desktop e Kernel agitam o ecossistema Linux nesta terça-feira
Como mudar o nome de dispositivos Bluetooth via linha de comando
Adicionando o repositório backports no Debian 13 Trixie