+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.
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);
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 ();
-//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>
#include <sys/time.h>
#include <time.h>
#include "ldaplogin.h"
-
+#include "vmailsetup.h"
typedef struct bindCredencial0
{
char *server;
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);
/**************************************************************************
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
version = LDAP_VERSION3;
ldap_set_option (*ld, LDAP_OPT_PROTOCOL_VERSION, &version);
gettimeofday (¤t, 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);
}
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:");
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);
}
#define READ_OP 1
#define WRITE_OP 0
-int ldapLogin (LDAP ** ld,int type);
-
+int ldapLogin (LDAP ** ld, int type);
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;
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);
}
{
char *menuContents[] = { "Add new mail account",
"Search & Edit account",
- "*Admin password change ",
+ "Admin password change ",
"*Setup",
"End", NULL
};
case (1):
doEdit ();
break;
+ case (2):
+ selectDN ();
+ break;
}
}
newtFinished ();
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)
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)
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;
}
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;
}
free (*data);
*data = newdata;
}
+ if (what == -1)
+ {
+ return (NULL);
+ }
return (newdata);
}
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)++;
+ }
}
}
#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)
{
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);
+}
int newAccount (void);
int infoWindow (char *wname, char *wmesg, int type);
-
+int selectDN (void);
#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
{
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);
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);
}
{
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));
+}
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);