123 |
int action; |
int action; |
124 |
}; |
}; |
125 |
|
|
126 |
|
struct UidSet { |
127 |
|
uid_t uid; |
128 |
|
int action; |
129 |
|
}; |
130 |
|
|
131 |
|
struct GidSet { |
132 |
|
gid_t gid; |
133 |
|
int action; |
134 |
|
}; |
135 |
|
|
136 |
struct DeviceSet { |
struct DeviceSet { |
137 |
int resource; |
int resource; |
138 |
int operator; |
int operator; |
166 |
ACTION_ALERT}; |
ACTION_ALERT}; |
167 |
static struct TimestampSet timestampset= {OPERATOR_EQUAL, 0, 0, ACTION_ALERT}; |
static struct TimestampSet timestampset= {OPERATOR_EQUAL, 0, 0, ACTION_ALERT}; |
168 |
static struct SizeSet sizeset= {OPERATOR_EQUAL, 0, 0, ACTION_ALERT}; |
static struct SizeSet sizeset= {OPERATOR_EQUAL, 0, 0, ACTION_ALERT}; |
169 |
|
static struct UidSet uidset= {0, ACTION_ALERT}; |
170 |
|
static struct GidSet gidset= {0, ACTION_ALERT}; |
171 |
static struct DeviceSet deviceset= {0, OPERATOR_EQUAL, -1, -1, ACTION_ALERT}; |
static struct DeviceSet deviceset= {0, OPERATOR_EQUAL, -1, -1, ACTION_ALERT}; |
172 |
|
|
173 |
/* Private prototypes */ |
/* Private prototypes */ |
174 |
static void initialize(); |
static void initialize(); |
175 |
static void postparse(); |
static void postparse(); |
176 |
static void addservice(Service_T); |
static void addservice(Service_T); |
177 |
static void addmail(char *, Mail_T, unsigned int); |
static void addmail(char *, Mail_T, unsigned int); |
178 |
static void createservice(int, char *, char *); |
static void createservice(int, char *, char *); |
179 |
static void adddependant(char *); |
static void adddependant(char *); |
180 |
static void addchecksum(char *); |
static void addchecksum(char *); |
181 |
static void addport(struct PortSet *); |
static void addport(struct PortSet *); |
182 |
static void addresource(struct ResourceSet *); |
static void addresource(struct ResourceSet *); |
183 |
static void addtimestamp(struct TimestampSet *); |
static void addtimestamp(struct TimestampSet *); |
184 |
static void addsize(struct SizeSet *); |
static void addsize(struct SizeSet *); |
185 |
static void adddevice(struct DeviceSet *); |
static void adddevice(struct DeviceSet *); |
186 |
static void *addprotocol(int); |
static void *addprotocol(int); |
187 |
static void addcommand(int); |
static void addcommand(int); |
188 |
static void addargument(char *); |
static void addargument(char *); |
189 |
static void adduid(char *user, uid_t uid); |
static uid_t get_uid(char *, uid_t); |
190 |
static void addgid(char *group, gid_t gid); |
static gid_t get_gid(char *, gid_t); |
191 |
static void setlogfile(char *); |
static void adduid(struct UidSet *); |
192 |
static void setpidfile(char *); |
static void addgid(struct GidSet *); |
193 |
static void setmailserver(char *); |
static void addeuid(uid_t); |
194 |
static void setuname(char *); |
static void addegid(gid_t); |
195 |
static void setpasswd(char *); |
static void setlogfile(char *); |
196 |
static void reset_mailset(); |
static void setpidfile(char *); |
197 |
static void reset_runmail(); |
static void setmailserver(char *); |
198 |
static void reset_portset(); |
static void setuname(char *); |
199 |
static void reset_resourceset(); |
static void setpasswd(char *); |
200 |
static void reset_timestampset(); |
static void reset_mailset(); |
201 |
static void reset_sizeset(); |
static void reset_runmail(); |
202 |
static void reset_deviceset(); |
static void reset_portset(); |
203 |
static void check_name(char *); |
static void reset_resourceset(); |
204 |
static void check_timeout(int, int); |
static void reset_timestampset(); |
205 |
static void check_every(int); |
static void reset_sizeset(); |
206 |
static int check_perm(int); |
static void reset_uidset(); |
207 |
static void check_hostname (char *); |
static void reset_gidset(); |
208 |
static void check_exec(char *); |
static void reset_deviceset(); |
209 |
static void createinfo(); |
static void check_name(char *); |
210 |
|
static void check_timeout(int, int); |
211 |
|
static void check_every(int); |
212 |
|
static int check_perm(int); |
213 |
|
static void check_hostname (char *); |
214 |
|
static void check_exec(char *); |
215 |
|
static void createinfo(); |
216 |
static char *append_hostname(char *); |
static char *append_hostname(char *); |
217 |
static void cleanup_md5_string(char *); |
static void cleanup_md5_string(char *); |
218 |
static void check_depend(); |
static void check_depend(); |
219 |
static void order_depend(Service_T); |
static void order_depend(Service_T); |
220 |
static void validate_depend(Service_T, int *); |
static void validate_depend(Service_T, int *); |
221 |
static void setsyslog(char *); |
static void setsyslog(char *); |
222 |
%} |
%} |
223 |
|
|
224 |
%union { |
%union { |
305 |
| every |
| every |
306 |
| alert |
| alert |
307 |
| permission |
| permission |
308 |
| size |
| uid |
309 |
|
| gid |
310 |
| checksum |
| checksum |
311 |
|
| size |
312 |
| mode |
| mode |
313 |
| group |
| group |
314 |
| depend |
| depend |
324 |
| every |
| every |
325 |
| alert |
| alert |
326 |
| permission |
| permission |
327 |
|
| uid |
328 |
|
| gid |
329 |
| mode |
| mode |
330 |
| group |
| group |
331 |
| depend |
| depend |
344 |
| every |
| every |
345 |
| alert |
| alert |
346 |
| permission |
| permission |
347 |
|
| uid |
348 |
|
| gid |
349 |
| mode |
| mode |
350 |
| group |
| group |
351 |
| depend |
| depend |
546 |
| PATH { addargument($1); } |
| PATH { addargument($1); } |
547 |
; |
; |
548 |
|
|
549 |
useroption : UID STRING { adduid($2, 0); free($2); } |
useroption : UID STRING { addeuid( get_uid($2, 0) ); } |
550 |
| GID STRING { addgid($2, 0); free($2); } |
| GID STRING { addegid( get_gid($2, 0) ); } |
551 |
| UID NUMBER { adduid(NULL, $2); } |
| UID NUMBER { addeuid( get_uid(NULL, $2) ); } |
552 |
| GID NUMBER { addgid(NULL, $2); } |
| GID NUMBER { addegid( get_gid(NULL, $2) ); } |
553 |
; |
; |
554 |
|
|
555 |
connection : IF FAILED host port type protocol nettimeout THEN action { |
connection : IF FAILED host port type protocol nettimeout THEN action { |
884 |
} |
} |
885 |
; |
; |
886 |
|
|
887 |
|
uid : IF FAILED UID STRING THEN action { |
888 |
|
uidset.uid= get_uid($4, 0); |
889 |
|
uidset.action= $<number>6; |
890 |
|
adduid(&uidset); |
891 |
|
} |
892 |
|
| IF FAILED UID NUMBER THEN action { |
893 |
|
uidset.uid= get_uid(NULL, $4); |
894 |
|
uidset.action= $<number>6; |
895 |
|
adduid(&uidset); |
896 |
|
} |
897 |
|
; |
898 |
|
|
899 |
|
gid : IF FAILED GID STRING THEN action { |
900 |
|
gidset.gid= get_gid($4, 0); |
901 |
|
gidset.action= $<number>6; |
902 |
|
addgid(&gidset); |
903 |
|
} |
904 |
|
| IF FAILED GID NUMBER THEN action { |
905 |
|
gidset.gid= get_gid(NULL, $4); |
906 |
|
gidset.action= $<number>6; |
907 |
|
addgid(&gidset); |
908 |
|
} |
909 |
|
; |
910 |
|
|
911 |
%% |
%% |
912 |
|
|
913 |
|
|
1049 |
current->do_monitor= TRUE; |
current->do_monitor= TRUE; |
1050 |
current->mode= MODE_ACTIVE; |
current->mode= MODE_ACTIVE; |
1051 |
current->perm= -1; |
current->perm= -1; |
|
current->uid= -1; |
|
|
current->gid= -1; |
|
1052 |
|
|
1053 |
current->type= type; |
current->type= type; |
1054 |
current->name= name; |
current->name= name; |
1346 |
|
|
1347 |
|
|
1348 |
/* |
/* |
1349 |
|
* Set Uid object in the current service |
1350 |
|
*/ |
1351 |
|
static void adduid(struct UidSet *us) { |
1352 |
|
|
1353 |
|
Uid_T u; |
1354 |
|
|
1355 |
|
ASSERT(us); |
1356 |
|
|
1357 |
|
NEW(u); |
1358 |
|
u->uid= us->uid; |
1359 |
|
u->action= us->action; |
1360 |
|
|
1361 |
|
if((u->action == ACTION_EXEC) && command) { |
1362 |
|
u->exec= command; |
1363 |
|
command= NULL; |
1364 |
|
} |
1365 |
|
|
1366 |
|
current->uid= u; |
1367 |
|
|
1368 |
|
reset_uidset(); |
1369 |
|
|
1370 |
|
} |
1371 |
|
|
1372 |
|
|
1373 |
|
/* |
1374 |
|
* Set Gid object in the current service |
1375 |
|
*/ |
1376 |
|
static void addgid(struct GidSet *gs) { |
1377 |
|
|
1378 |
|
Gid_T g; |
1379 |
|
|
1380 |
|
ASSERT(gs); |
1381 |
|
|
1382 |
|
NEW(g); |
1383 |
|
g->gid= gs->gid; |
1384 |
|
g->action= gs->action; |
1385 |
|
|
1386 |
|
if((g->action == ACTION_EXEC) && command) { |
1387 |
|
g->exec= command; |
1388 |
|
command= NULL; |
1389 |
|
} |
1390 |
|
|
1391 |
|
current->gid= g; |
1392 |
|
|
1393 |
|
reset_gidset(); |
1394 |
|
|
1395 |
|
} |
1396 |
|
|
1397 |
|
|
1398 |
|
/* |
1399 |
* Add a new device to the current service's device list |
* Add a new device to the current service's device list |
1400 |
*/ |
*/ |
1401 |
static void adddevice(struct DeviceSet *ds) { |
static void adddevice(struct DeviceSet *ds) { |
1504 |
|
|
1505 |
|
|
1506 |
/* |
/* |
1507 |
* Add a new user id to the current command object. If the parameter, |
* Return uid if found on the system. If the parameter user is NULL |
1508 |
* user is NULL the uid parameter is used for looking up the user id |
* the uid parameter is used for looking up the user id on the system, |
1509 |
* on the system, otherwise the user parameter is used. |
* otherwise the user parameter is used. |
1510 |
*/ |
*/ |
1511 |
static void adduid(char *user, uid_t uid) { |
static uid_t get_uid(char *user, uid_t uid) { |
1512 |
|
|
1513 |
if(!getuid()) { |
struct passwd *pwd; |
1514 |
|
|
1515 |
#ifdef HAVE_GETPWNAM_R |
if(user) { |
|
char buf[1024]; |
|
|
struct passwd pwd; |
|
|
#endif |
|
|
struct passwd *r; |
|
|
|
|
|
if(user) { |
|
|
|
|
|
#ifdef HAVE_GETPWNAM_R |
|
|
if((0 != getpwnam_r(user, &pwd, buf, 1024, &r)) || !r) { |
|
|
#else |
|
|
r = getpwnam(user); |
|
|
if ( r == NULL ) { |
|
|
#endif |
|
|
|
|
|
log("%s: Requested user '%s' not found on the system. " |
|
|
"Error at line %d\n", prog, user, lineno); |
|
|
cfg_errflag++; |
|
1516 |
|
|
1517 |
} |
pwd= getpwnam(user); |
1518 |
|
free(user); |
1519 |
|
|
1520 |
} else { |
if(pwd == NULL) |
1521 |
|
yyerror("Requested user not found on the system."); |
1522 |
|
|
1523 |
#ifdef HAVE_GETPWUID_R |
} else { |
|
if((0 != getpwuid_r(uid, &pwd, buf, 1024, &r)) || !r) { |
|
|
#else |
|
|
r = getpwuid(uid); |
|
|
if ( r == NULL ) { |
|
|
#endif |
|
|
|
|
|
log("%s: Requested uid '%d' not found on the system. " |
|
|
"Error at line %d\n", prog, uid, lineno); |
|
|
cfg_errflag++; |
|
1524 |
|
|
1525 |
} |
if( (pwd= getpwuid(uid)) == NULL ) |
1526 |
|
yyerror("Requested uid not found on the system."); |
1527 |
|
|
1528 |
} |
} |
1529 |
|
|
1530 |
|
return(pwd->pw_uid); |
1531 |
|
|
1532 |
|
} |
1533 |
|
|
1534 |
|
|
1535 |
|
/* |
1536 |
|
* Return gid if found on the system. If the parameter group is NULL |
1537 |
|
* the gid parameter is used for looking up the group id on the system, |
1538 |
|
* otherwise the group parameter is used. |
1539 |
|
*/ |
1540 |
|
static gid_t get_gid(char *group, gid_t gid) { |
1541 |
|
|
1542 |
|
struct group *grd; |
1543 |
|
|
1544 |
|
if(group) { |
1545 |
|
|
1546 |
|
grd= getgrnam(group); |
1547 |
|
free(group); |
1548 |
|
|
1549 |
|
if(grd == NULL) |
1550 |
|
yyerror("Requested group not found on the system."); |
1551 |
|
|
1552 |
|
} else { |
1553 |
|
|
1554 |
|
if( (grd= getgrgid(gid)) == NULL ) |
1555 |
|
yyerror("Requested gid not found on the system."); |
1556 |
|
|
1557 |
|
} |
1558 |
|
|
1559 |
|
return(grd->gr_gid); |
1560 |
|
|
1561 |
|
} |
1562 |
|
|
1563 |
if(r) { |
|
1564 |
command->has_uid= TRUE; |
/* |
1565 |
command->uid= r->pw_uid; |
* Add a new user id to the current command object. |
1566 |
} |
*/ |
1567 |
|
static void addeuid(uid_t uid) { |
1568 |
|
|
1569 |
|
if(!getuid()) { |
1570 |
|
|
1571 |
|
command->has_uid= TRUE; |
1572 |
|
command->uid= uid; |
1573 |
|
|
1574 |
} else { |
} else { |
1575 |
|
|
1582 |
|
|
1583 |
|
|
1584 |
/* |
/* |
1585 |
* Add a new group id to the current command object. If the parameter |
* Add a new group id to the current command object. |
|
* group is NULL the gid parameter is used for looking up the group id |
|
|
* on the system, otherwise the group parameter is used. |
|
1586 |
*/ |
*/ |
1587 |
static void addgid(char *group, gid_t gid) { |
static void addegid(gid_t gid) { |
1588 |
|
|
1589 |
if(!getuid()) { |
if(!getuid()) { |
1590 |
|
|
1591 |
#ifdef HAVE_GETGRNAM_R |
command->has_gid= TRUE; |
1592 |
char buf[1024]; |
command->gid= gid; |
|
struct group gwd; |
|
|
#endif |
|
|
struct group *r; |
|
1593 |
|
|
|
if(group) { |
|
|
|
|
|
#ifdef HAVE_GETGRNAM_R |
|
|
if((0 != getgrnam_r(group, &gwd, buf, 1024, &r)) || !r) { |
|
|
#else |
|
|
r = getgrnam(group); |
|
|
if ( r == NULL ) { |
|
|
#endif |
|
|
|
|
|
log("%s: Requested group '%s' not found on the system. " |
|
|
"Error at line %d\n", prog, group, lineno); |
|
|
cfg_errflag++; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
#ifdef HAVE_GETGRGID_R |
|
|
if((0 != getgrgid_r(gid, &gwd, buf, 1024, &r)) || !r) { |
|
|
#else |
|
|
r = getgrgid(gid); |
|
|
if ( r == NULL ) { |
|
|
#endif |
|
|
|
|
|
log("%s: Requested gid '%d' not found on the system. " |
|
|
"Error at line %d\n", prog, gid, lineno); |
|
|
cfg_errflag++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(r) { |
|
|
|
|
|
command->has_gid= TRUE; |
|
|
command->gid= r->gr_gid; |
|
|
|
|
|
} |
|
|
|
|
1594 |
} else { |
} else { |
1595 |
|
|
1596 |
log("%s: Ignoring gid statement at line %d, not running as root.\n", |
log("%s: Ignoring gid statement at line %d, not running as root.\n", |
1597 |
prog, lineno); |
prog, lineno); |
1598 |
|
|
1599 |
} |
} |
1600 |
|
|
1601 |
} |
} |
1857 |
|
|
1858 |
} |
} |
1859 |
|
|
1860 |
|
|
1861 |
|
/* |
1862 |
|
* Reset the Uid set to default values |
1863 |
|
*/ |
1864 |
|
static void reset_uidset() { |
1865 |
|
|
1866 |
|
uidset.uid= 0; |
1867 |
|
uidset.action= ACTION_ALERT; |
1868 |
|
|
1869 |
|
} |
1870 |
|
|
1871 |
|
|
1872 |
|
/* |
1873 |
|
* Reset the Gid set to default values |
1874 |
|
*/ |
1875 |
|
static void reset_gidset() { |
1876 |
|
|
1877 |
|
gidset.gid= 0; |
1878 |
|
gidset.action= ACTION_ALERT; |
1879 |
|
|
1880 |
|
} |
1881 |
|
|
1882 |
|
|
1883 |
/* |
/* |
1884 |
* Reset the Device set to default values |
* Reset the Device set to default values |