]> SAFE projects GIT repository - jmp/mailleur/commitdiff
uth plain and login authentication use crypted password (instead hash)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 10 Jul 2025 11:17:33 +0000 (07:17 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 10 Jul 2025 11:17:33 +0000 (07:17 -0400)
lib/devsql.c
lib/lvleml.c
lib/unisql.c
lib/unisql.h
sql/mailleur.sql

index d1c678874dd58ce994e1229893baeb03be6554a8..194274f6cf92995e2d083ae03590b8d199bd1128 100644 (file)
@@ -311,10 +311,11 @@ static USRTYP *select_user(SQLTYP *sql,char *email)
 //field available in table "emails"
 static const FLDTYP usrfield[]={
           {1,"email"},
-          {2,"hash"},
-          {3,"space"},
-          {4,"mxspace"},
-          {5,"locked"},
+          {2,"password"},
+          {3,"hash"},
+          {4,"space"},
+          {5,"mxspace"},
+          {6,"locked"},
           {0,(char *)0}
           };
 
@@ -366,16 +367,19 @@ while (proceed==true) {
           case 1        :       //user email
             usr->email=strdup(locval);
             break;
-          case 2        :       //'email:realm:password' MD5
+          case 2        :       //User crypted password
+            usr->password=strdup(locval);
+            break;
+          case 3        :       //'email:realm:password' MD5
             usr->hash=strdup(locval);
             break;
-          case 3        :       //user used space
+          case 4        :       //user used space
             usr->space=atoi(locval);
             break;
-          case 4        :       //user max space available
+          case 5        :       //user max space available
             usr->mxspace=atoi(locval);
             break;
-          case 5        :       //lock status
+          case 6        :       //lock status
             usr->lock=atoi(locval);
             break;
           default       :
index 2e3b47b7367457def2889e0bc231e557da4afb85..8b3f5f8eaae1fad44ac0f7e7071a7951cce6cecf 100644 (file)
@@ -384,24 +384,7 @@ while (proceed==true) {
         phase=999;      //No need to go further
         }
       break;
-    case 2      :  {    //computing the given md5
-      char *seq;
-      MD5TYP *givenmd5;
-
-      (void) rou_asprintf(&seq,"%s:%s:%s",data[1],rou_getrealm(),data[2]);
-      givenmd5=dig_hashmd5((unsigned char *)seq,strlen(seq));
-      if (givenmd5!=(MD5TYP *)0) {
-        givenhash=cnv_tohexa((char *)givenmd5,sizeof(MD5TYP));
-        (void) free(givenmd5);
-        }
-      if (givenhash==(char *)0) {
-        (void) rou_alert(0,"%s Unable to have md5 for <%s> (Bug?)",seq);
-        phase=999;      //trouble trouble
-        }
-      seq=rou_freestr(seq);
-      }
-      break;
-    case 3      :  {    //checking user password
+    case 2      :  {    //checking user password
       USRTYP *usr;
 
       usr=(USRTYP *)0;
@@ -409,12 +392,34 @@ while (proceed==true) {
       contact->authname=strdup(data[1]);
       *rmtpass=strdup(data[2]);
       if (sql_mngusr(contact->sqlptr,sql_select,data[1],&usr)==true) {
-        if (usr->hash==(char *)0) {
-          usr->hash=cnv_getrndstr(10);
-          (void) rou_alert(0,"%s usr=<%s> password empty, using random hash",
+        char *givenpass;;
+
+        givenpass=data[2];
+        *rmtpass=strdup(givenpass);
+        if (usr->password==(char *)0) {
+          (void) rou_alert(0,"%s usr=<%s> password empty, assigning one",
                               OPEP,data[1]);
+          usr->password=cnv_getrndstr(10);
+          }
+        if (usr->password[0]=='$') {
+          char *ptr;
+          char idsalt[100];
+
+          (void) memset(idsalt,'\000',sizeof(idsalt));
+          (void) strncpy(idsalt,usr->password,sizeof(idsalt)-1);
+          if ((ptr=strrchr(idsalt,'$'))!=(char *)0) {
+            ptr++;
+            *ptr='\000';
+            }
+          if ((ptr=crypt(givenpass,idsalt))==(char *)0) {
+            (void) rou_alert(0,"%s Trouble to crypt (Bug?) givenpass=<%s> "
+                               "salt=<%s> (error=<%s>)",
+                                OPEP,givenpass,idsalt,strerror(errno));
+            ptr=data[2]; //trying to overcome
+            }
+          givenpass=ptr;
           }
-        isok=(strcmp(givenhash,usr->hash)==0);
+        isok=(strcmp(givenpass,usr->password)==0);
         usr=sql_freeusr(usr);
         }
       }
index 76a1d2885e9ee2f256ece7592e859fbceb64f006..975aba6f8b422801997b6957d45908fad210fed0 100644 (file)
@@ -107,6 +107,7 @@ PUBLIC USRTYP *sql_freeusr(USRTYP *usr)
 {
 if (usr!=(USRTYP *)0) {
   usr->hash=rou_freestr(usr->hash);
+  usr->password=rou_freestr(usr->password);
   usr->email=rou_freestr(usr->email);
   (void) free(usr);
   usr=(USRTYP *)0;
index 4dcf5535804bba4d63c5031e968dc184ab7444d0..7903c54dc76229ed5b2a16e0d50cf46256420033 100644 (file)
@@ -20,6 +20,7 @@ typedef enum    {
 //structure about user within the database
 typedef struct  {
         char *email;    //user emails
+        char *password; //user crypted password
         char *hash;     //'email:realm:password' MD5
         u_int  lock;    //account is lock
         u_long space;   //user space used
index 9a0dccf40c84265a0b9a0291af2ab6f7105598c4..5247fd0f8b749a39f37991ef201c9b95c73ec207 100644 (file)
@@ -127,7 +127,7 @@ CREATE TRIGGER sethash
   BEFORE UPDATE ON emails FOR EACH ROW
     BEGIN
     set NEW.hash=MD5(HASHING);
-    set NEW.password=encrypt(NEW.password,'$1$abcdef');
+    set NEW.password=encrypt(NEW.password,concat('$1$',md5(rand())));
     END$$
     
   
@@ -135,7 +135,7 @@ CREATE TRIGGER updhash
   BEFORE INSERT ON emails FOR EACH ROW
     BEGIN
     set NEW.hash=MD5(HASHING);
-    set NEW.password=encrypt(NEW.password,'$1$abcdef');
+    set NEW.password=encrypt(NEW.password,concat('$1$',md5(rand())));
     END$$
 
 #endif