

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
2 messages in net.sourceforge.lists.courier-maildropFwd: [maildropl] static base + create...| From | Sent On | Attachments |
|---|---|---|
| Chris Masters | Sep 29, 2003 6:50 am | |
| Chris Masters | Sep 29, 2003 7:47 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Fwd: [maildropl] static base + create homedir/maildir/sub-maildir on-the-fly patch | Actions... |
|---|---|---|
| From: | Chris Masters (roti...@yahoo.com) | |
| Date: | Sep 29, 2003 7:47:00 am | |
| List: | net.sourceforge.lists.courier-maildrop | |
Helps if I attach it.
Note: forwarded message attached.
__________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com
Hi all,
Attached is the patch that can do the following:
Use a static base specified in ldap and mysql configs. Relative paths based on this are stored in mysql/ldap. With this patch you have to use a static base or maildrop will fail.
Based on Eriks patch, it also create (on-the-fly) home directories if they don't exist and maildir/sub-maildirs if they don't exist. Good for virtual users.
This is NOT fully tested so use at your own risk. I'm also not sure about the security compilcations that this may cause.
Thanks to Erik.
Chris
__________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com
------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf
_______________________________________________ Courier-maildrop mailing list Cour...@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/courier-maildrop
# diff -c maildir.C.old maildir.C *** maildir.C.old Sun Sep 28 15:31:42 2003 --- maildir.C Sun Sep 28 17:10:34 2003 *************** *** 51,56 **** --- 51,60 ---- { Buffer dirname; Buffer subdirname; + #if USEMYSQL + char *tempname, *slash; + struct stat stat_buf2; + #endif struct stat stat_buf;
int c;
***************
*** 59,64 ****
--- 63,134 ----
dirname=name;
c=dirname.pop();
if (c != SLASH_CHAR) dirname.push(c); // Strip trailing /
+ #if USEMYSQL
+ if ( stat( (const char *)dirname, &stat_buf ) ||
+ ! S_ISDIR(stat_buf.st_mode) )
+ {
+ tempname = strdup(name);
+ slash=tempname;
+ while(*slash == '/')
+ slash++;
+
+ while((slash = strchr(slash, '/')))
+ {
+ *slash = '\0';
+
+ if(stat( (const char *)tempname, &stat_buf2 ) ||
+ ! S_ISDIR(stat_buf2.st_mode))
+ if(mkdir(tempname, 0755))
+ {
+ fprintf(stderr, "Could not make
directory %s\n", tempname);
+ return(0);
+ }
+ else
+ fprintf(stderr, "Made directory %s\n",
tempname);
+
+
+ *slash++ = '/';
+ while(*slash == '/')
+ slash++;
+ }
+ free(tempname);
+ }
+
+ if(chdir(name))
+ {
+ fprintf(stderr, "Could not change to directory %s\n", name);
+ return(0);
+ }
+
+ if(stat( "new", &stat_buf2 ) ||
+ ! S_ISDIR(stat_buf2.st_mode))
+ {
+ if(mkdir("new", 0755))
+ {
+ fprintf(stderr, "Could not make directory %s/new\n",
name);
+ return(0);
+ }
+ }
+ if(stat( "cur", &stat_buf2 ) ||
+ ! S_ISDIR(stat_buf2.st_mode))
+ {
+ if(mkdir("cur", 0755))
+ {
+ fprintf(stderr, "Could not make directory
%s/cur\n", name);
+ return(0);
+ }
+ }
+ if(stat( "tmp", &stat_buf2 ) ||
+ ! S_ISDIR(stat_buf2.st_mode))
+ {
+ if(mkdir("tmp", 0755))
+ {
+ fprintf(stderr, "Could not make directory
%s/tmp\n", name);
+ return(0);
+ }
+ }
+ #endif
+
subdirname=dirname;
subdirname += "/tmp";
subdirname += '\0';
# diff -c main.C.old main.C *** main.C.old Sun Sep 28 16:05:30 2003 --- main.C Sun Sep 28 16:54:05 2003 *************** *** 759,769 **** if (VerboseLevel() > 1) merr << "maildrop: Changing to " << h << "\n";
if (chdir(h) < 0) { errexit=EX_TEMPFAIL; ! throw "Unable to change to home directory."; } recipe=".mailfilter";
if ( stat(".", &buf) < 0 || --- 759,819 ---- if (VerboseLevel() > 1) merr << "maildrop: Changing to " << h << "\n";
+ #if USEMYSQL
+ char *tempname, *slash;
+ struct stat stat_buf2;
+ #endif
+
+
if (chdir(h) < 0)
{
+ #if USEMYSQL
+ //create home directory if it does not exist
+ if (VerboseLevel() > 1)
+ merr << "maildrop: Creating directory " << h <<
"\n";
+
+ tempname = strdup(h);
+ slash=tempname;
+ while(*slash == '/')
+ slash++;
+
+ while((slash = strchr(slash, '/')))
+ {
+ *slash = '\0';
+
+ if(stat( (const char *)tempname, &stat_buf2 ) ||
+ !
S_ISDIR(stat_buf2.st_mode))
+ if(mkdir(tempname, 0755))
+ {
+ if (VerboseLevel() > 1)
+ merr << "maildrop:
Error making directory " << tempname << "\n";
+
+ errexit=EX_TEMPFAIL;
+ throw "Could not make
directory.";
+ }
+ else
+ {
+ if (VerboseLevel() > 1)
+ merr << "maildrop: Made
directory " << tempname << "\n";
+ }
+
+ *slash++ = '/';
+ while(*slash == '/')
+ slash++;
+ }
+ free(tempname);
+ if (chdir(h) < 0)
+ {
+ errexit=EX_TEMPFAIL;
+ throw "Could not change to directory.";
+ }
+
+ #else
errexit=EX_TEMPFAIL;
! throw "Could not change to directory.";
! #endif
}
+
recipe=".mailfilter";
if ( stat(".", &buf) < 0 ||
# diff -c mdldapconfig.c.old mdldapconfig.c *** mdldapconfig.c.old Sat Sep 27 16:59:06 2003 --- mdldapconfig.c Sat Sep 27 17:30:27 2003 *************** *** 30,35 **** --- 30,36 ---- cfg->gidnumber_attr = NULL; cfg->maildir_attr = NULL; cfg->homedirectory_attr = NULL; + cfg->maildir_base_ldap = NULL;
cfg->port = LDAP_DEFAULT_PORT;
*************** *** 64,69 **** --- 65,72 ---- cfg->maildir_attr = (char*)strdup(val); if ( !strcasecmp(var,"homedirectory_attr") ) cfg->homedirectory_attr = (char*)strdup(val); + if ( !strcasecmp(var,"homedirectory_base") ) + cfg->maildir_base_ldap = (char*)strdup(val); if ( !strcasecmp(var,"quota_attr") ) cfg->quota_attr = (char*)strdup(val);
# diff -c mdldapconfig.h.old mdldapconfig.h *** mdldapconfig.h.old Sat Sep 27 16:58:38 2003 --- mdldapconfig.h Sat Sep 27 16:46:39 2003 *************** *** 32,37 **** --- 32,38 ---- char *gidnumber_attr; char *maildir_attr; char *homedirectory_attr; + char *maildir_base_ldap; char *quota_attr;
int default_uidnumber;
# diff -c mdldap.c.old mdldap.c
*** mdldap.c.old Sat Sep 27 16:58:20 2003
--- mdldap.c Sun Sep 28 15:09:53 2003
***************
*** 94,100 ****
values=ldap_get_values(ldap,entry,cfg->maildir_attr);
if ( ldap_count_values(values) > 0 )
{
! rec->maildir = strdup(values[0]);
ldap_value_free(values);
} else
rec->maildir = NULL;
--- 94,104 ----
values=ldap_get_values(ldap,entry,cfg->maildir_attr);
if ( ldap_count_values(values) > 0 )
{
! rec->maildir= malloc(sizeof(char) * (strlen(values[0]) +
strlen(cfg->maildir_base_ldap) + 1));
! strcpy(rec->maildir,cfg->maildir_base_ldap);
! strcat(rec->maildir,values[0]);
!
! //rec->maildir = strdup(values[0]);
ldap_value_free(values);
} else
rec->maildir = NULL;
***************
*** 129,135 ****
values=ldap_get_values(ldap,entry,cfg->homedirectory_attr); if ( ldap_count_values(values) > 0 ) { ! rec->homedirectory = strdup(values[0]); ldap_value_free(values); } else { rec->homedirectory = NULL; --- 133,142 ----
values=ldap_get_values(ldap,entry,cfg->homedirectory_attr);
if ( ldap_count_values(values) > 0 ) {
! rec->homedirectory = malloc(sizeof(char) * (strlen(values[0]) +
strlen(cfg->maildir_base_ldap) + 1));
! strcpy(rec->homedirectory,cfg->maildir_base_ldap);
! strcat(rec->homedirectory,values[0]);
! //rec->homedirectory = strdup(values[0]);
ldap_value_free(values);
} else {
rec->homedirectory = NULL;
# diff -c mdmysql.c.old mdmysql.c *** mdmysql.c.old Sat Sep 27 14:21:05 2003 --- mdmysql.c Sun Sep 28 15:28:59 2003 *************** *** 92,99 **** if (errno == ERANGE) rec->uidnumber = cfg->default_uidnumber; rec->gidnumber=atoi(row[2]); if (errno == ERANGE) rec->gidnumber = cfg->default_gidnumber; ! rec->homedir=strdup(row[3]); ! rec->maildir=strdup(row[4]); rec->quota=strdup(row[5]); rec->mailstatus=strdup(row[6]);
--- 92,110 ----
if (errno == ERANGE) rec->uidnumber = cfg->default_uidnumber;
rec->gidnumber=atoi(row[2]);
if (errno == ERANGE) rec->gidnumber = cfg->default_gidnumber;
!
! //following lines added my cmasters 27-09-2003 for virtual base capability
! rec->homedir=malloc(sizeof(char) * (strlen(row[3]) +
strlen(cfg->maildir_base) + 1));
! memset(rec->homedir,'\0',(strlen(row[3]) + strlen(cfg->maildir_base) + 1));
! strcpy(rec->homedir,cfg->maildir_base);
! strcat(rec->homedir,row[3]);
! //rec->homedir=strdup(row[3]);
! rec->maildir=malloc(sizeof(char) * (strlen(row[3]) +
strlen(cfg->maildir_base) + 1));
! memset(rec->maildir,'\0',(strlen(row[4]) + strlen(cfg->maildir_base) + 1));
! strcpy(rec->maildir,cfg->maildir_base);
! strcat(rec->maildir,row[4]);
! //rec->maildir=strdup(row[4]);
!
rec->quota=strdup(row[5]);
rec->mailstatus=strdup(row[6]);
# diff -c mdmysqlconfig.c.old mdmysqlconfig.c *** mdmysqlconfig.c.old Sat Sep 27 16:40:25 2003 --- mdmysqlconfig.c Sat Sep 27 16:41:37 2003 *************** *** 28,33 **** --- 28,34 ---- cfg->gidnumber_field = NULL; cfg->maildir_field = NULL; cfg->homedir_field = NULL; + cfg->maildir_base = NULL; cfg->quota_field = NULL; cfg->mailstatus_field = NULL; cfg->where_clause = NULL; *************** *** 66,71 **** --- 67,74 ---- cfg->maildir_field = (char*)strdup(val); if ( !strcasecmp(var,"homedirectory_field") ) cfg->homedir_field = (char*)strdup(val); + if ( !strcasecmp(var,"homedirectory_base") ) + cfg->maildir_base = (char*)strdup(val); if ( !strcasecmp(var,"quota_field") ) cfg->quota_field = (char*)strdup(val); if ( !strcasecmp(var,"mailstatus_field") )
# diff -c mdmysqlconfig.h.old mdmysqlconfig.h *** mdmysqlconfig.h.old Sat Sep 27 16:40:52 2003 --- mdmysqlconfig.h Sat Sep 27 16:25:30 2003 *************** *** 32,37 **** --- 32,38 ---- char *gidnumber_field; char *homedir_field; char *maildir_field; + char *maildir_base; char *quota_field; char *mailstatus_field; char *where_clause;







