From: Peter Popovec Date: Mon, 14 Feb 2005 10:07:00 +0000 (+0100) Subject: Default is Maildir not mailbox X-Git-Tag: 0.1-2^0 X-Git-Url: http://zub.fei.tuke.sk/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e047ff276eef67d448605c55f3938dcad5a42968;p=ldapvmail 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 --- diff --git a/debian/changelog b/debian/changelog index 97a6e0d..a383ddc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 + + -- Sat, 12 Feb 2005 14:21:34 +0100 + ldapvmail (0.1-1) unstable; urgency=low * Initial Release. diff --git a/ldapadd.c b/ldapadd.c index e000cdf..7319a31 100644 --- 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 (); diff --git a/ldaplogin.c b/ldaplogin.c index 4eaae50..209b091 100644 --- a/ldaplogin.c +++ b/ldaplogin.c @@ -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 #include @@ -15,7 +13,7 @@ #include #include #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 (¤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); } @@ -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); } diff --git a/ldaplogin.h b/ldaplogin.h index e223da8..008f3e0 100644 --- a/ldaplogin.h +++ b/ldaplogin.h @@ -1,4 +1,3 @@ #define READ_OP 1 #define WRITE_OP 0 -int ldapLogin (LDAP ** ld,int type); - +int ldapLogin (LDAP ** ld, int type); diff --git a/ldappass.c b/ldappass.c index efb9c60..630a26d 100644 --- a/ldappass.c +++ b/ldappass.c @@ -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 c67f81d..61128b7 100644 --- 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)++; + } } } diff --git a/vmailHelper.c b/vmailHelper.c index 23acdf1..ad5f5e6 100644 --- a/vmailHelper.c +++ b/vmailHelper.c @@ -1,6 +1,12 @@ #include #include +#include #include "vmailHelper.h" +#include "ldaplogin.h" +#include "ldappass.h" +#include +#include + 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); +} diff --git a/vmailHelper.h b/vmailHelper.h index a862c93..9019ac4 100644 --- a/vmailHelper.h +++ b/vmailHelper.h @@ -1,3 +1,3 @@ int newAccount (void); int infoWindow (char *wname, char *wmesg, int type); - +int selectDN (void); diff --git a/vmailsetup.c b/vmailsetup.c index 2dfe6b3..d0c6b15 100644 --- a/vmailsetup.c +++ b/vmailsetup.c @@ -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)); +} diff --git a/vmailsetup.h b/vmailsetup.h index 90bd5da..0a81ee3 100644 --- a/vmailsetup.h +++ b/vmailsetup.h @@ -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);