]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Added the hash field within devsql.c
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 8 Jul 2025 11:23:04 +0000 (07:23 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 8 Jul 2025 11:23:04 +0000 (07:23 -0400)
lib/devsql.c
lib/unisql.c
lib/unisql.h
sql/mailleur.sql

index 99fae2bc4c49a379e37fef9db0a3e3fbd2ee8d04..80e0bf9372c92fded76c4975a325f2c223d60148 100644 (file)
@@ -36,14 +36,20 @@ typedef struct  {
 #define SESSIONS        "sessions"      //session tables
 #define ACTIONS         "actions"       //action tables
 
+typedef struct  {
+        int num;        //field number
+        char *name;     //field name;
+        }FLDTYP;
+
 //field available in table "emails"
-const char *usrfield[]={
-          "email",
-          "password",
-          "space",
-          "mxspace",
-          "locked",
-          (char *)0
+const FLDTYP usrfield[]={
+          {1,"email"},
+          {2,"password"},
+          {3,"space"},
+          {4,"mxspace"},
+          {5,"locked"},
+          {6,"hash"},
+          {0,(char *)0}
           };
 
 //field available in table "sessions"
@@ -352,29 +358,33 @@ while (proceed==true) {
       break;
     case 2      :       //user data extraction
       usr=(USRTYP *)calloc(1,sizeof(USRTYP));
-      for (int i=0;usrfield[i]!=(char *)0;i++) {
+      for (int i=0;usrfield[i].num!=0;i++) {
         char *locval;
       
-        if ((locval=getvalue(sql,rs,0,usrfield[i]))==(char *)0)
+        if ((locval=getvalue(sql,rs,0,usrfield[i].name))==(char *)0)
           continue;
-        switch (i) {
-          case 0        :       //user email
+        switch (usrfield[i].num) {
+          case 1        :       //user email
             usr->email=strdup(locval);
             break;
-          case 1        :       //user passwd
+          case 2        :       //user passwd
             usr->passwd=strdup(locval);
             break;
-          case 2        :       //user used space
+          case 3        :       //user used space
             usr->space=atoi(locval);
             break;
-          case 3        :       //user max space available
+          case 4        :       //user max space available
             usr->mxspace=atoi(locval);
             break;
-          case 4        :       //lock status
+          case 5        :       //lock status
             usr->lock=atoi(locval);
             break;
+          case 6        :       //'email:realm:password' MD5
+            usr->hash=strdup(locval);
+            break;
           default       :
-            (void) rou_alert(0,"%s field <%s> not used (Bug?)",OPEP,usrfield[i]);
+            (void) rou_alert(0,"%s field <%d:%s> not implemented (Bug?)",
+                                   OPEP,usrfield[i].num,usrfield[i].name);
             break;
           }
         }
index da7f1e4cf6351d20a9aa8208327d29900286bb95..909a356fc345ca2b5b09719630f01d85a4fcee35 100644 (file)
@@ -106,6 +106,7 @@ PUBLIC USRTYP *sql_freeusr(USRTYP *usr)
 
 {
 if (usr!=(USRTYP *)0) {
+  usr->hash=rou_freestr(usr->hash);
   usr->passwd=rou_freestr(usr->passwd);
   usr->email=rou_freestr(usr->email);
   (void) free(usr);
index a85874054ba9183629b730564d459d0196f858ca..e0dcab8e2ca6edec8772e40e23c8ca4ebe2a61e6 100644 (file)
@@ -24,6 +24,7 @@ typedef struct  {
         u_int  lock;    //account is lock
         u_long space;   //user space used
         u_long mxspace; //user maximun space
+        char *hash;     //'email:realm:password' MD5
         }USRTYP;
 
 //structure about an email session
index 275c6d99f60264025aeeac5947ed6540a00418f4..95201ddfdcda33883842bce0a46e6aba71c14f34 100644 (file)
@@ -55,11 +55,9 @@ CREATE TABLE emails  (
        email           TEXTUNIQUE,     //User email
        password        TEXT            //User password
                        DFLT '!',
-       realm           TEXT            //'email:realm:password' MD5
-                       DFLT '0ABCD9',
-       seq             BIGINT          //HASH as a seq
-                       DFLT 0,
-       hash            TEXT,           //'email:realm:passwor' MD5
+       realm           TEXT            //user realm
+                       DFLT 'mailleur-email',
+       hash            TEXT,           //'email:realm:password' MD5
        space           INTEGER         //space used by user email      
                        DFLT 0,
        mxspace         INTEGER         //Maximun space available
@@ -75,7 +73,6 @@ GRANT SELECT                          ON emails TO maildove;
 CREATE FUNCTION updpass()
   RETURNS trigger AS $$
        BEGIN
-       NEW.seq = hashtextextended(md5(concat (NEW.email,':',NEW.realm,':',new.password)),0);
        NEW.hash = md5(concat (NEW.email,':',NEW.realm,':',new.password));
        NEW.password = crypt(new.password, gen_salt('md5'));
        RETURN NEW;