4 messages in net.sourceforge.lists.courier-maildropRe: [maildropl] Maildrop : Setting us...
FromSent OnAttachments
Manpreet Singh NehraSep 19, 2003 4:29 pm 
Paul DlugSep 19, 2003 4:48 pm.patch
Petri RiihikallioSep 20, 2003 10:17 am 
Sam VarshavchikSep 20, 2003 7:13 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [maildropl] Maildrop : Setting user Id from within maildroprcActions...
From:Paul Dlug (pa@aps.org)
Date:Sep 19, 2003 4:48:20 pm
List:net.sourceforge.lists.courier-maildrop
Attachments:

I ran into what I think is the same problem with an LDAP virtual hosting situation. I need all mail mapped to one uid/gid for delivery. The patch I attached contains my modifications to maildrop 1.6.0 to support this. You should be able to make the same changes for the mysql code. (It's pretty easy).

--Paul

On Fri, 19 Sep 2003, Manpreet Singh Nehra wrote:

Hi everybody !

I have a setup running Postfix+MySQL+Courier+Amavisd-new+NAI+ClamAV+Spamassassin+Maildrop with Virtual Domains. (I guess that's all) The problem I am facing is: I want that every mail that is delivered to the any user of a domain should be
copied to the admin folder of that domain.

If I do not attempt to copy to the admin folder it works fine.

The following if my /etc/maildrop/maildroprc file <File> if(/^To:[:space:]*[a-zA-Z0-9_\.]*@!.*$/:h) { echo $MATCH2 if(/^X-Spam-Flag: *YES/) { cc "/var/virtual/$MATCH2/admin/mail/.Recieved.Spam/" to "$HOME/mail/.Spam" } else { cc "/var/virtual/$MATCH2/admin/mail/.Recieved/" echo "$HOME/mail/" } } </File>

The error I get in my maillog is

postfix/pipe[1692]: 0FDSVSFG2E: to=mys@somedomain.com, relay=maildrop, delay=234, status=deferred (temporary failure. Command output:
/usr/bin/maildrop: Unable to open mailbox. )

As far as I am able to infer it occurs because maildrop sets uid:gid to the user
to whom the mail is being delivered. And since the admin has a different uid then the
user maildrop is not able to deliver the mail.

What I am looking for is a workaround to change the uid of maildrop while
inseide the script[

The mail copying is very essential for the setup so it can't be eliminated.

Thanks in advance

Manpreet

diff -urN maildrop-1.6.0/maildrop/mdldap.c
maildrop-1.6.0-ldapext/maildrop/mdldap.c --- maildrop-1.6.0/maildrop/mdldap.c Sun Jun 9 11:26:19 2002 +++ maildrop-1.6.0-ldapext/maildrop/mdldap.c Fri Sep 12 11:42:09 2003 @@ -1,7 +1,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> +#include <sys/stat.h> #include <sys/time.h> +#include <sys/types.h>

#include "mdldapconfig.h" #include "mdldap.h" @@ -22,6 +25,7 @@ int needbind = 0; char *mail_filter; struct timeval tv; + struct stat *sb;

ldap = ldap_init(cfg->hostname,cfg->port); if ( !ldap ) @@ -91,14 +95,13 @@ free(dn); #endif

- values=ldap_get_values(ldap,entry,cfg->maildir_attr); + values=ldap_get_values(ldap,entry,cfg->uid_attr); if ( ldap_count_values(values) > 0 ) { - rec->maildir = strdup(values[0]); + rec->uid = strdup(values[0]); ldap_value_free(values); } else - rec->maildir = NULL; - + rec->uid = NULL;

values=ldap_get_values(ldap,entry,cfg->mail_attr); if ( ldap_count_values(values) > 0 ) { @@ -108,8 +111,12 @@ rec->mail = NULL; }

- values=ldap_get_values(ldap,entry,cfg->uidnumber_attr); - if ( ldap_count_values(values) > 0 ) + if (cfg->map_virtual_user > 0) { + rec->uidnumber = cfg->default_uidnumber; + rec->gidnumber = cfg->default_gidnumber; + } else { + values=ldap_get_values(ldap,entry,cfg->uidnumber_attr); + if ( ldap_count_values(values) > 0 ) { rec->uidnumber = atoi(values[0]); ldap_value_free(values); @@ -117,22 +124,40 @@ rec->uidnumber = cfg->default_uidnumber; }

- - values=ldap_get_values(ldap,entry,cfg->gidnumber_attr); - if ( ldap_count_values(values) > 0 ) + values=ldap_get_values(ldap,entry,cfg->gidnumber_attr); + if ( ldap_count_values(values) > 0 ) { rec->gidnumber = atoi(values[0]); ldap_value_free(values); } else { rec->gidnumber = cfg->default_gidnumber; } + }

- values=ldap_get_values(ldap,entry,cfg->homedirectory_attr); - if ( ldap_count_values(values) > 0 ) { - rec->homedirectory = strdup(values[0]); - ldap_value_free(values); + if (cfg->homedirectory_prefix != NULL) { + rec->homedirectory = (char*)malloc(strlen(cfg->homedirectory_prefix) +
strlen(rec->uid) + 2); + sprintf(rec->homedirectory, "%s/%s", cfg->homedirectory_prefix, rec->uid); + } else { + 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; + } + } + + if (cfg->maildir_prefix != NULL) { + rec->maildir = (char*)malloc(strlen(rec->homedirectory) +
strlen(cfg->maildir_prefix) + 2); + sprintf(rec->maildir, "%s/%s", rec->homedirectory, cfg->maildir_prefix); } else { - rec->homedirectory = NULL; + 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; }

values=ldap_get_values(ldap,entry,cfg->quota_attr); @@ -146,6 +171,20 @@

if ( needbind ) ldap_unbind(ldap); + + sb = (struct stat*)malloc(sizeof(struct stat)); + + if (stat(rec->homedirectory, sb) == -1) + { + if (cfg->homedirectory_create == 1) { + if (mkdir(rec->homedirectory, 0750) == -1) + fprintf(stderr, "Error creating home directory: %s\n",
rec->homedirectory); + if (chown(rec->homedirectory, rec->uidnumber, rec->gidnumber) < 0) + fprintf(stderr, "Error changing ownership\n"); + } + } + +

free(mail_filter); free(filter); diff -urN maildrop-1.6.0/maildrop/mdldap.h
maildrop-1.6.0-ldapext/maildrop/mdldap.h --- maildrop-1.6.0/maildrop/mdldap.h Sat Jan 20 13:09:31 2001 +++ maildrop-1.6.0-ldapext/maildrop/mdldap.h Tue Sep 2 14:55:34 2003 @@ -11,10 +11,12 @@ char *dn; char *maildir; char *mail; + char *uid; int uidnumber; int gidnumber; char *homedirectory; char *quota; + char *vacation; } mdldaprec;

diff -urN maildrop-1.6.0/maildrop/mdldapconfig.c
maildrop-1.6.0-ldapext/maildrop/mdldapconfig.c --- maildrop-1.6.0/maildrop/mdldapconfig.c Sun Jan 28 14:59:20 2001 +++ maildrop-1.6.0-ldapext/maildrop/mdldapconfig.c Tue Sep 2 14:55:34 2003 @@ -78,6 +78,18 @@

if ( !strcasecmp(var,"default_gidnumber") ) cfg->default_gidnumber = atoi(val); + + if ( !strcasecmp(var,"homedirectory_prefix") ) + cfg->homedirectory_prefix = (char*)strdup(val); + + if ( !strcasecmp(var,"homedirectory_create") ) + cfg->homedirectory_create = atoi(val); + + if ( !strcasecmp(var,"map_virtual_user") ) + cfg->map_virtual_user = atoi(val); + + if ( !strcasecmp(var,"maildir_prefix") ) + cfg->maildir_prefix = (char*)strdup(val); }

fclose(fp); @@ -95,12 +107,12 @@ cfg->gidnumber_attr = (char*)strdup(LDAP_DEFAULT_GIDNUMBER_ATTR); if ( !cfg->maildir_attr ) cfg->maildir_attr = (char*)strdup(LDAP_DEFAULT_MAILDIR_ATTR); - if ( !cfg->homedirectory_attr ) + if ( !cfg->homedirectory_attr && !cfg->homedirectory_prefix ) cfg->homedirectory_attr = (char*)strdup(LDAP_DEFAULT_HOMEDIRECTORY_ATTR); if ( !cfg->quota_attr ) cfg->quota_attr = (char*)strdup(LDAP_DEFAULT_QUOTA_ATTR); } - + free(buf); free(var); free(val); diff -urN maildrop-1.6.0/maildrop/mdldapconfig.h
maildrop-1.6.0-ldapext/maildrop/mdldapconfig.h --- maildrop-1.6.0/maildrop/mdldapconfig.h Sun Jan 28 14:59:20 2001 +++ maildrop-1.6.0-ldapext/maildrop/mdldapconfig.h Tue Sep 2 14:55:34 2003 @@ -34,8 +34,12 @@ char *homedirectory_attr; char *quota_attr;

+ int map_virtual_user; int default_uidnumber; int default_gidnumber; + char *homedirectory_prefix; + char *maildir_prefix; + int homedirectory_create;

int timeout; } mdldapconfig; diff -urN maildrop-1.6.0/maildropldap.config
maildrop-1.6.0-ldapext/maildropldap.config --- maildrop-1.6.0/maildropldap.config Sun Jan 28 14:59:20 2001 +++ maildrop-1.6.0-ldapext/maildropldap.config Fri Sep 12 11:37:17 2003 @@ -39,6 +39,9 @@ # hostname - host name of your ldap server hostname ldap.server.yourdomain.com

+# port - port of your ldap server +port 389 + # basedn - base DN by which to search for LDAP entries basedn dc=yourdomain,dc=com

@@ -81,6 +84,27 @@ # default_gid - default gid (number only) to use incase gidnumber attribute not # found in users ldap entry default_gidnumber 8 + +# VIRTUAL HOSTING OPTIONS +# +# map_virtual_user - if set, maps all users to the default_uid/gid below,
ignoring +# their uid/gid number in the ldap entry. This enables all mailboxes to be +# owned by a single local user. +#map_virtual_user 1 + +# homedirectory_prefix - if set, home directories are constructed by appending +# the uid to this prefix instead of looking them up. +#homedirectory_prefix /var/mail/virtual + +# homedirectory_create - create the home directory if it doesn't exist. This is +# done in the ldap code since the rest of maildrop relies on being able to
access +# the home directory. +#homedirectory_create 1 + +# maildir_prefix - location of the users maildir from their home directory +# disable to lookup the maildir in the ldap server. +#maildir_prefix ./Maildir +

# LDAP Field definitions #