Set device creation date if it hasn't been set yet
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* global debug output variables
|
* global debug output variables
|
||||||
@@ -52,13 +53,15 @@ bool policy_start(database_t *db, int session_id)
|
|||||||
enumerator_t *e;
|
enumerator_t *e;
|
||||||
int id, gid, device_id, product_id, group_id = 0, parent;
|
int id, gid, device_id, product_id, group_id = 0, parent;
|
||||||
int type, file, dir, arg_int, rec_fail, rec_noresult;
|
int type, file, dir, arg_int, rec_fail, rec_noresult;
|
||||||
|
u_int created;
|
||||||
char *argument;
|
char *argument;
|
||||||
|
|
||||||
/* get session data */
|
/* get session data */
|
||||||
e = db->query(db,
|
e = db->query(db,
|
||||||
"SELECT device, product FROM sessions WHERE id = ? ",
|
"SELECT s.device, s.product, d.created FROM sessions AS s "
|
||||||
DB_INT, session_id, DB_INT, DB_INT);
|
"LEFT JOIN devices AS d ON s.device = d.id WHERE s.id = ?",
|
||||||
if (!e || !e->enumerate(e, &device_id, &product_id))
|
DB_INT, session_id, DB_INT, DB_INT, DB_UINT);
|
||||||
|
if (!e || !e->enumerate(e, &device_id, &product_id, &created))
|
||||||
{
|
{
|
||||||
DESTROY_IF(e);
|
DESTROY_IF(e);
|
||||||
fprintf(stderr, "session %d not found\n", session_id);
|
fprintf(stderr, "session %d not found\n", session_id);
|
||||||
@@ -80,6 +83,18 @@ bool policy_start(database_t *db, int session_id)
|
|||||||
}
|
}
|
||||||
e->destroy(e);
|
e->destroy(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set the creation date if hasn't been set yet */
|
||||||
|
if (!created)
|
||||||
|
{
|
||||||
|
if (db->execute(db, NULL,
|
||||||
|
"UPDATE devices SET created = ? WHERE id = ?",
|
||||||
|
DB_UINT, time(NULL), DB_INT, device_id) != 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "creation date of device could not be set\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if no group membership found, try default product group */
|
/* if no group membership found, try default product group */
|
||||||
|
|||||||
Reference in New Issue
Block a user