Changeset 215 for trunk/src/sh_extern.c


Ignore:
Timestamp:
Feb 18, 2009, 7:11:26 PM (16 years ago)
Author:
katerina
Message:

Consolidate filtering code (ticket #142) and match on regular expressions (ticket #143).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_extern.c

    r214 r215  
    9292#include "sh_extern.h"
    9393#include "sh_calls.h"
     94#include "sh_filter.h"
    9495#define SH_NEED_PWD_GRP 1
    9596#include "sh_static.h"
     
    867868  char     type[4];
    868869
    869   int      for_c;
    870   char   * for_v[32];
    871   int      fand_c;
    872   char   * fand_v[32];
    873   int      fnot_c;
    874   char   * fnot_v[32];
     870  sh_filter_type * filter;
     871
    875872  time_t   deadtime;
    876873  time_t   last_run;
     
    900897sh_com_t * command_init(void)
    901898{
    902   int         i;
    903899  uid_t       ff_euid;
    904900  sh_com_t  * ext_com = NULL;
     
    924920
    925921  set3(ext_com->type, 'l', 'o', 'g');
    926   ext_com->for_c        = 0;
    927   ext_com->fand_c       = 0;
    928   ext_com->fnot_c       = 0;
     922  ext_com->filter       = NULL;
    929923  ext_com->deadtime     = 0;
    930924  ext_com->last_run     = 0;
    931925
    932   for (i = 0; i < 32; ++i)
    933     {
    934       ext_com->for_v[i]         = NULL;
    935       ext_com->fand_v[i]        = NULL;
    936       ext_com->fnot_v[i]        = NULL;
    937     }
    938926  ext_com->next             = NULL;
    939927
     
    11281116int sh_ext_cleanup(void)
    11291117{
    1130   int i;
    11311118  sh_com_t * retval;
    11321119
     
    11401127      sh_ext_tas_free (&(retval->tas));
    11411128
    1142       for (i = 0; i < 32; ++i)
    1143         {
    1144           if (NULL != retval->for_v[i])  SH_FREE(retval->for_v[i]);
    1145           if (NULL != retval->fand_v[i]) SH_FREE(retval->fand_v[i]);
    1146           if (NULL != retval->fnot_v[i]) SH_FREE(retval->fnot_v[i]);
    1147         }
     1129      if (retval->filter)
     1130        sh_filter_free (retval->filter);
    11481131
    11491132      SH_FREE(retval);
     
    11731156  if (ext_coms == NULL || ext_failed == (-1))
    11741157    return (-1);
    1175   return (sh_ext_add (str, &(ext_coms->for_c), ext_coms->for_v));
     1158  if (ext_coms->filter == NULL)
     1159    ext_coms->filter = sh_filter_alloc();
     1160  return (sh_filter_add(str, ext_coms->filter, SH_FILT_OR));
    11761161}
    11771162
     
    11831168  if (ext_coms == NULL || ext_failed == (-1))
    11841169    return (-1);
    1185   return (sh_ext_add (str, &(ext_coms->fand_c), ext_coms->fand_v));
     1170  if (ext_coms->filter == NULL)
     1171    ext_coms->filter = sh_filter_alloc();
     1172  return (sh_filter_add(str, ext_coms->filter, SH_FILT_AND));
    11861173}
    11871174
     
    11931180  if (ext_coms == NULL || ext_failed == (-1))
    11941181    return (-1);
    1195   return (sh_ext_add (str, &(ext_coms->fnot_c), ext_coms->fnot_v));
     1182  if (ext_coms->filter == NULL)
     1183    ext_coms->filter = sh_filter_alloc();
     1184  return (sh_filter_add(str, ext_coms->filter, SH_FILT_NOT));
    11961185}
    11971186
     
    13541343static int sh_ext_filter (char * message, sh_com_t * task)
    13551344{
    1356   int i;
    1357   int j = 0;
    13581345  time_t now_time;
    13591346
    13601347  SL_ENTER(_("sh_ext_filter"));
    13611348
    1362   /* Presence of any of these keywords prevents execution.
    1363    */
    1364   if (task->fnot_c > 0)
    1365     {
    1366       for (i = 0; i < task->fnot_c; ++i)
     1349  if (task->filter)
     1350    {
     1351      if (0 != sh_filter_filter (message, task->filter))
    13671352        {
    1368           if (NULL != sl_strstr(message, task->fnot_v[i]))
    1369             {
    1370               SL_RETURN ((-1), _("sh_ext_filter"));
    1371             }
     1353          SL_RETURN ((-1), _("sh_ext_filter"));
    13721354        }
    13731355    }
    13741356
    1375   /* Presence of all of these keywords is required for execution.
    1376    */
    1377   if (task->fand_c > 0)
    1378     {
    1379       j = 0;
    1380 
    1381       for (i = 0; i < task->fand_c; ++i)
    1382         {
    1383           if (NULL == sl_strstr(message, task->fand_v[i]))
    1384             {
    1385               SL_RETURN ((-1), _("sh_ext_filter"));
    1386             }
    1387         }
    1388 
    1389     }
    1390 
    1391   /* Presence of at least one of these keywords is required for execution.
    1392    */
    1393   if (task->for_c > 0)
    1394     {
    1395       for (i = 0; i < task->for_c; ++i)
    1396         {
    1397           if (NULL != sl_strstr(message, task->for_v[i]))
    1398             {
    1399               goto checkdeadtime;
    1400             }
    1401         }
    1402       SL_RETURN ((-1), _("sh_ext_filter"));
    1403     }
    1404 
    1405  checkdeadtime:
    1406   if (task->deadtime != (time_t) 0)   /* deadtime */
     1357  /* Filter passed, check deadtime */
     1358
     1359  if (task->deadtime != (time_t) 0)
    14071360    {
    14081361      now_time = time (NULL);
Note: See TracChangeset for help on using the changeset viewer.