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;
}
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Dica para encontrar diversos jogos Indies criativos
Instalando Discord no Debian 13
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Software livre - será que eu estou tão errado assim? (10)
Boot do PosRog so funciona em notebook (1)