PERFORCE change 181488 for review
Sergio Ligregni
ligregni at FreeBSD.org
Wed Jul 28 08:21:56 UTC 2010
http://p4web.freebsd.org/@@181488?ac=10
Change 181488 by ligregni at ligPhenom on 2010/07/28 05:51:39
It is now allowed to have multiple audit trail directories
at the slave system, the daemon syncs all of them (only those
explicitly specified)
Affected files ...
.. //depot/projects/soc2010/disaudit/damasterd.c#7 edit
.. //depot/projects/soc2010/disaudit/msocket_work.c#8 edit
.. //depot/projects/soc2010/disaudit/msocket_work.h#9 edit
.. //depot/projects/soc2010/disaudit/shipd.c#10 edit
.. //depot/projects/soc2010/disaudit/ssocket_work.c#8 edit
.. //depot/projects/soc2010/disaudit/ssocket_work.h#10 edit
.. //depot/projects/soc2010/disaudit/utils.c#3 edit
.. //depot/projects/soc2010/disaudit/utils.h#3 edit
Differences ...
==== //depot/projects/soc2010/disaudit/damasterd.c#7 (text+ko) ====
@@ -56,75 +56,69 @@
/*** DECLARATIONS ***/
/* local prototypes */
-static int check_files_equal(char *pathslave, char *sha256slave,
- char *hostname, char *path, char *fullpath);
-static int do_master_daemon();
-static int get_parameters();
-static int process_request(int sfd, struct sockaddr *clientinfo);
-static int receive_trail(int sfd, struct sockaddr *clientinfo);
-static int search_trail(int sfd, struct sockaddr *clientinfo);
+static int
+check_files_equal(char *pathslave, char *sha256slave,
+ char *hostname, char *path, char *fullpath);
+static int do_master_daemon();
+static int get_parameters();
+static int process_request(int sfd, struct sockaddr *clientinfo);
+static int receive_trail(int sfd, struct sockaddr *clientinfo);
+static int search_trail(int sfd, struct sockaddr *clientinfo);
/* Directory settings took from audit_control */
-char slave_trails_dir[MAX_DIR_SIZE + 1];
-char *ptr_std;
-int slave_dirs;
+char slave_trails_dir[MAX_DIR_SIZE + 1];
+char *ptr_std;
+int slave_dirs;
/* The level of trust the shipping process will have (0 means disabled) */
-int panic_level;
+int panic_level;
/* Port number */
-int port_number;
+int port_number;
-/*
- * The searching for a trail by it's name,
- * or by it's name & origin host, this is for example,
- * if we change a host name and this flag is on,
- * all it's trails will be sync again since the entire path
- * will be different, this is:
- * 2010xxxxx.HOST_ONE.201006date_recvd
- * then we change HOST_ONE to HOST_OTHER
- * with the flag on, there must be a trail:
- * 2010xxxxx.HOST_OTHER.201006date_recvd
- * but, there is not such trail so we sync again.
+/*
+ * The searching for a trail by it's name, or by it's name & origin host,
+ * this is for example, if we change a host name and this flag is on, all
+ * it's trails will be sync again since the entire path will be different,
+ * this is: 2010xxxxx.HOST_ONE.201006date_recvd then we change HOST_ONE to
+ * HOST_OTHER with the flag on, there must be a trail:
+ * 2010xxxxx.HOST_OTHER.201006date_recvd but, there is not such trail so we
+ * sync again.
*/
-int lookup_host;
+int lookup_host;
/*
- * DAMasterD
- * Distributed Audit Master Daemon
- *
- * This program runs on a master system, in order
- * to receive the trails (and perform the appropiate naming
- * and pathing) from the slave systems, when not runs with
- * debug option, it daemonize itself
+ * DAMasterD Distributed Audit Master Daemon
+ *
+ * This program runs on a master system, in order to receive the trails (and
+ * perform the appropiate naming and pathing) from the slave systems, when
+ * not runs with debug option, it daemonize itself
*/
int
main(int argc, char *argv[])
{
- char cl_opt;
+ char cl_opt;
debug = 0;
while ((cl_opt = getopt(argc, argv, "dl")) != -1)
switch (cl_opt) {
- case 'd':
- /* Debug option */
- debug = 1;
- break;
+ case 'd':
+ /* Debug option */
+ debug = 1;
+ break;
}
/* If not debugging, daemonize the program */
- if (debug == 0 && daemon(0,0) != 0) {
+ if (debug == 0 && daemon(0, 0) != 0) {
perror("Can't daemonize, exiting!");
exit(1);
}
-
/* Set the directory path, the host address, the panic level */
if (get_parameters() == -1) {
to_log("Can't get the parameters to work!");
exit(1);
}
-
ptr_std = slave_trails_dir + strlen(slave_trails_dir);
/*
@@ -135,7 +129,6 @@
to_log("DAMasterd disabled");
exit(0);
}
-
if (do_master_daemon() == -1)
exit(1);
@@ -145,17 +138,16 @@
static int
do_master_daemon()
{
- int socketfd, newsockfd, childpid;
- char message[256];
- struct sockaddr clientinfo;
+ int socketfd , newsockfd, childpid;
+ char message [256];
+ struct sockaddr clientinfo;
if ((socketfd = init_socket(port_number)) < 0) {
sprintf(message, "Error initializing socket on port %d",
- port_number);
+ port_number);
to_log(message);
return (-1);
}
-
while (1) {
newsockfd = accept_connection(socketfd, &clientinfo);
@@ -164,8 +156,6 @@
to_log(message);
return (-1);
}
-
-
if (!debug && (childpid = fork()) < 0) {
to_log("Error forking the process");
return (-1);
@@ -177,7 +167,6 @@
if (!debug)
close(socketfd);
}
-
close(newsockfd);
usleep(1000);
@@ -189,14 +178,14 @@
static int
get_parameters()
{
- /*
+ /*
* GSoC: using an special file, intended to include this values at
* audit_control
*/
- FILE *fpars = fopen(AUDIT_DAMASTERD_FILE, "r");
+ FILE *fpars = fopen(AUDIT_DAMASTERD_FILE, "r");
- char sslave_dirs[10];
- char lkup_host[10];
+ char sslave_dirs[10];
+ char lkup_host [10];
if (!fpars)
return (-1);
@@ -226,32 +215,30 @@
static int
process_request(int sfd, struct sockaddr *clientinfo)
{
- int res = 0;
+ int res = 0;
- char opt[2];
+ char opt [2];
- get_from_socket(sfd, opt, sizeof (opt));
+ get_from_socket(sfd, opt, sizeof(opt));
- while (res != -1)
- {
- switch(opt[0])
- {
- case '0':
- /* The process is finished */
- return 0;
- break;
- case '1':
- /* The request is about searching for a file */
- res = search_trail(sfd, clientinfo);
- break;
- case '2':
- /* The request is about receiving a trail */
- res = receive_trail(sfd, clientinfo);
- break;
- default:
- to_log("Can't understand user's request!");
+ while (res != -1) {
+ switch (opt[0]) {
+ case '0':
+ /* The process is finished */
+ return 0;
+ break;
+ case '1':
+ /* The request is about searching for a file */
+ res = search_trail(sfd, clientinfo);
+ break;
+ case '2':
+ /* The request is about receiving a trail */
+ res = receive_trail(sfd, clientinfo);
+ break;
+ default:
+ to_log("Can't understand user's request!");
}
- get_from_socket(sfd, opt, sizeof (opt));
+ get_from_socket(sfd, opt, sizeof(opt));
}
close(sfd);
@@ -262,69 +249,65 @@
static int
search_trail(int sfd, struct sockaddr *clientinfo)
{
- DIR *dp;
- struct dirent *dirp;
- struct stat statbuf;
+ DIR *dp;
+ struct dirent *dirp;
+ struct stat statbuf;
- char *ptr;
- char hbuf[NI_MAXHOST+1];
- char message[MAX_PATH_SIZE + MESSAGE_DESC_SIZE];
- char hostname[NI_MAXHOST+1];
- char pathslave[MAX_TRAILPATH_SIZE+1], sha256slave[SHA256_SIZE];
- char dirpath[MAX_DIR_SIZE+1];
- char found_trail[] = "n";
+ char *ptr;
+ char hbuf [NI_MAXHOST + 1];
+ char message [MAX_PATH_SIZE + MESSAGE_DESC_SIZE];
+ char hostname [NI_MAXHOST + 1];
+ char pathslave [MAX_TRAILPATH_SIZE + 1], sha256slave[SHA256_SIZE];
+ char dirpath [MAX_DIR_SIZE + 1];
+ char found_trail[] = "n";
- get_from_socket(sfd, pathslave, sizeof (pathslave));
- get_from_socket(sfd, sha256slave, sizeof (sha256slave));
+ get_from_socket(sfd, pathslave, sizeof(pathslave));
+ get_from_socket(sfd, sha256slave, sizeof(sha256slave));
strlcpy(hostname,
- inet_ntoa(((struct sockaddr_in *) clientinfo)->sin_addr),
- sizeof (hostname));
+ inet_ntoa(((struct sockaddr_in *)clientinfo)->sin_addr),
+ sizeof(hostname));
if (getnameinfo(clientinfo, clientinfo->sa_len, hbuf, sizeof(hbuf),
- NULL, 0, NI_NAMEREQD))
+ NULL, 0, NI_NAMEREQD))
to_log("Couldn't resolve hostname, using IP address");
else
- strlcpy(hostname, hbuf, sizeof (hostname));
+ strlcpy(hostname, hbuf, sizeof(hostname));
snprintf(message, sizeof(message),
"Looking for \"%s\" from \"%s\" with SHA256: \"%s\"", pathslave,
- hostname, sha256slave);
+ hostname, sha256slave);
to_log(message);
- strlcpy(dirpath, slave_trails_dir, sizeof (dirpath));
+ strlcpy(dirpath, slave_trails_dir, sizeof(dirpath));
if (slave_dirs) {
- strlcat(dirpath, "/", sizeof (dirpath));
- strlcat(dirpath, hostname, sizeof (dirpath));
+ strlcat(dirpath, "/", sizeof(dirpath));
+ strlcat(dirpath, hostname, sizeof(dirpath));
}
-
- if ( !(dp = opendir(dirpath)) ) {
+ if (!(dp = opendir(dirpath))) {
to_log("Can't open slave trails' directory");
send_to_socket(sfd, "n");
return (1);
}
-
/*
* We must count the elements (just the valid ones, this is: the
* trails) of the directory.
*/
- while ('n' == found_trail[0] && (dirp = readdir(dp)) != NULL )
+ while ('n' == found_trail[0] && (dirp = readdir(dp)) != NULL)
if (strcmp(dirp->d_name, ".") && strcmp(dirp->d_name, "..")) {
/* We have other than . or .. */
asprintf(&ptr, "%s/%s", dirpath, dirp->d_name);
- if ( stat(ptr, &statbuf) < 0 )
- {
+ if (stat(ptr, &statbuf) < 0) {
to_log("Stat error!");
return -1;
}
-
if (S_ISDIR(statbuf.st_mode) == 0) {
/* It's not a directory */
- if ( check_files_equal(pathslave, sha256slave,
- hostname, dirp->d_name, ptr) ) {
+ if (check_files_equal(pathslave, sha256slave,
+ hostname, dirp->d_name, ptr)) {
/*
* Check that the trails are the same
* name + SHA256
@@ -334,41 +317,36 @@
}
free(ptr);
}
-
closedir(dp);
- snprintf(message, sizeof (message), "The search for %s resulted: %s\n",
- pathslave, ('y' == found_trail[0]) ? "YES" : "NO");
+ snprintf(message, sizeof(message), "The search for %s resulted: %s\n",
+ pathslave, ('y' == found_trail[0]) ? "YES" : "NO");
send_to_socket(sfd, found_trail);
return (1);
}
/*
- * This function receives the name and MD5 checksum of the slave trail
- * and the path and fullpath (to get MD5) of the master trail
- * and checks if they are the same, also checks the lookup_host
- * variable to determine if the hostname must be searched as part
- * of the trails name
+ * This function receives the name and MD5 checksum of the slave trail and
+ * the path and fullpath (to get MD5) of the master trail and checks if they
+ * are the same, also checks the lookup_host variable to determine if the
+ * hostname must be searched as part of the trails name
*/
static int
check_files_equal(char *pathslave, char *sha256slave, char *hostname, char *path,
- char *fullpath)
+ char *fullpath)
{
- char path_to_find[strlen(pathslave) + strlen(hostname) + 2];
+ char path_to_find[strlen(pathslave) + strlen(hostname) + 2];
- strlcpy(path_to_find, pathslave, sizeof (path_to_find));
+ strlcpy(path_to_find, pathslave, sizeof(path_to_find));
- if (lookup_host)
- {
- strlcat(path_to_find, ".", sizeof (path_to_find));
- strlcat(path_to_find, hostname, sizeof (path_to_find));
+ if (lookup_host) {
+ strlcat(path_to_find, ".", sizeof(path_to_find));
+ strlcat(path_to_find, hostname, sizeof(path_to_find));
}
-
- if (!strncmp(path, path_to_find, strlen(path_to_find)))
- {
- char *sha256 = (char *) malloc (sizeof(char) * SHA256_SIZE);
+ if (!strncmp(path, path_to_find, strlen(path_to_find))) {
+ char *sha256 = (char *)malloc(sizeof(char) * SHA256_SIZE);
sha256 = SHA256_File(fullpath, sha256);
if (!strcmp(sha256, sha256slave))
@@ -376,82 +354,75 @@
free(sha256);
}
-
return (0);
}
static int
receive_trail(int sfd, struct sockaddr *clientinfo)
{
- DIR *dp;
+ DIR *dp;
- char fullpath[MAX_PATH_SIZE + 1];
- char hbuf[NI_MAXHOST+1];
- char message[MAX_PATH_SIZE + MESSAGE_DESC_SIZE];
- char hostname[NI_MAXHOST+1];
- char pathslave[MAX_TRAILPATH_SIZE+1];
- char dirpath[MAX_DIR_SIZE+1];
- char buffer[MAX_BUF_SIZE + 1];
- int brecv;
- time_t mtime;
- struct tm *ltime;
- unsigned file_size;
- int fd, bwrtn, bread;
+ char fullpath [MAX_PATH_SIZE + 1];
+ char hbuf [NI_MAXHOST + 1];
+ char message [MAX_PATH_SIZE + MESSAGE_DESC_SIZE];
+ char hostname [NI_MAXHOST + 1];
+ char pathslave [MAX_TRAILPATH_SIZE + 1];
+ char dirpath [MAX_DIR_SIZE + 1];
+ char buffer [MAX_BUF_SIZE + 1];
+ int brecv;
+ time_t mtime;
+ struct tm *ltime;
+ unsigned file_size;
+ int fd , bwrtn, bread;
- get_from_socket(sfd, pathslave, sizeof (pathslave));
+ get_from_socket(sfd, pathslave, sizeof(pathslave));
strlcpy(hostname,
- inet_ntoa(((struct sockaddr_in *) clientinfo)->sin_addr),
- sizeof (hostname));
+ inet_ntoa(((struct sockaddr_in *)clientinfo)->sin_addr),
+ sizeof(hostname));
if (getnameinfo(clientinfo, clientinfo->sa_len, hbuf, sizeof(hbuf),
- NULL, 0, NI_NAMEREQD))
+ NULL, 0, NI_NAMEREQD))
to_log("Couldn't resolve hostname, using IP address");
else
- strlcpy(hostname, hbuf, sizeof (hostname));
+ strlcpy(hostname, hbuf, sizeof(hostname));
- snprintf(message, sizeof (message), "Receiving \"%s\" from \"%s\"",
- pathslave, hostname);
+ snprintf(message, sizeof(message), "Receiving \"%s\" from \"%s\"",
+ pathslave, hostname);
to_log(message);
- strlcpy(dirpath, slave_trails_dir, sizeof (dirpath));
+ strlcpy(dirpath, slave_trails_dir, sizeof(dirpath));
- if ( !(dp = opendir(dirpath)) ) {
+ if (!(dp = opendir(dirpath))) {
to_log("Can't open Slave trails dir, please create it or"
- " change the value at config files!");
+ " change the value at config files!");
return (-1);
}
-
closedir(dp);
- if (slave_dirs)
- {
- strlcat(dirpath, "/", sizeof (dirpath));
- strlcat(dirpath, hostname, sizeof (dirpath));
+ if (slave_dirs) {
+ strlcat(dirpath, "/", sizeof(dirpath));
+ strlcat(dirpath, hostname, sizeof(dirpath));
}
-
- if ( !(dp = opendir(dirpath)) )
- {
+ if (!(dp = opendir(dirpath))) {
to_log("Creating slave dir for this host");
- if ( mkdir(dirpath, S_IRWXU | S_IRGRP | S_IXGRP) < 0 )
- {
+ if (mkdir(dirpath, S_IRWXU | S_IRGRP | S_IXGRP) < 0) {
to_log("Cant't create host's directory!");
return -1;
}
- }
- else
+ } else
closedir(dp);
- strlcat(dirpath, "/", sizeof (dirpath));
+ strlcat(dirpath, "/", sizeof(dirpath));
mtime = time(NULL);
ltime = gmtime(&mtime);
snprintf(fullpath, sizeof(fullpath), "%s%s.%s.%04d%02d%02d%02d%02d%02d",
- dirpath, pathslave, hostname, ltime->tm_year + 1900,
- ltime->tm_mon + 1, ltime->tm_mday, ltime->tm_hour, ltime->tm_min,
- ltime->tm_sec);
- snprintf(message, sizeof (message), "Create: %s", fullpath);
+ dirpath, pathslave, hostname, ltime->tm_year + 1900,
+ ltime->tm_mon + 1, ltime->tm_mday, ltime->tm_hour, ltime->tm_min,
+ ltime->tm_sec);
+ snprintf(message, sizeof(message), "Create: %s", fullpath);
to_log(message);
/* We get the trail size */
@@ -462,21 +433,18 @@
to_log("Can't create the trail at master system");
return (-1);
}
-
while (file_size) {
brecv = recv(sfd, &bread, sizeof(bread), 0);
if (brecv < 0) {
to_log("Error receiving the file");
return (-1);
}
-
brecv = recv(sfd, buffer, bread, 0);
if (brecv < 0) {
to_log("Error receiving the file");
return (-1);
- }
- else if (brecv == 0)
+ } else if (brecv == 0)
break;
bwrtn = write(fd, buffer, brecv);
@@ -485,11 +453,10 @@
to_log("Error writting the file");
return (-1);
}
-
file_size -= brecv;
}
- snprintf(message, sizeof (message), "Master got: %s", fullpath);
+ snprintf(message, sizeof(message), "Master got: %s", fullpath);
to_log(message);
close(fd);
@@ -499,7 +466,5 @@
to_log("Error changing permissions");
return (-1);
}
-
return (0);
}
-
==== //depot/projects/soc2010/disaudit/msocket_work.c#8 (text+ko) ====
@@ -40,12 +40,6 @@
#include <arpa/inet.h>
-/*** DECLARATIONS ***/
-
-/* local prototypes */
-int init_socket(int);
-int accept_connection(int, struct sockaddr *);
-
int
init_socket(int port)
{
@@ -87,4 +81,3 @@
return (retval);
}
-
==== //depot/projects/soc2010/disaudit/msocket_work.h#9 (text+ko) ====
==== //depot/projects/soc2010/disaudit/shipd.c#10 (text+ko) ====
@@ -56,91 +56,97 @@
/*** DECLARATIONS ***/
/* Trail Entries */
-typedef struct s_trail_entry
-{
- char name[MAX_TRAILPATH_SIZE + 1];
- int found;
+typedef struct s_trail_entry {
+ char name [MAX_TRAILPATH_SIZE + 1];
+ unsigned dir_id;
+ int found;
struct s_trail_entry *next;
-} trail_entry;
+} trail_entry;
/* Directory entries */
-typedef struct s_audit_dir_entry
-{
- char path[MAX_DIR_SIZE+1];
-} audit_dir_entry;
+/*
+ * This implementation replaces char audit_trails_dir[MAX_DIR_SIZE + 1]; in
+ * order to support multiple audit trail directories
+ */
+typedef struct s_audit_dir_entry {
+ unsigned id;
+ char name [MAX_DIR_SIZE + 1];
+ struct s_audit_dir_entry *next;
+} audit_dir_entry;
+
+/*** local prototypes ***/
+static int add_trail_entry(trail_entry ** root, char *name, unsigned dir_id);
+static int cmp_trails(const void *A, const void *B);
+static void delete_trail_entry(trail_entry ** root, int criteria, int number);
+static void do_daemon();
+static void do_daemon_date();
+static void do_daemon_all();
+static void do_last();
+static int get_last_trail(char *path, size_t path_size, unsigned *dir_id);
+static int get_parameters();
+static int is_audit_trail(char *path);
+static int is_in_master(trail_entry * cur, int *first_found);
+static void pll (trail_entry * root);
+static int send_trail(trail_entry * cur);
+static int add_audit_dir_entry(audit_dir_entry ** root, char *path, unsigned id);
+static void delete_audit_dir_entry(audit_dir_entry ** root);
+static void set_dir_id(audit_dir_entry ** temp, unsigned id);
/* Directory settings took from audit_control */
-char audit_trails_dir[MAX_DIR_SIZE + 1];
-char master_host[MAX_HOST_SIZE + 1];
-
-/*** local prototypes ***/
-static int add_trail_entry(trail_entry **root, char *name);
-static int cmp_trails (const void *A, const void *B);
-static void delete_trail_entry(trail_entry **root, int criteria, int number);
-static void do_daemon();
-static void do_daemon_date();
-static void do_daemon_all();
-static void do_last();
-static int get_last_trail(char *path, size_t path_size);
-static int get_parameters();
-static int is_audit_trail(char *path);
-static int is_in_master(trail_entry *cur, int *first_found);
-static void pll(trail_entry *root);
-static int send_trail(trail_entry *cur);
+char master_host[MAX_HOST_SIZE + 1];
+audit_dir_entry *audit_dir_root;
/* The level of trust the shipping process will have (0 means disabled) */
-int panic_level;
+int panic_level;
/* The frequency the daemon will be checking the master's trail list */
-int msec_freq;
+int msec_freq;
/* Port number */
-int port_number;
+int port_number;
/*
- * ShipD
- * Shipping Daemon
- *
- * This program is checking, according to the panic_level variable
- * the audit trail directories and send the trails to a master
- * system, when no runs with debug option, it daemonize itself
+ * ShipD Shipping Daemon
+ *
+ * This program is checking, according to the panic_level variable the audit
+ * trail directories and send the trails to a master system, when no runs
+ * with debug option, it daemonize itself
*/
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- char cl_opt;
- int last = 0;
+ char cl_opt;
+ int last = 0;
debug = 0;
+ audit_dir_root = NULL;
while ((cl_opt = getopt(argc, argv, "dl")) != -1)
switch (cl_opt) {
- case 'd':
- /* Debug option */
- debug = 1;
- break;
- case 'l':
- /*
- * Last trail (when called by AUDIT when it
- * closes the trail).
- */
- last = 1;
- break;
+ case 'd':
+ /* Debug option */
+ debug = 1;
+ break;
+ case 'l':
+ /*
+ * Last trail (when called by AUDIT when it closes
+ * the trail).
+ */
+ last = 1;
+ break;
}
/* If not debugging, daemonize the program */
- if (debug == 0 && daemon(0,0) != 0) {
+ if (debug == 0 && daemon(0, 0) != 0) {
perror("Can't daemonize, exiting!");
exit(1);
}
-
/* Set the directory path, the host address, the panic level */
if (get_parameters() == -1) {
to_log("Can't get the parameters to work!");
exit(1);
}
-
- /*
+ /*
* There is no shipd enabled and it wasn't called by AUDIT (normally
* the unique way to get 'last' on).
*/
@@ -148,7 +154,6 @@
to_log("Shipd disabled");
exit(0);
}
-
/*
* This means that the daemon will only search for the last closed
* trail and send to the master system.
@@ -157,12 +162,14 @@
do_last();
} else {
/*
- * Otherwise, we will perform a permanent listing checking and
- * sync them.
+ * Otherwise, we will perform a permanent listing checking
+ * and sync them.
*/
do_daemon();
}
+ delete_audit_dir_entry(&audit_dir_root);
+
return (0);
}
@@ -170,11 +177,15 @@
static int
get_parameters()
{
- /*
+ /*
* GSoC: using an special file, intended to include this values at
* audit_control.
*/
- FILE *fpars = fopen(AUDIT_SHIPD_FILE, "r");
+ FILE *fpars = fopen(AUDIT_SHIPD_FILE, "r");
+
+ char audit_trails_dir[MAX_DIR_SIZE + 1];
+
+ unsigned dir_id = 0;
if (!fpars)
return -1;
@@ -183,10 +194,15 @@
return -1;
/*
- * XXX This parsing of the shipd_control file might need to be
+ * XXX This parsing of the shipd_control file might need to be
* reworked a bit. -sson.
*/
fscanf(fpars, "%s", audit_trails_dir);
+ add_audit_dir_entry(&audit_dir_root, audit_trails_dir, ++dir_id);
+ fscanf(fpars, "%s", audit_trails_dir);
+ add_audit_dir_entry(&audit_dir_root, audit_trails_dir, ++dir_id);
+ fscanf(fpars, "%s", audit_trails_dir);
+ add_audit_dir_entry(&audit_dir_root, audit_trails_dir, ++dir_id);
fscanf(fpars, "%s", master_host);
fscanf(fpars, "%d", &panic_level);
fscanf(fpars, "%d", &msec_freq);
@@ -198,30 +214,30 @@
}
/*
- * Look for the last closed trail and
- * send it.
+ * Look for the last closed trail and send it.
*/
static void
do_last()
{
- char last_trail[MAX_TRAILPATH_SIZE + 1];
- char message[MAX_PATH_SIZE + MESSAGE_DESC_SIZE];
- trail_entry *root = NULL;
+ char last_trail[MAX_TRAILPATH_SIZE + 1];
+ char message [MAX_PATH_SIZE + MESSAGE_DESC_SIZE];
+ unsigned dir_id = 0;
+ trail_entry *root = NULL;
- if (get_last_trail(last_trail, sizeof (last_trail)) == -1)
+ if (get_last_trail(last_trail, sizeof(last_trail), &dir_id) == -1)
to_log("Nothing to send!");
- snprintf(message, sizeof (message), "Will send \"%s\" to %s",
- last_trail, master_host);
+ snprintf(message, sizeof(message), "Will send \"%s\" to %s",
+ last_trail, master_host);
to_log(message);
- add_trail_entry(&root, last_trail);
+ add_trail_entry(&root, last_trail, dir_id);
if (send_trail(root) == -1) {
to_log("Error sending the last trail");
} else {
- snprintf(message, sizeof (message),
- "Successfully sent \"%s\" to %s", last_trail, master_host);
+ snprintf(message, sizeof(message),
+ "Successfully sent \"%s\" to %s", last_trail, master_host);
to_log(message);
}
@@ -229,77 +245,84 @@
}
/*
- * Used by do_last() function, this get the last
- * closed trail in meaning of lexicographic
- * order (that is also a chronological one)
+ * Used by do_last() function, this get the last closed trail in meaning of
+ * lexicographic order (that is also a chronological one)
*/
static int
-get_last_trail(char *path, size_t path_size)
+get_last_trail(char *path, size_t path_size, unsigned *dir_id)
{
- DIR *dp;
- struct dirent *dirp;
- struct stat statbuf;
+ DIR *dp;
+ struct dirent *dirp;
+ struct stat statbuf;
+
+ audit_dir_entry *trail_directory = audit_dir_root;
- char *ptr;
+ char *ptr;
*path = 0;
- if ( !(dp = opendir(audit_trails_dir)) ) {
- to_log("Can't open directory");
- return -1;
- }
+ while (trail_directory) {
+ if (!(dp = opendir(trail_directory->name))) {
+ to_log("Can't open directory");
+ return -1;
+ }
+ /*
+ * Here we will pass through the entire directory and get the
+ * path of the latest closed trail.
+ */
+ while ((dirp = readdir(dp)) != NULL)
+ if (strcmp(dirp->d_name, ".") && strcmp(dirp->d_name, "..")) {
+ /* We have other than . or .. */
- /*
- * Here we will pass through the entire directory and get the path of
- * the latest closed trail.
- */
- while ( (dirp = readdir(dp)) != NULL )
- if (strcmp(dirp->d_name, ".") && strcmp(dirp->d_name, "..")) {
- /* We have other than . or .. */
+ asprintf(&ptr, "%s/%s", trail_directory->name, dirp->d_name);
- asprintf(&ptr, "%s/%s", audit_trails_dir, dirp->d_name);
-
- if ( stat(ptr, &statbuf) < 0 ) {
- to_log("Stat error!");
- return -1;
- }
-
- if (S_ISDIR(statbuf.st_mode) == 0) {
- /* It's not a directory */
- if ( is_audit_trail(dirp->d_name) ) {
- /* It's not other file */
- if (*path == 0) {
- /*
- * This is our first trail, so
- * assumme is the last.
- */
- strlcpy(path, dirp->d_name,
- path_size);
- } else {
- /*
- * Fortunately, the older a
- * trail is, the lower
- * lexocographic value it has.
- */
- if (strcmp (path, ptr) < 0)
- strlcpy(path,
- dirp->d_name,
- path_size);
+ if (stat(ptr, &statbuf) < 0) {
+ to_log("Stat error!");
+ return -1;
+ }
+ if (S_ISDIR(statbuf.st_mode) == 0) {
+ /* It's not a directory */
+ if (is_audit_trail(dirp->d_name)) {
+ /* It's not other file */
+ if (*path == 0) {
+ /*
+ * This is our first
+ * trail, so assumme
+ * is the last.
+ */
+ strlcpy(path, dirp->d_name,
+ path_size);
+ *dir_id = trail_directory->id;
+ } else {
+ /*
+ * Fortunately, the
+ * older a trail is,
+ * the lower
+ * lexicographic
+ * value it has.
+ */
+ if (strcmp(path, dirp->d_name) < 0) {
+ strlcpy(path,
+ dirp->d_name,
+ path_size);
+ *dir_id = trail_directory->id;
+ }
+ }
}
}
+ free(ptr);
}
- free(ptr);
- }
+ closedir(dp);
- closedir(dp);
+ trail_directory = trail_directory->next;
+ }
return (0);
}
/*
- * When exploring /var/audit/ (or the directory
- * where the trails are), not all files are trails
- * so we must ensure we will only deal with the ones
+ * When exploring /var/audit/ (or the directory where the trails are), not
+ * all files are trails so we must ensure we will only deal with the ones
* that are trails.
*/
static int
@@ -307,8 +330,7 @@
{
/*
* We have these posibilities, only the first one is allowed
- * 20100619223115.20100619223131
- * 20100619223131.not_terminated
+ * 20100619223115.20100619223131 20100619223131.not_terminated
* current
*/
@@ -322,19 +344,17 @@
static void
do_daemon()
{
- while (1)
- {
- switch (panic_level)
- {
+ while (1) {
+ switch (panic_level) {
case PANIC_DATE:
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list