Imported Upstream version 2.3
[ossec-hids.git] / src / analysisd / compiled_rules / generic_samples.c
1 /* @(#) $Id: generic_samples.c,v 1.2 2009/06/24 17:06:23 dcid Exp $ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All rights reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 3) as published by the FSF - Free Software
9  * Foundation.
10  *
11  * License details at the LICENSE file included with OSSEC or 
12  * online at: http://www.ossec.net/en/licensing.html
13  */
14
15
16 #include "shared.h"
17 #include "eventinfo.h"
18 #include "config.h"
19
20
21
22 /** Note: If the rule fails to match it should return NULL. 
23  * If you want processing to continue, return lf (the eventinfo structure).
24  */
25  
26
27
28 /* Example 1:
29  * Comparing if the srcuser and dstuser are the same. If they are the same,
30  * return true.
31  * If any of them is not set, return true too.
32  */
33 void *comp_srcuser_dstuser(Eventinfo *lf)
34 {
35     if(!lf->srcuser || !lf->dstuser)
36     {
37         return(lf);
38     }
39
40     if(strcmp(lf->srcuser, lf->dstuser) == 0)
41     {
42         return(lf);
43     }
44
45
46     /* In here, srcuser and dstuser are present and are different. */
47     return(NULL);
48 }
49
50
51
52 /* Example 2:
53  * Checking if the size of the id field is larger than 10.
54  */
55 void *check_id_size(Eventinfo *lf)
56 {
57     if(!lf->id)
58     {
59         return(NULL);
60     }
61
62     if(strlen(lf->id) >= 10)
63     {
64         return(lf);
65     }
66
67     return(NULL);
68 }
69
70
71
72 /* Example 3:
73  * Comparing the Target Account Name and Caller User Name
74  * on Windows logs.
75  * It will return NULL (not match) if any of these values
76  * are not present or if they are the same.
77  * This function will return TRUE if they are NOT the same.
78  */
79 void *comp_mswin_targetuser_calleruser_diff(Eventinfo *lf)
80 {
81     char *target_user;
82     char *caller_user;
83
84
85     target_user = strstr(lf->log, "Target Account Name");
86     caller_user = strstr(lf->log, "Caller User Name");
87
88     if(!target_user || !caller_user)
89     {
90         return(NULL);
91     }
92
93
94     /* We need to clear each user type and finish the string.
95      * It looks like:
96      * Target Account Name: account\t
97      * Caller User Name: account\t
98      */
99     target_user = strchr(target_user, ':');
100     caller_user = strchr(caller_user, ':');
101
102     if(!target_user || !caller_user)
103     {
104         return(NULL);
105     }
106
107
108     target_user++;
109     caller_user++;
110
111
112     while(*target_user != '\0')
113     {
114         if(*target_user != *caller_user)
115             return(lf);
116
117         if(*target_user == '\t' || 
118            (*target_user == ' '  && target_user[1] == ' '))
119             break;    
120
121         target_user++;caller_user++;           
122     }
123
124
125     /* If we got in here, the accounts are the same.
126      * So, we return NULL since we only want to alert if they are different.
127      */ 
128     return(NULL);
129 }
130
131
132 /* END generic samples. */
133