- Timestamp:
- Feb 18, 2009, 7:11:26 PM (16 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/samhain.c
r214 r215 746 746 #if defined(SH_WITH_SERVER) 747 747 sh_forward_free_all (); 748 #endif 749 #if defined(SH_WITH_MAIL) 750 sh_nmail_free(); 748 751 #endif 749 752 delete_cache(); … … 1749 1752 (void) sh_ext_cleanup(); 1750 1753 #endif 1754 #if defined(SH_WITH_MAIL) 1755 sh_nmail_free(); 1756 #endif 1757 1751 1758 /* delete the file list, make all database 1752 1759 * entries visible (allignore = FALSE) -
trunk/src/sh_extern.c
r214 r215 92 92 #include "sh_extern.h" 93 93 #include "sh_calls.h" 94 #include "sh_filter.h" 94 95 #define SH_NEED_PWD_GRP 1 95 96 #include "sh_static.h" … … 867 868 char type[4]; 868 869 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 875 872 time_t deadtime; 876 873 time_t last_run; … … 900 897 sh_com_t * command_init(void) 901 898 { 902 int i;903 899 uid_t ff_euid; 904 900 sh_com_t * ext_com = NULL; … … 924 920 925 921 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; 929 923 ext_com->deadtime = 0; 930 924 ext_com->last_run = 0; 931 925 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 }938 926 ext_com->next = NULL; 939 927 … … 1128 1116 int sh_ext_cleanup(void) 1129 1117 { 1130 int i;1131 1118 sh_com_t * retval; 1132 1119 … … 1140 1127 sh_ext_tas_free (&(retval->tas)); 1141 1128 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); 1148 1131 1149 1132 SH_FREE(retval); … … 1173 1156 if (ext_coms == NULL || ext_failed == (-1)) 1174 1157 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)); 1176 1161 } 1177 1162 … … 1183 1168 if (ext_coms == NULL || ext_failed == (-1)) 1184 1169 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)); 1186 1173 } 1187 1174 … … 1193 1180 if (ext_coms == NULL || ext_failed == (-1)) 1194 1181 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)); 1196 1185 } 1197 1186 … … 1354 1343 static int sh_ext_filter (char * message, sh_com_t * task) 1355 1344 { 1356 int i;1357 int j = 0;1358 1345 time_t now_time; 1359 1346 1360 1347 SL_ENTER(_("sh_ext_filter")); 1361 1348 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)) 1367 1352 { 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")); 1372 1354 } 1373 1355 } 1374 1356 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) 1407 1360 { 1408 1361 now_time = time (NULL); -
trunk/src/sh_forward.c
r214 r215 5056 5056 (void) sh_ext_cleanup(); 5057 5057 #endif 5058 #if defined(SH_WITH_MAIL) 5059 sh_nmail_free(); 5060 #endif 5058 5061 /* - mark all clients dead 5059 5062 * - read configuration file -
trunk/src/sh_mail.c
r214 r215 59 59 #include "sh_tools.h" 60 60 #include "sh_pthread.h" 61 #include "sh_filter.h" 61 62 #include "sh_mail_int.h" 62 63 #include "sh_nmail.h" … … 245 246 246 247 /*@notreached@*/ 247 }248 249 void sh_filter_filterfree (sh_filter_type * filter)250 {251 int i;252 253 if (filter)254 {255 for (i = 0; i < filter->for_c; ++i) {256 if (filter->for_v[i])257 SH_FREE(filter->for_v[i]);258 filter->for_v[i] = NULL;259 }260 filter->for_c = 0;261 for (i = 0; i < filter->fand_c; ++i) {262 if (filter->fand_v[i])263 SH_FREE(filter->fand_v[i]);264 filter->fand_v[i] = NULL;265 }266 filter->fand_c = 0;267 for (i = 0; i < filter->fnot_c; ++i) {268 if (filter->fnot_v[i])269 SH_FREE(filter->fnot_v[i]);270 filter->fnot_v[i] = NULL;271 }272 filter->fnot_c = 0;273 }274 }275 276 int sh_filter_filteradd (const char * argstring,277 sh_filter_type * filter, int ftype)278 {279 int i = 0;280 int flag = 0;281 size_t s;282 283 char * dupp;284 char * p;285 char * end;286 int * ntok;287 char ** stok;288 289 SL_ENTER(_("sh_filter_filteradd"));290 291 if (NULL == argstring)292 {293 SL_RETURN((-1), _("sh_filter_filteradd"));294 }295 296 if (ftype == SH_FILT_OR) {297 ntok = &(filter->for_c);298 stok = filter->for_v;299 }300 else if (ftype == SH_FILT_AND) {301 ntok = &(filter->fand_c);302 stok = filter->fand_v;303 }304 else if (ftype == SH_FILT_NOT) {305 ntok = &(filter->fnot_c);306 stok = filter->fnot_v;307 }308 else {309 SL_RETURN((-1), _("sh_filter_filteradd"));310 }311 312 *ntok = 0;313 314 dupp = sh_util_strdup(argstring);315 p = dupp;316 317 do318 {319 while (*p == ',' || *p == ' ' || *p == '\t')320 ++p;321 if (*p == '\0')322 break;323 324 end = p; ++end;325 if (*end == '\0')326 break;327 328 if (*p == '\'')329 {330 ++p; end = p; ++end;331 if (*p == '\0' || *end == '\0')332 break;333 while (*end != '\0' && *end != '\'')334 ++end;335 }336 else if (*p == '"')337 {338 ++p; end = p; ++end;339 if (*p == '\0' || *end == '\0')340 break;341 while (*end != '\0' && *end != '"')342 ++end;343 }344 else345 {346 while (*end != '\0' && *end != ',' && *end != ' ' && *end != '\t')347 ++end;348 }349 if (*end == '\0')350 flag = 1;351 else352 *end = '\0';353 354 s = strlen(p) + 1;355 if (stok[i] != NULL)356 SH_FREE(stok[i]);357 stok[i] = SH_ALLOC(s);358 (void) sl_strlcpy(stok[i], p, s);359 360 p = end; ++p;361 362 ++i;363 if (i == SH_FILT_NUM)364 break;365 }366 while (p != NULL && *p != '\0' && flag == 0);367 368 *ntok = i;369 SH_FREE(dupp);370 371 SL_RETURN (0, _("sh_filter_filteradd"));372 }373 374 /*375 * -- Check filters. Returns 0 if message passes.376 */377 int sh_filter_filter (const char * message, sh_filter_type * filter)378 {379 int i;380 381 SL_ENTER(_("sh_filter_filter"));382 383 if (filter)384 {385 386 /* Presence of any of these keywords prevents execution.387 */388 if (filter->fnot_c > 0)389 {390 for (i = 0; i < filter->fnot_c; ++i)391 {392 if (NULL != sl_strstr(message, filter->fnot_v[i]))393 {394 SL_RETURN ((-1), _("sh_filter_filter"));395 }396 }397 }398 399 /* Presence of all of these keywords is required for execution.400 */401 if (filter->fand_c > 0)402 {403 for (i = 0; i < filter->fand_c; ++i)404 {405 if (NULL == sl_strstr(message, filter->fand_v[i]))406 {407 SL_RETURN ((-1), _("sh_filter_filter"));408 }409 }410 }411 412 /* Presence of at least one of these keywords is required for execution.413 */414 if (filter->for_c > 0)415 {416 for (i = 0; i < filter->for_c; ++i)417 {418 if (NULL != sl_strstr(message, filter->for_v[i]))419 {420 goto isok;421 }422 }423 SL_RETURN ((-1), _("sh_filter_filter"));424 }425 }426 427 isok:428 SL_RETURN ((0), _("sh_filter_filter"));429 248 } 430 249 -
trunk/src/sh_readconf.c
r214 r215 1107 1107 { N_("setmailsender"), SH_SECTION_MAIL, SH_SECTION_MISC, 1108 1108 sh_mail_set_sender }, 1109 { N_("setmailalias"), SH_SECTION_MAIL, SH_SECTION_MISC, 1110 sh_nmail_add_alias }, 1109 1111 { N_("setmailaddress"), SH_SECTION_MAIL, SH_SECTION_MISC, 1110 1112 sh_nmail_add_recipient }, -
trunk/src/sh_string.c
r185 r215 127 127 * If nfields < actual fields, last string will be remainder. 128 128 */ 129 char ** split_array_ws(char *line, unsigned int * nfields, size_t * lengths) 129 130 #define SH_SPLIT_LIST 0 131 #define SH_SPLIT_WS 1 132 133 char ** split_array_ws_int (char *line, 134 unsigned int * nfields, size_t * lengths, 135 int isList) 130 136 { 131 137 char *a, *e, *s; … … 144 150 /* skip leading WS 145 151 */ 146 if ( *s && isspace((int)*s) ) 147 { 148 do { 149 ++s; 150 } while ( *s && isspace((int)*s) ); 151 } 152 if (isList == SH_SPLIT_WS) 153 { 154 if ( *s && isspace((int)*s) ) 155 { 156 do { 157 ++s; 158 } while ( *s && isspace((int)*s) ); 159 } 160 } 161 else 162 { 163 if ( *s && (*s == ' ' || *s == '\t' || *s == ',')) 164 { 165 do { 166 ++s; 167 } while ( *s && (*s == ' ' || *s == '\t' || *s == ',')); 168 } 169 } 152 170 153 171 if (*s) … … 157 175 */ 158 176 a = s; 159 do { 160 a++; 161 } while ( *a && (!isspace((int)*a)) ); 177 if (isList == SH_SPLIT_WS) 178 { 179 do { 180 a++; 181 } while ( *a && (!isspace((int)*a)) ); 182 } 183 else 184 { 185 do { 186 a++; 187 } while ( *a && (*a != ' ' && *a != '\t' && *a != ',')); 188 } 162 189 163 190 /* next token, *a is either ws or '\0' … … 201 228 } 202 229 230 char ** split_array_ws (char *line, 231 unsigned int * nfields, size_t * lengths) 232 { 233 return split_array_ws_int (line, nfields, lengths, SH_SPLIT_WS); 234 } 235 236 char ** split_array_list (char *line, 237 unsigned int * nfields, size_t * lengths) 238 { 239 return split_array_ws_int (line, nfields, lengths, SH_SPLIT_LIST); 240 } 203 241 204 242 #define SH_STRING_PARCEL 120
Note:
See TracChangeset
for help on using the changeset viewer.