Changeset 648


Ignore:
Timestamp:
01/14/14 13:26:24 (10 years ago)
Author:
bas
Message:

log run_email2trac errors to syslog instead of printf. This will improve debuging run_email2trac. Preparing for 2.8.0 release

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r647 r648  
    3434    Fixed by: Bas van der Vlies
    3535
    36 2.7.0
     36  * report run_email2trac errors to syslog (LOG_MAIL facility) instead of printf
     37    Author: Bas van der Vlies
    3738
    38392.7.0
  • trunk/debian/changelog

    r644 r648  
    1 email2trac (2.7.7-1) stable; urgency=low
     1email2trac (2.8.0-1) stable; urgency=low
    22
    33  * See Changelog
  • trunk/email2trac.spec

    r644 r648  
    11Summary: Utilities for converting emails to trac tickets
    22Name: email2trac
    3 Version: 2.7.7
     3Version: 2.8.0
    44Release: 1
    55License: Apache License 2.0
  • trunk/run_email2trac.c

    r628 r648  
    3232#include <stdio.h>
    3333#include <limits.h>
     34#include <syslog.h>
     35
    3436#ifdef HAVE_INITGROUPS
    3537#include <grp.h>
     
    4547{
    4648  if ( strlen(name) > 30 ) {
    47           if ( DEBUG ) printf("MTA_USERNAME is to large; %s\n", name);
    48           exit(-1);
     49    openlog("run_email2trac", LOG_PID, LOG_MAIL);
     50    syslog(LOG_ERR, "MTA_USERNAME is to large; %s\n", name);
     51    closelog();
     52    exit(-1);
    4953  }
     54}
     55
     56void email2trac_log(char *message)
     57{
     58    openlog("run_email2trac", LOG_PID, LOG_MAIL);
     59    syslog(LOG_ERR, message);
     60    closelog();
    5061}
    5162
    5263int main(int argc, char** argv) {
    5364
    54   int i,j;
    55   int caller = getuid();
    56   int status;
     65    int i,j;
     66    int caller = getuid();
     67    int status;
     68   
     69    char   **trac_script_args;
     70    char   *python_egg_cache = NULL;
     71    struct passwd *TRAC;
     72    struct passwd *MTA;
     73    struct stat script_attrs;
     74    const char *trac_script = TRAC_SCRIPT_PATH "/" TRAC_SCRIPT_NAME;
    5775
    58   char   **trac_script_args;
    59   char   *python_egg_cache = NULL;
    60   struct passwd *TRAC;
    61   struct passwd *MTA;
    62   struct stat script_attrs;
    63   const char *trac_script = TRAC_SCRIPT_PATH "/" TRAC_SCRIPT_NAME;
     76    char    error_msg[1024];
    6477 
    65   /*
    66   printf("trac_script = %s\n", trac_script);
    67   */
     78    /*
     79    printf("trac_script = %s\n", trac_script);
     80    */
    6881
    69   /* First copy arguments passed to the wrapper as scripts arguments
    70      after filtering out some of the possible script options */
     82    /*
     83    First copy arguments passed to the wrapper as scripts arguments
     84    aft er filtering out some of the possible script options
     85    */
    7186
    72   trac_script_args = (char**) malloc((argc+1)*sizeof(char*));
    73   if (trac_script_args == NULL) {
    74     if ( DEBUG ) printf("malloc failed\n");
    75     return 1;
    76   }
    77   trac_script_args[0] = TRAC_SCRIPT_NAME;
    78   for (i=j=1; i<argc; i++) {
    79     if ( (strcmp(argv[i],"--file") == 0) ||
    80          (strcmp(argv[i],"-f") == 0) ) {
    81       i++;
    82       continue;
     87    trac_script_args = (char**) malloc((argc+1)*sizeof(char*));
     88    if (trac_script_args == NULL) {
     89        snprintf(error_msg, sizeof(error_msg), "malloc failed");
     90        email2trac_log(error_msg);
     91        return 1;
     92    }
     93   
     94    trac_script_args[0] = TRAC_SCRIPT_NAME;
     95    for (i=j=1; i<argc; i++) {
     96
     97        if ( (strcmp(argv[i],"--file") == 0) ||
     98             (strcmp(argv[i],"-f") == 0) ) {
     99            i++;
     100            continue;
     101        }
     102        else if ( (strcmp(argv[i],"--eggcache") == 0) ||
     103                  (strcmp(argv[i],"-e") == 0) ) {
     104            i++;
     105            python_egg_cache = argv[i];
     106            continue;
     107        }
     108   
     109        trac_script_args[j] = argv[i];
     110        j++;
    83111    }
    84     else if ( (strcmp(argv[i],"--eggcache") == 0) ||
    85          (strcmp(argv[i],"-e") == 0) ) {
    86       i++;
    87       python_egg_cache = argv[i];
    88       continue;
     112
     113    trac_script_args[j] = NULL;
     114
     115    /* check caller */
     116    check_username(MTA_USER);
     117    MTA = getpwnam(MTA_USER);
     118   
     119    if ( MTA == NULL ) {
     120        snprintf(error_msg, sizeof(error_msg), "Invalid MTA user (%s)", MTA_USER);
     121        email2trac_log(error_msg);
     122        return -3;     /* 253 : MTA user not found */
     123    }
     124
     125    if ( caller !=  MTA->pw_uid ) {
     126        snprintf(error_msg, sizeof(error_msg), "Invalid caller UID (%d)", caller);
     127        email2trac_log(error_msg);
     128        return -2;     /* 254 : Invalid caller */
     129    }
     130 
     131    /* set UID/GID and supplementary groups to be Trac (or apache) user */
     132    check_username(TRAC_USER);
     133    if ( TRAC = getpwnam(TRAC_USER) ) {
     134#ifdef HAVE_INITGROUPS
     135        if (initgroups(TRAC_USER, TRAC->pw_gid)) {
     136            snprintf(error_msg, sizeof(error_msg), "initgroups failed");
     137            email2trac_log(error_msg);
     138            return -7;    /* 249 : Can't set supplementary groups */
     139        }
     140#endif
     141        if (setgid(TRAC->pw_gid) || setuid(TRAC->pw_uid)) {
     142            snprintf(error_msg, sizeof(error_msg), "setgid or setuid failed");
     143            email2trac_log(error_msg);
     144            return -5;   /* 251: Can't set gid or uid */
     145        }
     146    }
     147    else {
     148            snprintf(error_msg, sizeof(error_msg), "Invalid Trac user (%s)", TRAC_USER);
     149            email2trac_log(error_msg);
     150            return -6;     /* 250 : Trac user not found */
    89151    }
    90152   
    91     trac_script_args[j] = argv[i];
    92     j++;
    93   }
    94   trac_script_args[j] = NULL;
     153    /* Check that script exists */
     154    if ( stat(trac_script,&script_attrs) ) {
     155        snprintf(error_msg, sizeof(error_msg), "Script not found (%s)", trac_script);
     156        email2trac_log(error_msg);
     157        return -4;    /* 252 : script not found */
     158    }
     159 
     160    /* Set PYTHON_EGG_CACHE env variable if we have been told to do so */
     161    if ( python_egg_cache != NULL ) {
     162        setenv("PYTHON_EGG_CACHE",python_egg_cache ,1);
     163    }
    95164
    96   /* Check caller */
    97   check_username(MTA_USER);
    98   MTA = getpwnam(MTA_USER);
    99 
    100   if ( MTA == NULL ) {
    101     if ( DEBUG ) printf("Invalid MTA user (%s)\n", MTA_USER);
    102     return -3;     /* 253 : MTA user not found */
    103   }
    104 
    105   if ( caller !=  MTA->pw_uid ) {
    106     if ( DEBUG ) printf("Invalid caller UID (%d)\n",caller);
    107     return -2;     /* 254 : Invalid caller */
    108   }
    109  
    110   /* set UID/GID and supplementary groups to be Trac (or apache) user */
    111   check_username(TRAC_USER);
    112   if ( TRAC = getpwnam(TRAC_USER) ) {
    113 #ifdef HAVE_INITGROUPS
    114     if (initgroups(TRAC_USER, TRAC->pw_gid)) {
    115       if ( DEBUG ) printf("initgroups failed\n");
    116       return -7;    /* 249 : Can't set supplementary groups */
    117     }
    118 #endif
    119     if (setgid(TRAC->pw_gid) || setuid(TRAC->pw_uid)) {
    120       if ( DEBUG ) printf("setgid or setuid failed\n");
    121       return -5;   /* 251: Can't set gid or uid */
    122     }
    123   } else {
    124     if ( DEBUG ) printf("Invalid Trac user (%s)\n",TRAC_USER);
    125     return -6;     /* 250 : Trac user not found */
    126   }
    127          
    128   /* Check that script exists */
    129   if ( stat(trac_script,&script_attrs) ) {
    130     if ( DEBUG ) printf("Script not found (%s)\n",trac_script);
    131     return -4;    /* 252 : script not found */
    132   }
     165    /* Execute script */
     166    status = execv(trac_script, trac_script_args);
    133167 
    134   /* Set PYTHON_EGG_CACHE env variable if we have been told to do so */
    135   if ( python_egg_cache != NULL ) {
    136     setenv("PYTHON_EGG_CACHE",python_egg_cache ,1);
    137   }
    138 
    139   /* Execute script */
    140   status = execv(trac_script, trac_script_args);
    141  
    142   if ( DEBUG ) printf("Script %s execution failure (error=%d). Check permission and interpreter path.\n",trac_script,status);
    143   return -1;     /* 255 : should never reach this point */
    144 
     168    /* should never reach this point */
     169    snprintf(error_msg, sizeof(error_msg),
     170        "Script %s execution failure (error=%d). Check permission and interpreter path.",
     171        trac_script, status);
     172    email2trac_log(error_msg);
     173    return -1;
    145174}
    146175
Note: See TracChangeset for help on using the changeset viewer.