Ticket #228: jabberd2-2.2.0-crypt.patch

File jabberd2-2.2.0-crypt.patch, 1.0 KB (added by shino, 5 months ago)
  • storage/authreg_mysql.c

    old new  
    2020 
    2121/* this module talks to a MySQL server via libmysqlclient */ 
    2222 
     23#define _XOPEN_SOURCE 
    2324#include "c2s.h" 
    2425#include <mysql.h> 
    2526 
     
    2930 
    3031enum mysql_pws_crypt { MPC_PLAIN, MPC_CRYPT }; 
    3132 
     33static char salter[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./"; 
     34 
    3235typedef struct mysqlcontext_st { 
    3336  MYSQL * conn; 
    3437  char * sql_create; 
     
    173176    snprintf(iuser, MYSQL_LU+1, "%s", username); 
    174177    snprintf(irealm, MYSQL_LR+1, "%s", realm); 
    175178 
     179    if (ctx->password_type == MPC_CRYPT) { 
     180       char salt[12] = "$1$"; 
     181       int i; 
     182 
     183       srand(time(0)); 
     184       for(i=0; i<8; i++) 
     185               salt[3+i] = salter[rand()%64]; 
     186       salt[11] = '\0'; 
     187       strcpy(password, crypt(password, salt)); 
     188    } 
     189     
    176190    password[256]= '\0'; 
    177191 
    178192    mysql_real_escape_string(conn, euser, iuser, strlen(iuser));