Main Page | Class List | Directories | File List | Class Members | File Members

qmail-spamc.c

Go to the documentation of this file.
00001 /* <@LICENSE>
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to you under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at:
00008  * 
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  * </@LICENSE>
00017  */
00018 
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include <unistd.h>
00022 
00023 
00024 #define MAXOPTS 16
00025 
00026 #define TRY(exp) do {                                                         \
00027           if ((exp) == -1) {                                                  \
00028             fprintf(stderr, "%s:%d: '%s' failed: ",                           \
00029               __FILE__,                                                       \
00030               __LINE__,                                                       \
00031               #exp                                                            \
00032             ); perror(NULL);                                                  \
00033             exit(81);                                                         \
00034           }                                                                   \
00035         } while(0)
00036 
00037 
00038 int main(int argc, char **argv)
00039 {
00040     char *options[MAXOPTS];
00041     char *val = NULL;
00042     int   opt = 0;
00043 
00044     pid_t childpid;
00045     int pfds[2];
00046 
00047 
00048 #ifdef HAVE_QMAIL_RELAYCLIENT
00049     /*
00050      * bug 2927: use standard qmail-queue if this is a RELAYCLIENT
00051      */
00052     if (getenv("RELAYCLIENT")) {
00053        TRY(execlp("qmail-queue", "qmail-queue", NULL));
00054     }
00055 #endif
00056 
00057 
00058     /* create the array of options */
00059     options[opt++] = "spamc";            /* set zeroth argument */
00060     if ((val = getenv("SPAMDSOCK")) != NULL) {   /* Unix Domain Socket path */
00061         options[opt++] = "-U";
00062         options[opt++] = val;
00063     }
00064     if ((val = getenv("SPAMDHOST")) != NULL) {   /* remote spamd host name */
00065         options[opt++] = "-d";
00066         options[opt++] = val;
00067     }
00068     if ((val = getenv("SPAMDPORT")) != NULL) {   /* remote spamd port number */
00069         options[opt++] = "-p";
00070         options[opt++] = val;
00071     }
00072     if ((val = getenv("SPAMDSSL")) != NULL) {    /* use ssl for spamc/spamd */
00073         options[opt++] = "-S";
00074     }
00075     if ((val = getenv("SPAMDLIMIT")) != NULL) {  /* message size limit */
00076         options[opt++] = "-s";
00077         options[opt++] = val;
00078     }
00079     if ((val = getenv("SPAMDUSER")) != NULL) {   /* spamc user configuration */
00080         options[opt++] = "-u";
00081         options[opt++] = val;
00082     }
00083     options[opt] = NULL;                 /* terminate argument list */
00084 
00085 
00086     TRY(pipe(pfds));
00087     TRY(childpid = fork());
00088     if (childpid == 0) {                /* the child ... */
00089         TRY(close(1));                    /* close normal stdout */
00090         TRY(dup(pfds[1]));                /* make stdout same as pfds[1] */
00091         TRY(close(pfds[0]));              /* we don't need this */
00092         TRY(execvp("spamc", options));
00093     }
00094     else {                              /* the parent ... */
00095         TRY(close(0));                    /* close normal stdin */
00096         TRY(dup(pfds[0]));                /* make stdin same as pfds[0] */
00097         TRY(close(pfds[1]));              /* we don't need this */
00098         TRY(execlp("qmail-queue", "qmail-queue", NULL));
00099     }
00100     
00101     /* never reached */
00102     return 81;
00103 }
00104 

© sourcejam.com 2005-2008