]> zub.fei.tuke.sk Git - ldapvmail/commitdiff
Default is Maildir not mailbox 0.1-2
authorPeter Popovec <popovec@fei.tuke.sk>
Mon, 14 Feb 2005 10:07:00 +0000 (11:07 +0100)
committerPeter Popovec <popovec@fei.tuke.sk>
Mon, 31 Jan 2005 08:02:00 +0000 (09:02 +0100)
timeout for password cache from config
Write password cache timeout
fixed check for zero length string for sn in adduser
universal password change

debian/changelog
ldapadd.c
ldaplogin.c
ldaplogin.h
ldappass.c
vmail.c
vmailHelper.c
vmailHelper.h
vmailsetup.c
vmailsetup.h

index 97a6e0dda8755c51650477811600d7425160b06a..a383ddc1ee19cedf49f85f0bf82b84a5ebf1658c 100644 (file)
@@ -1,3 +1,13 @@
+ldapvmail (0.1-2) unstable; urgency=low
+
+  * Default is Maildir not mailbox
+  * timeout for password cache from config
+  * Write password cache timeout
+  * fixed check for zero length string for sn in adduser
+  * universal password change 
+
+ --  <popovec@kraken.home.kat.sk>  Sat, 12 Feb 2005 14:21:34 +0100
+
 ldapvmail (0.1-1) unstable; urgency=low
 
   * Initial Release.
index e000cdfe830172e35f99bc431a1586389028dc3a..7319a31bc0a353bab81e9511d3eaf808c64a6dac 100644 (file)
--- a/ldapadd.c
+++ b/ldapadd.c
@@ -92,7 +92,8 @@ newAccount ()
       DNentry =
        newtEntry (18, 2, addAttrxValue[0], 40, &DN, NEWT_FLAG_SCROLL);
       newtFormAddComponent (form, DNentry);
-      asprintf (&c1, "%s%s", GetDefaultVmailPath (), addAttrxValue[0]);
+      asprintf (&c1, "%s%s/Maildir/", GetDefaultVmailPath (),
+               addAttrxValue[0]);
       DNentry = newtEntry (18, 3, c1, 40, &PW, NEWT_FLAG_SCROLL);
       newtFormAddComponent (form, DNentry);
       DNentry = newtEntry (18, 4, NULL, 40, &GN, NEWT_FLAG_SCROLL);
@@ -141,7 +142,7 @@ newAccount ()
       newtFormDestroy (form);
     }
   while (strlen (addAttrxValue[2]) == 0 || strlen (addAttrxValue[3]) == 0
-        || strlen (addAttrxValue[3]) == 0 || strlen (addAttrxValue[4]) == 0);
+        || strlen (addAttrxValue[4]) == 0 || strlen (addAttrxValue[5]) == 0);
   newtPopWindow ();
 
 
index 4eaae50728a32216807fc6fe02700f29d8c6fcae..209b091222bac6d45aaf92b78ff5962244b2983d 100644 (file)
@@ -1,9 +1,7 @@
-//TODO EXTIME from setup
 //TODO bindCredencial structure is not initialized before is used. 
 //     (but only type and expire value is significant for init)
 
 #define _GNU_SOURCE
-#define EXTIME 300
 
 #include <stdio.h>
 #include <string.h>
@@ -15,7 +13,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include "ldaplogin.h"
-
+#include "vmailsetup.h"
 typedef struct bindCredencial0
 {
   char *server;
@@ -24,7 +22,7 @@ typedef struct bindCredencial0
   char *bindpw;
   struct timeval expire;
   char type;                   //0 anonymous  !0 real login
-  char ReadOnly;               //1 if no modyfy operation on ldap
+  char ReadOnly;               //1 if no modify operation on ldap
 } bindCredencial;
 
 static int get_ldap_login (bindCredencial * ldata);
@@ -32,16 +30,15 @@ static bindCredencial logindata;
 
 /**************************************************************************
 Call this to get LDAP ld structure associated with opened ldap connection
-second arg is only indication for credencial cache .. and must be set up to
-READ_OP or WRITE_OP. For WRITE_OP credencial must be rereaded. For READ_OP
-can be used old credencial only if is not expirred or old credencial is not 
-escaped with annonymous  bind. 
+second arg is only indication for credential cache .. and must be set up to
+READ_OP or WRITE_OP. For WRITE_OP credential must be rereaded. For READ_OP
+can be used old credential only if is not expired or old credential is not 
+escaped with anonymous  bind. 
 
-posible TODO .. cache can be turned on for WRITE_OP too in setup ? 
 
 return value:
-0 if success, -1 init error, -3 no homedir, -4 invalid credencial or other
-ld structure is walid only if zero is returned
+0 if success, -1 init error, -3 no homedir, -4 invalid credential or other
+ld structure is valid only if zero is returned
 
 *************************************************************************/
 int
@@ -59,20 +56,41 @@ ldapLogin (LDAP ** ld, int nomod)
   version = LDAP_VERSION3;
   ldap_set_option (*ld, LDAP_OPT_PROTOCOL_VERSION, &version);
   gettimeofday (&current, NULL);
-  //if we have anonymous credencial or operation is write or timeout exided
-  //we need to get new credencial
-  if (nomod == WRITE_OP || logindata.type == 0
-      || current.tv_sec > logindata.expire.tv_sec + EXTIME)
+  //if we have anonymous credential or timeout exited
+  //we need to get new credential (bnegative timeout  -> write passwd cache)
+
+  if (GetDefaultVmailPcache () < 0)
+    {
+      if (logindata.type == 0
+         || current.tv_sec >
+         logindata.expire.tv_sec + abs (GetDefaultVmailPcache ()))
+       {
+         if (0 != get_ldap_login (&logindata))
+           {
+             ldap_unbind (*ld);        //free ldap structure
+             return (-3);
+           }
+       }
+    }
+  else
+    //if we have anonymous credential or operation is write or timeout exited
+    //we need to get new credential
     {
-      if (0 != get_ldap_login (&logindata))
+      if (nomod == WRITE_OP || logindata.type == 0
+         || current.tv_sec >
+         logindata.expire.tv_sec + abs (GetDefaultVmailPcache ()))
        {
-         ldap_unbind (*ld);    //free ldap structure
-         return (-3);
+         if (0 != get_ldap_login (&logindata))
+           {
+             ldap_unbind (*ld);        //free ldap structure
+             return (-3);
+           }
        }
     }
   if (ldap_simple_bind_s (*ld, logindata.binddn, logindata.bindpw))
     {
       ldap_unbind (*ld);       //free ldap structure
+      logindata.type = 0;      //set as anonymous login
       return (-4);
     }
 
@@ -81,67 +99,17 @@ ldapLogin (LDAP ** ld, int nomod)
   return (0);
 }
 
-//user dialog for credencial 
+//user dialog for credential 
 
 int
 get_ldap_login (bindCredencial * ldata)
 {
-#define progConfigDir "/.vmaiL/"
-#define progConfigLdata "ldap_login"
 
-  char *home, *ssh, *confdir;
-  FILE *default_admin;
-  char *defaultAdminFile;
   char *defaultDN = NULL;
   char *PW, *DN;
   newtComponent form, Bok, Bcancel, Banon, label, answer, DNentry, PWentry;
 
-  home = strdup (getenv ("HOME"));
-  if (home == NULL)
-    return (-1);
-  asprintf (&confdir, "%s%s", home, progConfigDir);
-  //confdir = malloc ((strlen (home) + strlen (progConfigDir)) * sizeof (char));
-  //strcpy (confdir, home);
-  //strcat (confdir, progConfigDir);
-  free (home);
-  mkdir (confdir, 0700);
-
-  ssh = NULL;
-  home = getenv ("SSH_CLIENT");
-  if (home != NULL)
-    {
-      int i;
-      asprintf (&ssh, "%s%s", confdir, home);
-      //ssh = malloc ((strlen (home) + strlen (confdir)) * sizeof (char));
-      //strcpy (ssh, confdir);  //configdir
-      //strcat (ssh, home);     //and ssh dir
-      //cut ssh_client after space
-      for (i = strlen (confdir); *home != ' '; home++, i++);
-      *(ssh + i) = '/';
-      *(ssh + i + 1) = 0;
-
-      if (0 == mkdir (ssh, 0700))      //new ssh .. do copy of base config
-       {
-         //TODO copy from confdir to ssh 
-         // cp $confdir $ss 
-       }
-      //TODO only default config is used ..   
-      //confdir=ssh;  
-    }
-  asprintf (&defaultAdminFile, "%s%s", confdir, progConfigLdata);
-  if (NULL != defaultAdminFile)
-    {
-      default_admin = fopen (defaultAdminFile, "r");
-      if (default_admin != NULL)
-       {
-         defaultDN = malloc (100 * sizeof (char));
-         if (defaultDN != NULL)
-           fgets (defaultDN, 99, default_admin);
-         fclose (default_admin);
-       }
-      else
-       defaultDN = NULL;
-    }
+  defaultDN = GetDefaultVmailAdmin ();
   newtCenteredWindow (65, 10, "LDAP login");
   form = newtForm (NULL, NULL, 0);
   label = newtLabel (0, 2, "Admin DN:");
@@ -184,14 +152,6 @@ get_ldap_login (bindCredencial * ldata)
   ldata->type = 1;             //not anonymous
   newtFormDestroy (form);
   newtPopWindow ();
-  if (NULL != defaultAdminFile)
-    {
-      default_admin = fopen (defaultAdminFile, "w");
-      if (default_admin != NULL)
-       {
-         fprintf (default_admin, "%s", ldata->binddn);
-         fclose (default_admin);
-       }
-    }
+  SetDefaultVmailAdmin (ldata->binddn);
   return (0);
 }
index e223da83a0392e5bbb73c836aa698b4c7091928d..008f3e0ce3334b5e5acc22d3916fe2105d3aa502 100644 (file)
@@ -1,4 +1,3 @@
 #define READ_OP 1
 #define WRITE_OP 0
-int ldapLogin (LDAP ** ld,int type);
-
+int ldapLogin (LDAP ** ld, int type);
index efb9c60d67c5a8647a6f6097b9d098b6106d6bf5..630a26d7004edf370365590446c4c790253d44ab 100644 (file)
@@ -77,14 +77,14 @@ ldapPass (char *dn, char *pass)
     case (0):
       break;
     case (-1):
-      infoWindow ("VMAIL password", "LDAP init error", 1);
+      infoWindow ("Password change", "LDAP init error", 1);
       return (1);
     case (-3):
-      infoWindow ("VMAIL password",
+      infoWindow ("Password change",
                  "Couldn't bind to server, operation canceled", 1);
       return 1;
     default:
-      infoWindow ("VMAIL password",
+      infoWindow ("Password change",
                  "Couldn't bind to server, invalid credencial or other error",
                  1);
       return 1;
@@ -92,11 +92,11 @@ ldapPass (char *dn, char *pass)
   int ecode;
   if (0 == (ecode = ldap_modify_s (ld, dn, addAttr0)))
     {
-      infoWindow ("VMAIL password", "Password ok", 100);
+      infoWindow ("Password change", "Password updated successfully", 100);
       return (0);
     }
   else
-    infoWindow ("VMAIL password", ldap_err2string (ecode), 1);
+    infoWindow ("Password change", ldap_err2string (ecode), 1);
   return (1);
 
 }
diff --git a/vmail.c b/vmail.c
index c67f81df865b1b2242fcbafecbe9d6d34d74c791..61128b78be0356227dda3a159711672a8d3bde8b 100644 (file)
--- a/vmail.c
+++ b/vmail.c
@@ -46,7 +46,7 @@ main ()
     {
       char *menuContents[] = { "Add new mail account",
        "Search & Edit account",
-       "*Admin password change ",
+       "Admin password change ",
        "*Setup",
        "End", NULL
       };
@@ -67,6 +67,9 @@ main ()
        case (1):
          doEdit ();
          break;
+       case (2):
+         selectDN ();
+         break;
        }
     }
   newtFinished ();
@@ -303,12 +306,14 @@ renewEdit:
          co = (int) newtListboxGetCurrent (List1);
          data =
            ChangeEntry ("Novy forward:", &(vmail->forwardValues[co]), 1);
-         if (strlen (data) == 0)       //null length forward to the end of list
-           {
-             for (count = co; vmail->forwardValues[count] != NULL; count++)
-               vmail->forwardValues[count] = vmail->forwardValues[count + 1];
-             vmail->forwardValues[count - 1] = data;
-           }
+         if (data != NULL)
+           if (strlen (data) == 0)     //null length forward to the end of list
+             {
+               for (count = co; vmail->forwardValues[count] != NULL; count++)
+                 vmail->forwardValues[count] =
+                   vmail->forwardValues[count + 1];
+               vmail->forwardValues[count - 1] = data;
+             }
          if (data != vmail->forwardValues[co])
            {
              if (data != NULL && strlen (data) > 0)
@@ -339,12 +344,13 @@ renewEdit:
          realedit = 1;
          co = (int) newtListboxGetCurrent (List2);
          data = ChangeEntry ("Novy alias:", &(vmail->aliasValues[co]), 1);
-         if (strlen (data) == 0)       //null length forward to the end of list
-           {
-             for (count = co; vmail->aliasValues[count] != NULL; count++)
-               vmail->aliasValues[count] = vmail->aliasValues[count + 1];
-             vmail->aliasValues[count - 1] = data;
-           }
+         if (data != NULL)
+           if (strlen (data) == 0)     //null length forward to the end of list
+             {
+               for (count = co; vmail->aliasValues[count] != NULL; count++)
+                 vmail->aliasValues[count] = vmail->aliasValues[count + 1];
+               vmail->aliasValues[count - 1] = data;
+             }
          if (data != vmail->aliasValues[co])
            {
              if (data != NULL && strlen (data) > 0)
@@ -377,14 +383,15 @@ renewEdit:
            infoWindow ("add forward", "out of mem", 1);
          else
            {
-             ChangeEntry ("Novy forward:", newdata, 0);
-             if (strlen (*newdata) > 0)
-               {
-                 vmail->forwardValues = newdata;
-                 newtFormDestroy (form);
-                 realedit = 1;
-                 goto renewEdit;
-               }
+             if (NULL != (ChangeEntry ("Novy forward:", newdata, 0)))
+               if (strlen (*newdata) > 0)
+                 {
+                   vmail->forwardValues = newdata;
+                   newtFormDestroy (form);
+                   realedit = 1;
+                   goto renewEdit;
+                 }
+             continue;
            }
          break;
        }
@@ -395,14 +402,15 @@ renewEdit:
            infoWindow ("add alias", "out of mem", 1);
          else
            {
-             ChangeEntry ("Novy alias:", newdata, 0);
-             if (strlen (*newdata) > 0)
-               {
-                 vmail->aliasValues = newdata;
-                 newtFormDestroy (form);
-                 realedit = 1;
-                 goto renewEdit;
-               }
+             if (NULL != (ChangeEntry ("Novy alias:", newdata, 0)))
+               if (strlen (*newdata) > 0)
+                 {
+                   vmail->aliasValues = newdata;
+                   newtFormDestroy (form);
+                   realedit = 1;
+                   goto renewEdit;
+                 }
+             continue;
            }
          break;
        }
@@ -466,6 +474,10 @@ ChangeEntry (char *wname, char **data, int type)
       free (*data);
       *data = newdata;
     }
+  if (what == -1)
+    {
+      return (NULL);
+    }
   return (newdata);
 }
 
@@ -568,30 +580,30 @@ ldapEdit (vmailEntry * vmail)
       if (addAttrx[i] == "mailAlternateAddress")
        {
          addAttr0[i]->mod_values = vmail->aliasValues;
-         if(vmail->aliasValues!=NULL)
-         while (*vmail->aliasValues != NULL)
-           {
-             if (strlen (*vmail->aliasValues) == 0)
-               {
-                 *vmail->aliasValues = NULL;
-                 break;
-               }
-             (vmail->aliasValues)++;
-           }
+         if (vmail->aliasValues != NULL)
+           while (*vmail->aliasValues != NULL)
+             {
+               if (strlen (*vmail->aliasValues) == 0)
+                 {
+                   *vmail->aliasValues = NULL;
+                   break;
+                 }
+               (vmail->aliasValues)++;
+             }
        }
       if (addAttrx[i] == "mailForwardingAddress")
        {
          addAttr0[i]->mod_values = vmail->forwardValues;
-         if(vmail->forwardValues!=NULL)
-         while (*vmail->forwardValues != NULL)
-           {
-             if (strlen (*vmail->forwardValues) == 0)
-               {
-                 *vmail->forwardValues = NULL;
-                 break;
-               }
-             (vmail->forwardValues)++;
-           }
+         if (vmail->forwardValues != NULL)
+           while (*vmail->forwardValues != NULL)
+             {
+               if (strlen (*vmail->forwardValues) == 0)
+                 {
+                   *vmail->forwardValues = NULL;
+                   break;
+                 }
+               (vmail->forwardValues)++;
+             }
        }
 
     }
index 23acdf194777b1ad93477286d85ee60ac4ea0e67..ad5f5e64cb6fa2f4a1aa37019272b25fcffb4ee5 100644 (file)
@@ -1,6 +1,12 @@
 #include <newt.h>
 #include <stdio.h>
+#include <ldap.h>
 #include "vmailHelper.h"
+#include "ldaplogin.h"
+#include "ldappass.h"
+#include <sys/stat.h>
+#include <sys/types.h>
+
 int
 infoWindow (char *wname, char *wmesg, int type)
 {
@@ -27,3 +33,85 @@ infoWindow (char *wname, char *wmesg, int type)
   newtFormDestroy (form);
   return (0);
 }
+
+int
+selectDN ()
+{
+  char *entryValue;
+  newtComponent form, label, button, entry, cancel, answer;
+  LDAP *ld;
+  struct timeval timeout;
+  LDAPMessage *result;
+  newtCenteredWindow (65, 10, "Select DN");
+  form = newtForm (NULL, NULL, 0);
+  label = newtTextbox (1, 0, 50, 3, NEWT_FLAG_WRAP);
+  newtTextboxSetText (label, "Enter DN or uid/cn to search for DN");
+  newtFormAddComponent (form, label);
+
+  entry = newtEntry (6, 2, NULL, 53, &entryValue,
+                    NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
+  newtFormAddComponent (form, entry);
+  button = newtButton (19, 6, "Ok");
+  newtFormAddComponent (form, button);
+  cancel = newtButton (40, 6, "Cancel");
+  newtFormAddComponent (form, cancel);
+  answer = newtRunForm (form);
+  if (answer == cancel)
+    {
+      newtFormDestroy (form);
+      newtPopWindow ();
+      return (0);
+    }
+  switch (ldapLogin (&ld, READ_OP))
+    {
+    case (0):
+      break;
+    case (-1):
+      infoWindow ("VMAIL account search...", "LDAP init error", 1);
+      newtFormDestroy (form);
+      newtPopWindow ();
+      return (1);
+    case (-3):
+      infoWindow ("VMAIL account search...",
+                 "Couldn't bind to server, operation canceled", 1);
+      newtFormDestroy (form);
+      newtPopWindow ();
+      return 1;
+    default:
+      infoWindow ("VMAIL account search...",
+                 "Couldn't bind to server, invalid credencial or other error",
+                 1);
+      newtFormDestroy (form);
+      newtPopWindow ();
+      return 1;
+    }
+  timeout.tv_sec = 10;
+  timeout.tv_usec = 0;
+  int ecode;
+  ecode = ldap_search_st
+    (ld, entryValue, LDAP_SCOPE_BASE, "objectClass=*", NULL, 0, &timeout,
+     &result);
+  if (ecode != 0 && ecode != LDAP_INVALID_DN_SYNTAX
+      && ecode != LDAP_NO_SUCH_OBJECT)
+    {
+      infoWindow ("VMAIL account search...", ldap_err2string (ecode), 1);
+      ldap_unbind_s (ld);
+      newtFormDestroy (form);
+      newtPopWindow ();
+      return 1;
+    }
+  if (ecode == LDAP_NO_SUCH_OBJECT || ecode == LDAP_INVALID_DN_SYNTAX || 1 != ldap_count_entries (ld, result)) //othervise DN is ok 
+    {
+      //TODO aditional uid and cn search for DN
+      infoWindow ("VMAIL account search...", "Unable to find DN", 1);
+      newtFormDestroy (form);
+      newtPopWindow ();
+      return 1;
+    }
+//entryValue DN for operatrion
+//TODO ....
+  passBox (entryValue);
+  newtFormDestroy (form);
+  newtPopWindow ();
+  return (0);
+}
index a862c93d19323065039053f06763a422c8cc38dc..9019ac488b929abe4c53f0a3d69cc706671b940a 100644 (file)
@@ -1,3 +1,3 @@
 int newAccount (void);
 int infoWindow (char *wname, char *wmesg, int type);
-
+int selectDN (void);
index 2dfe6b38a12d8fd1b9ab6c0465d98fcbae5facd6..d0c6b15301975a132d7736daafb1da6aa73f1fce 100644 (file)
@@ -15,7 +15,8 @@
 #define progConfigVPath "vmail_path"
 #define VmailPath "/home/vmail/"
 #define progConfigVtree "vmail_tree"
-#define VmailTree "ou=vmail,ou=internet,dc=MYDOMAYN,dc=sk"
+#define progConfigPcache "vmail_password_cache"
+#define VmailTree "ou=vmail,ou=internet,dc=MYDOMAIN,dc=info"
 
 typedef struct setupData0
 {
@@ -29,9 +30,14 @@ typedef struct setupData0
   char *defaultVmailPathFile;  //path to file with path for mailboxes
   char *defaultVmailPathString;
 
-  char *defaultVmailTreeFile;
+  char *defaultVmailTreeFile;  //ldap subtree for vmail users
   char *defaultVmailTreeString;
 
+  char *defaultVmailPcacheFile;
+  char *defaultVmailPcacheString;      //timeout (seconds) for password cache
+  //no timeout, always get password. 
+  // 300 = 5 min timeout (only read password)
+  //-300 = 5 min timeout read and write password
 } setupData;
 
 char *getFromFile (char *filename);
@@ -93,6 +99,17 @@ get_setup (setupData * s)
       s->defaultVmailTreeString = strdup (VmailTree);
       setToFile (s->defaultVmailTreeFile, s->defaultVmailTreeString);
     }
+
+  asprintf (&(s->defaultVmailPcacheFile), "%s%s", s->confdir,
+           progConfigPcache);
+  s->defaultVmailPcacheString = getFromFile (s->defaultVmailPcacheFile);
+  if (s->defaultVmailPcacheString == NULL)
+    {
+      s->defaultVmailPcacheString = "600";
+      setToFile (s->defaultVmailPcacheFile, s->defaultVmailPcacheString);
+    }
+
+
   return (0);
 }
 
@@ -146,3 +163,24 @@ GetDefaultVmailSubtree ()
 {
   return (SetupDATA.defaultVmailTreeString);
 }
+
+char *
+GetDefaultVmailAdmin ()
+{
+  return (SetupDATA.defaultAdminString);
+}
+
+int
+SetDefaultVmailAdmin (char *DN)
+{
+  free (SetupDATA.defaultAdminString);
+  SetupDATA.defaultAdminString = strdup (DN);
+  setToFile (SetupDATA.defaultAdminFile, SetupDATA.defaultAdminString);
+  return (0);
+}
+
+int
+GetDefaultVmailPcache ()
+{
+  return (atoi (SetupDATA.defaultVmailPcacheString));
+}
index 90bd5dadbb7594dfd515aa04c8b996f0075470b1..0a81ee342dfe7bde0d7b7971ff6828d734224d15 100644 (file)
@@ -1,5 +1,6 @@
 int GetSetup (void);
-char * GetDefaultVmailPath (void);
-char * GetDefaultVmailSubtree (void);
-
-
+char *GetDefaultVmailPath (void);
+char *GetDefaultVmailSubtree (void);
+int GetDefaultVmailPcache (void);
+int SetDefaultVmailAdmin (char *DN);
+char *GetDefaultVmailAdmin (void);