d0d307
/*
d0d307
 * Wrapper for cyrus 'deliver' to allow anyone to run it -
d0d307
 * I hope this is secure!  Should be setgid mail.
d0d307
 */
d0d307
d0d307
#include <stdio.h>
d0d307
#include <unistd.h>
d0d307
#include <pwd.h>
d0d307
#include <sys/types.h>
d0d307
#include <sysexits.h>
d0d307
d0d307
#ifndef LIBEXECDIR
d0d307
#define LIBEXECDIR "/usr/lib/cyrus-imapd"
d0d307
#endif
d0d307
d0d307
int main(int argc, char *argv[])
d0d307
{
d0d307
    char *const envp[] = { NULL };
d0d307
    struct passwd *ent = getpwuid(getuid());
d0d307
    const char *uname = (ent && ent->pw_name && ent->pw_name[0])
d0d307
                              ? ent->pw_name : "anonymous";
d0d307
    
d0d307
    if (argc != 2) {
d0d307
        fprintf(stderr, "Usage: %s mailbox\n", argv[0]);
d0d307
        return EX_USAGE; 
d0d307
    }
d0d307
    
d0d307
    execle(LIBEXECDIR"/deliver", "deliver", "-e",
d0d307
           "-a", uname, "-m", argv[1],
d0d307
           NULL, envp);
d0d307
d0d307
    perror("exec "LIBEXECDIR"/deliver");           
d0d307
    return EX_OSERR; 
d0d307
}