From: Peter Popovec Date: Thu, 7 Apr 2005 12:09:00 +0000 (+0200) Subject: admin password, new implementation X-Git-Tag: 0.2.1^0 X-Git-Url: http://zub.fei.tuke.sk/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0452f8c3ae606a523c04dcc4edca5504828673a9;p=ldapvmail admin password, new implementation compilation warning clean fix initialization for Balias and Bforward buttons --- diff --git a/debian/changelog b/debian/changelog index bfc643f..3ff8677 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +ldapvmail (0.2.1) unstable; urgency=low + + * admin password, new implementation + * compilation warning clean + * fix initialization for Balias and Bforward buttons + + -- Peter Popovec Thu, 7 Apr 2005 13:55:05 +0200 + ldapvmail (0.2) unstable; urgency=low * Default is Maildir not mailbox diff --git a/debian/copyright b/debian/copyright index 57658b9..dea16ab 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,9 +1,8 @@ -This package was debianized by Peter Popovec on +By Peter Popovec on Sun, 30 Jan 2005 12:15:51 +0100. It was downloaded from http://zub.fei.tuke.sk/local.packages -Upstream Author(s): Peter Popovec Copyright: diff --git a/debian/ex.package.doc-base b/debian/ex.package.doc-base deleted file mode 100644 index a878f0b..0000000 --- a/debian/ex.package.doc-base +++ /dev/null @@ -1,22 +0,0 @@ -Document: ldapvmail -Title: Debian ldapvmail Manual -Author: -Abstract: This manual describes what ldapvmail is - and how it can be used to - manage online manuals on Debian systems. -Section: unknown - -Format: debiandoc-sgml -Files: /usr/share/doc/ldapvmail/ldapvmail.sgml.gz - -Format: postscript -Files: /usr/share/doc/ldapvmail/ldapvmail.ps.gz - -Format: text -Files: /usr/share/doc/ldapvmail/ldapvmail.text.gz - -Format: HTML -Index: /usr/share/doc/ldapvmail/html/index.html -Files: /usr/share/doc/ldapvmail/html/*.html - - diff --git a/ldapadd.c b/ldapadd.c index 7319a31..2f69955 100644 --- a/ldapadd.c +++ b/ldapadd.c @@ -17,7 +17,8 @@ newAccount () { newtComponent form, label, Bok, Bcancel, PWentry, DNentry, answer; struct newtExitStruct es; - char *DN, *PW, *GN, *SN; + const char *DN, *PW, *GN, *SN; + char *newDN; LDAP *ld; char *addAttrxValue[8]; @@ -181,7 +182,7 @@ newAccount () addAttr0[i]->mod_values[3] = strdup ("inetOrgPerson"); addAttr0[i]->mod_values[4] = strdup ("qmailUser"); addAttr0[i]->mod_values[5] = NULL; - asprintf (&DN, "uid=%s,%s", addAttrxValue[0], GetDefaultVmailSubtree ()); + asprintf (&newDN, "uid=%s,%s", addAttrxValue[0], GetDefaultVmailSubtree ()); switch (ldapLogin (&ld, WRITE_OP)) { @@ -201,7 +202,7 @@ newAccount () return 1; } int ecode; - if (0 == (ecode = ldap_add_s (ld, DN, addAttr0))) + if (0 == (ecode = ldap_add_s (ld, newDN, addAttr0))) { infoWindow ("VMAIL account add", "User ok", 100); return (0); diff --git a/ldaplogin.c b/ldaplogin.c index 209b091..bd1a92a 100644 --- a/ldaplogin.c +++ b/ldaplogin.c @@ -35,6 +35,8 @@ 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. +WRITE_OP_CACHED no timeout is checcked, if non anonymous credencial is +available, no new password is readed return value: 0 if success, -1 init error, -3 no homedir, -4 invalid credential or other @@ -56,41 +58,42 @@ ldapLogin (LDAP ** ld, int nomod) version = LDAP_VERSION3; ldap_set_option (*ld, LDAP_OPT_PROTOCOL_VERSION, &version); gettimeofday (¤t, NULL); - //if we have anonymous credential or timeout exited - //we need to get new credential (bnegative timeout -> write passwd cache) - - if (GetDefaultVmailPcache () < 0) + if (nomod != WRITE_OP_CACHED || logindata.type == 0) { - if (logindata.type == 0 - || current.tv_sec > - logindata.expire.tv_sec + abs (GetDefaultVmailPcache ())) + //if we have anonymous credential or timeout exited + //we need to get new credential (bnegative timeout -> write passwd cache) + + if (GetDefaultVmailPcache () < 0) { - if (0 != get_ldap_login (&logindata)) + if (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); + } } } - } - else - //if we have anonymous credential or operation is write or timeout exited - //we need to get new credential - { - if (nomod == WRITE_OP || logindata.type == 0 - || current.tv_sec > - logindata.expire.tv_sec + abs (GetDefaultVmailPcache ())) + 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 || 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 + logindata.type = 0; //set as anonymous login return (-4); } @@ -105,8 +108,8 @@ int get_ldap_login (bindCredencial * ldata) { - char *defaultDN = NULL; - char *PW, *DN; + const char *defaultDN = NULL; + const char *PW, *DN; newtComponent form, Bok, Bcancel, Banon, label, answer, DNentry, PWentry; defaultDN = GetDefaultVmailAdmin (); diff --git a/ldaplogin.h b/ldaplogin.h index 008f3e0..4c20526 100644 --- a/ldaplogin.h +++ b/ldaplogin.h @@ -1,3 +1,4 @@ #define READ_OP 1 #define WRITE_OP 0 +#define WRITE_OP_CACHED 2 int ldapLogin (LDAP ** ld, int type); diff --git a/ldappass.c b/ldappass.c index 630a26d..fa6d192 100644 --- a/ldappass.c +++ b/ldappass.c @@ -12,11 +12,11 @@ #include "vmailHelper.h" int -passBox (char *dn) +passBox (char *dn, LDAP * ld) { newtComponent form, Label, entry1, entry2, button, cancel, answer; - char *pass1, *pass2; - + const char *pass1, *pass2; + char *pass; newtOpenWindow (4, 8, 74, 10, "Change password for DN:"); form = newtForm (NULL, NULL, 0); entry1 = newtEntry (11, 3, NULL, 32, &pass1, NEWT_FLAG_PASSWORD); @@ -49,7 +49,8 @@ passBox (char *dn) "Sorry, passwords do not match", 1); continue; } - ldapPass (dn, pass1); + pass = strdup (pass1); + ldapPass (dn, pass, ld); break; } } @@ -59,9 +60,9 @@ passBox (char *dn) } int -ldapPass (char *dn, char *pass) +ldapPass (char *dn, char *pass, LDAP * ld) { - LDAP *ld; +// LDAP *ld; LDAPMod *addAttr0[2]; addAttr0[0] = malloc (sizeof (LDAPMod)); addAttr0[1] = NULL; @@ -71,23 +72,25 @@ ldapPass (char *dn, char *pass) asprintf (&addAttr0[0]->mod_values[0], "{crypt}%s", crypt (pass, "$!$pemasksk")); addAttr0[0]->mod_values[1] = NULL; - - switch (ldapLogin (&ld, WRITE_OP)) + if (ld == NULL) { - case (0): - break; - case (-1): - infoWindow ("Password change", "LDAP init error", 1); - return (1); - case (-3): - infoWindow ("Password change", - "Couldn't bind to server, operation canceled", 1); - return 1; - default: - infoWindow ("Password change", - "Couldn't bind to server, invalid credencial or other error", - 1); - return 1; + switch (ldapLogin (&ld, WRITE_OP)) + { + case (0): + break; + case (-1): + infoWindow ("Password change", "LDAP init error", 1); + return (1); + case (-3): + infoWindow ("Password change", + "Couldn't bind to server, operation canceled", 1); + return 1; + default: + 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))) diff --git a/ldappass.h b/ldappass.h index e186e8e..686a2c2 100644 --- a/ldappass.h +++ b/ldappass.h @@ -1,2 +1,2 @@ -int ldapPass (char *dn, char *pass); -int passBox (char *dn); +int ldapPass (char *dn, char *pass,LDAP *ld); +int passBox (char *dn,LDAP *ld); diff --git a/vmail.c b/vmail.c index 61128b7..197a9ad 100644 --- a/vmail.c +++ b/vmail.c @@ -11,7 +11,7 @@ #include "ldaplogin.h" #include "vmailHelper.h" #include "vmailsetup.h" - +#include "ldappass.h" typedef struct vmailEntry0 { @@ -27,15 +27,13 @@ typedef struct vmailEntry0 int ldapEdit (vmailEntry * vmail); int doEdit0 (vmailEntry * vmail); -int ldapPass (char *dn, char *pass); -int passBox (char *dn); int ChangeEntry0 (char *wname, char *olddata, char **data, int type); char *ChangeEntry (char *wname, char **data, int type); char *getSearchFilter (void); int doEdit (void); int -main () +main (int argc, char *argv[]) { int rc, textWidth; @@ -220,6 +218,7 @@ renewEdit: if (vmail->forwardValues != NULL) { + Bforward = NULL; Label0 = newtLabel (1, 6, "Forwarded to:"); newtFormAddComponent (form, Label0); List1 = @@ -241,6 +240,7 @@ renewEdit: } if (vmail->aliasValues != NULL) { + Balias=NULL; Label0 = newtLabel (1, 9, "Aliases:"); newtFormAddComponent (form, Label0); List2 = @@ -268,7 +268,6 @@ renewEdit: { int co; char *data = NULL; - realedit = 1; co = (int) newtListboxGetCurrent (List0); cycle1: { @@ -295,6 +294,7 @@ renewEdit: { if (strlen (data) == 0) goto cycle1; + realedit = 1; newtListboxSetEntry (List0, co, data); } } @@ -375,7 +375,7 @@ renewEdit: } if (answer == Bpass) - passBox (vmail->dn); + passBox (vmail->dn, NULL); if (answer == Bforward) { char **newdata; @@ -432,7 +432,7 @@ int ChangeEntry0 (char *wname, char *olddata, char **data, int type) { newtComponent form, entry, cancel, button, answer, add = NULL; - char *entryValue; + const char *entryValue; newtOpenWindow (4, 8, 74, 10, wname); form = newtForm (NULL, NULL, 0); entry = newtEntry (16, 1, olddata, 40, &entryValue, @@ -485,7 +485,8 @@ char * getSearchFilter () { newtComponent form, label, Bcancel, Bok, POPentry, MAILentry, answer; - char *DN, *PW, *filter; + const char *DN, *PW; + char *filter; newtCenteredWindow (65, 12, "Search account"); form = newtForm (NULL, NULL, 0); diff --git a/vmailHelper.c b/vmailHelper.c index ad5f5e6..4a1ae76 100644 --- a/vmailHelper.c +++ b/vmailHelper.c @@ -6,7 +6,8 @@ #include "ldappass.h" #include #include - +#include "vmailsetup.h" +#include int infoWindow (char *wname, char *wmesg, int type) { @@ -37,7 +38,8 @@ infoWindow (char *wname, char *wmesg, int type) int selectDN () { - char *entryValue; + const char *entryValue; + char *DN; newtComponent form, label, button, entry, cancel, answer; LDAP *ld; struct timeval timeout; @@ -47,8 +49,8 @@ selectDN () 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, + DN = GetDefaultVmailAdmin (); + entry = newtEntry (6, 2, DN, 53, &entryValue, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); newtFormAddComponent (form, entry); button = newtButton (19, 6, "Ok"); @@ -62,6 +64,20 @@ selectDN () newtPopWindow (); return (0); } + if (entryValue == NULL) + { + newtFormDestroy (form); + newtPopWindow (); + return (0); + + } + if (strlen (entryValue) == 0) + { + newtFormDestroy (form); + newtPopWindow (); + return (0); + + } switch (ldapLogin (&ld, READ_OP)) { case (0): @@ -108,9 +124,8 @@ selectDN () newtPopWindow (); return 1; } -//entryValue DN for operatrion -//TODO .... - passBox (entryValue); + DN = strdup (entryValue); + passBox (DN, ld); newtFormDestroy (form); newtPopWindow (); return (0);